forked from sofa-framework/SofaPython3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.py
More file actions
46 lines (30 loc) · 1.28 KB
/
basic.py
File metadata and controls
46 lines (30 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Required import for python
import Sofa
import SofaRuntime
def main():
# Make sure to load all necessary libraries
SofaRuntime.importPlugin("Sofa.Component.StateContainer")
# Call the above function to create the scene graph
root = Sofa.Core.Node("root")
createScene(root)
# Once defined, initialization of the scene graph
Sofa.Simulation.initRoot(root)
# Run the simulation for 10 steps
for iteration in range(10):
print(f'Iteration #{iteration}')
Sofa.Simulation.animate(root, root.dt.value)
print("Simulation made 10 time steps. Done")
# Function called when the scene graph is being created
def createScene(root):
root.addObject('RequiredPlugin', name='Sofa.Component.StateContainer')
# Scene must now include a AnimationLoop
root.addObject('DefaultAnimationLoop')
# Add new nodes and objects in the scene
node1 = root.addChild("Node1")
node2 = root.addChild("Node2")
node1.addObject("MechanicalObject", template="Rigid3d", position="0 0 0 0 0 0 1", showObject="1")
node2.addObject("MechanicalObject", template="Rigid3d", position="1 1 1 0 0 0 1", showObject="1")
return root
# Function used only if this script is called from a python environment
if __name__ == '__main__':
main()