diff options
| author | Marijn Tamis <[email protected]> | 2017-07-03 11:49:08 +0200 |
|---|---|---|
| committer | Marijn Tamis <[email protected]> | 2017-07-03 11:49:08 +0200 |
| commit | cfa944ded7370fb5f22b1fb894ecf6b9bd3f7381 (patch) | |
| tree | 5cc014922d20561d87105d279b6f7eb3e628c6d9 /NvCloth/samples/SampleBase | |
| parent | Fix windows line endings in github. (diff) | |
| download | nvcloth-1.1.1.tar.xz nvcloth-1.1.1.zip | |
NvCloth 1.1.1 Release. (22392725)v1.1.1
Diffstat (limited to 'NvCloth/samples/SampleBase')
| -rw-r--r-- | NvCloth/samples/SampleBase/Main.cpp | 6 | ||||
| -rw-r--r-- | NvCloth/samples/SampleBase/scene/scenes/ScaledScene.cpp | 98 | ||||
| -rw-r--r-- | NvCloth/samples/SampleBase/scene/scenes/ScaledScene.h | 32 | ||||
| -rw-r--r-- | NvCloth/samples/SampleBase/scene/scenes/WindScene.cpp | 2 |
4 files changed, 136 insertions, 2 deletions
diff --git a/NvCloth/samples/SampleBase/Main.cpp b/NvCloth/samples/SampleBase/Main.cpp index 433ed88..f4107c3 100644 --- a/NvCloth/samples/SampleBase/Main.cpp +++ b/NvCloth/samples/SampleBase/Main.cpp @@ -12,7 +12,9 @@ #include <sstream> #include <Windows.h> - +#include <iostream> +#include <io.h> +#include <fcntl.h> using namespace std; @@ -22,6 +24,8 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi #if defined(DEBUG) | defined(_DEBUG) _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); AllocConsole(); + FILE* fp; + freopen_s(&fp, "CONOUT$", "w", stdout); #endif SampleConfig config; diff --git a/NvCloth/samples/SampleBase/scene/scenes/ScaledScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/ScaledScene.cpp new file mode 100644 index 0000000..f2a5b82 --- /dev/null +++ b/NvCloth/samples/SampleBase/scene/scenes/ScaledScene.cpp @@ -0,0 +1,98 @@ +/* +* 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 "ScaledScene.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(ScaledScene,"Scaled Scene") + +void ScaledScene::onInitialize() +{ + /////////////////////////////////////////////////////////////////////// + ClothMeshData clothMesh; + + physx::PxMat44 transform = PxTransform(PxVec3(-2.f, 13.f, 0.f)*0.0, PxQuat(PxPi / 6.f, PxVec3(1.f, 0.f, 0.f))); + clothMesh.GeneratePlaneCloth(600.f, 700.f, 49, 59, false, transform); + clothMesh.AttachClothPlaneByAngles(49, 59); + + 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()); + mClothActor->mClothRenderable->setScale(physx::PxVec3(0.01, 0.01, 0.01)); + mClothActor->mClothRenderable->setTransform(PxTransform(PxVec3(-2.f, 13.f, 0.f),physx::PxQuat(physx::PxIdentity))); + } + + nv::cloth::Vector<int32_t>::Type phaseTypeInfo; + mFabric = NvClothCookFabricFromMesh(getSceneController()->getFactory(), meshDesc, physx::PxVec3(0.0f, -9.8f, 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()); + + physx::PxVec3 center = transform.transform(physx::PxVec3(0.0f, 0.0f, 0.0f)); + 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; + + 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); + particlesCopy.clear(); particlesCopy.shrink_to_fit(); + + mClothActor->mCloth->setGravity(physx::PxVec3(0.0f, -980.0f, 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->setLiftCoefficient(0.1f); + //mClothActor->mCloth->setWindVelocity(physx::PxVec3(50, 0.0, 50.0)); + mClothActor->mCloth->setFluidDensity(1.0f / powf(100, 3)); + + 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/ScaledScene.h b/NvCloth/samples/SampleBase/scene/scenes/ScaledScene.h new file mode 100644 index 0000000..eb47c36 --- /dev/null +++ b/NvCloth/samples/SampleBase/scene/scenes/ScaledScene.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 SCALED_SCENE_H +#define SCALED_SCENE_H + +#include "scene/Scene.h" + +class ScaledScene : public Scene +{ +public: + + ScaledScene(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/WindScene.cpp b/NvCloth/samples/SampleBase/scene/scenes/WindScene.cpp index 232316d..d84fb87 100644 --- a/NvCloth/samples/SampleBase/scene/scenes/WindScene.cpp +++ b/NvCloth/samples/SampleBase/scene/scenes/WindScene.cpp @@ -35,7 +35,7 @@ void WindScene::Animate(double dt) for(int i = 0; i < 3; i++) { - physx::PxVec3 wind = physx::PxVec3(dvx, vy, dvz); + physx::PxVec3 wind = physx::PxVec3(dvx, vy, dvz)/5.0f; mClothActor[i]->mCloth->setWindVelocity(wind); } } |