To import an OpenSim model, an application uses the class OpenSimParser. Its primary constructor is
OpenSimParser (File osimFile, File geometryDir) |
where osimFile references the .osim file and geometryPath references the folder where the geometry is located. If geometryPath is specified as null, the parser will look for the geometry under either "Geometry" or "geometry", in the same folder as the .osim file.
After creating the parser, the model can be loaded by calling createModel(), which reads the model file, generates the equivalent ArtiSynth components, and arranges them in the specified MechModel:
If the mech argument is null, createModel() generates a fresh MechModel and returns it.
The listing below shows a complete example given in
artisynth.demos.opensim.OpenSimArm26
which imports the Arm26 model by Reinbolt, Seth, Habib, and Hamner, and based on an earlier model Kate Holzbaur.
When loaded into ArtiSynth, the model appears as in Figure 12.1. The OpenSim model contains a number of components that are not implemented by ArtiSynth, as seen by the console messages
OpenSimParser: ignoring ControllerSet OpenSimParser: ignoring ContactGeometrySet OpenSimParser: ignoring ProbeSet
After calling createModel(), the build() method changes the view orientation, sets damping for the rigid bodies. and creates control panels to adjust the excitations and joint coordinates. These are actions described further in Section 12.4.