sceneObject.h 29 KB

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