tsStatic.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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;
  77. Box3F getBoundingBox(const MatrixF& mat, const Point3F& scale) const;
  78. void getFeatures(const MatrixF& mat, const VectorF& n, ConvexFeature* cf);
  79. // This returns a list of convex faces to collide against
  80. void getPolyList(AbstractPolyList* list);
  81. // This returns the furthest point from the input vector
  82. Point3F support(const VectorF& v) const;
  83. };
  84. /// A simple mesh shape with optional ambient animation.
  85. class TSStatic : public SceneObject
  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();
  129. void onRemove();
  130. // Collision
  131. void prepCollision();
  132. bool castRay(const Point3F& start, const Point3F& end, RayInfo* info);
  133. bool castRayRendered(const Point3F& start, const Point3F& end, RayInfo* info);
  134. bool buildPolyList(PolyListContext context, AbstractPolyList* polyList, const Box3F& box, const SphereF& sphere);
  135. bool buildExportPolyList(ColladaUtils::ExportData* exportData, const Box3F& box, const SphereF&);
  136. void buildConvex(const Box3F& box, Convex* convex);
  137. bool _createShape();
  138. void _updatePhysics();
  139. void _renderNormals(ObjectRenderInst* ri, SceneRenderState* state, BaseMatInstance* overrideMat);
  140. void _onResourceChanged(const Torque::Path& path);
  141. void onShapeChanged();
  142. // ProcessObject
  143. virtual void processTick(const Move* move);
  144. virtual void interpolateTick(F32 delta);
  145. virtual void advanceTime(F32 dt);
  146. virtual void onDynamicModified(const char* slotName, const char* newValue);
  147. /// Start or stop processing ticks depending on our state.
  148. void _updateShouldTick();
  149. String cubeDescName;
  150. U32 cubeDescId;
  151. ReflectorDesc* reflectorDesc;
  152. CubeReflector mCubeReflector;
  153. protected:
  154. Convex* mConvexList;
  155. DECLARE_SHAPEASSET(TSStatic, Shape, onShapeChanged);
  156. DECLARE_ASSET_NET_SETGET(TSStatic, Shape, AdvancedStaticOptionsMask);
  157. U32 mShapeHash;
  158. Vector<S32> mCollisionDetails;
  159. Vector<S32> mLOSDetails;
  160. TSShapeInstance* mShapeInstance;
  161. NetStringHandle mSkinNameHandle;
  162. String mAppliedSkinName;
  163. bool mPlayAmbient;
  164. TSThread* mAmbientThread;
  165. F32 mAnimOffset;
  166. F32 mAnimSpeed;
  167. /// The type of mesh data to return for collision queries.
  168. MeshType mCollisionType;
  169. /// The type of mesh data to return for decal polylist queries.
  170. MeshType mDecalType;
  171. bool mAllowPlayerStep;
  172. /// If true each submesh within the TSShape is culled
  173. /// against the object space frustum.
  174. bool mMeshCulling;
  175. /// If true the shape is sorted by the origin of the
  176. /// model instead of the nearest point of the bounds.
  177. bool mUseOriginSort;
  178. PhysicsBody* mPhysicsRep;
  179. LinearColorF mOverrideColor;
  180. // Debug stuff
  181. F32 mRenderNormalScalar;
  182. S32 mForceDetail;
  183. public:
  184. TSStatic();
  185. ~TSStatic();
  186. DECLARE_CONOBJECT(TSStatic);
  187. static void initPersistFields();
  188. static void consoleInit();
  189. static bool _setFieldSkin(void* object, const char* index, const char* data);
  190. static const char* _getFieldSkin(void* object, const char* data);
  191. // Skinning
  192. void setSkinName(const char* name);
  193. void reSkin();
  194. // NetObject
  195. U32 packUpdate(NetConnection* conn, U32 mask, BitStream* stream);
  196. void unpackUpdate(NetConnection* conn, BitStream* stream);
  197. // SceneObject
  198. void setTransform(const MatrixF& mat);
  199. void onScaleChanged();
  200. void prepRenderImage(SceneRenderState* state);
  201. void inspectPostApply();
  202. virtual void onMount(SceneObject* obj, S32 node);
  203. virtual void onUnmount(SceneObject* obj, S32 node);
  204. /// The type of mesh data use for collision queries.
  205. MeshType getCollisionType() const { return mCollisionType; }
  206. bool allowPlayerStep() const { return mAllowPlayerStep; }
  207. TSShapeInstance* getShapeInstance() const { return mShapeInstance; }
  208. U32 getNumDetails();
  209. const Vector<S32>& getCollisionDetails() const { return mCollisionDetails; }
  210. const Vector<S32>& getLOSDetails() const { return mLOSDetails; }
  211. bool hasAnim() { return mAmbientThread != NULL; }
  212. #ifdef TORQUE_TOOLS
  213. virtual void onInspect(GuiInspector*);
  214. #endif
  215. void updateMaterials();
  216. bool isAnimated() { return mPlayAmbient; }
  217. bool hasNode(const char* nodeName);
  218. void getNodeTransform(const char *nodeName, const MatrixF &xfm, MatrixF *outMat);
  219. virtual void getUtilizedAssets(Vector<StringTableEntry>* usedAssetsList);
  220. private:
  221. virtual void onStaticModified(const char* slotName, const char* newValue = NULL);
  222. protected:
  223. Vector<S32> mDecalDetails;
  224. Vector<S32>* mDecalDetailsPtr;
  225. ///Indicates if all statics should utilize the distance-based object fadeout logic
  226. static bool smUseStaticObjectFade;
  227. ///Distance at which static object fading begins if smUseStaticObjectFade is on
  228. static F32 smStaticObjectFadeStart;
  229. ///Distance at which static object fading should have fully faded if smUseStaticObjectFade is on
  230. static F32 smStaticObjectFadeEnd;
  231. ///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
  232. static F32 smStaticObjectUnfadeableSize;
  233. public:
  234. bool mIgnoreZodiacs;
  235. bool mHasGradients;
  236. bool mInvertGradientRange;
  237. Point2F mGradientRangeUser;
  238. Point2F mGradientRange;
  239. private:
  240. void set_special_typing();
  241. virtual void setSelectionFlags(U8 flags);
  242. };
  243. typedef TSStatic::MeshType TSMeshType;
  244. DefineEnumType(TSMeshType);
  245. #endif // _H_TSSTATIC