sceneObject.cpp 43 KB

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