sceneObject.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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. #ifndef _SCENEOBJECT_H_
  23. #define _SCENEOBJECT_H_
  24. #ifndef _NETOBJECT_H_
  25. #include "sim/netObject.h"
  26. #endif
  27. #ifndef _COLLISION_H_
  28. #include "collision/collision.h"
  29. #endif
  30. #ifndef _OBJECTTYPES_H_
  31. #include "T3D/objectTypes.h"
  32. #endif
  33. #ifndef _COLOR_H_
  34. #include "core/color.h"
  35. #endif
  36. #ifndef _BITSET_H_
  37. #include "core/bitSet.h"
  38. #endif
  39. #ifndef _PROCESSLIST_H_
  40. #include "T3D/gameBase/processList.h"
  41. #endif
  42. #ifndef _SCENECONTAINER_H_
  43. #include "scene/sceneContainer.h"
  44. #endif
  45. class SceneManager;
  46. class SceneRenderState;
  47. class SceneTraversalState;
  48. class SceneCameraState;
  49. class SceneObjectLink;
  50. class SceneObjectLightingPlugin;
  51. class Convex;
  52. class LightInfo;
  53. class SFXAmbience;
  54. struct ObjectRenderInst;
  55. struct Move;
  56. /// A 3D object.
  57. ///
  58. /// @section SceneObject_intro Introduction
  59. ///
  60. /// SceneObject exists as a foundation for 3D objects in Torque. It provides the
  61. /// basic functionality for:
  62. /// - A scene graph (in the Zones and Portals sections), allowing efficient
  63. /// and robust rendering of the game scene.
  64. /// - Various helper functions, including functions to get bounding information
  65. /// and momentum/velocity.
  66. /// - Collision detection, as well as ray casting.
  67. /// - Lighting. SceneObjects can register lights both at lightmap generation time,
  68. /// and dynamic lights at runtime (for special effects, such as from flame or
  69. /// a projectile, or from an explosion).
  70. /// - Manipulating scene objects, for instance varying scale.
  71. ///
  72. /// @section SceneObject_example An Example
  73. ///
  74. /// Melv May has written a most marvelous example object deriving from SceneObject.
  75. /// Unfortunately this page is too small to contain it.
  76. ///
  77. /// @see http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3217
  78. /// for a copy of Melv's example.
  79. class SceneObject : public NetObject, private SceneContainer::Link, public ProcessObject
  80. {
  81. public:
  82. typedef NetObject Parent;
  83. friend class SceneManager;
  84. friend class SceneContainer;
  85. friend class SceneZoneSpaceManager;
  86. friend class SceneCullingState; // _getZoneRefHead
  87. friend class SceneObjectLink; // mSceneObjectLinks
  88. enum
  89. {
  90. /// Maximum number of zones that an object can concurrently be assigned to.
  91. MaxObjectZones = 128,
  92. NumMountPoints = 32,
  93. NumMountPointBits = 5,
  94. };
  95. /// Networking dirty mask.
  96. enum SceneObjectMasks
  97. {
  98. InitialUpdateMask = BIT( 0 ),
  99. ScaleMask = BIT( 1 ),
  100. FlagMask = BIT( 2 ),
  101. MountedMask = BIT( 3 ),
  102. NextFreeMask = BIT( 4 )
  103. };
  104. /// Bit-flags stored in mObjectFlags.
  105. /// If a derived class adds more flags they must overload
  106. /// getObjectFlagMax to ensure those flags will be transmitted over
  107. /// the network.
  108. /// @see getObjectFlagMax
  109. enum SceneObjectFlags
  110. {
  111. /// If set, the object can be rendered.
  112. /// @note The per-class render disable flag can override the per-object flag.
  113. RenderEnabledFlag = BIT( 0 ),
  114. /// If set, the object can be selected in the editor.
  115. /// @note The per-class selection disable flag can override the per-object flag.
  116. SelectionEnabledFlag = BIT( 1 ),
  117. /// If set, object will not be subjected to culling when in the editor.
  118. /// This is useful to bypass zone culling and always render certain editor-only
  119. /// visual elements (like the zones themselves).
  120. DisableCullingInEditorFlag = BIT( 2 ),
  121. /// If set, object will be used as a visual occluder. In this case,
  122. /// the object should implement buildSilhouette() and return a
  123. /// *convex* silhouette polygon.
  124. VisualOccluderFlag = BIT( 3 ),
  125. /// If set, object will be used as a sound occluder.
  126. SoundOccluderFlag = BIT( 4 ),
  127. NextFreeFlag = BIT( 5 )
  128. };
  129. protected:
  130. /// Combination of SceneObjectFlags.
  131. BitSet32 mObjectFlags;
  132. /// SceneManager to which this SceneObject belongs.
  133. SceneManager* mSceneManager;
  134. /// Links installed by SceneTrackers attached to this object.
  135. SceneObjectLink* mSceneObjectLinks;
  136. /// SceneObjectLightingPlugin attached to this object.
  137. SceneObjectLightingPlugin* mLightPlugin;
  138. /// Object type mask.
  139. /// @see SimObjectTypes
  140. U32 mTypeMask;
  141. /// @name Mounting
  142. /// @{
  143. /// Mounted object.
  144. struct MountInfo
  145. {
  146. SceneObject* list; ///< Linked-list of objects mounted on this object
  147. SceneObject* object; ///< Object this object is mounted on.
  148. SceneObject* link; ///< Link to next object mounted to this object's mount
  149. S32 node; ///< Node point we are mounted to.
  150. MatrixF xfm;
  151. };
  152. ///
  153. MountInfo mMount;
  154. ///
  155. SimPersistID* mMountPID;
  156. /// @}
  157. /// @name Zoning
  158. /// @{
  159. /// Bidirectional link between a zone manager and its objects.
  160. struct ZoneRef : public SceneObjectRefBase< ZoneRef >
  161. {
  162. /// ID of zone.
  163. U32 zone;
  164. };
  165. /// Iterator over the zones that the object is assigned to.
  166. /// @note This iterator expects a clean zoning state. It will not update the
  167. /// zoning state in case it is dirty.
  168. struct ObjectZonesIterator
  169. {
  170. ObjectZonesIterator( SceneObject* object )
  171. : mCurrent( object->_getZoneRefHead() ) {}
  172. bool isValid() const
  173. {
  174. return ( mCurrent != NULL );
  175. }
  176. ObjectZonesIterator& operator ++()
  177. {
  178. AssertFatal( isValid(), "SceneObject::ObjectZonesIterator::operator++ - Invalid iterator!" );
  179. mCurrent = mCurrent->nextInObj;
  180. return *this;
  181. }
  182. U32 operator *() const
  183. {
  184. AssertFatal( isValid(), "SceneObject::ObjectZonesIterator::operator* - Invalid iterator!" );
  185. return mCurrent->zone;
  186. }
  187. private:
  188. ZoneRef* mCurrent;
  189. };
  190. friend struct ObjectZonesIterator;
  191. /// If an object moves, its zoning state needs to be updated. This is deferred
  192. /// to when the state is actually needed and this flag indicates a refresh
  193. /// is necessary.
  194. mutable bool mZoneRefDirty;
  195. /// Number of zones this object is assigned to.
  196. /// @note If #mZoneRefDirty is set, this might be outdated.
  197. mutable U32 mNumCurrZones;
  198. /// List of zones that this object is part of.
  199. /// @note If #mZoneRefDirty is set, this might be outdated.
  200. mutable ZoneRef* mZoneRefHead;
  201. /// Refresh the zoning state of this object, if it isn't up-to-date anymore.
  202. void _updateZoningState() const;
  203. /// Return the first link in the zone list of this object. Each link represents
  204. /// a single zone that the object is assigned to.
  205. ///
  206. /// @note This method will return the zoning list as is. In case the zoning state
  207. /// of the object is dirty, the list contents may be outdated.
  208. ZoneRef* _getZoneRefHead() const { return mZoneRefHead; }
  209. /// Gets the number of zones containing this object.
  210. U32 _getNumCurrZones() const { return mNumCurrZones; }
  211. /// Returns the nth zone containing this object.
  212. U32 _getCurrZone( const U32 index ) const;
  213. /// @}
  214. /// @name Transform and Collision Members
  215. /// @{
  216. /// Transform from object space to world space.
  217. MatrixF mObjToWorld;
  218. /// Transform from world space to object space (inverse).
  219. MatrixF mWorldToObj;
  220. /// Object scale.
  221. Point3F mObjScale;
  222. /// Bounding box in object space.
  223. Box3F mObjBox;
  224. /// Bounding box (AABB) in world space.
  225. Box3F mWorldBox;
  226. /// Bounding sphere in world space.
  227. SphereF mWorldSphere;
  228. /// Render matrix to transform object space to world space.
  229. MatrixF mRenderObjToWorld;
  230. /// Render matrix to transform world space to object space.
  231. MatrixF mRenderWorldToObj;
  232. /// Render bounding box in world space.
  233. Box3F mRenderWorldBox;
  234. /// Render bounding sphere in world space.
  235. SphereF mRenderWorldSphere;
  236. /// Whether this object is considered to have an infinite bounding box.
  237. bool mGlobalBounds;
  238. ///
  239. S32 mCollisionCount;
  240. /// Regenerates the world-space bounding box and bounding sphere.
  241. void resetWorldBox();
  242. /// Regenerates the render-world-space bounding box and sphere.
  243. void resetRenderWorldBox();
  244. /// Regenerates the object-space bounding box from the world-space
  245. /// bounding box, the world space to object space transform, and
  246. /// the object scale.
  247. void resetObjectBox();
  248. /// Called when the size of the object changes.
  249. virtual void onScaleChanged() {}
  250. /// @}
  251. /// Object which must be ticked before this object.
  252. SimObjectPtr< SceneObject > mAfterObject;
  253. /// @name SceneContainer Interface
  254. ///
  255. /// When objects are searched, we go through all the zones and ask them for
  256. /// all of their objects. Because an object can exist in multiple zones, the
  257. /// container sequence key is set to the id of the current search. Then, while
  258. /// searching, we check to see if an object's sequence key is the same as the
  259. /// current search key. If it is, it will NOT be added to the list of returns
  260. /// since it has already been processed.
  261. ///
  262. /// @{
  263. /// Container database that the object is assigned to.
  264. SceneContainer* mContainer;
  265. /// SceneContainer sequence key.
  266. U32 mContainerSeqKey;
  267. ///
  268. SceneObjectRef* mBinRefHead;
  269. U32 mBinMinX;
  270. U32 mBinMaxX;
  271. U32 mBinMinY;
  272. U32 mBinMaxY;
  273. /// Returns the container sequence key.
  274. U32 getContainerSeqKey() const { return mContainerSeqKey; }
  275. /// Sets the container sequence key.
  276. void setContainerSeqKey( const U32 key ) { mContainerSeqKey = key; }
  277. /// @}
  278. /// Called when this is added to a SceneManager.
  279. virtual bool onSceneAdd() { return true; }
  280. /// Called when this is removed from its current SceneManager.
  281. virtual void onSceneRemove() {}
  282. /// Returns the greatest object flag bit defined.
  283. /// Only bits within this range will be transmitted over the network.
  284. virtual U32 getObjectFlagMax() const { return NextFreeFlag - 1; }
  285. public:
  286. SceneObject();
  287. virtual ~SceneObject();
  288. /// Triggered when a SceneObject onAdd is called.
  289. static Signal< void( SceneObject* ) > smSceneObjectAdd;
  290. /// Triggered when a SceneObject onRemove is called.
  291. static Signal< void( SceneObject* ) > smSceneObjectRemove;
  292. /// Return the type mask that indicates to which broad object categories
  293. /// this object belongs.
  294. U32 getTypeMask() const { return mTypeMask; }
  295. /// @name SceneManager Functionality
  296. /// @{
  297. /// Return the SceneManager that this SceneObject belongs to.
  298. SceneManager* getSceneManager() const { return mSceneManager; }
  299. /// Adds object to the client or server container depending on the object
  300. void addToScene();
  301. /// Removes the object from the client/server container
  302. void removeFromScene();
  303. /// Returns a pointer to the container that contains this object
  304. SceneContainer* getContainer() { return mContainer; }
  305. /// @}
  306. /// @name Flags
  307. /// @{
  308. /// Return true if this object is rendered.
  309. bool isRenderEnabled() const;
  310. /// Set whether the object gets rendered.
  311. void setRenderEnabled( bool value );
  312. /// Return true if this object can be selected in the editor.
  313. bool isSelectionEnabled() const;
  314. /// Set whether the object can be selected in the editor.
  315. void setSelectionEnabled( bool value );
  316. /// Return true if the object doesn't want to be subjected to culling
  317. /// when in the editor.
  318. bool isCullingDisabledInEditor() const { return mObjectFlags.test( DisableCullingInEditorFlag ); }
  319. /// Return true if the object should be taken into account for visual occlusion.
  320. bool isVisualOccluder() const { return mObjectFlags.test( VisualOccluderFlag ); }
  321. /// @}
  322. /// @name Collision and transform related interface
  323. ///
  324. /// The Render Transform is the interpolated transform with respect to the
  325. /// frame rate. The Render Transform will differ from the object transform
  326. /// because the simulation is updated in fixed intervals, which controls the
  327. /// object transform. The framerate is, most likely, higher than this rate,
  328. /// so that is why the render transform is interpolated and will differ slightly
  329. /// from the object transform.
  330. ///
  331. /// @{
  332. /// Disables collisions for this object including raycasts
  333. virtual void disableCollision();
  334. /// Enables collisions for this object
  335. virtual void enableCollision();
  336. /// Returns true if collisions are enabled
  337. bool isCollisionEnabled() const { return mCollisionCount == 0; }
  338. /// This gets called when an object collides with this object.
  339. /// @param object Object colliding with this object
  340. /// @param vec Vector along which collision occurred
  341. virtual void onCollision( SceneObject *object, const VectorF &vec ) {}
  342. /// Returns true if this object allows itself to be displaced
  343. /// @see displaceObject
  344. virtual bool isDisplacable() const { return false; }
  345. /// Returns the momentum of this object
  346. virtual Point3F getMomentum() const { return Point3F( 0, 0, 0 ); }
  347. /// Sets the momentum of this object
  348. /// @param momentum Momentum
  349. virtual void setMomentum( const Point3F& momentum ) {}
  350. /// Returns the mass of this object
  351. virtual F32 getMass() const { return 1.f; }
  352. /// Displaces this object by a vector
  353. /// @param displaceVector Displacement vector
  354. virtual bool displaceObject( const Point3F& displaceVector ) { return false; }
  355. /// Returns the transform which can be used to convert object space
  356. /// to world space
  357. virtual const MatrixF& getTransform() const { return mObjToWorld; }
  358. /// Returns the transform which can be used to convert world space
  359. /// into object space
  360. const MatrixF& getWorldTransform() const { return mWorldToObj; }
  361. /// Returns the scale of the object
  362. const VectorF& getScale() const { return mObjScale; }
  363. /// Returns the bounding box for this object in local coordinates.
  364. const Box3F& getObjBox() const { return mObjBox; }
  365. /// Returns the bounding box for this object in world coordinates.
  366. const Box3F& getWorldBox() const { return mWorldBox; }
  367. /// Returns the bounding sphere for this object in world coordinates.
  368. const SphereF& getWorldSphere() const { return mWorldSphere; }
  369. /// Returns the center of the bounding box in world coordinates
  370. Point3F getBoxCenter() const { return ( mWorldBox.minExtents + mWorldBox.maxExtents ) * 0.5f; }
  371. /// Sets the Object -> World transform
  372. ///
  373. /// @param mat New transform matrix
  374. virtual void setTransform( const MatrixF &mat );
  375. /// Sets the scale for the object
  376. /// @param scale Scaling values
  377. virtual void setScale( const VectorF &scale );
  378. /// This sets the render transform for this object
  379. /// @param mat New render transform
  380. virtual void setRenderTransform(const MatrixF &mat);
  381. /// Returns the render transform
  382. const MatrixF& getRenderTransform() const { return mRenderObjToWorld; }
  383. /// Returns the render transform to convert world to local coordinates
  384. const MatrixF& getRenderWorldTransform() const { return mRenderWorldToObj; }
  385. /// Returns the render world box
  386. const Box3F& getRenderWorldBox() const { return mRenderWorldBox; }
  387. /// Sets the state of this object as hidden or not. If an object is hidden
  388. /// it is removed entirely from collisions, it is not ghosted and is
  389. /// essentially "non existant" as far as simulation is concerned.
  390. /// @param hidden True if object is to be hidden
  391. virtual void setHidden( bool hidden );
  392. /// Builds a convex hull for this object.
  393. ///
  394. /// Think of a convex hull as a low-res mesh which covers, as tightly as
  395. /// possible, the object mesh, and is used as a collision mesh.
  396. /// @param box
  397. /// @param convex Convex mesh generated (out)
  398. virtual void buildConvex( const Box3F& box,Convex* convex ) {}
  399. /// Builds a list of polygons which intersect a bounding volume.
  400. ///
  401. /// This will use either the sphere or the box, not both, the
  402. /// SceneObject implementation ignores sphere.
  403. ///
  404. /// @see AbstractPolyList
  405. /// @param context A contentual hint as to the type of polylist to build.
  406. /// @param polyList Poly list build (out)
  407. /// @param box Box bounding volume
  408. /// @param sphere Sphere bounding volume
  409. ///
  410. virtual bool buildPolyList( PolyListContext context,
  411. AbstractPolyList* polyList,
  412. const Box3F& box,
  413. const SphereF& sphere ) { return false; }
  414. /// Casts a ray and obtain collision information, returns true if RayInfo is modified.
  415. ///
  416. /// @param start Start point of ray
  417. /// @param end End point of ray
  418. /// @param info Collision information obtained (out)
  419. virtual bool castRay( const Point3F& start, const Point3F& end, RayInfo* info ) { return false; }
  420. /// Casts a ray against rendered geometry, returns true if RayInfo is modified.
  421. ///
  422. /// @param start Start point of ray
  423. /// @param end End point of ray
  424. /// @param info Collision information obtained (out)
  425. virtual bool castRayRendered( const Point3F& start, const Point3F& end, RayInfo* info );
  426. /// Build a world-space silhouette polygon for the object for the given camera settings.
  427. /// This is used for occlusion.
  428. ///
  429. /// @param cameraState Camera view parameters.
  430. /// @param outPoints Vector to store the resulting polygon points in. Leave untouched
  431. /// if method is not implemented.
  432. virtual void buildSilhouette( const SceneCameraState& cameraState, Vector< Point3F >& outPoints ) {}
  433. /// Return true if the given point is contained by the object's (collision) shape.
  434. ///
  435. /// The default implementation will return true if the point is within the object's
  436. /// bounding box. Subclasses should implement more precise tests.
  437. virtual bool containsPoint( const Point3F &point );
  438. virtual bool collideBox( const Point3F& start, const Point3F& end, RayInfo* info );
  439. /// Returns the position of the object.
  440. virtual Point3F getPosition() const;
  441. /// Returns the render-position of the object.
  442. ///
  443. /// @see getRenderTransform
  444. Point3F getRenderPosition() const;
  445. /// Sets the position of the object
  446. void setPosition ( const Point3F& pos );
  447. /// Gets the velocity of the object.
  448. virtual Point3F getVelocity() const { return Point3F::Zero; }
  449. /// Sets the velocity of the object
  450. /// @param v Velocity
  451. virtual void setVelocity( const Point3F &v ) {}
  452. /// Applies an impulse force to this object
  453. /// @param pos Position where impulse came from in world space
  454. /// @param vec Velocity vector (Impulse force F = m * v)
  455. virtual void applyImpulse( const Point3F &pos, const VectorF &vec ) {}
  456. /// Applies a radial impulse to the object
  457. /// using the impulse origin and force.
  458. /// @param origin Point of origin of the radial impulse.
  459. /// @param radius The radius of the impulse area.
  460. /// @param magnitude The strength of the impulse.
  461. virtual void applyRadialImpulse( const Point3F &origin, F32 radius, F32 magnitude ) {}
  462. /// Returns the distance from this object to a point
  463. /// @param pnt World space point to measure to
  464. virtual F32 distanceTo( const Point3F &pnt ) const;
  465. /// @}
  466. /// @name Mounting
  467. /// @{
  468. /// ex: Mount B to A at A's node N
  469. /// A.mountObject( B, N )
  470. ///
  471. /// @param obj Object to mount
  472. /// @param node Mount node ID
  473. virtual void mountObject( SceneObject *obj, S32 node, const MatrixF &xfm = MatrixF::Identity );
  474. /// Remove an object mounting
  475. /// @param obj Object to unmount
  476. virtual void unmountObject( SceneObject *obj );
  477. /// Unmount this object from it's mount
  478. virtual void unmount();
  479. /// Callback when this object is mounted.
  480. /// @param obj Object we are mounting to.
  481. /// @param node Node we are unmounting from.
  482. virtual void onMount( SceneObject *obj, S32 node );
  483. /// Callback when this object is unmounted. This should be overridden to
  484. /// set maskbits or do other object type specific work.
  485. /// @param obj Object we are unmounting from.
  486. /// @param node Node we are unmounting from.
  487. virtual void onUnmount( SceneObject *obj, S32 node );
  488. // Returns mount point to world space transform at tick time.
  489. virtual void getMountTransform( S32 index, const MatrixF &xfm, MatrixF *outMat );
  490. // Returns mount point to world space transform at render time.
  491. // Note this will only be correct if called after this object has interpolated.
  492. virtual void getRenderMountTransform( F32 delta, S32 index, const MatrixF &xfm, MatrixF *outMat );
  493. /// Return the object that this object is mounted to.
  494. virtual SceneObject* getObjectMount() { return mMount.object; }
  495. /// Return object link of next object mounted to this object's mount
  496. virtual SceneObject* getMountLink() { return mMount.link; }
  497. /// Returns object list of objects mounted to this object.
  498. virtual SceneObject* getMountList() { return mMount.list; }
  499. /// Returns the mount id that this is mounted to.
  500. virtual U32 getMountNode() { return mMount.node; }
  501. /// Returns true if this object is mounted to anything at all
  502. /// Also try to resolve the PID to objectId here if it is pending.
  503. virtual bool isMounted();
  504. /// Returns the number of object mounted along with this
  505. virtual S32 getMountedObjectCount();
  506. /// Returns the object mounted at a position in the mount list
  507. /// @param idx Position on the mount list
  508. virtual SceneObject* getMountedObject( S32 idx );
  509. /// Returns the node the object at idx is mounted to
  510. /// @param idx Index
  511. virtual S32 getMountedObjectNode( S32 idx );
  512. /// Returns the object a object on the mount list is mounted to
  513. /// @param node
  514. virtual SceneObject* getMountNodeObject( S32 node );
  515. void resolveMountPID();
  516. /// @}
  517. /// @name Sound
  518. /// @{
  519. /// Return whether the object's collision shape is blocking sound.
  520. bool isOccludingSound() const { return mObjectFlags.test( SoundOccluderFlag ); }
  521. /// Return the ambient sound space active inside the volume of this object or NULL if the object does
  522. /// not have its own ambient space.
  523. virtual SFXAmbience* getSoundAmbience() const { return NULL; }
  524. /// @}
  525. /// @name Rendering
  526. /// @{
  527. /// Called when the SceneManager is ready for the registration of render instances.
  528. /// @param state Rendering state.
  529. virtual void prepRenderImage( SceneRenderState* state ) {}
  530. /// @}
  531. /// @name Lighting
  532. /// @{
  533. void setLightingPlugin( SceneObjectLightingPlugin* plugin ) { mLightPlugin = plugin; }
  534. SceneObjectLightingPlugin* getLightingPlugin() { return mLightPlugin; }
  535. /// @}
  536. /// @name Global Bounds
  537. /// @{
  538. const bool isGlobalBounds() const
  539. {
  540. return mGlobalBounds;
  541. }
  542. /// If global bounds are set to be true, then the object is assumed to
  543. /// have an infinitely large bounding box for collision and rendering
  544. /// purposes.
  545. ///
  546. /// They can't be toggled currently.
  547. void setGlobalBounds();
  548. /// @}
  549. /// Return the ProcessList for this object to use.
  550. ProcessList* getProcessList() const;
  551. // ProcessObject,
  552. virtual void processAfter( ProcessObject *obj );
  553. virtual void clearProcessAfter();
  554. virtual ProcessObject* getAfterObject() const { return mAfterObject; }
  555. virtual void setProcessTick( bool t );
  556. // NetObject.
  557. virtual U32 packUpdate( NetConnection* conn, U32 mask, BitStream* stream );
  558. virtual void unpackUpdate( NetConnection* conn, BitStream* stream );
  559. virtual void onCameraScopeQuery( NetConnection* connection, CameraScopeQuery* query );
  560. // SimObject.
  561. virtual bool onAdd();
  562. virtual void onRemove();
  563. virtual void onDeleteNotify( SimObject *object );
  564. virtual void inspectPostApply();
  565. virtual bool writeField( StringTableEntry fieldName, const char* value );
  566. static void initPersistFields();
  567. DECLARE_CONOBJECT( SceneObject );
  568. private:
  569. SceneObject( const SceneObject& ); ///< @deprecated disallowed
  570. /// For ScopeAlways objects to be able to properly implement setHidden(), they
  571. /// need to temporarily give up ScopeAlways status while being hidden. Otherwise
  572. /// the client-side ghost will not disappear as the server-side object will be
  573. /// forced to stay in scope.
  574. bool mIsScopeAlways;
  575. /// @name Protected field getters/setters
  576. /// @{
  577. static const char* _getRenderEnabled( void *object, const char *data );
  578. static bool _setRenderEnabled( void *object, const char *index, const char *data );
  579. static const char* _getSelectionEnabled( void *object, const char *data );
  580. static bool _setSelectionEnabled( void *object, const char *index, const char *data );
  581. static bool _setFieldPosition( void *object, const char *index, const char *data );
  582. static bool _setFieldRotation( void *object, const char *index, const char *data );
  583. static bool _setFieldScale( void *object, const char *index, const char *data );
  584. static bool _setMountPID( void* object, const char* index, const char* data );
  585. /// @}
  586. };
  587. #endif // _SCENEOBJECT_H_