sceneObject.h 30 KB

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