7 #include "imstkCamera.h" 8 #include "imstkCollisionUtils.h" 9 #include "imstkDirectionalLight.h" 10 #include "imstkGeometryUtilities.h" 11 #include "imstkKeyboardDeviceClient.h" 12 #include "imstkKeyboardSceneControl.h" 13 #include "imstkMouseDeviceClient.h" 14 #include "imstkMouseSceneControl.h" 16 #include "imstkPlane.h" 17 #include "imstkRbdConstraint.h" 18 #include "imstkRenderMaterial.h" 19 #include "imstkRigidBodyModel2.h" 20 #include "imstkRigidObject2.h" 21 #include "imstkRigidObjectCollision.h" 22 #include "imstkScene.h" 23 #include "imstkSceneManager.h" 24 #include "imstkSimulationManager.h" 25 #include "imstkSimulationUtils.h" 26 #include "imstkSphere.h" 27 #include "imstkSurfaceMesh.h" 28 #include "imstkUnidirectionalPlaneToSphereCD.h" 29 #include "imstkVisualModel.h" 30 #include "imstkVTKViewer.h" 32 using namespace imstk;
48 auto scene = std::make_shared<Scene>(
"RbdMeshMeshCollision");
53 auto rbdModel = std::make_shared<RigidBodyModel2>();
59 rbdModel->getConfig()->m_gravity = Vec3d(0.0, -9.8, 0.0);
60 rbdModel->getConfig()->m_maxNumIterations = 10;
64 auto sphere = std::make_shared<Sphere>(Vec3d(0, 0, 0), 0.5);
68 auto sphereObject = std::make_shared<RigidObject2>(
"Sphere");
72 auto sphereVisualModel = std::make_shared<VisualModel>();
73 sphereVisualModel->setGeometry(sphere);
74 sphereObject->addVisualModel(sphereVisualModel);
77 auto sphereMaterial = std::make_shared<RenderMaterial>();
78 sphereMaterial->setDiffuseColor(
Color(1.0, 0.333, 0.259));
80 sphereMaterial->setRoughness(0.5);
81 sphereMaterial->setMetalness(0.5);
82 sphereVisualModel->setRenderMaterial(sphereMaterial);
85 sphereObject->setCollidingGeometry(sphere);
88 sphereObject->setPhysicsGeometry(sphere);
90 sphereObject->setDynamicalModel(rbdModel);
91 sphereObject->getRigidBody()->m_mass = 1.0;
93 sphereObject->getRigidBody()->m_initPos = Vec3d(0.0, 3.0, 0.0);
94 sphereObject->getRigidBody()->m_intertiaTensor = Mat3d::Identity();
97 scene->addSceneObject(sphereObject);
100 auto plane = std::make_shared<Plane>(Vec3d::Zero(), Vec3d::UnitY());
104 plane->setWidth(10.0);
107 auto planeObject = std::make_shared<CollidingObject>(
"Plane");
108 planeObject->setVisualGeometry(plane);
109 planeObject->setCollidingGeometry(plane);
110 scene->addSceneObject(planeObject);
117 scene->addInteraction(
118 std::make_shared<RigidObjectCollision>(sphereObject, planeObject, UnidirectionalPlaneToSphereCD::getStaticTypeName()));
121 scene->getActiveCamera()->setPosition(0, 3, 20);
122 scene->getActiveCamera()->setFocalPoint(0.0, 0.0, 0.0);
123 scene->getActiveCamera()->setViewUp(0, 1, 0);
128 scene->addLight(
"light", light);
131 auto viewer = std::make_shared<VTKViewer>();
132 viewer->setActiveScene(scene);
135 auto sceneManager = std::make_shared<SceneManager>();
136 sceneManager->setActiveScene(scene);
137 sceneManager->pause();
140 auto simulationManager = std::make_shared<SimulationManager>();
141 simulationManager->addModule(viewer);
142 simulationManager->addModule(sceneManager);
143 simulationManager->setDesiredDt(0.001);
146 std::shared_ptr<Entity> mouseAndKeyControls =
147 SimulationUtils::createDefaultSceneControl(simulationManager);
148 scene->addSceneObject(mouseAndKeyControls);
155 connect<Event>(sceneManager, &SceneManager::postUpdate, [scene](
Event*) {
162 simulationManager->start();
Base class for events which contain a type, priority, and data priority defaults to 0 and uses a grea...
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...
Physically based rendering.
static LoggerG3 & startLogger()
Starts logger with default sinks, use getInstance to create a logger with no sinks.