Materials and textures for most loaded OBJ files are not rendered...

201 views
Skip to first unread message

Marcel Offermans

unread,
Jun 17, 2022, 5:00:40 PM6/17/22
to ProjectChrono
Hi all, can anybody tell me how to enable the correct rendering of textures and materials that are defined within the various OBJ files? They are missing for most demos, and I tried both the latest 7.0.3 release as well as "develop". Is this a bug?

Radu Serban

unread,
Jun 18, 2022, 8:09:36 AM6/18/22
to ProjectChrono

Marcel,

 

Indeed, this is a known current limitation (bug if you wish) in the Irrlicht run-time visualization module.
I have recently redesigned the entire framework for specifying visualization models and rendering. The code is set up to make use of both the OBJ and any MTL file, but there’s still something I must be missing when creating the Irrlicht materials and mesh buffers that prevents rendering of material textures.

 

I can think of 3 options for now:

  • I will look again at this issue when I get a chance.  However, it’s not a top priority right now (also because the expectation is that we will eventually replace Irrlicht run-time visualization with a VSG-based system).  So, you may have to wait a bit longer.

  • You (or someone else familiar with Irrlicht) could help with a fix for this through a pull request 😊
    For whoever is interested, the two relevant parts in the code to look at are:
  • Instead of using a trimesh asset read from file (in which case Chrono constructs an internal mesh representation and also reads in visual materials which are later passed on the run-time visualization system to be converted in their own objects), use a ChObjFileShape and attach that as a visual shape to your model.   The difference is that a ChObjFileShape is only a reference to a Wavefront OBJ file which is passed as such to the visualization system;  if it knows how to do that, it is the renderer responsibility (in this case Irrlicht) to open that OBJ file (and any associated MTL files) and create its own internal meshes and materials.  Irrlicht knows how to do that, and the material textures show up fine if going this route.
    For an example of this, look at the “Gator” vehicle model and something like demo_VEH_Gator.

 

--Radu

--
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/9e0c9aab-d5ad-4bc2-bcd0-b9dcdda77b9bn%40googlegroups.com.

Marcel Offermans

unread,
Jun 18, 2022, 8:30:16 AM6/18/22
to ProjectChrono
Thank you for providing these pointers. I will have a go at this although, since I'm new to the project, I can't promise I can figure it out. :)

What is a "VSG-based system" out of interest?

Greetings, Marcel

Radu Serban

unread,
Jun 18, 2022, 10:46:21 AM6/18/22
to ProjectChrono

Marcel, assuming you are talking about option #2 I listed below, keep in mind that this is not a trivial task unless you have some experience with rendering pipelines in general and Irrlicht in particular.  Also, this will not teach you much about Chrono. 
However, if you are interested in learning more about that kind of things, by all means, give it a shot.

 

VSG is VulkanSceneGraph. See https://vsg-dev.github.io/VulkanSceneGraph/

Marcel Offermans

unread,
Jun 18, 2022, 11:08:02 AM6/18/22
to ProjectChrono
Indeed I was referring to #2 and I'm aware that this is far from trivial. It's a bit of a side step, but to explore Chrono it would be really helpful for me to be able to load arbitrary 3D OBJ files, mainly for terrain models, and have those rendered with textures (as without they become grey blobs that are hard to drive for a human driver). Based on your info, a workaround for the vehicles is to modify ChVehicleGeometry::AddVisualizationAssets(...) and basically make it do the same for both m_has_obj and m_has_mesh:

    if (vis == VisualizationType::MESH && (m_has_obj || m_has_mesh)) {
        auto obj_shape = chrono_types::make_shared<ChObjFileShape>();
        obj_shape->SetFilename(vehicle::GetDataFile(m_vis_mesh_file));
        body->AddVisualShape(obj_shape, ChFrame<>());
        return;
    }

Which simply confirms what you wrote earlier, that having irrlicht load the object directly does seem to work. I took the demo_VEH_CityBus as an example. One thing that I did have to change is to remove all but the diffuse texture from the material (deleting the lines that are so subtly marked in red below):

# Blender MTL File: 'None'
# Material Count: 1
newmtl lambert15SG
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Kd 0.500000 0.500000 0.500000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 1
map_Kd textures/Bus_Texturing_Bus_Chassis_BaseColor.jpg
map_Pr textures/Bus_Texturing_Bus_Chassis_Roughness.jpg
map_Pm textures/Bus_Texturing_Bus_Chassis_Metallic.jpg
map_d textures/Bus_Chassis_Opacity.jpg


When I do that, I get a bus (with opaque windows and no real material properties but) with a texture!

And thanks for clarifying what VSG is, I was not aware of that project yet. I am following the progress of some completely different library (Godot game engine) to Vulkan, and that's a long journey for them. That said, Vulkan is a much more modern graphics engine. Is that something that's being developed somewhere out in the open (Chrono integration with VSG)?

Greetings, Marcel

Radu Serban

unread,
Jun 18, 2022, 11:28:44 AM6/18/22
to ProjectChrono

Chrono::VSG is being developed in the feature/vsg branch.  Right now, it’s pretty much a one-man job, with Rainer - our collaborator in Germany – doing all the heavy lifting. If you are interested and willing to help, that would be great!

 

Best,

Marcel Offermans

unread,
Jun 18, 2022, 3:31:29 PM6/18/22
to ProjectChrono
I quickly tried downloading, cloning and building it and all the dependencies but failed. Is it in a state right now where it should build? I'm certainly no Vulkan expert (most I've done is a bit of OpenGL and some higher level DX11 stuff). I guess for now I'll focus on trying to pinpoint the issue with irrlicht. I'm already a step further than I was yesterday with the workaround above, so I have something to zoom into. Again, thanks for the help!

Greetings, Marcel

Radu Serban

unread,
Jun 19, 2022, 7:52:28 AM6/19/22
to ProjectChrono

Indeed, getting all dependencies right takes a bit of work.  But yes, if you get all of them straightened out, Chrono::VSG should build fine.
VSG is itself under continuous development and the hope is that they will streamline the installation process at some point.  There’s not much point for us to try to do anything about it until then.

Marcel Offermans

unread,
Jun 19, 2022, 8:17:25 AM6/19/22
to ProjectChrono
I found and fixed the issue with the textures (#401) and added a PR: https://github.com/projectchrono/chrono/pull/402

Greetings, Marcel
Reply all
Reply to author
Forward
0 new messages