From 2835d138450b20744c3b97e7ae827372ceac5958 Mon Sep 17 00:00:00 2001 From: Marijn Tamis Date: Mon, 1 Apr 2019 13:09:20 +0200 Subject: Add new SetSpheres and SetPlanes api's to bring them in line with setTriangles. --- NvCloth/src/ClothImpl.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'NvCloth/src/ClothImpl.h') 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, uint32_t first, uint32_t last); + virtual void setSpheres(Range startSpheres, Range targetSpheres); virtual uint32_t getNumSpheres() const; virtual void setCapsules(Range, uint32_t first, uint32_t last); virtual uint32_t getNumCapsules() const; virtual void setPlanes(Range, uint32_t first, uint32_t last); + virtual void setPlanes(Range startPlanes, Range targetPlanes); virtual uint32_t getNumPlanes() const; virtual void setConvexes(Range, uint32_t first, uint32_t last); @@ -616,6 +618,38 @@ inline void ClothImpl::setSpheres(Range spheres, uint32_ getChildCloth()->wakeUp(); } +template +inline void ClothImpl::setSpheres(Range startSpheres, Range targetSpheres) +{ + NV_CLOTH_ASSERT(startSpheres.size() == targetSpheres.size()); + + //Clamp ranges to the first 32 spheres + startSpheres = Range(startSpheres.begin(), std::min(startSpheres.end(), startSpheres.begin() + 32)); + targetSpheres = Range(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 inline uint32_t ClothImpl::getNumSpheres() const { @@ -774,6 +808,38 @@ inline void ClothImpl::setPlanes(Range planes, uint32_t wakeUp(); } +template +inline void ClothImpl::setPlanes(Range startPlanes, Range targetPlanes) +{ + NV_CLOTH_ASSERT(startPlanes.size() == targetPlanes.size()); + + //Clamp ranges to the first 32 planes + startPlanes = Range(startPlanes.begin(), std::min(startPlanes.end(), startPlanes.begin() + 32)); + targetPlanes = Range(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 inline uint32_t ClothImpl::getNumPlanes() const { -- cgit v1.2.3