How to visualize tires, wheels etc?

136 views
Skip to first unread message

JC Denton

unread,
Jul 31, 2023, 11:10:57 PM7/31/23
to ProjectChrono
I'm using my own engine, and I have a callback system setup to draw like so:

m_system->GetCollisionSystem()->Visualize(ChCollisionSystem::VIS_Shapes | ChCollisionSystem::VIS_Aabb);

This works fine for my chassis.

But for my wheels and tires it doesn't.

My wheel set's its visual mesh file via:

  m_vis_mesh_file = "Meshes/Collision/LeftWheel.obj";

and my tire's visualize mesh via:

void RangeRoverSport_TMeasyTire::AddVisualizationAssets(VisualizationType vis) 
{
    if (vis == VisualizationType::MESH)
    {      
        m_trimesh_shape = AddVisualizationMesh(m_meshFile_left, m_meshFile_right);        
    }
    else 
{
        ChTMeasyTire::AddVisualizationAssets(vis);
    }
}

but perhaps this is only meant for visualizing with irrlicht and doesn't support drawing out to my own engine?

Thanks!
-JC


Marcel Offermans

unread,
Aug 1, 2023, 3:18:45 AM8/1/23
to projec...@googlegroups.com
Hello JC,

On 01-Aug-23 5:10, 'JC Denton' via ProjectChrono wrote:
> I'm using my own engine, and I have a callback system setup to draw
> like so:
>
> m_system->GetCollisionSystem()->Visualize(ChCollisionSystem::VIS_Shapes
> | ChCollisionSystem::VIS_Aabb);
>
> This works fine for my chassis.
I learned something new, you are registering a callback to draw a
visualization of the collision shapes and using those callbacks to
render something in your engine. That's nice. As far as I'm aware, a
similar hook does not exist for rendering visualizations in general...
> But for my wheels and tires it doesn't.
>
> My wheel set's its visual mesh file via:
>
>   m_vis_mesh_file = "Meshes/Collision/LeftWheel.obj";
>
> and my tire's visualize mesh via:
>
> void
> RangeRoverSport_TMeasyTire::AddVisualizationAssets(VisualizationType vis)
> {
>     if (vis == VisualizationType::MESH)
>     {
>         m_trimesh_shape = AddVisualizationMesh(m_meshFile_left,
> m_meshFile_right);
>     }
>     else
> {
>         ChTMeasyTire::AddVisualizationAssets(vis);
>     }
> }
>
> but perhaps this is only meant for visualizing with irrlicht and
> doesn't support drawing out to my own engine?

I'm pretty sure that assumption is correct. Irrlicht and Vulkan Scene
Graph (VSG) both basically iterate over the whole system and will grab
those assets and render them. The good news is, you can do something
similar yourself. I have done something similar to render terrain and
vehicles for my own simulator.

Greetings, Marcel


JC Denton

unread,
Aug 1, 2023, 11:27:51 PM8/1/23
to ProjectChrono
Thanks Marcel!

I do indeed visualize my wheels and chassis no problem in Unreal engine, however my visual mesh in Unreal is not the same as the collision meshes in Chrono. I would like to draw the scene as Chrono sees it,
to ensure it aligns 1:1 with what Unreal sees.

Hoping there is a way (ideally without modifying Chrono engine code) to visualize the contact points, tire, wheel etc.

I notice inside ChWheel::AddVisualizationAssets() we have some logic to setup triangle meshes:

void ChWheel::AddVisualizationAssets(VisualizationType vis) 
{
    if (vis == VisualizationType::MESH && !m_vis_mesh_file.empty()) {
        ChQuaternion<> rot = (m_side == VehicleSide::LEFT) ? Q_from_AngZ(0) : Q_from_AngZ(CH_C_PI);
        auto trimesh = geometry::ChTriangleMeshConnected::CreateFromWavefrontFile(vehicle::GetDataFile(m_vis_mesh_file),
                                                                                  true, true);
        m_trimesh_shape = chrono_types::make_shared<ChTriangleMeshShape>();
        m_trimesh_shape->SetMesh(trimesh);
        m_trimesh_shape->SetName(filesystem::path(m_vis_mesh_file).stem());
        m_trimesh_shape->SetMutable(false);
        m_spindle->AddVisualShape(m_trimesh_shape, ChFrame<>(ChVector<>(0, m_offset, 0), ChMatrix33<>(rot)));
        return;
    }
}

Is there an easy general way to draw arbitrary chrono shapes such as ChTriangleMeshConnected or ChCylinderShape? Or do I need to roll my own
function to iterate over each chrono shape's verts and then render them on my Unreal side?

Thanks!

Marcel Offermans

unread,
Aug 2, 2023, 3:11:41 AM8/2/23
to projec...@googlegroups.com
Hello JC,

Responses in-line below.

On 02-Aug-23 5:27, 'JC Denton' via ProjectChrono wrote:
> I do indeed visualize my wheels and chassis no problem in Unreal
> engine, however my visual mesh in Unreal is not the same as the
> collision meshes in Chrono. I would like to draw the scene as Chrono
> sees it,
> to ensure it aligns 1:1 with what Unreal sees.

