Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a6ff885
add folder for STLIB
bakpaul Apr 14, 2025
60352a4
Add reusable methods
bakpaul Apr 14, 2025
d024105
Add working files
bakpaul Apr 14, 2025
10082bf
Created example scenes
bakpaul Apr 14, 2025
d167479
Fix example
bakpaul Apr 14, 2025
dd9cc34
orga folders
hugtalbot Apr 14, 2025
7589706
Fix package
bakpaul Apr 14, 2025
2f844d7
bootstrap examples
bakpaul Apr 14, 2025
2c55e7d
start beginner scene
hugtalbot Apr 14, 2025
9b9e057
Move around files
bakpaul Apr 14, 2025
b989159
Move examples into SofaPython3 main example folder
bakpaul Apr 14, 2025
b42833b
Add unsaved modifications
bakpaul Apr 14, 2025
fa0bd74
reoganisation after discussion
EulalieCoevoet Apr 14, 2025
4380356
Add gemetries
bakpaul Apr 14, 2025
ba978ce
WIP FileParameters
bakpaul Apr 14, 2025
fc88100
Add beginner example
bakpaul Apr 14, 2025
7c314c6
Add unsaved changes
bakpaul Apr 14, 2025
b70a52b
Start work on visual and collision
bakpaul Apr 14, 2025
7cedc42
work on Tuesday : visual, geometry
hugtalbot Apr 15, 2025
5f183d5
add basePrefabParameters.py
hugtalbot Apr 15, 2025
97a2381
Add extracted geometry
bakpaul Apr 15, 2025
00fd16b
Fix visual example
bakpaul Apr 15, 2025
423a484
Finished collisions
bakpaul Apr 15, 2025
c97bfa3
[stlib-splib] work on prefabs: cleaning (#501)
EulalieCoevoet Jun 2, 2025
995d1b3
[stlib] adds README
EulalieCoevoet Jun 2, 2025
01531ca
[stlib] minor changes from discussion
EulalieCoevoet Jun 2, 2025
fc1404a
[splib] updates entity
EulalieCoevoet Jun 3, 2025
dd230b9
update README
hugtalbot Jun 3, 2025
57efa1d
add init in prefab
hugtalbot Jun 3, 2025
938f05b
Add first implem of entity
bakpaul Jun 3, 2025
592c13d
before the train 3/3
hugtalbot Jun 3, 2025
ca864d8
very last commit befor train
EulalieCoevoet Jun 3, 2025
1d8cdd3
WIP
bakpaul Jun 3, 2025
bacb258
Retore original. Still crash due to wrong string conversion
bakpaul Jun 3, 2025
09f45c5
[stlib] Deformable Entity (#502)
EulalieCoevoet Jun 13, 2025
d4b6042
Fix linkpath by introducing init method + make addDeformableMaterial …
bakpaul Jun 13, 2025
aad2a5e
[STLIB] Add the unified "add" in Sofa.Core.Node (#503)
damienmarchal Jul 17, 2025
1b15154
Add new tests for prefabs
bakpaul Jul 17, 2025
e2fff56
Revert modification of __genericAdd
bakpaul Jul 17, 2025
9de87d4
update addMass using elementType
hugtalbot Jul 17, 2025
75fa28f
[Prefabs] Reorder files to match concepts (#547)
bakpaul Oct 28, 2025
ae1d496
[Prefabs] cleaning to fix deformable example (#549)
EulalieCoevoet Oct 28, 2025
ac3ed74
Fix by passing state link when using other topology than edges (#550)
bakpaul Oct 28, 2025
44f5f4c
Add plane, still need to really implement function + started creating…
bakpaul Oct 28, 2025
1cd8917
Fix plane and some splib deprecated components
bakpaul Oct 29, 2025
a08ddaf
Remove SofaScene
bakpaul Oct 29, 2025
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
Prev Previous commit
Next Next commit
Fix plane and some splib deprecated components
  • Loading branch information
bakpaul committed Oct 29, 2025
commit 1cd89170d7fab87b108d8136dee907ee831c8494
35 changes: 21 additions & 14 deletions examples/stlib/SofaScene.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
from stlib.geometries.plane import PlaneParameters
from stlib.collision import CollisionParameters
from stlib.collision import Collision
from stlib.visual import Visual
from splib.core.enum_types import CollisionPrimitive
from splib.simulation.headers import setupLagrangianCollision
import dataclasses
import numpy as np



def createScene(root):
##Solvers


setupLagrangianCollision(root, displayFlags = "showVisualModels",backgroundColor=[0.8, 0.8, 0.8, 1],
parallelComputing = True,alarmDistance=0.3, contactDistance=0.02,
frictionCoef=0.5, tolerance=1.0e-4, maxIterations=20)

##Environement

planes_lengthNormal = np.array([])
planes_length = 1
planes_width = 1
planes_nbEdgeLength = 1
planes_nbEdgeWidth = 1
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([0,0,0]), np.array([0,0,-1]),
planes_lengthNormal, planes_length, planes_width, planes_nbEdgeLength, planes_nbEdgeWidth)
root.add(Collision, plane1_collisionParams)
plane1_collisionParams.geometry = PlaneParameters(np.array([15,0,1]), 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
plane1_visu = plane1.addChild("Visu")
plane1_visu.addObject("OglModel", name="VisualModel", src="@../Geometry/container")


plane2_collisionParams = CollisionParameters()
plane2_collisionParams.name = "DOWN"
plane2_collisionParams.primitives = [CollisionPrimitive.TRIANGLES]
plane2_collisionParams.kwargs = {"TriangleCollision" : {"moving" : False, "simulated" : False}}
plane2_collisionParams.geometry = PlaneParameters(np.array([0,0,0]), np.array([0,0,1]),
planes_lengthNormal, planes_length, planes_width, planes_nbEdgeLength, planes_nbEdgeWidth)
root.add(Collision, plane2_collisionParams)
plane2_collisionParams.geometry = PlaneParameters(np.array([15,0,-20]), np.array([0,0,1]),
planes_lengthNormal, planes_lengthNbEdge, planes_widthNbEdge, planes_lengthSize, planes_widthSize)
plane2 = root.add(Collision, parameters = plane2_collisionParams)
plane2_visu = plane2.addChild("Visu")
plane2_visu.addObject("OglModel", name="VisualModel", src="@../Geometry/container")


## Real models
2 changes: 1 addition & 1 deletion splib/simulation/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def setupLagrangianCollision(node, displayFlags = "showVisualModels",background
node.addObject('CollisionResponse',name="ContactManager", response="FrictionContactConstraint", responseParams="mu="+str(frictionCoef),**kwargs)

node.addObject('NewProximityIntersection' ,name="Distance", alarmDistance=alarmDistance, contactDistance=contactDistance, **kwargs)
node.addObject('GenericConstraintSolver',name="ConstraintSolver", tolerance=tolerance, maxIterations=maxIterations, multithreading=parallelComputing,**kwargs)
node.addObject('ProjectedGaussSeidelConstraintSolver',name="ConstraintSolver", tolerance=tolerance, maxIterations=maxIterations, multithreading=parallelComputing,**kwargs)
node.addObject("ConstraintAttachButtonSetting")

return node
2 changes: 1 addition & 1 deletion stlib/collision.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, parameters: CollisionParameters):

def init(self):

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

self.addObject("MechanicalObject", template="Vec3", position=f"@{self.parameters.geometry.name}/container.position")
for primitive in self.parameters.primitives:
Expand Down
2 changes: 1 addition & 1 deletion stlib/geometries/__geometry__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, parameters: GeometryParameters):
def init(self):

# Generate attribute (positions, edges, triangles, quads, tetrahedra, hexahedra) from the internal data provider
if self.parameters.data is not None :
if isinstance(self.parameters.data, InternalDataProvider) :
self.parameters.data.generateAttribute(self)
if self.parameters.dynamicTopology :
if self.parameters.elementType is not None :
Expand Down
44 changes: 31 additions & 13 deletions stlib/geometries/plane.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
from stlib.geometries import GeometryParameters, InternalDataProvider
from stlib.geometries import GeometryParameters, InternalDataProvider, Geometry
import dataclasses
import numpy as np

@dataclasses.dataclass
class PlaneDataProvider(InternalDataProvider):
center : np.ndarray[float]
normal : np.ndarray[float]
lengthNormal : np.ndarray[float]
nbEdgeLength : int
nbEdgeWidth : int
width : float
edgeSize : float
center : np.ndarray[float] = dataclasses.field(default_factory = lambda : np.array([0,0,0]))
normal : np.ndarray[float] = dataclasses.field(default_factory = lambda : np.array([0,0,1]))
lengthNormal : np.ndarray[float] = dataclasses.field(default_factory = lambda : np.array([1,0,0]))
lengthNbEdge : int = 1
widthNbEdge : int = 1
lengthSize : float = 1.0
widthSize : float = 1.0

def __post_init__(self, **kwargs):
InternalDataProvider.__init__(self,**kwargs)

def generateAttribute(self):
#TODO
pass
def generateAttribute(self, parent : Geometry):

lengthEdgeSize = self.lengthSize / self.lengthNbEdge
widthEdgeSize = self.widthSize / self.widthNbEdge

self.widthNormal = np.cross(self.normal,self.lengthNormal)
bottomLeftCorner = self.center - self.lengthNormal * self.lengthNbEdge * lengthEdgeSize / 2 - self.widthNormal * self.widthNbEdge * widthEdgeSize / 2

self.position = np.array([[ bottomLeftCorner + j * self.widthNormal * widthEdgeSize + i * self.lengthNormal * lengthEdgeSize for j in range(self.widthNbEdge + 1) ] for i in range(self.lengthNbEdge + 1)])

self.triangles = np.empty((2 * self.widthNbEdge * self.lengthNbEdge, 3), dtype = int)
for i in range(self.lengthNbEdge):
for j in range(self.widthNbEdge):
self.triangles[i*self.widthNbEdge*2 + j * 2 , 0] = j + i * (self.widthNbEdge + 1)
self.triangles[i*self.widthNbEdge*2 + j * 2 , 1] = j + (i+1) * (self.widthNbEdge + 1)
self.triangles[i*self.widthNbEdge*2 + j * 2 , 2] = j + 1 + i * (self.widthNbEdge + 1)
self.triangles[i*self.widthNbEdge*2 + j * 2 + 1, 0] = j + 1 + i * (self.widthNbEdge + 1)
self.triangles[i*self.widthNbEdge*2 + j * 2 + 1, 1] = j + (i+1) * (self.widthNbEdge + 1)
self.triangles[i*self.widthNbEdge*2 + j * 2 + 1, 2] = j + 1 + (i+1) * (self.widthNbEdge + 1)




class PlaneParameters(GeometryParameters):

def __init__(self, center, normal, lengthNormal, length, width, nbEdgeLength, nbEdgeWidth, dynamicTopology = False):
GeometryParameters.__init__(data = PlaneDataProvider(center=center, normal=normal, lengthNormal=lengthNormal, length=length, width=width, nbEdgeLength=nbEdgeLength, nbEdgeWidth=nbEdgeWidth),
def __init__(self, center, normal, lengthNormal, lengthNbEdge, widthNbEdge, lengthSize, widthSize, dynamicTopology = False):
GeometryParameters.__init__(self, data = PlaneDataProvider(center=center, normal=normal, lengthNormal=lengthNormal, lengthNbEdge=lengthNbEdge, widthNbEdge=widthNbEdge, lengthSize=lengthSize, widthSize=widthSize),
dynamicTopology = dynamicTopology)