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:
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:
- ChPhysicsItem or inherited classes (most often either ChBody or fea::ChMesh), in this case:
- visual assets contained in the ChVisualModel will automatically move together with the object;
- a ChVisualModel is automatically added under the hood whenever a call to AddVisualShape() is made.
- directly to a ChVisualSystem:
- asset are considered fixed to ground and they will not move during simulation;
- a ChVisualModel must be explicitely created and added to the system by calling ChVisualSystem::AddVisualModel()
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:
Tutorials
Refer to demo_IRR_assets to have an overview on how to apply assets to rigid bodies.