afxLightBase_T3D.cpp
Engine/source/afx/ce/afxLightBase_T3D.cpp
Public Functions
ConsoleDocClass(afxT3DLightBaseData , "@brief A datablock baseclass <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/class/classafxt3dpointlightdata/">afxT3DPointLightData</a> and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxT3DSpotLightData.\n\n</a>" "Not intended <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be used directly, <a href="/coding/class/classafxt3dlightbasedata/">afxT3DLightBaseData</a> exists <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> provide base member variables and generic functionality " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the derived classes <a href="/coding/class/classafxt3dpointlightdata/">afxT3DPointLightData</a> and afxT3DSpotLightData." "\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxT3DPointLightData\n\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxT3DSpotLightData\n\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">PointLight\n\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SpotLight\n\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxEffects\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )
Detailed Description
Public Functions
ConsoleDocClass(afxT3DLightBaseData , "@brief A datablock baseclass <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/class/classafxt3dpointlightdata/">afxT3DPointLightData</a> and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxT3DSpotLightData.\n\n</a>" "Not intended <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be used directly, <a href="/coding/class/classafxt3dlightbasedata/">afxT3DLightBaseData</a> exists <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> provide base member variables and generic functionality " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the derived classes <a href="/coding/class/classafxt3dpointlightdata/">afxT3DPointLightData</a> and afxT3DSpotLightData." "\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxT3DPointLightData\n\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxT3DSpotLightData\n\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">PointLight\n\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SpotLight\n\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxEffects\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )
IMPLEMENT_CO_DATABLOCK_V1(afxT3DLightBaseData )
1 2 3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames 5// Copyright (C) 2015 Faust Logic, Inc. 6// 7// Permission is hereby granted, free of charge, to any person obtaining a copy 8// of this software and associated documentation files (the "Software"), to 9// deal in the Software without restriction, including without limitation the 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 11// sell copies of the Software, and to permit persons to whom the Software is 12// furnished to do so, subject to the following conditions: 13// 14// The above copyright notice and this permission notice shall be included in 15// all copies or substantial portions of the Software. 16// 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23// IN THE SOFTWARE. 24// 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 26 27#include "afx/arcaneFX.h" 28 29#include "console/consoleTypes.h" 30#include "core/stream/bitStream.h" 31#include "T3D/lightAnimData.h" 32 33#include "afx/ce/afxLightBase_T3D.h" 34 35//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 36// afxT3DLightBaseData 37 38IMPLEMENT_CO_DATABLOCK_V1(afxT3DLightBaseData); 39 40ConsoleDocClass( afxT3DLightBaseData, 41 "@brief A datablock baseclass for afxT3DPointLightData and afxT3DSpotLightData.\n\n" 42 43 "Not intended to be used directly, afxT3DLightBaseData exists to provide base member variables and generic functionality " 44 "for the derived classes afxT3DPointLightData and afxT3DSpotLightData." 45 "\n\n" 46 47 "@see afxT3DPointLightData\n\n" 48 "@see afxT3DSpotLightData\n\n" 49 "@see PointLight\n\n" 50 "@see SpotLight\n\n" 51 52 "@ingroup afxEffects\n" 53 "@ingroup AFX\n" 54 "@ingroup Datablocks\n" 55); 56 57afxT3DLightBaseData::afxT3DLightBaseData() 58 : mIsEnabled( true ), 59 mColor( LinearColorF::WHITE ), 60 mBrightness( 1.0f ), 61 mCastShadows( false ), 62 mPriority( 1.0f ), 63 mAnimationData( NULL ), 64 mFlareData( NULL ), 65 mFlareScale( 1.0f ) 66{ 67 68 mLocalRenderViz = false; 69 70 // marked true if datablock ids need to 71 // be converted into pointers 72 do_id_convert = false; 73} 74 75afxT3DLightBaseData::afxT3DLightBaseData(const afxT3DLightBaseData& other, bool temp_clone) : GameBaseData(other, temp_clone) 76{ 77 mIsEnabled = other.mIsEnabled; 78 mColor = other.mColor; 79 mBrightness = other.mBrightness; 80 mCastShadows = other.mCastShadows; 81 mPriority = other.mPriority; 82 mAnimationData = other.mAnimationData; 83 mAnimState = other.mAnimState; 84 mFlareData = other.mFlareData; 85 mFlareScale = other.mFlareScale; 86 87 mLocalRenderViz = other.mLocalRenderViz; 88 89 do_id_convert = other.do_id_convert; 90} 91 92// 93// NOTE: keep this as consistent as possible with LightBase::initPersistFields() 94// 95void afxT3DLightBaseData::initPersistFields() 96{ 97 // We only add the basic lighting options that all lighting 98 // systems would use... the specific lighting system options 99 // are injected at runtime by the lighting system itself. 100 101 addGroup( "Light" ); 102 103 addField( "isEnabled", TypeBool, Offset( mIsEnabled, afxT3DLightBaseData ), 104 "Enables/Disables the object rendering and functionality in the scene."); 105 addField( "color", TypeColorF, Offset( mColor, afxT3DLightBaseData ), 106 "Changes the base color hue of the light."); 107 addField( "brightness", TypeF32, Offset( mBrightness, afxT3DLightBaseData ), 108 "Adjusts the lights power, 0 being off completely."); 109 addField( "castShadows", TypeBool, Offset( mCastShadows, afxT3DLightBaseData ), 110 "Enables/disables shadow casts by this light."); 111 addField( "priority", TypeF32, Offset( mPriority, afxT3DLightBaseData ), 112 "Used for sorting of lights by the light manager. Priority determines if a light " 113 "has a stronger effect than, those with a lower value"); 114 addField( "localRenderViz", TypeBool, Offset( mLocalRenderViz, afxT3DLightBaseData ), 115 "Enables/disables a semi-transparent geometry to help visualize the light's " 116 "range and placement."); 117 118 endGroup( "Light" ); 119 120 addGroup( "Light Animation" ); 121 122 addField( "animate", TypeBool, Offset( mAnimState.active, afxT3DLightBaseData ), 123 "Toggles animation for the light on and off"); 124 addField( "animationType", TYPEID<LightAnimData>(), Offset( mAnimationData, afxT3DLightBaseData ), 125 "Datablock containing light animation information (LightAnimData)"); 126 addField( "animationPeriod", TypeF32, Offset( mAnimState.animationPeriod, afxT3DLightBaseData ), 127 "The length of time in seconds for a single playback of the light animation"); 128 addField( "animationPhase", TypeF32, Offset( mAnimState.animationPhase, afxT3DLightBaseData ), 129 "The phase used to offset the animation start time to vary the animation of " 130 "nearby lights."); 131 132 endGroup( "Light Animation" ); 133 134 addGroup( "Misc" ); 135 136 addField( "flareType", TYPEID<LightFlareData>(), Offset( mFlareData, afxT3DLightBaseData ), 137 "Datablock containing light flare information (LightFlareData)"); 138 addField( "flareScale", TypeF32, Offset( mFlareScale, afxT3DLightBaseData ), 139 "Globally scales all features of the light flare"); 140 141 endGroup( "Misc" ); 142 143 /* 144 // Now inject any light manager specific fields. 145 LightManager::initLightFields(); 146 */ 147 148 // We do the parent fields at the end so that 149 // they show up that way in the inspector. 150 Parent::initPersistFields(); 151} 152 153bool afxT3DLightBaseData::onAdd() 154{ 155 if (Parent::onAdd() == false) 156 return false; 157 158 return true; 159} 160 161void afxT3DLightBaseData::packData(BitStream* stream) 162{ 163 Parent::packData(stream); 164 165 // note: BitStream's overloaded write() for LinearColorF will convert 166 // to ColorI for transfer and then back to LinearColorF. This is fine 167 // for most color usage but for lighting colors we want to preserve 168 // "pushed" color values which may be greater than 1.0 so the color 169 // is instead sent as individual color primaries. 170 stream->write( mColor.red ); 171 stream->write( mColor.green ); 172 stream->write( mColor.blue ); 173 174 stream->write( mBrightness ); 175 stream->writeFlag( mCastShadows ); 176 stream->write( mAnimState.animationPeriod ); 177 stream->write( mAnimState.animationPhase ); 178 stream->write( mFlareScale ); 179 180 writeDatablockID(stream, mAnimationData, mPacked); 181 writeDatablockID(stream, mFlareData, mPacked); 182} 183 184void afxT3DLightBaseData::unpackData(BitStream* stream) 185{ 186 Parent::unpackData(stream); 187 188 stream->read( &mColor.red ); 189 stream->read( &mColor.green ); 190 stream->read( &mColor.blue ); 191 mColor.alpha = 1.0f; 192 193 stream->read( &mBrightness ); 194 mCastShadows = stream->readFlag(); 195 stream->read( &mAnimState.animationPeriod ); 196 stream->read( &mAnimState.animationPhase ); 197 stream->read( &mFlareScale ); 198 199 mAnimationData = (LightAnimData*)(uintptr_t)readDatablockID(stream); 200 mFlareData = (LightFlareData*)(uintptr_t)readDatablockID(stream); 201 202 do_id_convert = true; 203} 204 205bool afxT3DLightBaseData::preload(bool server, String &errorStr) 206{ 207 if (!Parent::preload(server, errorStr)) 208 return false; 209 210 // Resolve objects transmitted from server 211 if (!server) 212 { 213 if (do_id_convert) 214 { 215 SimObjectId anim_id = SimObjectId((uintptr_t)mAnimationData); 216 if (anim_id != 0) 217 { 218 // try to convert id to pointer 219 if (!Sim::findObject(anim_id, mAnimationData)) 220 { 221 Con::errorf(ConsoleLogEntry::General, 222 "afxT3DLightBaseData::preload() -- bad datablockId: 0x%x (animationType)", 223 anim_id); 224 } 225 } 226 SimObjectId flare_id = SimObjectId((uintptr_t)mFlareData); 227 if (flare_id != 0) 228 { 229 // try to convert id to pointer 230 if (!Sim::findObject(flare_id, mFlareData)) 231 { 232 Con::errorf(ConsoleLogEntry::General, 233 "afxT3DLightBaseData::preload() -- bad datablockId: 0x%x (flareType)", 234 flare_id); 235 } 236 } 237 do_id_convert = false; 238 } 239 } 240 241 return true; 242} 243 244//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 245