pxCloth.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. #ifndef _PXCLOTH_H_
  23. #define _PXCLOTH_H_
  24. #ifndef _GAMEBASE_H_
  25. #include "T3D/gameBase/gameBase.h"
  26. #endif
  27. #ifndef _GFXPRIMITIVEBUFFER_H_
  28. #include "gfx/gfxPrimitiveBuffer.h"
  29. #endif
  30. #ifndef _GFXVERTEXBUFFER_H_
  31. #include "gfx/gfxVertexBuffer.h"
  32. #endif
  33. #ifndef _PHYSX_H_
  34. #include "T3D/physics/physx/px.h"
  35. #endif
  36. #ifndef _T3D_PHYSICS_PHYSICSPLUGIN_H_
  37. #include "T3D/physics/physicsPlugin.h"
  38. #endif
  39. class Material;
  40. class BaseMatInstance;
  41. class PxWorld;
  42. class NxScene;
  43. class NxClothMesh;
  44. class NxCloth;
  45. class PxCloth : public GameBase
  46. {
  47. typedef GameBase Parent;
  48. enum MaskBits
  49. {
  50. TransformMask = Parent::NextFreeMask << 0,
  51. ClothMask = Parent::NextFreeMask << 1,
  52. MaterialMask = Parent::NextFreeMask << 3,
  53. NextFreeMask = Parent::NextFreeMask << 4
  54. };
  55. public:
  56. PxCloth();
  57. virtual ~PxCloth();
  58. DECLARE_CONOBJECT( PxCloth );
  59. // SimObject
  60. virtual bool onAdd();
  61. virtual void onRemove();
  62. static void initPersistFields();
  63. virtual void inspectPostApply();
  64. void onPhysicsReset( PhysicsResetEvent reset );
  65. // NetObject
  66. virtual U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
  67. virtual void unpackUpdate( NetConnection *conn, BitStream *stream );
  68. // SceneObject
  69. virtual void setTransform( const MatrixF &mat );
  70. virtual void setScale( const VectorF &scale );
  71. virtual void prepRenderImage( SceneRenderState *state );
  72. // GameBase
  73. virtual bool onNewDataBlock( GameBaseData *dptr, bool reload );
  74. virtual void processTick( const Move *move );
  75. virtual void interpolateTick( F32 delta );
  76. protected:
  77. PxWorld *mWorld;
  78. NxScene *mScene;
  79. /// Cooked cloth collision mesh.
  80. NxClothMesh *mClothMesh;
  81. /// The cloth actor used
  82. NxCloth *mCloth;
  83. NxMeshData mReceiveBuffers;
  84. bool mBendingEnabled;
  85. bool mDampingEnabled;
  86. bool mTriangleCollisionEnabled;
  87. bool mSelfCollisionEnabled;
  88. F32 mDensity;
  89. F32 mThickness;
  90. F32 mFriction;
  91. F32 mBendingStiffness;
  92. F32 mStretchingStiffness;
  93. F32 mDampingCoefficient;
  94. F32 mCollisionResponseCoefficient;
  95. F32 mAttachmentResponseCoefficient;
  96. U32 mAttachmentMask;
  97. static EnumTable mAttachmentFlagTable;
  98. String mMaterialName;
  99. SimObjectPtr<Material> mMaterial;
  100. BaseMatInstance *mMatInst;
  101. String lookupName;
  102. /// The output verts from the PhysX simulation.
  103. GFXVertexPNTT *mVertexRenderBuffer;
  104. /// The output indices from the PhysX simulation.
  105. U16 *mIndexRenderBuffer;
  106. U32 mMaxVertices;
  107. U32 mMaxIndices;
  108. /// The number of indices in the cloth which
  109. /// is updated by the PhysX simulation.
  110. U32 mNumIndices;
  111. /// The number of verts in the cloth which
  112. /// is updated by the PhysX simulation.
  113. U32 mNumVertices;
  114. U32 mMeshDirtyFlags;
  115. bool mIsVBDirty;
  116. GFXPrimitiveBufferHandle mPrimBuffer;
  117. GFXVertexBufferHandle<GFXVertexPNTT> mVB;
  118. Point2I mPatchVerts;
  119. Point2F mPatchSize;
  120. MatrixF mResetXfm;
  121. void _initMaterial();
  122. void _releaseMesh();
  123. void _releaseCloth();
  124. bool _createClothPatch();
  125. void _recreateCloth( const MatrixF &transform );
  126. void _updateClothProperties();
  127. void _initClothMesh();
  128. void _initReceiveBuffers();
  129. void _setupAttachments();
  130. void _updateStaticCloth();
  131. void _updateVBIB();
  132. };
  133. #endif // _PXCLOTH_H_