Main Page   Class List   Class Members  

  • Main Page
  • Modules
  • Classes
  • Files
  • File List

Cloth.h

Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and
00007 // any modifications thereto. Any use, reproduction, disclosure, or
00008 // distribution of this software and related documentation without an express
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 //
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved.
00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
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                                 // better packing of member
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 // abstract cloth instance
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     /* particle properties */
00113     virtual uint32_t getNumParticles() const = 0;
00115     virtual void lockParticles() const = 0; //Might be better if it was called map/unmapParticles
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     /* solver parameters */
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     // portion of local frame velocity applied to particles
00189     // 0 (default): particles are unaffected
00190     // same as damping: damp global particle velocity
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     // damp, drag, stiffness exponent per second
00219     virtual void setStiffnessFrequency(float) = 0;
00220     virtual float getStiffnessFrequency() const = 0;
00221 
00222     // filter width for averaging dt^2 factor of gravity and
00223     // external acceleration, in numbers of iterations (default=30).
00224     virtual void setAcceleationFilterWidth(uint32_t) = 0;
00225     virtual uint32_t getAccelerationFilterWidth() const = 0;
00226 
00227     // setup edge constraint solver iteration
00228     virtual void setPhaseConfig(Range<const PhaseConfig> configs) = 0;
00229 
00230     /* collision parameters */
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     // controls how quickly mass is increased during collisions
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     // set virtual particles for collision handling.
00304     // each indices element consists of 3 particle
00305     // indices and an index into the lerp weights array.
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     /* tether constraint parameters */
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     /* motion constraint parameters */
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     /* separation constraint parameters */
00344 
00345     // return reference to separation constraints (position, radius)
00346     // The entire range must be written after calling this function.
00347     virtual Range<physx::PxVec4> getSeparationConstraints() = 0;
00348     virtual void clearSeparationConstraints() = 0;
00349     virtual uint32_t getNumSeparationConstraints() const = 0;
00350 
00351     /* clear interpolation */
00352 
00353     // assign current to previous positions for
00354     // collision spheres, motion, and separation constraints
00355     virtual void clearInterpolation() = 0;
00356 
00357     /* particle acceleration parameters */
00358 
00359     // return reference to particle accelerations (in local coordinates)
00360     // The entire range must be written after calling this function.
00361     virtual Range<physx::PxVec4> getParticleAccelerations() = 0;
00362     virtual void clearParticleAccelerations() = 0;
00363     virtual uint32_t getNumParticleAccelerations() const = 0;
00364 
00365     /* wind */
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     /* self collision */
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     /* rest positions */
00404 
00405     // set rest particle positions used during self-collision
00406     virtual void setRestPositions(Range<const physx::PxVec4>) = 0;
00407     virtual uint32_t getNumRestPositions() const = 0;
00408 
00409     /* bounding box */
00410 
00412     virtual const physx::PxVec3& getBoundingBoxCenter() const = 0;
00414     virtual const physx::PxVec3& getBoundingBoxScale() const = 0;
00415 
00416     /* sleeping (disabled by default) */
00417 
00418     // max particle velocity (per axis) to pass sleep test
00419     virtual void setSleepThreshold(float) = 0;
00420     virtual float getSleepThreshold() const = 0;
00421     // test sleep condition every nth millisecond
00422     virtual void setSleepTestInterval(uint32_t) = 0;
00423     virtual uint32_t getSleepTestInterval() const = 0;
00424     // put cloth to sleep when n consecutive sleep tests pass
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     // Returns value set by setUserData().
00435     virtual void* getUserData() const = 0;
00436 };
00437 
00438 // wrappers to prevent non-const overload from marking particles dirty
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 } // namespace cloth
00449 } // namespace nv
Copyright © 2016-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com