11import Sofa
2- import Sofa .Gui
3- import SofaRuntime
42import tempfile
53import os
64
75
8-
9- def main ():
10- # Make sure to load all SOFA libraries
11- SofaRuntime .importPlugin ("SofaOpenglVisual" )
12-
13- root = Sofa .Core .Node ("root" )
14-
6+ def createScene (root ):
157 # Call the above function to create the scene graph
168 scene = """
17- <Node name="rootNode" dt="0.005" gravity="0 0 0">
18-
9+ <Node dt="0.005" gravity="0 0 0">
10+ <RequiredPlugin name="SofaOpenglVisual" />
1911 <DefaultVisualManagerLoop/>
2012 <DefaultAnimationLoop/>
2113
@@ -31,21 +23,32 @@ def main():
3123 tf = tempfile .NamedTemporaryFile (mode = "w+t" , suffix = ".scn" , delete = False )
3224 tf .write (scene )
3325 tf .flush ()
34- node = Sofa .Simulation .load (tf .name )
26+ loaded_node = Sofa .Simulation .load (tf .name )
27+ root .addChild (loaded_node )
28+ os .remove (tf .name )
29+
30+
31+ def main ():
32+ import SofaRuntime
33+ import Sofa .Gui
34+
35+ root = Sofa .Core .Node ("root" )
36+ createScene (root )
37+ Sofa .Simulation .init (root )
3538
3639 # Find out the supported GUIs
3740 print ("Supported GUIs are: " + Sofa .Gui .GUIManager .ListSupportedGUI ("," ))
3841 # Launch the GUI (qt or qglviewer)
3942 Sofa .Gui .GUIManager .Init ("myscene" , "qglviewer" )
40- Sofa .Gui .GUIManager .createGUI (node , __file__ )
43+ Sofa .Gui .GUIManager .createGUI (root , __file__ )
4144 Sofa .Gui .GUIManager .SetDimension (1080 , 1080 )
4245 # Initialization of the scene will be done here
43- Sofa .Gui .GUIManager .MainLoop (node )
46+ Sofa .Gui .GUIManager .MainLoop (root )
4447 Sofa .Gui .GUIManager .closeGUI ()
4548 print ("GUI was closed" )
4649 print ("Simulation is done." )
47- os . remove ( tf . name )
50+
4851
4952# Function used only if this script is called from a python environment
5053if __name__ == '__main__' :
51- main ()
54+ main ()
0 commit comments