sceneObject.cpp 59 KB

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