7 #include "imstkCamera.h" 8 #include "imstkDirectionalLight.h" 9 #include "imstkGeometryUtilities.h" 10 #include "imstkKeyboardDeviceClient.h" 11 #include "imstkKeyboardSceneControl.h" 12 #include "imstkMouseDeviceClient.h" 13 #include "imstkMouseSceneControl.h" 15 #include "imstkPbdModel.h" 16 #include "imstkPbdModelConfig.h" 17 #include "imstkPbdObject.h" 18 #include "imstkRenderMaterial.h" 19 #include "imstkScene.h" 20 #include "imstkSceneManager.h" 21 #include "imstkSimulationManager.h" 22 #include "imstkSimulationUtils.h" 23 #include "imstkSpotLight.h" 24 #include "imstkSurfaceMesh.h" 25 #include "imstkSurfaceMeshSubdivide.h" 26 #include "imstkVisualModel.h" 27 #include "imstkVTKViewer.h" 29 using namespace imstk;
39 static std::shared_ptr<PbdObject>
40 makeClothObj(
const std::string& name,
49 std::shared_ptr<SurfaceMesh> clothMesh =
51 Vec2d(width, height), Vec2i(nRows, nCols));
55 pbdParams->
enableConstraint(PbdModelConfig::ConstraintGenType::Distance, 1.0e2);
56 pbdParams->
enableConstraint(PbdModelConfig::ConstraintGenType::Dihedral, 1.0e1);
57 pbdParams->
m_gravity = Vec3d(0.0, -9.8, 0.0);
58 pbdParams->
m_dt = 0.01;
67 material->setBackFaceCulling(
false);
68 material->setDisplayMode(RenderMaterial::DisplayMode::WireframeSurface);
71 visualModel->setGeometry(clothMesh);
75 clothObj->addVisualModel(visualModel);
76 clothObj->setPhysicsGeometry(clothMesh);
77 clothObj->setDynamicalModel(pbdModel);
78 clothObj->getPbdBody()->fixedNodeIds = { 0, nCols - 1 };
79 clothObj->getPbdBody()->uniformMassValue = width * height / (nRows * nCols);
96 scene->getActiveCamera()->setFocalPoint(0.0, -5.0, 0.0);
97 scene->getActiveCamera()->setPosition(0.0, 1.5, 25.0);
98 scene->getActiveCamera()->setViewUp(0.0, 1.0, 0.0);
100 std::shared_ptr<PbdObject> clothObj = makeClothObj(
"Cloth", 10.0, 10.0, 8, 8);
101 scene->addSceneObject(clothObj);
107 scene->addLight(
"whitelight", whiteLight);
111 colorLight->setPosition(Vec3d(-5.0, -3.0, 5.0));
116 scene->addLight(
"colorlight", colorLight);
127 sceneManager->pause();
135 std::shared_ptr<Entity> mouseAndKeyControls =
136 SimulationUtils::createDefaultSceneControl(driver);
137 scene->addSceneObject(mouseAndKeyControls);
148 std::shared_ptr<SurfaceMesh> clothMesh = std::dynamic_pointer_cast<
SurfaceMesh>(clothObj->getPhysicsGeometry());
150 subdiv->setInputMesh(clothMesh);
151 subdiv->setNumberOfSubdivisions(1);
152 subdiv->setSubdivisionType(SurfaceMeshSubdivide::Type::LINEAR);
154 std::shared_ptr<SurfaceMesh> newClothMesh = subdiv->getOutputMesh();
159 clothMesh->setInitialVertexPositions(std::make_shared<
VecDataArray<double, 3>>(*newClothMesh->getVertexPositions()));
160 clothMesh->setVertexPositions(newClothMesh->getVertexPositions());
161 clothMesh->setCells(newClothMesh->getCells());
162 clothMesh->setVertexAttribute(
"Velocities", newClothMesh->getVertexAttribute(
"Velocities"));
163 clothMesh->postModified();
166 clothObj->initialize();
167 clothObj->getPbdModel()->initialize();
void configure(std::shared_ptr< PbdModelConfig > params)
Set simulation parameters.
void setDesiredDt(const double dt)
Sets the target fixed timestep (may violate), seconds This ultimately effects the number of iteration...
void setActiveScene(std::shared_ptr< Scene > scene) override
Set scene to be rendered.
std::shared_ptr< SurfaceMesh > toTriangleGrid(const Vec3d ¢er, const Vec2d &size, const Vec2i &dim, const Quatd orientation=Quatd::Identity(), const double uvScale=1.0)
Produces a triangle grid on a plane given the imstkPlane.
void setColor(const Color &c)
Set the light color.
std::shared_ptr< KeyboardDeviceClient > getKeyboardDevice() const override
Returns the device that emits key events.
void addModule(std::shared_ptr< Module > module) override
Add a module to run.
void enableConstraint(ConstraintGenType type, const double stiffness, const int bodyId=2)
Enables a constraint of type defined by ConstraintGenType with given stiffness. If constraint of that...
unsigned int m_iterations
Internal constraints pbd solver iterations.
void setIntensity(const double intensity)
Set the light intensity. This value is unbounded.
std::shared_ptr<T> obj = std::make_shared<T>(); equivalent, convenience class for STL shared allocati...
Provides the information of a key event (press, release, & which key)
Represents a set of triangles & vertices via an array of Vec3d double vertices & Vec3i integer indice...
void setRenderMaterial(std::shared_ptr< RenderMaterial > renderMaterial)
Set/Get render material.
double m_dt
Time step size.
void setSpotAngle(const double angle)
Set the spotlight angle in degrees.
void setFocalPoint(const Vec3d &p)
Get/Set the light focal point.
void setActiveScene(std::string newSceneName)
Sets the currently updating scene.
static LoggerG3 & startLogger()
Starts logger with default sinks, use getInstance to create a logger with no sinks.
Vec3d m_gravity
Gravity acceleration.