From 9e05bfe2a20980be00e2aec4e70a6b249bb45624 Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Fri, 2 Sep 2022 09:50:59 +0200 Subject: [PATCH 1/2] [examples] Update all plugins and remove DefaultVisualManagerLoop --- examples/access_compliance_matrix.py | 8 +++++--- examples/access_mass_matrix.py | 10 ++++++++++ examples/access_matrix.py | 14 +++++++++----- examples/access_stiffness_matrix.py | 10 ++++++++++ examples/basic-addGUI.py | 6 +----- examples/basic.py | 3 +++ examples/emptyController.py | 1 - examples/emptyDataEngine.py | 5 +++-- examples/emptyForceField.py | 5 ++++- examples/example-forcefield.py | 17 ++++++++++------- examples/liver-scriptcontroller.py | 25 +++++++++++++++++++++---- examples/liver.py | 20 +++++++++++++++++--- examples/loadXMLfromPython.py | 5 ++--- examples/springForceField.py | 7 ++++++- 14 files changed, 101 insertions(+), 35 deletions(-) diff --git a/examples/access_compliance_matrix.py b/examples/access_compliance_matrix.py index bca17705..b10ff8f6 100644 --- a/examples/access_compliance_matrix.py +++ b/examples/access_compliance_matrix.py @@ -17,7 +17,9 @@ def createScene(root): "Sofa.Component.Mapping.MappedMatrix", "Sofa.Component.Mass", "Sofa.Component.ODESolver.Backward", - "Sofa.Component.Topology.Container.Dynamic"]) + "Sofa.Component.Topology.Container.Dynamic", + "Sofa.Component.Mapping.NonLinear", + "Sofa.Component.StateContainer"]) root.addObject("FreeMotionAnimationLoop", solveVelocityConstraintFirst=True) constraint_solver = root.addObject("GenericConstraintSolver", tolerance=1e-9, maxIterations=1000) @@ -27,7 +29,7 @@ def createScene(root): root.addObject("SparseCholeskySolver") root.addObject("GenericConstraintCorrection") - root.addObject("EdgeSetTopologyContainer", position="@loader.position", edges="@loader.edges") + root.addObject("EdgeSetTopologyContainer", name="topo", position="@loader.position", edges="@loader.edges") root.addObject("MechanicalObject", name="defoDOF", template="Vec3d") root.addObject("EdgeSetGeometryAlgorithms", drawEdges=True) root.addObject("FixedConstraint", indices=[0]) @@ -36,7 +38,7 @@ def createScene(root): ext = root.addChild("extensionsNode") ext.addObject("MechanicalObject", template="Vec1d", name="extensionsDOF") - ext.addObject("DistanceMapping", name="distanceMapping") + ext.addObject("DistanceMapping", name="distanceMapping", topology="@../topo") ext.addObject("UniformConstraint", template="Vec1d", iterative=True) root.addObject(MatrixAccessController('MatrixAccessor', name='matrixAccessor', constraint_solver=constraint_solver)) diff --git a/examples/access_mass_matrix.py b/examples/access_mass_matrix.py index d5dbe1f2..0aae0a32 100644 --- a/examples/access_mass_matrix.py +++ b/examples/access_mass_matrix.py @@ -20,6 +20,16 @@ def createScene(root): root.addObject('EulerImplicitSolver', rayleighStiffness="0.1", rayleighMass="0.1") root.addObject('SparseLDLSolver', applyPermutation="false", template="CompressedRowSparseMatrixd") + root.addObject('RequiredPlugin', pluginName=["Sofa.Component.Constraint.Projective", + "Sofa.Component.Engine.Select", + "Sofa.Component.ODESolver.Backward", + "Sofa.Component.LinearSolver.Direct", + "Sofa.Component.SolidMechanics.FEM.Elastic", + "Sofa.Component.Mass", + "Sofa.Component.StateContainer", + "Sofa.Component.Topology.Container.Grid", + "Sofa.Component.Visual"]) + root.addObject('MechanicalObject', name="DoFs") mass = root.addObject('MeshMatrixMass', name="mass", totalMass="320") root.addObject('RegularGridTopology', name="grid", nx="4", ny="4", nz="20", xmin="-9", xmax="-6", ymin="0", ymax="3", zmin="0", zmax="19") diff --git a/examples/access_matrix.py b/examples/access_matrix.py index 48ec6273..1fba1196 100644 --- a/examples/access_matrix.py +++ b/examples/access_matrix.py @@ -12,11 +12,15 @@ def createScene(root): root.addObject('DefaultAnimationLoop') root.addObject('DefaultVisualManagerLoop') - root.addObject('RequiredPlugin', name='Sofa.Component.ODESolver.Backward') - root.addObject('RequiredPlugin', name='Sofa.Component.LinearSolver.Direct') - root.addObject('RequiredPlugin', name='Sofa.Component.Engine.Select') - root.addObject('RequiredPlugin', name='Sofa.Component.Constraint.Projective') - root.addObject('RequiredPlugin', name='Sofa.Component.SolidMechanics.FEM.Elastic') + root.addObject('RequiredPlugin', pluginName=["Sofa.Component.Constraint.Projective", + "Sofa.Component.Engine.Select", + "Sofa.Component.ODESolver.Backward", + "Sofa.Component.LinearSolver.Direct", + "Sofa.Component.SolidMechanics.FEM.Elastic", + "Sofa.Component.Mass", + "Sofa.Component.StateContainer", + "Sofa.Component.Topology.Container.Grid", + "Sofa.Component.Visual"]) root.addObject('EulerImplicitSolver', rayleighStiffness="0.1", rayleighMass="0.1") linear_solver = root.addObject('SparseLDLSolver', applyPermutation="false", template="CompressedRowSparseMatrixMat3x3d") diff --git a/examples/access_stiffness_matrix.py b/examples/access_stiffness_matrix.py index 15063fb5..90188caa 100644 --- a/examples/access_stiffness_matrix.py +++ b/examples/access_stiffness_matrix.py @@ -17,6 +17,16 @@ def createScene(root): root.addObject('DefaultAnimationLoop') root.addObject('DefaultVisualManagerLoop') + root.addObject('RequiredPlugin', pluginName=["Sofa.Component.Constraint.Projective", + "Sofa.Component.Engine.Select", + "Sofa.Component.ODESolver.Backward", + "Sofa.Component.LinearSolver.Direct", + "Sofa.Component.SolidMechanics.FEM.Elastic", + "Sofa.Component.Mass", + "Sofa.Component.StateContainer", + "Sofa.Component.Topology.Container.Grid", + "Sofa.Component.Visual"]) + root.addObject('EulerImplicitSolver', rayleighStiffness="0.1", rayleighMass="0.1") root.addObject('SparseLDLSolver', applyPermutation="false", template="CompressedRowSparseMatrixd") diff --git a/examples/basic-addGUI.py b/examples/basic-addGUI.py index 1f3f135f..d8fa2cc1 100644 --- a/examples/basic-addGUI.py +++ b/examples/basic-addGUI.py @@ -9,9 +9,6 @@ def main(): import SofaRuntime import Sofa.Gui - # Make sure to load all SOFA libraries - SofaRuntime.importPlugin("Sofa.Component.StateContainer") - SofaRuntime.importPlugin("SofaOpenglVisual") #Create the root node root = Sofa.Core.Node("root") @@ -39,8 +36,7 @@ def main(): # Function called when the scene graph is being created def createScene(root): - # Scene must now include a VisualLoop - root.addObject('DefaultVisualManagerLoop') + root.addObject("RequiredPlugin", pluginName=["Sofa.Component.StateContainer"]) # Scene must now include a AnimationLoop root.addObject('DefaultAnimationLoop') diff --git a/examples/basic.py b/examples/basic.py index a79c0759..26f65313 100644 --- a/examples/basic.py +++ b/examples/basic.py @@ -29,6 +29,9 @@ def createScene(root): node1 = root.addChild("Node1") node2 = root.addChild("Node2") + root.addObject("RequiredPlugin", pluginName=["Sofa.Component.StateContainer"]) + root.addObject('DefaultAnimationLoop') + 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") diff --git a/examples/emptyController.py b/examples/emptyController.py index 6aacb575..99dfc5f6 100644 --- a/examples/emptyController.py +++ b/examples/emptyController.py @@ -95,7 +95,6 @@ def createScene(root): def main(): import SofaRuntime import Sofa.Gui - SofaRuntime.importPlugin("SofaOpenglVisual") root=Sofa.Core.Node("root") createScene(root) diff --git a/examples/emptyDataEngine.py b/examples/emptyDataEngine.py index 6ed465f6..fedf3e7f 100644 --- a/examples/emptyDataEngine.py +++ b/examples/emptyDataEngine.py @@ -22,7 +22,9 @@ def update(): def createScene(root): root.dt = 0.01 - root.addObject('DefaultVisualManagerLoop') + root.bbox = [[0, 0, 0],[1,1,1]] + + root.addObject('DefaultAnimationLoop') # Add our python forcefield in the scene root.addObject( EmptyDataEngine(name="MyEmptyDataEngine") ) @@ -31,7 +33,6 @@ def createScene(root): def main(): import Sofa.Gui import SofaRuntime - SofaRuntime.importPlugin("SofaOpenglVisual") root=Sofa.Core.Node("root") createScene(root) Sofa.Simulation.init(root) diff --git a/examples/emptyForceField.py b/examples/emptyForceField.py index b19ba7bf..301f7125 100644 --- a/examples/emptyForceField.py +++ b/examples/emptyForceField.py @@ -37,7 +37,10 @@ def addKToMatrix(self, mparams, nNodes, nDofs): def createScene(root): root.dt = 0.01 - root.addObject('DefaultVisualManagerLoop') + root.bbox = [[0, 0, 0],[1,1,1]] + + root.addObject("RequiredPlugin", pluginName=["Sofa.Component.LinearSolver.Iterative", "Sofa.Component.ODESolver.Backward", + "Sofa.Component.StateContainer"]) root.addObject('DefaultAnimationLoop') node1 = root.addChild("Node1") diff --git a/examples/example-forcefield.py b/examples/example-forcefield.py index 4d5b07a9..5bd3c684 100644 --- a/examples/example-forcefield.py +++ b/examples/example-forcefield.py @@ -30,10 +30,16 @@ def addDForce(self, df, dx, params): def createScene(node): - node.addObject("RequiredPlugin", name="Sofa.GL.Component") - node.addObject("RequiredPlugin", name="Sofa.Component.LinearSolver.Direct") - node.addObject("RequiredPlugin", name="Sofa.Component.ODESolver.Backward") - node.addObject("OglLineAxis") + node.addObject("RequiredPlugin", pluginName=["Sofa.GL.Component", + "Sofa.Component.LinearSolver.Direct", + "Sofa.Component.LinearSolver.Iterative", + "Sofa.Component.ODESolver.Backward", + "Sofa.Component.LinearSolver.Iterative", + "Sofa.Component.Mass", + "Sofa.Component.StateContainer", + "Sofa.Component.Visual"]) + + node.addObject("LineAxis") node.addObject("DefaultAnimationLoop", name="loop") node.addObject("EulerImplicitSolver") node.addObject("CGLinearSolver", tolerance=1e-12, threshold=1e-12, iterations=25) @@ -53,9 +59,6 @@ def createScene(node): def main(): import SofaRuntime import Sofa.Gui - SofaRuntime.importPlugin("SofaOpenglVisual") - SofaRuntime.importPlugin("Sofa.Component.StateContainer") - SofaRuntime.importPlugin("SofaImplicitOdeSolver") root=Sofa.Core.Node("root") createScene(root) diff --git a/examples/liver-scriptcontroller.py b/examples/liver-scriptcontroller.py index 3aedf399..54df7516 100644 --- a/examples/liver-scriptcontroller.py +++ b/examples/liver-scriptcontroller.py @@ -29,17 +29,34 @@ def createScene(root): root.gravity=[0, -9.81, 0] root.dt=0.02 - root.addObject('DefaultVisualManagerLoop') + root.addObject("RequiredPlugin", pluginName=["Sofa.Component.Collision.Detection.Intersection", + "Sofa.Component.Collision.Detection.Algorithm", + "Sofa.Component.AnimationLoop", + "Sofa.Component.Collision.Geometry", + "Sofa.Component.Collision.Response.Contact", + "Sofa.Component.Constraint.Projective", + "Sofa.Component.IO.Mesh", + "Sofa.Component.LinearSolver.Iterative", + "Sofa.Component.Mass", + "Sofa.Component.ODESolver.Backward", + "Sofa.Component.StateContainer", + "Sofa.Component.Mapping.Linear", + "Sofa.Component.SolidMechanics.FEM.Elastic", + "Sofa.Component.Visual", + "Sofa.GL.Component.Rendering3D", + "Sofa.Component.Topology.Container.Dynamic"]) + root.addObject('DefaultAnimationLoop') + root.addObject('VisualStyle', displayFlags="showCollisionModels hideVisualModels showForceFields") - root.addObject('RequiredPlugin', pluginName="SofaImplicitOdeSolver SofaLoader SofaOpenglVisual SofaBoundaryCondition SofaGeneralLoader SofaGeneralSimpleFem") root.addObject('DefaultPipeline', name="CollisionPipeline") - root.addObject('BruteForceDetection', name="N2") + root.addObject('BruteForceBroadPhase', name="BruteForce") + root.addObject('BVHNarrowPhase', name="BVHNarrow") root.addObject('DefaultContactManager', name="CollisionResponse", response="PenalityContactForceField") root.addObject('DiscreteIntersection') - root.addObject('MeshObjLoader', name="LiverSurface", filename="mesh/liver-smooth.obj") + 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) diff --git a/examples/liver.py b/examples/liver.py index 7ae9f44f..75017f94 100644 --- a/examples/liver.py +++ b/examples/liver.py @@ -31,18 +31,32 @@ def createScene(root): root.gravity=[0, -9.81, 0] root.dt=0.02 - root.addObject('DefaultVisualManagerLoop') root.addObject('DefaultAnimationLoop') + root.addObject("RequiredPlugin", pluginName=["Sofa.Component.Collision.Detection.Intersection", + "Sofa.Component.Collision.Detection.Algorithm", + "Sofa.Component.Collision.Geometry", + "Sofa.Component.Collision.Response.Contact", + "Sofa.Component.Constraint.Projective", + "Sofa.Component.IO.Mesh", + "Sofa.Component.LinearSolver.Iterative", + "Sofa.Component.Mass", + "Sofa.Component.ODESolver.Backward", + "Sofa.Component.StateContainer", + "Sofa.Component.Mapping.Linear", + "Sofa.Component.SolidMechanics.FEM.Elastic", + "Sofa.Component.Visual", + "Sofa.GL.Component.Rendering3D", + "Sofa.Component.Topology.Container.Dynamic"]) + root.addObject('VisualStyle', displayFlags="showCollisionModels") - root.addObject('RequiredPlugin', pluginName="Sofa.Component") root.addObject('DefaultPipeline', name="CollisionPipeline") root.addObject('BruteForceBroadPhase', name="BroadPhase") root.addObject('BVHNarrowPhase', name="NarrowPhase") root.addObject('DefaultContactManager', name="CollisionResponse", response="PenalityContactForceField") root.addObject('DiscreteIntersection') - root.addObject('MeshObjLoader', name="LiverSurface", filename="mesh/liver-smooth.obj") + 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") diff --git a/examples/loadXMLfromPython.py b/examples/loadXMLfromPython.py index 396b730f..8374b443 100644 --- a/examples/loadXMLfromPython.py +++ b/examples/loadXMLfromPython.py @@ -7,9 +7,8 @@ def createScene(root): # Call the above function to create the scene graph scene=""" - - - + + diff --git a/examples/springForceField.py b/examples/springForceField.py index 4b668a7a..19eda7cf 100644 --- a/examples/springForceField.py +++ b/examples/springForceField.py @@ -5,9 +5,14 @@ def createScene(root): root.gravity = [0, -9.81, 0] + root.bbox = [[0, 0, 0],[1,1,1]] root.addObject('DefaultAnimationLoop') - root.addObject('DefaultVisualManagerLoop') + root.addObject("RequiredPlugin", pluginName=["Sofa.Component.IO.Mesh", "Sofa.Component.Mass", + "Sofa.Component.LinearSolver.Iterative", "Sofa.Component.MechanicalLoad", + "Sofa.Component.Mapping.NonLinear", "Sofa.Component.ODESolver.Backward", + "Sofa.Component.SolidMechanics.Spring", "Sofa.Component.StateContainer", + "Sofa.GL.Component.Rendering3D"]) surface_node = root.addChild('Surface') surface_loader = surface_node.addObject('MeshOBJLoader', name='surface_loader', filename='mesh/ball.obj') From 7e2f7e5415b742d52665c3d3d55722cbb91ec643 Mon Sep 17 00:00:00 2001 From: Hugo Date: Wed, 7 Sep 2022 11:52:57 +0200 Subject: [PATCH 2/2] Update examples/loadXMLfromPython.py --- examples/loadXMLfromPython.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/loadXMLfromPython.py b/examples/loadXMLfromPython.py index 8374b443..56e107cc 100644 --- a/examples/loadXMLfromPython.py +++ b/examples/loadXMLfromPython.py @@ -8,7 +8,7 @@ def createScene(root): scene=""" - +