11from stlib .geometries .plane import PlaneParameters
2- from stlib .collision import CollisionParameters
3- from stlib .collision import Collision
4- from stlib .visual import Visual
5- from splib .core .enum_types import CollisionPrimitive
6- from splib .simulation .headers import setupLagrangianCollision
2+ from stlib .geometries .file import FileParameters
3+ from stlib .geometries .extract import ExtractParameters
4+ from stlib .materials .deformable import DeformableBehaviorParameters
5+ from stlib .collision import Collision , CollisionParameters
6+ from stlib .entities import Entity , EntityParameters
7+ from stlib .visual import Visual , VisualParameters
8+ from splib .core .enum_types import CollisionPrimitive , ElementType , ConstitutiveLaw
9+ from splib .simulation .headers import setupLagrangianCollision , setupDefaultHeader
10+ from splib .simulation .ode_solvers import addImplicitODE
11+ from splib .simulation .linear_solvers import addLinearSolver
712import dataclasses
813import numpy as np
914
1015
1116
1217def createScene (root ):
18+ root .gravity = [0 ,0 ,9.81 ]
1319 ##Solvers
14- setupLagrangianCollision (root , displayFlags = "showVisualModels" ,backgroundColor = [0.8 , 0.8 , 0.8 , 1 ],
15- parallelComputing = True ,alarmDistance = 0.3 , contactDistance = 0.02 ,
16- frictionCoef = 0.5 , tolerance = 1.0e-4 , maxIterations = 20 )
20+ setupDefaultHeader (root , displayFlags = "showVisualModels" ,backgroundColor = [0.8 , 0.8 , 0.8 , 1 ],
21+ parallelComputing = True )
22+ # setupLagrangianCollision(root, displayFlags = "showVisualModels",backgroundColor=[0.8, 0.8, 0.8, 1],
23+ # parallelComputing = True,alarmDistance=0.3, contactDistance=0.02,
24+ # frictionCoef=0.5, tolerance=1.0e-4, maxIterations=20)
1725
1826 ##Environement
1927 planes_lengthNormal = np .array ([0 , 1 , 0 ])
@@ -29,7 +37,8 @@ def createScene(root):
2937 plane1_collisionParams .geometry = PlaneParameters (np .array ([15 ,0 ,1 ]), np .array ([0 ,0 ,- 1 ]),
3038 planes_lengthNormal , planes_lengthNbEdge , planes_widthNbEdge , planes_lengthSize , planes_widthSize )
3139 plane1 = root .add (Collision , parameters = plane1_collisionParams )
32- #TODO being able to reuse already loaded geometry of current prefab to add any new sub prefab
40+ # TODO being able to reuse already loaded geometry of current prefab to add any new sub prefab
41+ # We need to enable to directly pass a link to an already existing prefab in place of a prefab parameter object
3342 plane1_visu = plane1 .addChild ("Visu" )
3443 plane1_visu .addObject ("OglModel" , name = "VisualModel" , src = "@../Geometry/container" )
3544
@@ -46,3 +55,68 @@ def createScene(root):
4655
4756
4857 ## Real models
58+ Beam = root .addChild ("Beam" )
59+
60+ VolumetricObjects = root .addChild ("VolumetricObjects" )
61+ addImplicitODE (VolumetricObjects )
62+ addLinearSolver (VolumetricObjects , constantSparsity = True )
63+
64+ ### Logo
65+ LogoParams = EntityParameters ()
66+ LogoParams .name = "Logo"
67+ LogoParams .geometry = FileParameters (filename = "mesh/SofaScene/Logo.vtk" )
68+ LogoParams .geometry .elementType = ElementType .TETRAHEDRA
69+ LogoParams .material = DeformableBehaviorParameters ()
70+ LogoParams .material .constitutiveLawType = ConstitutiveLaw .ELASTIC
71+ LogoParams .material .parameters = [200 , 0.4 ]
72+
73+ def logoAddMaterial (node ):
74+ DeformableBehaviorParameters .addDeformableMaterial (node )
75+ node .addObject ("ConstantForceField" , name = "ConstantForceUpwards" , totalForce = [0 , 0 , - 5.0 ])
76+ #TODO deal with that is a more smooth way in the material directly
77+ node .addObject ("LinearSolverConstraintCorrection" , name = "ConstraintCorrection" , linearSolver = VolumetricObjects .LinearSolver .linkpath , ODESolver = VolumetricObjects .ODESolver .linkpath )
78+
79+
80+ LogoParams .material .addMaterial = logoAddMaterial
81+ LogoParams .material .massDensity = 0.003261
82+ LogoParams .collision = CollisionParameters ()
83+ LogoParams .collision .primitives = [CollisionPrimitive .SPHERES ]
84+ LogoParams .collision .geometry = FileParameters (filename = "mesh/SofaScene/LogoColli.sph" )
85+ #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
86+ LogoParams .collision .kwargs = {"SphereCollision" : {"radius" : "@Geometry/loader.listRadius" }}
87+ LogoParams .visual = VisualParameters ()
88+ LogoParams .visual .geometry = FileParameters (filename = "mesh/SofaScene/LogoVisu.obj" )
89+ LogoParams .visual .color = [0.7 , .35 , 0 , 0.8 ]
90+
91+ Logo = VolumetricObjects .add (Entity , parameters = LogoParams )
92+
93+ ### S
94+ SParams = EntityParameters ()
95+ SParams .name = "S"
96+ SParams .geometry = FileParameters (filename = "mesh/SofaScene/S.vtk" )
97+ SParams .geometry .elementType = ElementType .TETRAHEDRA
98+ SParams .material = DeformableBehaviorParameters ()
99+ SParams .material .constitutiveLawType = ConstitutiveLaw .ELASTIC
100+ SParams .material .parameters = [200 , 0.45 ]
101+
102+ def SAddMaterial (node ):
103+ DeformableBehaviorParameters .addDeformableMaterial (node )
104+ #TODO deal with that is a more smooth way in the material directly
105+ node .addObject ("LinearSolverConstraintCorrection" , name = "ConstraintCorrection" , linearSolver = VolumetricObjects .LinearSolver .linkpath , ODESolver = VolumetricObjects .ODESolver .linkpath )
106+
107+ SParams .material .addMaterial = SAddMaterial
108+ SParams .material .massDensity = 0.011021
109+ SParams .collision = CollisionParameters ()
110+ SParams .collision .primitives = [CollisionPrimitive .TRIANGLES ]
111+ # #TODO: to fix link issues for extracted geometry, it might be better to give source geometry relative link + parameters
112+ SParams .collision .geometry = ExtractParameters (destinationType = ElementType .TRIANGLES , sourceParameters = SParams .geometry )
113+ SParams .visual = VisualParameters ()
114+ SParams .visual .geometry = FileParameters (filename = "mesh/SofaScene/SVisu.obj" )
115+ SParams .visual .color = [0.7 , .7 , 0.7 , 0.8 ]
116+
117+ S = VolumetricObjects .add (Entity , parameters = SParams )
118+
119+
120+ SDensity = 0.011021
121+ ODensity = SDensity
122+ ADensity = 0.00693695
0 commit comments