aboutsummaryrefslogtreecommitdiff
path: root/NvCloth/samples/SampleBase/scene/scenes
diff options
context:
space:
mode:
Diffstat (limited to 'NvCloth/samples/SampleBase/scene/scenes')
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/CCDScene.cpp153
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/CCDScene.h37
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/CapsuleScene.cpp129
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/CapsuleScene.h33
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/ConvexCollisionScene.cpp138
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/ConvexCollisionScene.h33
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/DistanceConstraintScene.cpp100
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/DistanceConstraintScene.h32
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/FreeFallScene.cpp12
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/FrictionScene.cpp22
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/FrictionScene.h4
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/GeodesicScene.cpp114
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/GeodesicScene.h36
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/InterCollisionScene.cpp128
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/InterCollisionScene.h33
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/LocalGlobalScene.cpp141
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/LocalGlobalScene.h40
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/MultiSolverScene.cpp131
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/MultiSolverScene.h33
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/PlaneCollisionScene.cpp135
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/PlaneCollisionScene.h33
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/SelfCollisionScene.cpp155
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/SelfCollisionScene.h33
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/SimpleScene.cpp16
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/SphereScene.cpp121
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/SphereScene.h33
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/StiffnessPerConstraintScene.cpp122
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/StiffnessPerConstraintScene.h33
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/TetherScene.cpp26
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/TriangleScene.cpp131
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/TriangleScene.h33
-rw-r--r--NvCloth/samples/SampleBase/scene/scenes/WindScene.cpp49
32 files changed, 2206 insertions, 63 deletions
diff --git a/NvCloth/samples/SampleBase/scene/scenes/CCDScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/CCDScene.cpp
new file mode 100644
index 0000000..2d0eaa8
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/CCDScene.cpp
@@ -0,0 +1,153 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#include "CCDScene.h"
+#include "Scene/SceneController.h"
+#include <NvClothExt/ClothFabricCooker.h>
+#include "ClothMeshGenerator.h"
+#include <NvCloth/Fabric.h>
+#include <NvCloth/Solver.h>
+#include <NvCloth/Cloth.h>
+#include <NvCloth/Factory.h>
+#include "Renderer.h"
+#include "renderer/RenderUtils.h"
+#include "windows.h"
+#include "utils/MeshGenerator.h"
+
+DECLARE_SCENE_NAME(CCDScene, "CCD Scene")
+
+void CCDScene::Animate(double dt)
+{
+ static float time = 0.0f;
+ time += dt;
+
+ physx::PxTransform invTranslation(-mOffset - physx::PxVec3(0.f, 10.f, -2.f));
+ physx::PxTransform rotation(physx::PxQuat(cosf(time)*physx::PxHalfPi-physx::PxHalfPi,physx::PxVec3(0.0f,1.0f,0.0f)));
+ physx::PxTransform translation(mOffset + physx::PxVec3(0.f, 10.f, -2.f) + physx::PxVec3(0.0f,0.0f,10.0f*sinf(time)));
+ physx::PxTransform totalTransform = translation.transform(rotation.transform(invTranslation));
+
+ physx::PxVec4 spheres[2] = {physx::PxVec4(totalTransform.transform(physx::PxVec3(0.f, 10.f, -2.f) + mOffset),2.0),
+ physx::PxVec4(totalTransform.transform(physx::PxVec3(0.f, 11.f, 3.f) + mOffset),0.5)};
+
+ mClothActor[0]->mCloth->setSpheres(nv::cloth::Range<physx::PxVec4>(spheres, spheres + 2), 0, mClothActor[0]->mCloth->getNumSpheres());
+
+ mCollisionMehs->setTransform(totalTransform);
+
+ Scene::Animate(dt);
+}
+
+void CCDScene::initializeCloth(int index, physx::PxVec3 offset)
+{
+ mOffset = offset;
+
+ ///////////////////////////////////////////////////////////////////////
+ ClothMeshData clothMesh;
+
+ physx::PxMat44 transform = PxTransform(PxVec3(0.f, 13.f, 0.f)+ mOffset, PxQuat(0, PxVec3(1.f, 0.f, 0.f)));
+ clothMesh.GeneratePlaneCloth(5.f, 6.f, 69, 79, false, transform);
+ clothMesh.AttachClothPlaneByAngles(69, 79);
+ clothMesh.SetInvMasses(0.5f + (float)index * 2.0f);
+
+ mClothActor[index] = new ClothActor;
+ nv::cloth::ClothMeshDesc meshDesc = clothMesh.GetClothMeshDesc();
+ {
+ mClothActor[index]->mClothRenderMesh = new ClothRenderMesh(meshDesc);
+ mClothActor[index]->mClothRenderable = getSceneController()->getRenderer().createRenderable(*(static_cast<IRenderMesh*>(mClothActor[index]->mClothRenderMesh)), *getSceneController()->getDefaultMaterial());
+
+ float r, g, b;
+ r = index == 0 ? 1.0f : 0.3f;
+ g = index == 1 ? 1.0f : 0.3f;
+ b = index == 2 ? 1.0f : 0.3f;
+
+ mClothActor[index]->mClothRenderable->setColor(DirectX::XMFLOAT4(r, g, b, 1.0f));
+ }
+
+ nv::cloth::Vector<int32_t>::Type phaseTypeInfo;
+ mFabric[index] = NvClothCookFabricFromMesh(getSceneController()->getFactory(), meshDesc, physx::PxVec3(0.0f, 0.0f, 1.0f), &phaseTypeInfo, false);
+ trackFabric(mFabric[index]);
+
+ // Initialize start positions and masses for the actual cloth instance
+ // (note: the particle/vertex positions do not have to match the mesh description here. Set the positions to the initial shape of this cloth instance)
+ std::vector<physx::PxVec4> particlesCopy;
+ particlesCopy.resize(clothMesh.mVertices.size());
+
+ physx::PxVec3 clothOffset = transform.getPosition();
+ for(int i = 0; i < (int)clothMesh.mVertices.size(); i++)
+ {
+ // To put attachment point closer to each other
+ if(clothMesh.mInvMasses[i] < 1e-6)
+ clothMesh.mVertices[i] = (clothMesh.mVertices[i] - clothOffset)*0.95f + clothOffset;
+
+ particlesCopy[i] = physx::PxVec4(clothMesh.mVertices[i], clothMesh.mInvMasses[i]); // w component is 1/mass, or 0.0f for anchored/fixed particles
+ }
+
+ // Create the cloth from the initial positions/masses and the fabric
+ mClothActor[index]->mCloth = getSceneController()->getFactory()->createCloth(nv::cloth::Range<physx::PxVec4>(&particlesCopy[0], &particlesCopy[0] + particlesCopy.size()), *mFabric[index]);
+ particlesCopy.clear(); particlesCopy.shrink_to_fit();
+
+ mClothActor[index]->mCloth->setGravity(physx::PxVec3(0.0f, -9.8f, 0.0f));
+ mClothActor[index]->mCloth->setDamping(physx::PxVec3(0.1f, 0.1f, 0.1f));
+ mClothActor[index]->mCloth->setSelfCollisionDistance(0.07f);
+ mClothActor[index]->mCloth->enableContinuousCollision(true);
+ mClothActor[index]->mCloth->setSolverFrequency(240);
+
+
+ physx::PxVec4 spheres[2] = {physx::PxVec4(physx::PxVec3(0.f, 10.f, -2.f) + mOffset,2.0),
+ physx::PxVec4(physx::PxVec3(0.f, 11.f, 3.f) + mOffset,0.5)};
+
+ mClothActor[index]->mCloth->setSpheres(nv::cloth::Range<physx::PxVec4>(spheres, spheres + 2), 0, mClothActor[index]->mCloth->getNumSpheres());
+
+ uint32_t caps[4];
+ caps[0] = 0;
+ caps[1] = 1;
+
+ mClothActor[index]->mCloth->setCapsules(nv::cloth::Range<uint32_t>(caps, caps + 2), 0, mClothActor[index]->mCloth->getNumCapsules());
+
+ //create render mesh
+ auto mesh = MeshGenerator::generateCollisionCapsules(spheres,2,caps,2,-0.05f);
+ auto renderMesh = new MeshGenerator::MeshGeneratorRenderMesh(mesh);
+ mCollisionMehs = getSceneController()->getRenderer().createRenderable(*renderMesh, *getSceneController()->getDefaultMaterial());
+ trackRenderable(mCollisionMehs);
+
+ // Setup phase configs
+ std::vector<nv::cloth::PhaseConfig> phases(mFabric[index]->getNumPhases());
+ for(int i = 0; i < (int)phases.size(); i++)
+ {
+ phases[i].mPhaseIndex = i;
+ phases[i].mStiffness = 1.0f;
+ phases[i].mStiffnessMultiplier = 1.0f;
+ phases[i].mCompressionLimit = 1.0f;
+ phases[i].mStretchLimit = 1.0f;
+ }
+ mClothActor[index]->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
+ mClothActor[index]->mCloth->setDragCoefficient(0.5f);
+ mClothActor[index]->mCloth->setLiftCoefficient(0.6f);
+
+ trackClothActor(mClothActor[index]);
+
+ // Add the cloth to the solver for simulation
+ addClothToSolver(mClothActor[index], mSolver);
+}
+
+void CCDScene::onInitialize()
+{
+ mSolver = getSceneController()->getFactory()->createSolver();
+ trackSolver(mSolver);
+
+ initializeCloth(0, physx::PxVec3(0.0f, 0.0f, 0.0f));
+
+ {
+ IRenderMesh* mesh = getSceneController()->getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Plane);
+ Renderable* plane = getSceneController()->getRenderer().createRenderable(*mesh, *getSceneController()->getDefaultPlaneMaterial());
+ plane->setTransform(PxTransform(PxVec3(0.f, 0.f, 0.f), PxQuat(PxPiDivTwo, PxVec3(0.f, 0.f, 1.f))));
+ plane->setScale(PxVec3(1000.f));
+ trackRenderable(plane);
+ }
+}
diff --git a/NvCloth/samples/SampleBase/scene/scenes/CCDScene.h b/NvCloth/samples/SampleBase/scene/scenes/CCDScene.h
new file mode 100644
index 0000000..e988fb7
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/CCDScene.h
@@ -0,0 +1,37 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#ifndef CCD_SCENE_H
+#define CCD_SCENE_H
+
+#include "scene/Scene.h"
+#include <foundation/PxVec3.h>
+
+class CCDScene : public Scene
+{
+public:
+
+ CCDScene(SceneController* sceneController): Scene(sceneController) {}
+
+ virtual void Animate(double dt) override;
+ void initializeCloth(int index, physx::PxVec3 offset);
+ virtual void onInitialize() override;
+
+private:
+ nv::cloth::Fabric* mFabric[1];
+ nv::cloth::Solver* mSolver;
+ ClothActor* mClothActor[1];
+
+ physx::PxVec3 mOffset;
+ Renderable* mCollisionMehs;
+};
+
+
+#endif \ No newline at end of file
diff --git a/NvCloth/samples/SampleBase/scene/scenes/CapsuleScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/CapsuleScene.cpp
new file mode 100644
index 0000000..e16899c
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/CapsuleScene.cpp
@@ -0,0 +1,129 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#include "CapsuleScene.h"
+#include "Scene/SceneController.h"
+#include <NvClothExt/ClothFabricCooker.h>
+#include "ClothMeshGenerator.h"
+#include <NvCloth/Fabric.h>
+#include <NvCloth/Solver.h>
+#include <NvCloth/Cloth.h>
+#include <NvCloth/Factory.h>
+#include "Renderer.h"
+#include "renderer/RenderUtils.h"
+#include "windows.h"
+#include "utils/MeshGenerator.h"
+
+DECLARE_SCENE_NAME(CapsuleScene, "Capsule Scene")
+
+
+void CapsuleScene::initializeCloth(int index, physx::PxVec3 offset)
+{
+ ///////////////////////////////////////////////////////////////////////
+ ClothMeshData clothMesh;
+
+ physx::PxMat44 transform = PxTransform(PxVec3(0.f, 13.f, 0.f)+ offset, PxQuat(0, PxVec3(1.f, 0.f, 0.f)));
+ clothMesh.GeneratePlaneCloth(5.f, 6.f, 69, 79, false, transform);
+ clothMesh.AttachClothPlaneByAngles(69, 79);
+ clothMesh.SetInvMasses(0.5f + (float)index * 2.0f);
+
+ mClothActor[index] = new ClothActor;
+ nv::cloth::ClothMeshDesc meshDesc = clothMesh.GetClothMeshDesc();
+ {
+ mClothActor[index]->mClothRenderMesh = new ClothRenderMesh(meshDesc);
+ mClothActor[index]->mClothRenderable = getSceneController()->getRenderer().createRenderable(*(static_cast<IRenderMesh*>(mClothActor[index]->mClothRenderMesh)), *getSceneController()->getDefaultMaterial());
+
+ float r, g, b;
+ r = index == 0 ? 1.0f : 0.3f;
+ g = index == 1 ? 1.0f : 0.3f;
+ b = index == 2 ? 1.0f : 0.3f;
+
+ mClothActor[index]->mClothRenderable->setColor(DirectX::XMFLOAT4(r, g, b, 1.0f));
+ }
+
+ nv::cloth::Vector<int32_t>::Type phaseTypeInfo;
+ mFabric[index] = NvClothCookFabricFromMesh(getSceneController()->getFactory(), meshDesc, physx::PxVec3(0.0f, 0.0f, 1.0f), &phaseTypeInfo, false);
+ trackFabric(mFabric[index]);
+
+ // Initialize start positions and masses for the actual cloth instance
+ // (note: the particle/vertex positions do not have to match the mesh description here. Set the positions to the initial shape of this cloth instance)
+ std::vector<physx::PxVec4> particlesCopy;
+ particlesCopy.resize(clothMesh.mVertices.size());
+
+ physx::PxVec3 clothOffset = transform.getPosition();
+ for(int i = 0; i < (int)clothMesh.mVertices.size(); i++)
+ {
+ // To put attachment point closer to each other
+ if(clothMesh.mInvMasses[i] < 1e-6)
+ clothMesh.mVertices[i] = (clothMesh.mVertices[i] - clothOffset)*0.95f + clothOffset;
+
+ particlesCopy[i] = physx::PxVec4(clothMesh.mVertices[i], clothMesh.mInvMasses[i]); // w component is 1/mass, or 0.0f for anchored/fixed particles
+ }
+
+ // Create the cloth from the initial positions/masses and the fabric
+ mClothActor[index]->mCloth = getSceneController()->getFactory()->createCloth(nv::cloth::Range<physx::PxVec4>(&particlesCopy[0], &particlesCopy[0] + particlesCopy.size()), *mFabric[index]);
+ particlesCopy.clear(); particlesCopy.shrink_to_fit();
+
+ mClothActor[index]->mCloth->setGravity(physx::PxVec3(0.0f, -9.8f, 0.0f));
+ mClothActor[index]->mCloth->setDamping(physx::PxVec3(0.1f, 0.1f, 0.1f));
+
+
+ physx::PxVec4 spheres[2] = {physx::PxVec4(physx::PxVec3(0.f, 10.f, -2.f) + offset,3.0),
+ physx::PxVec4(physx::PxVec3(0.f, 10.f, 2.f) + offset,1.0)};
+
+ mClothActor[index]->mCloth->setSpheres(nv::cloth::Range<physx::PxVec4>(spheres, spheres + 2), 0, mClothActor[index]->mCloth->getNumSpheres());
+
+ uint32_t caps[4];
+ caps[0] = 0;
+ caps[1] = 1;
+
+ mClothActor[index]->mCloth->setCapsules(nv::cloth::Range<uint32_t>(caps, caps + 2), 0, mClothActor[index]->mCloth->getNumCapsules());
+
+ //create render mesh
+ auto mesh = MeshGenerator::generateCollisionCapsules(spheres,2,caps,2,-0.05f);
+ auto renderMesh = new MeshGenerator::MeshGeneratorRenderMesh(mesh);
+ Renderable* renderable = getSceneController()->getRenderer().createRenderable(*renderMesh, *getSceneController()->getDefaultMaterial());
+ trackRenderable(renderable);
+
+ // Setup phase configs
+ std::vector<nv::cloth::PhaseConfig> phases(mFabric[index]->getNumPhases());
+ for(int i = 0; i < (int)phases.size(); i++)
+ {
+ phases[i].mPhaseIndex = i;
+ phases[i].mStiffness = 1.0f;
+ phases[i].mStiffnessMultiplier = 1.0f;
+ phases[i].mCompressionLimit = 1.0f;
+ phases[i].mStretchLimit = 1.0f;
+ }
+ mClothActor[index]->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
+ mClothActor[index]->mCloth->setDragCoefficient(0.5f);
+ mClothActor[index]->mCloth->setLiftCoefficient(0.6f);
+
+ trackClothActor(mClothActor[index]);
+
+ // Add the cloth to the solver for simulation
+ addClothToSolver(mClothActor[index], mSolver);
+}
+
+void CapsuleScene::onInitialize()
+{
+ mSolver = getSceneController()->getFactory()->createSolver();
+ trackSolver(mSolver);
+
+ initializeCloth(0, physx::PxVec3(0.0f, 0.0f, 0.0f));
+
+ {
+ IRenderMesh* mesh = getSceneController()->getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Plane);
+ Renderable* plane = getSceneController()->getRenderer().createRenderable(*mesh, *getSceneController()->getDefaultPlaneMaterial());
+ plane->setTransform(PxTransform(PxVec3(0.f, 0.f, 0.f), PxQuat(PxPiDivTwo, PxVec3(0.f, 0.f, 1.f))));
+ plane->setScale(PxVec3(1000.f));
+ trackRenderable(plane);
+ }
+}
diff --git a/NvCloth/samples/SampleBase/scene/scenes/CapsuleScene.h b/NvCloth/samples/SampleBase/scene/scenes/CapsuleScene.h
new file mode 100644
index 0000000..f1f68fd
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/CapsuleScene.h
@@ -0,0 +1,33 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#ifndef CAPSULE_SCENE_H
+#define CAPSULE_SCENE_H
+
+#include "scene/Scene.h"
+#include <foundation/PxVec3.h>
+
+class CapsuleScene : public Scene
+{
+public:
+
+ CapsuleScene(SceneController* sceneController): Scene(sceneController) {}
+
+ void initializeCloth(int index, physx::PxVec3 offset);
+ virtual void onInitialize() override;
+
+private:
+ nv::cloth::Fabric* mFabric[1];
+ nv::cloth::Solver* mSolver;
+ ClothActor* mClothActor[1];
+};
+
+
+#endif \ No newline at end of file
diff --git a/NvCloth/samples/SampleBase/scene/scenes/ConvexCollisionScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/ConvexCollisionScene.cpp
new file mode 100644
index 0000000..28df734
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/ConvexCollisionScene.cpp
@@ -0,0 +1,138 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#include "ConvexCollisionScene.h"
+#include "Scene/SceneController.h"
+#include <NvClothExt/ClothFabricCooker.h>
+#include "ClothMeshGenerator.h"
+#include <NvCloth/Fabric.h>
+#include <NvCloth/Solver.h>
+#include <NvCloth/Cloth.h>
+#include <NvCloth/Factory.h>
+#include "Renderer.h"
+#include "renderer/RenderUtils.h"
+#include "windows.h"
+#include "utils/MeshGenerator.h"
+
+DECLARE_SCENE_NAME(ConvexCollisionScene, "Convex Collision Scene")
+
+
+void ConvexCollisionScene::initializeCloth(int index, physx::PxVec3 offset)
+{
+ ///////////////////////////////////////////////////////////////////////
+ ClothMeshData clothMesh;
+
+ physx::PxMat44 transform = PxTransform(PxVec3(0.f, 13.f, 0.f)+ offset, PxQuat(0, PxVec3(1.f, 0.f, 0.f)));
+ clothMesh.GeneratePlaneCloth(5.f, 6.f, 59, 69, false, transform);
+ clothMesh.AttachClothPlaneByAngles(59, 69);
+ clothMesh.SetInvMasses(0.5f + (float)index * 2.0f);
+
+ mClothActor[index] = new ClothActor;
+ nv::cloth::ClothMeshDesc meshDesc = clothMesh.GetClothMeshDesc();
+ {
+ mClothActor[index]->mClothRenderMesh = new ClothRenderMesh(meshDesc);
+ mClothActor[index]->mClothRenderable = getSceneController()->getRenderer().createRenderable(*(static_cast<IRenderMesh*>(mClothActor[index]->mClothRenderMesh)), *getSceneController()->getDefaultMaterial());
+
+ float r, g, b;
+ r = index == 0 ? 1.0f : 0.3f;
+ g = index == 1 ? 1.0f : 0.3f;
+ b = index == 2 ? 1.0f : 0.3f;
+
+ mClothActor[index]->mClothRenderable->setColor(DirectX::XMFLOAT4(r, g, b, 1.0f));
+ }
+
+ nv::cloth::Vector<int32_t>::Type phaseTypeInfo;
+ mFabric[index] = NvClothCookFabricFromMesh(getSceneController()->getFactory(), meshDesc, physx::PxVec3(0.0f, 0.0f, 1.0f), &phaseTypeInfo, false);
+ trackFabric(mFabric[index]);
+
+ // Initialize start positions and masses for the actual cloth instance
+ // (note: the particle/vertex positions do not have to match the mesh description here. Set the positions to the initial shape of this cloth instance)
+ std::vector<physx::PxVec4> particlesCopy;
+ particlesCopy.resize(clothMesh.mVertices.size());
+
+ physx::PxVec3 clothOffset = transform.getPosition();
+ for(int i = 0; i < (int)clothMesh.mVertices.size(); i++)
+ {
+ // To put attachment point closer to each other
+ if(clothMesh.mInvMasses[i] < 1e-6)
+ clothMesh.mVertices[i] = (clothMesh.mVertices[i] - clothOffset)*0.95f + clothOffset;
+
+ particlesCopy[i] = physx::PxVec4(clothMesh.mVertices[i], clothMesh.mInvMasses[i]); // w component is 1/mass, or 0.0f for anchored/fixed particles
+ }
+
+ // Create the cloth from the initial positions/masses and the fabric
+ mClothActor[index]->mCloth = getSceneController()->getFactory()->createCloth(nv::cloth::Range<physx::PxVec4>(&particlesCopy[0], &particlesCopy[0] + particlesCopy.size()), *mFabric[index]);
+ particlesCopy.clear(); particlesCopy.shrink_to_fit();
+
+ mClothActor[index]->mCloth->setGravity(physx::PxVec3(0.0f, -9.8f, 0.0f));
+ mClothActor[index]->mCloth->setDamping(physx::PxVec3(0.1f, 0.1f, 0.1f));
+
+ //Generate collision planes
+ std::vector<physx::PxVec4> planes;
+ uint32_t mask1 = MeshGenerator::generateConvexPolyhedronPlanes(4, 4, physx::PxVec3(0.7f, 10.0f, -1.0f), 1.0f, &planes);
+ uint32_t mask2 = MeshGenerator::generateConvexPolyhedronPlanes(4, 4, physx::PxVec3(-0.7f, 10.0f, 0.0f), 1.0f, &planes);
+ MeshGenerator::Mesh mesh1 = MeshGenerator::generateCollisionConvex(planes.data(),mask1,-0.05f,false);
+ MeshGenerator::Mesh mesh2 = MeshGenerator::generateCollisionConvex(planes.data(), mask2, -0.05f, false);
+
+ //assign as collision data
+ nv::cloth::Range<const physx::PxVec4> planesR(&planes[0], &planes[0] + planes.size());
+ mClothActor[index]->mCloth->setPlanes(planesR, 0, mClothActor[index]->mCloth->getNumPlanes());
+
+ //assign convex indices
+ std::vector<uint32_t> indices;
+ indices.push_back(mask1);
+ indices.push_back(mask2);
+ nv::cloth::Range<uint32_t> cind(&indices[0], &indices[0] + indices.size());
+ mClothActor[index]->mCloth->setConvexes(cind, 0, mClothActor[index]->mCloth->getNumConvexes());
+
+ //create render mesh
+ //scale down the render model to not intersect the triangles so much
+ auto renderMesh1 = new MeshGenerator::MeshGeneratorRenderMesh(mesh1);
+ Renderable* renderable1 = getSceneController()->getRenderer().createRenderable(*renderMesh1, *getSceneController()->getDefaultMaterial());
+ trackRenderable(renderable1);
+ auto renderMesh2 = new MeshGenerator::MeshGeneratorRenderMesh(mesh2);
+ Renderable* renderable2 = getSceneController()->getRenderer().createRenderable(*renderMesh2, *getSceneController()->getDefaultMaterial());
+ trackRenderable(renderable2);
+
+ // Setup phase configs
+ std::vector<nv::cloth::PhaseConfig> phases(mFabric[index]->getNumPhases());
+ for(int i = 0; i < (int)phases.size(); i++)
+ {
+ phases[i].mPhaseIndex = i;
+ phases[i].mStiffness = 1.0f;
+ phases[i].mStiffnessMultiplier = 1.0f;
+ phases[i].mCompressionLimit = 1.0f;
+ phases[i].mStretchLimit = 1.0f;
+ }
+ mClothActor[index]->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
+ mClothActor[index]->mCloth->setDragCoefficient(0.1f);
+ mClothActor[index]->mCloth->setLiftCoefficient(0.1f);
+
+ trackClothActor(mClothActor[index]);
+
+ // Add the cloth to the solver for simulation
+ addClothToSolver(mClothActor[index], mSolver);
+}
+
+void ConvexCollisionScene::onInitialize()
+{
+ mSolver = getSceneController()->getFactory()->createSolver();
+ trackSolver(mSolver);
+
+ initializeCloth(0, physx::PxVec3(0.0f, 0.0f, 0.0f));
+
+ {
+ IRenderMesh* mesh = getSceneController()->getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Plane);
+ Renderable* plane = getSceneController()->getRenderer().createRenderable(*mesh, *getSceneController()->getDefaultPlaneMaterial());
+ plane->setTransform(PxTransform(PxVec3(0.f, 0.f, 0.f), PxQuat(PxPiDivTwo, PxVec3(0.f, 0.f, 1.f))));
+ plane->setScale(PxVec3(1000.f));
+ trackRenderable(plane);
+ }
+}
diff --git a/NvCloth/samples/SampleBase/scene/scenes/ConvexCollisionScene.h b/NvCloth/samples/SampleBase/scene/scenes/ConvexCollisionScene.h
new file mode 100644
index 0000000..7c9d062
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/ConvexCollisionScene.h
@@ -0,0 +1,33 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#ifndef CONVEX_COLLISION_SCENE_H
+#define CONVEX_COLLISION_SCENE_H
+
+#include "scene/Scene.h"
+#include <foundation/PxVec3.h>
+
+class ConvexCollisionScene : public Scene
+{
+public:
+
+ ConvexCollisionScene(SceneController* sceneController): Scene(sceneController) {}
+
+ void initializeCloth(int index, physx::PxVec3 offset);
+ virtual void onInitialize() override;
+
+private:
+ nv::cloth::Fabric* mFabric[1];
+ nv::cloth::Solver* mSolver;
+ ClothActor* mClothActor[1];
+};
+
+
+#endif \ No newline at end of file
diff --git a/NvCloth/samples/SampleBase/scene/scenes/DistanceConstraintScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/DistanceConstraintScene.cpp
new file mode 100644
index 0000000..eaac8e1
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/DistanceConstraintScene.cpp
@@ -0,0 +1,100 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#include "DistanceConstraintScene.h"
+#include "Scene/SceneController.h"
+#include <NvClothExt/ClothFabricCooker.h>
+#include "ClothMeshGenerator.h"
+#include <NvCloth/Fabric.h>
+#include <NvCloth/Solver.h>
+#include <NvCloth/Cloth.h>
+#include <NvCloth/Factory.h>
+#include "Renderer.h"
+#include "renderer/RenderUtils.h"
+
+DECLARE_SCENE_NAME(DistanceConstraintScene,"Distance Constraint Scene")
+
+void DistanceConstraintScene::onInitialize()
+{
+ ///////////////////////////////////////////////////////////////////////
+ ClothMeshData clothMesh;
+
+ physx::PxMat44 transform = PxTransform(PxVec3(0.f, 13.f, 0.f), physx::PxQuat(-0.9f, physx::PxVec3(0.0f, 1.0f, 0.0f)) * physx::PxQuat(PxPiDivFour, physx::PxVec3(1.0f, 0.0f, 0.0f)));
+ clothMesh.GeneratePlaneCloth(6.f, 7.f, 39, 39, false, transform);
+ clothMesh.AttachClothPlaneByAngles(39, 39);
+
+ mClothActor = new ClothActor;
+ nv::cloth::ClothMeshDesc meshDesc = clothMesh.GetClothMeshDesc();
+ {
+ mClothActor->mClothRenderMesh = new ClothRenderMesh(meshDesc);
+ mClothActor->mClothRenderable = getSceneController()->getRenderer().createRenderable(*(static_cast<IRenderMesh*>(mClothActor->mClothRenderMesh)), *getSceneController()->getDefaultMaterial());
+ mClothActor->mClothRenderable->setColor(getRandomPastelColor());
+ }
+
+ nv::cloth::Vector<int32_t>::Type phaseTypeInfo;
+ mFabric = NvClothCookFabricFromMesh(getSceneController()->getFactory(), meshDesc, physx::PxVec3(0.0f, -1.0f, 0.0f), &phaseTypeInfo, false);
+ trackFabric(mFabric);
+
+ // Initialize start positions and masses for the actual cloth instance
+ // (note: the particle/vertex positions do not have to match the mesh description here. Set the positions to the initial shape of this cloth instance)
+ std::vector<physx::PxVec4> particlesCopy;
+ particlesCopy.resize(clothMesh.mVertices.size());
+
+ for(int i = 0; i < (int)clothMesh.mVertices.size(); i++)
+ {
+ particlesCopy[i] = physx::PxVec4(clothMesh.mVertices[i], clothMesh.mInvMasses[i]); // w component is 1/mass, or 0.0f for anchored/fixed particles
+ }
+
+ // Create the cloth from the initial positions/masses and the fabric
+ mClothActor->mCloth = getSceneController()->getFactory()->createCloth(nv::cloth::Range<physx::PxVec4>(&particlesCopy[0], &particlesCopy[0] + particlesCopy.size()), *mFabric);
+
+
+ ////////////////////////////////////
+ //// Set distance constraints ////
+ ////////////////////////////////////
+ nv::cloth::Range<physx::PxVec4> distanceConstraints = mClothActor->mCloth->getMotionConstraints();
+ for(int i = 0; i < (int)distanceConstraints.size(); i++)
+ {
+ distanceConstraints[i] = physx::PxVec4(particlesCopy[i].getXYZ(), 0.002f*(i % 800) * 0.002f*(i % 800));
+ }
+
+ particlesCopy.clear(); particlesCopy.shrink_to_fit();
+
+ mClothActor->mCloth->setGravity(physx::PxVec3(0.0f, -9.8f, 0.0f));
+
+ // Setup phase configs
+ std::vector<nv::cloth::PhaseConfig> phases(mFabric->getNumPhases());
+ for(int i = 0; i < (int)phases.size(); i++)
+ {
+ phases[i].mPhaseIndex = i;
+ phases[i].mStiffness = 1.0f;
+ phases[i].mStiffnessMultiplier = 1.0f;
+ phases[i].mCompressionLimit = 1.0f;
+ phases[i].mStretchLimit = 1.0f;
+ }
+ mClothActor->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
+// mClothActor->mCloth->setDragCoefficient(0.1f);
+// mClothActor->mCloth->setDragCoefficient(0.1f);
+
+ mSolver = getSceneController()->getFactory()->createSolver();
+ trackSolver(mSolver);
+ trackClothActor(mClothActor);
+
+ // Add the cloth to the solver for simulation
+ addClothToSolver(mClothActor, mSolver);
+
+ {
+ IRenderMesh* mesh = getSceneController()->getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Plane);
+ Renderable* plane = getSceneController()->getRenderer().createRenderable(*mesh, *getSceneController()->getDefaultPlaneMaterial());
+ plane->setTransform(PxTransform(PxVec3(0.f, 0.f, 0.f), PxQuat(PxPiDivTwo, PxVec3(0.f, 0.f, 1.f))));
+ plane->setScale(PxVec3(1000.f));
+ trackRenderable(plane);
+ }
+}
diff --git a/NvCloth/samples/SampleBase/scene/scenes/DistanceConstraintScene.h b/NvCloth/samples/SampleBase/scene/scenes/DistanceConstraintScene.h
new file mode 100644
index 0000000..5c61195
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/DistanceConstraintScene.h
@@ -0,0 +1,32 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#ifndef DISTANCE_CONSTRAINT_SCENE_H
+#define DISTANCE_CONSTRAINT_SCENE_H
+
+#include "scene/Scene.h"
+
+class DistanceConstraintScene : public Scene
+{
+public:
+
+ DistanceConstraintScene(SceneController* sceneController):Scene(sceneController) {}
+
+ virtual void onInitialize() override;
+
+private:
+ nv::cloth::Fabric* mFabric;
+ nv::cloth::Solver* mSolver;
+ ClothActor* mClothActor;
+
+};
+
+
+#endif \ No newline at end of file
diff --git a/NvCloth/samples/SampleBase/scene/scenes/FreeFallScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/FreeFallScene.cpp
index c1f6a00..9cd1121 100644
--- a/NvCloth/samples/SampleBase/scene/scenes/FreeFallScene.cpp
+++ b/NvCloth/samples/SampleBase/scene/scenes/FreeFallScene.cpp
@@ -74,7 +74,7 @@ void FreeFallScene::initializeCloth(int index, physx::PxVec3 offset)
mClothActor[index]->mCloth->setGravity(physx::PxVec3(0.0f, -1.0f, 0.0f));
mClothActor[index]->mCloth->setFriction(0.1);
- mClothActor[index]->mCloth->setDragCoefficient(0.5);
+ mClothActor[index]->mCloth->setDragCoefficient(0.1);
mClothActor[index]->mCloth->setLiftCoefficient(0.0);
// Setup phase configs
@@ -89,8 +89,6 @@ void FreeFallScene::initializeCloth(int index, physx::PxVec3 offset)
}
mClothActor[index]->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
- mSolver = getSceneController()->getFactory()->createSolver();
- trackSolver(mSolver);
trackClothActor(mClothActor[index]);
// Add the cloth to the solver for simulation
@@ -99,12 +97,12 @@ void FreeFallScene::initializeCloth(int index, physx::PxVec3 offset)
void FreeFallScene::onInitialize()
{
- float spaceX = -1.5f;
+ mSolver = getSceneController()->getFactory()->createSolver();
+ trackSolver(mSolver);
+ float spaceX = -1.1f;
for(int i = 0; i < 4; ++i)
- {
- initializeCloth(i, physx::PxVec3(16.f + float((i+1)*(i+1)) * spaceX, 2.f, -7.f));
- }
+ initializeCloth(i, physx::PxVec3(8.f + float((i+1)*(i+1)) * spaceX, 2.f, -7.f));
{
IRenderMesh* mesh = getSceneController()->getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Plane);
diff --git a/NvCloth/samples/SampleBase/scene/scenes/FrictionScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/FrictionScene.cpp
index 3c181ea..3848c6f 100644
--- a/NvCloth/samples/SampleBase/scene/scenes/FrictionScene.cpp
+++ b/NvCloth/samples/SampleBase/scene/scenes/FrictionScene.cpp
@@ -26,8 +26,8 @@ void FrictionScene::initializeCloth(int index, physx::PxVec3 offset, float frict
///////////////////////////////////////////////////////////////////////
ClothMeshData clothMesh;
- physx::PxMat44 transform = PxTransform(PxVec3(0.f, 13.f, 0.f)+ offset, PxQuat(PxPi / 6.f, PxVec3(1.f, 0.f, 0.f)));
- clothMesh.GeneratePlaneCloth(3.f, 3.f, 29, 29, false, transform);
+ physx::PxMat44 transform = PxTransform(PxVec3(0.f, 9.f, 0.f) + offset, PxQuat(PxPi / 6.f, PxVec3(1.f, 0.f, 0.f)));
+ clothMesh.GeneratePlaneCloth(4.f, 5.f, 29, 34, false, transform);
mClothActor[index] = new ClothActor;
nv::cloth::ClothMeshDesc meshDesc = clothMesh.GetClothMeshDesc();
@@ -47,7 +47,7 @@ void FrictionScene::initializeCloth(int index, physx::PxVec3 offset, float frict
particlesCopy.resize(clothMesh.mVertices.size());
physx::PxVec3 clothOffset = transform.getPosition();
- for(int i = 0; i < (int)clothMesh.mVertices.size(); i++)
+ for (int i = 0; i < (int)clothMesh.mVertices.size(); i++)
{
// To put attachment point closer to each other
if(clothMesh.mInvMasses[i] < 1e-6)
@@ -67,7 +67,7 @@ void FrictionScene::initializeCloth(int index, physx::PxVec3 offset, float frict
mClothActor[index]->mCloth->setPlanes(planesR, 0, mClothActor[index]->mCloth->getNumPlanes());
std::vector<uint32_t> indices;
indices.resize(planes.size());
- for(int i = 0; i < (int)indices.size(); i++)
+ for (int i = 0; i < (int)indices.size(); i++)
indices[i] = 1 << i;
nv::cloth::Range<uint32_t> cind(&indices[0], &indices[0] + indices.size());
mClothActor[index]->mCloth->setConvexes(cind, 0, mClothActor[index]->mCloth->getNumConvexes());
@@ -76,7 +76,7 @@ void FrictionScene::initializeCloth(int index, physx::PxVec3 offset, float frict
// Setup phase configs
std::vector<nv::cloth::PhaseConfig> phases(mFabric[index]->getNumPhases());
- for(int i = 0; i < (int)phases.size(); i++)
+ for (int i = 0; i < (int)phases.size(); i++)
{
phases[i].mPhaseIndex = i;
phases[i].mStiffness = 1.0f;
@@ -87,8 +87,6 @@ void FrictionScene::initializeCloth(int index, physx::PxVec3 offset, float frict
mClothActor[index]->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
mClothActor[index]->mCloth->setFriction(frictionCoef);
- mSolver = getSceneController()->getFactory()->createSolver();
- trackSolver(mSolver);
trackClothActor(mClothActor[index]);
// Add the cloth to the solver for simulation
@@ -97,15 +95,15 @@ void FrictionScene::initializeCloth(int index, physx::PxVec3 offset, float frict
void FrictionScene::onInitialize()
{
-
+ mSolver = getSceneController()->getFactory()->createSolver();
+ trackSolver(mSolver);
- float spaceX = -4.f;
+ float spaceX = -5.f;
float frictionDelta = 0.2f;
- for(int i = 0; i < 4; ++i)
+ for (int i = 0; i < 5; ++i)
{
- float friction = i > 0 ? float(i) * frictionDelta : 0.f; // 0.0, 0.2, 0.4, 0.6
-
+ float friction = i > 0 ? float(i) * frictionDelta : 0.f; // 0.0, 0.2, 0.4, 0.6, 0.8
initializeCloth(i, physx::PxVec3(4.f + float(i) * spaceX, 4.f, -18.f), friction);
}
diff --git a/NvCloth/samples/SampleBase/scene/scenes/FrictionScene.h b/NvCloth/samples/SampleBase/scene/scenes/FrictionScene.h
index 4173e09..8d03307 100644
--- a/NvCloth/samples/SampleBase/scene/scenes/FrictionScene.h
+++ b/NvCloth/samples/SampleBase/scene/scenes/FrictionScene.h
@@ -24,9 +24,9 @@ public:
virtual void onInitialize() override;
private:
- nv::cloth::Fabric* mFabric[4];
+ nv::cloth::Fabric* mFabric[5];
nv::cloth::Solver* mSolver;
- ClothActor* mClothActor[4];
+ ClothActor* mClothActor[5];
};
diff --git a/NvCloth/samples/SampleBase/scene/scenes/GeodesicScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/GeodesicScene.cpp
new file mode 100644
index 0000000..3216dca
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/GeodesicScene.cpp
@@ -0,0 +1,114 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#include "GeodesicScene.h"
+#include "Scene/SceneController.h"
+#include <NvClothExt/ClothFabricCooker.h>
+#include "ClothMeshGenerator.h"
+#include <NvCloth/Fabric.h>
+#include <NvCloth/Solver.h>
+#include <NvCloth/Cloth.h>
+#include <NvCloth/Factory.h>
+#include "Renderer.h"
+#include "renderer/RenderUtils.h"
+
+DECLARE_SCENE_NAME(GeodesicScene, "Geodesic Scene")
+
+void GeodesicScene::initializeCloth(int index, physx::PxVec3 offset, bool geodesic)
+{
+ ///////////////////////////////////////////////////////////////////////
+ ClothMeshData clothMesh;
+
+ physx::PxMat44 transform = PxTransform(PxVec3(0.f, 13.f, 0.f) + offset, PxQuat(0, PxVec3(1.f, 0.f, 0.f)));
+ clothMesh.GeneratePlaneCloth(6.f, 10.0f, 39, 59, false, transform,true,true);
+ clothMesh.AttachClothPlaneByAngles(39, 59);
+
+ /*for(int y = 0; y < 60; y++)
+ {
+ for(int x = 0; x < 40; x++)
+ {
+ //clothMesh.mVertices[x + y * 40].y = transform.transform(PxVec3(0.0f, y&2?0.25f:-0.25f, 0.0f)).y;
+ PxVec3 pos = transform.transform(PxVec3(0.0f, y & 1 ? 0.1f : -0.1f, 10.0f * (float)(y>>2)/(float)60.0f));
+ clothMesh.mVertices[x + y * 40].y = pos.y;
+ clothMesh.mVertices[x + y * 40].z = pos.z;
+ }
+ }*/
+
+ mClothActor[index] = new ClothActor;
+ nv::cloth::ClothMeshDesc meshDesc = clothMesh.GetClothMeshDesc();
+ {
+ mClothActor[index]->mClothRenderMesh = new ClothRenderMesh(meshDesc);
+ mClothActor[index]->mClothRenderable = getSceneController()->getRenderer().createRenderable(*(static_cast<IRenderMesh*>(mClothActor[index]->mClothRenderMesh)), *getSceneController()->getDefaultMaterial());
+ mClothActor[index]->mClothRenderable->setColor(getRandomPastelColor());
+ }
+
+ nv::cloth::Vector<int32_t>::Type phaseTypeInfo;
+ mFabric[index] = NvClothCookFabricFromMesh(getSceneController()->getFactory(), meshDesc, physx::PxVec3(0.0f, 0.0f, 1.0f),
+ &phaseTypeInfo, geodesic);
+ trackFabric(mFabric[index]);
+
+ // Initialize start positions and masses for the actual cloth instance
+ // (note: the particle/vertex positions do not have to match the mesh description here. Set the positions to the initial shape of this cloth instance)
+ std::vector<physx::PxVec4> particlesCopy;
+ particlesCopy.resize(clothMesh.mVertices.size());
+
+ physx::PxVec3 clothOffset = transform.getPosition();
+ for (int i = 0; i < (int)clothMesh.mVertices.size(); i++)
+ {
+ // To put attachment point closer to each other
+ if(clothMesh.mInvMasses[i] < 1e-6)
+ clothMesh.mVertices[i] = (clothMesh.mVertices[i] - clothOffset)*0.99f + clothOffset;
+
+ particlesCopy[i] = physx::PxVec4(clothMesh.mVertices[i], clothMesh.mInvMasses[i]); // w component is 1/mass, or 0.0f for anchored/fixed particles
+ }
+
+ // Create the cloth from the initial positions/masses and the fabric
+ mClothActor[index]->mCloth = getSceneController()->getFactory()->createCloth(nv::cloth::Range<physx::PxVec4>(&particlesCopy[0], &particlesCopy[0] + particlesCopy.size()), *mFabric[index]);
+ particlesCopy.clear(); particlesCopy.shrink_to_fit();
+
+ mClothActor[index]->mCloth->setGravity(physx::PxVec3(0.0f, -9.8f, 0.0f));
+ mClothActor[index]->mCloth->setTetherConstraintStiffness(1.0f);
+
+ // Setup phase configs
+ std::vector<nv::cloth::PhaseConfig> phases(mFabric[index]->getNumPhases());
+ for (int i = 0; i < (int)phases.size(); i++)
+ {
+ phases[i].mPhaseIndex = i;
+ phases[i].mStiffness = 1.0f;
+ phases[i].mStiffnessMultiplier = 1.0f;
+ phases[i].mCompressionLimit = 1.0f;
+ phases[i].mStretchLimit = 1.0f;
+ }
+ mClothActor[index]->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
+
+ trackClothActor(mClothActor[index]);
+
+ // Add the cloth to the solver for simulation
+ addClothToSolver(mClothActor[index], mSolver);
+}
+
+void GeodesicScene::onInitialize()
+{
+ mSolver = getSceneController()->getFactory()->createSolver();
+ trackSolver(mSolver);
+
+ initializeCloth(0, physx::PxVec3(-5.0f, 0.0f, 0.0f), false);
+ initializeCloth(1, physx::PxVec3(4.0f, 0.0f, 0.0f), true);
+
+ mTime = 0.0f;
+
+ {
+ IRenderMesh* mesh = getSceneController()->getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Plane);
+ Renderable* plane = getSceneController()->getRenderer().createRenderable(*mesh, *getSceneController()->getDefaultPlaneMaterial());
+ plane->setTransform(PxTransform(PxVec3(0.f, 0.f, 0.f), PxQuat(PxPiDivTwo, PxVec3(0.f, 0.f, 1.f))));
+ plane->setScale(PxVec3(1000.f));
+ trackRenderable(plane);
+ }
+}
diff --git a/NvCloth/samples/SampleBase/scene/scenes/GeodesicScene.h b/NvCloth/samples/SampleBase/scene/scenes/GeodesicScene.h
new file mode 100644
index 0000000..3a0822e
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/GeodesicScene.h
@@ -0,0 +1,36 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#ifndef GEODESIC_SCENE_H
+#define GEODESIC_SCENE_H
+
+#include "scene/Scene.h"
+#include <foundation/PxVec3.h>
+
+class GeodesicScene : public Scene
+{
+public:
+
+ GeodesicScene(SceneController* sceneController): Scene(sceneController) {}
+
+ void initializeCloth(int index, physx::PxVec3 offset, bool geodesic);
+ virtual void onInitialize() override;
+
+private:
+ nv::cloth::Fabric* mFabric[2];
+ nv::cloth::Solver* mSolver;
+ ClothActor* mClothActor[2];
+
+ float mTime;
+
+};
+
+
+#endif \ No newline at end of file
diff --git a/NvCloth/samples/SampleBase/scene/scenes/InterCollisionScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/InterCollisionScene.cpp
new file mode 100644
index 0000000..b75facd
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/InterCollisionScene.cpp
@@ -0,0 +1,128 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#include "InterCollisionScene.h"
+#include "Scene/SceneController.h"
+#include <NvClothExt/ClothFabricCooker.h>
+#include "ClothMeshGenerator.h"
+#include <NvCloth/Fabric.h>
+#include <NvCloth/Solver.h>
+#include <NvCloth/Cloth.h>
+#include <NvCloth/Factory.h>
+#include "Renderer.h"
+#include "renderer/RenderUtils.h"
+
+DECLARE_SCENE_NAME(InterCollisionScene, "Inter Collision Scene")
+
+void InterCollisionScene::initializeCloth(int index, physx::PxMat44 transform)
+{
+ ///////////////////////////////////////////////////////////////////////
+ ClothMeshData clothMesh;
+ float w = 5.f - index;
+ float h = 6.f + index;
+ transform *= PxTransform(PxVec3(0.f, 13.f, 0.f), PxQuat(0, PxVec3(1.f, 0.f, 0.f)));
+ clothMesh.GeneratePlaneCloth(w,h, 5*w, 5*h, false, transform);
+ clothMesh.AttachClothPlaneByAngles(5 * w, 5 * h);
+ //clothMesh.SetInvMasses(1.0f / (1000.0f / (5.0f*w*5.0f*h)));
+
+ mClothActor[index] = new ClothActor;
+ nv::cloth::ClothMeshDesc meshDesc = clothMesh.GetClothMeshDesc();
+ {
+ mClothActor[index]->mClothRenderMesh = new ClothRenderMesh(meshDesc);
+ mClothActor[index]->mClothRenderable = getSceneController()->getRenderer().createRenderable(*(static_cast<IRenderMesh*>(mClothActor[index]->mClothRenderMesh)), *getSceneController()->getDefaultMaterial());
+ mClothActor[index]->mClothRenderable->setColor(getRandomPastelColor());
+ }
+
+ nv::cloth::Vector<int32_t>::Type phaseTypeInfo;
+ mFabric[index] = NvClothCookFabricFromMesh(getSceneController()->getFactory(), meshDesc, physx::PxVec3(0.0f, 0.0f, 1.0f), &phaseTypeInfo, false);
+ trackFabric(mFabric[index]);
+
+ // Initialize start positions and masses for the actual cloth instance
+ // (note: the particle/vertex positions do not have to match the mesh description here. Set the positions to the initial shape of this cloth instance)
+ std::vector<physx::PxVec4> particlesCopy;
+ particlesCopy.resize(clothMesh.mVertices.size());
+
+ physx::PxVec3 clothOffset = transform.getPosition();
+ for(int i = 0; i < (int)clothMesh.mVertices.size(); i++)
+ {
+ // To put attachment point closer to each other
+ if(clothMesh.mInvMasses[i] < 1e-6)
+ clothMesh.mVertices[i] = (clothMesh.mVertices[i] - clothOffset)*0.9f + clothOffset;
+
+ particlesCopy[i] = physx::PxVec4(clothMesh.mVertices[i], clothMesh.mInvMasses[i]); // w component is 1/mass, or 0.0f for anchored/fixed particles
+ }
+
+ // Create the cloth from the initial positions/masses and the fabric
+ mClothActor[index]->mCloth = getSceneController()->getFactory()->createCloth(nv::cloth::Range<physx::PxVec4>(&particlesCopy[0], &particlesCopy[0] + particlesCopy.size()), *mFabric[index]);
+ particlesCopy.clear(); particlesCopy.shrink_to_fit();
+
+ std::vector<physx::PxVec4> planes;
+ planes.push_back(physx::PxVec4(physx::PxVec3(0.0f, 1.f, 0.0f), -0.01f));
+
+ nv::cloth::Range<const physx::PxVec4> planesR(&planes[0], &planes[0] + planes.size());
+ mClothActor[index]->mCloth->setPlanes(planesR, 0, mClothActor[index]->mCloth->getNumPlanes());
+ std::vector<uint32_t> indices;
+ indices.resize(planes.size());
+ for(int i = 0; i < (int)indices.size(); i++)
+ indices[i] = 1 << i;
+ nv::cloth::Range<uint32_t> cind(&indices[0], &indices[0] + indices.size());
+ mClothActor[index]->mCloth->setConvexes(cind, 0, mClothActor[index]->mCloth->getNumConvexes());
+
+ mClothActor[index]->mCloth->setGravity(physx::PxVec3(0.0f, -1.0f, 0.0f));
+ mClothActor[index]->mCloth->setFriction(0.1);
+ mClothActor[index]->mCloth->setDragCoefficient(0.1f);
+ mClothActor[index]->mCloth->setLiftCoefficient(0.1f);
+ mClothActor[index]->mCloth->setSolverFrequency(120.0f);
+
+ // Setup phase configs
+ std::vector<nv::cloth::PhaseConfig> phases(mFabric[index]->getNumPhases());
+ for(int i = 0; i < (int)phases.size(); i++)
+ {
+ phases[i].mPhaseIndex = i;
+ phases[i].mStiffness = 1.0f;
+ phases[i].mStiffnessMultiplier = 1.0f;
+ phases[i].mCompressionLimit = 1.0f;
+ phases[i].mStretchLimit = 1.0f;
+ }
+ mClothActor[index]->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
+
+ trackClothActor(mClothActor[index]);
+
+ // Add the cloth to the solver for simulation
+ addClothToSolver(mClothActor[index], mSolver);
+}
+
+void InterCollisionScene::onInitialize()
+{
+ mSolver = getSceneController()->getFactory()->createSolver();
+ mSolver->setInterCollisionNbIterations(8);
+ mSolver->setInterCollisionDistance(0.4f);
+ mSolver->setInterCollisionStiffness(0.95f);
+ mSolver->setInterCollisionFilter(
+ [](void* a, void* b) {
+ return true;
+ }
+ );
+ trackSolver(mSolver);
+
+ physx::PxMat44 posTrans(physx::PxIdentity);
+ posTrans.setPosition(physx::PxVec3(0.0f, 0.f, -1.0f));
+ initializeCloth(0, posTrans);
+ posTrans.setPosition(physx::PxVec3(0.0f, 0.8f, -1.2f));
+ initializeCloth(1, posTrans);
+
+ {
+ IRenderMesh* mesh = getSceneController()->getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Plane);
+ Renderable* plane = getSceneController()->getRenderer().createRenderable(*mesh, *getSceneController()->getDefaultPlaneMaterial());
+ plane->setTransform(PxTransform(PxVec3(0.f, 0.f, 0.f), PxQuat(PxPiDivTwo, PxVec3(0.f, 0.f, 1.f))));
+ plane->setScale(PxVec3(1000.f));
+ trackRenderable(plane);
+ }
+}
diff --git a/NvCloth/samples/SampleBase/scene/scenes/InterCollisionScene.h b/NvCloth/samples/SampleBase/scene/scenes/InterCollisionScene.h
new file mode 100644
index 0000000..1ef0b45
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/InterCollisionScene.h
@@ -0,0 +1,33 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#ifndef INTER_COLLISION_SCENE_H
+#define INTER_COLLISION_SCENE_H
+
+#include "scene/Scene.h"
+#include <foundation/PxVec3.h>
+
+class InterCollisionScene : public Scene
+{
+public:
+
+ InterCollisionScene(SceneController* sceneController): Scene(sceneController) {}
+
+ void initializeCloth(int index, physx::PxMat44 transform);
+ virtual void onInitialize() override;
+
+private:
+ nv::cloth::Fabric* mFabric[2];
+ nv::cloth::Solver* mSolver;
+ ClothActor* mClothActor[2];
+};
+
+
+#endif \ No newline at end of file
diff --git a/NvCloth/samples/SampleBase/scene/scenes/LocalGlobalScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/LocalGlobalScene.cpp
new file mode 100644
index 0000000..57cd1a2
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/LocalGlobalScene.cpp
@@ -0,0 +1,141 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#include "LocalGlobalScene.h"
+#include "Scene/SceneController.h"
+#include <NvClothExt/ClothFabricCooker.h>
+#include "ClothMeshGenerator.h"
+#include <NvCloth/Fabric.h>
+#include <NvCloth/Solver.h>
+#include <NvCloth/Cloth.h>
+#include <NvCloth/Factory.h>
+#include "Renderer.h"
+#include "renderer/RenderUtils.h"
+#include "windows.h"
+
+DECLARE_SCENE_NAME(LocalGlobalScene, "Local/Global Scene")
+
+void LocalGlobalScene::Animate(double dt)
+{
+ physx::PxVec3 position(sin(mTime * 2.0f) * 3.0f, sinf(mTime) * 2.0f, cosf(mTime) - 1.0f);
+ physx::PxQuat rotation(sin(mTime * 1.0f) * 4.0f, physx::PxVec3(0.0f, 1.0f, 0.0f));
+
+
+ mTime += dt;
+
+ mClothActor[0]->mCloth->setTranslation(position);
+ mClothActor[0]->mCloth->setRotation(rotation);
+ mClothActor[0]->mClothRenderable->setTransform(physx::PxTransform(position + physx::PxVec3(-4.f, 0.f, 0.f), rotation));
+
+ mClothActor[1]->mClothRenderable->setTransform(physx::PxTransform(physx::PxVec3(4.f, 0.f, 0.f), physx::PxQuat(1.f)));
+ {
+ nv::cloth::MappedRange<physx::PxVec4> particles = mClothActor[1]->mCloth->getCurrentParticles();
+ for (int i = 0; i < 2; i++)
+ {
+ particles[mAttachmentVertices[i]] = physx::PxVec4(physx::PxTransform(position, rotation).transform(mAttachmentVertexOriginalPositions[i].getXYZ()), mAttachmentVertexOriginalPositions[i].w);
+ }
+ }
+ Scene::Animate(dt);
+}
+
+void LocalGlobalScene::initializeCloth(int index, physx::PxVec3 offset)
+{
+ ///////////////////////////////////////////////////////////////////////
+ ClothMeshData clothMesh;
+
+ physx::PxMat44 transform = PxTransform(PxVec3(0.f, 13.f, 0.f)+ offset, PxQuat(PxPi / 2.0f, PxVec3(1.f, 0.f, 0.f)));
+ clothMesh.GeneratePlaneCloth(5.f, 6.f, 69, 79, false, transform);
+ clothMesh.AttachClothPlaneByAngles(69, 79);
+ clothMesh.SetInvMasses(0.5f + (float)index * 2.0f);
+
+ mClothActor[index] = new ClothActor;
+ nv::cloth::ClothMeshDesc meshDesc = clothMesh.GetClothMeshDesc();
+ {
+ mClothActor[index]->mClothRenderMesh = new ClothRenderMesh(meshDesc);
+ mClothActor[index]->mClothRenderable = getSceneController()->getRenderer().createRenderable(*(static_cast<IRenderMesh*>(mClothActor[index]->mClothRenderMesh)), *getSceneController()->getDefaultMaterial());
+
+ float r, g, b;
+ r = index == 0 ? 1.0f : 0.3f;
+ g = index == 1 ? 1.0f : 0.3f;
+ b = index == 2 ? 1.0f : 0.3f;
+
+ mClothActor[index]->mClothRenderable->setColor(DirectX::XMFLOAT4(r, g, b, 1.0f));
+ }
+
+ nv::cloth::Vector<int32_t>::Type phaseTypeInfo;
+ mFabric[index] = NvClothCookFabricFromMesh(getSceneController()->getFactory(), meshDesc, physx::PxVec3(0.0f, 0.0f, 1.0f), &phaseTypeInfo, false);
+ trackFabric(mFabric[index]);
+
+ // Initialize start positions and masses for the actual cloth instance
+ // (note: the particle/vertex positions do not have to match the mesh description here. Set the positions to the initial shape of this cloth instance)
+ std::vector<physx::PxVec4> particlesCopy;
+ particlesCopy.resize(clothMesh.mVertices.size());
+
+ physx::PxVec3 clothOffset = transform.getPosition();
+ for (int i = 0; i < (int)clothMesh.mVertices.size(); i++)
+ {
+ // To put attachment point closer to each other
+ if(clothMesh.mInvMasses[i] < 1e-6)
+ clothMesh.mVertices[i] = (clothMesh.mVertices[i] - clothOffset)*0.95f + clothOffset;
+
+ particlesCopy[i] = physx::PxVec4(clothMesh.mVertices[i], clothMesh.mInvMasses[i]); // w component is 1/mass, or 0.0f for anchored/fixed particles
+ }
+
+ if(index == 1)
+ {
+ mAttachmentVertices[0] = 0;
+ mAttachmentVertices[1] = 69;
+ mAttachmentVertexOriginalPositions[0] = particlesCopy[mAttachmentVertices[0]];
+ mAttachmentVertexOriginalPositions[1] = particlesCopy[mAttachmentVertices[1]];
+ }
+
+ // Create the cloth from the initial positions/masses and the fabric
+ mClothActor[index]->mCloth = getSceneController()->getFactory()->createCloth(nv::cloth::Range<physx::PxVec4>(&particlesCopy[0], &particlesCopy[0] + particlesCopy.size()), *mFabric[index]);
+ particlesCopy.clear(); particlesCopy.shrink_to_fit();
+
+ mClothActor[index]->mCloth->setGravity(physx::PxVec3(0.0f, -9.8f, 0.0f));
+
+ // Setup phase configs
+ std::vector<nv::cloth::PhaseConfig> phases(mFabric[index]->getNumPhases());
+ for (int i = 0; i < (int)phases.size(); i++)
+ {
+ phases[i].mPhaseIndex = i;
+ phases[i].mStiffness = 1.0f;
+ phases[i].mStiffnessMultiplier = 1.0f;
+ phases[i].mCompressionLimit = 1.0f;
+ phases[i].mStretchLimit = 1.0f;
+ }
+ mClothActor[index]->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
+ mClothActor[index]->mCloth->setDragCoefficient(0.1f);
+ mClothActor[index]->mCloth->setLiftCoefficient(0.2f);
+
+ mSolver[index] = getSceneController()->getFactory()->createSolver();
+ trackSolver(mSolver[index]);
+ trackClothActor(mClothActor[index]);
+
+ // Add the cloth to the solver for simulation
+ addClothToSolver(mClothActor[index], mSolver[index]);
+}
+
+void LocalGlobalScene::onInitialize()
+{
+ initializeCloth(1, physx::PxVec3(0.0f, 0.0f, 0.0f));
+ initializeCloth(0, physx::PxVec3(0.0f, 0.0f, 0.0f));
+
+ mTime = 0.0f;
+
+ {
+ IRenderMesh* mesh = getSceneController()->getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Plane);
+ Renderable* plane = getSceneController()->getRenderer().createRenderable(*mesh, *getSceneController()->getDefaultPlaneMaterial());
+ plane->setTransform(PxTransform(PxVec3(0.f, 0.f, 0.f), PxQuat(PxPiDivTwo, PxVec3(0.f, 0.f, 1.f))));
+ plane->setScale(PxVec3(1000.f));
+ trackRenderable(plane);
+ }
+}
diff --git a/NvCloth/samples/SampleBase/scene/scenes/LocalGlobalScene.h b/NvCloth/samples/SampleBase/scene/scenes/LocalGlobalScene.h
new file mode 100644
index 0000000..3b2bfa6
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/LocalGlobalScene.h
@@ -0,0 +1,40 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#ifndef LOCAL_GLOBAL_SCENE_H
+#define LOCAL_GLOBAL_SCENE_H
+
+#include "scene/Scene.h"
+#include <foundation/PxVec3.h>
+
+class LocalGlobalScene : public Scene
+{
+public:
+
+ LocalGlobalScene(SceneController* sceneController): Scene(sceneController) {}
+
+ virtual void Animate(double dt) override;
+ void initializeCloth(int index, physx::PxVec3 offset);
+ virtual void onInitialize() override;
+
+private:
+ nv::cloth::Fabric* mFabric[2];
+ nv::cloth::Solver* mSolver[2];
+ ClothActor* mClothActor[2];
+
+ int mAttachmentVertices[2];
+ physx::PxVec4 mAttachmentVertexOriginalPositions[2];
+
+ float mTime;
+
+};
+
+
+#endif \ No newline at end of file
diff --git a/NvCloth/samples/SampleBase/scene/scenes/MultiSolverScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/MultiSolverScene.cpp
new file mode 100644
index 0000000..d708069
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/MultiSolverScene.cpp
@@ -0,0 +1,131 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#include "MultiSolverScene.h"
+#include "Scene/SceneController.h"
+#include <NvClothExt/ClothFabricCooker.h>
+#include "ClothMeshGenerator.h"
+#include <NvCloth/Fabric.h>
+#include <NvCloth/Solver.h>
+#include <NvCloth/Cloth.h>
+#include <NvCloth/Factory.h>
+#include "Renderer.h"
+#include "renderer/RenderUtils.h"
+#include "windows.h"
+#include "utils/MeshGenerator.h"
+
+DECLARE_SCENE_NAME(MultiSolverScene, "Multi Solver Scene")
+
+
+void MultiSolverScene::initializeCloth(int index, physx::PxVec3 offset)
+{
+ mSolver[index] = getSceneController()->getFactory()->createSolver();
+ trackSolver(mSolver[index]);
+
+ ///////////////////////////////////////////////////////////////////////
+ ClothMeshData clothMesh;
+
+ physx::PxMat44 transform = PxTransform(PxVec3(0.f, 13.f, 0.f)+ offset, PxQuat(0, PxVec3(1.f, 0.f, 0.f)));
+ clothMesh.GeneratePlaneCloth(5.f, 6.f, 69, 79, false, transform);
+ clothMesh.AttachClothPlaneByAngles(69, 79);
+ clothMesh.SetInvMasses(0.5f + (float)index * 2.0f);
+
+ mClothActor[index] = new ClothActor;
+ nv::cloth::ClothMeshDesc meshDesc = clothMesh.GetClothMeshDesc();
+ {
+ mClothActor[index]->mClothRenderMesh = new ClothRenderMesh(meshDesc);
+ mClothActor[index]->mClothRenderable = getSceneController()->getRenderer().createRenderable(*(static_cast<IRenderMesh*>(mClothActor[index]->mClothRenderMesh)), *getSceneController()->getDefaultMaterial());
+
+ float r, g, b;
+ r = index == 0 ? 1.0f : 0.3f;
+ g = index == 1 ? 1.0f : 0.3f;
+ b = index == 2 ? 1.0f : 0.3f;
+
+ mClothActor[index]->mClothRenderable->setColor(DirectX::XMFLOAT4(r, g, b, 1.0f));
+ }
+
+ nv::cloth::Vector<int32_t>::Type phaseTypeInfo;
+ mFabric[index] = NvClothCookFabricFromMesh(getSceneController()->getFactory(), meshDesc, physx::PxVec3(0.0f, 0.0f, 1.0f), &phaseTypeInfo, false);
+ trackFabric(mFabric[index]);
+
+ // Initialize start positions and masses for the actual cloth instance
+ // (note: the particle/vertex positions do not have to match the mesh description here. Set the positions to the initial shape of this cloth instance)
+ std::vector<physx::PxVec4> particlesCopy;
+ particlesCopy.resize(clothMesh.mVertices.size());
+
+ physx::PxVec3 clothOffset = transform.getPosition();
+ for(int i = 0; i < (int)clothMesh.mVertices.size(); i++)
+ {
+ // To put attachment point closer to each other
+ if(clothMesh.mInvMasses[i] < 1e-6)
+ clothMesh.mVertices[i] = (clothMesh.mVertices[i] - clothOffset)*0.95f + clothOffset;
+
+ particlesCopy[i] = physx::PxVec4(clothMesh.mVertices[i], clothMesh.mInvMasses[i]); // w component is 1/mass, or 0.0f for anchored/fixed particles
+ }
+
+ // Create the cloth from the initial positions/masses and the fabric
+ mClothActor[index]->mCloth = getSceneController()->getFactory()->createCloth(nv::cloth::Range<physx::PxVec4>(&particlesCopy[0], &particlesCopy[0] + particlesCopy.size()), *mFabric[index]);
+ particlesCopy.clear(); particlesCopy.shrink_to_fit();
+
+ mClothActor[index]->mCloth->setGravity(physx::PxVec3(0.0f, -9.8f, 0.0f));
+ mClothActor[index]->mCloth->setDamping(physx::PxVec3(0.1f, 0.1f, 0.1f));
+ mClothActor[index]->mCloth->setFriction(0.5f);
+
+
+ physx::PxVec4 spheres[2] = {physx::PxVec4(physx::PxVec3(0.f, 11.f, -2.f) + offset,1.5),
+ physx::PxVec4(physx::PxVec3(0.f, 11.f, 2.f) + offset,1.0)};
+
+ mClothActor[index]->mCloth->setSpheres(nv::cloth::Range<physx::PxVec4>(spheres, spheres + 2), 0, mClothActor[index]->mCloth->getNumSpheres());
+
+ uint32_t caps[4];
+ caps[0] = 0;
+ caps[1] = 1;
+
+ mClothActor[index]->mCloth->setCapsules(nv::cloth::Range<uint32_t>(caps, caps + 2), 0, mClothActor[index]->mCloth->getNumCapsules());
+
+ //create render mesh
+ auto mesh = MeshGenerator::generateCollisionCapsules(spheres,2,caps,2,-0.05f);
+ auto renderMesh = new MeshGenerator::MeshGeneratorRenderMesh(mesh);
+ Renderable* renderable = getSceneController()->getRenderer().createRenderable(*renderMesh, *getSceneController()->getDefaultMaterial());
+ trackRenderable(renderable);
+
+ // Setup phase configs
+ std::vector<nv::cloth::PhaseConfig> phases(mFabric[index]->getNumPhases());
+ for(int i = 0; i < (int)phases.size(); i++)
+ {
+ phases[i].mPhaseIndex = i;
+ phases[i].mStiffness = 1.0f;
+ phases[i].mStiffnessMultiplier = 1.0f;
+ phases[i].mCompressionLimit = 1.0f;
+ phases[i].mStretchLimit = 1.0f;
+ }
+ mClothActor[index]->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
+ mClothActor[index]->mCloth->setDragCoefficient(0.5f);
+ mClothActor[index]->mCloth->setLiftCoefficient(0.6f);
+
+ trackClothActor(mClothActor[index]);
+
+ // Add the cloth to the solver for simulation
+ addClothToSolver(mClothActor[index], mSolver[index]);
+}
+
+void MultiSolverScene::onInitialize()
+{
+ initializeCloth(0, physx::PxVec3(-5.0f, 0.0f, 0.0f));
+ initializeCloth(0, physx::PxVec3(5.0f, 0.0f, 0.0f));
+
+ {
+ IRenderMesh* mesh = getSceneController()->getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Plane);
+ Renderable* plane = getSceneController()->getRenderer().createRenderable(*mesh, *getSceneController()->getDefaultPlaneMaterial());
+ plane->setTransform(PxTransform(PxVec3(0.f, 0.f, 0.f), PxQuat(PxPiDivTwo, PxVec3(0.f, 0.f, 1.f))));
+ plane->setScale(PxVec3(1000.f));
+ trackRenderable(plane);
+ }
+}
diff --git a/NvCloth/samples/SampleBase/scene/scenes/MultiSolverScene.h b/NvCloth/samples/SampleBase/scene/scenes/MultiSolverScene.h
new file mode 100644
index 0000000..f95c54e
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/MultiSolverScene.h
@@ -0,0 +1,33 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#ifndef MULTI_SOLVER_SCENE_H
+#define MULTI_SOLVER_SCENE_H
+
+#include "scene/Scene.h"
+#include <foundation/PxVec3.h>
+
+class MultiSolverScene : public Scene
+{
+public:
+
+ MultiSolverScene(SceneController* sceneController): Scene(sceneController) {}
+
+ void initializeCloth(int index, physx::PxVec3 offset);
+ virtual void onInitialize() override;
+
+private:
+ nv::cloth::Fabric* mFabric[1];
+ nv::cloth::Solver* mSolver[2];
+ ClothActor* mClothActor[1];
+};
+
+
+#endif \ No newline at end of file
diff --git a/NvCloth/samples/SampleBase/scene/scenes/PlaneCollisionScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/PlaneCollisionScene.cpp
new file mode 100644
index 0000000..fcf4060
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/PlaneCollisionScene.cpp
@@ -0,0 +1,135 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#include "PlaneCollisionScene.h"
+#include "Scene/SceneController.h"
+#include <NvClothExt/ClothFabricCooker.h>
+#include "ClothMeshGenerator.h"
+#include <NvCloth/Fabric.h>
+#include <NvCloth/Solver.h>
+#include <NvCloth/Cloth.h>
+#include <NvCloth/Factory.h>
+#include "Renderer.h"
+#include "renderer/RenderUtils.h"
+#include "windows.h"
+#include "utils/MeshGenerator.h"
+
+DECLARE_SCENE_NAME(PlaneCollisionScene, "Plane Collision Scene")
+
+
+void PlaneCollisionScene::initializeCloth(int index, physx::PxVec3 offset)
+{
+ ///////////////////////////////////////////////////////////////////////
+ ClothMeshData clothMesh;
+
+ physx::PxMat44 transform = PxTransform(PxVec3(0.f, 13.f, 0.f)+ offset, PxQuat(0, PxVec3(1.f, 0.f, 0.f)));
+ clothMesh.GeneratePlaneCloth(5.f, 6.f, 59, 69, false, transform);
+ clothMesh.AttachClothPlaneByAngles(59, 69);
+ clothMesh.SetInvMasses(0.5f + (float)index * 2.0f);
+
+ mClothActor[index] = new ClothActor;
+ nv::cloth::ClothMeshDesc meshDesc = clothMesh.GetClothMeshDesc();
+ {
+ mClothActor[index]->mClothRenderMesh = new ClothRenderMesh(meshDesc);
+ mClothActor[index]->mClothRenderable = getSceneController()->getRenderer().createRenderable(*(static_cast<IRenderMesh*>(mClothActor[index]->mClothRenderMesh)), *getSceneController()->getDefaultMaterial());
+
+ float r, g, b;
+ r = index == 0 ? 1.0f : 0.3f;
+ g = index == 1 ? 1.0f : 0.3f;
+ b = index == 2 ? 1.0f : 0.3f;
+
+ mClothActor[index]->mClothRenderable->setColor(DirectX::XMFLOAT4(r, g, b, 1.0f));
+ }
+
+ nv::cloth::Vector<int32_t>::Type phaseTypeInfo;
+ mFabric[index] = NvClothCookFabricFromMesh(getSceneController()->getFactory(), meshDesc, physx::PxVec3(0.0f, 0.0f, 1.0f), &phaseTypeInfo, false);
+ trackFabric(mFabric[index]);
+
+ // Initialize start positions and masses for the actual cloth instance
+ // (note: the particle/vertex positions do not have to match the mesh description here. Set the positions to the initial shape of this cloth instance)
+ std::vector<physx::PxVec4> particlesCopy;
+ particlesCopy.resize(clothMesh.mVertices.size());
+
+ physx::PxVec3 clothOffset = transform.getPosition();
+ for(int i = 0; i < (int)clothMesh.mVertices.size(); i++)
+ {
+ // To put attachment point closer to each other
+ if(clothMesh.mInvMasses[i] < 1e-6)
+ clothMesh.mVertices[i] = (clothMesh.mVertices[i] - clothOffset)*0.95f + clothOffset;
+
+ particlesCopy[i] = physx::PxVec4(clothMesh.mVertices[i], clothMesh.mInvMasses[i]); // w component is 1/mass, or 0.0f for anchored/fixed particles
+ }
+
+ // Create the cloth from the initial positions/masses and the fabric
+ mClothActor[index]->mCloth = getSceneController()->getFactory()->createCloth(nv::cloth::Range<physx::PxVec4>(&particlesCopy[0], &particlesCopy[0] + particlesCopy.size()), *mFabric[index]);
+ particlesCopy.clear(); particlesCopy.shrink_to_fit();
+
+ mClothActor[index]->mCloth->setGravity(physx::PxVec3(0.0f, -9.8f, 0.0f));
+ mClothActor[index]->mCloth->setDamping(physx::PxVec3(0.1f, 0.1f, 0.1f));
+
+ //Generate collision planes
+ std::vector<physx::PxVec4> planes;
+ planes.push_back(physx::PxVec4(physx::PxVec3(-0.5f, 0.4f, 0.0f).getNormalized(), -4.0f));
+ planes.push_back(physx::PxVec4(physx::PxVec3(0.0f, 0.4f, 0.5f).getNormalized(), -4.0f));
+ uint32_t mask = 3;
+ MeshGenerator::Mesh mesh = MeshGenerator::generateCollisionConvex(planes.data(), mask, -0.01f, true);
+
+ //assign as collision data
+ nv::cloth::Range<const physx::PxVec4> planesR(&planes[0], &planes[0] + planes.size());
+ mClothActor[index]->mCloth->setPlanes(planesR, 0, mClothActor[index]->mCloth->getNumPlanes());
+
+ //assign convex indices
+ std::vector<uint32_t> indices;
+ indices.push_back(1);
+ indices.push_back(2);
+ nv::cloth::Range<uint32_t> cind(&indices[0], &indices[0] + indices.size());
+ mClothActor[index]->mCloth->setConvexes(cind, 0, mClothActor[index]->mCloth->getNumConvexes());
+
+ //create render mesh
+ //scale down the render model to not intersect the triangles so much
+ auto renderMesh = new MeshGenerator::MeshGeneratorRenderMesh(mesh);
+ Renderable* renderable = getSceneController()->getRenderer().createRenderable(*renderMesh, *getSceneController()->getDefaultMaterial());
+ trackRenderable(renderable);
+
+ // Setup phase configs
+ std::vector<nv::cloth::PhaseConfig> phases(mFabric[index]->getNumPhases());
+ for(int i = 0; i < (int)phases.size(); i++)
+ {
+ phases[i].mPhaseIndex = i;
+ phases[i].mStiffness = 1.0f;
+ phases[i].mStiffnessMultiplier = 1.0f;
+ phases[i].mCompressionLimit = 1.0f;
+ phases[i].mStretchLimit = 1.0f;
+ }
+ mClothActor[index]->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
+ mClothActor[index]->mCloth->setDragCoefficient(0.1f);
+ mClothActor[index]->mCloth->setLiftCoefficient(0.1f);
+
+ trackClothActor(mClothActor[index]);
+
+ // Add the cloth to the solver for simulation
+ addClothToSolver(mClothActor[index], mSolver);
+}
+
+void PlaneCollisionScene::onInitialize()
+{
+ mSolver = getSceneController()->getFactory()->createSolver();
+ trackSolver(mSolver);
+
+ initializeCloth(0, physx::PxVec3(0.0f, 0.0f, 0.0f));
+
+ {
+ IRenderMesh* mesh = getSceneController()->getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Plane);
+ Renderable* plane = getSceneController()->getRenderer().createRenderable(*mesh, *getSceneController()->getDefaultPlaneMaterial());
+ plane->setTransform(PxTransform(PxVec3(0.f, 0.f, 0.f), PxQuat(PxPiDivTwo, PxVec3(0.f, 0.f, 1.f))));
+ plane->setScale(PxVec3(1000.f));
+ trackRenderable(plane);
+ }
+}
diff --git a/NvCloth/samples/SampleBase/scene/scenes/PlaneCollisionScene.h b/NvCloth/samples/SampleBase/scene/scenes/PlaneCollisionScene.h
new file mode 100644
index 0000000..32ff35b
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/PlaneCollisionScene.h
@@ -0,0 +1,33 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#ifndef PLANE_COLLISION_SCENE_H
+#define PLANE_COLLISION_SCENE_H
+
+#include "scene/Scene.h"
+#include <foundation/PxVec3.h>
+
+class PlaneCollisionScene : public Scene
+{
+public:
+
+ PlaneCollisionScene(SceneController* sceneController): Scene(sceneController) {}
+
+ void initializeCloth(int index, physx::PxVec3 offset);
+ virtual void onInitialize() override;
+
+private:
+ nv::cloth::Fabric* mFabric[1];
+ nv::cloth::Solver* mSolver;
+ ClothActor* mClothActor[1];
+};
+
+
+#endif \ No newline at end of file
diff --git a/NvCloth/samples/SampleBase/scene/scenes/SelfCollisionScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/SelfCollisionScene.cpp
new file mode 100644
index 0000000..6a407ea
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/SelfCollisionScene.cpp
@@ -0,0 +1,155 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#include "SelfCollisionScene.h"
+#include "Scene/SceneController.h"
+#include <NvClothExt/ClothFabricCooker.h>
+#include "ClothMeshGenerator.h"
+#include <NvCloth/Fabric.h>
+#include <NvCloth/Solver.h>
+#include <NvCloth/Cloth.h>
+#include <NvCloth/Factory.h>
+#include "Renderer.h"
+#include "renderer/RenderUtils.h"
+
+DECLARE_SCENE_NAME(SelfCollisionScene, "Self Collision Scene")
+
+void SelfCollisionScene::initializeCloth(int index, physx::PxMat44 transform)
+{
+ ///////////////////////////////////////////////////////////////////////
+
+ float w = 5.f - index;
+ float h = 6.f + index;
+ transform *= PxTransform(PxVec3(0.f, 13.f, 0.f), PxQuat(0, PxVec3(1.f, 0.f, 0.f)));
+ ClothMeshData clothMesh;
+ clothMesh.GeneratePlaneCloth(w, h, 5 * w, 5 * h, false, transform);
+ clothMesh.AttachClothPlaneByAngles(5 * w, 5 * h);
+ clothMesh.SetInvMasses(1.0f / (1000.0f / (5.0f*w*5.0f*h)));
+
+ float w2 = w - 1.0f;
+ float h2 = h + 1.0f;
+ transform *= PxTransform(PxVec3(0.f, 0.8f, -0.2f), PxQuat(0, PxVec3(1.f, 0.f, 0.f)));
+ ClothMeshData clothMesh2;
+ clothMesh2.GeneratePlaneCloth(w2, h2, 5 * w2, 5 * h2, false, transform);
+ clothMesh2.AttachClothPlaneByAngles(5 * w2, 5 * h2);
+ clothMesh2.SetInvMasses(1.0f / (1000.0f / (5.0f*w2*5.0f*h2)));
+ int FirstParticleIndexCloth2 = (int)clothMesh.mVertices.size();
+ clothMesh.Merge(clothMesh2);
+
+ mClothActor[index] = new ClothActor;
+ nv::cloth::ClothMeshDesc meshDesc = clothMesh.GetClothMeshDesc();
+ {
+ mClothActor[index]->mClothRenderMesh = new ClothRenderMesh(meshDesc);
+ mClothActor[index]->mClothRenderable = getSceneController()->getRenderer().createRenderable(*(static_cast<IRenderMesh*>(mClothActor[index]->mClothRenderMesh)), *getSceneController()->getDefaultMaterial());
+ mClothActor[index]->mClothRenderable->setColor(getRandomPastelColor());
+ }
+
+ nv::cloth::Vector<int32_t>::Type phaseTypeInfo;
+ mFabric[index] = NvClothCookFabricFromMesh(getSceneController()->getFactory(), meshDesc, physx::PxVec3(0.0f, 0.0f, 1.0f), &phaseTypeInfo, false);
+ trackFabric(mFabric[index]);
+
+ // Initialize start positions and masses for the actual cloth instance
+ // (note: the particle/vertex positions do not have to match the mesh description here. Set the positions to the initial shape of this cloth instance)
+ std::vector<physx::PxVec4> particlesCopy;
+ particlesCopy.resize(clothMesh.mVertices.size());
+
+ physx::PxVec3 clothOffset = transform.getPosition();
+ for(int i = 0; i < (int)clothMesh.mVertices.size(); i++)
+ {
+ // To put attachment point closer to each other
+ if(clothMesh.mInvMasses[i] < 1e-6)
+ clothMesh.mVertices[i] = (clothMesh.mVertices[i] - clothOffset)*0.9f + clothOffset;
+
+ particlesCopy[i] = physx::PxVec4(clothMesh.mVertices[i], clothMesh.mInvMasses[i]); // w component is 1/mass, or 0.0f for anchored/fixed particles
+ }
+
+ // Create the cloth from the initial positions/masses and the fabric
+ mClothActor[index]->mCloth = getSceneController()->getFactory()->createCloth(nv::cloth::Range<physx::PxVec4>(&particlesCopy[0], &particlesCopy[0] + particlesCopy.size()), *mFabric[index]);
+ particlesCopy.clear(); particlesCopy.shrink_to_fit();
+
+ std::vector<physx::PxVec4> planes;
+ planes.push_back(physx::PxVec4(physx::PxVec3(0.0f, 1.f, 0.0f), -0.01f));
+
+ nv::cloth::Range<const physx::PxVec4> planesR(&planes[0], &planes[0] + planes.size());
+ mClothActor[index]->mCloth->setPlanes(planesR, 0, mClothActor[index]->mCloth->getNumPlanes());
+ std::vector<uint32_t> indices;
+ indices.resize(planes.size());
+ for(int i = 0; i < (int)indices.size(); i++)
+ indices[i] = 1 << i;
+ nv::cloth::Range<uint32_t> cind(&indices[0], &indices[0] + indices.size());
+ mClothActor[index]->mCloth->setConvexes(cind, 0, mClothActor[index]->mCloth->getNumConvexes());
+
+ mClothActor[index]->mCloth->setGravity(physx::PxVec3(0.0f, -1.0f, 0.0f));
+ mClothActor[index]->mCloth->setFriction(0.1);
+ mClothActor[index]->mCloth->setDragCoefficient(0.1f);
+ mClothActor[index]->mCloth->setLiftCoefficient(0.1f);
+ mClothActor[index]->mCloth->setSolverFrequency(120.0f);
+ mClothActor[index]->mCloth->setSelfCollisionDistance(0.26);
+ mClothActor[index]->mCloth->setSelfCollisionStiffness(0.95);
+
+ std::vector<uint32_t> selfCollisionIndices;
+
+ //only enable every other particle for self collision
+ for(int y = 0; y < 5*h + 1; y++)
+ for(int x = 0; x < 5 * w + 1; x++)
+ if((x & 1) ^ (y & 1)) selfCollisionIndices.push_back(x + y*(5 * w + 1));
+
+ for(int y = 0; y < 5 * h2 + 1; y++)
+ for(int x = 0; x < 5 * w2 + 1; x++)
+ if((x & 1) ^ (y & 1)) selfCollisionIndices.push_back(FirstParticleIndexCloth2 + x + y*(5 * w2 + 1));
+
+ nv::cloth::Range<uint32_t> selfCollisionIndicesRange (&selfCollisionIndices[0], &selfCollisionIndices[0] + selfCollisionIndices.size());
+ mClothActor[index]->mCloth->setSelfCollisionIndices(selfCollisionIndicesRange);
+
+ // Setup phase configs
+ std::vector<nv::cloth::PhaseConfig> phases(mFabric[index]->getNumPhases());
+ for(int i = 0; i < (int)phases.size(); i++)
+ {
+ phases[i].mPhaseIndex = i;
+ phases[i].mStiffness = 1.0f;
+ phases[i].mStiffnessMultiplier = 1.0f;
+ phases[i].mCompressionLimit = 1.0f;
+ phases[i].mStretchLimit = 1.0f;
+ }
+ mClothActor[index]->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
+
+ trackClothActor(mClothActor[index]);
+
+ // Add the cloth to the solver for simulation
+ addClothToSolver(mClothActor[index], mSolver);
+}
+
+void SelfCollisionScene::onInitialize()
+{
+ mSolver = getSceneController()->getFactory()->createSolver();
+ /*mSolver->setInterCollisionNbIterations(8);
+ mSolver->setInterCollisionDistance(0.4f);
+ mSolver->setInterCollisionStiffness(0.95f);
+ mSolver->setInterCollisionFilter(
+ [](void* a, void* b) {
+ return true;
+ }
+ );*/
+ trackSolver(mSolver);
+
+ physx::PxMat44 posTrans(physx::PxIdentity);
+ posTrans.setPosition(physx::PxVec3(0.0f, 0.f, -1.0f));
+ initializeCloth(0, posTrans);
+ //posTrans.setPosition(physx::PxVec3(0.0f, 0.8f, -1.2f));
+ //initializeCloth(1, posTrans);
+
+ {
+ IRenderMesh* mesh = getSceneController()->getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Plane);
+ Renderable* plane = getSceneController()->getRenderer().createRenderable(*mesh, *getSceneController()->getDefaultPlaneMaterial());
+ plane->setTransform(PxTransform(PxVec3(0.f, 0.f, 0.f), PxQuat(PxPiDivTwo, PxVec3(0.f, 0.f, 1.f))));
+ plane->setScale(PxVec3(1000.f));
+ trackRenderable(plane);
+ }
+}
diff --git a/NvCloth/samples/SampleBase/scene/scenes/SelfCollisionScene.h b/NvCloth/samples/SampleBase/scene/scenes/SelfCollisionScene.h
new file mode 100644
index 0000000..0fcdeac
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/SelfCollisionScene.h
@@ -0,0 +1,33 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#ifndef SELF_COLLISION_SCENE_H
+#define SELF_COLLISION_SCENE_H
+
+#include "scene/Scene.h"
+#include <foundation/PxVec3.h>
+
+class SelfCollisionScene : public Scene
+{
+public:
+
+ SelfCollisionScene(SceneController* sceneController): Scene(sceneController) {}
+
+ void initializeCloth(int index, physx::PxMat44 transform);
+ virtual void onInitialize() override;
+
+private:
+ nv::cloth::Fabric* mFabric[2];
+ nv::cloth::Solver* mSolver;
+ ClothActor* mClothActor[2];
+};
+
+
+#endif \ No newline at end of file
diff --git a/NvCloth/samples/SampleBase/scene/scenes/SimpleScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/SimpleScene.cpp
index 68bb96b..b52e2c6 100644
--- a/NvCloth/samples/SampleBase/scene/scenes/SimpleScene.cpp
+++ b/NvCloth/samples/SampleBase/scene/scenes/SimpleScene.cpp
@@ -26,9 +26,9 @@ void SimpleScene::onInitialize()
///////////////////////////////////////////////////////////////////////
ClothMeshData clothMesh;
- physx::PxMat44 transform = PxTransform(PxVec3(0.f, 13.f, 0.f), PxQuat(PxPi / 6.f, PxVec3(1.f, 0.f, 0.f)));
- clothMesh.GeneratePlaneCloth(6.f, 7.f, 59, 69, false, transform);
- clothMesh.AttachClothPlaneByAngles(59, 69);
+ physx::PxMat44 transform = PxTransform(PxVec3(-2.f, 13.f, 0.f), PxQuat(PxPi / 6.f, PxVec3(1.f, 0.f, 0.f)));
+ clothMesh.GeneratePlaneCloth(6.f, 7.f, 49, 59, false, transform);
+ clothMesh.AttachClothPlaneByAngles(49, 59);
mClothActor = new ClothActor;
nv::cloth::ClothMeshDesc meshDesc = clothMesh.GetClothMeshDesc();
@@ -48,11 +48,11 @@ void SimpleScene::onInitialize()
particlesCopy.resize(clothMesh.mVertices.size());
physx::PxVec3 center = transform.transform(physx::PxVec3(0.0f, 0.0f, 0.0f));
- for(int i = 0; i < (int)clothMesh.mVertices.size(); i++)
+ for (int i = 0; i < (int)clothMesh.mVertices.size(); i++)
{
// To put attachment point closer to each other
if(clothMesh.mInvMasses[i] < 1e-6)
- clothMesh.mVertices[i] = (clothMesh.mVertices[i] - center)*0.85f + center;
+ clothMesh.mVertices[i] = (clothMesh.mVertices[i] - center) * 0.85f + center;
particlesCopy[i] = physx::PxVec4(clothMesh.mVertices[i], clothMesh.mInvMasses[i]); // w component is 1/mass, or 0.0f for anchored/fixed particles
}
@@ -65,7 +65,7 @@ void SimpleScene::onInitialize()
// Setup phase configs
std::vector<nv::cloth::PhaseConfig> phases(mFabric->getNumPhases());
- for(int i = 0; i < (int)phases.size(); i++)
+ for (int i = 0; i < (int)phases.size(); i++)
{
phases[i].mPhaseIndex = i;
phases[i].mStiffness = 1.0f;
@@ -74,8 +74,8 @@ void SimpleScene::onInitialize()
phases[i].mStretchLimit = 1.0f;
}
mClothActor->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
- mClothActor->mCloth->setDragCoefficient(0.5f);
- mClothActor->mCloth->setDragCoefficient(0.5f);
+ mClothActor->mCloth->setDragCoefficient(0.1f);
+ mClothActor->mCloth->setDragCoefficient(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
new file mode 100644
index 0000000..d963011
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/SphereScene.cpp
@@ -0,0 +1,121 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#include "SphereScene.h"
+#include "Scene/SceneController.h"
+#include <NvClothExt/ClothFabricCooker.h>
+#include "ClothMeshGenerator.h"
+#include <NvCloth/Fabric.h>
+#include <NvCloth/Solver.h>
+#include <NvCloth/Cloth.h>
+#include <NvCloth/Factory.h>
+#include "Renderer.h"
+#include "renderer/RenderUtils.h"
+#include "windows.h"
+
+DECLARE_SCENE_NAME(SphereScene, "Sphere Scene")
+
+
+void SphereScene::initializeCloth(int index, physx::PxVec3 offset)
+{
+ ///////////////////////////////////////////////////////////////////////
+ ClothMeshData clothMesh;
+
+ physx::PxMat44 transform = PxTransform(PxVec3(0.f, 13.f, 0.f)+ offset, PxQuat(0, PxVec3(1.f, 0.f, 0.f)));
+ clothMesh.GeneratePlaneCloth(5.f, 6.f, 69, 79, false, transform);
+ clothMesh.AttachClothPlaneByAngles(69, 79);
+ clothMesh.SetInvMasses(0.5f + (float)index * 2.0f);
+
+ mClothActor[index] = new ClothActor;
+ nv::cloth::ClothMeshDesc meshDesc = clothMesh.GetClothMeshDesc();
+ {
+ mClothActor[index]->mClothRenderMesh = new ClothRenderMesh(meshDesc);
+ mClothActor[index]->mClothRenderable = getSceneController()->getRenderer().createRenderable(*(static_cast<IRenderMesh*>(mClothActor[index]->mClothRenderMesh)), *getSceneController()->getDefaultMaterial());
+
+ float r, g, b;
+ r = index == 0 ? 1.0f : 0.3f;
+ g = index == 1 ? 1.0f : 0.3f;
+ b = index == 2 ? 1.0f : 0.3f;
+
+ mClothActor[index]->mClothRenderable->setColor(DirectX::XMFLOAT4(r, g, b, 1.0f));
+ }
+
+ nv::cloth::Vector<int32_t>::Type phaseTypeInfo;
+ mFabric[index] = NvClothCookFabricFromMesh(getSceneController()->getFactory(), meshDesc, physx::PxVec3(0.0f, 0.0f, 1.0f), &phaseTypeInfo, false);
+ trackFabric(mFabric[index]);
+
+ // Initialize start positions and masses for the actual cloth instance
+ // (note: the particle/vertex positions do not have to match the mesh description here. Set the positions to the initial shape of this cloth instance)
+ std::vector<physx::PxVec4> particlesCopy;
+ particlesCopy.resize(clothMesh.mVertices.size());
+
+ physx::PxVec3 clothOffset = transform.getPosition();
+ for(int i = 0; i < (int)clothMesh.mVertices.size(); i++)
+ {
+ // To put attachment point closer to each other
+ if(clothMesh.mInvMasses[i] < 1e-6)
+ clothMesh.mVertices[i] = (clothMesh.mVertices[i] - clothOffset)*0.95f + clothOffset;
+
+ particlesCopy[i] = physx::PxVec4(clothMesh.mVertices[i], clothMesh.mInvMasses[i]); // w component is 1/mass, or 0.0f for anchored/fixed particles
+ }
+
+ // Create the cloth from the initial positions/masses and the fabric
+ mClothActor[index]->mCloth = getSceneController()->getFactory()->createCloth(nv::cloth::Range<physx::PxVec4>(&particlesCopy[0], &particlesCopy[0] + particlesCopy.size()), *mFabric[index]);
+ particlesCopy.clear(); particlesCopy.shrink_to_fit();
+
+ mClothActor[index]->mCloth->setGravity(physx::PxVec3(0.0f, -9.8f, 0.0f));
+ mClothActor[index]->mCloth->setDamping(physx::PxVec3(0.1f, 0.1f, 0.1f));
+
+
+ {
+ IRenderMesh* mesh = getSceneController()->getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Sphere);
+ Renderable* sphere = getSceneController()->getRenderer().createRenderable(*mesh, *getSceneController()->getDefaultMaterial());
+ sphere->setTransform(PxTransform(PxVec3(0.f, 10.f, -1.f) + offset, PxQuat(PxPiDivTwo, PxVec3(0.f, 0.f, 1.f))));
+ sphere->setScale(PxVec3(1.5f));
+ trackRenderable(sphere);
+ }
+
+ physx::PxVec4 spheres[1] = {physx::PxVec4(physx::PxVec3(0.f, 10.f, -1.f) + offset,1.5)};
+
+ mClothActor[index]->mCloth->setSpheres(nv::cloth::Range<physx::PxVec4>(spheres, spheres + 1), 0, mClothActor[index]->mCloth->getNumSpheres());
+
+ // Setup phase configs
+ std::vector<nv::cloth::PhaseConfig> phases(mFabric[index]->getNumPhases());
+ for(int i = 0; i < (int)phases.size(); i++)
+ {
+ phases[i].mPhaseIndex = i;
+ phases[i].mStiffness = 1.0f;
+ phases[i].mStiffnessMultiplier = 1.0f;
+ phases[i].mCompressionLimit = 1.0f;
+ phases[i].mStretchLimit = 1.0f;
+ }
+ mClothActor[index]->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
+
+ trackClothActor(mClothActor[index]);
+
+ // Add the cloth to the solver for simulation
+ addClothToSolver(mClothActor[index], mSolver);
+}
+
+void SphereScene::onInitialize()
+{
+ mSolver = getSceneController()->getFactory()->createSolver();
+ trackSolver(mSolver);
+
+ initializeCloth(0, physx::PxVec3(0.0f, 0.0f, 0.0f));
+
+ {
+ IRenderMesh* mesh = getSceneController()->getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Plane);
+ Renderable* plane = getSceneController()->getRenderer().createRenderable(*mesh, *getSceneController()->getDefaultPlaneMaterial());
+ plane->setTransform(PxTransform(PxVec3(0.f, 0.f, 0.f), PxQuat(PxPiDivTwo, PxVec3(0.f, 0.f, 1.f))));
+ plane->setScale(PxVec3(1000.f));
+ trackRenderable(plane);
+ }
+}
diff --git a/NvCloth/samples/SampleBase/scene/scenes/SphereScene.h b/NvCloth/samples/SampleBase/scene/scenes/SphereScene.h
new file mode 100644
index 0000000..60d7753
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/SphereScene.h
@@ -0,0 +1,33 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#ifndef SPHERE_SCENE_H
+#define SPHERE_SCENE_H
+
+#include "scene/Scene.h"
+#include <foundation/PxVec3.h>
+
+class SphereScene : public Scene
+{
+public:
+
+ SphereScene(SceneController* sceneController): Scene(sceneController) {}
+
+ void initializeCloth(int index, physx::PxVec3 offset);
+ virtual void onInitialize() override;
+
+private:
+ nv::cloth::Fabric* mFabric[1];
+ nv::cloth::Solver* mSolver;
+ ClothActor* mClothActor[1];
+};
+
+
+#endif \ No newline at end of file
diff --git a/NvCloth/samples/SampleBase/scene/scenes/StiffnessPerConstraintScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/StiffnessPerConstraintScene.cpp
new file mode 100644
index 0000000..4ed9daf
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/StiffnessPerConstraintScene.cpp
@@ -0,0 +1,122 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#include "StiffnessPerConstraintScene.h"
+#include "Scene/SceneController.h"
+#include <NvClothExt/ClothFabricCooker.h>
+#include "ClothMeshGenerator.h"
+#include <NvCloth/Fabric.h>
+#include <NvCloth/Solver.h>
+#include <NvCloth/Cloth.h>
+#include <NvCloth/Factory.h>
+#include "Renderer.h"
+#include "renderer/RenderUtils.h"
+#include "windows.h"
+
+DECLARE_SCENE_NAME(StiffnessPerConstraintScene, "Stiffness per constraint scene")
+
+void StiffnessPerConstraintScene::initializeCloth(int index, physx::PxVec3 offset)
+{
+ ///////////////////////////////////////////////////////////////////////
+ ClothMeshData clothMesh;
+
+ physx::PxMat44 transform = PxTransform(PxVec3(0.f, 13.f, 0.f)+ offset, PxQuat(0, PxVec3(1.f, 0.f, 0.f)));
+ clothMesh.GeneratePlaneCloth(5.f, 6.25f, 39, 49, false, transform);
+ clothMesh.AttachClothPlaneByAngles(39, 39);
+ clothMesh.SetInvMasses(0.5f + (float)index * 2.0f);
+
+ mClothActor[index] = new ClothActor;
+ nv::cloth::ClothMeshDesc meshDesc = clothMesh.GetClothMeshDesc();
+ {
+ meshDesc.pointsStiffness.stride = sizeof(float);
+ meshDesc.pointsStiffness.count = meshDesc.points.count;
+ float* stiffnessValues = new float[meshDesc.pointsStiffness.count];
+ meshDesc.pointsStiffness.data = stiffnessValues;
+ for(int y = 0; y<50; y++)
+ for(int x = 0; x<40; x++)
+ {
+ stiffnessValues[x + y * 40] = ((y) % 8)<5 ? 1.0f : 0.1f;
+ }
+
+ mClothActor[index]->mClothRenderMesh = new ClothRenderMesh(meshDesc);
+ mClothActor[index]->mClothRenderable = getSceneController()->getRenderer().createRenderable(*(static_cast<IRenderMesh*>(mClothActor[index]->mClothRenderMesh)), *getSceneController()->getDefaultMaterial());
+
+ float r, g, b;
+ r = index == 0 ? 1.0f : 0.3f;
+ g = index == 1 ? 1.0f : 0.3f;
+ b = index == 2 ? 1.0f : 0.3f;
+
+ mClothActor[index]->mClothRenderable->setColor(DirectX::XMFLOAT4(r, g, b, 1.0f));
+ }
+
+ nv::cloth::Vector<int32_t>::Type phaseTypeInfo;
+ mFabric[index] = NvClothCookFabricFromMesh(getSceneController()->getFactory(), meshDesc, physx::PxVec3(0.0f, 0.0f, 1.0f), &phaseTypeInfo, false);
+ trackFabric(mFabric[index]);
+
+ // Initialize start positions and masses for the actual cloth instance
+ // (note: the particle/vertex positions do not have to match the mesh description here. Set the positions to the initial shape of this cloth instance)
+ std::vector<physx::PxVec4> particlesCopy;
+ particlesCopy.resize(clothMesh.mVertices.size());
+
+ physx::PxVec3 clothOffset = transform.getPosition();
+ for(int i = 0; i < (int)clothMesh.mVertices.size(); i++)
+ {
+ // To put attachment point closer to each other
+ if(clothMesh.mInvMasses[i] < 1e-6)
+ clothMesh.mVertices[i] = (clothMesh.mVertices[i] - clothOffset)*0.95f + clothOffset;
+
+ particlesCopy[i] = physx::PxVec4(clothMesh.mVertices[i], clothMesh.mInvMasses[i]); // w component is 1/mass, or 0.0f for anchored/fixed particles
+ }
+
+ // Create the cloth from the initial positions/masses and the fabric
+ mClothActor[index]->mCloth = getSceneController()->getFactory()->createCloth(nv::cloth::Range<physx::PxVec4>(&particlesCopy[0], &particlesCopy[0] + particlesCopy.size()), *mFabric[index]);
+ particlesCopy.clear(); particlesCopy.shrink_to_fit();
+
+ mClothActor[index]->mCloth->setGravity(physx::PxVec3(0.0f, -9.8f, 0.0f));
+ mClothActor[index]->mCloth->setTetherConstraintStiffness(0.1);
+ mClothActor[index]->mCloth->setTetherConstraintScale(1.5f);
+ mClothActor[index]->mCloth->setDragCoefficient(0.1);
+ mClothActor[index]->mCloth->setSolverFrequency(120.0f);
+ mClothActor[index]->mCloth->setDamping(physx::PxVec3(0.1f, 0.1f, 0.1f));
+
+ // Setup phase configs
+ std::vector<nv::cloth::PhaseConfig> phases(mFabric[index]->getNumPhases());
+ for(int i = 0; i < (int)phases.size(); i++)
+ {
+ phases[i].mPhaseIndex = i;
+ phases[i].mStiffness = 1.0f;
+ phases[i].mStiffnessMultiplier = 1.0f;
+ phases[i].mCompressionLimit = 1.0f;
+ phases[i].mStretchLimit = 1.0f;
+ }
+ mClothActor[index]->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
+ mClothActor[index]->mCloth->setDragCoefficient(0.1f);
+ mClothActor[index]->mCloth->setLiftCoefficient(0.1f);
+
+ trackClothActor(mClothActor[index]);
+
+ // Add the cloth to the solver for simulation
+ addClothToSolver(mClothActor[index], mSolver);
+}
+
+void StiffnessPerConstraintScene::onInitialize()
+{
+ mSolver = getSceneController()->getFactory()->createSolver();
+ trackSolver(mSolver);
+ initializeCloth(0, physx::PxVec3(0.0f, 0.0f, 0.0f));
+
+ {
+ IRenderMesh* mesh = getSceneController()->getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Plane);
+ Renderable* plane = getSceneController()->getRenderer().createRenderable(*mesh, *getSceneController()->getDefaultPlaneMaterial());
+ plane->setTransform(PxTransform(PxVec3(0.f, 0.f, 0.f), PxQuat(PxPiDivTwo, PxVec3(0.f, 0.f, 1.f))));
+ plane->setScale(PxVec3(1000.f));
+ trackRenderable(plane);
+ }
+}
diff --git a/NvCloth/samples/SampleBase/scene/scenes/StiffnessPerConstraintScene.h b/NvCloth/samples/SampleBase/scene/scenes/StiffnessPerConstraintScene.h
new file mode 100644
index 0000000..bd56a13
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/StiffnessPerConstraintScene.h
@@ -0,0 +1,33 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#ifndef STIFFNESS_PER_CONSTRAINT_SCENE_H
+#define STIFFNESS_PER_CONSTRAINT_SCENE_H
+
+#include "scene/Scene.h"
+#include <foundation/PxVec3.h>
+
+class StiffnessPerConstraintScene : public Scene
+{
+public:
+
+ StiffnessPerConstraintScene(SceneController* sceneController): Scene(sceneController) {}
+
+ void initializeCloth(int index, physx::PxVec3 offset);
+ virtual void onInitialize() override;
+
+private:
+ nv::cloth::Fabric* mFabric[1];
+ nv::cloth::Solver* mSolver;
+ ClothActor* mClothActor[1];
+};
+
+
+#endif \ No newline at end of file
diff --git a/NvCloth/samples/SampleBase/scene/scenes/TetherScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/TetherScene.cpp
index b818d9d..ecd0850 100644
--- a/NvCloth/samples/SampleBase/scene/scenes/TetherScene.cpp
+++ b/NvCloth/samples/SampleBase/scene/scenes/TetherScene.cpp
@@ -23,12 +23,11 @@ DECLARE_SCENE_NAME(TetherScene, "Tether Scene")
void TetherScene::initializeCloth(int index, physx::PxVec3 offset, float tetherStiffness)
{
- ///////////////////////////////////////////////////////////////////////
ClothMeshData clothMesh;
- physx::PxMat44 transform = PxTransform(PxVec3(0.f, 13.f, 0.f)+ offset, PxQuat(PxPi / 6.f, PxVec3(1.f, 0.f, 0.f)));
- clothMesh.GeneratePlaneCloth(6.f, 7.5f, 39, 59, false, transform);
- clothMesh.AttachClothPlaneByAngles(39, 59);
+ physx::PxMat44 transform = PxTransform(PxVec3(0.f, 13.f, 0.f) + offset, PxQuat(PxPi / 6.f, PxVec3(1.f, 0.f, 0.f)));
+ clothMesh.GeneratePlaneCloth(6.f, 7.f, 49, 59, false, transform);
+ clothMesh.AttachClothPlaneByAngles(49, 59);
mClothActor[index] = new ClothActor;
nv::cloth::ClothMeshDesc meshDesc = clothMesh.GetClothMeshDesc();
@@ -48,13 +47,13 @@ void TetherScene::initializeCloth(int index, physx::PxVec3 offset, float tetherS
particlesCopy.resize(clothMesh.mVertices.size());
physx::PxVec3 clothOffset = transform.getPosition();
- for(int i = 0; i < (int)clothMesh.mVertices.size(); i++)
+ for (int i = 0; i < (int)clothMesh.mVertices.size(); i++)
{
// To put attachment point closer to each other
if(clothMesh.mInvMasses[i] < 1e-6)
- clothMesh.mVertices[i] = (clothMesh.mVertices[i] - clothOffset)*0.8f + clothOffset;
+ clothMesh.mVertices[i] = (clothMesh.mVertices[i] - clothOffset) * 0.8f + clothOffset;
- particlesCopy[i] = physx::PxVec4(clothMesh.mVertices[i], clothMesh.mInvMasses[i]); // w component is 1/mass, or 0.0f for anchored/fixed particles
+ particlesCopy[i] = physx::PxVec4(clothMesh.mVertices[i], 0.5f * clothMesh.mInvMasses[i]); // w component is 1/mass, or 0.0f for anchored/fixed particles
}
// Create the cloth from the initial positions/masses and the fabric
@@ -66,19 +65,16 @@ void TetherScene::initializeCloth(int index, physx::PxVec3 offset, float tetherS
// Setup phase configs
std::vector<nv::cloth::PhaseConfig> phases(mFabric[index]->getNumPhases());
- for(int i = 0; i < (int)phases.size(); i++)
+ for (int i = 0; i < (int)phases.size(); i++)
{
phases[i].mPhaseIndex = i;
- phases[i].mStiffness = 1.0f;
+ phases[i].mStiffness = 0.75f;
phases[i].mStiffnessMultiplier = 1.0f;
phases[i].mCompressionLimit = 1.0f;
phases[i].mStretchLimit = 1.0f;
}
mClothActor[index]->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
-
- mSolver = getSceneController()->getFactory()->createSolver();
- trackSolver(mSolver);
trackClothActor(mClothActor[index]);
// Add the cloth to the solver for simulation
@@ -87,9 +83,11 @@ void TetherScene::initializeCloth(int index, physx::PxVec3 offset, float tetherS
void TetherScene::onInitialize()
{
+ mSolver = getSceneController()->getFactory()->createSolver();
+ trackSolver(mSolver);
- initializeCloth(0,physx::PxVec3(-5.0f,0.0f,0.0f),0);
- initializeCloth(1, physx::PxVec3(4.0f, 0.0f, 0.0f),1);
+ initializeCloth(0,physx::PxVec3(-7.0f, 2.0f, 0.0f), 0.0f);
+ initializeCloth(1, physx::PxVec3(2.0f, 2.0f, 0.0f), 1.0f);
mTime = 0.0f;
diff --git a/NvCloth/samples/SampleBase/scene/scenes/TriangleScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/TriangleScene.cpp
new file mode 100644
index 0000000..1822bb9
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/TriangleScene.cpp
@@ -0,0 +1,131 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#include "TriangleScene.h"
+#include "Scene/SceneController.h"
+#include <NvClothExt/ClothFabricCooker.h>
+#include "ClothMeshGenerator.h"
+#include <NvCloth/Fabric.h>
+#include <NvCloth/Solver.h>
+#include <NvCloth/Cloth.h>
+#include <NvCloth/Factory.h>
+#include "Renderer.h"
+#include "renderer/RenderUtils.h"
+#include "windows.h"
+#include "utils/MeshGenerator.h"
+
+DECLARE_SCENE_NAME(TriangleScene, "Triangle Scene")
+
+
+void TriangleScene::initializeCloth(int index, physx::PxVec3 offset)
+{
+ ///////////////////////////////////////////////////////////////////////
+ ClothMeshData clothMesh;
+
+ physx::PxMat44 transform = PxTransform(PxVec3(0.f, 13.f, 0.f)+ offset, PxQuat(0, PxVec3(1.f, 0.f, 0.f)));
+ clothMesh.GeneratePlaneCloth(5.f, 6.f, 39, 44, false, transform);
+ clothMesh.AttachClothPlaneByAngles(39, 44);
+ clothMesh.SetInvMasses(0.5f + (float)index * 2.0f);
+
+ mClothActor[index] = new ClothActor;
+ nv::cloth::ClothMeshDesc meshDesc = clothMesh.GetClothMeshDesc();
+ {
+ mClothActor[index]->mClothRenderMesh = new ClothRenderMesh(meshDesc);
+ mClothActor[index]->mClothRenderable = getSceneController()->getRenderer().createRenderable(*(static_cast<IRenderMesh*>(mClothActor[index]->mClothRenderMesh)), *getSceneController()->getDefaultMaterial());
+
+ float r, g, b;
+ r = index == 0 ? 1.0f : 0.3f;
+ g = index == 1 ? 1.0f : 0.3f;
+ b = index == 2 ? 1.0f : 0.3f;
+
+ mClothActor[index]->mClothRenderable->setColor(DirectX::XMFLOAT4(r, g, b, 1.0f));
+ }
+
+ nv::cloth::Vector<int32_t>::Type phaseTypeInfo;
+ mFabric[index] = NvClothCookFabricFromMesh(getSceneController()->getFactory(), meshDesc, physx::PxVec3(0.0f, 0.0f, 1.0f), &phaseTypeInfo, false);
+ trackFabric(mFabric[index]);
+
+ // Initialize start positions and masses for the actual cloth instance
+ // (note: the particle/vertex positions do not have to match the mesh description here. Set the positions to the initial shape of this cloth instance)
+ std::vector<physx::PxVec4> particlesCopy;
+ particlesCopy.resize(clothMesh.mVertices.size());
+
+ physx::PxVec3 clothOffset = transform.getPosition();
+ for(int i = 0; i < (int)clothMesh.mVertices.size(); i++)
+ {
+ // To put attachment point closer to each other
+ if(clothMesh.mInvMasses[i] < 1e-6)
+ clothMesh.mVertices[i] = (clothMesh.mVertices[i] - clothOffset)*0.95f + clothOffset;
+
+ particlesCopy[i] = physx::PxVec4(clothMesh.mVertices[i], clothMesh.mInvMasses[i]); // w component is 1/mass, or 0.0f for anchored/fixed particles
+ }
+
+ // Create the cloth from the initial positions/masses and the fabric
+ mClothActor[index]->mCloth = getSceneController()->getFactory()->createCloth(nv::cloth::Range<physx::PxVec4>(&particlesCopy[0], &particlesCopy[0] + particlesCopy.size()), *mFabric[index]);
+ particlesCopy.clear(); particlesCopy.shrink_to_fit();
+
+ mClothActor[index]->mCloth->setGravity(physx::PxVec3(0.0f, -9.8f, 0.0f));
+ mClothActor[index]->mCloth->setDamping(physx::PxVec3(0.1f, 0.1f, 0.1f));
+
+ //Generate triangle sphere
+ physx::PxVec3 meshOffset(0.0f, 11.0f, -1.0f);
+ auto mesh = MeshGenerator::generateIcosahedron(1.5f,1);
+ mesh.applyTransfom(physx::PxMat44(physx::PxTransform(meshOffset)));
+
+ //assign as collision data
+ physx::PxVec3* collisionTriangles;
+ int vertexCount = mesh.generateTriangleList(&collisionTriangles);
+ nv::cloth::Range<const physx::PxVec3> trRange(&collisionTriangles[0], &collisionTriangles[0] + vertexCount);
+ mClothActor[index]->mCloth->setTriangles(trRange, 0, 0);
+
+ //create render mesh
+ //scale down the render model to not intersect the triangles so much
+ mesh.applyTransfom( physx::PxMat44(physx::PxTransform(meshOffset))* //redo translation
+ physx::PxMat44(physx::PxVec4(0.97,0.97,0.97,1.0f))* //scale
+ physx::PxMat44(physx::PxTransform(-meshOffset))); //undo translation
+ auto renderMesh = new MeshGenerator::MeshGeneratorRenderMesh(mesh);
+ Renderable* renderable = getSceneController()->getRenderer().createRenderable(*renderMesh, *getSceneController()->getDefaultMaterial());
+ trackRenderable(renderable);
+
+ // Setup phase configs
+ std::vector<nv::cloth::PhaseConfig> phases(mFabric[index]->getNumPhases());
+ for(int i = 0; i < (int)phases.size(); i++)
+ {
+ phases[i].mPhaseIndex = i;
+ phases[i].mStiffness = 1.0f;
+ phases[i].mStiffnessMultiplier = 1.0f;
+ phases[i].mCompressionLimit = 1.0f;
+ phases[i].mStretchLimit = 1.0f;
+ }
+ mClothActor[index]->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
+ mClothActor[index]->mCloth->setDragCoefficient(0.1f);
+ mClothActor[index]->mCloth->setLiftCoefficient(0.1f);
+
+ trackClothActor(mClothActor[index]);
+
+ // Add the cloth to the solver for simulation
+ addClothToSolver(mClothActor[index], mSolver);
+}
+
+void TriangleScene::onInitialize()
+{
+ mSolver = getSceneController()->getFactory()->createSolver();
+ trackSolver(mSolver);
+
+ initializeCloth(0, physx::PxVec3(0.0f, 0.0f, 0.0f));
+
+ {
+ IRenderMesh* mesh = getSceneController()->getRenderer().getPrimitiveRenderMesh(PrimitiveRenderMeshType::Plane);
+ Renderable* plane = getSceneController()->getRenderer().createRenderable(*mesh, *getSceneController()->getDefaultPlaneMaterial());
+ plane->setTransform(PxTransform(PxVec3(0.f, 0.f, 0.f), PxQuat(PxPiDivTwo, PxVec3(0.f, 0.f, 1.f))));
+ plane->setScale(PxVec3(1000.f));
+ trackRenderable(plane);
+ }
+}
diff --git a/NvCloth/samples/SampleBase/scene/scenes/TriangleScene.h b/NvCloth/samples/SampleBase/scene/scenes/TriangleScene.h
new file mode 100644
index 0000000..35cfefb
--- /dev/null
+++ b/NvCloth/samples/SampleBase/scene/scenes/TriangleScene.h
@@ -0,0 +1,33 @@
+/*
+* Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved.
+*
+* NVIDIA CORPORATION and its licensors retain all intellectual property
+* and proprietary rights in and to this software, related documentation
+* and any modifications thereto. Any use, reproduction, disclosure or
+* distribution of this software and related documentation without an express
+* license agreement from NVIDIA CORPORATION is strictly prohibited.
+*/
+
+#ifndef TRIANGLE_SCENE_H
+#define TRIANGLE_SCENE_H
+
+#include "scene/Scene.h"
+#include <foundation/PxVec3.h>
+
+class TriangleScene : public Scene
+{
+public:
+
+ TriangleScene(SceneController* sceneController): Scene(sceneController) {}
+
+ void initializeCloth(int index, physx::PxVec3 offset);
+ virtual void onInitialize() override;
+
+private:
+ nv::cloth::Fabric* mFabric[1];
+ nv::cloth::Solver* mSolver;
+ ClothActor* mClothActor[1];
+};
+
+
+#endif \ No newline at end of file
diff --git a/NvCloth/samples/SampleBase/scene/scenes/WindScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/WindScene.cpp
index 51cec1d..232316d 100644
--- a/NvCloth/samples/SampleBase/scene/scenes/WindScene.cpp
+++ b/NvCloth/samples/SampleBase/scene/scenes/WindScene.cpp
@@ -18,6 +18,7 @@
#include <NvCloth/Factory.h>
#include "Renderer.h"
#include "renderer/RenderUtils.h"
+#include "windows.h"
DECLARE_SCENE_NAME(WindScene, "Wind Scene")
@@ -27,17 +28,19 @@ void WindScene::Animate(double dt)
if(mTime > 3.7f)
{
- float dvx = 3.f * cos(25.f * mTime);
- float vy = max(0.f, 0.9f * cos(11.f * mTime));
- float dvz = 1.5f * sin(19.f * mTime);
+ float dvx = 6.0f * sin((1.f + sinf(mTime) * 0.5f) * mTime);
+ float vy = 0;
+ float dvz = 50.0f + 7.0f * sin((9.f + sinf(mTime + 2.0f) * 0.5f) * mTime)
+ + 4.0f * sin((7.f + sinf(mTime * 0.9f) * 0.5f) * mTime);
+
for(int i = 0; i < 3; i++)
{
- physx::PxVec3 wind = physx::PxVec3(2.5f + dvx, vy, 15.f + dvz);
+ physx::PxVec3 wind = physx::PxVec3(dvx, vy, dvz);
mClothActor[i]->mCloth->setWindVelocity(wind);
}
}
- doSimulationStep(dt);
+ Scene::Animate(dt);
}
void WindScene::initializeCloth(int index, physx::PxVec3 offset)
@@ -45,17 +48,23 @@ void WindScene::initializeCloth(int index, physx::PxVec3 offset)
///////////////////////////////////////////////////////////////////////
ClothMeshData clothMesh;
- physx::PxMat44 transform = PxTransform(PxVec3(0.f, 13.f, 0.f)+ offset, PxQuat(PxPi / 6.f, PxVec3(1.f, 0.f, 0.f)));
- clothMesh.GeneratePlaneCloth(5.f, 6.f, 49, 59, false, transform);
- clothMesh.AttachClothPlaneByAngles(49, 59);
- clothMesh.SetInvMasses(0.2f + (float)index * 1.4f);
+ physx::PxMat44 transform = PxTransform(PxVec3(0.f, 13.f, 0.f) + offset, PxQuat(PxPi / 2.0f, PxVec3(1.f, 0.f, 0.f)));
+ clothMesh.GeneratePlaneCloth(5.f, 6.f, 69, 79, false, transform);
+ clothMesh.AttachClothPlaneByAngles(69, 79);
+ clothMesh.SetInvMasses(0.5f + (float)index * 2.0f);
mClothActor[index] = new ClothActor;
nv::cloth::ClothMeshDesc meshDesc = clothMesh.GetClothMeshDesc();
{
mClothActor[index]->mClothRenderMesh = new ClothRenderMesh(meshDesc);
mClothActor[index]->mClothRenderable = getSceneController()->getRenderer().createRenderable(*(static_cast<IRenderMesh*>(mClothActor[index]->mClothRenderMesh)), *getSceneController()->getDefaultMaterial());
- mClothActor[index]->mClothRenderable->setColor(getRandomPastelColor());
+
+ float r, g, b;
+ r = index == 0 ? 1.0f : 0.3f;
+ g = index == 1 ? 1.0f : 0.3f;
+ b = index == 2 ? 1.0f : 0.3f;
+
+ mClothActor[index]->mClothRenderable->setColor(DirectX::XMFLOAT4(r, g, b, 1.0f));
}
nv::cloth::Vector<int32_t>::Type phaseTypeInfo;
@@ -68,11 +77,11 @@ void WindScene::initializeCloth(int index, physx::PxVec3 offset)
particlesCopy.resize(clothMesh.mVertices.size());
physx::PxVec3 clothOffset = transform.getPosition();
- for(int i = 0; i < (int)clothMesh.mVertices.size(); i++)
+ for (int i = 0; i < (int)clothMesh.mVertices.size(); i++)
{
// To put attachment point closer to each other
if(clothMesh.mInvMasses[i] < 1e-6)
- clothMesh.mVertices[i] = (clothMesh.mVertices[i] - clothOffset)*0.9f + clothOffset;
+ clothMesh.mVertices[i] = (clothMesh.mVertices[i] - clothOffset)*0.95f + clothOffset;
particlesCopy[i] = physx::PxVec4(clothMesh.mVertices[i], clothMesh.mInvMasses[i]); // w component is 1/mass, or 0.0f for anchored/fixed particles
}
@@ -85,7 +94,7 @@ void WindScene::initializeCloth(int index, physx::PxVec3 offset)
// Setup phase configs
std::vector<nv::cloth::PhaseConfig> phases(mFabric[index]->getNumPhases());
- for(int i = 0; i < (int)phases.size(); i++)
+ for (int i = 0; i < (int)phases.size(); i++)
{
phases[i].mPhaseIndex = i;
phases[i].mStiffness = 1.0f;
@@ -94,11 +103,9 @@ void WindScene::initializeCloth(int index, physx::PxVec3 offset)
phases[i].mStretchLimit = 1.0f;
}
mClothActor[index]->mCloth->setPhaseConfig(nv::cloth::Range<nv::cloth::PhaseConfig>(&phases.front(), &phases.back()));
- mClothActor[index]->mCloth->setDragCoefficient(0.5f);
- mClothActor[index]->mCloth->setLiftCoefficient(0.6f);
+ mClothActor[index]->mCloth->setDragCoefficient(0.4f);
+ mClothActor[index]->mCloth->setLiftCoefficient(0.25f);
- mSolver = getSceneController()->getFactory()->createSolver();
- trackSolver(mSolver);
trackClothActor(mClothActor[index]);
// Add the cloth to the solver for simulation
@@ -107,10 +114,12 @@ void WindScene::initializeCloth(int index, physx::PxVec3 offset)
void WindScene::onInitialize()
{
+ mSolver = getSceneController()->getFactory()->createSolver();
+ trackSolver(mSolver);
- initializeCloth(2,physx::PxVec3(-9.0f,0.0f,0.0f));
- initializeCloth(1, physx::PxVec3(-2.0f, 0.0f, 0.0f));
- initializeCloth(0, physx::PxVec3(5.0f, 0.0f, 0.0f));
+ initializeCloth(2,physx::PxVec3(-11.0f, 0.0f,0.0f));
+ initializeCloth(1, physx::PxVec3(-4.0f, 0.0f, 0.0f));
+ initializeCloth(0, physx::PxVec3(3.0f, 0.0f, 0.0f));
mTime = 0.0f;