11 May Creating a scene procedurally
The process to create a scene procedurally with SOFA Front-end is easy as you do not have to manipulate the (complex) template types of your objects. It is very similar to what you do when you create a scene through a Xml file.
The first step is, of course, to get a handle on the simulation root.
1 2 3 4 5 6 | #include <sfe/Simulation.h> int main ( int argc, char** argv ) { sfe::Simulation simulation = sfe::getSimulation(); sfe::Node root = simulation.root(); |
The creation is quite straightforward: you just have to call the createObject method on handle of the parent node. This method will call the factory of the object and will insert it under that node. If you want to set the value of some data, you can do it using an initializer list.
7 8 9 10 11 | // Creates the object FreeAnimationLoop and place it under root root.createObject("FreeMotionAnimationLoop"); // Creates the object LCPConstraintSolver and sets tolerance to 0.001 and mu to 0.8 root.createObject("LCPConstraintSolver", { { "tolerance", "0.001" }, { "mu", "0.8" } }); |
To create a child node, you can use the method createChild, you will be able to use the new node just as you did with root.
12 13 14 15 16 17 | // Creates a new node named "Child" and place it under root sfe::Node child = root.createChild("Child"); // Creates a new object under child child.createObject("EulerImplicitSolver"); ... |
You can also modify the value of dt and gravity for the simulation itself by calling the setDt and setGravity methods respectively. Do not forget to initialize the simulation before you iterate it.
18 19 20 21 22 | ... simulation.setGravity( 0, 0, -9.8 ); simulation.setDt( 0.015 ); // Initializes the scene. simulation.init(); |
Sorry, the comment form is closed at this time.