Extending Blender SOFA

18 Mar Extending Blender SOFA

It is possible to customize Blender SOFA to improve the tuning of your scenes. For instance, you can expose a new data to the GUI or modify existing models in order to replace the default solver with your preferred one.

The magic happens in the files placed in the directory Blender/[version]/datafiles/ge_physics_sofa/sga/definitions.

For each available physical type, we have defined a SOFA sub-graph. When ‘P’ is pressed, the objects placed in the Blender scene are parsed and the corresponding sub-graph is added in the SOFA scene. Those sub-graphs are defined in Xml files placed in the sofa directory. For example, here is the file for the Rigid objects.

1
2
3
4
5
6
7
<Node name="$name"  >
    <EulerImplicitSolver rayleighStiffness="$rayleighStiffness" rayleighMass="$rayleighMass" />
    <CGLinearSolver iterations="$CGIterations" tolerance="$CGTolerance" threshold="$CGThreshold" />
    <MechanicalObject template="Rigid" position="0 0 0  0 0 0 1" translation="$translation" rotation="$rotation"/>
    <UniformMass totalmass="$mass"/>
    <UncoupledConstraintCorrection/>
</Node>

By editing those files you will modify the SOFA sub-graphs for all the objects labelled as Rigid. This allows you to can replace the Solver with your preferred one or change the type of Mass.

Notice that some data are initialized with a string starting with a $ and followed by an id. Those string are replaced by the values of a property of the same name that you can set in the Blender GUI. To appear in the GUI, the properties have to be defined in a  Xml files placed in the sub-directory properties. For instance, you have below the file for the Rigid objects.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<Type id="Rigid" label="Rigid Object" description="Rigid object" >
    <Property id="name" type="string" label="Name" description="Name of the object in Sofa" />
    <Property id="translation" type="Vec3d" label="Translation" description="Position of the object" />
    <Property id="rotation" type="Vec3d" label="Rotation" description="Rotation of the object" />
    
    <Property id="mass" type="float" label="Mass" description="Total mass of the object" min="0" default="1" />
    
    <Property id="rayleighMass" type="float" label="Mass damping" description="Rayleigh damping coefficient related to mass" min="0" default="0.1" advanced="1" />
    <Property id="rayleighStiffness" type="float" label="Stiffness damping" description="Rayleigh damping coefficient related to stiffness" min="0" default="0.1" advanced="1" />
    <Property id="CGIterations" type="float" label="CG Iterations" description="Maximum number of iterations of the Conjugate Gradient solution" min="1" default="20" advanced="1" />
    <Property id="CGTolerance" type="float" label="CG Tolerance" description="Desired precision of the Conjugate Gradient solution" min="0" default="1e-5" advanced="1" />
    <Property id="CGThreshold" type="float" label="CG threshold" description="Minimum value of the denominator in the Conjugate Gradient solution" min="0" default="1e-5" advanced="1" />
    
    <Constant id="template" value="Rigid" />
 </Type>

A property should provide the following informations:

  • id. The id of the property, that is used to identify it in the SOFA Xml file.
  • type. The type of the property. It can be bool, float, Vec3i, Vec3d, … The exact list is available in the readme.txt file placed in the definitions directory.
  • label. The label displayed in the Blender GUI to identify the property.
  • min, max, default. Min, max and default values for the property. They are optional.
  • advanced. If value is 1 (default is 0), the property appears in a panel labelled advanced.

There is still a bit more that you can do, look at the existing file to have an idea. For instance, you can add your own SOFA objects: put the xml sub-graph in a file in the sofa/physics repertory, and the declaration of the properties in a file of the same name in properties/physics.
We are currently adding functionalities to the sub-graph files: testing for conditions, inserting nodes in other existing objects.

No Comments

Post A Comment