-
Notifications
You must be signed in to change notification settings - Fork 54
[Prefabs] Add modifiers #612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 25_04_work_on_new_prefabs
Are you sure you want to change the base?
Changes from all commits
dd60d77
1e2553c
c76d9b3
59b663a
b652302
0e62193
2360fa5
c8d4b4b
f168808
68aa1e2
f1435ba
8037538
f09df01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| from stlib.geometries.plane import PlaneParameters | ||
| from stlib.geometries.file import FileParameters | ||
| from stlib.geometries.extract import ExtractParameters | ||
| from stlib.materials.deformable import DeformableBehaviorParameters | ||
| from stlib.collision import Collision, CollisionParameters | ||
| from stlib.entities import Entity, EntityParameters | ||
| from stlib.visual import Visual, VisualParameters | ||
| from splib.core.enum_types import CollisionPrimitive, ElementType, ConstitutiveLaw | ||
| from splib.simulation.headers import setupLagrangianCollision, setupDefaultHeader | ||
| from splib.simulation.ode_solvers import addImplicitODE | ||
| from splib.simulation.linear_solvers import addLinearSolver | ||
| import dataclasses | ||
| import numpy as np | ||
|
|
||
|
|
||
| from stlib.node_modifiers import NodeModifier | ||
| from stlib.node_modifiers.footers import SimulationSolversParameters, SimulationSettingsParameters | ||
| from stlib.node_modifiers.attachments import FixConstraintParameters, AttachmentConstraintParameters | ||
|
|
||
| def createScene(root): | ||
| root.gravity=[0,0,9.81] | ||
| root.dt=0.01 | ||
|
|
||
| ##Environement | ||
| planes_lengthNormal = np.array([0, 1, 0]) | ||
| planes_lengthNbEdge = 1 | ||
| planes_widthNbEdge = 2 | ||
| planes_lengthSize = 30 | ||
| planes_widthSize = 70 | ||
|
|
||
| plane1_collisionParams = CollisionParameters() | ||
| plane1_collisionParams.name = "UP" | ||
| plane1_collisionParams.primitives = [CollisionPrimitive.TRIANGLES] | ||
| plane1_collisionParams.kwargs = {"TriangleCollision" : {"moving" : False, "simulated" : False}} | ||
| plane1_collisionParams.geometry = PlaneParameters(np.array([15,0,5]), np.array([0,0,-1]), | ||
| planes_lengthNormal, planes_lengthNbEdge, planes_widthNbEdge, planes_lengthSize, planes_widthSize) | ||
| plane1 = root.add(Collision, parameters = plane1_collisionParams) | ||
| # TODO being able to reuse already loaded geometry of current prefab to add any new sub prefab | ||
| # We need to enable to directly pass a link to an already existing prefab in place of a prefab parameter object | ||
| plane1_visu = plane1.addChild("Visu") | ||
| plane1_visu.addObject("OglModel", name="VisualModel", src="@../Geometry/container") | ||
|
|
||
|
|
||
| ### Logo | ||
| ModelsNode = root.addChild("ModelsNode") | ||
|
|
||
| LogoParams = EntityParameters(name = "Logo1", | ||
| geometry = FileParameters(filename="mesh/SofaScene/Logo.vtk"), | ||
| material = DeformableBehaviorParameters(), | ||
| collision = CollisionParameters(geometry = FileParameters(filename="mesh/SofaScene/LogoColli.sph")), | ||
| visual = VisualParameters(geometry = FileParameters(filename="mesh/SofaScene/LogoVisu.obj"))) | ||
|
|
||
| LogoParams.geometry.elementType = ElementType.TETRAHEDRA | ||
| LogoParams.material.constitutiveLawType = ConstitutiveLaw.ELASTIC | ||
| LogoParams.material.parameters = [200, 0.4] | ||
| LogoParams.material.massDensity = 0.003261 | ||
| LogoParams.collision.primitives = [CollisionPrimitive.SPHERES] | ||
| #TODO make this flawless with spheres. Here collisions elements are not in the topology and a link is to be made between the loader and the collision object | ||
| LogoParams.collision.kwargs = {"SphereCollision" : {"radius" : "@Geometry/loader.listRadius"}} | ||
| LogoParams.visual.color = [0.7, .35, 0, 0.8] | ||
|
|
||
| Logo = ModelsNode.add(Entity, parameters = LogoParams) | ||
|
|
||
|
|
||
|
|
||
| ### S | ||
| SParams = EntityParameters() | ||
| SParams.name = "S" | ||
| SParams.geometry = FileParameters(filename="mesh/SofaScene/S.vtk") | ||
| SParams.geometry.elementType = ElementType.TETRAHEDRA | ||
| SParams.material = DeformableBehaviorParameters() | ||
| SParams.material.constitutiveLawType = ConstitutiveLaw.ELASTIC | ||
| SParams.material.parameters = [200, 0.45] | ||
| SParams.material.massDensity = 0.011021 | ||
| SParams.collision = CollisionParameters() | ||
| SParams.collision.primitives = [CollisionPrimitive.TRIANGLES] | ||
| # # #TODO: to fix link issues for extracted geometry, it might be better to give source geometry relative link + parameters | ||
| ## TODO: not working with static container because the init order is always wrong so that the triangle vector is always empty when initializing the container | ||
| SParams.collision.geometry = ExtractParameters(destinationType=ElementType.TRIANGLES, sourceParameters=SParams.geometry) | ||
| SParams.visual = VisualParameters() | ||
| SParams.visual.geometry = FileParameters(filename="mesh/SofaScene/SVisu.obj") | ||
| SParams.visual.color = [0.7, .7, 0.7, 0.8] | ||
|
|
||
| S = ModelsNode.add(Entity, parameters = SParams) | ||
|
|
||
| #TODO make the name automatically match the modifier type if none is given | ||
| root.add(NodeModifier, on = [ModelsNode], parameters = SimulationSolversParameters(constantSparsity=False)) | ||
|
|
||
| root.add(NodeModifier, on = [root], parameters = SimulationSettingsParameters(displayFlags = ["showVisualModels", "showInteractionForceFields"], | ||
| enableCollisionDetection = True, | ||
| useLagrangian = True, | ||
| parallelComputing = False, | ||
| alarmDistance=0.3, contactDistance=0.02, | ||
| frictionCoef=0.5, tolerance=1.0e-4, maxIterations=20)) | ||
|
|
||
| Logo.add(NodeModifier, on = [Logo], parameters = FixConstraintParameters( boxROIs=[[-1, -2, -13, 3, 2, -7]])) | ||
| Logo.add(NodeModifier, on = [Logo], parameters = FixConstraintParameters( boxROIs=[[-100, -2, -13, -300, 2, -7]])) | ||
| ModelsNode.add(NodeModifier, on = [S, Logo], parameters = AttachmentConstraintParameters(name = "AttachmentConstraintParameters", indices1=[26,20,119,121], indices2=[722,732,574,573], stiffness=0.5, damping=0.0, | ||
| length=[((9.43-9.35)**2 + (-.44-0.48)**2 + (-6.01+6.56)**2)**(0.5) ])) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| from splib.simulation.linear_solvers import * | ||
| from splib.mechanics.linear_elasticity import * | ||
|
Comment on lines
4
to
5
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in this PR, but I think I would prefer: - I'm not a big fan of the |
||
| from splib.mechanics.mass import * | ||
| from splib.mechanics.fix_points import * | ||
| from splib.mechanics.attachment import * | ||
| from splib.topology.loader import * | ||
| from splib.core.node_wrapper import * | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| __all__ = ["linear_elasticity","hyperelasticity","fix_points","collision_model","mass"] | ||
| __all__ = ["linear_elasticity","hyperelasticity","attachment","collision_model","mass"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,16 +67,16 @@ def setupPenalityCollisionHeader(node, displayFlags = "showVisualModels",backgr | |
| node.addObject(parallelPrefix+'BVHNarrowPhase', name="narrowPhase", **kwargs) | ||
|
|
||
| if(stick): | ||
| node.addObject('CollisionResponse',name="ContactManager", response="BarycentricStickContact",**kwargs) | ||
| node.addObject('CollisionResponse',name="ContactManager", response="StickContactForceField",**kwargs) | ||
| else: | ||
| node.addObject('CollisionResponse',name="ContactManager", response="BarycentricPenalityContact",**kwargs) | ||
| node.addObject('CollisionResponse',name="ContactManager", response="PenalityContactForceField",**kwargs) | ||
| node.addObject('LocalMinDistance' ,name="Distance", alarmDistance=alarmDistance, contactDistance=contactDistance, **kwargs) | ||
|
|
||
| return node | ||
|
|
||
|
|
||
| @ReusableMethod | ||
| def setupLagrangianCollision(node, displayFlags = "showVisualModels",backgroundColor=[1,1,1,1], parallelComputing=False, stick=False, alarmDistance=DEFAULT_VALUE, contactDistance=DEFAULT_VALUE, frictionCoef=0.0, tolerance=0.0, maxIterations=100, **kwargs): | ||
| def setupLagrangianCollision(node, enableCollision = True, displayFlags = "showVisualModels",backgroundColor=[1,1,1,1], parallelComputing=False, stick=False, alarmDistance=DEFAULT_VALUE, contactDistance=DEFAULT_VALUE, frictionCoef=0.0, tolerance=0.0, maxIterations=100, **kwargs): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why adding this boolean? Isn't |
||
| node.addObject('VisualStyle', displayFlags=displayFlags) | ||
| node.addObject('BackgroundSetting', color=backgroundColor) | ||
|
|
||
|
|
@@ -107,21 +107,24 @@ def setupLagrangianCollision(node, displayFlags = "showVisualModels",background | |
| if(parallelComputing): | ||
| parallelPrefix="Parallel" | ||
|
|
||
| node.addObject('CollisionPipeline', name="collisionPipeline", | ||
| **kwargs) | ||
| if enableCollision: | ||
| node.addObject('CollisionPipeline', name="collisionPipeline", | ||
| **kwargs) | ||
|
|
||
| node.addObject(parallelPrefix+'BruteForceBroadPhase', name="broadPhase", | ||
| **kwargs) | ||
| node.addObject(parallelPrefix+'BruteForceBroadPhase', name="broadPhase", | ||
| **kwargs) | ||
|
|
||
| node.addObject(parallelPrefix+'BVHNarrowPhase', name="narrowPhase", | ||
| **kwargs) | ||
| node.addObject(parallelPrefix+'BVHNarrowPhase', name="narrowPhase", | ||
| **kwargs) | ||
|
|
||
| if(stick): | ||
| node.addObject('CollisionResponse',name="ContactManager", response="StickContactConstraint", responseParams="tol="+str(tolerance),**kwargs) | ||
| else: | ||
| node.addObject('CollisionResponse',name="ContactManager", response="FrictionContactConstraint", responseParams="mu="+str(frictionCoef),**kwargs) | ||
|
|
||
| node.addObject('NewProximityIntersection' ,name="Distance", alarmDistance=alarmDistance, contactDistance=contactDistance, **kwargs) | ||
|
|
||
| if(stick): | ||
| node.addObject('CollisionResponse',name="ContactManager", response="StickContactConstraint", responseParams="tol="+str(tolerance),**kwargs) | ||
| else: | ||
| node.addObject('CollisionResponse',name="ContactManager", response="FrictionContactConstraint", responseParams="mu="+str(frictionCoef),**kwargs) | ||
|
|
||
| node.addObject('NewProximityIntersection' ,name="Distance", alarmDistance=alarmDistance, contactDistance=contactDistance, **kwargs) | ||
| node.addObject('BlockGaussSeidelConstraintSolver',name="ConstraintSolver", tolerance=tolerance, maxIterations=maxIterations, multithreading=parallelComputing,**kwargs) | ||
| node.addObject("ConstraintAttachButtonSetting") | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .__node_modifier__ import * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a minor cleaning. It simplifies the code/readability a little bit.