99from stlib .core .basePrefab import BasePrefab
1010
1111from stlib .geometries .file import FileParameters
12- from stlib .materials .rigid import RigidParameters
12+ from stlib .materials .rigid import RigidMaterialParameters
1313from splib .core .enum_types import ElementType
1414
15+ from dynapydantic import Polymorphic
16+ import Sofa
17+
1518
1619class EntityParameters (BaseParameters ):
1720 name : str = "Entity"
1821
19- stateType : StateType = StateType .RIGID
20-
2122 ### QUID
2223 addCollision : Optional [Callable ] = Collision (CollisionParameters ())
2324 addVisual : Optional [Callable ] = Visual (VisualParameters ())
2425
25- geometry : GeometryParameters = GeometryParameters (elementType = ElementType .POINTS , data = InternalDataProvider (position = [[0. , 0. , 0. ]]))
26- material : MaterialParameters = RigidParameters ()
26+ geometry : Polymorphic [ GeometryParameters ] = GeometryParameters (elementType = ElementType .POINTS , data = InternalDataProvider (position = [[0. , 0. , 0. ]]))
27+ material : Polymorphic [ MaterialParameters ] = RigidMaterialParameters ()
2728 collision : Optional [CollisionParameters ] = None
2829 visual : Optional [VisualParameters ] = VisualParameters (geometry = FileParameters (filename = "mesh/cube.obj" ))
2930
@@ -46,11 +47,10 @@ def __init__(self, parameters: EntityParameters):
4647
4748 def init (self ):
4849 self .geometry = self .add (Geometry , parameters = self .parameters .geometry )
49- self .checkMaterialCompatibility ()
5050
5151 self .material = self .add (Material , parameters = self .parameters .material )
52- self .material .getMechanicalState ().position . parent = self .geometry .container . position .linkpath
53-
52+ self .material .getMechanicalState ().topology = self .geometry .container .linkpath
53+
5454 if self .parameters .collision is not None :
5555 self .collision = self .add (Collision , parameters = self .parameters .collision )
5656 self .addMapping (self .collision )
@@ -59,18 +59,13 @@ def init(self):
5959 self .visual = self .add (Visual , parameters = self .parameters .visual )
6060 self .addMapping (self .visual )
6161
62- def checkMaterialCompatibility (self ):
63- if self .parameters .material .stateType != self .parameters .stateType :
64- print ("WARNING: imcompatibility between templates of both the entity and the material" )
65- self .parameters .material .stateType = self .parameters .stateType
66-
6762
6863 def addMapping (self , destinationPrefab ):
6964
70- template = f'{ self .parameters .stateType } ,Vec3' # TODO: check that it is always true
65+ template = f'{ self .parameters .material . stateType } ,Vec3' # TODO: check that it is always true
7166
7267 #TODO: all paths are expecting Geometry to be called Geomtry and so on. We need to robustify this by using the name parameter somehow
73- if ( self .parameters .stateType == StateType .VEC3 ):
68+ if ( self .parameters .material . stateType == StateType .VEC3 ):
7469 destinationPrefab .addObject ("BarycentricMapping" ,
7570 output = destinationPrefab .linkpath ,
7671 output_topology = destinationPrefab .geometry .container .linkpath ,
0 commit comments