sceneObject.h 28 KB

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