Skip to content

25 04 use reusable method in prefabs instead of self add object #493

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

Open
wants to merge 2 commits into
base: 25_04_work_on_new_prefabs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions splib/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import List, Callable, Tuple, Dict
from functools import wraps
from node_wrapper import ReusableMethod


class defaultValueType():
def __init__(self):
Expand Down Expand Up @@ -32,5 +34,9 @@ def wrapper(*args, **kwargs):
return MapArg


@ReusableMethod
def addObject(node,typeName : str, name : str , **kwargs):
node.addObject(typeName, name = name, **kwargs)



4 changes: 2 additions & 2 deletions stlib/geometry/__geometry__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def __init__(self, params: GeometryParameters):
params.data.generateAttribute(self)
if(params.dynamicTopology):
if(params.elementType is not None):
addDynamicTopology(self, container = dataclasses.asdict(params.data))
addDynamicTopology(self, container = dataclasses.asdict(params.data), **params.kwargs)
else:
raise ValueError
else:
addStaticTopology(self, container = dataclasses.asdict(params.data))
addStaticTopology(self, container = dataclasses.asdict(params.data),**params.kwargs)
2 changes: 2 additions & 0 deletions stlib/geometry/cube.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from stlib.geometry import GeometryParameters

#TODO this is outdated an need to be updated with the InternalDataProvider

class CubeParameters(GeometryParameters):
def __init__(self, center, edgeLength, pointPerEdge, dynamicTopology = False):

Expand Down
2 changes: 1 addition & 1 deletion stlib/geometry/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from Sofa.Core import Node


#TODO enable passing kwargs to this to use addObject instead and again get the benefit from splib
class ExtractInternalDataProvider(InternalDataProvider):
destElemType : ElementType
fromElemType : ElementType
Expand Down
2 changes: 2 additions & 0 deletions stlib/geometry/sphere.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from stlib.geometry import GeometryParameters

#TODO this is outdated an need to be updated with the InternalDataProvider

class SphereParameters(GeometryParameters):
def __init__(self, center, radius, pointPerRad, dynamicTopology = False):

Expand Down
4 changes: 2 additions & 2 deletions stlib/prefabs/collision.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from stlib.geometry import Geometry, GeometryParameters
from stlib.geometry.file import FileParameters
from splib.core.enum_types import CollisionPrimitive
from splib.core.utils import DEFAULT_VALUE
from splib.core.utils import DEFAULT_VALUE, addObject
from splib.mechanics.collision_model import addCollisionModels
from Sofa.Core import Object

Expand All @@ -28,7 +28,7 @@ def __init__(self, params: CollisionParameters):

geom = self.add(Geometry, params.geometry)

self.addObject("MechanicalObject",template="Vec3", position=f"@{params.geometry.name}/container.position")
addObject(self,"MechanicalObject",name="MechanicalObject",template="Vec3", position=f"@{params.geometry.name}/container.position", **params.kwargs)
for primitive in params.primitives:
addCollisionModels(self,primitive,
topology=f"@{params.geometry.name}/container",
Expand Down
9 changes: 5 additions & 4 deletions stlib/prefabs/visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
from stlib.core.baseParameters import BaseParameters, Callable, Optional, dataclasses, Any
from stlib.geometry import Geometry, GeometryParameters
from stlib.geometry.file import FileParameters
from splib.core.utils import DEFAULT_VALUE, addObject

from Sofa.Core import Object

@dataclasses.dataclass
class VisualParameters(BaseParameters):
color : Optional[list[float]] = None
texture : Optional[str] = None
color : Optional[list[float]] = DEFAULT_VALUE
texture : Optional[str] = DEFAULT_VALUE

geometry : GeometryParameters = dataclasses.field(default_factory = lambda : GeometryParameters())
addMapping : Optional[Callable] = None
Expand All @@ -18,8 +20,7 @@ def __init__(self, params: VisualParameters):
BasePrefab.__init__(self, params)

geom = self.add(Geometry, params.geometry)
# TODO : handle optional color, texture using DEFAULT_VALUE mechanism (as implemented by Paul)
self.addObject("OglModel", color=params.color, src=geom.container.linkpath)
addObject(self,"OglModel", "MechanicalState", color=params.color, src=geom.container.linkpath, **params.kwargs)

if params.addMapping is not None:
params.addMapping(self)
Expand Down
Loading