sceneObject.h 30 KB

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