Skip to content

Commit 4f8fd50

Browse files
committed
[Examples] Fix scenes before the release
Signed-off-by: Jean-Nicolas Brunet <[email protected]>
1 parent 11a8c6f commit 4f8fd50

10 files changed

Lines changed: 42 additions & 119 deletions

examples/CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@ project(Examples)
22

33
set(EXAMPLES_FILES
44
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
5+
${CMAKE_CURRENT_SOURCE_DIR}/advanced_timer.py
6+
${CMAKE_CURRENT_SOURCE_DIR}/BaseCamera.py
57
${CMAKE_CURRENT_SOURCE_DIR}/basic.py
68
${CMAKE_CURRENT_SOURCE_DIR}/basic-addGUI.py
9+
${CMAKE_CURRENT_SOURCE_DIR}/easingScene.py
10+
${CMAKE_CURRENT_SOURCE_DIR}/easingSceneMatplotlib.py
711
${CMAKE_CURRENT_SOURCE_DIR}/emptyController.py
812
${CMAKE_CURRENT_SOURCE_DIR}/emptyDataEngine.py
913
${CMAKE_CURRENT_SOURCE_DIR}/emptyForceField.py
10-
${CMAKE_CURRENT_SOURCE_DIR}/example-forcefield2.py
1114
${CMAKE_CURRENT_SOURCE_DIR}/example-forcefield.py
1215
${CMAKE_CURRENT_SOURCE_DIR}/example-scriptcontroller.py
13-
${CMAKE_CURRENT_SOURCE_DIR}/BaseCamera.py
14-
${CMAKE_CURRENT_SOURCE_DIR}/easingSceneMatplotlib.py
15-
${CMAKE_CURRENT_SOURCE_DIR}/easingScene.py
1616
${CMAKE_CURRENT_SOURCE_DIR}/keyEvents.py
17-
${CMAKE_CURRENT_SOURCE_DIR}/realTimeClockScene.py
17+
${CMAKE_CURRENT_SOURCE_DIR}/liver.py
18+
${CMAKE_CURRENT_SOURCE_DIR}/loadXMLfromPython.py
1819
${CMAKE_CURRENT_SOURCE_DIR}/ReadTheDocs_Example.py
20+
${CMAKE_CURRENT_SOURCE_DIR}/realTimeClockScene.py
1921
${CMAKE_CURRENT_SOURCE_DIR}/pygame_renderingloop/backend_pygame.py
2022
${CMAKE_CURRENT_SOURCE_DIR}/pygame_renderingloop/pygame_test.py
2123
${CMAKE_CURRENT_SOURCE_DIR}/additional-examples/ControllerScene.py

examples/advanced_timer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def createScene(root):
4343
root.dt = 0.01
4444

4545
# List of required plugins
46+
root.addObject('RequiredPlugin', name='SofaBaseMechanics')
4647
root.addObject('RequiredPlugin', name='SofaSparseSolver')
4748
root.addObject('RequiredPlugin', name='SofaGraphComponent')
4849
root.addObject('RequiredPlugin', name='SofaOpenglVisual')

examples/basic-addGUI.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Required import for python
22
import Sofa
3-
import SofaRuntime
4-
import Sofa.Gui
53

64

75
# Choose in your script to activate or not the GUI
86
USE_GUI = True
97

108

119
def main():
10+
import SofaRuntime
11+
import Sofa.Gui
1212
# Make sure to load all SOFA libraries
1313
SofaRuntime.importPlugin("SofaBaseMechanics")
1414
SofaRuntime.importPlugin("SofaOpenglVisual")

examples/emptyController.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Sofa
2-
import Sofa.Gui
32

43

54
# This python script shows the functions to be implemented
@@ -94,6 +93,8 @@ def createScene(root):
9493

9594

9695
def main():
96+
import SofaRuntime
97+
import Sofa.Gui
9798
SofaRuntime.importPlugin("SofaOpenglVisual")
9899
root=Sofa.Core.Node("root")
99100
createScene(root)

examples/emptyDataEngine.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Sofa
2-
import Sofa.Gui
32
from Sofa.Helper import msg_info
43

54

@@ -30,6 +29,8 @@ def createScene(root):
3029

3130

3231
def main():
32+
import Sofa.Gui
33+
import SofaRuntime
3334
SofaRuntime.importPlugin("SofaOpenglVisual")
3435
root=Sofa.Core.Node("root")
3536
createScene(root)

examples/emptyForceField.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import Sofa
2-
import SofaRuntime
3-
import Sofa.Gui
42
from Sofa.Helper import msg_info
53
import numpy as np
64

@@ -53,6 +51,8 @@ def createScene(root):
5351

5452

5553
def main():
54+
import SofaRuntime
55+
import Sofa.Gui
5656
SofaRuntime.importPlugin("SofaOpenglVisual")
5757
SofaRuntime.importPlugin("SofaImplicitOdeSolver")
5858

examples/example-forcefield.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
"""Implementation of a RestShapeForceField in python"""
22
# coding: utf8
33
import Sofa
4-
import SofaRuntime
5-
import Sofa.Gui
64
import numpy as np
75

6+
87
class RestShapeForceField(Sofa.Core.ForceField):
98
"""Implementation of a RestShapeForceField in python"""
109
def __init__(self, ks=1.0, kd=1.0, *args, **kwargs):
@@ -30,6 +29,7 @@ def addDForce(self, df, dx, params):
3029
#def addKToMatrix(self, a, b):
3130
# print(" Python::addKToMatrix: ", a, " ", b)
3231

32+
3333
def createScene(node):
3434
node.addObject("RequiredPlugin", name="SofaOpenglVisual")
3535
node.addObject("RequiredPlugin", name="SofaSparseSolver")
@@ -49,7 +49,10 @@ def createScene(node):
4949

5050
return node
5151

52+
5253
def main():
54+
import SofaRuntime
55+
import Sofa.Gui
5356
SofaRuntime.importPlugin("SofaOpenglVisual")
5457
SofaRuntime.importPlugin("SofaBaseMechanics")
5558
SofaRuntime.importPlugin("SofaImplicitOdeSolver")

examples/example-forcefield2.py

Lines changed: 0 additions & 88 deletions
This file was deleted.

examples/liver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Required import for python
22
import Sofa
3-
import SofaRuntime
4-
import Sofa.Gui
53

64

75
# Choose in your script to activate or not the GUI
86
USE_GUI = True
97

108

119
def main():
10+
import SofaRuntime
11+
import Sofa.Gui
1212
SofaRuntime.importPlugin("SofaOpenglVisual")
1313
SofaRuntime.importPlugin("SofaImplicitOdeSolver")
1414

examples/loadXMLfromPython.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
import Sofa
2-
import Sofa.Gui
3-
import SofaRuntime
42
import tempfile
53
import 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
5053
if __name__ == '__main__':
51-
main()
54+
main()

0 commit comments

Comments
 (0)