sceneObject.cpp 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995
  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. //Disabled temporarily
  491. /*addGroup("GameObject");
  492. addField("GameObject", TypeGameObjectAssetPtr, Offset(mGameObjectAsset, SceneObject), "The asset Id used for the game object this entity is based on.");
  493. addField("dirtyGameObject", TypeBool, Offset(mDirtyGameObject, SceneObject), "If this entity is a GameObject, it flags if this instance delinates from the template.",
  494. AbstractClassRep::FieldFlags::FIELD_HideInInspectors);
  495. endGroup("GameObject");*/
  496. addGroup( "Transform" );
  497. addProtectedField( "position", TypeMatrixPosition, Offset( mObjToWorld, SceneObject ),
  498. &_setFieldPosition, &defaultProtectedGetFn,
  499. "Object world position." );
  500. addProtectedField( "rotation", TypeMatrixRotation, Offset( mObjToWorld, SceneObject ),
  501. &_setFieldRotation, &defaultProtectedGetFn,
  502. "Object world orientation." );
  503. addProtectedField( "scale", TypePoint3F, Offset( mObjScale, SceneObject ),
  504. &_setFieldScale, &defaultProtectedGetFn,
  505. "Object world scale." );
  506. endGroup( "Transform" );
  507. addGroup( "Editing" );
  508. addProtectedField( "isRenderEnabled", TypeBool, Offset( mObjectFlags, SceneObject ),
  509. &_setRenderEnabled, &_getRenderEnabled,
  510. "Controls client-side rendering of the object.\n"
  511. "@see isRenderable()\n" );
  512. addProtectedField( "isSelectionEnabled", TypeBool, Offset( mObjectFlags, SceneObject ),
  513. &_setSelectionEnabled, &_getSelectionEnabled,
  514. "Determines if the object may be selected from wihin the Tools.\n"
  515. "@see isSelectable()\n" );
  516. endGroup( "Editing" );
  517. addGroup( "Mounting" );
  518. addProtectedField( "mountPID", TypePID, Offset( mMountPID, SceneObject ), &_setMountPID, &defaultProtectedGetFn,
  519. "@brief PersistentID of object we are mounted to.\n\n"
  520. "Unlike the SimObjectID that is determined at run time, the PersistentID of an object is saved with the level/mission and "
  521. "may be used to form a link between objects." );
  522. addField( "mountNode", TypeS32, Offset( mMount.node, SceneObject ), "Node we are mounted to." );
  523. addField( "mountPos", TypeMatrixPosition, Offset( mMount.xfm, SceneObject ), "Position we are mounted at ( object space of our mount object )." );
  524. addField( "mountRot", TypeMatrixRotation, Offset( mMount.xfm, SceneObject ), "Rotation we are mounted at ( object space of our mount object )." );
  525. endGroup( "Mounting" );
  526. Parent::initPersistFields();
  527. }
  528. bool SceneObject::_setGameObject(void* object, const char* index, const char* data)
  529. {
  530. // Sanity!
  531. AssertFatal(data != NULL, "Cannot use a NULL asset Id.");
  532. return true; //rbI->setMeshAsset(data);
  533. }
  534. //-----------------------------------------------------------------------------
  535. bool SceneObject::_setFieldPosition( void *object, const char *index, const char *data )
  536. {
  537. SceneObject* so = static_cast<SceneObject*>( object );
  538. if ( so )
  539. {
  540. MatrixF txfm( so->getTransform() );
  541. Con::setData( TypeMatrixPosition, &txfm, 0, 1, &data );
  542. so->setTransform( txfm );
  543. }
  544. return false;
  545. }
  546. //-----------------------------------------------------------------------------
  547. bool SceneObject::_setFieldRotation( void *object, const char *index, const char *data )
  548. {
  549. SceneObject* so = static_cast<SceneObject*>( object );
  550. if ( so )
  551. {
  552. MatrixF txfm( so->getTransform() );
  553. Con::setData( TypeMatrixRotation, &txfm, 0, 1, &data );
  554. so->setTransform( txfm );
  555. }
  556. return false;
  557. }
  558. //-----------------------------------------------------------------------------
  559. bool SceneObject::_setFieldScale( void *object, const char *index, const char *data )
  560. {
  561. SceneObject* so = static_cast<SceneObject*>( object );
  562. if ( so )
  563. {
  564. Point3F scale;
  565. Con::setData( TypePoint3F, &scale, 0, 1, &data );
  566. so->setScale( scale );
  567. }
  568. return false;
  569. }
  570. //-----------------------------------------------------------------------------
  571. bool SceneObject::writeField( StringTableEntry fieldName, const char* value )
  572. {
  573. if( !Parent::writeField( fieldName, value ) )
  574. return false;
  575. static StringTableEntry sIsRenderEnabled = StringTable->insert( "isRenderEnabled" );
  576. static StringTableEntry sIsSelectionEnabled = StringTable->insert( "isSelectionEnabled" );
  577. static StringTableEntry sMountNode = StringTable->insert( "mountNode" );
  578. static StringTableEntry sMountPos = StringTable->insert( "mountPos" );
  579. static StringTableEntry sMountRot = StringTable->insert( "mountRot" );
  580. // Don't write flag fields if they are at their default values.
  581. if( fieldName == sIsRenderEnabled && dAtob( value ) )
  582. return false;
  583. else if( fieldName == sIsSelectionEnabled && dAtob( value ) )
  584. return false;
  585. else if ( mMountPID == NULL && ( fieldName == sMountNode ||
  586. fieldName == sMountPos ||
  587. fieldName == sMountRot ) )
  588. {
  589. return false;
  590. }
  591. return true;
  592. }
  593. //-----------------------------------------------------------------------------
  594. static void scopeCallback( SceneObject* obj, void* conPtr )
  595. {
  596. NetConnection* ptr = reinterpret_cast< NetConnection* >( conPtr );
  597. if( obj->isScopeable() )
  598. ptr->objectInScope(obj);
  599. }
  600. void SceneObject::onCameraScopeQuery( NetConnection* connection, CameraScopeQuery* query )
  601. {
  602. SceneManager* sceneManager = getSceneManager();
  603. GameConnection* conn = dynamic_cast<GameConnection*> (connection);
  604. if (conn && (query->visibleDistance = conn->getVisibleGhostDistance()) == 0.0f)
  605. if ((query->visibleDistance = sceneManager->getVisibleGhostDistance()) == 0.0f)
  606. query->visibleDistance = sceneManager->getVisibleDistance();
  607. // Object itself is in scope.
  608. if( this->isScopeable() )
  609. connection->objectInScope( this );
  610. // If we're mounted to something, that object is in scope too.
  611. if( isMounted() )
  612. connection->objectInScope( mMount.object );
  613. // If we're added to a scene graph, let the graph do the scene scoping.
  614. // Otherwise just put everything in the server container in scope.
  615. if( getSceneManager() )
  616. getSceneManager()->scopeScene( query, connection );
  617. else
  618. gServerContainer.findObjects( 0xFFFFFFFF, scopeCallback, connection );
  619. }
  620. //-----------------------------------------------------------------------------
  621. bool SceneObject::isRenderEnabled() const
  622. {
  623. #ifdef TORQUE_TOOLS
  624. if (gEditingMission)
  625. {
  626. AbstractClassRep *classRep = getClassRep();
  627. return (mObjectFlags.test(RenderEnabledFlag) && classRep->isRenderEnabled());
  628. }
  629. #endif
  630. return (mObjectFlags.test(RenderEnabledFlag));
  631. }
  632. //-----------------------------------------------------------------------------
  633. void SceneObject::setRenderEnabled( bool value )
  634. {
  635. if( value )
  636. mObjectFlags.set( RenderEnabledFlag );
  637. else
  638. mObjectFlags.clear( RenderEnabledFlag );
  639. setMaskBits( FlagMask );
  640. }
  641. //-----------------------------------------------------------------------------
  642. const char* SceneObject::_getRenderEnabled( void* object, const char* data )
  643. {
  644. SceneObject* obj = reinterpret_cast< SceneObject* >( object );
  645. if( obj->mObjectFlags.test( RenderEnabledFlag ) )
  646. return "1";
  647. else
  648. return "0";
  649. }
  650. //-----------------------------------------------------------------------------
  651. bool SceneObject::_setRenderEnabled( void *object, const char *index, const char *data )
  652. {
  653. SceneObject* obj = reinterpret_cast< SceneObject* >( object );
  654. obj->setRenderEnabled( dAtob( data ) );
  655. return false;
  656. }
  657. //-----------------------------------------------------------------------------
  658. bool SceneObject::isSelectionEnabled() const
  659. {
  660. AbstractClassRep *classRep = getClassRep();
  661. return ( mObjectFlags.test( SelectionEnabledFlag ) && classRep->isSelectionEnabled() );
  662. }
  663. //-----------------------------------------------------------------------------
  664. void SceneObject::setSelectionEnabled( bool value )
  665. {
  666. if( value )
  667. mObjectFlags.set( SelectionEnabledFlag );
  668. else
  669. mObjectFlags.clear( SelectionEnabledFlag );
  670. // Not synchronized on network so don't set dirty bit.
  671. }
  672. //-----------------------------------------------------------------------------
  673. const char* SceneObject::_getSelectionEnabled( void* object, const char* data )
  674. {
  675. SceneObject* obj = reinterpret_cast< SceneObject* >( object );
  676. if( obj->mObjectFlags.test( SelectionEnabledFlag ) )
  677. return "true";
  678. else
  679. return "false";
  680. }
  681. //-----------------------------------------------------------------------------
  682. bool SceneObject::_setSelectionEnabled( void *object, const char *index, const char *data )
  683. {
  684. SceneObject* obj = reinterpret_cast< SceneObject* >( object );
  685. obj->setSelectionEnabled( dAtob( data ) );
  686. return false;
  687. }
  688. //--------------------------------------------------------------------------
  689. U32 SceneObject::packUpdate( NetConnection* conn, U32 mask, BitStream* stream )
  690. {
  691. U32 retMask = Parent::packUpdate( conn, mask, stream );
  692. if ( stream->writeFlag( mask & FlagMask ) )
  693. stream->writeRangedU32( (U32)mObjectFlags, 0, getObjectFlagMax() );
  694. // PATHSHAPE
  695. //Begin attachment
  696. retMask = 0; //retry mask
  697. if (stream->writeFlag(getParent() != NULL)) {
  698. stream->writeAffineTransform(mGraph.objToParent);
  699. }
  700. if (stream->writeFlag(mask & MountedMask))
  701. {
  702. // Check to see if we need to write an object ID
  703. if (stream->writeFlag(mGraph.parent)) {
  704. S32 t = conn->getGhostIndex(mGraph.parent);
  705. // Check to see if we can actually ghost this...
  706. if (t == -1) {
  707. // Cant, try again later
  708. retMask |= MountedMask;
  709. stream->writeFlag(false);
  710. }
  711. else {
  712. // Can, write it.
  713. stream->writeFlag(true);
  714. stream->writeRangedU32(U32(t), 0, NetConnection::MaxGhostCount);
  715. stream->writeAffineTransform(mGraph.objToParent);
  716. //Con::errorf("%d: sent mounted on %d", getId(), mGraph.parent->getId());
  717. }
  718. }
  719. }
  720. // End of Attachment
  721. // PATHSHAPE END
  722. if ( mask & MountedMask )
  723. {
  724. if ( mMount.object )
  725. {
  726. S32 gIndex = conn->getGhostIndex( mMount.object );
  727. if ( stream->writeFlag( gIndex != -1 ) )
  728. {
  729. stream->writeFlag( true );
  730. stream->writeInt( gIndex, NetConnection::GhostIdBitSize );
  731. if ( stream->writeFlag( mMount.node != -1 ) )
  732. stream->writeInt( mMount.node, NumMountPointBits );
  733. mathWrite( *stream, mMount.xfm );
  734. }
  735. else
  736. // Will have to try again later
  737. retMask |= MountedMask;
  738. }
  739. else
  740. // Unmount if this isn't the initial packet
  741. if ( stream->writeFlag( !(mask & InitialUpdateMask) ) )
  742. stream->writeFlag( false );
  743. }
  744. else
  745. stream->writeFlag( false );
  746. return retMask;
  747. }
  748. //-----------------------------------------------------------------------------
  749. void SceneObject::unpackUpdate( NetConnection* conn, BitStream* stream )
  750. {
  751. Parent::unpackUpdate( conn, stream );
  752. // FlagMask
  753. if ( stream->readFlag() )
  754. mObjectFlags = stream->readRangedU32( 0, getObjectFlagMax() );
  755. // PATHSHAPE
  756. // begin of attachment
  757. if (stream->readFlag())
  758. {
  759. MatrixF m;
  760. stream->readAffineTransform(&m);
  761. mGraph.objToParent = m;
  762. }
  763. if (stream->readFlag())
  764. {
  765. // Check to see if we need to read an object ID
  766. if (stream->readFlag())
  767. {
  768. // Check to see if we can actually ghost this...
  769. if (stream->readFlag())
  770. {
  771. GameBase *newParent = static_cast<GameBase*>(conn->resolveGhost(stream->readRangedU32(0, NetConnection::MaxGhostCount)));
  772. MatrixF m;
  773. stream->readAffineTransform(&m);
  774. if (getParent() != newParent)
  775. {
  776. clearProcessAfter();
  777. processAfter(newParent);
  778. }
  779. attachToParent(newParent, &m);
  780. //Con::errorf("%d: got mounted on %d", getId(), mParentObject->getId());
  781. }
  782. }
  783. else
  784. {
  785. attachToParent(NULL);
  786. }
  787. }
  788. // End of attachment
  789. // PATHSHAPE END
  790. // MountedMask
  791. if ( stream->readFlag() )
  792. {
  793. if ( stream->readFlag() )
  794. {
  795. S32 gIndex = stream->readInt( NetConnection::GhostIdBitSize );
  796. SceneObject* obj = dynamic_cast<SceneObject*>( conn->resolveGhost( gIndex ) );
  797. S32 node = -1;
  798. if ( stream->readFlag() ) // node != -1
  799. node = stream->readInt( NumMountPointBits );
  800. MatrixF xfm;
  801. mathRead( *stream, &xfm );
  802. if ( !obj )
  803. {
  804. conn->setLastError( "Invalid packet from server." );
  805. return;
  806. }
  807. obj->mountObject( this, node, xfm );
  808. }
  809. else
  810. unmount();
  811. }
  812. }
  813. //-----------------------------------------------------------------------------
  814. void SceneObject::_updateZoningState() const
  815. {
  816. if( mZoneRefDirty )
  817. {
  818. SceneZoneSpaceManager* manager = getSceneManager()->getZoneManager();
  819. if( manager )
  820. manager->updateObject( const_cast< SceneObject* >( this ) );
  821. else
  822. mZoneRefDirty = false;
  823. }
  824. }
  825. //-----------------------------------------------------------------------------
  826. U32 SceneObject::getCurrZone( const U32 index ) const
  827. {
  828. _updateZoningState();
  829. // Not the most efficient way to do this, walking the list,
  830. // but it's an uncommon call...
  831. ZoneRef* walk = mZoneRefHead;
  832. for( U32 i = 0; i < index; ++ i )
  833. {
  834. walk = walk->nextInObj;
  835. AssertFatal( walk != NULL, "SceneObject::_getCurrZone - Too few object refs!" );
  836. }
  837. AssertFatal( walk != NULL, "SceneObject::_getCurrZone - Too few object refs!" );
  838. return walk->zone;
  839. }
  840. //-----------------------------------------------------------------------------
  841. Point3F SceneObject::getPosition() const
  842. {
  843. Point3F pos;
  844. mObjToWorld.getColumn(3, &pos);
  845. return pos;
  846. }
  847. //-----------------------------------------------------------------------------
  848. Point3F SceneObject::getRenderPosition() const
  849. {
  850. Point3F pos;
  851. mRenderObjToWorld.getColumn(3, &pos);
  852. return pos;
  853. }
  854. //-----------------------------------------------------------------------------
  855. void SceneObject::setPosition(const Point3F &pos)
  856. {
  857. AssertFatal( !mIsNaN( pos ), "SceneObject::setPosition() - The position is NaN!" );
  858. MatrixF xform = mObjToWorld;
  859. xform.setColumn(3, pos);
  860. setTransform(xform);
  861. }
  862. //-----------------------------------------------------------------------------
  863. F32 SceneObject::distanceTo(const Point3F &pnt) const
  864. {
  865. return mWorldBox.getDistanceToPoint( pnt );
  866. }
  867. //-----------------------------------------------------------------------------
  868. void SceneObject::processAfter( ProcessObject *obj )
  869. {
  870. AssertFatal( dynamic_cast<SceneObject*>( obj ), "SceneObject::processAfter - Got non-SceneObject!" );
  871. mAfterObject = (SceneObject*)obj;
  872. if ( mAfterObject->mAfterObject == this )
  873. mAfterObject->mAfterObject = NULL;
  874. getProcessList()->markDirty();
  875. }
  876. //-----------------------------------------------------------------------------
  877. void SceneObject::clearProcessAfter()
  878. {
  879. mAfterObject = NULL;
  880. }
  881. //-----------------------------------------------------------------------------
  882. void SceneObject::setProcessTick( bool t )
  883. {
  884. if ( t == mProcessTick )
  885. return;
  886. if ( mProcessTick )
  887. {
  888. if ( !getMountedObjectCount() )
  889. plUnlink(); // Only unlink if there is nothing mounted to us
  890. mProcessTick = false;
  891. }
  892. else
  893. {
  894. // Just to be sure...
  895. plUnlink();
  896. getProcessList()->addObject( this );
  897. mProcessTick = true;
  898. }
  899. }
  900. //-----------------------------------------------------------------------------
  901. ProcessList* SceneObject::getProcessList() const
  902. {
  903. if ( isClientObject() )
  904. return ClientProcessList::get();
  905. else
  906. return ServerProcessList::get();
  907. }
  908. //-------------------------------------------------------------------------
  909. bool SceneObject::isMounted()
  910. {
  911. resolveMountPID();
  912. return mMount.object != NULL;
  913. }
  914. //-----------------------------------------------------------------------------
  915. S32 SceneObject::getMountedObjectCount()
  916. {
  917. S32 count = 0;
  918. for (SceneObject* itr = mMount.list; itr; itr = itr->mMount.link)
  919. count++;
  920. return count;
  921. }
  922. //-----------------------------------------------------------------------------
  923. SceneObject* SceneObject::getMountedObject(S32 idx)
  924. {
  925. if (idx >= 0) {
  926. S32 count = 0;
  927. for (SceneObject* itr = mMount.list; itr; itr = itr->mMount.link)
  928. if (count++ == idx)
  929. return itr;
  930. }
  931. return NULL;
  932. }
  933. //-----------------------------------------------------------------------------
  934. S32 SceneObject::getMountedObjectNode(S32 idx)
  935. {
  936. if (idx >= 0) {
  937. S32 count = 0;
  938. for (SceneObject* itr = mMount.list; itr; itr = itr->mMount.link)
  939. if (count++ == idx)
  940. return itr->mMount.node;
  941. }
  942. return -1;
  943. }
  944. //-----------------------------------------------------------------------------
  945. SceneObject* SceneObject::getMountNodeObject(S32 node)
  946. {
  947. for (SceneObject* itr = mMount.list; itr; itr = itr->mMount.link)
  948. if (itr->mMount.node == node)
  949. return itr;
  950. return NULL;
  951. }
  952. //-----------------------------------------------------------------------------
  953. bool SceneObject::_setMountPID( void* object, const char* index, const char* data )
  954. {
  955. SceneObject* so = static_cast<SceneObject*>( object );
  956. if ( so )
  957. {
  958. // Unmount old object (PID reference is released even if it had been resolved yet)
  959. if ( so->mMountPID )
  960. {
  961. so->mMountPID->decRefCount();
  962. so->mMountPID = NULL;
  963. }
  964. so->unmount();
  965. // Get the new PID (new object will be mounted on demand)
  966. Con::setData( TypePID, &so->mMountPID, 0, 1, &data );
  967. if ( so->mMountPID )
  968. so->mMountPID->incRefCount(); // Prevent PID from being deleted out from under us!
  969. }
  970. return false;
  971. }
  972. void SceneObject::resolveMountPID()
  973. {
  974. if ( mMountPID && !mMount.object )
  975. {
  976. SceneObject *obj = dynamic_cast< SceneObject* >( mMountPID->getObject() );
  977. if ( obj )
  978. obj->mountObject( this, mMount.node, mMount.xfm );
  979. }
  980. }
  981. //-----------------------------------------------------------------------------
  982. void SceneObject::mountObject( SceneObject *obj, S32 node, const MatrixF &xfm )
  983. {
  984. if ( obj->mMount.object == this )
  985. {
  986. // Already mounted to this
  987. // So update our node and xfm which may have changed.
  988. obj->mMount.node = node;
  989. obj->mMount.xfm = xfm;
  990. }
  991. else
  992. {
  993. if ( obj->mMount.object )
  994. obj->unmount();
  995. obj->mMount.object = this;
  996. obj->mMount.node = node;
  997. obj->mMount.link = mMount.list;
  998. obj->mMount.xfm = xfm;
  999. mMount.list = obj;
  1000. // Assign PIDs to both objects
  1001. if ( isServerObject() )
  1002. {
  1003. obj->getOrCreatePersistentId();
  1004. if ( !obj->mMountPID )
  1005. {
  1006. obj->mMountPID = getOrCreatePersistentId();
  1007. obj->mMountPID->incRefCount();
  1008. }
  1009. }
  1010. obj->onMount( this, node );
  1011. }
  1012. }
  1013. //-----------------------------------------------------------------------------
  1014. void SceneObject::unmountObject( SceneObject *obj )
  1015. {
  1016. if ( obj->mMount.object == this )
  1017. {
  1018. // Find and unlink the object
  1019. for ( SceneObject **ptr = &mMount.list; *ptr; ptr = &(*ptr)->mMount.link )
  1020. {
  1021. if ( *ptr == obj )
  1022. {
  1023. *ptr = obj->mMount.link;
  1024. break;
  1025. }
  1026. }
  1027. obj->mMount.object = NULL;
  1028. obj->mMount.link = NULL;
  1029. if( obj->mMountPID != NULL ) // Only on server.
  1030. {
  1031. obj->mMountPID->decRefCount();
  1032. obj->mMountPID = NULL;
  1033. }
  1034. obj->onUnmount( this, obj->mMount.node );
  1035. }
  1036. }
  1037. //-----------------------------------------------------------------------------
  1038. void SceneObject::unmount()
  1039. {
  1040. if (mMount.object)
  1041. mMount.object->unmountObject(this);
  1042. }
  1043. //-----------------------------------------------------------------------------
  1044. void SceneObject::onMount( SceneObject *obj, S32 node )
  1045. {
  1046. deleteNotify( obj );
  1047. if ( !isGhost() )
  1048. {
  1049. setMaskBits( MountedMask );
  1050. //onMount_callback( node );
  1051. }
  1052. }
  1053. //-----------------------------------------------------------------------------
  1054. void SceneObject::onUnmount( SceneObject *obj, S32 node )
  1055. {
  1056. clearNotify(obj);
  1057. if ( !isGhost() )
  1058. {
  1059. setMaskBits( MountedMask );
  1060. //onUnmount_callback( node );
  1061. }
  1062. }
  1063. //-----------------------------------------------------------------------------
  1064. void SceneObject::getMountTransform( S32 index, const MatrixF &xfm, MatrixF *outMat )
  1065. {
  1066. MatrixF mountTransform( xfm );
  1067. const Point3F &scale = getScale();
  1068. Point3F position = mountTransform.getPosition();
  1069. position.convolve( scale );
  1070. mountTransform.setPosition( position );
  1071. outMat->mul( mObjToWorld, mountTransform );
  1072. }
  1073. //-----------------------------------------------------------------------------
  1074. void SceneObject::getRenderMountTransform( F32 delta, S32 index, const MatrixF &xfm, MatrixF *outMat )
  1075. {
  1076. MatrixF mountTransform( xfm );
  1077. const Point3F &scale = getScale();
  1078. Point3F position = mountTransform.getPosition();
  1079. position.convolve( scale );
  1080. mountTransform.setPosition( position );
  1081. outMat->mul( mRenderObjToWorld, mountTransform );
  1082. }
  1083. //=============================================================================
  1084. // Console API.
  1085. //=============================================================================
  1086. // MARK: ---- Console API ----
  1087. //-----------------------------------------------------------------------------
  1088. DefineEngineMethod( SceneObject, getType, S32, (),,
  1089. "Return the type mask for this object.\n"
  1090. "@return The numeric type mask for the object." )
  1091. {
  1092. return object->getTypeMask();
  1093. }
  1094. //-----------------------------------------------------------------------------
  1095. DefineEngineMethod( SceneObject, mountObject, bool,
  1096. ( SceneObject* objB, S32 slot, TransformF txfm ), ( TransformF::Identity ),
  1097. "@brief Mount objB to this object at the desired slot with optional transform.\n\n"
  1098. "@param objB Object to mount onto us\n"
  1099. "@param slot Mount slot ID\n"
  1100. "@param txfm (optional) mount offset transform\n"
  1101. "@return true if successful, false if failed (objB is not valid)" )
  1102. {
  1103. if ( objB )
  1104. {
  1105. object->mountObject( objB, slot, txfm.getMatrix() );
  1106. return true;
  1107. }
  1108. return false;
  1109. }
  1110. //-----------------------------------------------------------------------------
  1111. DefineEngineMethod( SceneObject, unmountObject, bool, ( SceneObject* target ),,
  1112. "@brief Unmount an object from ourselves.\n\n"
  1113. "@param target object to unmount\n"
  1114. "@return true if successful, false if failed\n" )
  1115. {
  1116. if ( target )
  1117. {
  1118. object->unmountObject(target);
  1119. return true;
  1120. }
  1121. return false;
  1122. }
  1123. //-----------------------------------------------------------------------------
  1124. DefineEngineMethod( SceneObject, unmount, void, (),,
  1125. "Unmount us from the currently mounted object if any.\n" )
  1126. {
  1127. object->unmount();
  1128. }
  1129. //-----------------------------------------------------------------------------
  1130. DefineEngineMethod( SceneObject, isMounted, bool, (),,
  1131. "@brief Check if we are mounted to another object.\n\n"
  1132. "@return true if mounted to another object, false if not mounted." )
  1133. {
  1134. return object->isMounted();
  1135. }
  1136. //-----------------------------------------------------------------------------
  1137. DefineEngineMethod( SceneObject, getObjectMount, S32, (),,
  1138. "@brief Get the object we are mounted to.\n\n"
  1139. "@return the SimObjectID of the object we're mounted to, or 0 if not mounted." )
  1140. {
  1141. return object->isMounted()? object->getObjectMount()->getId(): 0;
  1142. }
  1143. //-----------------------------------------------------------------------------
  1144. DefineEngineMethod( SceneObject, getMountedObjectCount, S32, (),,
  1145. "Get the number of objects mounted to us.\n"
  1146. "@return the number of mounted objects." )
  1147. {
  1148. return object->getMountedObjectCount();
  1149. }
  1150. //-----------------------------------------------------------------------------
  1151. DefineEngineMethod( SceneObject, getMountedObject, S32, ( S32 slot ),,
  1152. "Get the object mounted at a particular slot.\n"
  1153. "@param slot mount slot index to query\n"
  1154. "@return ID of the object mounted in the slot, or 0 if no object." )
  1155. {
  1156. SceneObject* mobj = object->getMountedObject( slot );
  1157. return mobj? mobj->getId(): 0;
  1158. }
  1159. //-----------------------------------------------------------------------------
  1160. DefineEngineMethod( SceneObject, getMountedObjectNode, S32, ( S32 slot ),,
  1161. "@brief Get the mount node index of the object mounted at our given slot.\n\n"
  1162. "@param slot mount slot index to query\n"
  1163. "@return index of the mount node used by the object mounted in this slot." )
  1164. {
  1165. return object->getMountedObjectNode( slot );
  1166. }
  1167. //-----------------------------------------------------------------------------
  1168. DefineEngineMethod( SceneObject, getMountNodeObject, S32, ( S32 node ),,
  1169. "@brief Get the object mounted at our given node index.\n\n"
  1170. "@param node mount node index to query\n"
  1171. "@return ID of the first object mounted at the node, or 0 if none found." )
  1172. {
  1173. SceneObject* mobj = object->getMountNodeObject( node );
  1174. return mobj? mobj->getId(): 0;
  1175. }
  1176. //-----------------------------------------------------------------------------
  1177. DefineEngineMethod( SceneObject, getTransform, TransformF, (),,
  1178. "Get the object's transform.\n"
  1179. "@return the current transform of the object\n" )
  1180. {
  1181. return object->getTransform();
  1182. }
  1183. //-----------------------------------------------------------------------------
  1184. DefineEngineMethod( SceneObject, getInverseTransform, TransformF, (),,
  1185. "Get the object's inverse transform.\n"
  1186. "@return the inverse transform of the object\n" )
  1187. {
  1188. return object->getWorldTransform();
  1189. }
  1190. //-----------------------------------------------------------------------------
  1191. DefineEngineMethod( SceneObject, getPosition, Point3F, (),,
  1192. "Get the object's world position.\n"
  1193. "@return the current world position of the object\n" )
  1194. {
  1195. return object->getTransform().getPosition();
  1196. }
  1197. DefineEngineMethod( SceneObject, setPosition, void, (Point3F pos),,
  1198. "Set the object's world position.\n"
  1199. "@param pos the new world position of the object\n" )
  1200. {
  1201. return object->setPosition(pos);
  1202. }
  1203. //-----------------------------------------------------------------------------
  1204. DefineEngineMethod( SceneObject, getEulerRotation, Point3F, (),,
  1205. "Get Euler rotation of this object.\n"
  1206. "@return the orientation of the object in the form of rotations around the "
  1207. "X, Y and Z axes in degrees.\n" )
  1208. {
  1209. Point3F euler = object->getTransform().toEuler();
  1210. // Convert to degrees.
  1211. euler.x = mRadToDeg( euler.x );
  1212. euler.y = mRadToDeg( euler.y );
  1213. euler.z = mRadToDeg( euler.z );
  1214. return euler;
  1215. }
  1216. //-----------------------------------------------------------------------------
  1217. DefineEngineMethod( SceneObject, getForwardVector, VectorF, (),,
  1218. "Get the direction this object is facing.\n"
  1219. "@return a vector indicating the direction this object is facing.\n"
  1220. "@note This is the object's y axis." )
  1221. {
  1222. return object->getTransform().getForwardVector();
  1223. }
  1224. //-----------------------------------------------------------------------------
  1225. DefineEngineMethod( SceneObject, getRightVector, VectorF, (),,
  1226. "Get the right vector of the object.\n"
  1227. "@return a vector indicating the right direction of this object."
  1228. "@note This is the object's x axis." )
  1229. {
  1230. return object->getTransform().getRightVector();
  1231. }
  1232. //-----------------------------------------------------------------------------
  1233. DefineEngineMethod( SceneObject, getUpVector, VectorF, (),,
  1234. "Get the up vector of the object.\n"
  1235. "@return a vector indicating the up direction of this object."
  1236. "@note This is the object's z axis." )
  1237. {
  1238. return object->getTransform().getUpVector();
  1239. }
  1240. //-----------------------------------------------------------------------------
  1241. DefineEngineMethod( SceneObject, setTransform, void, ( TransformF txfm ),,
  1242. "Set the object's transform (orientation and position)."
  1243. "@param txfm object transform to set" )
  1244. {
  1245. // PATHSHAPE
  1246. object->PerformUpdatesForChildren(txfm.getMatrix());
  1247. // PATHSHAPE END
  1248. if ( !txfm.hasRotation() )
  1249. object->setPosition( txfm.getPosition() );
  1250. else
  1251. object->setTransform( txfm.getMatrix() );
  1252. }
  1253. //-----------------------------------------------------------------------------
  1254. DefineEngineMethod( SceneObject, getScale, Point3F, (),,
  1255. "Get the object's scale.\n"
  1256. "@return object scale as a Point3F" )
  1257. {
  1258. return object->getScale();
  1259. }
  1260. //-----------------------------------------------------------------------------
  1261. DefineEngineMethod( SceneObject, setScale, void, ( Point3F scale ),,
  1262. "Set the object's scale.\n"
  1263. "@param scale object scale to set\n" )
  1264. {
  1265. object->setScale( scale );
  1266. }
  1267. //-----------------------------------------------------------------------------
  1268. DefineEngineMethod( SceneObject, getWorldBox, Box3F, (),,
  1269. "Get the object's world bounding box.\n"
  1270. "@return six fields, two Point3Fs, containing the min and max points of the "
  1271. "worldbox." )
  1272. {
  1273. return object->getWorldBox();
  1274. }
  1275. //-----------------------------------------------------------------------------
  1276. DefineEngineMethod( SceneObject, getWorldBoxCenter, Point3F, (),,
  1277. "Get the center of the object's world bounding box.\n"
  1278. "@return the center of the world bounding box for this object." )
  1279. {
  1280. Point3F center;
  1281. object->getWorldBox().getCenter( &center );
  1282. return center;
  1283. }
  1284. //-----------------------------------------------------------------------------
  1285. DefineEngineMethod( SceneObject, getObjectBox, Box3F, (),,
  1286. "Get the object's bounding box (relative to the object's origin).\n"
  1287. "@return six fields, two Point3Fs, containing the min and max points of the "
  1288. "objectbox." )
  1289. {
  1290. return object->getObjBox();
  1291. }
  1292. //-----------------------------------------------------------------------------
  1293. DefineEngineMethod( SceneObject, isGlobalBounds, bool, (),,
  1294. "Check if this object has a global bounds set.\n"
  1295. "If global bounds are set to be true, then the object is assumed to have an "
  1296. "infinitely large bounding box for collision and rendering purposes.\n"
  1297. "@return true if the object has a global bounds." )
  1298. {
  1299. return object->isGlobalBounds();
  1300. }
  1301. DefineEngineMethod(SceneObject, setForwardVector, void, (VectorF newForward, VectorF upVector), (VectorF(0, 0, 0), VectorF(0, 0, 1)),
  1302. "Sets the forward vector of a scene object, making it face Y+ along the new vector.\n"
  1303. "@param The new forward vector to set.\n"
  1304. "@param (Optional) The up vector to use to help orient the rotation.")
  1305. {
  1306. object->setForwardVector(newForward, upVector);
  1307. }
  1308. // PATHSHAPE
  1309. // Move RenderTransform by set amount
  1310. // no longer used
  1311. void SceneObject::moveRender(const Point3F &delta)
  1312. {
  1313. Point3F pos;
  1314. const MatrixF& tmat = getRenderTransform();
  1315. tmat.getColumn(3,&pos);
  1316. AngAxisF aa(tmat);
  1317. pos += delta;
  1318. MatrixF mat;
  1319. aa.setMatrix(&mat);
  1320. mat.setColumn(3,pos);
  1321. setRenderTransform(mat);
  1322. }
  1323. void SceneObject::PerformUpdatesForChildren(MatrixF mat){
  1324. UpdateXformChange(mat);
  1325. for (U32 i=0; i < getNumChildren(); i++) {
  1326. SceneObject *o = getChild(i);
  1327. o->updateChildTransform(); //update the position of the child object
  1328. }
  1329. }
  1330. // This function will move the players based on how much it's
  1331. // parent have moved
  1332. void SceneObject::updateChildTransform(){
  1333. if (getParent() != NULL){
  1334. MatrixF one;
  1335. MatrixF two;
  1336. MatrixF three;
  1337. MatrixF four;
  1338. MatrixF mat;
  1339. one= getTransform();
  1340. two = getParent()->getTransform();
  1341. one.affineInverse();
  1342. four.mul(two,one);
  1343. mat.mul(getParent()->mLastXform,getTransform());
  1344. setTransform(mat);
  1345. }
  1346. }
  1347. // This function will move the rendered image based on how much it's
  1348. // parent have moved since the processtick.
  1349. // For some reason the player object must be updated via it's GetRenderTransform seen below,
  1350. // Other objects seem to require getTransform() only
  1351. void SceneObject::updateRenderChangesByParent(){
  1352. if (getParent() != NULL){
  1353. MatrixF renderXform = getParent()->getRenderTransform();
  1354. MatrixF xform = getParent()->getTransform();
  1355. xform.affineInverse();
  1356. MatrixF offset;
  1357. offset.mul(renderXform, xform);
  1358. MatrixF mat;
  1359. //add the "offset" caused by the parents change, and add it to it's own
  1360. // This is needed by objects that update their own render transform thru interpolate tick
  1361. // Mostly for stationary objects.
  1362. if (getClassName() == StringTable->insert("Player"))
  1363. mat.mul(offset,getRenderTransform());
  1364. else
  1365. mat.mul(offset,getTransform());
  1366. setRenderTransform(mat);
  1367. }
  1368. }
  1369. //Ramen - Move Transform by set amount
  1370. //written by Anthony Lovell
  1371. void SceneObject::move(F32 x, F32 y, F32 z)
  1372. {
  1373. Point3F delta;
  1374. delta.x = x;
  1375. delta.y = y;
  1376. delta.z = z;
  1377. move(delta);
  1378. }
  1379. // move by a specified delta in root coordinate space
  1380. void SceneObject::move(const Point3F &delta)
  1381. {
  1382. Point3F pos;
  1383. const MatrixF& tmat = getTransform();
  1384. tmat.getColumn(3,&pos);
  1385. AngAxisF aa(tmat);
  1386. pos += delta;
  1387. MatrixF mat;
  1388. aa.setMatrix(&mat);
  1389. mat.setColumn(3,pos);
  1390. setTransform(mat);
  1391. }
  1392. //written by Anthony Lovell ----------------------------------------------------------
  1393. U32
  1394. SceneObject::getNumChildren() const
  1395. {
  1396. U32 num = 0;
  1397. for (SceneObject *cur = mGraph.firstChild; cur; cur = cur->mGraph.nextSibling)
  1398. num++;
  1399. return num;
  1400. }
  1401. //written by Anthony Lovell ----------------------------------------------------------
  1402. SceneObject *
  1403. SceneObject::getChild(U32 index) const
  1404. {
  1405. SceneObject *cur = mGraph.firstChild;
  1406. for (U32 i = 0;
  1407. cur && i < index;
  1408. i++)
  1409. cur = cur->mGraph.nextSibling;
  1410. return cur;
  1411. }
  1412. void SceneObject::UpdateXformChange(const MatrixF &mat){
  1413. // This function gets the difference between the Transform and current Render transform
  1414. // Used for Interpolation matching with the child objects who rely on this data.
  1415. MatrixF oldxform = getTransform();
  1416. oldxform.affineInverse();
  1417. mLastXform.mul(mat,oldxform);
  1418. }
  1419. //----------------------------------------------------------
  1420. bool
  1421. SceneObject::attachChildAt(SceneObject *subObject, MatrixF atThisOffset, S32 node)
  1422. {
  1423. AssertFatal(subObject, "attaching a null subObject");
  1424. AssertFatal(!isChildOf(subObject), "cyclic attachChild()");
  1425. bool b = subObject->attachToParent(this, &atThisOffset, node);
  1426. if (!b)
  1427. return false;
  1428. return true;
  1429. }
  1430. //----------------------------------------------------------
  1431. bool
  1432. SceneObject::attachChildAt(SceneObject *subObject, Point3F atThisPosition)
  1433. {
  1434. AssertFatal(subObject, "attaching a null subObject");
  1435. AssertFatal(!isChildOf(subObject), "cyclic attachChild()");
  1436. bool b = subObject->attachToParent(this);
  1437. if (!b)
  1438. return false;
  1439. subObject->mGraph.objToParent.setColumn(3, atThisPosition);
  1440. // calcTransformFromLocalTransform();
  1441. return true;
  1442. }
  1443. //----------------------------------------------------------
  1444. bool
  1445. SceneObject::attachChild(SceneObject *child)
  1446. {
  1447. AssertFatal(child, "attaching a null subObject");
  1448. AssertFatal(!isChildOf(child), "cyclic attachChild()");
  1449. return child->attachToParent(this);
  1450. }
  1451. //----------------------------------------------------------
  1452. /// returns a count of children plus their children, recursively
  1453. U32
  1454. SceneObject::getNumProgeny() const
  1455. {
  1456. U32 num = 0;
  1457. for (SceneObject *cur = mGraph.firstChild; cur; cur = cur->mGraph.nextSibling) {
  1458. num += 1 + cur->getNumProgeny();
  1459. }
  1460. return num;
  1461. }
  1462. DefineEngineMethod(SceneObject, getNumChildren, S32, (),, "returns number of direct child objects")
  1463. {
  1464. return object->getNumChildren();
  1465. }
  1466. DefineEngineMethod(SceneObject, getNumProgeny, S32, (),, "returns number of recursively-nested child objects")
  1467. {
  1468. return object->getNumProgeny();
  1469. }
  1470. DefineEngineMethod(SceneObject, getChild, S32, (S32 _index), (0), "getChild(S32 index) -- returns child SceneObject at given index")
  1471. {
  1472. SceneObject *s = object->getChild(_index);
  1473. return s ? s->getId() : 0;
  1474. }
  1475. DefineEngineMethod(SceneObject, attachChildAt, bool, (SceneObject* _subObject, MatrixF _offset, S32 _node), (nullAsType<SceneObject*>(), MatrixF::Identity, 0), "(SceneObject subObject, MatrixF offset, S32 offset)"
  1476. "Mount object to this one with the specified offset expressed in our coordinate space.")
  1477. {
  1478. if (_subObject != nullptr)
  1479. {
  1480. return object->attachChildAt(_subObject, _offset, _node);
  1481. }
  1482. else
  1483. {
  1484. Con::errorf("Couldn't addObject()!");
  1485. return false;
  1486. }
  1487. }
  1488. DefineEngineMethod(SceneObject, attachToParent, bool, (const char*_sceneObject), ,"attachToParent(SceneObject)"
  1489. "specify a null or non-null parent")
  1490. {
  1491. SceneObject * t;
  1492. if(Sim::findObject(_sceneObject, t))
  1493. {
  1494. return object->attachToParent(t);
  1495. }
  1496. else
  1497. {
  1498. if ((!String::compare("0", _sceneObject))|| (!String::compare("", _sceneObject)))
  1499. return object->attachToParent(NULL);
  1500. else
  1501. {
  1502. Con::errorf("Couldn't setParent()!");
  1503. return false;
  1504. }
  1505. }
  1506. }
  1507. DefineEngineMethod(SceneObject, getParent, S32, (),, "returns ID of parent SceneObject")
  1508. {
  1509. SceneObject *p = object->getParent();
  1510. return p ? p->getId() : -1;
  1511. }
  1512. DefineEngineMethod(SceneObject, attachChild, bool, (const char*_subObject),, "(SceneObject subObject)"
  1513. "attach an object to this one, preserving its present transform.")
  1514. {
  1515. SceneObject * t;
  1516. MatrixF m;
  1517. if(Sim::findObject(_subObject, t))
  1518. return object->attachChild(t);
  1519. Con::errorf("Couldn't addObject()!");
  1520. return false;
  1521. }
  1522. bool SceneObject::isChildOf(SceneObject *so)
  1523. {
  1524. SceneObject *p = mGraph.parent;
  1525. if (p) {
  1526. if (p == so)
  1527. return true;
  1528. else
  1529. return p->isChildOf(so);
  1530. } else
  1531. return false;
  1532. }
  1533. bool SceneObject::attachToParent(SceneObject *newParent, MatrixF *atThisOffset/* = NULL */, S32 node )
  1534. {
  1535. SceneObject *oldParent = mGraph.parent;
  1536. if (oldParent == newParent)
  1537. return true;
  1538. // cycles in the scene hierarchy are forbidden!
  1539. // that is: a SceneObject cannot be a child of its progeny
  1540. if (newParent && newParent->isChildOf(this))
  1541. return false;
  1542. mGraph.parent = newParent;
  1543. if (oldParent) {
  1544. clearNotify(oldParent);
  1545. // remove this SceneObject from the list of children of oldParent
  1546. SceneObject *cur = oldParent->mGraph.firstChild;
  1547. if (cur == this) { // if we are the first child, this is easy
  1548. oldParent->mGraph.firstChild = mGraph.nextSibling;
  1549. } else {
  1550. while (cur->mGraph.nextSibling != this) {
  1551. cur = cur->mGraph.nextSibling;
  1552. // ASSERT cur != NULL;
  1553. }
  1554. cur->mGraph.nextSibling = mGraph.nextSibling;
  1555. }
  1556. oldParent->onLostChild(this);
  1557. }
  1558. if (newParent) {
  1559. deleteNotify(newParent); // if we are deleted, inform our parent
  1560. // add this SceneObject to the list of children of oldParent
  1561. mGraph.nextSibling = newParent->mGraph.firstChild;
  1562. newParent->mGraph.firstChild = this;
  1563. mGraph.parent = newParent;
  1564. newParent->onNewChild(this);
  1565. if (atThisOffset)
  1566. mGraph.objToParent = *atThisOffset;
  1567. } else {
  1568. mGraph.parent = NULL;
  1569. mGraph.nextSibling = NULL;
  1570. mGraph.objToParent = mObjToWorld;
  1571. }
  1572. onLostParent(oldParent);
  1573. onNewParent(newParent);
  1574. setMaskBits(MountedMask);
  1575. return true;
  1576. }
  1577. DefineEngineMethod(SceneObject, detachChild, bool, (const char*_subObject),, "SceneObject subObject")
  1578. {
  1579. SceneObject * t;
  1580. if(Sim::findObject(_subObject, t)) {
  1581. return t->attachToParent(NULL);
  1582. } else
  1583. return false;
  1584. }
  1585. // subclasses can do something with these if they care to
  1586. void SceneObject::onNewParent(SceneObject *newParent) {}
  1587. void SceneObject::onLostParent(SceneObject *oldParent){}
  1588. void SceneObject::onNewChild(SceneObject *newKid){}
  1589. void SceneObject::onLostChild(SceneObject *lostKid){}