forked from sofa-framework/SofaPython3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadXMLfromPython.py
More file actions
54 lines (44 loc) · 1.45 KB
/
loadXMLfromPython.py
File metadata and controls
54 lines (44 loc) · 1.45 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
47
48
49
50
51
52
53
54
import Sofa
import tempfile
import os
def createScene(root):
# Call the above function to create the scene graph
scene="""
<Node dt="0.005" gravity="0 0 0">
<RequiredPlugin name="Sofa.GL.Component.Rendering2D" />
<RequiredPlugin name="Sofa.Component.StateContainer" />
<Node name="child1">
<MechanicalObject template="Rigid3d" position="0 0 0 0 0 0 1" showObject="1"/>
</Node>
<Node name="child2">
<MechanicalObject template="Rigid3d" position="1 1 1 0 0 0 1" showObject="1"/>
</Node>
</Node>
"""
tf = tempfile.NamedTemporaryFile(mode="w+t", suffix=".scn", delete=False)
tf.write(scene)
tf.flush()
tf.close()
loaded_node = Sofa.Simulation.load(tf.name)
root.addChild(loaded_node)
os.remove(tf.name)
def main():
import SofaRuntime
import Sofa.Gui
root = Sofa.Core.Node("root")
createScene(root)
Sofa.Simulation.initRoot(root)
# Find out the supported GUIs
print ("Supported GUIs are: " + Sofa.Gui.GUIManager.ListSupportedGUI(","))
# Launch the GUI (qt or qglviewer)
Sofa.Gui.GUIManager.Init("myscene", "qglviewer")
Sofa.Gui.GUIManager.createGUI(root, __file__)
Sofa.Gui.GUIManager.SetDimension(1080, 1080)
# Initialization of the scene will be done here
Sofa.Gui.GUIManager.MainLoop(root)
Sofa.Gui.GUIManager.closeGUI()
print("GUI was closed")
print("Simulation is done.")
# Function used only if this script is called from a python environment
if __name__ == '__main__':
main()