7 #include "imstkCamera.h" 8 #include "imstkGeometryUtilities.h" 9 #include "imstkImageData.h" 10 #include "imstkKeyboardDeviceClient.h" 11 #include "imstkKeyboardSceneControl.h" 12 #include "imstkMeshIO.h" 13 #include "imstkMouseDeviceClient.h" 14 #include "imstkMouseSceneControl.h" 16 #include "imstkPbdModel.h" 17 #include "imstkPbdModelConfig.h" 18 #include "imstkPbdObject.h" 19 #include "imstkRenderMaterial.h" 20 #include "imstkScene.h" 21 #include "imstkSceneManager.h" 22 #include "imstkSimulationManager.h" 23 #include "imstkSimulationUtils.h" 24 #include "imstkSurfaceMesh.h" 25 #include "imstkVisualModel.h" 26 #include "imstkVTKViewer.h" 28 using namespace imstk;
31 setFabricTextures(std::shared_ptr<RenderMaterial> material)
33 auto diffuseTex = MeshIO::read<ImageData>(iMSTK_DATA_ROOT
"/textures/fabricDiffuse.jpg");
34 material->addTexture(std::make_shared<Texture>(diffuseTex, Texture::Type::Diffuse));
35 auto normalTex = MeshIO::read<ImageData>(iMSTK_DATA_ROOT
"/textures/fabricNormal.jpg");
36 material->addTexture(std::make_shared<Texture>(normalTex, Texture::Type::Normal));
37 auto ormTex = MeshIO::read<ImageData>(iMSTK_DATA_ROOT
"/textures/fabricORM.jpg");
38 material->addTexture(std::make_shared<Texture>(ormTex, Texture::Type::ORM));
42 setFleshTextures(std::shared_ptr<RenderMaterial> material)
44 auto diffuseTex = MeshIO::read<ImageData>(iMSTK_DATA_ROOT
"/textures/fleshDiffuse.jpg");
45 material->addTexture(std::make_shared<Texture>(diffuseTex, Texture::Type::Diffuse));
46 auto normalTex = MeshIO::read<ImageData>(iMSTK_DATA_ROOT
"/textures/fleshNormal.jpg");
47 material->addTexture(std::make_shared<Texture>(normalTex, Texture::Type::Normal));
48 auto ormTex = MeshIO::read<ImageData>(iMSTK_DATA_ROOT
"/textures/fleshORM.jpg");
49 material->addTexture(std::make_shared<Texture>(ormTex, Texture::Type::ORM));
60 static std::shared_ptr<PbdObject>
61 makeClothObj(
const std::string& name,
70 std::shared_ptr<SurfaceMesh> clothMesh =
72 Vec2d(10.0, 10.0), Vec2i(16, 16), Quatd::Identity(), 2.0);
76 pbdParams->
enableConstraint(PbdModelConfig::ConstraintGenType::Distance, 1.0e2);
77 pbdParams->
enableConstraint(PbdModelConfig::ConstraintGenType::Dihedral, 1.0e1);
78 pbdParams->
m_gravity = Vec3d(0.0, -9.8, 0.0);
79 pbdParams->
m_dt = 0.005;
88 material->setBackFaceCulling(
false);
89 material->setDisplayMode(RenderMaterial::DisplayMode::Surface);
91 setFleshTextures(material);
93 visualModel->setGeometry(clothMesh);
97 clothObj->addVisualModel(visualModel);
98 clothObj->setPhysicsGeometry(clothMesh);
99 clothObj->setDynamicalModel(pbdModel);
100 clothObj->getPbdBody()->fixedNodeIds = { 0, colCount - 1 };
101 clothObj->getPbdBody()->uniformMassValue = width * height / (rowCount * colCount);
118 scene->getActiveCamera()->setFocalPoint(0.0, -5.0, 0.0);
119 scene->getActiveCamera()->setPosition(0.0, 1.5, 25.0);
120 scene->getActiveCamera()->setViewUp(0.0, 1.0, 0.0);
122 std::shared_ptr<PbdObject> clothObj = makeClothObj(
"Cloth", 10.0, 10.0, 16, 16);
123 scene->addSceneObject(clothObj);
134 sceneManager->pause();
142 std::shared_ptr<Entity> mouseAndKeyControls =
143 SimulationUtils::createDefaultSceneControl(driver);
144 scene->addSceneObject(mouseAndKeyControls);
146 using Vec3uc = Eigen::Matrix<unsigned char, 3, 1>;
152 setFleshTextures(clothObj->getVisualModel(0)->getRenderMaterial());
154 else if (e->m_key ==
'2')
156 setFabricTextures(clothObj->getVisualModel(0)->getRenderMaterial());
159 else if (e->m_key ==
'h')
161 auto imageData = clothObj->getVisualModel(0)->getRenderMaterial()->getTexture(Texture::Type::Diffuse)->getImageData();
163 Vec3uc* scalarPtr = scalars->getPointer();
164 for (
int i = 0; i < scalars->size(); i++)
166 scalarPtr[i] = (scalarPtr[i].cast<
double>() * 0.8).cast<
unsigned char>();
168 clothObj->getVisualModel(0)->getRenderMaterial()->getTexture(Texture::Type::Diffuse)->postModified();
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.
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.
Simple dynamic array implementation that also supports event posting and viewing/facade.
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)
void setRenderMaterial(std::shared_ptr< RenderMaterial > renderMaterial)
Set/Get render material.
double m_dt
Time step size.
void setActiveScene(std::string newSceneName)
Sets the currently updating scene.
Physically based rendering.
static LoggerG3 & startLogger()
Starts logger with default sinks, use getInstance to create a logger with no sinks.
Vec3d m_gravity
Gravity acceleration.