5 The `Scene` defines a flat collection of `SceneObject`s and fully represents the virtual environment. `SceneObject`s may be a surgical tool, a tissue, OR table, a leg, light, or even non-visual objects. A simple visual object can be added to the `Scene` as:
8 auto scene = std::make_shared<Scene>("MyScene");
10 auto myObject = std::make_shared<SceneObject>("MyObject");
11 auto visuals = myObject->addComponent<VisualModel>();
12 // visuals->setGeometry(<my geometry here>);
13 scene->addSceneObject(myObject);
16 iMSTK contains an entity-component (ECS) model that is still a work in progress. Whilst objects/entities represent whole concepts such as a `tool` or `table`. A component represents a **swappable** part of the object/entity such as the legs of a table or reciprocation of a saw tool. ECS's are common in many game engines for modularity and flexibility. One may subclass Component or Behaviour to add new functionality.
20 Whilst iMSTK is in the middle of an ECS refactor. The SceneObject represents and object in the scene. It stems from Entity providing an optional visual geometry and a `TaskGraph` to introduce `TaskNode` steps to the scene `TaskGraph` that is run during advacement of the scene.
22 Many types stem from SceneObject eventually to be moved to `Component`s, here's a full list of those types:
24 - **SceneObject**: Provides an object with a visual geometry and empty virtual update function. Geometry is optional.
25 - **CollidingObject**: Provides an object with both visual and colliding geometry.
26 - **PbdObject**: Provides a PbdModel governing its physics.
27 - **RigidObject**: Provides a RigidBodyModel governing its physics.
28 - **RigidObject2**: Provides a RigidBodyModel2 governing its physics.
29 - **FemDeformableObject**: Provides a FemModel governing its physics.
30 - **SPHObject**: Provides a SPHModel governing i
31 - **LevelSetDeformableObject**: Provides a LevelSetModel governing its physics.
35 An entity (`SceneObject` base) is made of many components. A component represents a data-only part of an entity. It does no function, has an initialization, and a reference to the entity it is part of. Components can be placed on/off entities/objects whenever. One can extend to hold relevant data and use elsewhere.
38 class MyComponent : public Component
41 Mat4d myTransform = Mat4d::Identity();
47 A `Behaviour` is a `Component` that has function. Generally only recommend for small independent bits of logic. Anything that involves multiple components, call order, lots of communication, or multiple `Entity`'s may need its own system such the VTKRenderer or Scene. Alternatively the TaskGraph can be used.
50 class MyBehaviour : public Behaviour
53 void update() override {} // Called per SceneManager::update (Scene::advance)
54 void visualUpdate() override {} // Called per VTKViewer::update
58 It is safe to assume the physics system is complete before entering any components. See more in the computational flow section.
60 ## Initialization of the Scene
62 Initialization of the scene and the things in it is done as follows:
65 - Initialize all `SceneObject`'s of the `Scene`
66 - Initialize all `Component`'s of every `SceneObject` in the `Scene`
67 - If any `Component`s are introduced during `Component::initialize`, they are initialized too
68 - Initialize all the `DynamicalModel`'s used by `SceneObject`'s in the `Scene`
69 - Build the `TaskGraph` of the `Scene`
71 ## Advancement of a Scene
73 Normally the `Scene` would be given to the `SceneManager` to run and `VTKViewer` to render. These would be apart of `SimulationManager`. However, one is able to advance the scene at their own timestep by using:
76 scene->initialize(); // Must be initialized first
77 scene->advance(0.001); // Timestep to advance by
80 Update order is as follows:
81 - Update all `SceneObject`s and `Behaviour`s on them.
82 - Update all `TaskGraph` nodes (including physics steps).