diff options
| author | Marijn Tamis <[email protected]> | 2019-04-01 13:09:20 +0200 |
|---|---|---|
| committer | Marijn Tamis <[email protected]> | 2019-04-01 13:09:20 +0200 |
| commit | 2835d138450b20744c3b97e7ae827372ceac5958 (patch) | |
| tree | 8a1a38f613ee18d5bac1d24aa2d40059aadf8b73 | |
| parent | Update documentation that was missing from latest release. (diff) | |
| download | nvcloth-2835d138450b20744c3b97e7ae827372ceac5958.tar.xz nvcloth-2835d138450b20744c3b97e7ae827372ceac5958.zip | |
Add new SetSpheres and SetPlanes api's to bring them in line with setTriangles.1.1.5
| -rw-r--r-- | NvCloth/include/NvCloth/Cloth.h | 4 | ||||
| -rw-r--r-- | NvCloth/src/ClothImpl.h | 66 |
2 files changed, 69 insertions, 1 deletions
diff --git a/NvCloth/include/NvCloth/Cloth.h b/NvCloth/include/NvCloth/Cloth.h index e00deb3..287f1cc 100644 --- a/NvCloth/include/NvCloth/Cloth.h +++ b/NvCloth/include/NvCloth/Cloth.h @@ -263,6 +263,7 @@ class Cloth : public UserAllocated \endcode */ virtual void setSpheres(Range<const physx::PxVec4> spheres, uint32_t first, uint32_t last) = 0; + virtual void setSpheres(Range<const physx::PxVec4> startSpheres, Range<const physx::PxVec4> targetSpheres) = 0; /// Returns the number of spheres currently set. virtual uint32_t getNumSpheres() const = 0; @@ -291,6 +292,7 @@ class Cloth : public UserAllocated Use setConvexes to enable planes for collision detection. */ virtual void setPlanes(Range<const physx::PxVec4> planes, uint32_t first, uint32_t last) = 0; + virtual void setPlanes(Range<const physx::PxVec4> startPlanes, Range<const physx::PxVec4> targetPlanes) = 0; /// Returns the number of planes currently set. virtual uint32_t getNumPlanes() const = 0; @@ -308,7 +310,7 @@ class Cloth : public UserAllocated The values currently in range [first, last[ will be replaced with the content of triangles. */ virtual void setTriangles(Range<const physx::PxVec3> triangles, uint32_t first, uint32_t last) = 0; - virtual void setTriangles(Range<const physx::PxVec3> triangles, Range<const physx::PxVec3>, uint32_t first) = 0; + virtual void setTriangles(Range<const physx::PxVec3> startTriangles, Range<const physx::PxVec3> targetTriangles, uint32_t first) = 0; /// Returns the number of triangles currently set. virtual uint32_t getNumTriangles() const = 0; diff --git a/NvCloth/src/ClothImpl.h b/NvCloth/src/ClothImpl.h index dde7cdd..6686cd7 100644 --- a/NvCloth/src/ClothImpl.h +++ b/NvCloth/src/ClothImpl.h @@ -109,12 +109,14 @@ class ClothImpl : public Cloth virtual uint32_t getAccelerationFilterWidth() const; virtual void setSpheres(Range<const physx::PxVec4>, uint32_t first, uint32_t last); + virtual void setSpheres(Range<const physx::PxVec4> startSpheres, Range<const physx::PxVec4> targetSpheres); virtual uint32_t getNumSpheres() const; virtual void setCapsules(Range<const uint32_t>, uint32_t first, uint32_t last); virtual uint32_t getNumCapsules() const; virtual void setPlanes(Range<const physx::PxVec4>, uint32_t first, uint32_t last); + virtual void setPlanes(Range<const physx::PxVec4> startPlanes, Range<const physx::PxVec4> targetPlanes); virtual uint32_t getNumPlanes() const; virtual void setConvexes(Range<const uint32_t>, uint32_t first, uint32_t last); @@ -617,6 +619,38 @@ inline void ClothImpl<T>::setSpheres(Range<const physx::PxVec4> spheres, uint32_ } template <typename T> +inline void ClothImpl<T>::setSpheres(Range<const physx::PxVec4> startSpheres, Range<const physx::PxVec4> targetSpheres) +{ + NV_CLOTH_ASSERT(startSpheres.size() == targetSpheres.size()); + + //Clamp ranges to the first 32 spheres + startSpheres = Range<const physx::PxVec4>(startSpheres.begin(), std::min(startSpheres.end(), startSpheres.begin() + 32)); + targetSpheres = Range<const physx::PxVec4>(targetSpheres.begin(), std::min(targetSpheres.end(), targetSpheres.begin() + 32)); + + uint32_t oldSize = uint32_t(getChildCloth()->mStartCollisionSpheres.size()); + uint32_t newSize = uint32_t(startSpheres.size()); + + if(newSize > std::min(getChildCloth()->mStartCollisionSpheres.capacity(), getChildCloth()->mTargetCollisionSpheres.capacity())) + { + //context lock only if we are growing the array + ContextLockType contextLock(getChildCloth()->mFactory); + getChildCloth()->mStartCollisionSpheres.assign(startSpheres.begin(), startSpheres.end()); + getChildCloth()->mTargetCollisionSpheres.assign(targetSpheres.begin(), targetSpheres.end()); + getChildCloth()->notifyChanged(); + } + else + { + getChildCloth()->mStartCollisionSpheres.assign(startSpheres.begin(), startSpheres.end()); + getChildCloth()->mTargetCollisionSpheres.assign(targetSpheres.begin(), targetSpheres.end()); + + if(newSize - oldSize) //notify only if the size changed + getChildCloth()->notifyChanged(); + } + + wakeUp(); +} + +template <typename T> inline uint32_t ClothImpl<T>::getNumSpheres() const { return uint32_t(getChildCloth()->mStartCollisionSpheres.size()); @@ -775,6 +809,38 @@ inline void ClothImpl<T>::setPlanes(Range<const physx::PxVec4> planes, uint32_t } template <typename T> +inline void ClothImpl<T>::setPlanes(Range<const physx::PxVec4> startPlanes, Range<const physx::PxVec4> targetPlanes) +{ + NV_CLOTH_ASSERT(startPlanes.size() == targetPlanes.size()); + + //Clamp ranges to the first 32 planes + startPlanes = Range<const physx::PxVec4>(startPlanes.begin(), std::min(startPlanes.end(), startPlanes.begin() + 32)); + targetPlanes = Range<const physx::PxVec4>(targetPlanes.begin(), std::min(targetPlanes.end(), targetPlanes.begin() + 32)); + + uint32_t oldSize = uint32_t(getChildCloth()->mStartCollisionPlanes.size()); + uint32_t newSize = uint32_t(startPlanes.size()); + + if(newSize > std::min(getChildCloth()->mStartCollisionPlanes.capacity(), getChildCloth()->mTargetCollisionPlanes.capacity())) + { + //context lock only if we are growing the array + ContextLockType contextLock(getChildCloth()->mFactory); + getChildCloth()->mStartCollisionPlanes.assign(startPlanes.begin(), startPlanes.end()); + getChildCloth()->mTargetCollisionPlanes.assign(targetPlanes.begin(), targetPlanes.end()); + getChildCloth()->notifyChanged(); + } + else + { + getChildCloth()->mStartCollisionPlanes.assign(startPlanes.begin(), startPlanes.end()); + getChildCloth()->mTargetCollisionPlanes.assign(targetPlanes.begin(), targetPlanes.end()); + + if(newSize - oldSize) //notify only if the size changed + getChildCloth()->notifyChanged(); + } + + wakeUp(); +} + +template <typename T> inline uint32_t ClothImpl<T>::getNumPlanes() const { return uint32_t(getChildCloth()->mStartCollisionPlanes.size()); |