sceneObject.h 30 KB

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