pxCloth.h
Engine/source/T3D/physics/physx/pxCloth.h
Classes:
class
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _PXCLOTH_H_ 25#define _PXCLOTH_H_ 26 27#ifndef _GAMEBASE_H_ 28#include "T3D/gameBase/gameBase.h" 29#endif 30#ifndef _GFXPRIMITIVEBUFFER_H_ 31#include "gfx/gfxPrimitiveBuffer.h" 32#endif 33#ifndef _GFXVERTEXBUFFER_H_ 34#include "gfx/gfxVertexBuffer.h" 35#endif 36#ifndef _PHYSX_H_ 37#include "T3D/physics/physx/px.h" 38#endif 39#ifndef _T3D_PHYSICS_PHYSICSPLUGIN_H_ 40#include "T3D/physics/physicsPlugin.h" 41#endif 42 43class Material; 44class BaseMatInstance; 45class PxWorld; 46class NxScene; 47class NxClothMesh; 48class NxCloth; 49 50 51class PxCloth : public GameBase 52{ 53 typedef GameBase Parent; 54 55 enum MaskBits 56 { 57 TransformMask = Parent::NextFreeMask << 0, 58 ClothMask = Parent::NextFreeMask << 1, 59 MaterialMask = Parent::NextFreeMask << 3, 60 NextFreeMask = Parent::NextFreeMask << 4 61 }; 62 63public: 64 65 PxCloth(); 66 virtual ~PxCloth(); 67 68 DECLARE_CONOBJECT( PxCloth ); 69 70 // SimObject 71 virtual bool onAdd(); 72 virtual void onRemove(); 73 static void initPersistFields(); 74 virtual void inspectPostApply(); 75 void onPhysicsReset( PhysicsResetEvent reset ); 76 77 // NetObject 78 virtual U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream ); 79 virtual void unpackUpdate( NetConnection *conn, BitStream *stream ); 80 81 // SceneObject 82 virtual void setTransform( const MatrixF &mat ); 83 virtual void setScale( const VectorF &scale ); 84 virtual void prepRenderImage( SceneRenderState *state ); 85 86 // GameBase 87 virtual bool onNewDataBlock( GameBaseData *dptr, bool reload ); 88 virtual void processTick( const Move *move ); 89 virtual void interpolateTick( F32 delta ); 90 91protected: 92 93 PxWorld *mWorld; 94 95 NxScene *mScene; 96 97 /// Cooked cloth collision mesh. 98 NxClothMesh *mClothMesh; 99 100 /// The cloth actor used 101 NxCloth *mCloth; 102 103 NxMeshData mReceiveBuffers; 104 105 bool mBendingEnabled; 106 bool mDampingEnabled; 107 bool mTriangleCollisionEnabled; 108 bool mSelfCollisionEnabled; 109 110 F32 mDensity; 111 F32 mThickness; 112 F32 mFriction; 113 F32 mBendingStiffness; 114 F32 mStretchingStiffness; 115 F32 mDampingCoefficient; 116 F32 mCollisionResponseCoefficient; 117 F32 mAttachmentResponseCoefficient; 118 119 U32 mAttachmentMask; 120 121 static EnumTable mAttachmentFlagTable; 122 123 String mMaterialName; 124 SimObjectPtr<Material> mMaterial; 125 BaseMatInstance *mMatInst; 126 127 String lookupName; 128 129 /// The output verts from the PhysX simulation. 130 GFXVertexPNTT *mVertexRenderBuffer; 131 132 /// The output indices from the PhysX simulation. 133 U16 *mIndexRenderBuffer; 134 135 U32 mMaxVertices; 136 U32 mMaxIndices; 137 138 /// The number of indices in the cloth which 139 /// is updated by the PhysX simulation. 140 U32 mNumIndices; 141 142 /// The number of verts in the cloth which 143 /// is updated by the PhysX simulation. 144 U32 mNumVertices; 145 146 U32 mMeshDirtyFlags; 147 bool mIsVBDirty; 148 149 GFXPrimitiveBufferHandle mPrimBuffer; 150 GFXVertexBufferHandle<GFXVertexPNTT> mVB; 151 152 Point2I mPatchVerts; 153 Point2F mPatchSize; 154 155 MatrixF mResetXfm; 156 157 void _initMaterial(); 158 159 void _releaseMesh(); 160 void _releaseCloth(); 161 162 bool _createClothPatch(); 163 164 void _recreateCloth( const MatrixF &transform ); 165 166 void _updateClothProperties(); 167 168 void _initClothMesh(); 169 void _initReceiveBuffers(); 170 void _setupAttachments(); 171 172 void _updateStaticCloth(); 173 174 void _updateVBIB(); 175}; 176 177#endif // _PXCLOTH_H_ 178