Understood, and this of course is a generic "issue". Collision meshes
are always simplified meshes to keep a decent performance and the visual
mesh (regardless of Unreal, Irrlicht or VSG rendering it) will be
different. I typically use a mental model where I distinguish three worlds:

1. The visual one, that is normally rendered.

2. The collision world, that has all kinds of collidable (simple) shapes
bumping into each other (car bodies bumping into terrain or other cars).

3. The tire world, that typically uses its own type of collision system
(although that depends a bit on the type of tire, I mostly use
semi-empirical ones for my use case.

> Hoping there is a way (ideally without modifying Chrono engine code)
> to visualize the contact points, tire, wheel etc.

I've gone through a similar process and with the help of this community
and a few small patches I have mostly managed to get to the data I want
to visualize without having to change the engine. I did end up doing a
lot of the drawing "myself". There is a lot of information available at
the end of every physics "step" so the biggest deal then becomes how to
pass all that data to (in your case) Unreal. Part of that design is also
about potentially decoupling the physics thread from your rendering (at
least in my case I quickly concluded that with physics running at 1000
fps my graphics card was never going to keep up).

> I notice inside ChWheel::AddVisualizationAssets() we have some logic
> to setup triangle meshes:
>
> void ChWheel::AddVisualizationAssets(VisualizationType vis)
> {
>     if (vis == VisualizationType::MESH && !m_vis_mesh_file.empty()) {
>         ChQuaternion<> rot = (m_side == VehicleSide::LEFT) ?
> Q_from_AngZ(0) : Q_from_AngZ(CH_C_PI);
>         auto trimesh =
> geometry::ChTriangleMeshConnected::CreateFromWavefrontFile(vehicle::GetDataFile(m_vis_mesh_file),
>                   true, true);
>         m_trimesh_shape =
> chrono_types::make_shared<ChTriangleMeshShape>();
>         m_trimesh_shape->SetMesh(trimesh);
> m_trimesh_shape->SetName(filesystem::path(m_vis_mesh_file).stem());
>         m_trimesh_shape->SetMutable(false);
>         m_spindle->AddVisualShape(m_trimesh_shape,
> ChFrame<>(ChVector<>(0, m_offset, 0), ChMatrix33<>(rot)));
>         return;
>     }
> }
>
> Is there an easy general way to draw arbitrary chrono shapes such as
> ChTriangleMeshConnected or ChCylinderShape? Or do I need to roll my
> own function to iterate over each chrono shape's verts and then render
> them on my Unreal side?

I don't think there is. For "primitive" shapes I ended up implementing
them myself based on the provided parameters and I mostly use those to
visualize how the vehicle physics respond. For "mesh" shapes I ended up
completely ignoring what is defined in Chrono and loading my own 3D
model, using a bit of glue code to make the right parts of that model
show up in the places calculated by Chrono (position and orientation).
You could also take the defined OBJ meshes and load those in Unreal I
guess. OBJ is nice because it's a simple format to generate and parse.
That said, I ended up wanting to have the whole vehicle in a single
graphics file, so I ended up with a GLTF file containing all the parts
(body, wheels, etc.).

Greetings, Marcel


JC Denton

unread,
Aug 3, 2023, 1:06:10 AM8/3/23
to ProjectChrono
Thanks Marcel!

I do indeed have my physics thread separate from my render thread. I have a queued callback system to send render debug info from
my chrono dll to the unreal side in a thread safe manner.

I rolled my own debug helper class to manually loop through the vertices from ChCylinder and ChTriangleMeshes and
push those into vert structures that Unreal can read. Seems to be rendering the meshes in unreal okay, just gotta work out some transform conversions now
and expand it to other chrono shape types.

I just pulled the vert data directly from the m_trimesh_shape which exists inside ChWheel already.
So now I have my Unreal visual meshes driven from the Chrono physics output + the chrono collision debug shapes rendering overlayed on top for comparison which is exactly
what I was looking for.

Thanks!

-JC

Marcel Offermans

unread,
Aug 3, 2023, 4:10:40 AM8/3/23
to projec...@googlegroups.com

Great to hear, JC!

Transformation of coordinate systems is something we all have to live with when converting from 3D modeling tools and physics engines to game engines.

One question I have, when you transfer "low level mesh data" from Chrono to Unreal, do you also have a method of caching that so you can send it to the GPU once (and not every frame)?

In any case, it's nice to hear your project is coming along nicely, good luck with it!

Greetings, Marcel

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/e09f2aa7-f738-41c9-a197-8e2b74126e4dn%40googlegroups.com.

JC Denton

unread,
Aug 3, 2023, 11:06:22 AM8/3/23
to ProjectChrono
Hi Marcel,

I do not have a caching system yet, that would be a smart move!
Currently the Unreal side is drawing these debug meshes once per game thread tick (when debugging is enabled), so its not like its once per chrono step.
This debug drawing is purely for debug purpose and wouldn't be visible to the end user. Still though, its a good idea, might as well not waste time looping
over all the verts if the mesh hasn't actually moved.


Thanks!
-JC
Reply all
Reply to author
Forward
0 new messages