sceneObject.cpp 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434
  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. #include "platform/platform.h"
  23. #include "scene/sceneObject.h"
  24. #include "platform/profiler.h"
  25. #include "console/consoleTypes.h"
  26. #include "console/engineAPI.h"
  27. #include "console/simPersistID.h"
  28. #include "sim/netConnection.h"
  29. #include "core/stream/bitStream.h"
  30. #include "scene/sceneManager.h"
  31. #include "scene/sceneTracker.h"
  32. #include "scene/sceneRenderState.h"
  33. #include "scene/zones/sceneZoneSpace.h"
  34. #include "collision/extrudedPolyList.h"
  35. #include "collision/earlyOutPolyList.h"
  36. #include "collision/optimizedPolyList.h"
  37. #include "math/mPolyhedron.h"
  38. #include "gfx/bitmap/gBitmap.h"
  39. #include "math/util/frustum.h"
  40. #include "math/mathIO.h"
  41. #include "math/mTransform.h"
  42. #include "T3D/gameBase/gameProcess.h"
  43. IMPLEMENT_CONOBJECT(SceneObject);
  44. ConsoleDocClass( SceneObject,
  45. "@brief A networkable object that exists in the 3D world.\n\n"
  46. "The SceneObject class provides the foundation for 3D objects in the Engine. It "
  47. "exposes the functionality for:\n\n"
  48. "<ul><li>Position, rotation and scale within the world.</li>"
  49. "<li>Working with a scene graph (in the Zone and Portal sections), allowing efficient "
  50. "and robust rendering of the game scene.</li>"
  51. "<li>Various helper functions, including functions to get bounding information "
  52. "and momentum/velocity.</li>"
  53. "<li>Mounting one SceneObject to another.</li>"
  54. "<li>An interface for collision detection, as well as ray casting.</li>"
  55. "<li>Lighting. SceneObjects can register lights both at lightmap generation "
  56. "time, and dynamic lights at runtime (for special effects, such as from flame "
  57. "or a projectile, or from an explosion).</li></ul>\n\n"
  58. "You do not typically work with SceneObjects themselves. The SceneObject provides a reference "
  59. "within the game world (the scene), but does not render to the client on its own. The "
  60. "same is true of collision detection beyond that of the bounding box. Instead you "
  61. "use one of the many classes that derrive from SceneObject, such as TSStatic.\n\n"
  62. "@section SceneObject_Hiding Difference Between setHidden() and isRenderEnabled\n\n"
  63. "When it comes time to decide if a SceneObject should render or not, there are two "
  64. "methods that can stop the SceneObject from rendering at all. You need to be aware of "
  65. "the differences between these two methods as they impact how the SceneObject is networked "
  66. "from the server to the client.\n\n"
  67. "The first method of manually controlling if a SceneObject is rendered is through its "
  68. "SceneObject::isRenderEnabled property. When set to false the SceneObject is considered invisible but "
  69. "still present within the scene. This means it still takes part in collisions and continues "
  70. "to be networked.\n\n"
  71. "The second method is using the setHidden() method. This will actually remove a SceneObject "
  72. "from the scene and it will no longer be networked from the server to the cleint. Any client-side "
  73. "ghost of the object will be deleted as the server no longer considers the object to be in scope.\n\n"
  74. "@ingroup gameObjects\n"
  75. );
  76. Signal< void( SceneObject* ) > SceneObject::smSceneObjectAdd;
  77. Signal< void( SceneObject* ) > SceneObject::smSceneObjectRemove;
  78. //-----------------------------------------------------------------------------
  79. SceneObject::SceneObject()
  80. {
  81. mContainer = 0;
  82. mTypeMask = DefaultObjectType;
  83. mCollisionCount = 0;
  84. mGlobalBounds = false;
  85. mObjScale.set(1,1,1);
  86. mObjToWorld.identity();
  87. mWorldToObj.identity();
  88. mObjBox = Box3F(Point3F(0, 0, 0), Point3F(0, 0, 0));
  89. mWorldBox = Box3F(Point3F(0, 0, 0), Point3F(0, 0, 0));
  90. mWorldSphere = SphereF(Point3F(0, 0, 0), 0);
  91. mRenderObjToWorld.identity();
  92. mRenderWorldToObj.identity();
  93. mRenderWorldBox = Box3F(Point3F(0, 0, 0), Point3F(0, 0, 0));
  94. mRenderWorldSphere = SphereF(Point3F(0, 0, 0), 0);
  95. mContainerSeqKey = 0;
  96. mBinRefHead = NULL;
  97. mSceneManager = NULL;
  98. mNumCurrZones = 0;
  99. mZoneRefHead = NULL;
  100. mZoneRefDirty = false;
  101. mBinMinX = 0xFFFFFFFF;
  102. mBinMaxX = 0xFFFFFFFF;
  103. mBinMinY = 0xFFFFFFFF;
  104. mBinMaxY = 0xFFFFFFFF;
  105. mLightPlugin = NULL;
  106. mMount.object = NULL;
  107. mMount.link = NULL;
  108. mMount.list = NULL;
  109. mMount.node = -1;
  110. mMount.xfm = MatrixF::Identity;
  111. mMountPID = NULL;
  112. mSceneObjectLinks = NULL;
  113. mObjectFlags.set( RenderEnabledFlag | SelectionEnabledFlag );
  114. mIsScopeAlways = false;
  115. }
  116. //-----------------------------------------------------------------------------
  117. SceneObject::~SceneObject()
  118. {
  119. AssertFatal( mZoneRefHead == NULL && mBinRefHead == NULL,
  120. "SceneObject::~SceneObject - Object still linked in reference lists!");
  121. AssertFatal( !mSceneObjectLinks,
  122. "SceneObject::~SceneObject() - object is still linked to SceneTrackers" );
  123. unlink();
  124. }
  125. //-----------------------------------------------------------------------------
  126. bool SceneObject::castRayRendered(const Point3F &start, const Point3F &end, RayInfo *info)
  127. {
  128. // By default, all ray checking against the rendered mesh will be passed
  129. // on to the collision mesh. This saves having to define both methods
  130. // for simple objects.
  131. return castRay( start, end, info );
  132. }
  133. //-----------------------------------------------------------------------------
  134. bool SceneObject::containsPoint( const Point3F& point )
  135. {
  136. // If it's not in the AABB, then it can't be in the OBB either,
  137. // so early out.
  138. if( !mWorldBox.isContained( point ) )
  139. return false;
  140. // Transform point into object space and test it against
  141. // our object space bounding box.
  142. Point3F objPoint( 0, 0, 0 );
  143. getWorldTransform().mulP( point, &objPoint );
  144. objPoint.convolveInverse( getScale() );
  145. return ( mObjBox.isContained( objPoint ) );
  146. }
  147. //-----------------------------------------------------------------------------
  148. bool SceneObject::collideBox(const Point3F &start, const Point3F &end, RayInfo *info)
  149. {
  150. const F32 * pStart = (const F32*)start;
  151. const F32 * pEnd = (const F32*)end;
  152. const F32 * pMin = (const F32*)mObjBox.minExtents;
  153. const F32 * pMax = (const F32*)mObjBox.maxExtents;
  154. F32 maxStartTime = -1;
  155. F32 minEndTime = 1;
  156. F32 startTime;
  157. F32 endTime;
  158. // used for getting normal
  159. U32 hitIndex = 0xFFFFFFFF;
  160. U32 side;
  161. // walk the axis
  162. for(U32 i = 0; i < 3; i++)
  163. {
  164. //
  165. if(pStart[i] < pEnd[i])
  166. {
  167. if(pEnd[i] < pMin[i] || pStart[i] > pMax[i])
  168. return(false);
  169. F32 dist = pEnd[i] - pStart[i];
  170. startTime = (pStart[i] < pMin[i]) ? (pMin[i] - pStart[i]) / dist : -1;
  171. endTime = (pEnd[i] > pMax[i]) ? (pMax[i] - pStart[i]) / dist : 1;
  172. side = 1;
  173. }
  174. else
  175. {
  176. if(pStart[i] < pMin[i] || pEnd[i] > pMax[i])
  177. return(false);
  178. F32 dist = pStart[i] - pEnd[i];
  179. startTime = (pStart[i] > pMax[i]) ? (pStart[i] - pMax[i]) / dist : -1;
  180. endTime = (pEnd[i] < pMin[i]) ? (pStart[i] - pMin[i]) / dist : 1;
  181. side = 0;
  182. }
  183. //
  184. if(startTime > maxStartTime)
  185. {
  186. maxStartTime = startTime;
  187. hitIndex = i * 2 + side;
  188. }
  189. if(endTime < minEndTime)
  190. minEndTime = endTime;
  191. if(minEndTime < maxStartTime)
  192. return(false);
  193. }
  194. // fail if inside
  195. if(maxStartTime < 0.f)
  196. return(false);
  197. //
  198. static Point3F boxNormals[] = {
  199. Point3F( 1, 0, 0),
  200. Point3F(-1, 0, 0),
  201. Point3F( 0, 1, 0),
  202. Point3F( 0,-1, 0),
  203. Point3F( 0, 0, 1),
  204. Point3F( 0, 0,-1),
  205. };
  206. //
  207. AssertFatal(hitIndex != 0xFFFFFFFF, "SceneObject::collideBox");
  208. info->t = maxStartTime;
  209. info->object = this;
  210. mObjToWorld.mulV(boxNormals[hitIndex], &info->normal);
  211. info->material = 0;
  212. return(true);
  213. }
  214. //-----------------------------------------------------------------------------
  215. void SceneObject::disableCollision()
  216. {
  217. mCollisionCount++;
  218. AssertFatal(mCollisionCount < 50, "SceneObject::disableCollision called 50 times on the same object. Is this inside a circular loop?" );
  219. }
  220. //-----------------------------------------------------------------------------
  221. void SceneObject::enableCollision()
  222. {
  223. if (mCollisionCount)
  224. --mCollisionCount;
  225. }
  226. //-----------------------------------------------------------------------------
  227. bool SceneObject::onAdd()
  228. {
  229. if ( !Parent::onAdd() )
  230. return false;
  231. mIsScopeAlways = mNetFlags.test( ScopeAlways );
  232. mWorldToObj = mObjToWorld;
  233. mWorldToObj.affineInverse();
  234. resetWorldBox();
  235. setRenderTransform(mObjToWorld);
  236. resolveMountPID();
  237. smSceneObjectAdd.trigger(this);
  238. return true;
  239. }
  240. //-----------------------------------------------------------------------------
  241. void SceneObject::onRemove()
  242. {
  243. smSceneObjectRemove.trigger(this);
  244. unmount();
  245. plUnlink();
  246. Parent::onRemove();
  247. }
  248. //-----------------------------------------------------------------------------
  249. void SceneObject::addToScene()
  250. {
  251. if( mSceneManager )
  252. return;
  253. if( isClientObject() )
  254. gClientSceneGraph->addObjectToScene( this );
  255. else
  256. gServerSceneGraph->addObjectToScene( this );
  257. }
  258. //-----------------------------------------------------------------------------
  259. void SceneObject::removeFromScene()
  260. {
  261. if( !mSceneManager )
  262. return;
  263. mSceneManager->removeObjectFromScene( this );
  264. }
  265. //-----------------------------------------------------------------------------
  266. void SceneObject::onDeleteNotify( SimObject *obj )
  267. {
  268. // We are comparing memory addresses so even if obj really is not a
  269. // ProcessObject this cast shouldn't break anything.
  270. if ( obj == mAfterObject )
  271. mAfterObject = NULL;
  272. if ( obj == mMount.object )
  273. unmount();
  274. Parent::onDeleteNotify( obj );
  275. }
  276. //-----------------------------------------------------------------------------
  277. void SceneObject::inspectPostApply()
  278. {
  279. if( isServerObject() )
  280. setMaskBits( MountedMask );
  281. Parent::inspectPostApply();
  282. }
  283. //-----------------------------------------------------------------------------
  284. void SceneObject::setGlobalBounds()
  285. {
  286. mGlobalBounds = true;
  287. mObjBox.minExtents.set( -1e10, -1e10, -1e10 );
  288. mObjBox.maxExtents.set( 1e10, 1e10, 1e10 );
  289. if( mSceneManager )
  290. mSceneManager->notifyObjectDirty( this );
  291. }
  292. //-----------------------------------------------------------------------------
  293. void SceneObject::setTransform( const MatrixF& mat )
  294. {
  295. // This test is a bit expensive so turn it off in release.
  296. #ifdef TORQUE_DEBUG
  297. //AssertFatal( mat.isAffine(), "SceneObject::setTransform() - Bad transform (non affine)!" );
  298. #endif
  299. PROFILE_SCOPE( SceneObject_setTransform );
  300. // Update the transforms.
  301. mObjToWorld = mWorldToObj = mat;
  302. mWorldToObj.affineInverse();
  303. // Update the world-space AABB.
  304. resetWorldBox();
  305. // If we're in a SceneManager, sync our scene state.
  306. if( mSceneManager != NULL )
  307. mSceneManager->notifyObjectDirty( this );
  308. setRenderTransform( mat );
  309. }
  310. //-----------------------------------------------------------------------------
  311. void SceneObject::setScale( const VectorF &scale )
  312. {
  313. AssertFatal( !mIsNaN( scale ), "SceneObject::setScale() - The scale is NaN!" );
  314. // Avoid unnecessary scaling operations.
  315. if ( mObjScale.equal( scale ) )
  316. return;
  317. mObjScale = scale;
  318. setTransform(MatrixF(mObjToWorld));
  319. // Make sure that any subclasses of me get a chance to react to the
  320. // scale being changed.
  321. onScaleChanged();
  322. setMaskBits( ScaleMask );
  323. }
  324. //-----------------------------------------------------------------------------
  325. void SceneObject::resetWorldBox()
  326. {
  327. AssertFatal(mObjBox.isValidBox(), "SceneObject::resetWorldBox - Bad object box!");
  328. mWorldBox = mObjBox;
  329. mWorldBox.minExtents.convolve(mObjScale);
  330. mWorldBox.maxExtents.convolve(mObjScale);
  331. mObjToWorld.mul(mWorldBox);
  332. AssertFatal(mWorldBox.isValidBox(), "SceneObject::resetWorldBox - Bad world box!");
  333. // Create mWorldSphere from mWorldBox
  334. mWorldBox.getCenter(&mWorldSphere.center);
  335. mWorldSphere.radius = (mWorldBox.maxExtents - mWorldSphere.center).len();
  336. // Update tracker links.
  337. for( SceneObjectLink* link = mSceneObjectLinks; link != NULL;
  338. link = link->getNextLink() )
  339. link->update();
  340. }
  341. //-----------------------------------------------------------------------------
  342. void SceneObject::resetObjectBox()
  343. {
  344. AssertFatal( mWorldBox.isValidBox(), "SceneObject::resetObjectBox - Bad world box!" );
  345. mObjBox = mWorldBox;
  346. mWorldToObj.mul( mObjBox );
  347. Point3F objScale( mObjScale );
  348. objScale.setMax( Point3F( (F32)POINT_EPSILON, (F32)POINT_EPSILON, (F32)POINT_EPSILON ) );
  349. mObjBox.minExtents.convolveInverse( objScale );
  350. mObjBox.maxExtents.convolveInverse( objScale );
  351. AssertFatal( mObjBox.isValidBox(), "SceneObject::resetObjectBox - Bad object box!" );
  352. // Update the mWorldSphere from mWorldBox
  353. mWorldBox.getCenter( &mWorldSphere.center );
  354. mWorldSphere.radius = ( mWorldBox.maxExtents - mWorldSphere.center ).len();
  355. // Update scene managers.
  356. for( SceneObjectLink* link = mSceneObjectLinks; link != NULL;
  357. link = link->getNextLink() )
  358. link->update();
  359. }
  360. //-----------------------------------------------------------------------------
  361. void SceneObject::setRenderTransform(const MatrixF& mat)
  362. {
  363. PROFILE_START(SceneObj_setRenderTransform);
  364. mRenderObjToWorld = mRenderWorldToObj = mat;
  365. mRenderWorldToObj.affineInverse();
  366. AssertFatal(mObjBox.isValidBox(), "Bad object box!");
  367. resetRenderWorldBox();
  368. PROFILE_END();
  369. }
  370. //-----------------------------------------------------------------------------
  371. void SceneObject::resetRenderWorldBox()
  372. {
  373. AssertFatal( mObjBox.isValidBox(), "Bad object box!" );
  374. mRenderWorldBox = mObjBox;
  375. mRenderWorldBox.minExtents.convolve( mObjScale );
  376. mRenderWorldBox.maxExtents.convolve( mObjScale );
  377. mRenderObjToWorld.mul( mRenderWorldBox );
  378. AssertFatal( mRenderWorldBox.isValidBox(), "Bad world box!" );
  379. // Create mRenderWorldSphere from mRenderWorldBox.
  380. mRenderWorldBox.getCenter( &mRenderWorldSphere.center );
  381. mRenderWorldSphere.radius = ( mRenderWorldBox.maxExtents - mRenderWorldSphere.center ).len();
  382. }
  383. //-----------------------------------------------------------------------------
  384. void SceneObject::setHidden( bool hidden )
  385. {
  386. if( hidden != isHidden() )
  387. {
  388. // Add/remove the object from the scene. Removing it
  389. // will also cause the NetObject to go out of scope since
  390. // the container query will not find it anymore. However,
  391. // ScopeAlways objects need to be treated separately as we
  392. // do next.
  393. if( !hidden )
  394. addToScene();
  395. else
  396. removeFromScene();
  397. // ScopeAlways objects stay in scope no matter what, i.e. even
  398. // if they aren't in the scene query anymore. So, to force ghosts
  399. // to go away, we need to clear ScopeAlways while we are hidden.
  400. if( hidden && mIsScopeAlways )
  401. clearScopeAlways();
  402. else if( !hidden && mIsScopeAlways )
  403. setScopeAlways();
  404. Parent::setHidden( hidden );
  405. }
  406. }
  407. //-----------------------------------------------------------------------------
  408. void SceneObject::initPersistFields()
  409. {
  410. addGroup( "Transform" );
  411. addProtectedField( "position", TypeMatrixPosition, Offset( mObjToWorld, SceneObject ),
  412. &_setFieldPosition, &defaultProtectedGetFn,
  413. "Object world position." );
  414. addProtectedField( "rotation", TypeMatrixRotation, Offset( mObjToWorld, SceneObject ),
  415. &_setFieldRotation, &defaultProtectedGetFn,
  416. "Object world orientation." );
  417. addProtectedField( "scale", TypePoint3F, Offset( mObjScale, SceneObject ),
  418. &_setFieldScale, &defaultProtectedGetFn,
  419. "Object world scale." );
  420. endGroup( "Transform" );
  421. addGroup( "Editing" );
  422. addProtectedField( "isRenderEnabled", TypeBool, Offset( mObjectFlags, SceneObject ),
  423. &_setRenderEnabled, &_getRenderEnabled,
  424. "Controls client-side rendering of the object.\n"
  425. "@see isRenderable()\n" );
  426. addProtectedField( "isSelectionEnabled", TypeBool, Offset( mObjectFlags, SceneObject ),
  427. &_setSelectionEnabled, &_getSelectionEnabled,
  428. "Determines if the object may be selected from wihin the Tools.\n"
  429. "@see isSelectable()\n" );
  430. endGroup( "Editing" );
  431. addGroup( "Mounting" );
  432. addProtectedField( "mountPID", TypePID, Offset( mMountPID, SceneObject ), &_setMountPID, &defaultProtectedGetFn,
  433. "@brief PersistentID of object we are mounted to.\n\n"
  434. "Unlike the SimObjectID that is determined at run time, the PersistentID of an object is saved with the level/mission and "
  435. "may be used to form a link between objects." );
  436. addField( "mountNode", TypeS32, Offset( mMount.node, SceneObject ), "Node we are mounted to." );
  437. addField( "mountPos", TypeMatrixPosition, Offset( mMount.xfm, SceneObject ), "Position we are mounted at ( object space of our mount object )." );
  438. addField( "mountRot", TypeMatrixRotation, Offset( mMount.xfm, SceneObject ), "Rotation we are mounted at ( object space of our mount object )." );
  439. endGroup( "Mounting" );
  440. Parent::initPersistFields();
  441. }
  442. //-----------------------------------------------------------------------------
  443. bool SceneObject::_setFieldPosition( void *object, const char *index, const char *data )
  444. {
  445. SceneObject* so = static_cast<SceneObject*>( object );
  446. if ( so )
  447. {
  448. MatrixF txfm( so->getTransform() );
  449. Con::setData( TypeMatrixPosition, &txfm, 0, 1, &data );
  450. so->setTransform( txfm );
  451. }
  452. return false;
  453. }
  454. //-----------------------------------------------------------------------------
  455. bool SceneObject::_setFieldRotation( void *object, const char *index, const char *data )
  456. {
  457. SceneObject* so = static_cast<SceneObject*>( object );
  458. if ( so )
  459. {
  460. MatrixF txfm( so->getTransform() );
  461. Con::setData( TypeMatrixRotation, &txfm, 0, 1, &data );
  462. so->setTransform( txfm );
  463. }
  464. return false;
  465. }
  466. //-----------------------------------------------------------------------------
  467. bool SceneObject::_setFieldScale( void *object, const char *index, const char *data )
  468. {
  469. SceneObject* so = static_cast<SceneObject*>( object );
  470. if ( so )
  471. {
  472. Point3F scale;
  473. Con::setData( TypePoint3F, &scale, 0, 1, &data );
  474. so->setScale( scale );
  475. }
  476. return false;
  477. }
  478. //-----------------------------------------------------------------------------
  479. bool SceneObject::writeField( StringTableEntry fieldName, const char* value )
  480. {
  481. if( !Parent::writeField( fieldName, value ) )
  482. return false;
  483. static StringTableEntry sIsRenderEnabled = StringTable->insert( "isRenderEnabled" );
  484. static StringTableEntry sIsSelectionEnabled = StringTable->insert( "isSelectionEnabled" );
  485. static StringTableEntry sMountNode = StringTable->insert( "mountNode" );
  486. static StringTableEntry sMountPos = StringTable->insert( "mountPos" );
  487. static StringTableEntry sMountRot = StringTable->insert( "mountRot" );
  488. // Don't write flag fields if they are at their default values.
  489. if( fieldName == sIsRenderEnabled && dAtob( value ) )
  490. return false;
  491. else if( fieldName == sIsSelectionEnabled && dAtob( value ) )
  492. return false;
  493. else if ( mMountPID == NULL && ( fieldName == sMountNode ||
  494. fieldName == sMountPos ||
  495. fieldName == sMountRot ) )
  496. {
  497. return false;
  498. }
  499. return true;
  500. }
  501. //-----------------------------------------------------------------------------
  502. static void scopeCallback( SceneObject* obj, void* conPtr )
  503. {
  504. NetConnection* ptr = reinterpret_cast< NetConnection* >( conPtr );
  505. if( obj->isScopeable() )
  506. ptr->objectInScope(obj);
  507. }
  508. void SceneObject::onCameraScopeQuery( NetConnection* connection, CameraScopeQuery* query )
  509. {
  510. // Object itself is in scope.
  511. if( this->isScopeable() )
  512. connection->objectInScope( this );
  513. // If we're mounted to something, that object is in scope too.
  514. if( isMounted() )
  515. connection->objectInScope( mMount.object );
  516. // If we're added to a scene graph, let the graph do the scene scoping.
  517. // Otherwise just put everything in the server container in scope.
  518. if( getSceneManager() )
  519. getSceneManager()->scopeScene( query, connection );
  520. else
  521. gServerContainer.findObjects( 0xFFFFFFFF, scopeCallback, connection );
  522. }
  523. //-----------------------------------------------------------------------------
  524. bool SceneObject::isRenderEnabled() const
  525. {
  526. AbstractClassRep *classRep = getClassRep();
  527. return ( mObjectFlags.test( RenderEnabledFlag ) && classRep->isRenderEnabled() );
  528. }
  529. //-----------------------------------------------------------------------------
  530. void SceneObject::setRenderEnabled( bool value )
  531. {
  532. if( value )
  533. mObjectFlags.set( RenderEnabledFlag );
  534. else
  535. mObjectFlags.clear( RenderEnabledFlag );
  536. setMaskBits( FlagMask );
  537. }
  538. //-----------------------------------------------------------------------------
  539. const char* SceneObject::_getRenderEnabled( void* object, const char* data )
  540. {
  541. SceneObject* obj = reinterpret_cast< SceneObject* >( object );
  542. if( obj->mObjectFlags.test( RenderEnabledFlag ) )
  543. return "true";
  544. else
  545. return "false";
  546. }
  547. //-----------------------------------------------------------------------------
  548. bool SceneObject::_setRenderEnabled( void *object, const char *index, const char *data )
  549. {
  550. SceneObject* obj = reinterpret_cast< SceneObject* >( object );
  551. obj->setRenderEnabled( dAtob( data ) );
  552. return false;
  553. }
  554. //-----------------------------------------------------------------------------
  555. bool SceneObject::isSelectionEnabled() const
  556. {
  557. AbstractClassRep *classRep = getClassRep();
  558. return ( mObjectFlags.test( SelectionEnabledFlag ) && classRep->isSelectionEnabled() );
  559. }
  560. //-----------------------------------------------------------------------------
  561. void SceneObject::setSelectionEnabled( bool value )
  562. {
  563. if( value )
  564. mObjectFlags.set( SelectionEnabledFlag );
  565. else
  566. mObjectFlags.clear( SelectionEnabledFlag );
  567. // Not synchronized on network so don't set dirty bit.
  568. }
  569. //-----------------------------------------------------------------------------
  570. const char* SceneObject::_getSelectionEnabled( void* object, const char* data )
  571. {
  572. SceneObject* obj = reinterpret_cast< SceneObject* >( object );
  573. if( obj->mObjectFlags.test( SelectionEnabledFlag ) )
  574. return "true";
  575. else
  576. return "false";
  577. }
  578. //-----------------------------------------------------------------------------
  579. bool SceneObject::_setSelectionEnabled( void *object, const char *index, const char *data )
  580. {
  581. SceneObject* obj = reinterpret_cast< SceneObject* >( object );
  582. obj->setSelectionEnabled( dAtob( data ) );
  583. return false;
  584. }
  585. //--------------------------------------------------------------------------
  586. U32 SceneObject::packUpdate( NetConnection* conn, U32 mask, BitStream* stream )
  587. {
  588. U32 retMask = Parent::packUpdate( conn, mask, stream );
  589. if ( stream->writeFlag( mask & FlagMask ) )
  590. stream->writeRangedU32( (U32)mObjectFlags, 0, getObjectFlagMax() );
  591. if ( mask & MountedMask )
  592. {
  593. if ( mMount.object )
  594. {
  595. S32 gIndex = conn->getGhostIndex( mMount.object );
  596. if ( stream->writeFlag( gIndex != -1 ) )
  597. {
  598. stream->writeFlag( true );
  599. stream->writeInt( gIndex, NetConnection::GhostIdBitSize );
  600. if ( stream->writeFlag( mMount.node != -1 ) )
  601. stream->writeInt( mMount.node, NumMountPointBits );
  602. mathWrite( *stream, mMount.xfm );
  603. }
  604. else
  605. // Will have to try again later
  606. retMask |= MountedMask;
  607. }
  608. else
  609. // Unmount if this isn't the initial packet
  610. if ( stream->writeFlag( !(mask & InitialUpdateMask) ) )
  611. stream->writeFlag( false );
  612. }
  613. else
  614. stream->writeFlag( false );
  615. return retMask;
  616. }
  617. //-----------------------------------------------------------------------------
  618. void SceneObject::unpackUpdate( NetConnection* conn, BitStream* stream )
  619. {
  620. Parent::unpackUpdate( conn, stream );
  621. // FlagMask
  622. if ( stream->readFlag() )
  623. mObjectFlags = stream->readRangedU32( 0, getObjectFlagMax() );
  624. // MountedMask
  625. if ( stream->readFlag() )
  626. {
  627. if ( stream->readFlag() )
  628. {
  629. S32 gIndex = stream->readInt( NetConnection::GhostIdBitSize );
  630. SceneObject* obj = dynamic_cast<SceneObject*>( conn->resolveGhost( gIndex ) );
  631. S32 node = -1;
  632. if ( stream->readFlag() ) // node != -1
  633. node = stream->readInt( NumMountPointBits );
  634. MatrixF xfm;
  635. mathRead( *stream, &xfm );
  636. if ( !obj )
  637. {
  638. conn->setLastError( "Invalid packet from server." );
  639. return;
  640. }
  641. obj->mountObject( this, node, xfm );
  642. }
  643. else
  644. unmount();
  645. }
  646. }
  647. //-----------------------------------------------------------------------------
  648. void SceneObject::_updateZoningState() const
  649. {
  650. if( mZoneRefDirty )
  651. {
  652. SceneZoneSpaceManager* manager = getSceneManager()->getZoneManager();
  653. if( manager )
  654. manager->updateObject( const_cast< SceneObject* >( this ) );
  655. else
  656. mZoneRefDirty = false;
  657. }
  658. }
  659. //-----------------------------------------------------------------------------
  660. U32 SceneObject::_getCurrZone( const U32 index ) const
  661. {
  662. _updateZoningState();
  663. // Not the most efficient way to do this, walking the list,
  664. // but it's an uncommon call...
  665. ZoneRef* walk = mZoneRefHead;
  666. for( U32 i = 0; i < index; ++ i )
  667. {
  668. walk = walk->nextInObj;
  669. AssertFatal( walk != NULL, "SceneObject::_getCurrZone - Too few object refs!" );
  670. }
  671. AssertFatal( walk != NULL, "SceneObject::_getCurrZone - Too few object refs!" );
  672. return walk->zone;
  673. }
  674. //-----------------------------------------------------------------------------
  675. Point3F SceneObject::getPosition() const
  676. {
  677. Point3F pos;
  678. mObjToWorld.getColumn(3, &pos);
  679. return pos;
  680. }
  681. //-----------------------------------------------------------------------------
  682. Point3F SceneObject::getRenderPosition() const
  683. {
  684. Point3F pos;
  685. mRenderObjToWorld.getColumn(3, &pos);
  686. return pos;
  687. }
  688. //-----------------------------------------------------------------------------
  689. void SceneObject::setPosition(const Point3F &pos)
  690. {
  691. AssertFatal( !mIsNaN( pos ), "SceneObject::setPosition() - The position is NaN!" );
  692. MatrixF xform = mObjToWorld;
  693. xform.setColumn(3, pos);
  694. setTransform(xform);
  695. }
  696. //-----------------------------------------------------------------------------
  697. F32 SceneObject::distanceTo(const Point3F &pnt) const
  698. {
  699. return mWorldBox.getDistanceToPoint( pnt );
  700. }
  701. //-----------------------------------------------------------------------------
  702. void SceneObject::processAfter( ProcessObject *obj )
  703. {
  704. AssertFatal( dynamic_cast<SceneObject*>( obj ), "SceneObject::processAfter - Got non-SceneObject!" );
  705. mAfterObject = (SceneObject*)obj;
  706. if ( mAfterObject->mAfterObject == this )
  707. mAfterObject->mAfterObject = NULL;
  708. getProcessList()->markDirty();
  709. }
  710. //-----------------------------------------------------------------------------
  711. void SceneObject::clearProcessAfter()
  712. {
  713. mAfterObject = NULL;
  714. }
  715. //-----------------------------------------------------------------------------
  716. void SceneObject::setProcessTick( bool t )
  717. {
  718. if ( t == mProcessTick )
  719. return;
  720. if ( mProcessTick )
  721. {
  722. plUnlink();
  723. mProcessTick = false;
  724. }
  725. else
  726. {
  727. // Just to be sure...
  728. plUnlink();
  729. getProcessList()->addObject( this );
  730. mProcessTick = true;
  731. }
  732. }
  733. //-----------------------------------------------------------------------------
  734. ProcessList* SceneObject::getProcessList() const
  735. {
  736. if ( isClientObject() )
  737. return ClientProcessList::get();
  738. else
  739. return ServerProcessList::get();
  740. }
  741. //-------------------------------------------------------------------------
  742. bool SceneObject::isMounted()
  743. {
  744. resolveMountPID();
  745. return mMount.object != NULL;
  746. }
  747. //-----------------------------------------------------------------------------
  748. S32 SceneObject::getMountedObjectCount()
  749. {
  750. S32 count = 0;
  751. for (SceneObject* itr = mMount.list; itr; itr = itr->mMount.link)
  752. count++;
  753. return count;
  754. }
  755. //-----------------------------------------------------------------------------
  756. SceneObject* SceneObject::getMountedObject(S32 idx)
  757. {
  758. if (idx >= 0) {
  759. S32 count = 0;
  760. for (SceneObject* itr = mMount.list; itr; itr = itr->mMount.link)
  761. if (count++ == idx)
  762. return itr;
  763. }
  764. return NULL;
  765. }
  766. //-----------------------------------------------------------------------------
  767. S32 SceneObject::getMountedObjectNode(S32 idx)
  768. {
  769. if (idx >= 0) {
  770. S32 count = 0;
  771. for (SceneObject* itr = mMount.list; itr; itr = itr->mMount.link)
  772. if (count++ == idx)
  773. return itr->mMount.node;
  774. }
  775. return -1;
  776. }
  777. //-----------------------------------------------------------------------------
  778. SceneObject* SceneObject::getMountNodeObject(S32 node)
  779. {
  780. for (SceneObject* itr = mMount.list; itr; itr = itr->mMount.link)
  781. if (itr->mMount.node == node)
  782. return itr;
  783. return NULL;
  784. }
  785. //-----------------------------------------------------------------------------
  786. bool SceneObject::_setMountPID( void* object, const char* index, const char* data )
  787. {
  788. SceneObject* so = static_cast<SceneObject*>( object );
  789. if ( so )
  790. {
  791. // Unmount old object (PID reference is released even if it had been resolved yet)
  792. if ( so->mMountPID )
  793. {
  794. so->mMountPID->decRefCount();
  795. so->mMountPID = NULL;
  796. }
  797. so->unmount();
  798. // Get the new PID (new object will be mounted on demand)
  799. Con::setData( TypePID, &so->mMountPID, 0, 1, &data );
  800. if ( so->mMountPID )
  801. so->mMountPID->incRefCount(); // Prevent PID from being deleted out from under us!
  802. }
  803. return false;
  804. }
  805. void SceneObject::resolveMountPID()
  806. {
  807. if ( mMountPID && !mMount.object )
  808. {
  809. SceneObject *obj = dynamic_cast< SceneObject* >( mMountPID->getObject() );
  810. if ( obj )
  811. obj->mountObject( this, mMount.node, mMount.xfm );
  812. }
  813. }
  814. //-----------------------------------------------------------------------------
  815. void SceneObject::mountObject( SceneObject *obj, S32 node, const MatrixF &xfm )
  816. {
  817. if ( obj->mMount.object == this )
  818. {
  819. // Already mounted to this
  820. // So update our node and xfm which may have changed.
  821. obj->mMount.node = node;
  822. obj->mMount.xfm = xfm;
  823. }
  824. else
  825. {
  826. if ( obj->mMount.object )
  827. obj->unmount();
  828. obj->mMount.object = this;
  829. obj->mMount.node = node;
  830. obj->mMount.link = mMount.list;
  831. obj->mMount.xfm = xfm;
  832. mMount.list = obj;
  833. // Assign PIDs to both objects
  834. if ( isServerObject() )
  835. {
  836. obj->getOrCreatePersistentId();
  837. if ( !obj->mMountPID )
  838. {
  839. obj->mMountPID = getOrCreatePersistentId();
  840. obj->mMountPID->incRefCount();
  841. }
  842. }
  843. obj->onMount( this, node );
  844. }
  845. }
  846. //-----------------------------------------------------------------------------
  847. void SceneObject::unmountObject( SceneObject *obj )
  848. {
  849. if ( obj->mMount.object == this )
  850. {
  851. // Find and unlink the object
  852. for ( SceneObject **ptr = &mMount.list; *ptr; ptr = &(*ptr)->mMount.link )
  853. {
  854. if ( *ptr == obj )
  855. {
  856. *ptr = obj->mMount.link;
  857. break;
  858. }
  859. }
  860. obj->mMount.object = NULL;
  861. obj->mMount.link = NULL;
  862. if( obj->mMountPID != NULL ) // Only on server.
  863. {
  864. obj->mMountPID->decRefCount();
  865. obj->mMountPID = NULL;
  866. }
  867. obj->onUnmount( this, obj->mMount.node );
  868. }
  869. }
  870. //-----------------------------------------------------------------------------
  871. void SceneObject::unmount()
  872. {
  873. if (mMount.object)
  874. mMount.object->unmountObject(this);
  875. }
  876. //-----------------------------------------------------------------------------
  877. void SceneObject::onMount( SceneObject *obj, S32 node )
  878. {
  879. deleteNotify( obj );
  880. if ( !isGhost() )
  881. {
  882. setMaskBits( MountedMask );
  883. //onMount_callback( node );
  884. }
  885. }
  886. //-----------------------------------------------------------------------------
  887. void SceneObject::onUnmount( SceneObject *obj, S32 node )
  888. {
  889. clearNotify(obj);
  890. if ( !isGhost() )
  891. {
  892. setMaskBits( MountedMask );
  893. //onUnmount_callback( node );
  894. }
  895. }
  896. //-----------------------------------------------------------------------------
  897. void SceneObject::getMountTransform( S32 index, const MatrixF &xfm, MatrixF *outMat )
  898. {
  899. MatrixF mountTransform( xfm );
  900. const Point3F &scale = getScale();
  901. Point3F position = mountTransform.getPosition();
  902. position.convolve( scale );
  903. mountTransform.setPosition( position );
  904. outMat->mul( mObjToWorld, mountTransform );
  905. }
  906. //-----------------------------------------------------------------------------
  907. void SceneObject::getRenderMountTransform( F32 delta, S32 index, const MatrixF &xfm, MatrixF *outMat )
  908. {
  909. MatrixF mountTransform( xfm );
  910. const Point3F &scale = getScale();
  911. Point3F position = mountTransform.getPosition();
  912. position.convolve( scale );
  913. mountTransform.setPosition( position );
  914. outMat->mul( mRenderObjToWorld, mountTransform );
  915. }
  916. //=============================================================================
  917. // Console API.
  918. //=============================================================================
  919. // MARK: ---- Console API ----
  920. //-----------------------------------------------------------------------------
  921. DefineEngineMethod( SceneObject, getType, S32, (),,
  922. "Return the type mask for this object.\n"
  923. "@return The numeric type mask for the object." )
  924. {
  925. return object->getTypeMask();
  926. }
  927. //-----------------------------------------------------------------------------
  928. DefineEngineMethod( SceneObject, mountObject, bool,
  929. ( SceneObject* objB, S32 slot, TransformF txfm ), ( MatrixF::Identity ),
  930. "@brief Mount objB to this object at the desired slot with optional transform.\n\n"
  931. "@param objB Object to mount onto us\n"
  932. "@param slot Mount slot ID\n"
  933. "@param txfm (optional) mount offset transform\n"
  934. "@return true if successful, false if failed (objB is not valid)" )
  935. {
  936. if ( objB )
  937. {
  938. object->mountObject( objB, slot, txfm.getMatrix() );
  939. return true;
  940. }
  941. return false;
  942. }
  943. //-----------------------------------------------------------------------------
  944. DefineEngineMethod( SceneObject, unmountObject, bool, ( SceneObject* target ),,
  945. "@brief Unmount an object from ourselves.\n\n"
  946. "@param target object to unmount\n"
  947. "@return true if successful, false if failed\n" )
  948. {
  949. if ( target )
  950. {
  951. object->unmountObject(target);
  952. return true;
  953. }
  954. return false;
  955. }
  956. //-----------------------------------------------------------------------------
  957. DefineEngineMethod( SceneObject, unmount, void, (),,
  958. "Unmount us from the currently mounted object if any.\n" )
  959. {
  960. object->unmount();
  961. }
  962. //-----------------------------------------------------------------------------
  963. DefineEngineMethod( SceneObject, isMounted, bool, (),,
  964. "@brief Check if we are mounted to another object.\n\n"
  965. "@return true if mounted to another object, false if not mounted." )
  966. {
  967. return object->isMounted();
  968. }
  969. //-----------------------------------------------------------------------------
  970. DefineEngineMethod( SceneObject, getObjectMount, S32, (),,
  971. "@brief Get the object we are mounted to.\n\n"
  972. "@return the SimObjectID of the object we're mounted to, or 0 if not mounted." )
  973. {
  974. return object->isMounted()? object->getObjectMount()->getId(): 0;
  975. }
  976. //-----------------------------------------------------------------------------
  977. DefineEngineMethod( SceneObject, getMountedObjectCount, S32, (),,
  978. "Get the number of objects mounted to us.\n"
  979. "@return the number of mounted objects." )
  980. {
  981. return object->getMountedObjectCount();
  982. }
  983. //-----------------------------------------------------------------------------
  984. DefineEngineMethod( SceneObject, getMountedObject, S32, ( S32 slot ),,
  985. "Get the object mounted at a particular slot.\n"
  986. "@param slot mount slot index to query\n"
  987. "@return ID of the object mounted in the slot, or 0 if no object." )
  988. {
  989. SceneObject* mobj = object->getMountedObject( slot );
  990. return mobj? mobj->getId(): 0;
  991. }
  992. //-----------------------------------------------------------------------------
  993. DefineEngineMethod( SceneObject, getMountedObjectNode, S32, ( S32 slot ),,
  994. "@brief Get the mount node index of the object mounted at our given slot.\n\n"
  995. "@param slot mount slot index to query\n"
  996. "@return index of the mount node used by the object mounted in this slot." )
  997. {
  998. return object->getMountedObjectNode( slot );
  999. }
  1000. //-----------------------------------------------------------------------------
  1001. DefineEngineMethod( SceneObject, getMountNodeObject, S32, ( S32 node ),,
  1002. "@brief Get the object mounted at our given node index.\n\n"
  1003. "@param node mount node index to query\n"
  1004. "@return ID of the first object mounted at the node, or 0 if none found." )
  1005. {
  1006. SceneObject* mobj = object->getMountNodeObject( node );
  1007. return mobj? mobj->getId(): 0;
  1008. }
  1009. //-----------------------------------------------------------------------------
  1010. DefineEngineMethod( SceneObject, getTransform, TransformF, (),,
  1011. "Get the object's transform.\n"
  1012. "@return the current transform of the object\n" )
  1013. {
  1014. return object->getTransform();
  1015. }
  1016. //-----------------------------------------------------------------------------
  1017. DefineEngineMethod( SceneObject, getInverseTransform, TransformF, (),,
  1018. "Get the object's inverse transform.\n"
  1019. "@return the inverse transform of the object\n" )
  1020. {
  1021. return object->getWorldTransform();
  1022. }
  1023. //-----------------------------------------------------------------------------
  1024. DefineEngineMethod( SceneObject, getPosition, Point3F, (),,
  1025. "Get the object's world position.\n"
  1026. "@return the current world position of the object\n" )
  1027. {
  1028. return object->getTransform().getPosition();
  1029. }
  1030. //-----------------------------------------------------------------------------
  1031. DefineEngineMethod( SceneObject, getEulerRotation, Point3F, (),,
  1032. "Get Euler rotation of this object.\n"
  1033. "@return the orientation of the object in the form of rotations around the "
  1034. "X, Y and Z axes in degrees.\n" )
  1035. {
  1036. Point3F euler = object->getTransform().toEuler();
  1037. // Convert to degrees.
  1038. euler.x = mRadToDeg( euler.x );
  1039. euler.y = mRadToDeg( euler.y );
  1040. euler.z = mRadToDeg( euler.z );
  1041. return euler;
  1042. }
  1043. //-----------------------------------------------------------------------------
  1044. DefineEngineMethod( SceneObject, getForwardVector, VectorF, (),,
  1045. "Get the direction this object is facing.\n"
  1046. "@return a vector indicating the direction this object is facing.\n"
  1047. "@note This is the object's y axis." )
  1048. {
  1049. return object->getTransform().getForwardVector();
  1050. }
  1051. //-----------------------------------------------------------------------------
  1052. DefineEngineMethod( SceneObject, getRightVector, VectorF, (),,
  1053. "Get the right vector of the object.\n"
  1054. "@return a vector indicating the right direction of this object."
  1055. "@note This is the object's x axis." )
  1056. {
  1057. return object->getTransform().getRightVector();
  1058. }
  1059. //-----------------------------------------------------------------------------
  1060. DefineEngineMethod( SceneObject, getUpVector, VectorF, (),,
  1061. "Get the up vector of the object.\n"
  1062. "@return a vector indicating the up direction of this object."
  1063. "@note This is the object's z axis." )
  1064. {
  1065. return object->getTransform().getUpVector();
  1066. }
  1067. //-----------------------------------------------------------------------------
  1068. DefineEngineMethod( SceneObject, setTransform, void, ( TransformF txfm ),,
  1069. "Set the object's transform (orientation and position)."
  1070. "@param txfm object transform to set" )
  1071. {
  1072. if ( !txfm.hasRotation() )
  1073. object->setPosition( txfm.getPosition() );
  1074. else
  1075. object->setTransform( txfm.getMatrix() );
  1076. }
  1077. //-----------------------------------------------------------------------------
  1078. DefineEngineMethod( SceneObject, getScale, Point3F, (),,
  1079. "Get the object's scale.\n"
  1080. "@return object scale as a Point3F" )
  1081. {
  1082. return object->getScale();
  1083. }
  1084. //-----------------------------------------------------------------------------
  1085. DefineEngineMethod( SceneObject, setScale, void, ( Point3F scale ),,
  1086. "Set the object's scale.\n"
  1087. "@param scale object scale to set\n" )
  1088. {
  1089. object->setScale( scale );
  1090. }
  1091. //-----------------------------------------------------------------------------
  1092. DefineEngineMethod( SceneObject, getWorldBox, Box3F, (),,
  1093. "Get the object's world bounding box.\n"
  1094. "@return six fields, two Point3Fs, containing the min and max points of the "
  1095. "worldbox." )
  1096. {
  1097. return object->getWorldBox();
  1098. }
  1099. //-----------------------------------------------------------------------------
  1100. DefineEngineMethod( SceneObject, getWorldBoxCenter, Point3F, (),,
  1101. "Get the center of the object's world bounding box.\n"
  1102. "@return the center of the world bounding box for this object." )
  1103. {
  1104. Point3F center;
  1105. object->getWorldBox().getCenter( &center );
  1106. return center;
  1107. }
  1108. //-----------------------------------------------------------------------------
  1109. DefineEngineMethod( SceneObject, getObjectBox, Box3F, (),,
  1110. "Get the object's bounding box (relative to the object's origin).\n"
  1111. "@return six fields, two Point3Fs, containing the min and max points of the "
  1112. "objectbox." )
  1113. {
  1114. return object->getObjBox();
  1115. }
  1116. //-----------------------------------------------------------------------------
  1117. DefineEngineMethod( SceneObject, isGlobalBounds, bool, (),,
  1118. "Check if this object has a global bounds set.\n"
  1119. "If global bounds are set to be true, then the object is assumed to have an "
  1120. "infinitely large bounding box for collision and rendering purposes.\n"
  1121. "@return true if the object has a global bounds." )
  1122. {
  1123. return object->isGlobalBounds();
  1124. }