Rosanswers logo


I am currently looking into loading an stl-file into rviz and be able to color some parts of the mesh differently than others (dynamically, depending on other input). To my understanding the way to do this would be to somehow parse the stl file and convert it to a triangle list. The triangles can then be colored independently depending on whatever the other input is.

So my question would be if there is already some kind of library out there that does exactly this, or will I have to implement it myself? (I saw some other threads talking about this kind of topic, but they always only linked to http://www.ros.org/wiki/rviz/DisplayTypes/Marker or something similar.)

In case it is relevant: I am on ros kinetic (and optionally melodic).

If you have any other type of solution to this kind of problem I'm happy to hear it.

Thanks in advance,



EDIT : Thanks to @aPonza's answer i could use the geometric_shapes package to achieve my goal of loading a mesh file and convert it to a rviz triangle list. To do this i used createMeshFromResource and then read the Data out of the Mesh object that it generated.

Reading out of the Mesh Object was a little different than i expect since it uses vertex- and index-buffers but thanks to @gvdhoorn's comment with the link to the slides i was able to grasp that concept better.

Originally posted by GS on ROS Answers with karma: 3 on 2018-12-13

Post score: 0

Original comments

Comment by ahendrix on 2018-12-13:
I think the assimp library that is already used within rviz for mesh loading can load STL files into some kind of mesh, but I'm not sure how easy it is to modify that mesh after it has been loaded.

Comment by gvdhoorn on 2018-12-13:
Not an answer, but you may be interested in "Introducing Tools for Storing, Rendering and Annotating Triangle Meshes in ROS and RViz" (video, slides).

Comment by gvdhoorn on 2018-12-13:
Also: rviz_visual_tools supports directly publising Mesh resources. I don't believe you can colour them though (in the way you describe/desire).


1 Answer 1


Rosanswers logo

As far as I know, like @ahendrix is saying, you can use assimp via createMeshFromResource. This already gives you the triangles you're looking for, but you could also afterwards convert it to a shapes::ShapeMsg via constructMsgFromShape or its variant shape_msgs::Mesh with a further call to boost::get, more or less like it's explained in here.

Originally posted by aPonza with karma: 589 on 2018-12-13

This answer was ACCEPTED on the original site

Post score: 1


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.