00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #pragma once
00031
00032 #include "NvCloth/Range.h"
00033 #include "NvCloth/PhaseConfig.h"
00034 #include <foundation/PxVec3.h>
00035 #include "NvCloth/Allocator.h"
00036
00037 struct ID3D11Buffer;
00038
00039 namespace nv
00040 {
00041 namespace cloth
00042 {
00043
00044 class Factory;
00045 class Fabric;
00046 class Cloth;
00047
00048 #ifdef _MSC_VER
00049 #pragma warning(disable : 4371) // layout of class may have changed from a previous version of the compiler due to
00050
00051 #endif
00052
00053 template <typename T>
00054 struct MappedRange : public Range<T>
00055 {
00056 MappedRange(T* first, T* last, const Cloth& cloth, void (Cloth::*lock)() const, void (Cloth::*unlock)() const)
00057 : Range<T>(first, last), mCloth(cloth), mLock(lock), mUnlock(unlock)
00058 {
00059 }
00060
00061 MappedRange(const MappedRange& other)
00062 : Range<T>(other), mCloth(other.mCloth), mLock(other.mLock), mUnlock(other.mUnlock)
00063 {
00064 (mCloth.*mLock)();
00065 }
00066
00067 ~MappedRange()
00068 {
00069 (mCloth.*mUnlock)();
00070 }
00071
00072 private:
00073 MappedRange& operator = (const MappedRange&);
00074
00075 const Cloth& mCloth;
00076 void (Cloth::*mLock)() const;
00077 void (Cloth::*mUnlock)() const;
00078 };
00079
00080 struct GpuParticles
00081 {
00082 physx::PxVec4* mCurrent;
00083 physx::PxVec4* mPrevious;
00084 ID3D11Buffer* mBuffer;
00085 };
00086
00087
00088 class Cloth : public UserAllocated
00089 {
00090 protected:
00091 Cloth() {}
00092 Cloth(const Cloth&);
00093 Cloth& operator = (const Cloth&);
00094
00095 public:
00096 virtual ~Cloth() {}
00097
00104 virtual Cloth* clone(Factory& factory) const = 0;
00105
00107 virtual Fabric& getFabric() const = 0;
00109 virtual Factory& getFactory() const = 0;
00110
00111
00113 virtual uint32_t getNumParticles() const = 0;
00115 virtual void lockParticles() const = 0;
00117 virtual void unlockParticles() const = 0;
00118
00124 virtual MappedRange<physx::PxVec4> getCurrentParticles() = 0;
00125
00130 virtual MappedRange<const physx::PxVec4> getCurrentParticles() const = 0;
00131
00135 virtual MappedRange<physx::PxVec4> getPreviousParticles() = 0;
00136
00140 virtual MappedRange<const physx::PxVec4> getPreviousParticles() const = 0;
00141
00143 virtual GpuParticles getGpuParticles() = 0;
00144
00145
00152 virtual void setTranslation(const physx::PxVec3& trans) = 0;
00153
00158 virtual void setRotation(const physx::PxQuat& rot) = 0;
00159
00161 virtual const physx::PxVec3& getTranslation() const = 0;
00163 virtual const physx::PxQuat& getRotation() const = 0;
00164
00166 virtual void clearInertia() = 0;
00167
00169 virtual void teleport(const physx::PxVec3& delta) = 0;
00170
00171
00172
00174 virtual float getPreviousIterationDt() const = 0;
00175
00177 virtual void setGravity(const physx::PxVec3&) = 0;
00179 virtual physx::PxVec3 getGravity() const = 0;
00180
00184 virtual void setDamping(const physx::PxVec3&) = 0;
00186 virtual physx::PxVec3 getDamping() const = 0;
00187
00188
00189
00190
00191 virtual void setLinearDrag(const physx::PxVec3&) = 0;
00192 virtual physx::PxVec3 getLinearDrag() const = 0;
00193 virtual void setAngularDrag(const physx::PxVec3&) = 0;
00194 virtual physx::PxVec3 getAngularDrag() const = 0;
00195
00199 virtual void setLinearInertia(const physx::PxVec3&) = 0;
00201 virtual physx::PxVec3 getLinearInertia() const = 0;
00203 virtual void setAngularInertia(const physx::PxVec3&) = 0;
00205 virtual physx::PxVec3 getAngularInertia() const = 0;
00207 virtual void setCentrifugalInertia(const physx::PxVec3&) = 0;
00209 virtual physx::PxVec3 getCentrifugalInertia() const = 0;
00210
00214 virtual void setSolverFrequency(float) = 0;
00216 virtual float getSolverFrequency() const = 0;
00217
00218
00219 virtual void setStiffnessFrequency(float) = 0;
00220 virtual float getStiffnessFrequency() const = 0;
00221
00222
00223
00224 virtual void setAcceleationFilterWidth(uint32_t) = 0;
00225 virtual uint32_t getAccelerationFilterWidth() const = 0;
00226
00227
00228 virtual void setPhaseConfig(Range<const PhaseConfig> configs) = 0;
00229
00230
00231
00239 virtual void setSpheres(Range<const physx::PxVec4> spheres, uint32_t first, uint32_t last) = 0;
00241 virtual uint32_t getNumSpheres() const = 0;
00242
00243
00257 virtual void setCapsules(Range<const uint32_t> capsules, uint32_t first, uint32_t last) = 0;
00259 virtual uint32_t getNumCapsules() const = 0;
00260
00267 virtual void setPlanes(Range<const physx::PxVec4> planes, uint32_t first, uint32_t last) = 0;
00269 virtual uint32_t getNumPlanes() const = 0;
00270
00276 virtual void setConvexes(Range<const uint32_t> convexMasks, uint32_t first, uint32_t last) = 0;
00278 virtual uint32_t getNumConvexes() const = 0;
00279
00284 virtual void setTriangles(Range<const physx::PxVec3> triangles, uint32_t first, uint32_t last) = 0;
00285 virtual void setTriangles(Range<const physx::PxVec3> triangles, Range<const physx::PxVec3>, uint32_t first) = 0;
00287 virtual uint32_t getNumTriangles() const = 0;
00288
00290 virtual bool isContinuousCollisionEnabled() const = 0;
00292 virtual void enableContinuousCollision(bool) = 0;
00293
00294
00295 virtual float getCollisionMassScale() const = 0;
00296 virtual void setCollisionMassScale(float) = 0;
00297
00299 virtual void setFriction(float) = 0;
00301 virtual float getFriction() const = 0;
00302
00303
00304
00305
00306 virtual void setVirtualParticles(Range<const uint32_t[4]> indices, Range<const physx::PxVec3> weights) = 0;
00307 virtual uint32_t getNumVirtualParticles() const = 0;
00308 virtual uint32_t getNumVirtualParticleWeights() const = 0;
00309
00310
00311
00316 virtual void setTetherConstraintScale(float scale) = 0;
00318 virtual float getTetherConstraintScale() const = 0;
00323 virtual void setTetherConstraintStiffness(float stiffness) = 0;
00325 virtual float getTetherConstraintStiffness() const = 0;
00326
00327
00328
00332 virtual Range<physx::PxVec4> getMotionConstraints() = 0;
00335 virtual void clearMotionConstraints() = 0;
00336 virtual uint32_t getNumMotionConstraints() const = 0;
00337 virtual void setMotionConstraintScaleBias(float scale, float bias) = 0;
00338 virtual float getMotionConstraintScale() const = 0;
00339 virtual float getMotionConstraintBias() const = 0;
00340 virtual void setMotionConstraintStiffness(float stiffness) = 0;
00341 virtual float getMotionConstraintStiffness() const = 0;
00342
00343
00344
00345
00346
00347 virtual Range<physx::PxVec4> getSeparationConstraints() = 0;
00348 virtual void clearSeparationConstraints() = 0;
00349 virtual uint32_t getNumSeparationConstraints() const = 0;
00350
00351
00352
00353
00354
00355 virtual void clearInterpolation() = 0;
00356
00357
00358
00359
00360
00361 virtual Range<physx::PxVec4> getParticleAccelerations() = 0;
00362 virtual void clearParticleAccelerations() = 0;
00363 virtual uint32_t getNumParticleAccelerations() const = 0;
00364
00365
00366
00368 virtual void setWindVelocity(physx::PxVec3) = 0;
00370 virtual physx::PxVec3 getWindVelocity() const = 0;
00372 virtual void setDragCoefficient(float) = 0;
00374 virtual float getDragCoefficient() const = 0;
00376 virtual void setLiftCoefficient(float) = 0;
00378 virtual float getLiftCoefficient() const = 0;
00380 virtual void setFluidDensity(float) = 0;
00382 virtual float getFluidDensity() const = 0;
00383
00384
00385
00387 virtual void setSelfCollisionDistance(float distance) = 0;
00389 virtual float getSelfCollisionDistance() const = 0;
00391 virtual void setSelfCollisionStiffness(float stiffness) = 0;
00393 virtual float getSelfCollisionStiffness() const = 0;
00394
00399 virtual void setSelfCollisionIndices(Range<const uint32_t>) = 0;
00401 virtual uint32_t getNumSelfCollisionIndices() const = 0;
00402
00403
00404
00405
00406 virtual void setRestPositions(Range<const physx::PxVec4>) = 0;
00407 virtual uint32_t getNumRestPositions() const = 0;
00408
00409
00410
00412 virtual const physx::PxVec3& getBoundingBoxCenter() const = 0;
00414 virtual const physx::PxVec3& getBoundingBoxScale() const = 0;
00415
00416
00417
00418
00419 virtual void setSleepThreshold(float) = 0;
00420 virtual float getSleepThreshold() const = 0;
00421
00422 virtual void setSleepTestInterval(uint32_t) = 0;
00423 virtual uint32_t getSleepTestInterval() const = 0;
00424
00425 virtual void setSleepAfterCount(uint32_t) = 0;
00426 virtual uint32_t getSleepAfterCount() const = 0;
00427 virtual uint32_t getSleepPassCount() const = 0;
00428 virtual bool isAsleep() const = 0;
00429 virtual void putToSleep() = 0;
00430 virtual void wakeUp() = 0;
00431
00433 virtual void setUserData(void*) = 0;
00434
00435 virtual void* getUserData() const = 0;
00436 };
00437
00438
00439 inline MappedRange<const physx::PxVec4> readCurrentParticles(const Cloth& cloth)
00440 {
00441 return cloth.getCurrentParticles();
00442 }
00443 inline MappedRange<const physx::PxVec4> readPreviousParticles(const Cloth& cloth)
00444 {
00445 return cloth.getPreviousParticles();
00446 }
00447
00448 }
00449 }