tsStatic.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. #ifndef _TSSTATIC_H_
  23. #define _TSSTATIC_H_
  24. #ifndef _SCENEOBJECT_H_
  25. #include "scene/sceneObject.h"
  26. #endif
  27. #ifndef _CONVEX_H_
  28. #include "collision/convex.h"
  29. #endif
  30. #ifndef __RESOURCE_H__
  31. #include "core/resource.h"
  32. #endif
  33. #ifndef _NETSTRINGTABLE_H_
  34. #include "sim/netStringTable.h"
  35. #endif
  36. #ifndef _TSSHAPE_H_
  37. #include "ts/tsShape.h"
  38. #endif
  39. class TSShapeInstance;
  40. class TSThread;
  41. class TSStatic;
  42. class PhysicsBody;
  43. struct ObjectRenderInst;
  44. class TSStaticPolysoupConvex : public Convex
  45. {
  46. typedef Convex Parent;
  47. friend class TSMesh;
  48. public:
  49. TSStaticPolysoupConvex();
  50. ~TSStaticPolysoupConvex() {};
  51. public:
  52. Box3F box;
  53. Point3F verts[4];
  54. PlaneF normal;
  55. S32 idx;
  56. TSMesh *mesh;
  57. static SceneObject* smCurObject;
  58. public:
  59. // Returns the bounding box in world coordinates
  60. Box3F getBoundingBox() const;
  61. Box3F getBoundingBox(const MatrixF& mat, const Point3F& scale) const;
  62. void getFeatures(const MatrixF& mat,const VectorF& n, ConvexFeature* cf);
  63. // This returns a list of convex faces to collide against
  64. void getPolyList(AbstractPolyList* list);
  65. // This returns the furthest point from the input vector
  66. Point3F support(const VectorF& v) const;
  67. };
  68. /// A simple mesh shape with optional ambient animation.
  69. class TSStatic : public SceneObject
  70. {
  71. typedef SceneObject Parent;
  72. static U32 smUniqueIdentifier;
  73. enum MaskBits
  74. {
  75. TransformMask = Parent::NextFreeMask << 0,
  76. AdvancedStaticOptionsMask = Parent::NextFreeMask << 1,
  77. UpdateCollisionMask = Parent::NextFreeMask << 2,
  78. SkinMask = Parent::NextFreeFlag << 3,
  79. NextFreeMask = Parent::NextFreeMask << 4
  80. };
  81. public:
  82. /// The different types of mesh data types
  83. enum MeshType
  84. {
  85. None = 0, ///< No mesh
  86. Bounds = 1, ///< Bounding box of the shape
  87. CollisionMesh = 2, ///< Specifically designated collision meshes
  88. VisibleMesh = 3 ///< Rendered mesh polygons
  89. };
  90. protected:
  91. bool onAdd();
  92. void onRemove();
  93. // Collision
  94. void prepCollision();
  95. bool castRay(const Point3F &start, const Point3F &end, RayInfo* info);
  96. bool castRayRendered(const Point3F &start, const Point3F &end, RayInfo* info);
  97. bool buildPolyList(PolyListContext context, AbstractPolyList* polyList, const Box3F &box, const SphereF& sphere);
  98. void buildConvex(const Box3F& box, Convex* convex);
  99. bool _createShape();
  100. void _updatePhysics();
  101. void _renderNormals( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
  102. void _onResourceChanged( const Torque::Path &path );
  103. // ProcessObject
  104. virtual void processTick( const Move *move );
  105. virtual void interpolateTick( F32 delta );
  106. virtual void advanceTime( F32 dt );
  107. /// Start or stop processing ticks depending on our state.
  108. void _updateShouldTick();
  109. protected:
  110. Convex *mConvexList;
  111. StringTableEntry mShapeName;
  112. U32 mShapeHash;
  113. Resource<TSShape> mShape;
  114. Vector<S32> mCollisionDetails;
  115. Vector<S32> mLOSDetails;
  116. TSShapeInstance *mShapeInstance;
  117. NetStringHandle mSkinNameHandle;
  118. String mAppliedSkinName;
  119. bool mPlayAmbient;
  120. TSThread* mAmbientThread;
  121. /// The type of mesh data to return for collision queries.
  122. MeshType mCollisionType;
  123. /// The type of mesh data to return for decal polylist queries.
  124. MeshType mDecalType;
  125. bool mAllowPlayerStep;
  126. /// If true each submesh within the TSShape is culled
  127. /// against the object space frustum.
  128. bool mMeshCulling;
  129. /// If true the shape is sorted by the origin of the
  130. /// model instead of the nearest point of the bounds.
  131. bool mUseOriginSort;
  132. PhysicsBody *mPhysicsRep;
  133. // Debug stuff
  134. F32 mRenderNormalScalar;
  135. S32 mForceDetail;
  136. public:
  137. TSStatic();
  138. ~TSStatic();
  139. DECLARE_CONOBJECT(TSStatic);
  140. static void initPersistFields();
  141. static bool _setFieldSkin( void *object, const char* index, const char* data );
  142. static const char *_getFieldSkin( void *object, const char *data );
  143. // Skinning
  144. void setSkinName( const char *name );
  145. void reSkin();
  146. // NetObject
  147. U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
  148. void unpackUpdate( NetConnection *conn, BitStream *stream );
  149. // SceneObject
  150. void setTransform( const MatrixF &mat );
  151. void onScaleChanged();
  152. void prepRenderImage( SceneRenderState *state );
  153. void inspectPostApply();
  154. /// The type of mesh data use for collision queries.
  155. MeshType getCollisionType() const { return mCollisionType; }
  156. bool allowPlayerStep() const { return mAllowPlayerStep; }
  157. Resource<TSShape> getShape() const { return mShape; }
  158. StringTableEntry getShapeFileName() { return mShapeName; }
  159. TSShapeInstance* getShapeInstance() const { return mShapeInstance; }
  160. const Vector<S32>& getCollisionDetails() const { return mCollisionDetails; }
  161. const Vector<S32>& getLOSDetails() const { return mLOSDetails; }
  162. };
  163. typedef TSStatic::MeshType TSMeshType;
  164. DefineEnumType( TSMeshType );
  165. #endif // _H_TSSTATIC