tsStatic.h 8.7 KB

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