diff options
Diffstat (limited to 'NvCloth/samples/SampleBase')
25 files changed, 108 insertions, 44 deletions
diff --git a/NvCloth/samples/SampleBase/scene/Scene.cpp b/NvCloth/samples/SampleBase/scene/Scene.cpp index 6296a05..00e23ae 100644 --- a/NvCloth/samples/SampleBase/scene/Scene.cpp +++ b/NvCloth/samples/SampleBase/scene/Scene.cpp @@ -451,6 +451,24 @@ void Scene::addClothToSolver(ClothActor* clothActor, nv::cloth::Solver* solver) mClothSolverMap[clothActor] = solver; } +void Scene::addClothsToSolver(nv::cloth::Range<ClothActor*> clothActors, nv::cloth::Solver* solver) +{ + // A temporary vector of Cloth*, to construct a Range from and pass to solver + std::vector<nv::cloth::Cloth*> cloths; + + for (uint32_t i = 0; i < clothActors.size(); ++i) + { + auto* clothActor = clothActors[i]; + assert(mClothSolverMap.find(clothActor) == mClothSolverMap.end()); + mClothSolverMap[clothActor] = solver; + + cloths.push_back(clothActor->mCloth); + } + + auto clothsRange = nv::cloth::Range<nv::cloth::Cloth*>(&cloths.front(), &cloths.back() + 1); + solver->addCloths(clothsRange); +} + void Scene::trackRenderable(Renderable* renderable) { trackT(mRenderableList, renderable); diff --git a/NvCloth/samples/SampleBase/scene/Scene.h b/NvCloth/samples/SampleBase/scene/Scene.h index 1c14fbd..4ef2bed 100644 --- a/NvCloth/samples/SampleBase/scene/Scene.h +++ b/NvCloth/samples/SampleBase/scene/Scene.h @@ -75,7 +75,9 @@ protected: void trackFabric(nv::cloth::Fabric* fabric); void untrackFabric(nv::cloth::Fabric* fabric); - void addClothToSolver(ClothActor* clothActor, nv::cloth::Solver* solver); //Helps to detach cloths from solver at AutoDeinit. + //Help to detach cloths from solver at AutoDeinit. + void addClothToSolver(ClothActor* clothActor, nv::cloth::Solver* solver); + void addClothsToSolver(nv::cloth::Range<ClothActor*> clothActors, nv::cloth::Solver* solver); void trackRenderable(Renderable* renderMesh); void untrackRenderable(Renderable* renderMesh); diff --git a/NvCloth/samples/SampleBase/scene/scenes/CCDScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/CCDScene.cpp index 2d0eaa8..4d3bb84 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/CCDScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/CCDScene.cpp @@ -9,7 +9,7 @@ */ #include "CCDScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> diff --git a/NvCloth/samples/SampleBase/scene/scenes/CapsuleScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/CapsuleScene.cpp index e16899c..981e699 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/CapsuleScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/CapsuleScene.cpp @@ -9,7 +9,7 @@ */ #include "CapsuleScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> diff --git a/NvCloth/samples/SampleBase/scene/scenes/ConvexCollisionScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/ConvexCollisionScene.cpp index 28df734..bbafbff 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/ConvexCollisionScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/ConvexCollisionScene.cpp @@ -9,7 +9,7 @@ */ #include "ConvexCollisionScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> diff --git a/NvCloth/samples/SampleBase/scene/scenes/DistanceConstraintScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/DistanceConstraintScene.cpp index eaac8e1..8be7184 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/DistanceConstraintScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/DistanceConstraintScene.cpp @@ -9,7 +9,7 @@ */ #include "DistanceConstraintScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> diff --git a/NvCloth/samples/SampleBase/scene/scenes/FrictionScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/FrictionScene.cpp index 3848c6f..f2f5063 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/FrictionScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/FrictionScene.cpp @@ -9,7 +9,7 @@ */ #include "FrictionScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> diff --git a/NvCloth/samples/SampleBase/scene/scenes/GeodesicScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/GeodesicScene.cpp index 3216dca..bdf14c8 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/GeodesicScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/GeodesicScene.cpp @@ -9,7 +9,7 @@ */ #include "GeodesicScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> diff --git a/NvCloth/samples/SampleBase/scene/scenes/InterCollisionScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/InterCollisionScene.cpp index b75facd..0dd1aa7 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/InterCollisionScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/InterCollisionScene.cpp @@ -9,7 +9,7 @@ */ #include "InterCollisionScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> diff --git a/NvCloth/samples/SampleBase/scene/scenes/LocalGlobalScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/LocalGlobalScene.cpp index 57cd1a2..6583476 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/LocalGlobalScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/LocalGlobalScene.cpp @@ -9,7 +9,7 @@ */ #include "LocalGlobalScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> diff --git a/NvCloth/samples/SampleBase/scene/scenes/MultiSolverScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/MultiSolverScene.cpp index d708069..a82325f 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/MultiSolverScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/MultiSolverScene.cpp @@ -9,7 +9,7 @@ */ #include "MultiSolverScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> diff --git a/NvCloth/samples/SampleBase/scene/scenes/PlaneCollisionScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/PlaneCollisionScene.cpp index fcf4060..8a677f1 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/PlaneCollisionScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/PlaneCollisionScene.cpp @@ -9,7 +9,7 @@ */ #include "PlaneCollisionScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> diff --git a/NvCloth/samples/SampleBase/scene/scenes/ScaledScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/ScaledScene.cpp index f2a5b82..a9059b8 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/ScaledScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/ScaledScene.cpp @@ -9,7 +9,7 @@ */ #include "ScaledScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> diff --git a/NvCloth/samples/SampleBase/scene/scenes/SelfCollisionScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/SelfCollisionScene.cpp index 6a407ea..89fed39 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/SelfCollisionScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/SelfCollisionScene.cpp @@ -9,7 +9,7 @@ */ #include "SelfCollisionScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> diff --git a/NvCloth/samples/SampleBase/scene/scenes/SimpleScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/SimpleScene.cpp index b52e2c6..e774665 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/SimpleScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/SimpleScene.cpp @@ -9,7 +9,7 @@ */ #include "SimpleScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> @@ -76,6 +76,7 @@ void SimpleScene::onInitialize() mClothActor->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back())); mClothActor->mCloth->setDragCoefficient(0.1f); mClothActor->mCloth->setDragCoefficient(0.1f); + //mClothActor->mCloth->setSelfCollisionDistance(0.1f); mSolver = getSceneController()->getFactory()->createSolver(); trackSolver(mSolver); diff --git a/NvCloth/samples/SampleBase/scene/scenes/SphereScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/SphereScene.cpp index d963011..2e6912e 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/SphereScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/SphereScene.cpp @@ -9,7 +9,7 @@ */ #include "SphereScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> diff --git a/NvCloth/samples/SampleBase/scene/scenes/StiffnessPerConstraintScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/StiffnessPerConstraintScene.cpp index 4ed9daf..e92c1dc 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/StiffnessPerConstraintScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/StiffnessPerConstraintScene.cpp @@ -9,7 +9,7 @@ */ #include "StiffnessPerConstraintScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> diff --git a/NvCloth/samples/SampleBase/scene/scenes/TetherScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/TetherScene.cpp index ecd0850..d437af3 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/TetherScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/TetherScene.cpp @@ -9,7 +9,7 @@ */ #include "TetherScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> diff --git a/NvCloth/samples/SampleBase/scene/scenes/TriangleScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/TriangleScene.cpp index 1822bb9..10d185d 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/TriangleScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/TriangleScene.cpp @@ -9,7 +9,7 @@ */ #include "TriangleScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> diff --git a/NvCloth/samples/SampleBase/scene/scenes/WindScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/WindScene.cpp index d84fb87..8866473 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/WindScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/WindScene.cpp @@ -9,7 +9,7 @@ */ #include "WindScene.h" -#include "Scene/SceneController.h" +#include "scene/SceneController.h" #include <NvClothExt/ClothFabricCooker.h> #include "ClothMeshGenerator.h" #include <NvCloth/Fabric.h> diff --git a/NvCloth/samples/SampleBase/ui/CommonUIController.cpp b/NvCloth/samples/SampleBase/ui/CommonUIController.cpp index 63284a2..492e3e9 100644 --- a/NvCloth/samples/SampleBase/ui/CommonUIController.cpp +++ b/NvCloth/samples/SampleBase/ui/CommonUIController.cpp @@ -188,6 +188,8 @@ void CommonUIController::drawUI() drawCodeProfiler(&s_showProfilerWindow); } #endif + + getSceneController().drawStatsUI(); } /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/NvCloth/samples/SampleBase/utils/ClothMeshGenerator.cpp b/NvCloth/samples/SampleBase/utils/ClothMeshGenerator.cpp index 49f9ada..495ba15 100644 --- a/NvCloth/samples/SampleBase/utils/ClothMeshGenerator.cpp +++ b/NvCloth/samples/SampleBase/utils/ClothMeshGenerator.cpp @@ -72,6 +72,7 @@ GeneratePlaneCloth(x,y,2,2) generates: pos = physx::PxVec3(((float)x / (float)segmentsX) * width, ((float)(y&2) / (float)segmentsY) * height, ((float)((y+1)&~1) / (float)segmentsY) * height); + break; default: pos = physx::PxVec3(((float)x / (float)segmentsX) * width, 0.f, diff --git a/NvCloth/samples/SampleBase/utils/ClothMeshGenerator.h b/NvCloth/samples/SampleBase/utils/ClothMeshGenerator.h index d6cf0fd..1db4115 100644 --- a/NvCloth/samples/SampleBase/utils/ClothMeshGenerator.h +++ b/NvCloth/samples/SampleBase/utils/ClothMeshGenerator.h @@ -25,7 +25,7 @@ struct ClothMeshData a(_a), b(_b), c(_c){} uint32_t a, b, c; - Triangle operator+(uint32_t offset)const { return Triangle(a + offset, b + offset, c + offset); }; + Triangle operator+(uint32_t offset)const { return Triangle(a + offset, b + offset, c + offset); } }; struct Quad { @@ -34,7 +34,7 @@ struct ClothMeshData a(_a), b(_b), c(_c), d(_d){} uint32_t a, b, c, d; - Quad operator+(uint32_t offset)const { return Quad(a + offset, b + offset, c + offset, d + offset); }; + Quad operator+(uint32_t offset)const { return Quad(a + offset, b + offset, c + offset, d + offset); } }; std::vector<physx::PxVec3> mVertices; std::vector<physx::PxVec2> mUvs; diff --git a/NvCloth/samples/SampleBase/utils/JobManager.cpp b/NvCloth/samples/SampleBase/utils/JobManager.cpp index 093db60..2a18d1c 100644 --- a/NvCloth/samples/SampleBase/utils/JobManager.cpp +++ b/NvCloth/samples/SampleBase/utils/JobManager.cpp @@ -124,13 +124,16 @@ void MultithreadedSolverHelper::StartSimulation(float dt) for (int j = 0; j < mSolver->getSimulationChunkCount(); j++) mSimulationChunkJobs[j].Reset(); } + mStartSimulationJob.Reset(); mEndSimulationJob.Reset(mSolver->getSimulationChunkCount()); mStartSimulationJob.RemoveReference(); - } void MultithreadedSolverHelper::WaitForSimulation() { + if (mSolver->getSimulationChunkCount() == 0) + return; + mEndSimulationJob.Wait(); }
\ No newline at end of file diff --git a/NvCloth/samples/SampleBase/utils/MeshGenerator.cpp b/NvCloth/samples/SampleBase/utils/MeshGenerator.cpp index 857daed..5541cc3 100644 --- a/NvCloth/samples/SampleBase/utils/MeshGenerator.cpp +++ b/NvCloth/samples/SampleBase/utils/MeshGenerator.cpp @@ -348,6 +348,20 @@ Mesh generateIcosahedron(float radius, int subdivisions) return mesh; } +namespace +{ + physx::PxVec3 IntersectSpheres(float* circleRadius, physx::PxVec3 aCenter, float aRadius, physx::PxVec3 bCenter, float bRadius) + { + //Intersect spheres in 2d (http://paulbourke.net/geometry/circlesphere/ Intersection of two circles) + float d = (aCenter - bCenter).magnitude(); + float a = (aRadius*aRadius - bRadius*bRadius + d*d) / (2.0f*d); + float h = sqrtf(aRadius*aRadius - a*a); + physx::PxVec3 P3 = aCenter + a * (bCenter - aCenter) / d; + if(circleRadius) *circleRadius = h; + return P3; + } +}; + Mesh generateCone(physx::PxVec4 a, physx::PxVec4 b, int segments, float grow, bool correctCone) { Mesh mesh; @@ -365,41 +379,64 @@ Mesh generateCone(physx::PxVec4 a, physx::PxVec4 b, int segments, float grow, bo basis[2].normalize(); computeBasis(basis[2], &basis[0], &basis[1]); - physx::PxVec3 pa = aCenter + aRadius*basis[0]; - physx::PxVec3 pb = bCenter + bRadius*basis[0]; - physx::PxVec3 dir = pb - pa; - - physx::PxVec3 n = basis[2].cross(dir); - physx::PxVec3 n2 = dir.cross(n); - physx::PxVec3 focusPoint = aCenter + ((pa - aCenter).dot(n2)) / basis[2].dot(n2) * basis[2]; - if(correctCone) { + //make the cone connect seamlessly to the spheres + { + //http://jwilson.coe.uga.edu/emt669/Student.Folders/Kertscher.Jeff/Essay.3/Tangents.html + + //sphere a with smaller radius + float cRadius = aRadius - bRadius; + physx::PxVec3 cCenter = aCenter; + + //sphere in between the a and b + physx::PxVec3 dCenter = (aCenter+bCenter)*0.5f; + float dRadius = (aCenter - bCenter).magnitude()*0.5f; + + //intersection between c and d to get tangent point + float iRadius; + physx::PxVec3 iCenter = IntersectSpheres(&iRadius, dCenter, dRadius, cCenter, cRadius); + physx::PxVec3 iPoint = iCenter + basis[0] * iRadius; //tangent point on c + physx::PxVec3 offset = (iPoint - aCenter).getNormalized(); //offset direction + + physx::PxVec3 aPoint = aCenter + offset*aRadius; + aCenter = (aPoint - aCenter).dot(basis[2])*basis[2] + aCenter; + aRadius = (aPoint - aCenter).magnitude(); + physx::PxVec3 bPoint = bCenter + offset*bRadius; + bCenter = (bPoint - aCenter).dot(basis[2])*basis[2] + aCenter; + bRadius = (bPoint - bCenter).magnitude(); + + + } + + //old code, probably wrong + /* + physx::PxVec3 pa = aCenter + aRadius*basis[0]; + physx::PxVec3 pb = bCenter + bRadius*basis[0]; + physx::PxVec3 dir = pb - pa; + + //construct plane containing pa and pb, with normal perpendicular to basis[0] + physx::PxVec3 n = basis[2].cross(dir); + physx::PxVec3 n2 = dir.cross(n); + + //line plane intersection + physx::PxVec3 focusPoint = aCenter + ((pa - aCenter).dot(n2)) / basis[2].dot(n2) * basis[2]; + { float focusDistance = (focusPoint - aCenter).magnitude(); + //make circle with center in mid point between focusPoint and aCenter physx::PxVec3 cCenter = (focusPoint + aCenter)*0.5f; float cRadius = focusDistance*0.5f; - float d = (aCenter - cCenter).magnitude(); - float a = (aRadius*aRadius - cRadius*cRadius + d*d) / (2.0f*d); - float h = sqrtf(aRadius*aRadius - a*a); - physx::PxVec3 P3 = aCenter + a * (cCenter - aCenter) / d; - aCenter = P3; - aRadius = h; + aCenter = IntersectSpheres(&aRadius, aCenter, aRadius, cCenter, cRadius); } { float focusDistance = (focusPoint - bCenter).magnitude(); physx::PxVec3 cCenter = (focusPoint + bCenter)*0.5f; float cRadius = focusDistance*0.5f; - float d = (bCenter - cCenter).magnitude(); - float a = (bRadius*bRadius - cRadius*cRadius + d*d) / (2.0f*d); - float h = sqrtf(bRadius*bRadius - a*a); - physx::PxVec3 P3 = bCenter + a * (cCenter - bCenter) / d; - - bCenter = P3; - bRadius = h; - } + bCenter = IntersectSpheres(&bRadius, bCenter, bRadius, cCenter, cRadius); + }*/ } |