Skip to content

Collision Pipelines

Collision between objects is split in several phases, each implemented in a different component. Each phase is scheduled by a collision pipeline. The collision pipelines are executed in an animation loop.

The Steps

The collision pipeline follows three steps:

  1. reset of the collision
  2. a collision detection
  3. a collision response

Implementation

A collision pipeline is called from an animation loop through a CollisionVisitor executing the 3 steps of the pipeline in CollisionVisitor::processCollisionPipeline.

The visitor executes the following functions, each corresponding to a step of the pipeline:

/// Remove collision response from last step
void Pipeline::computeCollisionReset()

/// Detect new collisions. Note that this step must not modify the simulation graph
void Pipeline::computeCollisionDetection()
/// Add collision response in the simulation graph
void Pipeline::computeCollisionResponse()

Each of these functions will call a delegate, available in the Pipeline:

/// Remove collision response from last step
void doCollisionReset() override;

/// Detect new collisions. Note that this step must not modify the simulation graph
void doCollisionDetection(const sofa::helper::vector<core::CollisionModel*>& collisionModels) override;
/// Add collision response in the simulation graph
void doCollisionResponse() override;

The 3 delegate functions describe the 3 different steps, and are usually overriden in derived classes. See an example in DefaultPipeline.

Notes: In some cases, the 3 steps are called manually by the animation loop through 3 dedicated visitors (CollisionResetVisitor, CollisionDetectionVisitor and CollisionResponseVisitor). Each of these visitors executes only one step (instead of the 3). This is to avoid race conditions in a multithreaded environment.

Examples of Components

The following components are all collision pipelines, and can be placed in a simulation scene:

The default collision detection and modeling pipeline

Target: Sofa.Component.Collision.Detection.Algorithm

namespace: sofa::component::collision::detection::algorithm

parents:

  • Pipeline

Data

Name Description Default value
name object name unnamed
printLog if true, emits extra messages at runtime. 0
tags list of the subsets the objet belongs to
bbox this object bounding box
componentState The state of the component among (Dirty, Valid, Undefined, Loading, Invalid). Undefined
listening if true, handle the events, otherwise ignore the events 0
verbose Display extra informations at each computation step. (default=false) 0
depth Max depth of bounding trees. (default=6, min=?, max=?) 6
Visualization
draw Draw the detected collisions. (default=false) 0
Name Description Destination type name
context Graph Node containing this object (or BaseContext::getDefault() if no graph is used) BaseContext
slaves Sub-objects used internally by this object BaseObject
master nullptr for regular objects, or master object for which this object is one sub-objects BaseObject