diff --git a/SoftRobotics/StepByStep-introduction/0-basic.py b/SoftRobotics/StepByStep-introduction/0-basic.py index a343b8b..481cf5c 100644 --- a/SoftRobotics/StepByStep-introduction/0-basic.py +++ b/SoftRobotics/StepByStep-introduction/0-basic.py @@ -3,6 +3,6 @@ def createScene(rootNode): rootNode.dt = 0.01 # Time step rootNode.gravity = [ 0., 0. ,0.] # Gravitational acceleration applied on the entire scene - rootNode.addObject("DefaultAnimationLoop", name="animation loop") + rootNode.addObject("DefaultAnimationLoop", name="animation_loop") rootNode.addChild("MyObject", bbox=[0,0,0,1,1,1]) # bbox is only needed here to define a non-zero simulation space since the scene is empty diff --git a/SoftRobotics/StepByStep-introduction/9-boundary-conditions.py b/SoftRobotics/StepByStep-introduction/10-boundary-conditions.py similarity index 100% rename from SoftRobotics/StepByStep-introduction/9-boundary-conditions.py rename to SoftRobotics/StepByStep-introduction/10-boundary-conditions.py diff --git a/SoftRobotics/StepByStep-introduction/10-controller-access-data.py b/SoftRobotics/StepByStep-introduction/11-controller-access-data.py similarity index 100% rename from SoftRobotics/StepByStep-introduction/10-controller-access-data.py rename to SoftRobotics/StepByStep-introduction/11-controller-access-data.py diff --git a/SoftRobotics/StepByStep-introduction/11-collision-model.py b/SoftRobotics/StepByStep-introduction/12-collision-model.py similarity index 100% rename from SoftRobotics/StepByStep-introduction/11-collision-model.py rename to SoftRobotics/StepByStep-introduction/12-collision-model.py diff --git a/SoftRobotics/StepByStep-introduction/12-controller-create-objects.py b/SoftRobotics/StepByStep-introduction/13-controller-create-objects.py similarity index 94% rename from SoftRobotics/StepByStep-introduction/12-controller-create-objects.py rename to SoftRobotics/StepByStep-introduction/13-controller-create-objects.py index 24d103a..e5741b1 100644 --- a/SoftRobotics/StepByStep-introduction/12-controller-create-objects.py +++ b/SoftRobotics/StepByStep-introduction/13-controller-create-objects.py @@ -19,17 +19,23 @@ def generateRadius(self): def generatXPos(self): return self.iteration%11 * 10 -170 + def updateCollisionPipeline(self): + self.rootNode.removeObject(self.rootNode.collision_pipeline) + self.rootNode.addObject("CollisionPipeline", name="collision_pipeline") + self.rootNode.collision_pipeline.init() + def addFallingParticle(self, node): iteration_loc = self.iteration newParticle = node.addChild("ParticleToCollideWith-"+str(iteration_loc)) newParticle.addObject("EulerImplicitSolver") - newParticle.addObject("CGLinearSolver", iterations=200, tolerance=1e-09, threshold=1e-09) + newParticle.addObject("SparseLDLSolver", name="linear_solver", template="CompressedRowSparseMatrixMat3x3d") newParticle.addObject("MechanicalObject", template="Rigid3", name="myParticle", position=[self.generatXPos(), 80, 0, 0,0,0,1], showObject=True) newParticle.addObject("UniformMass", totalMass=1) newParticle.addObject("ConstantForceField", totalForce=[0,-50,0,0,0,0], indices=0) newParticle.addObject("SphereCollisionModel", radius=self.generateRadius(), contactStiffness=100) newParticle.init() self.iteration = iteration_loc +1 + self.updateCollisionPipeline() def removeFallingParticle(self, node): iteration_loc = self.iteration - 1 @@ -41,6 +47,7 @@ def removeFallingParticle(self, node): myParticleNode = self.rootNode.removeChild(str(name)) self.iteration = iteration_loc + self.updateCollisionPipeline() def onKeypressedEvent(self, event): key = event["key"] diff --git a/SoftRobotics/StepByStep-introduction/13-lagrangian-constraints.py b/SoftRobotics/StepByStep-introduction/14-lagrangian-constraints.py similarity index 100% rename from SoftRobotics/StepByStep-introduction/13-lagrangian-constraints.py rename to SoftRobotics/StepByStep-introduction/14-lagrangian-constraints.py diff --git a/SoftRobotics/StepByStep-introduction/14-final-pneunet.py b/SoftRobotics/StepByStep-introduction/15-final-pneunet.py similarity index 100% rename from SoftRobotics/StepByStep-introduction/14-final-pneunet.py rename to SoftRobotics/StepByStep-introduction/15-final-pneunet.py diff --git a/SoftRobotics/StepByStep-introduction/6-elastic-finger-units.py b/SoftRobotics/StepByStep-introduction/6-elastic-finger-units.py new file mode 100644 index 0000000..197fa0d --- /dev/null +++ b/SoftRobotics/StepByStep-introduction/6-elastic-finger-units.py @@ -0,0 +1,37 @@ +def createScene(rootNode): + + from Sofa.Units.Definitions import s, m, mm, N, g, kg, Pa + from Sofa.Units.UnitSystem import MechanicalUnitSystem + + scene_unit = MechanicalUnitSystem(s, m, kg) + + rootNode.name = "RootNode" + rootNode.dt = scene_unit(0.01, s) + rootNode.gravity = [0, scene_unit(-9.81, N/kg), 0] # Defining gravity along -Y + + rootNode.addObject("DefaultAnimationLoop", name="animation_loop", computeBoundingBox=False) + + rootNode.addObject("RequiredPlugin", pluginName=["Sofa.Component.StateContainer","Sofa.Component.Mass","Sofa.Component.MechanicalLoad", + "Sofa.Component.LinearSolver.Direct","Sofa.Component.ODESolver.Backward", + "Sofa.Component.IO.Mesh","Sofa.Component.Topology.Container.Dynamic", + "Sofa.Component.SolidMechanics.FEM.Elastic","Sofa.Component.Topology.Container.Constant", + "Sofa.Component.Visual"]) + rootNode.addObject("VisualStyle", name="visual_options", displayFlags="showForceFields") + + rootNode.addObject("MeshVTKLoader", name="mesh_loader_coarse", filename="../PneuNets_remeshed.vtk") # Using a VTK file format, thus using MeshVTKLoader + + ################################################ + # Mechanical representation of the finger object + mechanicalModel = rootNode.addChild("Finger") + + mechanicalModel.addObject("EulerImplicitSolver", name="integration_scheme") + mechanicalModel.addObject("SparseLDLSolver", name="linear_solver", template="CompressedRowSparseMatrixMat3x3d") + + # MeshTopology is a static topology container, i.e. it does not support topology changes (unlike TetrahedronSetTopologyContainer) + mechanicalModel.addObject("MeshTopology", name="topology_container", src="@../mesh_loader_coarse" ) + + mechanicalModel.addObject("MechanicalObject", template="Vec3", name="state_container", showObject=True) # Define the template as Vec3 for 3D deformable bodies + + mechanicalModel.addObject("TetrahedronFEMForceField", name="elastic_material_law", template="Vec3", poissonRatio=0.3, youngModulus=scene_unit(100, Pa)) # Define an elastic constitutive law + mechanicalModel.addObject("MeshMatrixMass", name="mass", template="Vec3,Vec3", totalMass=scene_unit(500, g)) # Use a mass integrated over the volume + ################################################ diff --git a/SoftRobotics/StepByStep-introduction/6-rendering-model.py b/SoftRobotics/StepByStep-introduction/7-rendering-model.py similarity index 100% rename from SoftRobotics/StepByStep-introduction/6-rendering-model.py rename to SoftRobotics/StepByStep-introduction/7-rendering-model.py diff --git a/SoftRobotics/StepByStep-introduction/7-mapping.py b/SoftRobotics/StepByStep-introduction/8-mapping.py similarity index 100% rename from SoftRobotics/StepByStep-introduction/7-mapping.py rename to SoftRobotics/StepByStep-introduction/8-mapping.py diff --git a/SoftRobotics/StepByStep-introduction/8-different-representations.py b/SoftRobotics/StepByStep-introduction/9-different-representations.py similarity index 100% rename from SoftRobotics/StepByStep-introduction/8-different-representations.py rename to SoftRobotics/StepByStep-introduction/9-different-representations.py