void PxCloth::setTransform( const MatrixF &mat ) { Parent::setTransform( mat ); setMaskBits( TransformMask ); // Only need to do this if we're on the server // or if we're not currently ticking physics. if ( !mWorld || !mWorld->isEnabled() ) _updateStaticCloth(); }
void PxCloth::inspectPostApply() { Parent::inspectPostApply(); // Must have at least 2 verts. mPatchVerts.x = getMax( 2, mPatchVerts.x ); mPatchVerts.y = getMax( 2, mPatchVerts.y ); if ( isServerObject() ) _updateStaticCloth(); setMaskBits( TransformMask | MaterialMask | ClothMask ); }
bool PxCloth::_createClothPatch() { // Make sure we have a mesh. if ( !mClothMesh ) { _initClothMesh(); if ( !mClothMesh ) return false; } // Make sure we can change the world. mWorld->releaseWriteLock(); _releaseCloth(); NxClothDesc desc; desc.globalPose.setRowMajor44( getTransform() ); desc.thickness = mThickness; desc.density = mDensity; desc.bendingStiffness = mBendingStiffness; desc.dampingCoefficient = mDampingCoefficient; desc.friction = mFriction; // start jc // todo: expose this desc.sleepLinearVelocity = 0.0000001f; // end jc if ( mBendingEnabled ) desc.flags |= NX_CLF_BENDING; if ( mDampingEnabled ) desc.flags |= NX_CLF_DAMPING; if ( mTriangleCollisionEnabled ) desc.flags |= NX_CLF_TRIANGLE_COLLISION; if ( mSelfCollisionEnabled ) desc.flags |= NX_CLF_SELFCOLLISION; desc.clothMesh = mClothMesh; desc.meshData = mReceiveBuffers; if ( !desc.isValid() ) return false; mCloth = mScene->createCloth( desc ); mIsVBDirty = true; _updateStaticCloth(); _setupAttachments(); return true; }
bool PxCloth::onAdd() { if ( !Parent::onAdd() ) return false; // Cloth is only created on the client. if ( isClientObject() ) { mWorld = dynamic_cast<PxWorld*>( PHYSICSMGR->getWorld( "client" ) ); if ( !mWorld || !mWorld->getScene() ) { Con::errorf( "PxCloth::onAdd() - PhysXWorld not initialized... cloth disabled!" ); return true; } mScene = mWorld->getScene(); mResetXfm = getTransform(); _createClothPatch(); PhysicsPlugin::getPhysicsResetSignal().notify( this, &PxCloth::onPhysicsReset, 1053.0f ); } // On the server we use the static update // to setup the bounds of the cloth. if ( isServerObject() ) _updateStaticCloth(); addToScene(); // Also the server object never ticks. if ( isServerObject() ) setProcessTick( false ); return true; }