2
0

sceneObject.cpp 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  23. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  24. // Copyright (C) 2015 Faust Logic, Inc.
  25. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  26. #include "platform/platform.h"
  27. #include "scene/sceneObject.h"
  28. #include "platform/profiler.h"
  29. #include "console/consoleTypes.h"
  30. #include "console/engineAPI.h"
  31. #include "console/simPersistID.h"
  32. #include "sim/netConnection.h"
  33. #include "core/stream/bitStream.h"
  34. #include "scene/sceneManager.h"
  35. #include "scene/sceneTracker.h"
  36. #include "scene/sceneRenderState.h"
  37. #include "scene/zones/sceneZoneSpace.h"
  38. #include "collision/extrudedPolyList.h"
  39. #include "collision/earlyOutPolyList.h"
  40. #include "collision/optimizedPolyList.h"
  41. #include "math/mPolyhedron.h"
  42. #include "gfx/bitmap/gBitmap.h"
  43. #include "math/util/frustum.h"
  44. #include "math/mathIO.h"
  45. #include "math/mTransform.h"
  46. #include "T3D/gameBase/gameProcess.h"
  47. #include "T3D/gameBase/gameConnection.h"
  48. #include "T3D/accumulationVolume.h"
  49. IMPLEMENT_CONOBJECT(SceneObject);
  50. ConsoleDocClass( SceneObject,
  51. "@brief A networkable object that exists in the 3D world.\n\n"
  52. "The SceneObject class provides the foundation for 3D objects in the Engine. It "
  53. "exposes the functionality for:\n\n"
  54. "<ul><li>Position, rotation and scale within the world.</li>"
  55. "<li>Working with a scene graph (in the Zone and Portal sections), allowing efficient "
  56. "and robust rendering of the game scene.</li>"
  57. "<li>Various helper functions, including functions to get bounding information "
  58. "and momentum/velocity.</li>"
  59. "<li>Mounting one SceneObject to another.</li>"
  60. "<li>An interface for collision detection, as well as ray casting.</li>"
  61. "<li>Lighting. SceneObjects can register lights both at lightmap generation "
  62. "time, and dynamic lights at runtime (for special effects, such as from flame "
  63. "or a projectile, or from an explosion).</li></ul>\n\n"
  64. "You do not typically work with SceneObjects themselves. The SceneObject provides a reference "
  65. "within the game world (the scene), but does not render to the client on its own. The "
  66. "same is true of collision detection beyond that of the bounding box. Instead you "
  67. "use one of the many classes that derrive from SceneObject, such as TSStatic.\n\n"
  68. "@section SceneObject_Hiding Difference Between setHidden() and isRenderEnabled\n\n"
  69. "When it comes time to decide if a SceneObject should render or not, there are two "
  70. "methods that can stop the SceneObject from rendering at all. You need to be aware of "
  71. "the differences between these two methods as they impact how the SceneObject is networked "
  72. "from the server to the client.\n\n"
  73. "The first method of manually controlling if a SceneObject is rendered is through its "
  74. "SceneObject::isRenderEnabled property. When set to false the SceneObject is considered invisible but "
  75. "still present within the scene. This means it still takes part in collisions and continues "
  76. "to be networked.\n\n"
  77. "The second method is using the setHidden() method. This will actually remove a SceneObject "
  78. "from the scene and it will no longer be networked from the server to the cleint. Any client-side "
  79. "ghost of the object will be deleted as the server no longer considers the object to be in scope.\n\n"
  80. "@ingroup gameObjects\n"
  81. );
  82. #ifdef TORQUE_TOOLS
  83. extern bool gEditingMission;
  84. #endif
  85. Signal< void( SceneObject* ) > SceneObject::smSceneObjectAdd;
  86. Signal< void( SceneObject* ) > SceneObject::smSceneObjectRemove;
  87. //-----------------------------------------------------------------------------
  88. SceneObject::SceneObject()
  89. {
  90. mContainer = 0;
  91. mTypeMask = DefaultObjectType;
  92. mCollisionCount = 0;
  93. mGlobalBounds = false;
  94. mObjScale.set(1,1,1);
  95. mObjToWorld.identity();
  96. mWorldToObj.identity();
  97. mObjBox = Box3F(Point3F(0, 0, 0), Point3F(0, 0, 0));
  98. mWorldBox = Box3F(Point3F(0, 0, 0), Point3F(0, 0, 0));
  99. mWorldSphere = SphereF(Point3F(0, 0, 0), 0);
  100. mRenderObjToWorld.identity();
  101. mRenderWorldToObj.identity();
  102. mRenderWorldBox = Box3F(Point3F(0, 0, 0), Point3F(0, 0, 0));
  103. mRenderWorldSphere = SphereF(Point3F(0, 0, 0), 0);
  104. mContainerSeqKey = 0;
  105. mBinRefHead = NULL;
  106. mSceneManager = NULL;
  107. mNumCurrZones = 0;
  108. mZoneRefHead = NULL;
  109. mZoneRefDirty = false;
  110. mBinMinX = 0xFFFFFFFF;
  111. mBinMaxX = 0xFFFFFFFF;
  112. mBinMinY = 0xFFFFFFFF;
  113. mBinMaxY = 0xFFFFFFFF;
  114. mLightPlugin = NULL;
  115. mMount.object = NULL;
  116. mMount.link = NULL;
  117. mMount.list = NULL;
  118. mMount.node = -1;
  119. mMount.xfm = MatrixF::Identity;
  120. mMountPID = NULL;
  121. mSceneObjectLinks = NULL;
  122. mObjectFlags.set( RenderEnabledFlag | SelectionEnabledFlag );
  123. // PATHSHAPE
  124. // init the scenegraph relationships to indicate no parent, no children, and no siblings
  125. mGraph.parent = NULL;
  126. mGraph.nextSibling = NULL;
  127. mGraph.firstChild = NULL;
  128. mGraph.objToParent.identity();
  129. // PATHSHAPE END
  130. mIsScopeAlways = false;
  131. mAccuTex = NULL;
  132. mSelectionFlags = 0;
  133. mPathfindingIgnore = false;
  134. mGameObjectAssetId = StringTable->insert("");
  135. mDirtyGameObject = false;
  136. }
  137. //-----------------------------------------------------------------------------
  138. SceneObject::~SceneObject()
  139. {
  140. AssertFatal( mZoneRefHead == NULL && mBinRefHead == NULL,
  141. "SceneObject::~SceneObject - Object still linked in reference lists!");
  142. AssertFatal( !mSceneObjectLinks,
  143. "SceneObject::~SceneObject() - object is still linked to SceneTrackers" );
  144. mAccuTex = NULL;
  145. unlink();
  146. }
  147. //-----------------------------------------------------------------------------
  148. bool SceneObject::castRayRendered(const Point3F &start, const Point3F &end, RayInfo *info)
  149. {
  150. // By default, all ray checking against the rendered mesh will be passed
  151. // on to the collision mesh. This saves having to define both methods
  152. // for simple objects.
  153. return castRay( start, end, info );
  154. }
  155. //-----------------------------------------------------------------------------
  156. bool SceneObject::containsPoint( const Point3F& point )
  157. {
  158. // If it's not in the AABB, then it can't be in the OBB either,
  159. // so early out.
  160. if( !mWorldBox.isContained( point ) )
  161. return false;
  162. // Transform point into object space and test it against
  163. // our object space bounding box.
  164. Point3F objPoint( 0, 0, 0 );
  165. getWorldTransform().mulP( point, &objPoint );
  166. objPoint.convolveInverse( getScale() );
  167. return ( mObjBox.isContained( objPoint ) );
  168. }
  169. //-----------------------------------------------------------------------------
  170. bool SceneObject::collideBox(const Point3F &start, const Point3F &end, RayInfo *info)
  171. {
  172. const F32 * pStart = (const F32*)start;
  173. const F32 * pEnd = (const F32*)end;
  174. const F32 * pMin = (const F32*)mObjBox.minExtents;
  175. const F32 * pMax = (const F32*)mObjBox.maxExtents;
  176. F32 maxStartTime = -1;
  177. F32 minEndTime = 1;
  178. F32 startTime;
  179. F32 endTime;
  180. // used for getting normal
  181. U32 hitIndex = 0xFFFFFFFF;
  182. U32 side;
  183. // walk the axis
  184. for(U32 i = 0; i < 3; i++)
  185. {
  186. //
  187. if(pStart[i] < pEnd[i])
  188. {
  189. if(pEnd[i] < pMin[i] || pStart[i] > pMax[i])
  190. return(false);
  191. F32 dist = pEnd[i] - pStart[i];
  192. startTime = (pStart[i] < pMin[i]) ? (pMin[i] - pStart[i]) / dist : -1;
  193. endTime = (pEnd[i] > pMax[i]) ? (pMax[i] - pStart[i]) / dist : 1;
  194. side = 1;
  195. }
  196. else
  197. {
  198. if(pStart[i] < pMin[i] || pEnd[i] > pMax[i])
  199. return(false);
  200. F32 dist = pStart[i] - pEnd[i];
  201. startTime = (pStart[i] > pMax[i]) ? (pStart[i] - pMax[i]) / dist : -1;
  202. endTime = (pEnd[i] < pMin[i]) ? (pStart[i] - pMin[i]) / dist : 1;
  203. side = 0;
  204. }
  205. //
  206. if(startTime > maxStartTime)
  207. {
  208. maxStartTime = startTime;
  209. hitIndex = i * 2 + side;
  210. }
  211. if(endTime < minEndTime)
  212. minEndTime = endTime;
  213. if(minEndTime < maxStartTime)
  214. return(false);
  215. }
  216. // fail if inside
  217. if(maxStartTime < 0.f)
  218. return(false);
  219. //
  220. static Point3F boxNormals[] = {
  221. Point3F( 1, 0, 0),
  222. Point3F(-1, 0, 0),
  223. Point3F( 0, 1, 0),
  224. Point3F( 0,-1, 0),
  225. Point3F( 0, 0, 1),
  226. Point3F( 0, 0,-1),
  227. };
  228. //
  229. AssertFatal(hitIndex != 0xFFFFFFFF, "SceneObject::collideBox");
  230. info->t = maxStartTime;
  231. info->object = this;
  232. mObjToWorld.mulV(boxNormals[hitIndex], &info->normal);
  233. info->material = 0;
  234. return(true);
  235. }
  236. //-----------------------------------------------------------------------------
  237. void SceneObject::disableCollision()
  238. {
  239. for (SceneObject* ptr = getMountList(); ptr; ptr = ptr->getMountLink())
  240. ptr->disableCollision();
  241. mCollisionCount++;
  242. AssertFatal(mCollisionCount < 50, "SceneObject::disableCollision called 50 times on the same object. Is this inside a circular loop?" );
  243. }
  244. //-----------------------------------------------------------------------------
  245. void SceneObject::enableCollision()
  246. {
  247. for (SceneObject* ptr = getMountList(); ptr; ptr = ptr->getMountLink())
  248. ptr->enableCollision();
  249. if (mCollisionCount)
  250. --mCollisionCount;
  251. }
  252. //-----------------------------------------------------------------------------
  253. bool SceneObject::onAdd()
  254. {
  255. if ( !Parent::onAdd() )
  256. return false;
  257. mIsScopeAlways = mNetFlags.test( ScopeAlways );
  258. mWorldToObj = mObjToWorld;
  259. mWorldToObj.affineInverse();
  260. resetWorldBox();
  261. setRenderTransform(mObjToWorld);
  262. resolveMountPID();
  263. smSceneObjectAdd.trigger(this);
  264. return true;
  265. }
  266. //-----------------------------------------------------------------------------
  267. void SceneObject::onRemove()
  268. {
  269. smSceneObjectRemove.trigger(this);
  270. unmount();
  271. plUnlink();
  272. Parent::onRemove();
  273. // PATHSHAPE
  274. if ( getParent() != NULL) attachToParent( NULL);
  275. // PATHSHAPE END
  276. }
  277. //-----------------------------------------------------------------------------
  278. void SceneObject::addToScene()
  279. {
  280. if( mSceneManager )
  281. return;
  282. if( isClientObject() )
  283. gClientSceneGraph->addObjectToScene( this );
  284. else
  285. gServerSceneGraph->addObjectToScene( this );
  286. }
  287. //-----------------------------------------------------------------------------
  288. void SceneObject::removeFromScene()
  289. {
  290. if( !mSceneManager )
  291. return;
  292. mSceneManager->removeObjectFromScene( this );
  293. }
  294. //-----------------------------------------------------------------------------
  295. void SceneObject::onDeleteNotify( SimObject *obj )
  296. {
  297. // We are comparing memory addresses so even if obj really is not a
  298. // ProcessObject this cast shouldn't break anything.
  299. if ( obj == mAfterObject )
  300. mAfterObject = NULL;
  301. if ( obj == mMount.object )
  302. unmount();
  303. Parent::onDeleteNotify( obj );
  304. }
  305. //-----------------------------------------------------------------------------
  306. void SceneObject::inspectPostApply()
  307. {
  308. if( isServerObject() )
  309. setMaskBits( MountedMask );
  310. Parent::inspectPostApply();
  311. }
  312. //-----------------------------------------------------------------------------
  313. void SceneObject::setGlobalBounds()
  314. {
  315. mGlobalBounds = true;
  316. mObjBox.minExtents.set( -1e10, -1e10, -1e10 );
  317. mObjBox.maxExtents.set( 1e10, 1e10, 1e10 );
  318. if( mSceneManager )
  319. mSceneManager->notifyObjectDirty( this );
  320. }
  321. //-----------------------------------------------------------------------------
  322. void SceneObject::setTransform( const MatrixF& mat )
  323. {
  324. // This test is a bit expensive so turn it off in release.
  325. #ifdef TORQUE_DEBUG
  326. //AssertFatal( mat.isAffine(), "SceneObject::setTransform() - Bad transform (non affine)!" );
  327. #endif
  328. PROFILE_SCOPE( SceneObject_setTransform );
  329. // PATHSHAPE
  330. PerformUpdatesForChildren(mat);
  331. // PATHSHAPE END
  332. // Update the transforms.
  333. mObjToWorld = mWorldToObj = mat;
  334. mWorldToObj.affineInverse();
  335. // Update the world-space AABB.
  336. resetWorldBox();
  337. // If we're in a SceneManager, sync our scene state.
  338. if( mSceneManager != NULL )
  339. mSceneManager->notifyObjectDirty( this );
  340. setRenderTransform( mat );
  341. }
  342. //-----------------------------------------------------------------------------
  343. void SceneObject::setScale( const VectorF &scale )
  344. {
  345. AssertFatal( !mIsNaN( scale ), "SceneObject::setScale() - The scale is NaN!" );
  346. // Avoid unnecessary scaling operations.
  347. if ( mObjScale.equal( scale ) )
  348. return;
  349. mObjScale = scale;
  350. setTransform(MatrixF(mObjToWorld));
  351. // Make sure that any subclasses of me get a chance to react to the
  352. // scale being changed.
  353. onScaleChanged();
  354. setMaskBits( ScaleMask );
  355. }
  356. void SceneObject::setForwardVector(VectorF newForward, VectorF upVector)
  357. {
  358. MatrixF mat = getTransform();
  359. VectorF up(0.0f, 0.0f, 1.0f);
  360. VectorF axisX;
  361. VectorF axisY = newForward;
  362. VectorF axisZ;
  363. if (upVector != VectorF::Zero)
  364. up = upVector;
  365. // Validate and normalize input:
  366. F32 lenSq;
  367. lenSq = axisY.lenSquared();
  368. if (lenSq < 0.000001f)
  369. {
  370. axisY.set(0.0f, 1.0f, 0.0f);
  371. Con::errorf("SceneObject::setForwardVector() - degenerate forward vector");
  372. }
  373. else
  374. {
  375. axisY /= mSqrt(lenSq);
  376. }
  377. lenSq = up.lenSquared();
  378. if (lenSq < 0.000001f)
  379. {
  380. up.set(0.0f, 0.0f, 1.0f);
  381. Con::errorf("SceneObject::setForwardVector() - degenerate up vector - too small");
  382. }
  383. else
  384. {
  385. up /= mSqrt(lenSq);
  386. }
  387. if (fabsf(mDot(up, axisY)) > 0.9999f)
  388. {
  389. Con::errorf("SceneObject::setForwardVector() - degenerate up vector - same as forward");
  390. // I haven't really tested this, but i think it generates something which should be not parallel to the previous vector:
  391. F32 tmp = up.x;
  392. up.x = -up.y;
  393. up.y = up.z;
  394. up.z = tmp;
  395. }
  396. // construct the remaining axes:
  397. mCross(axisY, up, &axisX);
  398. mCross(axisX, axisY, &axisZ);
  399. mat.setColumn(0, axisX);
  400. mat.setColumn(1, axisY);
  401. mat.setColumn(2, axisZ);
  402. setTransform(mat);
  403. }
  404. //-----------------------------------------------------------------------------
  405. void SceneObject::resetWorldBox()
  406. {
  407. AssertFatal(mObjBox.isValidBox(), "SceneObject::resetWorldBox - Bad object box!");
  408. mWorldBox = mObjBox;
  409. mWorldBox.minExtents.convolve(mObjScale);
  410. mWorldBox.maxExtents.convolve(mObjScale);
  411. mObjToWorld.mul(mWorldBox);
  412. AssertFatal(mWorldBox.isValidBox(), "SceneObject::resetWorldBox - Bad world box!");
  413. // Create mWorldSphere from mWorldBox
  414. mWorldBox.getCenter(&mWorldSphere.center);
  415. mWorldSphere.radius = (mWorldBox.maxExtents - mWorldSphere.center).len();
  416. // Update tracker links.
  417. for( SceneObjectLink* link = mSceneObjectLinks; link != NULL;
  418. link = link->getNextLink() )
  419. link->update();
  420. }
  421. //-----------------------------------------------------------------------------
  422. void SceneObject::resetObjectBox()
  423. {
  424. AssertFatal( mWorldBox.isValidBox(), "SceneObject::resetObjectBox - Bad world box!" );
  425. mObjBox = mWorldBox;
  426. mWorldToObj.mul( mObjBox );
  427. Point3F objScale( mObjScale );
  428. objScale.setMax( Point3F( (F32)POINT_EPSILON, (F32)POINT_EPSILON, (F32)POINT_EPSILON ) );
  429. mObjBox.minExtents.convolveInverse( objScale );
  430. mObjBox.maxExtents.convolveInverse( objScale );
  431. AssertFatal( mObjBox.isValidBox(), "SceneObject::resetObjectBox - Bad object box!" );
  432. // Update the mWorldSphere from mWorldBox
  433. mWorldBox.getCenter( &mWorldSphere.center );
  434. mWorldSphere.radius = ( mWorldBox.maxExtents - mWorldSphere.center ).len();
  435. // Update scene managers.
  436. for( SceneObjectLink* link = mSceneObjectLinks; link != NULL;
  437. link = link->getNextLink() )
  438. link->update();
  439. }
  440. //-----------------------------------------------------------------------------
  441. void SceneObject::setRenderTransform(const MatrixF& mat)
  442. {
  443. PROFILE_START(SceneObj_setRenderTransform);
  444. mRenderObjToWorld = mRenderWorldToObj = mat;
  445. mRenderWorldToObj.affineInverse();
  446. AssertFatal(mObjBox.isValidBox(), "Bad object box!");
  447. resetRenderWorldBox();
  448. PROFILE_END();
  449. }
  450. //-----------------------------------------------------------------------------
  451. void SceneObject::resetRenderWorldBox()
  452. {
  453. AssertFatal( mObjBox.isValidBox(), "Bad object box!" );
  454. mRenderWorldBox = mObjBox;
  455. mRenderWorldBox.minExtents.convolve( mObjScale );
  456. mRenderWorldBox.maxExtents.convolve( mObjScale );
  457. mRenderObjToWorld.mul( mRenderWorldBox );
  458. AssertFatal( mRenderWorldBox.isValidBox(), "Bad world box!" );
  459. // Create mRenderWorldSphere from mRenderWorldBox.
  460. mRenderWorldBox.getCenter( &mRenderWorldSphere.center );
  461. mRenderWorldSphere.radius = ( mRenderWorldBox.maxExtents - mRenderWorldSphere.center ).len();
  462. }
  463. //-----------------------------------------------------------------------------
  464. void SceneObject::setHidden( bool hidden )
  465. {
  466. if( hidden != isHidden() )
  467. {
  468. // Add/remove the object from the scene. Removing it
  469. // will also cause the NetObject to go out of scope since
  470. // the container query will not find it anymore. However,
  471. // ScopeAlways objects need to be treated separately as we
  472. // do next.
  473. if( !hidden )
  474. addToScene();
  475. else
  476. removeFromScene();
  477. // ScopeAlways objects stay in scope no matter what, i.e. even
  478. // if they aren't in the scene query anymore. So, to force ghosts
  479. // to go away, we need to clear ScopeAlways while we are hidden.
  480. if( hidden && mIsScopeAlways )
  481. clearScopeAlways();
  482. else if( !hidden && mIsScopeAlways )
  483. setScopeAlways();
  484. Parent::setHidden( hidden );
  485. }
  486. }
  487. //-----------------------------------------------------------------------------
  488. void SceneObject::initPersistFields()
  489. {
  490. addGroup("GameObject");
  491. addField("GameObject", TypeGameObjectAssetPtr, Offset(mGameObjectAsset, SceneObject), "The asset Id used for the game object this entity is based on.");
  492. addField("dirtyGameObject", TypeBool, Offset(mDirtyGameObject, SceneObject), "If this entity is a GameObject, it flags if this instance delinates from the template.",
  493. AbstractClassRep::FieldFlags::FIELD_HideInInspectors);
  494. endGroup("GameObject");
  495. addGroup( "Transform" );
  496. addProtectedField( "position", TypeMatrixPosition, Offset( mObjToWorld, SceneObject ),
  497. &_setFieldPosition, &defaultProtectedGetFn,
  498. "Object world position." );
  499. addProtectedField( "rotation", TypeMatrixRotation, Offset( mObjToWorld, SceneObject ),
  500. &_setFieldRotation, &defaultProtectedGetFn,
  501. "Object world orientation." );
  502. addProtectedField( "scale", TypePoint3F, Offset( mObjScale, SceneObject ),
  503. &_setFieldScale, &defaultProtectedGetFn,
  504. "Object world scale." );
  505. endGroup( "Transform" );
  506. addGroup( "Editing" );
  507. addProtectedField( "isRenderEnabled", TypeBool, Offset( mObjectFlags, SceneObject ),
  508. &_setRenderEnabled, &_getRenderEnabled,
  509. "Controls client-side rendering of the object.\n"
  510. "@see isRenderable()\n" );
  511. addProtectedField( "isSelectionEnabled", TypeBool, Offset( mObjectFlags, SceneObject ),
  512. &_setSelectionEnabled, &_getSelectionEnabled,
  513. "Determines if the object may be selected from wihin the Tools.\n"
  514. "@see isSelectable()\n" );
  515. endGroup( "Editing" );
  516. addGroup( "Mounting" );
  517. addProtectedField( "mountPID", TypePID, Offset( mMountPID, SceneObject ), &_setMountPID, &defaultProtectedGetFn,
  518. "@brief PersistentID of object we are mounted to.\n\n"
  519. "Unlike the SimObjectID that is determined at run time, the PersistentID of an object is saved with the level/mission and "
  520. "may be used to form a link between objects." );
  521. addField( "mountNode", TypeS32, Offset( mMount.node, SceneObject ), "Node we are mounted to." );
  522. addField( "mountPos", TypeMatrixPosition, Offset( mMount.xfm, SceneObject ), "Position we are mounted at ( object space of our mount object )." );
  523. addField( "mountRot", TypeMatrixRotation, Offset( mMount.xfm, SceneObject ), "Rotation we are mounted at ( object space of our mount object )." );
  524. endGroup( "Mounting" );
  525. Parent::initPersistFields();
  526. }
  527. bool SceneObject::_setGameObject(void* object, const char* index, const char* data)
  528. {
  529. // Sanity!
  530. AssertFatal(data != NULL, "Cannot use a NULL asset Id.");
  531. return true; //rbI->setMeshAsset(data);
  532. }
  533. //-----------------------------------------------------------------------------
  534. bool SceneObject::_setFieldPosition( void *object, const char *index, const char *data )
  535. {
  536. SceneObject* so = static_cast<SceneObject*>( object );
  537. if ( so )
  538. {
  539. MatrixF txfm( so->getTransform() );
  540. Con::setData( TypeMatrixPosition, &txfm, 0, 1, &data );
  541. so->setTransform( txfm );
  542. }
  543. return false;
  544. }
  545. //-----------------------------------------------------------------------------
  546. bool SceneObject::_setFieldRotation( void *object, const char *index, const char *data )
  547. {
  548. SceneObject* so = static_cast<SceneObject*>( object );
  549. if ( so )
  550. {
  551. MatrixF txfm( so->getTransform() );
  552. Con::setData( TypeMatrixRotation, &txfm, 0, 1, &data );
  553. so->setTransform( txfm );
  554. }
  555. return false;
  556. }
  557. //-----------------------------------------------------------------------------
  558. bool SceneObject::_setFieldScale( void *object, const char *index, const char *data )
  559. {
  560. SceneObject* so = static_cast<SceneObject*>( object );
  561. if ( so )
  562. {
  563. Point3F scale;
  564. Con::setData( TypePoint3F, &scale, 0, 1, &data );
  565. so->setScale( scale );
  566. }
  567. return false;
  568. }
  569. //-----------------------------------------------------------------------------
  570. bool SceneObject::writeField( StringTableEntry fieldName, const char* value )
  571. {
  572. if( !Parent::writeField( fieldName, value ) )
  573. return false;
  574. static StringTableEntry sIsRenderEnabled = StringTable->insert( "isRenderEnabled" );
  575. static StringTableEntry sIsSelectionEnabled = StringTable->insert( "isSelectionEnabled" );
  576. static StringTableEntry sMountNode = StringTable->insert( "mountNode" );
  577. static StringTableEntry sMountPos = StringTable->insert( "mountPos" );
  578. static StringTableEntry sMountRot = StringTable->insert( "mountRot" );
  579. // Don't write flag fields if they are at their default values.
  580. if( fieldName == sIsRenderEnabled && dAtob( value ) )
  581. return false;
  582. else if( fieldName == sIsSelectionEnabled && dAtob( value ) )
  583. return false;
  584. else if ( mMountPID == NULL && ( fieldName == sMountNode ||
  585. fieldName == sMountPos ||
  586. fieldName == sMountRot ) )
  587. {
  588. return false;
  589. }
  590. return true;
  591. }
  592. //-----------------------------------------------------------------------------
  593. static void scopeCallback( SceneObject* obj, void* conPtr )
  594. {
  595. NetConnection* ptr = reinterpret_cast< NetConnection* >( conPtr );
  596. if( obj->isScopeable() )
  597. ptr->objectInScope(obj);
  598. }
  599. void SceneObject::onCameraScopeQuery( NetConnection* connection, CameraScopeQuery* query )
  600. {
  601. SceneManager* sceneManager = getSceneManager();
  602. GameConnection* conn = dynamic_cast<GameConnection*> (connection);
  603. if (conn && (query->visibleDistance = conn->getVisibleGhostDistance()) == 0.0f)
  604. if ((query->visibleDistance = sceneManager->getVisibleGhostDistance()) == 0.0f)
  605. query->visibleDistance = sceneManager->getVisibleDistance();
  606. // Object itself is in scope.
  607. if( this->isScopeable() )
  608. connection->objectInScope( this );
  609. // If we're mounted to something, that object is in scope too.
  610. if( isMounted() )
  611. connection->objectInScope( mMount.object );
  612. // If we're added to a scene graph, let the graph do the scene scoping.
  613. // Otherwise just put everything in the server container in scope.
  614. if( getSceneManager() )
  615. getSceneManager()->scopeScene( query, connection );
  616. else
  617. gServerContainer.findObjects( 0xFFFFFFFF, scopeCallback, connection );
  618. }
  619. //-----------------------------------------------------------------------------
  620. bool SceneObject::isRenderEnabled() const
  621. {
  622. #ifdef TORQUE_TOOLS
  623. if (gEditingMission)
  624. {
  625. AbstractClassRep *classRep = getClassRep();
  626. return (mObjectFlags.test(RenderEnabledFlag) && classRep->isRenderEnabled());
  627. }
  628. #endif
  629. return (mObjectFlags.test(RenderEnabledFlag));
  630. }
  631. //-----------------------------------------------------------------------------
  632. void SceneObject::setRenderEnabled( bool value )
  633. {
  634. if( value )
  635. mObjectFlags.set( RenderEnabledFlag );
  636. else
  637. mObjectFlags.clear( RenderEnabledFlag );
  638. setMaskBits( FlagMask );
  639. }
  640. //-----------------------------------------------------------------------------
  641. const char* SceneObject::_getRenderEnabled( void* object, const char* data )
  642. {
  643. SceneObject* obj = reinterpret_cast< SceneObject* >( object );
  644. if( obj->mObjectFlags.test( RenderEnabledFlag ) )
  645. return "1";
  646. else
  647. return "0";
  648. }
  649. //-----------------------------------------------------------------------------
  650. bool SceneObject::_setRenderEnabled( void *object, const char *index, const char *data )
  651. {
  652. SceneObject* obj = reinterpret_cast< SceneObject* >( object );
  653. obj->setRenderEnabled( dAtob( data ) );
  654. return false;
  655. }
  656. //-----------------------------------------------------------------------------
  657. bool SceneObject::isSelectionEnabled() const
  658. {
  659. AbstractClassRep *classRep = getClassRep();
  660. return ( mObjectFlags.test( SelectionEnabledFlag ) && classRep->isSelectionEnabled() );
  661. }
  662. //-----------------------------------------------------------------------------
  663. void SceneObject::setSelectionEnabled( bool value )
  664. {
  665. if( value )
  666. mObjectFlags.set( SelectionEnabledFlag );
  667. else
  668. mObjectFlags.clear( SelectionEnabledFlag );
  669. // Not synchronized on network so don't set dirty bit.
  670. }
  671. //-----------------------------------------------------------------------------
  672. const char* SceneObject::_getSelectionEnabled( void* object, const char* data )
  673. {
  674. SceneObject* obj = reinterpret_cast< SceneObject* >( object );
  675. if( obj->mObjectFlags.test( SelectionEnabledFlag ) )
  676. return "true";
  677. else
  678. return "false";
  679. }
  680. //-----------------------------------------------------------------------------
  681. bool SceneObject::_setSelectionEnabled( void *object, const char *index, const char *data )
  682. {
  683. SceneObject* obj = reinterpret_cast< SceneObject* >( object );
  684. obj->setSelectionEnabled( dAtob( data ) );
  685. return false;
  686. }
  687. //--------------------------------------------------------------------------
  688. U32 SceneObject::packUpdate( NetConnection* conn, U32 mask, BitStream* stream )
  689. {
  690. U32 retMask = Parent::packUpdate( conn, mask, stream );
  691. if ( stream->writeFlag( mask & FlagMask ) )
  692. stream->writeRangedU32( (U32)mObjectFlags, 0, getObjectFlagMax() );
  693. // PATHSHAPE
  694. //Begin attachment
  695. retMask = 0; //retry mask
  696. if (stream->writeFlag(getParent() != NULL)) {
  697. stream->writeAffineTransform(mGraph.objToParent);
  698. }
  699. if (stream->writeFlag(mask & MountedMask))
  700. {
  701. // Check to see if we need to write an object ID
  702. if (stream->writeFlag(mGraph.parent)) {
  703. S32 t = conn->getGhostIndex(mGraph.parent);
  704. // Check to see if we can actually ghost this...
  705. if (t == -1) {
  706. // Cant, try again later
  707. retMask |= MountedMask;
  708. stream->writeFlag(false);
  709. }
  710. else {
  711. // Can, write it.
  712. stream->writeFlag(true);
  713. stream->writeRangedU32(U32(t), 0, NetConnection::MaxGhostCount);
  714. stream->writeAffineTransform(mGraph.objToParent);
  715. //Con::errorf("%d: sent mounted on %d", getId(), mGraph.parent->getId());
  716. }
  717. }
  718. }
  719. // End of Attachment
  720. // PATHSHAPE END
  721. if ( mask & MountedMask )
  722. {
  723. if ( mMount.object )
  724. {
  725. S32 gIndex = conn->getGhostIndex( mMount.object );
  726. if ( stream->writeFlag( gIndex != -1 ) )
  727. {
  728. stream->writeFlag( true );
  729. stream->writeInt( gIndex, NetConnection::GhostIdBitSize );
  730. if ( stream->writeFlag( mMount.node != -1 ) )
  731. stream->writeInt( mMount.node, NumMountPointBits );
  732. mathWrite( *stream, mMount.xfm );
  733. }
  734. else
  735. // Will have to try again later
  736. retMask |= MountedMask;
  737. }
  738. else
  739. // Unmount if this isn't the initial packet
  740. if ( stream->writeFlag( !(mask & InitialUpdateMask) ) )
  741. stream->writeFlag( false );
  742. }
  743. else
  744. stream->writeFlag( false );
  745. return retMask;
  746. }
  747. //-----------------------------------------------------------------------------
  748. void SceneObject::unpackUpdate( NetConnection* conn, BitStream* stream )
  749. {
  750. Parent::unpackUpdate( conn, stream );
  751. // FlagMask
  752. if ( stream->readFlag() )
  753. mObjectFlags = stream->readRangedU32( 0, getObjectFlagMax() );
  754. // PATHSHAPE
  755. // begin of attachment
  756. if (stream->readFlag())
  757. {
  758. MatrixF m;
  759. stream->readAffineTransform(&m);
  760. mGraph.objToParent = m;
  761. }
  762. if (stream->readFlag())
  763. {
  764. // Check to see if we need to read an object ID
  765. if (stream->readFlag())
  766. {
  767. // Check to see if we can actually ghost this...
  768. if (stream->readFlag())
  769. {
  770. GameBase *newParent = static_cast<GameBase*>(conn->resolveGhost(stream->readRangedU32(0, NetConnection::MaxGhostCount)));
  771. MatrixF m;
  772. stream->readAffineTransform(&m);
  773. if (getParent() != newParent)
  774. {
  775. clearProcessAfter();
  776. processAfter(newParent);
  777. }
  778. attachToParent(newParent, &m);
  779. //Con::errorf("%d: got mounted on %d", getId(), mParentObject->getId());
  780. }
  781. }
  782. else
  783. {
  784. attachToParent(NULL);
  785. }
  786. }
  787. // End of attachment
  788. // PATHSHAPE END
  789. // MountedMask
  790. if ( stream->readFlag() )
  791. {
  792. if ( stream->readFlag() )
  793. {
  794. S32 gIndex = stream->readInt( NetConnection::GhostIdBitSize );
  795. SceneObject* obj = dynamic_cast<SceneObject*>( conn->resolveGhost( gIndex ) );
  796. S32 node = -1;
  797. if ( stream->readFlag() ) // node != -1
  798. node = stream->readInt( NumMountPointBits );
  799. MatrixF xfm;
  800. mathRead( *stream, &xfm );
  801. if ( !obj )
  802. {
  803. conn->setLastError( "Invalid packet from server." );
  804. return;
  805. }
  806. obj->mountObject( this, node, xfm );
  807. }
  808. else
  809. unmount();
  810. }
  811. }
  812. //-----------------------------------------------------------------------------
  813. void SceneObject::_updateZoningState() const
  814. {
  815. if( mZoneRefDirty )
  816. {
  817. SceneZoneSpaceManager* manager = getSceneManager()->getZoneManager();
  818. if( manager )
  819. manager->updateObject( const_cast< SceneObject* >( this ) );
  820. else
  821. mZoneRefDirty = false;
  822. }
  823. }
  824. //-----------------------------------------------------------------------------
  825. U32 SceneObject::getCurrZone( const U32 index ) const
  826. {
  827. _updateZoningState();
  828. // Not the most efficient way to do this, walking the list,
  829. // but it's an uncommon call...
  830. ZoneRef* walk = mZoneRefHead;
  831. for( U32 i = 0; i < index; ++ i )
  832. {
  833. walk = walk->nextInObj;
  834. AssertFatal( walk != NULL, "SceneObject::_getCurrZone - Too few object refs!" );
  835. }
  836. AssertFatal( walk != NULL, "SceneObject::_getCurrZone - Too few object refs!" );
  837. return walk->zone;
  838. }
  839. //-----------------------------------------------------------------------------
  840. Point3F SceneObject::getPosition() const
  841. {
  842. Point3F pos;
  843. mObjToWorld.getColumn(3, &pos);
  844. return pos;
  845. }
  846. //-----------------------------------------------------------------------------
  847. Point3F SceneObject::getRenderPosition() const
  848. {
  849. Point3F pos;
  850. mRenderObjToWorld.getColumn(3, &pos);
  851. return pos;
  852. }
  853. //-----------------------------------------------------------------------------
  854. void SceneObject::setPosition(const Point3F &pos)
  855. {
  856. AssertFatal( !mIsNaN( pos ), "SceneObject::setPosition() - The position is NaN!" );
  857. MatrixF xform = mObjToWorld;
  858. xform.setColumn(3, pos);
  859. setTransform(xform);
  860. }
  861. //-----------------------------------------------------------------------------
  862. F32 SceneObject::distanceTo(const Point3F &pnt) const
  863. {
  864. return mWorldBox.getDistanceToPoint( pnt );
  865. }
  866. //-----------------------------------------------------------------------------
  867. void SceneObject::processAfter( ProcessObject *obj )
  868. {
  869. AssertFatal( dynamic_cast<SceneObject*>( obj ), "SceneObject::processAfter - Got non-SceneObject!" );
  870. mAfterObject = (SceneObject*)obj;
  871. if ( mAfterObject->mAfterObject == this )
  872. mAfterObject->mAfterObject = NULL;
  873. getProcessList()->markDirty();
  874. }
  875. //-----------------------------------------------------------------------------
  876. void SceneObject::clearProcessAfter()
  877. {
  878. mAfterObject = NULL;
  879. }
  880. //-----------------------------------------------------------------------------
  881. void SceneObject::setProcessTick( bool t )
  882. {
  883. if ( t == mProcessTick )
  884. return;
  885. if ( mProcessTick )
  886. {
  887. if ( !getMountedObjectCount() )
  888. plUnlink(); // Only unlink if there is nothing mounted to us
  889. mProcessTick = false;
  890. }
  891. else
  892. {
  893. // Just to be sure...
  894. plUnlink();
  895. getProcessList()->addObject( this );
  896. mProcessTick = true;
  897. }
  898. }
  899. //-----------------------------------------------------------------------------
  900. ProcessList* SceneObject::getProcessList() const
  901. {
  902. if ( isClientObject() )
  903. return ClientProcessList::get();
  904. else
  905. return ServerProcessList::get();
  906. }
  907. //-------------------------------------------------------------------------
  908. bool SceneObject::isMounted()
  909. {
  910. resolveMountPID();
  911. return mMount.object != NULL;
  912. }
  913. //-----------------------------------------------------------------------------
  914. S32 SceneObject::getMountedObjectCount()
  915. {
  916. S32 count = 0;
  917. for (SceneObject* itr = mMount.list; itr; itr = itr->mMount.link)
  918. count++;
  919. return count;
  920. }
  921. //-----------------------------------------------------------------------------
  922. SceneObject* SceneObject::getMountedObject(S32 idx)
  923. {
  924. if (idx >= 0) {
  925. S32 count = 0;
  926. for (SceneObject* itr = mMount.list; itr; itr = itr->mMount.link)
  927. if (count++ == idx)
  928. return itr;
  929. }
  930. return NULL;
  931. }
  932. //-----------------------------------------------------------------------------
  933. S32 SceneObject::getMountedObjectNode(S32 idx)
  934. {
  935. if (idx >= 0) {
  936. S32 count = 0;
  937. for (SceneObject* itr = mMount.list; itr; itr = itr->mMount.link)
  938. if (count++ == idx)
  939. return itr->mMount.node;
  940. }
  941. return -1;
  942. }
  943. //-----------------------------------------------------------------------------
  944. SceneObject* SceneObject::getMountNodeObject(S32 node)
  945. {
  946. for (SceneObject* itr = mMount.list; itr; itr = itr->mMount.link)
  947. if (itr->mMount.node == node)
  948. return itr;
  949. return NULL;
  950. }
  951. //-----------------------------------------------------------------------------
  952. bool SceneObject::_setMountPID( void* object, const char* index, const char* data )
  953. {
  954. SceneObject* so = static_cast<SceneObject*>( object );
  955. if ( so )
  956. {
  957. // Unmount old object (PID reference is released even if it had been resolved yet)
  958. if ( so->mMountPID )
  959. {
  960. so->mMountPID->decRefCount();
  961. so->mMountPID = NULL;
  962. }
  963. so->unmount();
  964. // Get the new PID (new object will be mounted on demand)
  965. Con::setData( TypePID, &so->mMountPID, 0, 1, &data );
  966. if ( so->mMountPID )
  967. so->mMountPID->incRefCount(); // Prevent PID from being deleted out from under us!
  968. }
  969. return false;
  970. }
  971. void SceneObject::resolveMountPID()
  972. {
  973. if ( mMountPID && !mMount.object )
  974. {
  975. SceneObject *obj = dynamic_cast< SceneObject* >( mMountPID->getObject() );
  976. if ( obj )
  977. obj->mountObject( this, mMount.node, mMount.xfm );
  978. }
  979. }
  980. //-----------------------------------------------------------------------------
  981. void SceneObject::mountObject( SceneObject *obj, S32 node, const MatrixF &xfm )
  982. {
  983. if ( obj->mMount.object == this )
  984. {
  985. // Already mounted to this
  986. // So update our node and xfm which may have changed.
  987. obj->mMount.node = node;
  988. obj->mMount.xfm = xfm;
  989. }
  990. else
  991. {
  992. if ( obj->mMount.object )
  993. obj->unmount();
  994. obj->mMount.object = this;
  995. obj->mMount.node = node;
  996. obj->mMount.link = mMount.list;
  997. obj->mMount.xfm = xfm;
  998. mMount.list = obj;
  999. // Assign PIDs to both objects
  1000. if ( isServerObject() )
  1001. {
  1002. obj->getOrCreatePersistentId();
  1003. if ( !obj->mMountPID )
  1004. {
  1005. obj->mMountPID = getOrCreatePersistentId();
  1006. obj->mMountPID->incRefCount();
  1007. }
  1008. }
  1009. obj->onMount( this, node );
  1010. }
  1011. }
  1012. //-----------------------------------------------------------------------------
  1013. void SceneObject::unmountObject( SceneObject *obj )
  1014. {
  1015. if ( obj->mMount.object == this )
  1016. {
  1017. // Find and unlink the object
  1018. for ( SceneObject **ptr = &mMount.list; *ptr; ptr = &(*ptr)->mMount.link )
  1019. {
  1020. if ( *ptr == obj )
  1021. {
  1022. *ptr = obj->mMount.link;
  1023. break;
  1024. }
  1025. }
  1026. obj->mMount.object = NULL;
  1027. obj->mMount.link = NULL;
  1028. if( obj->mMountPID != NULL ) // Only on server.
  1029. {
  1030. obj->mMountPID->decRefCount();
  1031. obj->mMountPID = NULL;
  1032. }
  1033. obj->onUnmount( this, obj->mMount.node );
  1034. }
  1035. }
  1036. //-----------------------------------------------------------------------------
  1037. void SceneObject::unmount()
  1038. {
  1039. if (mMount.object)
  1040. mMount.object->unmountObject(this);
  1041. }
  1042. //-----------------------------------------------------------------------------
  1043. void SceneObject::onMount( SceneObject *obj, S32 node )
  1044. {
  1045. deleteNotify( obj );
  1046. if ( !isGhost() )
  1047. {
  1048. setMaskBits( MountedMask );
  1049. //onMount_callback( node );
  1050. }
  1051. }
  1052. //-----------------------------------------------------------------------------
  1053. void SceneObject::onUnmount( SceneObject *obj, S32 node )
  1054. {
  1055. clearNotify(obj);
  1056. if ( !isGhost() )
  1057. {
  1058. setMaskBits( MountedMask );
  1059. //onUnmount_callback( node );
  1060. }
  1061. }
  1062. //-----------------------------------------------------------------------------
  1063. void SceneObject::getMountTransform( S32 index, const MatrixF &xfm, MatrixF *outMat )
  1064. {
  1065. MatrixF mountTransform( xfm );
  1066. const Point3F &scale = getScale();
  1067. Point3F position = mountTransform.getPosition();
  1068. position.convolve( scale );
  1069. mountTransform.setPosition( position );
  1070. outMat->mul( mObjToWorld, mountTransform );
  1071. }
  1072. //-----------------------------------------------------------------------------
  1073. void SceneObject::getRenderMountTransform( F32 delta, S32 index, const MatrixF &xfm, MatrixF *outMat )
  1074. {
  1075. MatrixF mountTransform( xfm );
  1076. const Point3F &scale = getScale();
  1077. Point3F position = mountTransform.getPosition();
  1078. position.convolve( scale );
  1079. mountTransform.setPosition( position );
  1080. outMat->mul( mRenderObjToWorld, mountTransform );
  1081. }
  1082. //=============================================================================
  1083. // Console API.
  1084. //=============================================================================
  1085. // MARK: ---- Console API ----
  1086. //-----------------------------------------------------------------------------
  1087. DefineEngineMethod( SceneObject, getType, S32, (),,
  1088. "Return the type mask for this object.\n"
  1089. "@return The numeric type mask for the object." )
  1090. {
  1091. return object->getTypeMask();
  1092. }
  1093. //-----------------------------------------------------------------------------
  1094. DefineEngineMethod( SceneObject, mountObject, bool,
  1095. ( SceneObject* objB, S32 slot, TransformF txfm ), ( TransformF::Identity ),
  1096. "@brief Mount objB to this object at the desired slot with optional transform.\n\n"
  1097. "@param objB Object to mount onto us\n"
  1098. "@param slot Mount slot ID\n"
  1099. "@param txfm (optional) mount offset transform\n"
  1100. "@return true if successful, false if failed (objB is not valid)" )
  1101. {
  1102. if ( objB )
  1103. {
  1104. object->mountObject( objB, slot, txfm.getMatrix() );
  1105. return true;
  1106. }
  1107. return false;
  1108. }
  1109. //-----------------------------------------------------------------------------
  1110. DefineEngineMethod( SceneObject, unmountObject, bool, ( SceneObject* target ),,
  1111. "@brief Unmount an object from ourselves.\n\n"
  1112. "@param target object to unmount\n"
  1113. "@return true if successful, false if failed\n" )
  1114. {
  1115. if ( target )
  1116. {
  1117. object->unmountObject(target);
  1118. return true;
  1119. }
  1120. return false;
  1121. }
  1122. //-----------------------------------------------------------------------------
  1123. DefineEngineMethod( SceneObject, unmount, void, (),,
  1124. "Unmount us from the currently mounted object if any.\n" )
  1125. {
  1126. object->unmount();
  1127. }
  1128. //-----------------------------------------------------------------------------
  1129. DefineEngineMethod( SceneObject, isMounted, bool, (),,
  1130. "@brief Check if we are mounted to another object.\n\n"
  1131. "@return true if mounted to another object, false if not mounted." )
  1132. {
  1133. return object->isMounted();
  1134. }
  1135. //-----------------------------------------------------------------------------
  1136. DefineEngineMethod( SceneObject, getObjectMount, S32, (),,
  1137. "@brief Get the object we are mounted to.\n\n"
  1138. "@return the SimObjectID of the object we're mounted to, or 0 if not mounted." )
  1139. {
  1140. return object->isMounted()? object->getObjectMount()->getId(): 0;
  1141. }
  1142. //-----------------------------------------------------------------------------
  1143. DefineEngineMethod( SceneObject, getMountedObjectCount, S32, (),,
  1144. "Get the number of objects mounted to us.\n"
  1145. "@return the number of mounted objects." )
  1146. {
  1147. return object->getMountedObjectCount();
  1148. }
  1149. //-----------------------------------------------------------------------------
  1150. DefineEngineMethod( SceneObject, getMountedObject, S32, ( S32 slot ),,
  1151. "Get the object mounted at a particular slot.\n"
  1152. "@param slot mount slot index to query\n"
  1153. "@return ID of the object mounted in the slot, or 0 if no object." )
  1154. {
  1155. SceneObject* mobj = object->getMountedObject( slot );
  1156. return mobj? mobj->getId(): 0;
  1157. }
  1158. //-----------------------------------------------------------------------------
  1159. DefineEngineMethod( SceneObject, getMountedObjectNode, S32, ( S32 slot ),,
  1160. "@brief Get the mount node index of the object mounted at our given slot.\n\n"
  1161. "@param slot mount slot index to query\n"
  1162. "@return index of the mount node used by the object mounted in this slot." )
  1163. {
  1164. return object->getMountedObjectNode( slot );
  1165. }
  1166. //-----------------------------------------------------------------------------
  1167. DefineEngineMethod( SceneObject, getMountNodeObject, S32, ( S32 node ),,
  1168. "@brief Get the object mounted at our given node index.\n\n"
  1169. "@param node mount node index to query\n"
  1170. "@return ID of the first object mounted at the node, or 0 if none found." )
  1171. {
  1172. SceneObject* mobj = object->getMountNodeObject( node );
  1173. return mobj? mobj->getId(): 0;
  1174. }
  1175. //-----------------------------------------------------------------------------
  1176. DefineEngineMethod( SceneObject, getTransform, TransformF, (),,
  1177. "Get the object's transform.\n"
  1178. "@return the current transform of the object\n" )
  1179. {
  1180. return object->getTransform();
  1181. }
  1182. //-----------------------------------------------------------------------------
  1183. DefineEngineMethod( SceneObject, getInverseTransform, TransformF, (),,
  1184. "Get the object's inverse transform.\n"
  1185. "@return the inverse transform of the object\n" )
  1186. {
  1187. return object->getWorldTransform();
  1188. }
  1189. //-----------------------------------------------------------------------------
  1190. DefineEngineMethod( SceneObject, getPosition, Point3F, (),,
  1191. "Get the object's world position.\n"
  1192. "@return the current world position of the object\n" )
  1193. {
  1194. return object->getTransform().getPosition();
  1195. }
  1196. DefineEngineMethod( SceneObject, setPosition, void, (Point3F pos),,
  1197. "Set the object's world position.\n"
  1198. "@param pos the new world position of the object\n" )
  1199. {
  1200. return object->setPosition(pos);
  1201. }
  1202. //-----------------------------------------------------------------------------
  1203. DefineEngineMethod( SceneObject, getEulerRotation, Point3F, (),,
  1204. "Get Euler rotation of this object.\n"
  1205. "@return the orientation of the object in the form of rotations around the "
  1206. "X, Y and Z axes in degrees.\n" )
  1207. {
  1208. Point3F euler = object->getTransform().toEuler();
  1209. // Convert to degrees.
  1210. euler.x = mRadToDeg( euler.x );
  1211. euler.y = mRadToDeg( euler.y );
  1212. euler.z = mRadToDeg( euler.z );
  1213. return euler;
  1214. }
  1215. //-----------------------------------------------------------------------------
  1216. DefineEngineMethod( SceneObject, getForwardVector, VectorF, (),,
  1217. "Get the direction this object is facing.\n"
  1218. "@return a vector indicating the direction this object is facing.\n"
  1219. "@note This is the object's y axis." )
  1220. {
  1221. return object->getTransform().getForwardVector();
  1222. }
  1223. //-----------------------------------------------------------------------------
  1224. DefineEngineMethod( SceneObject, getRightVector, VectorF, (),,
  1225. "Get the right vector of the object.\n"
  1226. "@return a vector indicating the right direction of this object."
  1227. "@note This is the object's x axis." )
  1228. {
  1229. return object->getTransform().getRightVector();
  1230. }
  1231. //-----------------------------------------------------------------------------
  1232. DefineEngineMethod( SceneObject, getUpVector, VectorF, (),,
  1233. "Get the up vector of the object.\n"
  1234. "@return a vector indicating the up direction of this object."
  1235. "@note This is the object's z axis." )
  1236. {
  1237. return object->getTransform().getUpVector();
  1238. }
  1239. //-----------------------------------------------------------------------------
  1240. DefineEngineMethod( SceneObject, setTransform, void, ( TransformF txfm ),,
  1241. "Set the object's transform (orientation and position)."
  1242. "@param txfm object transform to set" )
  1243. {
  1244. // PATHSHAPE
  1245. object->PerformUpdatesForChildren(txfm.getMatrix());
  1246. // PATHSHAPE END
  1247. if ( !txfm.hasRotation() )
  1248. object->setPosition( txfm.getPosition() );
  1249. else
  1250. object->setTransform( txfm.getMatrix() );
  1251. }
  1252. //-----------------------------------------------------------------------------
  1253. DefineEngineMethod( SceneObject, getScale, Point3F, (),,
  1254. "Get the object's scale.\n"
  1255. "@return object scale as a Point3F" )
  1256. {
  1257. return object->getScale();
  1258. }
  1259. //-----------------------------------------------------------------------------
  1260. DefineEngineMethod( SceneObject, setScale, void, ( Point3F scale ),,
  1261. "Set the object's scale.\n"
  1262. "@param scale object scale to set\n" )
  1263. {
  1264. object->setScale( scale );
  1265. }
  1266. //-----------------------------------------------------------------------------
  1267. DefineEngineMethod( SceneObject, getWorldBox, Box3F, (),,
  1268. "Get the object's world bounding box.\n"
  1269. "@return six fields, two Point3Fs, containing the min and max points of the "
  1270. "worldbox." )
  1271. {
  1272. return object->getWorldBox();
  1273. }
  1274. //-----------------------------------------------------------------------------
  1275. DefineEngineMethod( SceneObject, getWorldBoxCenter, Point3F, (),,
  1276. "Get the center of the object's world bounding box.\n"
  1277. "@return the center of the world bounding box for this object." )
  1278. {
  1279. Point3F center;
  1280. object->getWorldBox().getCenter( &center );
  1281. return center;
  1282. }
  1283. //-----------------------------------------------------------------------------
  1284. DefineEngineMethod( SceneObject, getObjectBox, Box3F, (),,
  1285. "Get the object's bounding box (relative to the object's origin).\n"
  1286. "@return six fields, two Point3Fs, containing the min and max points of the "
  1287. "objectbox." )
  1288. {
  1289. return object->getObjBox();
  1290. }
  1291. //-----------------------------------------------------------------------------
  1292. DefineEngineMethod( SceneObject, isGlobalBounds, bool, (),,
  1293. "Check if this object has a global bounds set.\n"
  1294. "If global bounds are set to be true, then the object is assumed to have an "
  1295. "infinitely large bounding box for collision and rendering purposes.\n"
  1296. "@return true if the object has a global bounds." )
  1297. {
  1298. return object->isGlobalBounds();
  1299. }
  1300. DefineEngineMethod(SceneObject, setForwardVector, void, (VectorF newForward, VectorF upVector), (VectorF(0, 0, 0), VectorF(0, 0, 1)),
  1301. "Sets the forward vector of a scene object, making it face Y+ along the new vector.\n"
  1302. "@param The new forward vector to set.\n"
  1303. "@param (Optional) The up vector to use to help orient the rotation.")
  1304. {
  1305. object->setForwardVector(newForward, upVector);
  1306. }
  1307. // PATHSHAPE
  1308. // Move RenderTransform by set amount
  1309. // no longer used
  1310. void SceneObject::moveRender(const Point3F &delta)
  1311. {
  1312. Point3F pos;
  1313. const MatrixF& tmat = getRenderTransform();
  1314. tmat.getColumn(3,&pos);
  1315. AngAxisF aa(tmat);
  1316. pos += delta;
  1317. MatrixF mat;
  1318. aa.setMatrix(&mat);
  1319. mat.setColumn(3,pos);
  1320. setRenderTransform(mat);
  1321. }
  1322. void SceneObject::PerformUpdatesForChildren(MatrixF mat){
  1323. UpdateXformChange(mat);
  1324. for (U32 i=0; i < getNumChildren(); i++) {
  1325. SceneObject *o = getChild(i);
  1326. o->updateChildTransform(); //update the position of the child object
  1327. }
  1328. }
  1329. // This function will move the players based on how much it's
  1330. // parent have moved
  1331. void SceneObject::updateChildTransform(){
  1332. if (getParent() != NULL){
  1333. MatrixF one;
  1334. MatrixF two;
  1335. MatrixF three;
  1336. MatrixF four;
  1337. MatrixF mat;
  1338. one= getTransform();
  1339. two = getParent()->getTransform();
  1340. one.affineInverse();
  1341. four.mul(two,one);
  1342. mat.mul(getParent()->mLastXform,getTransform());
  1343. setTransform(mat);
  1344. }
  1345. }
  1346. // This function will move the rendered image based on how much it's
  1347. // parent have moved since the processtick.
  1348. // For some reason the player object must be updated via it's GetRenderTransform seen below,
  1349. // Other objects seem to require getTransform() only
  1350. void SceneObject::updateRenderChangesByParent(){
  1351. if (getParent() != NULL){
  1352. MatrixF renderXform = getParent()->getRenderTransform();
  1353. MatrixF xform = getParent()->getTransform();
  1354. xform.affineInverse();
  1355. MatrixF offset;
  1356. offset.mul(renderXform, xform);
  1357. MatrixF mat;
  1358. //add the "offset" caused by the parents change, and add it to it's own
  1359. // This is needed by objects that update their own render transform thru interpolate tick
  1360. // Mostly for stationary objects.
  1361. if (getClassName() == StringTable->insert("Player"))
  1362. mat.mul(offset,getRenderTransform());
  1363. else
  1364. mat.mul(offset,getTransform());
  1365. setRenderTransform(mat);
  1366. }
  1367. }
  1368. //Ramen - Move Transform by set amount
  1369. //written by Anthony Lovell
  1370. void SceneObject::move(F32 x, F32 y, F32 z)
  1371. {
  1372. Point3F delta;
  1373. delta.x = x;
  1374. delta.y = y;
  1375. delta.z = z;
  1376. move(delta);
  1377. }
  1378. // move by a specified delta in root coordinate space
  1379. void SceneObject::move(const Point3F &delta)
  1380. {
  1381. Point3F pos;
  1382. const MatrixF& tmat = getTransform();
  1383. tmat.getColumn(3,&pos);
  1384. AngAxisF aa(tmat);
  1385. pos += delta;
  1386. MatrixF mat;
  1387. aa.setMatrix(&mat);
  1388. mat.setColumn(3,pos);
  1389. setTransform(mat);
  1390. }
  1391. //written by Anthony Lovell ----------------------------------------------------------
  1392. U32
  1393. SceneObject::getNumChildren() const
  1394. {
  1395. U32 num = 0;
  1396. for (SceneObject *cur = mGraph.firstChild; cur; cur = cur->mGraph.nextSibling)
  1397. num++;
  1398. return num;
  1399. }
  1400. //written by Anthony Lovell ----------------------------------------------------------
  1401. SceneObject *
  1402. SceneObject::getChild(U32 index) const
  1403. {
  1404. SceneObject *cur = mGraph.firstChild;
  1405. for (U32 i = 0;
  1406. cur && i < index;
  1407. i++)
  1408. cur = cur->mGraph.nextSibling;
  1409. return cur;
  1410. }
  1411. void SceneObject::UpdateXformChange(const MatrixF &mat){
  1412. // This function gets the difference between the Transform and current Render transform
  1413. // Used for Interpolation matching with the child objects who rely on this data.
  1414. MatrixF oldxform = getTransform();
  1415. oldxform.affineInverse();
  1416. mLastXform.mul(mat,oldxform);
  1417. }
  1418. //----------------------------------------------------------
  1419. bool
  1420. SceneObject::attachChildAt(SceneObject *subObject, MatrixF atThisOffset, S32 node)
  1421. {
  1422. AssertFatal(subObject, "attaching a null subObject");
  1423. AssertFatal(!isChildOf(subObject), "cyclic attachChild()");
  1424. bool b = subObject->attachToParent(this, &atThisOffset, node);
  1425. if (!b)
  1426. return false;
  1427. return true;
  1428. }
  1429. //----------------------------------------------------------
  1430. bool
  1431. SceneObject::attachChildAt(SceneObject *subObject, Point3F atThisPosition)
  1432. {
  1433. AssertFatal(subObject, "attaching a null subObject");
  1434. AssertFatal(!isChildOf(subObject), "cyclic attachChild()");
  1435. bool b = subObject->attachToParent(this);
  1436. if (!b)
  1437. return false;
  1438. subObject->mGraph.objToParent.setColumn(3, atThisPosition);
  1439. // calcTransformFromLocalTransform();
  1440. return true;
  1441. }
  1442. //----------------------------------------------------------
  1443. bool
  1444. SceneObject::attachChild(SceneObject *child)
  1445. {
  1446. AssertFatal(child, "attaching a null subObject");
  1447. AssertFatal(!isChildOf(child), "cyclic attachChild()");
  1448. return child->attachToParent(this);
  1449. }
  1450. //----------------------------------------------------------
  1451. /// returns a count of children plus their children, recursively
  1452. U32
  1453. SceneObject::getNumProgeny() const
  1454. {
  1455. U32 num = 0;
  1456. for (SceneObject *cur = mGraph.firstChild; cur; cur = cur->mGraph.nextSibling) {
  1457. num += 1 + cur->getNumProgeny();
  1458. }
  1459. return num;
  1460. }
  1461. DefineEngineMethod(SceneObject, getNumChildren, S32, (),, "returns number of direct child objects")
  1462. {
  1463. return object->getNumChildren();
  1464. }
  1465. DefineEngineMethod(SceneObject, getNumProgeny, S32, (),, "returns number of recursively-nested child objects")
  1466. {
  1467. return object->getNumProgeny();
  1468. }
  1469. DefineEngineMethod(SceneObject, getChild, S32, (S32 _index), (0), "getChild(S32 index) -- returns child SceneObject at given index")
  1470. {
  1471. SceneObject *s = object->getChild(_index);
  1472. return s ? s->getId() : 0;
  1473. }
  1474. DefineEngineMethod(SceneObject, attachChildAt, bool, (SceneObject* _subObject, MatrixF _offset, S32 _node), (nullAsType<SceneObject*>(), MatrixF::Identity, 0), "(SceneObject subObject, MatrixF offset, S32 offset)"
  1475. "Mount object to this one with the specified offset expressed in our coordinate space.")
  1476. {
  1477. if (_subObject != nullptr)
  1478. {
  1479. return object->attachChildAt(_subObject, _offset, _node);
  1480. }
  1481. else
  1482. {
  1483. Con::errorf("Couldn't addObject()!");
  1484. return false;
  1485. }
  1486. }
  1487. DefineEngineMethod(SceneObject, attachToParent, bool, (const char*_sceneObject), ,"attachToParent(SceneObject)"
  1488. "specify a null or non-null parent")
  1489. {
  1490. SceneObject * t;
  1491. if(Sim::findObject(_sceneObject, t))
  1492. {
  1493. return object->attachToParent(t);
  1494. }
  1495. else
  1496. {
  1497. if ((!String::compare("0", _sceneObject))|| (!String::compare("", _sceneObject)))
  1498. return object->attachToParent(NULL);
  1499. else
  1500. {
  1501. Con::errorf("Couldn't setParent()!");
  1502. return false;
  1503. }
  1504. }
  1505. }
  1506. DefineEngineMethod(SceneObject, getParent, S32, (),, "returns ID of parent SceneObject")
  1507. {
  1508. SceneObject *p = object->getParent();
  1509. return p ? p->getId() : -1;
  1510. }
  1511. DefineEngineMethod(SceneObject, attachChild, bool, (const char*_subObject),, "(SceneObject subObject)"
  1512. "attach an object to this one, preserving its present transform.")
  1513. {
  1514. SceneObject * t;
  1515. MatrixF m;
  1516. if(Sim::findObject(_subObject, t))
  1517. return object->attachChild(t);
  1518. Con::errorf("Couldn't addObject()!");
  1519. return false;
  1520. }
  1521. bool SceneObject::isChildOf(SceneObject *so)
  1522. {
  1523. SceneObject *p = mGraph.parent;
  1524. if (p) {
  1525. if (p == so)
  1526. return true;
  1527. else
  1528. return p->isChildOf(so);
  1529. } else
  1530. return false;
  1531. }
  1532. bool SceneObject::attachToParent(SceneObject *newParent, MatrixF *atThisOffset/* = NULL */, S32 node )
  1533. {
  1534. SceneObject *oldParent = mGraph.parent;
  1535. if (oldParent == newParent)
  1536. return true;
  1537. // cycles in the scene hierarchy are forbidden!
  1538. // that is: a SceneObject cannot be a child of its progeny
  1539. if (newParent && newParent->isChildOf(this))
  1540. return false;
  1541. mGraph.parent = newParent;
  1542. if (oldParent) {
  1543. clearNotify(oldParent);
  1544. // remove this SceneObject from the list of children of oldParent
  1545. SceneObject *cur = oldParent->mGraph.firstChild;
  1546. if (cur == this) { // if we are the first child, this is easy
  1547. oldParent->mGraph.firstChild = mGraph.nextSibling;
  1548. } else {
  1549. while (cur->mGraph.nextSibling != this) {
  1550. cur = cur->mGraph.nextSibling;
  1551. // ASSERT cur != NULL;
  1552. }
  1553. cur->mGraph.nextSibling = mGraph.nextSibling;
  1554. }
  1555. oldParent->onLostChild(this);
  1556. }
  1557. if (newParent) {
  1558. deleteNotify(newParent); // if we are deleted, inform our parent
  1559. // add this SceneObject to the list of children of oldParent
  1560. mGraph.nextSibling = newParent->mGraph.firstChild;
  1561. newParent->mGraph.firstChild = this;
  1562. mGraph.parent = newParent;
  1563. newParent->onNewChild(this);
  1564. if (atThisOffset)
  1565. mGraph.objToParent = *atThisOffset;
  1566. } else {
  1567. mGraph.parent = NULL;
  1568. mGraph.nextSibling = NULL;
  1569. mGraph.objToParent = mObjToWorld;
  1570. }
  1571. onLostParent(oldParent);
  1572. onNewParent(newParent);
  1573. setMaskBits(MountedMask);
  1574. return true;
  1575. }
  1576. DefineEngineMethod(SceneObject, detachChild, bool, (const char*_subObject),, "SceneObject subObject")
  1577. {
  1578. SceneObject * t;
  1579. if(Sim::findObject(_subObject, t)) {
  1580. return t->attachToParent(NULL);
  1581. } else
  1582. return false;
  1583. }
  1584. // subclasses can do something with these if they care to
  1585. void SceneObject::onNewParent(SceneObject *newParent) {}
  1586. void SceneObject::onLostParent(SceneObject *oldParent){}
  1587. void SceneObject::onNewChild(SceneObject *newKid){}
  1588. void SceneObject::onLostChild(SceneObject *lostKid){}