11 Skinning

11.6 Collisions

It is possible to make skin bodies collide with other ArtiSynth bodies, such as RigidBody and FemModel3d, which implement the Collidable interface (Chapter 8). SkinMeshBody itself implements CollidableBody, and is considered a deformable body, so that collisions can be activated either by setting one of the default collision behaviors involving deformable bodies, or by setting an explicit collision behavior between it and another body. Self collisions involving SkinMeshBody are not currently supported.

As described in Section 8.4, collisions work by computing the intersection between the meshes of the skin body and other collidables. The vertices, faces, and (possibly) edges of the resulting intersection region are then used to compute contact constraints, which propagate the effect of the contact back onto the collidable bodies’ dynamic components. For a skin mesh, the dynamic components are the Frame master bodies and the nodes of the FEM master bodies.

Collisions involving SkinMeshBody frequently suffer from the problem of being overconstrained (Section 8.6), whereby the the number of contacts exceeds the number of master body DOFs available to handle the collision. This may occur if the skin body contains only rigid bodies, or if the mesh resolution exceeds the resolution of the FEM master bodies. Managing overconstrained collisions is discussed in Section 8.6, with the easiest method being constraint reduction, which can be activated by setting to true the reduceConstraints property for either the collision manager or a specific CollisionBehavior involving the skin body.

Caveats: The distance between the vertices of a skinned mesh and its master bodies can sometimes cause odd or counter-intuitive collision behavior. Collision handling may also be noticeably slower if frameBlending is set to DUAL_QUATERNION_LINEAR or DUAL_QUATERNION_ITERATIVE. If any of the master bodies are FEM models, collisions resulting in large friction forces may result in unstable behavior.

11.6.1 Example: collision with a cylinder

Figure 11.6: SkinBodyCollide demo, showing a skin mesh colliding with a cylinder about 0.6 seconds into the simulation.

Collisions involving SkinMeshBody are illustrated by the demo model artisynth.demos.tutorial.SkinBodyCollide, which extends the demo AllBodySkinning to add a cylinder with which the skin body can collide. The code for the demo is given below:

1 package artisynth.demos.tutorial;
2
3 import artisynth.core.femmodels.SkinMeshBody;
4 import artisynth.core.mechmodels.CollisionBehavior;
5 import artisynth.core.mechmodels.MechModel;
6 import artisynth.core.mechmodels.RigidBody;
7 import maspack.matrix.RigidTransform3d;
8
9 public class SkinBodyCollide extends AllBodySkinning {
10
11    public void build (String[] args) {
12       super.build (args);
13
14       // get components from the super class
15       MechModel mech = (MechModel)models().get("mech");
16       SkinMeshBody skinBody = (SkinMeshBody)mech.meshBodies().get("skin");
17       RigidBody block0 = mech.rigidBodies().get("block0");
18
19       // set block0 dynamic so the skin body and its masters can
20       // fall under gravity
21       block0.setDynamic (true);
22
23       // create a cylinder for the skin body to collide with
24       RigidBody cylinder =
25          RigidBody.createCylinder (
26             "cylinder", 0.5, 2.0, /*density=*/1000.0, /*nsides=*/50);
27       cylinder.setDynamic (false);
28       cylinder.setPose (
29          new RigidTransform3d (-0.5, 0, -1.5, 0, 0, Math.PI/2));
30       mech.addRigidBody (cylinder);
31
32       // enable collisions between the cylinder and the skin body
33       CollisionBehavior cb = new CollisionBehavior (true, 0);
34       mech.setCollisionBehavior (cylinder, skinBody, cb);
35       mech.getCollisionManager().setReduceConstraints (true);
36    }
37 }

The model subclasses AllBodySkinning, using the superclass build() method within its own build method to create the original model (line 12). It then obtains references to the MechModel, SkinMeshBody, and leftmost block, using their names to find them in various component lists (lines 14-17). (If the original model had stored references to these components as accessible member attributes, this step would not be needed.)

These component references are then used to make changes to the model: the left block is made dynamic so that the skin mesh can fall freely (line 21), a cylinder is created and added (lines 23-30), collisions are enabled between the skin body and the cylinder (lines 32-34), and the collision manager is asked to use constraint reduction to minimize the chance of overconstrained contact (line 35).

To run this example in ArtiSynth, select All demos > tutorial > SkinBodyCollide from the Models menu. When run, the skin body should fall and collide with the cylinder as shown in Figure 11.6.