sceneObject.cpp 59 KB

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