Visualization System

Chrono objects - either bodies, meshes or even abstract shapes with no underlying physics - can be rendered and visualized through different rendering engines. At the same time, Chrono is not binded to any of them, thus allowing an easy extension to other rendering systems. Various visualization systems are indeed available.

Any visualization system inherits from a common base class - namely ChVisualSystem, defined in the core module - that always includes a pointer to a given ChSystem. This binding allows the visual system to be informed about simulation updates, thus being able to update any visual asset according to the new bodies positions. Visual systems may allow simultaneous rendering of multiple Chrono systems, however only opengl::ChVisualSystemOpenGL currently supports this feature.

Together with the ChVisualSystem, Chrono offers also a wide set of renderer-agnostic visual assets: each visual system takes care of converting them into renderer-specific assets. These visual assets are mainly represented by the ChVisualShape classes.

Visual Shapes and Models

The simplest way to add a visual shape (ChVisualShape) to a physics object could be as simple as a couple of lines of code:

auto visshape = chrono_types::make_shared<ChVisualShapeBox>(20, 1, 20);
visshape->SetColor(ChColor(0.2f, 0.3f, 1.0f));
body->AddVisualShape(visshape, ChFramed(ChVector3d(0, -1, 0), QUNIT));

In which we assume that body is of a type inheriting from ChPhysicsItem e.g. ChBody.

While being quite immediate, this approach is hiding most of the internal structure of the visual assets in Chrono. In fact ChVisualShapes are just a piece of the overall picture.

ChVisualModel

An object of type ChVisualModel takes care of holding (through pointers) all the visual assets of a given object.

A ChVisualModel object can be attached either to a:

Any ChVisualModel contains, among other members:

  • a list of pairs of ChVisualShapes together with their relative ChFrame, expressing the relative position of the shape with respect to the parent object frame;
  • a list of ChVisualShapeFEA for representation of meshes.

Although it is always possible to attach shapes explicitely to the visual model through ChVisualModel::AddShape(), most of the time the average user may attach ChVisualShape in one shot to any ChPhysicsItem (e.g. ChBody) by directly calling ChPhysicsItem::AddVisualShape(). Same applies for ChPhysicsItem::AddVisualShapeFEA(). Even in these cases, the commands are implicitely adding shapes to the underlying ChVisualModel.

Please mind that, when attached to ChBodyAuxRef the reference frame is considered to be REF frame, not COG as shown in the picture below.

ChVisualShape and ChVisualMaterial

Visual shapes inherits either from ChVisualShape or ChVisualShapeFEA and usually have names prefixed with ChVisualShape____. They usually holds also a ChGeometry object to describe their shape, together with one or more ChVisualMaterials, defining any appearance property of the asset.

If no ChVisualMaterial has been explicitely added to the ChVisualShape it will get added automatically whenever the user sets a non-default value for any property of the shape. Multiple materials are usually used in combination with meshes like ChVisualShapeModelFile where multiple materials might be listed in the input OBJ file.

Please refer to the ChVisualShape reference page to have a complete overview of all the possible derived classes.

To conclude, a more pedantic way to achieve the very same effect of the example above could be:

auto body = chrono_types::make_shared<ChBody>();
auto vismat = chrono_types::make_shared<ChVisualMaterial>(20, 1, 20);
vismat->SetDiffuseColor(ChColor(0.2f, 0.3f, 1.0f));
auto visshape = chrono_types::make_shared<ChVisualShapeBox>(20, 1, 20);
visshape->SetMaterial(0, vismat);
auto vismodel = chrono_types::make_shared<ChVisualModel>(20, 1, 20);
vismodel->AddShape(visshape, ChFramed(ChVector3d(0, -1, 0), QUNIT));
body->AddVisualModel(vismodel);

Tutorials

Refer to demo_IRR_assets to have an overview on how to apply assets to rigid bodies.

ChFrame< double > ChFramed
Alias for double-precision coordinate frames.
Definition: ChFrame.h:346
ChVector3< double > ChVector3d
Alias for double-precision vectors.
Definition: ChVector3.h:283