Extract colors from individual volumes in step file

Dear all,

This is my first post in this forum, so my apologies if anything goes wrong here.

I am writing an application in C++ where I input a step file, extract and export individual volumes to stl files, and extract their respective colors as well. The extraction and conversion to stl works well so far, but I'm really struggling with extracting their respective colors (actually, have been trying this for a couple of months before finally giving up and posting here).

Attached what I've done so far - the file has both the stl Extraction (which works well), and the color Extraction (not really working). I would be really thankful if anyone could give me a help here.

Many thanks in advance.

Br,
Leonardo.

Kirill Gavrilov's picture

Is there a particular need to use legacy STL format instead of glTF or OBJ writers natively supporting colors / materials?

Leonardo Ghizoni's picture

Dear Kirill,

Thanks for the feedback.

Yes, I have an external program that reads individual STL files, import them, and export them into another format for monte carlo simulations. The program currently can read only the STL files. I have defined separate color vectors due to the interface I have as input to the monte carlo program.

Does the STL format pose a challenge in extracting the colors?

Br,
Leonardo.

Kirill Gavrilov's picture

At minimum, you may take a look on how colors are exported in RWObj_CafWriter source code. It relies on an auxiliary tool RWMesh_FaceIterator (as well as XCAFPrs_DocumentExplorer for iterating over parts in the document), which allows iterating over TopoDS_Face and return result style or color (RWMesh_FaceIterator::FaceColor()) deduced from XCAF document.

Leonardo Ghizoni's picture

Hi again,

Actually, I just noted that I can indeed import OBJ individual files into my program. I assume that would be easier in terms of both exporting the individual OBJ files and getting their respective colors?

Leonardo.