sceneObject.cpp 44 KB

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