sceneObject.h 34 KB

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