tsStatic.h 7.8 KB

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