Sofa Template Library
This library should contain sofa scene template. It should contain common scene template used regularly to make the writing of scene with Sofa easy. The templates should be compatible with .pyscn and PSL scenes. The library also contains cool utility functions we should always consider to use.
from stlib3.scene import MainHeader
from stlib3.solver import DefaultSolver
from stlib3.physics.rigid import Cube, Sphere, Floor
from stlib3.physics.deformable import ElasticMaterialObject
def createScene(rootNode):
MainHeader(rootNode)
DefaultSolver(rootNode)
Sphere(rootNode, name="sphere", translation=[-5.0, 0.0, 0.0])
Cube(rootNode, name="cube", translation=[5.0,0.0,0.0])
ElasticMaterialObject(rootNode, name="dragon",
volumeMeshFileName="mesh/liver.msh",
surfaceMeshFileName="mesh/dragon.stl",
translation=[0.0,0.0,0.0])
Floor(rootNode, name="plane", translation=[0.0, -1.0, 0.0])
The API documentation is available at readthedocs
There are two ways to compile plugins for SOFA. The most commonly used is the In-tree build, i.e. building the plugin while building SOFA from its sources on github. The second option, which is less commonly used but provides more flexibility, is the Out-of-tree build, where SOFA is pre-built and installed (from sources or by downloading its binaries) and the plugin is compiled as a standalone module, against the SOFA libraries
First you need to have SOFA on your machine, since to build STLIB you will need to build it through SOFA.
git clone https://github.com/sofa-framework/sofa.git
Then clone STLIB
git clone https://github.com/SofaDefrost/STLIB.git
In the configurations of SOFA build settings, set PLUGIN_SOFAPYTHON
to ON
and SOFA_EXTERNAL_DIRECTORIES
to the absolute path of STLIB your_path/STLIB
Then build SOFA
Now you should be able to use import stlib
in python from inside SOFA (running the .py from runSofa)
Either Download the latest binary release or build and install from the sources, as described on sofa-framework's download page. Remember the installation directory, you will need it later on.
Then clone STLIB
git clone https://github.com/SofaDefrost/STLIB.git
create a build/ folder next to your STLIB repository's directory, and in CMake-gui, set the source folder with
In the configurations of STLIB build settings, add the following CMake entries:
CMAKE_PREFIX_PATH
= SOFA_INSTALLATION_DIRECTORY
PLUGIN_SOFAPYTHON
= ON
SOFA_BUILD_METIS
= ON
Configure, Generate, then build AND install the plugin. During the install step, STLIB will be deployed in SOFA's installation directory, and you will be able to use import stlib
in python from inside SOFA (running the .py from runSofa)