sceneObject.h 34 KB

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