sceneObject.cpp 58 KB

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