tsStatic.h 9.7 KB

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