tsStatic.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. bool buildExportPolyList(ColladaUtils::ExportData* exportData, const Box3F &box, const SphereF &);
  118. void buildConvex(const Box3F& box, Convex* convex);
  119. bool _createShape();
  120. void _updatePhysics();
  121. void _renderNormals( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
  122. void _onResourceChanged( const Torque::Path &path );
  123. // ProcessObject
  124. virtual void processTick( const Move *move );
  125. virtual void interpolateTick( F32 delta );
  126. virtual void advanceTime( F32 dt );
  127. /// Start or stop processing ticks depending on our state.
  128. void _updateShouldTick();
  129. String cubeDescName;
  130. U32 cubeDescId;
  131. ReflectorDesc *reflectorDesc;
  132. CubeReflector mCubeReflector;
  133. protected:
  134. Convex *mConvexList;
  135. StringTableEntry mShapeName;
  136. U32 mShapeHash;
  137. Resource<TSShape> mShape;
  138. Vector<S32> mCollisionDetails;
  139. Vector<S32> mLOSDetails;
  140. TSShapeInstance *mShapeInstance;
  141. NetStringHandle mSkinNameHandle;
  142. String mAppliedSkinName;
  143. bool mPlayAmbient;
  144. TSThread* mAmbientThread;
  145. /// The type of mesh data to return for collision queries.
  146. MeshType mCollisionType;
  147. /// The type of mesh data to return for decal polylist queries.
  148. MeshType mDecalType;
  149. bool mAllowPlayerStep;
  150. /// If true each submesh within the TSShape is culled
  151. /// against the object space frustum.
  152. bool mMeshCulling;
  153. /// If true the shape is sorted by the origin of the
  154. /// model instead of the nearest point of the bounds.
  155. bool mUseOriginSort;
  156. PhysicsBody *mPhysicsRep;
  157. // Debug stuff
  158. F32 mRenderNormalScalar;
  159. S32 mForceDetail;
  160. public:
  161. TSStatic();
  162. ~TSStatic();
  163. DECLARE_CONOBJECT(TSStatic);
  164. static void initPersistFields();
  165. static bool _setFieldSkin( void *object, const char* index, const char* data );
  166. static const char *_getFieldSkin( void *object, const char *data );
  167. // Skinning
  168. void setSkinName( const char *name );
  169. void reSkin();
  170. // NetObject
  171. U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
  172. void unpackUpdate( NetConnection *conn, BitStream *stream );
  173. // SceneObject
  174. void setTransform( const MatrixF &mat );
  175. void onScaleChanged();
  176. void prepRenderImage( SceneRenderState *state );
  177. void inspectPostApply();
  178. virtual void onMount( SceneObject *obj, S32 node );
  179. virtual void onUnmount( SceneObject *obj, S32 node );
  180. /// The type of mesh data use for collision queries.
  181. MeshType getCollisionType() const { return mCollisionType; }
  182. bool allowPlayerStep() const { return mAllowPlayerStep; }
  183. Resource<TSShape> getShape() const { return mShape; }
  184. StringTableEntry getShapeFileName() { return mShapeName; }
  185. void setShapeFileName(StringTableEntry shapeName) { mShapeName = shapeName; }
  186. TSShapeInstance* getShapeInstance() const { return mShapeInstance; }
  187. U32 getNumDetails();
  188. const Vector<S32>& getCollisionDetails() const { return mCollisionDetails; }
  189. const Vector<S32>& getLOSDetails() const { return mLOSDetails; }
  190. private:
  191. virtual void onStaticModified(const char* slotName, const char*newValue = NULL);
  192. protected:
  193. Vector<S32> mDecalDetails;
  194. Vector<S32>* mDecalDetailsPtr;
  195. public:
  196. bool mIgnoreZodiacs;
  197. bool mHasGradients;
  198. bool mInvertGradientRange;
  199. Point2F mGradientRangeUser;
  200. Point2F mGradientRange;
  201. private:
  202. void set_special_typing();
  203. virtual void setSelectionFlags(U8 flags);
  204. };
  205. typedef TSStatic::MeshType TSMeshType;
  206. DefineEnumType( TSMeshType );
  207. #endif // _H_TSSTATIC