sceneObject.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  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. bool mPathfindingIgnore;
  292. /// Triggered when a SceneObject onAdd is called.
  293. static Signal< void( SceneObject* ) > smSceneObjectAdd;
  294. /// Triggered when a SceneObject onRemove is called.
  295. static Signal< void( SceneObject* ) > smSceneObjectRemove;
  296. /// Return the type mask that indicates to which broad object categories
  297. /// this object belongs.
  298. U32 getTypeMask() const { return mTypeMask; }
  299. /// @name SceneManager Functionality
  300. /// @{
  301. /// Return the SceneManager that this SceneObject belongs to.
  302. SceneManager* getSceneManager() const { return mSceneManager; }
  303. /// Adds object to the client or server container depending on the object
  304. void addToScene();
  305. /// Removes the object from the client/server container
  306. void removeFromScene();
  307. /// Returns a pointer to the container that contains this object
  308. SceneContainer* getContainer() { return mContainer; }
  309. /// @}
  310. /// @name Flags
  311. /// @{
  312. /// Return true if this object is rendered.
  313. bool isRenderEnabled() const;
  314. /// Set whether the object gets rendered.
  315. void setRenderEnabled( bool value );
  316. /// Return true if this object can be selected in the editor.
  317. bool isSelectionEnabled() const;
  318. /// Set whether the object can be selected in the editor.
  319. void setSelectionEnabled( bool value );
  320. /// Return true if the object doesn't want to be subjected to culling
  321. /// when in the editor.
  322. bool isCullingDisabledInEditor() const { return mObjectFlags.test( DisableCullingInEditorFlag ); }
  323. /// Return true if the object should be taken into account for visual occlusion.
  324. bool isVisualOccluder() const { return mObjectFlags.test( VisualOccluderFlag ); }
  325. /// @}
  326. /// @name Collision and transform related interface
  327. ///
  328. /// The Render Transform is the interpolated transform with respect to the
  329. /// frame rate. The Render Transform will differ from the object transform
  330. /// because the simulation is updated in fixed intervals, which controls the
  331. /// object transform. The framerate is, most likely, higher than this rate,
  332. /// so that is why the render transform is interpolated and will differ slightly
  333. /// from the object transform.
  334. ///
  335. /// @{
  336. /// Disables collisions for this object including raycasts
  337. virtual void disableCollision();
  338. /// Enables collisions for this object
  339. virtual void enableCollision();
  340. /// Returns true if collisions are enabled
  341. bool isCollisionEnabled() const { return mCollisionCount == 0; }
  342. /// This gets called when an object collides with this object.
  343. /// @param object Object colliding with this object
  344. /// @param vec Vector along which collision occurred
  345. virtual void onCollision( SceneObject *object, const VectorF &vec ) {}
  346. /// Returns true if this object allows itself to be displaced
  347. /// @see displaceObject
  348. virtual bool isDisplacable() const { return false; }
  349. /// Returns the momentum of this object
  350. virtual Point3F getMomentum() const { return Point3F( 0, 0, 0 ); }
  351. /// Sets the momentum of this object
  352. /// @param momentum Momentum
  353. virtual void setMomentum( const Point3F& momentum ) {}
  354. /// Returns the mass of this object
  355. virtual F32 getMass() const { return 1.f; }
  356. /// Displaces this object by a vector
  357. /// @param displaceVector Displacement vector
  358. virtual bool displaceObject( const Point3F& displaceVector ) { return false; }
  359. /// Returns the transform which can be used to convert object space
  360. /// to world space
  361. virtual const MatrixF& getTransform() const { return mObjToWorld; }
  362. /// Returns the transform which can be used to convert world space
  363. /// into object space
  364. const MatrixF& getWorldTransform() const { return mWorldToObj; }
  365. /// Returns the scale of the object
  366. const VectorF& getScale() const { return mObjScale; }
  367. /// Returns the bounding box for this object in local coordinates.
  368. const Box3F& getObjBox() const { return mObjBox; }
  369. /// Returns the bounding box for this object in world coordinates.
  370. const Box3F& getWorldBox() const { return mWorldBox; }
  371. /// Returns the bounding sphere for this object in world coordinates.
  372. const SphereF& getWorldSphere() const { return mWorldSphere; }
  373. /// Returns the center of the bounding box in world coordinates
  374. Point3F getBoxCenter() const { return ( mWorldBox.minExtents + mWorldBox.maxExtents ) * 0.5f; }
  375. /// Sets the Object -> World transform
  376. ///
  377. /// @param mat New transform matrix
  378. virtual void setTransform( const MatrixF &mat );
  379. /// Sets the scale for the object
  380. /// @param scale Scaling values
  381. virtual void setScale( const VectorF &scale );
  382. /// This sets the render transform for this object
  383. /// @param mat New render transform
  384. virtual void setRenderTransform(const MatrixF &mat);
  385. /// Returns the render transform
  386. const MatrixF& getRenderTransform() const { return mRenderObjToWorld; }
  387. /// Returns the render transform to convert world to local coordinates
  388. const MatrixF& getRenderWorldTransform() const { return mRenderWorldToObj; }
  389. /// Returns the render world box
  390. const Box3F& getRenderWorldBox() const { return mRenderWorldBox; }
  391. /// Sets the state of this object as hidden or not. If an object is hidden
  392. /// it is removed entirely from collisions, it is not ghosted and is
  393. /// essentially "non existant" as far as simulation is concerned.
  394. /// @param hidden True if object is to be hidden
  395. virtual void setHidden( bool hidden );
  396. /// Builds a convex hull for this object.
  397. ///
  398. /// Think of a convex hull as a low-res mesh which covers, as tightly as
  399. /// possible, the object mesh, and is used as a collision mesh.
  400. /// @param box
  401. /// @param convex Convex mesh generated (out)
  402. virtual void buildConvex( const Box3F& box,Convex* convex ) {}
  403. /// Builds a list of polygons which intersect a bounding volume.
  404. ///
  405. /// This will use either the sphere or the box, not both, the
  406. /// SceneObject implementation ignores sphere.
  407. ///
  408. /// @see AbstractPolyList
  409. /// @param context A contentual hint as to the type of polylist to build.
  410. /// @param polyList Poly list build (out)
  411. /// @param box Box bounding volume
  412. /// @param sphere Sphere bounding volume
  413. ///
  414. virtual bool buildPolyList( PolyListContext context,
  415. AbstractPolyList* polyList,
  416. const Box3F& box,
  417. const SphereF& sphere ) { return false; }
  418. /// Casts a ray and obtain collision information, returns true if RayInfo is modified.
  419. ///
  420. /// @param start Start point of ray
  421. /// @param end End point of ray
  422. /// @param info Collision information obtained (out)
  423. virtual bool castRay( const Point3F& start, const Point3F& end, RayInfo* info ) { return false; }
  424. /// Casts a ray against rendered geometry, returns true if RayInfo is modified.
  425. ///
  426. /// @param start Start point of ray
  427. /// @param end End point of ray
  428. /// @param info Collision information obtained (out)
  429. virtual bool castRayRendered( const Point3F& start, const Point3F& end, RayInfo* info );
  430. /// Build a world-space silhouette polygon for the object for the given camera settings.
  431. /// This is used for occlusion.
  432. ///
  433. /// @param cameraState Camera view parameters.
  434. /// @param outPoints Vector to store the resulting polygon points in. Leave untouched
  435. /// if method is not implemented.
  436. virtual void buildSilhouette( const SceneCameraState& cameraState, Vector< Point3F >& outPoints ) {}
  437. /// Return true if the given point is contained by the object's (collision) shape.
  438. ///
  439. /// The default implementation will return true if the point is within the object's
  440. /// bounding box. Subclasses should implement more precise tests.
  441. virtual bool containsPoint( const Point3F &point );
  442. virtual bool collideBox( const Point3F& start, const Point3F& end, RayInfo* info );
  443. /// Returns the position of the object.
  444. virtual Point3F getPosition() const;
  445. /// Returns the render-position of the object.
  446. ///
  447. /// @see getRenderTransform
  448. Point3F getRenderPosition() const;
  449. /// Sets the position of the object
  450. void setPosition ( const Point3F& pos );
  451. /// Gets the velocity of the object.
  452. virtual Point3F getVelocity() const { return Point3F::Zero; }
  453. /// Sets the velocity of the object
  454. /// @param v Velocity
  455. virtual void setVelocity( const Point3F &v ) {}
  456. /// Applies an impulse force to this object
  457. /// @param pos Position where impulse came from in world space
  458. /// @param vec Velocity vector (Impulse force F = m * v)
  459. virtual void applyImpulse( const Point3F &pos, const VectorF &vec ) {}
  460. /// Applies a radial impulse to the object
  461. /// using the impulse origin and force.
  462. /// @param origin Point of origin of the radial impulse.
  463. /// @param radius The radius of the impulse area.
  464. /// @param magnitude The strength of the impulse.
  465. virtual void applyRadialImpulse( const Point3F &origin, F32 radius, F32 magnitude ) {}
  466. /// Returns the distance from this object to a point
  467. /// @param pnt World space point to measure to
  468. virtual F32 distanceTo( const Point3F &pnt ) const;
  469. /// @}
  470. /// @name Mounting
  471. /// @{
  472. /// ex: Mount B to A at A's node N
  473. /// A.mountObject( B, N )
  474. ///
  475. /// @param obj Object to mount
  476. /// @param node Mount node ID
  477. virtual void mountObject( SceneObject *obj, S32 node, const MatrixF &xfm = MatrixF::Identity );
  478. /// Remove an object mounting
  479. /// @param obj Object to unmount
  480. virtual void unmountObject( SceneObject *obj );
  481. /// Unmount this object from it's mount
  482. virtual void unmount();
  483. /// Callback when this object is mounted.
  484. /// @param obj Object we are mounting to.
  485. /// @param node Node we are unmounting from.
  486. virtual void onMount( SceneObject *obj, S32 node );
  487. /// Callback when this object is unmounted. This should be overridden to
  488. /// set maskbits or do other object type specific work.
  489. /// @param obj Object we are unmounting from.
  490. /// @param node Node we are unmounting from.
  491. virtual void onUnmount( SceneObject *obj, S32 node );
  492. // Returns mount point to world space transform at tick time.
  493. virtual void getMountTransform( S32 index, const MatrixF &xfm, MatrixF *outMat );
  494. // Returns mount point to world space transform at render time.
  495. // Note this will only be correct if called after this object has interpolated.
  496. virtual void getRenderMountTransform( F32 delta, S32 index, const MatrixF &xfm, MatrixF *outMat );
  497. /// Return the object that this object is mounted to.
  498. virtual SceneObject* getObjectMount() { return mMount.object; }
  499. /// Return object link of next object mounted to this object's mount
  500. virtual SceneObject* getMountLink() { return mMount.link; }
  501. /// Returns object list of objects mounted to this object.
  502. virtual SceneObject* getMountList() { return mMount.list; }
  503. /// Returns the mount id that this is mounted to.
  504. virtual U32 getMountNode() { return mMount.node; }
  505. /// Returns true if this object is mounted to anything at all
  506. /// Also try to resolve the PID to objectId here if it is pending.
  507. virtual bool isMounted();
  508. /// Returns the number of object mounted along with this
  509. virtual S32 getMountedObjectCount();
  510. /// Returns the object mounted at a position in the mount list
  511. /// @param idx Position on the mount list
  512. virtual SceneObject* getMountedObject( S32 idx );
  513. /// Returns the node the object at idx is mounted to
  514. /// @param idx Index
  515. virtual S32 getMountedObjectNode( S32 idx );
  516. /// Returns the object a object on the mount list is mounted to
  517. /// @param node
  518. virtual SceneObject* getMountNodeObject( S32 node );
  519. void resolveMountPID();
  520. /// @}
  521. /// @name Sound
  522. /// @{
  523. /// Return whether the object's collision shape is blocking sound.
  524. bool isOccludingSound() const { return mObjectFlags.test( SoundOccluderFlag ); }
  525. /// Return the ambient sound space active inside the volume of this object or NULL if the object does
  526. /// not have its own ambient space.
  527. virtual SFXAmbience* getSoundAmbience() const { return NULL; }
  528. /// @}
  529. /// @name Rendering
  530. /// @{
  531. /// Called when the SceneManager is ready for the registration of render instances.
  532. /// @param state Rendering state.
  533. virtual void prepRenderImage( SceneRenderState* state ) {}
  534. /// @}
  535. /// @name Lighting
  536. /// @{
  537. void setLightingPlugin( SceneObjectLightingPlugin* plugin ) { mLightPlugin = plugin; }
  538. SceneObjectLightingPlugin* getLightingPlugin() { return mLightPlugin; }
  539. /// @}
  540. /// @name Global Bounds
  541. /// @{
  542. const bool isGlobalBounds() const
  543. {
  544. return mGlobalBounds;
  545. }
  546. /// If global bounds are set to be true, then the object is assumed to
  547. /// have an infinitely large bounding box for collision and rendering
  548. /// purposes.
  549. ///
  550. /// They can't be toggled currently.
  551. void setGlobalBounds();
  552. /// @}
  553. /// Return the ProcessList for this object to use.
  554. ProcessList* getProcessList() const;
  555. // ProcessObject,
  556. virtual void processAfter( ProcessObject *obj );
  557. virtual void clearProcessAfter();
  558. virtual ProcessObject* getAfterObject() const { return mAfterObject; }
  559. virtual void setProcessTick( bool t );
  560. // NetObject.
  561. virtual U32 packUpdate( NetConnection* conn, U32 mask, BitStream* stream );
  562. virtual void unpackUpdate( NetConnection* conn, BitStream* stream );
  563. virtual void onCameraScopeQuery( NetConnection* connection, CameraScopeQuery* query );
  564. // SimObject.
  565. virtual bool onAdd();
  566. virtual void onRemove();
  567. virtual void onDeleteNotify( SimObject *object );
  568. virtual void inspectPostApply();
  569. virtual bool writeField( StringTableEntry fieldName, const char* value );
  570. static void initPersistFields();
  571. DECLARE_CONOBJECT( SceneObject );
  572. private:
  573. SceneObject( const SceneObject& ); ///< @deprecated disallowed
  574. /// For ScopeAlways objects to be able to properly implement setHidden(), they
  575. /// need to temporarily give up ScopeAlways status while being hidden. Otherwise
  576. /// the client-side ghost will not disappear as the server-side object will be
  577. /// forced to stay in scope.
  578. bool mIsScopeAlways;
  579. /// @name Protected field getters/setters
  580. /// @{
  581. static const char* _getRenderEnabled( void *object, const char *data );
  582. static bool _setRenderEnabled( void *object, const char *index, const char *data );
  583. static const char* _getSelectionEnabled( void *object, const char *data );
  584. static bool _setSelectionEnabled( void *object, const char *index, const char *data );
  585. static bool _setFieldPosition( void *object, const char *index, const char *data );
  586. static bool _setFieldRotation( void *object, const char *index, const char *data );
  587. static bool _setFieldScale( void *object, const char *index, const char *data );
  588. static bool _setMountPID( void* object, const char* index, const char* data );
  589. static bool _setAccuEnabled( void *object, const char *index, const char *data );
  590. /// @}
  591. // Accumulation Texture
  592. // Note: This was placed in SceneObject to both ShapeBase and TSStatic could support it.
  593. public:
  594. GFXTextureObject* mAccuTex;
  595. };
  596. #endif // _SCENEOBJECT_H_