From eb6394a1e781b94b24ba0c976f8d1f206eb4e136 Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Wed, 16 Dec 2020 18:12:08 +0100 Subject: [PATCH 1/9] Remove useless scene --- examples/test.scn | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 examples/test.scn diff --git a/examples/test.scn b/examples/test.scn deleted file mode 100644 index f5e9e027..00000000 --- a/examples/test.scn +++ /dev/null @@ -1,3 +0,0 @@ - - - From bfa129aaa644a12b3965a47bd178a0515d367154 Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Wed, 16 Dec 2020 18:13:02 +0100 Subject: [PATCH 2/9] Add new basic scenes showing features: basic, basicGUI --- examples/basic-addGUI.py | 59 ++++++++++++++++++++++++++++++++++++++++ examples/basic.py | 42 ++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 examples/basic-addGUI.py create mode 100644 examples/basic.py diff --git a/examples/basic-addGUI.py b/examples/basic-addGUI.py new file mode 100644 index 00000000..70344b85 --- /dev/null +++ b/examples/basic-addGUI.py @@ -0,0 +1,59 @@ +# Required import for python +import Sofa +import SofaRuntime +import Sofa.Gui + + +USE_GUI = True + + +def main(): + # Make sure to load all SOFA libraries + SofaRuntime.importPlugin("SofaOpenglVisual") + + # Call the above function to create the scene graph + rootNode = createScene(Sofa.Core.Node("root")) + + if not USE_GUI: + Sofa.Simulation.init(rootNode) + for iteration in range(10): + Sofa.Simulation.animate(rootNode, rootNode.dt.value) + else: + # Find out the supported GUIs + print ("Supported GUIs are: " + Sofa.Gui.GUIManager.ListSupportedGUI(",")) + # Launch the GUI + Sofa.Gui.GUIManager.Init("myscene", "qglviewer") + Sofa.Gui.GUIManager.createGUI(rootNode, __file__) + Sofa.Gui.GUIManager.SetDimension(1080, 1080) + # Initialization of the scene will be done here + Sofa.Gui.GUIManager.MainLoop(rootNode) + Sofa.Gui.GUIManager.closeGUI() + print("GUI was closed") + + print("Simulation is done.") + + +# Function called when the scene graph is being created +def createScene(root): + # Scene must now include a VisualLoop + root.addObject('DefaultVisualManagerLoop') + + # 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") + node1.addObject("OglModel") + + node2.addObject("MechanicalObject") + node2.addObject("OglModel") + + return root + + +# Function used only if this script is called from a python environment +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/examples/basic.py b/examples/basic.py new file mode 100644 index 00000000..eb369b2a --- /dev/null +++ b/examples/basic.py @@ -0,0 +1,42 @@ +# Required import for python +import Sofa +import SofaRuntime + + +def main(): + # Make sure to load all SOFA libraries + SofaRuntime.importPlugin("SofaOpenglVisual") + + # Call the above function to create the scene graph + rootNode = createScene(Sofa.Core.Node("root")) + + # Once defined, initialization of the scene graph + Sofa.Simulation.init(rootNode) + + # Run the simulation for 10 steps + for iteration in range(10): + print(f'Iteration #{iteration}') + Sofa.Simulation.animate(rootNode, rootNode.dt.value) + + print("Simulation made 10 time steps. Done") + + +# Function called when the scene graph is being created +def createScene(root): + + # Add new nodes and objects in the scene + node1 = root.addChild("Node1") + node2 = root.addChild("Node2") + + node1.addObject("MechanicalObject", position="0 0 0") + node1.addObject("OglModel") + + node2.addObject("MechanicalObject", position="1 1 1") + node2.addObject("OglModel") + + return root + + +# Function used only if this script is called from a python environment +if __name__ == '__main__': + main() \ No newline at end of file From b8ed982a908ccbd45e6fc921b4eaa5e783f1c1e4 Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Wed, 16 Dec 2020 18:13:25 +0100 Subject: [PATCH 3/9] Remove old example using GUI --- examples/SofaGui.py | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 examples/SofaGui.py diff --git a/examples/SofaGui.py b/examples/SofaGui.py deleted file mode 100644 index 9a63d385..00000000 --- a/examples/SofaGui.py +++ /dev/null @@ -1,21 +0,0 @@ -import Sofa -import Sofa.Core -import Sofa.Simulation -import Sofa.Gui - -print ("Supported GUIs are " + Sofa.Gui.GUIManager.ListSupportedGUI(",")) - - -root = Sofa.Core.Node("root") -# Create the rest of the scene here... - - -# Initialize all components found in the scene -Sofa.Simulation.init(root) - - -# Launch the GUI -Sofa.Gui.GUIManager.Init("simple_scene", "qt") -Sofa.Gui.GUIManager.createGUI(root) -Sofa.Gui.GUIManager.MainLoop(root) -Sofa.Gui.GUIManager.closeGUI() From 3ef762ef5a3565df89383b5a336183b955953ae4 Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Wed, 16 Dec 2020 18:13:55 +0100 Subject: [PATCH 4/9] Renamed --- examples/example.pyscn | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 examples/example.pyscn diff --git a/examples/example.pyscn b/examples/example.pyscn deleted file mode 100644 index 99475184..00000000 --- a/examples/example.pyscn +++ /dev/null @@ -1,16 +0,0 @@ -# coding: utf8 - -import sys -import Sofa - -def createScene(root): - node1 = root.addChild("Node1") - node2 = root.addChild("Node2") - - node1.addObject("MechanicalObject") - node1.addObject("OglModel") - - node2.addObject("MechanicalObject") - node2.addObject("OglModel") - - return root From 8f5836d29cd08d0d48dae2a7aff26b8560fdbb98 Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Wed, 16 Dec 2020 22:24:56 +0100 Subject: [PATCH 5/9] Create a sub directory for additional scenes --- .../ControllerScene.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) rename examples/{ => additional-examples}/ControllerScene.py (88%) diff --git a/examples/ControllerScene.py b/examples/additional-examples/ControllerScene.py similarity index 88% rename from examples/ControllerScene.py rename to examples/additional-examples/ControllerScene.py index db26a1d5..18ebcc83 100755 --- a/examples/ControllerScene.py +++ b/examples/additional-examples/ControllerScene.py @@ -81,6 +81,7 @@ def onKeypressedEvent(self, c): print("You just switch to rotation control ") self.move = 1 + def createScene(root): # rpath =os.environ["SOFA_ROOT"]+"../src/share/mesh/" @@ -91,8 +92,8 @@ def createScene(root): loader = root.addObject('MeshObjLoader', name='loader', filename="mesh/liver.obj") - te = root.addObject( - "TransformEngine", name="te", input_position=loader.position.getLinkPath(), rotation=[0,0,0]) + te = root.addObject("TransformEngine", name="te", + input_position=loader.position.getLinkPath(), rotation=[0,0,0]) mo = root.addObject("MechanicalObject", name="mo", position=te.output_position.getLinkPath()) @@ -100,26 +101,32 @@ def createScene(root): visu.addObject('OglModel', name="visu", src=loader.getLinkPath()) visu.addObject('IdentityMapping', name="BM", src=mo.getLinkPath()) + # If script is loaded by SOFA (runSofa), this script must be added as a controller if not _runAsPythonScript: root.addObject(RotationController(name="MyController", engine=root.te)) def main(): - # can be executed from terminal directly: - - # Register all the common component in the factory. + # Load the required plugins SofaRuntime.importPlugin("SofaOpenglVisual") + SofaRuntime.importPlugin("SofaGeneralEngine") + + # Check and save if the script is called from python environment global _runAsPythonScript _runAsPythonScript = True - root = Sofa.Core.Node() + # Create and initialize the scene + root = Sofa.Core.Node() createScene(root) Sofa.Simulation.init(root) + + # Run simulation for i in range(0, 360): Sofa.Simulation.animate(root, root.dt.value) root.te.rotation[0] += 1 - #print("For i = "+ str(i)+", we have : "+str(root.te.rotation.value[0])) + print("Last value is : "+ str(root.te.rotation.value[0])) + if __name__ == '__main__': main() From 28c97d15135a2eeef79fad39c410ad67965f6b63 Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Wed, 16 Dec 2020 22:26:43 +0100 Subject: [PATCH 6/9] Update templates for Controller, FF, DataEngine --- examples/emptyController.py | 98 +++++++++++++++++++++++++++++++------ examples/emptyDataEngine.py | 41 +++++++++++++--- examples/emptyForceField.py | 57 ++++++++++++++++++--- 3 files changed, 166 insertions(+), 30 deletions(-) diff --git a/examples/emptyController.py b/examples/emptyController.py index 03670eb8..e3dcd1c4 100644 --- a/examples/emptyController.py +++ b/examples/emptyController.py @@ -1,44 +1,110 @@ -import Sofa.Core +import Sofa +import Sofa.Gui + +# This python script shows the functions to be implemented +# in order to create your Controller in python class EmptyController(Sofa.Core.Controller): - """ custom %EmptyController% component for SOFA """ def __init__(self, *args, **kwargs): + # These are needed (and the normal way to override from a python class) Sofa.Core.Controller.__init__(self, *args, **kwargs) + + # Default BaseObject functions******************************** + def init(self): pass - def init(): + def bwdInit(): pass def reinit(): pass - # DEFAULT EVENTS: - def onAnimateBeginEvent(self, event): - """ called at the beginning of each time step """ + # Default Events ********************************************* + def onAnimateBeginEvent(self, event): # called at each begin of animation step pass - def onAnimateEndEvent(self, event): - """ called at the end of each time step """ + def onAnimateEndEvent(self, event): # called at each end of animation step pass def onKeypressedEvent(self, event): - """ called when a key release event is triggered from the UI """ - pass + key = event['key'] + if ord(key) == 19: # up + print("You pressed the Up key") + + if ord(key) == 21: # down + print("You pressed the Down key") + + if ord(key) == 18: # left + print("You pressed the Left key") + + if ord(key) == 20: # right + print("You pressed the Right key") def onKeyreleasedEvent(self, event): - """ called when a key release event is triggered from the UI """ - pass + key = event['key'] + if ord(key) == 19: # up + print("You released the Up key") + + if ord(key) == 21: # down + print("You released the Down key") + + if ord(key) == 18: # left + print("You released the Left key") + + if ord(key) == 20: # right + print("You released the Right key") def onMouseEvent(self, event): - """ called when a mouse event is triggered from the UI """ - pass + if (event['State']== 0): # mouse moving + print("Mouse is moving (x,y) = "+str(event['mouseX'])+" , "+str(event['mouseY'])) + + if (event['State']==1): # left mouse clicked + print("Left mouse clicked") + + if (event['State']==2): # left mouse released + print("Left mouse released") + + if (event['State']==3): # right mouse released + print("Right mouse clicked") + + if (event['State']==4): # right mouse released + print("Right mouse released") + + if (event['State']==5): # wheel clicked + print("Mouse wheel clicked") + + if (event['State']==6): # wheel released + print("Mouse wheel released") def onScriptEvent(self, event): - """ catches events sent from other python scripts """ pass def onEvent(self, event): - """ generic method called when no script method exists for the sent event """ pass + +def createScene(root): + root.dt = 0.01 + root.addObject('DefaultVisualManagerLoop') + root.addObject('DefaultAnimationLoop') + + # Add our python controller in the scene + root.addObject( EmptyController(name="MyEmptyController") ) + + +def main(): + root=Sofa.Core.Node("root") + createScene(root) + + Sofa.Gui.GUIManager.Init("myscene", "qglviewer") + Sofa.Gui.GUIManager.createGUI(root, __file__) + Sofa.Gui.GUIManager.SetDimension(1080, 1080) + Sofa.Gui.GUIManager.MainLoop(root) + Sofa.Gui.GUIManager.closeGUI() + + print("End of simulation.") + + +if __name__ == '__main__': + main() diff --git a/examples/emptyDataEngine.py b/examples/emptyDataEngine.py index d822cfc0..5b43f0fe 100644 --- a/examples/emptyDataEngine.py +++ b/examples/emptyDataEngine.py @@ -1,22 +1,47 @@ -import Sofa.Core +import Sofa +import Sofa.Gui from Sofa.Helper import msg_info +# This python script shows the functions to be implemented +# in order to create your DataEngine in python class EmptyDataEngine(Sofa.Core.DataEngine): - """ custom %EmptyDataEngine% component for SOFA """ def __init__(self, *args, **kwargs): Sofa.Core.DataEngine.__init__(self, *args, **kwargs) pass - def init(): + def init(self): pass def update(): - """ - called anytime an output is accessed while the component - is dirty (input has changed) - """ + # Function called anytime an output is accessed while the component + # is dirty (input has changed) msg_info('Not implemented yet') pass - + + +def createScene(root): + root.dt = 0.01 + root.addObject('DefaultVisualManagerLoop') + + # Add our python forcefield in the scene + root.addObject( EmptyDataEngine(name="MyEmptyDataEngine") ) + + +def main(): + root=Sofa.Core.Node("root") + createScene(root) + Sofa.Simulation.init(root) + + Sofa.Gui.GUIManager.Init("myscene", "qglviewer") + Sofa.Gui.GUIManager.createGUI(root, __file__) + Sofa.Gui.GUIManager.SetDimension(1080, 1080) + Sofa.Gui.GUIManager.MainLoop(root) + Sofa.Gui.GUIManager.closeGUI() + + print("End of simulation.") + + +if __name__ == '__main__': + main() diff --git a/examples/emptyForceField.py b/examples/emptyForceField.py index 9362933a..f033fcc2 100644 --- a/examples/emptyForceField.py +++ b/examples/emptyForceField.py @@ -1,24 +1,69 @@ -import Sofa.Core -import numpy as np +import Sofa +import Sofa.Gui from Sofa.Helper import msg_info +import numpy as np -class EmptyForcefield(Sofa.Core.ForceField): + +# This python script shows the functions to be implemented +# in order to create your ForceField in python +class EmptyForceField(Sofa.Core.ForceField): def __init__(self, *args, **kwargs): Sofa.Core.ForceField.__init__(self, *args, **kwargs) pass + # Function called at the component initialization def init(self): + msg_info('init: not implemented yet') pass + # Function implementing the explicit force f(x(t), v(t)) def addForce(self, m, forces, pos, vel): - msg_info('Not implemented yet') + msg_info('addForce: not implemented yet') pass + # Function implementing the matrix-vector multiplication + # between the derivative of the force f with regards to + # the degrees of freedom, multiplied by a vector dx def addDForce(self, m, dforce, dx): - msg_info('Not implemented yet') + msg_info('addDForce: not implemented yet') pass + # Function implementing the matrix corresponding to the + # derivative of the force f with regards to the degrees + # of freedom def addKToMatrix(self, mparams, nNodes, nDofs): - msg_info('Not implemented yet') + msg_info('addKToMatrix: not implemented yet') pass + +def createScene(root): + root.dt = 0.01 + root.addObject('DefaultVisualManagerLoop') + root.addObject('DefaultAnimationLoop') + + node1 = root.addChild("Node1") + + node1.addObject('EulerImplicitSolver') + node1.addObject('CGLinearSolver', iterations="100", tolerance="10-3", threshold="10-3") + node1.addObject('MechanicalObject', template="Vec3d") + + # Add our python forcefield in the scene + node1.addObject( EmptyForceField(name="MyEmptyForceField") ) + + +def main(): + root=Sofa.Core.Node("root") + createScene(root) + Sofa.Simulation.init(root) + + Sofa.Gui.GUIManager.Init("myscene", "qglviewer") + Sofa.Gui.GUIManager.createGUI(root, __file__) + Sofa.Gui.GUIManager.SetDimension(1080, 1080) + Sofa.Gui.GUIManager.MainLoop(root) + Sofa.Gui.GUIManager.closeGUI() + + print("End of simulation.") + + +if __name__ == '__main__': + main() From 8717e39ed52ca897ca99546aa69e24b9a79a829b Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Wed, 16 Dec 2020 22:27:00 +0100 Subject: [PATCH 7/9] Minor changes and indentation --- examples/BaseCamera.py | 2 +- examples/basic-addGUI.py | 83 +++++++++++++++++++++------------------- examples/basic.py | 47 ++++++++++++----------- 3 files changed, 68 insertions(+), 64 deletions(-) diff --git a/examples/BaseCamera.py b/examples/BaseCamera.py index 88f0b402..e2ac348c 100644 --- a/examples/BaseCamera.py +++ b/examples/BaseCamera.py @@ -78,7 +78,7 @@ def Sphere(rootNode, name, position, color): #### Visualization of the sphere sphereVisu = sphere.addChild("VisualModel") sphereVisu.loader = sphereVisu.addObject('MeshObjLoader', name="loader", - filename="mesh/ball.obj", scale=0.5) + filename="mesh/ball.obj", scale=0.5) sphereVisu.addObject('OglModel', name="model", src="@loader", color=color) sphereVisu.addObject('RigidMapping') return sphere diff --git a/examples/basic-addGUI.py b/examples/basic-addGUI.py index 70344b85..b7df9bb5 100644 --- a/examples/basic-addGUI.py +++ b/examples/basic-addGUI.py @@ -4,54 +4,57 @@ import Sofa.Gui +# Choose in your script to activate or not the GUI USE_GUI = True def main(): - # Make sure to load all SOFA libraries - SofaRuntime.importPlugin("SofaOpenglVisual") - - # Call the above function to create the scene graph - rootNode = createScene(Sofa.Core.Node("root")) - - if not USE_GUI: - Sofa.Simulation.init(rootNode) - for iteration in range(10): - Sofa.Simulation.animate(rootNode, rootNode.dt.value) - else: - # Find out the supported GUIs - print ("Supported GUIs are: " + Sofa.Gui.GUIManager.ListSupportedGUI(",")) - # Launch the GUI - Sofa.Gui.GUIManager.Init("myscene", "qglviewer") - Sofa.Gui.GUIManager.createGUI(rootNode, __file__) - Sofa.Gui.GUIManager.SetDimension(1080, 1080) - # Initialization of the scene will be done here - Sofa.Gui.GUIManager.MainLoop(rootNode) - Sofa.Gui.GUIManager.closeGUI() - print("GUI was closed") - - print("Simulation is done.") + # Make sure to load all SOFA libraries + SofaRuntime.importPlugin("SofaOpenglVisual") + + #Create the root node + root = Sofa.Core.Node("root") + # Call the below 'createScene' function to create the scene graph + createScene(root) + Sofa.Simulation.init(root) + + if not USE_GUI: + for iteration in range(10): + Sofa.Simulation.animate(root, root.dt.value) + else: + # 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 called when the scene graph is being created def createScene(root): - # Scene must now include a VisualLoop - root.addObject('DefaultVisualManagerLoop') - - # 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") - node1.addObject("OglModel") - - node2.addObject("MechanicalObject") - node2.addObject("OglModel") - - return root + # Scene must now include a VisualLoop + root.addObject('DefaultVisualManagerLoop') + + # 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") + node1.addObject("OglModel") + + node2.addObject("MechanicalObject") + node2.addObject("OglModel") + + return root # Function used only if this script is called from a python environment diff --git a/examples/basic.py b/examples/basic.py index eb369b2a..f27ad13e 100644 --- a/examples/basic.py +++ b/examples/basic.py @@ -4,37 +4,38 @@ def main(): - # Make sure to load all SOFA libraries - SofaRuntime.importPlugin("SofaOpenglVisual") - - # Call the above function to create the scene graph - rootNode = createScene(Sofa.Core.Node("root")) + # Make sure to load all SOFA libraries + SofaRuntime.importPlugin("SofaOpenglVisual") + + # 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.init(rootNode) + # Once defined, initialization of the scene graph + Sofa.Simulation.init(root) - # Run the simulation for 10 steps - for iteration in range(10): - print(f'Iteration #{iteration}') - Sofa.Simulation.animate(rootNode, rootNode.dt.value) + # 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") + print("Simulation made 10 time steps. Done") # Function called when the scene graph is being created def createScene(root): - # Add new nodes and objects in the scene - node1 = root.addChild("Node1") - node2 = root.addChild("Node2") - - node1.addObject("MechanicalObject", position="0 0 0") - node1.addObject("OglModel") - - node2.addObject("MechanicalObject", position="1 1 1") - node2.addObject("OglModel") - - return root + # Add new nodes and objects in the scene + node1 = root.addChild("Node1") + node2 = root.addChild("Node2") + + node1.addObject("MechanicalObject", position="0 0 0") + node1.addObject("OglModel") + + node2.addObject("MechanicalObject", position="1 1 1") + node2.addObject("OglModel") + + return root # Function used only if this script is called from a python environment From 3d905d6b7d2bce25259a4c61ef5cf21a909f0404 Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Wed, 16 Dec 2020 22:27:27 +0100 Subject: [PATCH 8/9] Add the liver scene to compare with existing XML in SOFA --- examples/liver.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 examples/liver.py diff --git a/examples/liver.py b/examples/liver.py new file mode 100644 index 00000000..97ac43fe --- /dev/null +++ b/examples/liver.py @@ -0,0 +1,71 @@ +# Required import for python +import Sofa +import SofaRuntime +import Sofa.Gui + + +# Choose in your script to activate or not the GUI +USE_GUI = True + + +def main(): + SofaRuntime.importPlugin("SofaOpenglVisual") + + root = Sofa.Core.Node("root") + createScene(root) + Sofa.Simulation.init(root) + + if not USE_GUI: + for iteration in range(10): + Sofa.Simulation.animate(root, root.dt.value) + else: + Sofa.Gui.GUIManager.Init("myscene", "qglviewer") + Sofa.Gui.GUIManager.createGUI(root, __file__) + Sofa.Gui.GUIManager.SetDimension(1080, 1080) + Sofa.Gui.GUIManager.MainLoop(root) + Sofa.Gui.GUIManager.closeGUI() + + +def createScene(root): + root.gravity=[0, -9.81, 0] + root.dt=0.02 + + root.addObject('DefaultVisualManagerLoop') + root.addObject('DefaultAnimationLoop') + + root.addObject('VisualStyle', displayFlags="showCollisionModels") + root.addObject('RequiredPlugin', pluginName="SofaOpenglVisual SofaBoundaryCondition SofaGeneralLoader SofaGeneralSimpleFem") + root.addObject('DefaultPipeline', name="CollisionPipeline") + root.addObject('BruteForceDetection', name="N2") + root.addObject('DefaultContactManager', name="CollisionResponse", response="default") + root.addObject('DiscreteIntersection') + + root.addObject('MeshObjLoader', name="LiverSurface", filename="mesh/liver-smooth.obj") + + liver = root.addChild('Liver') + liver.addObject('EulerImplicitSolver', name="cg_odesolver", rayleighStiffness="0.1", rayleighMass="0.1") + liver.addObject('CGLinearSolver', name="linear_solver", iterations="25", tolerance="1e-09", threshold="1e-09") + liver.addObject('MeshGmshLoader', name="meshLoader", filename="mesh/liver.msh") + liver.addObject('TetrahedronSetTopologyContainer', name="topo", src="@meshLoader") + liver.addObject('MechanicalObject', name="dofs", src="@meshLoader") + liver.addObject('TetrahedronSetGeometryAlgorithms', template="Vec3d", name="GeomAlgo") + liver.addObject('DiagonalMass', name="Mass", massDensity="1.0") + liver.addObject('TetrahedralCorotationalFEMForceField', template="Vec3d", name="FEM", method="large", poissonRatio="0.3", youngModulus="3000", computeGlobalMatrix="0") + liver.addObject('FixedConstraint', name="FixedConstraint", indices="3 39 64") + + visu = liver.addChild('Visu') + visu.addObject('OglModel', name="VisualModel", src="@../../LiverSurface") + visu.addObject('BarycentricMapping', name="VisualMapping", input="@../dofs", output="@VisualModel") + + surf = liver.addChild('Surf') + surf.addObject('SphereLoader', name="sphereLoader", filename="mesh/liver.sph") + surf.addObject('MechanicalObject', name="spheres", position="@sphereLoader.position") + surf.addObject('SphereCollisionModel', name="CollisionModel", listRadius="@sphereLoader.listRadius") + surf.addObject('BarycentricMapping', name="CollisionMapping", input="@../dofs", output="@spheres") + + return root + + +# Function used only if this script is called from a python environment +if __name__ == '__main__': + main() \ No newline at end of file From 6ba3ef57675840385fe7729b69d505d0b6699eb8 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Fri, 18 Dec 2020 14:54:56 +0100 Subject: [PATCH 9/9] Update CMakeLists for examples repo --- examples/CMakeLists.txt | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 8161aff2..3f444712 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,25 +1,24 @@ project(Examples) set(EXAMPLES_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/BaseCamera.py ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt - ${CMAKE_CURRENT_SOURCE_DIR}/ControllerScene.py - ${CMAKE_CURRENT_SOURCE_DIR}/easingSceneMatplotlib.py - ${CMAKE_CURRENT_SOURCE_DIR}/easingScene.py + ${CMAKE_CURRENT_SOURCE_DIR}/basic.py + ${CMAKE_CURRENT_SOURCE_DIR}/basic-addGUI.py ${CMAKE_CURRENT_SOURCE_DIR}/emptyController.py ${CMAKE_CURRENT_SOURCE_DIR}/emptyDataEngine.py ${CMAKE_CURRENT_SOURCE_DIR}/emptyForceField.py ${CMAKE_CURRENT_SOURCE_DIR}/example-forcefield2.py ${CMAKE_CURRENT_SOURCE_DIR}/example-forcefield.py - ${CMAKE_CURRENT_SOURCE_DIR}/example.pyscn ${CMAKE_CURRENT_SOURCE_DIR}/example-scriptcontroller.py + ${CMAKE_CURRENT_SOURCE_DIR}/BaseCamera.py + ${CMAKE_CURRENT_SOURCE_DIR}/easingSceneMatplotlib.py + ${CMAKE_CURRENT_SOURCE_DIR}/easingScene.py ${CMAKE_CURRENT_SOURCE_DIR}/keyEvents.py + ${CMAKE_CURRENT_SOURCE_DIR}/realTimeClockScene.py + ${CMAKE_CURRENT_SOURCE_DIR}/ReadTheDocs_Example.py ${CMAKE_CURRENT_SOURCE_DIR}/pygame_renderingloop/backend_pygame.py ${CMAKE_CURRENT_SOURCE_DIR}/pygame_renderingloop/pygame_test.py - ${CMAKE_CURRENT_SOURCE_DIR}/ReadTheDocs_Example.py - ${CMAKE_CURRENT_SOURCE_DIR}/realTimeClockScene.py - ${CMAKE_CURRENT_SOURCE_DIR}/SofaGui.py - ${CMAKE_CURRENT_SOURCE_DIR}/test.scn + ${CMAKE_CURRENT_SOURCE_DIR}/additional-examples/ControllerScene.py ) add_custom_target(${PROJECT_NAME} SOURCES ${EXAMPLES_FILES})