Incorrect reading of vertex colors on OBJ import?

Hello there!

I just ran into something strange when importing OBJ files.

I am writing a Grasshopper definition to export meshes with vertex colors for multi-color 3D printing. The script manually assigns vertex colors to a mesh on a black-white gradient. When the mesh is baked to Rhino, everything looks great:

The problem comes if I export the mesh to OBJ (including VCs) and then import the mesh again into Rhino, to verify everything went well. I get this coloring:

As you see, I get these white vertices in areas where they should be much darker. Although I actually enjoy the aesthetics of this glitch, it is unintentional nonetheless… :rofl:

Upon inspection of the vertex colors and the OBJ file, I have detected that these white spots happen on vertices with vertex color 1, 1, 1. My theory is: is it possible that the OBJ importer is trying to make best guesses about the numerical range of the vc ([0,1] or [0,255]), but it is doing it per-vertex, not holistically, and therefore, believes 1,1,1 vcs are full white? And could there be a workaround to this that does not involve writing a full OBJ importer from scratch…? :sweat_smile:

Thank you team!

obj-with-vertex-colors.zip (335.5 KB)

The exported OBJ file is attached ^^^

@tim - is this something you can help with?

Update: on a full RGB colored mesh, these glitches still appear:

Upon inspection, the cyan point on the nose tip has a vertex color of 0,1,1.

Hi Jose,

Have you determined whether downstream apps, besides Rhino, open with the vertex colors correct? That will tell me if it’s an import or export problem. Probably would be best to just have the baked object in a 3dm file so I can see what’s going on.

Tim

Here is the baked file in 3dm format:
3dm-with-vertex-colors.zip (852.5 KB)

You can probably replicate the export/import workflow yourself.

Problem is, most other apps that visualize meshes with vertex colors take the colors in normalized range, not 0,255 as Rhino exports it. So having trouble cross-checking this…

Hang on. I just carefully re-read the thread here. So you’re saying that a color 1,1,1, which ought be very dark grey is coming in white instead? Definitely a bug.

I know there’s something in there to try to determine whether the color is 0.0-1.0 or 0-255 but I do think it’s a per vertex thing. At the moment at least. It would be easy enough to sample a number of arbitrary colors to set a flag for the entire file though.

I’ll dig into this today and I don’t need a 3dm file.

You can set whether you want colors to be 0.0-1.0 or 0-255 in the mesh tab of the export options. If you’re using that. It should be in the dotnet options too. I’ll check. One sec.

It is in RhinoCommon too. To set it there tweak this property. Rhino.FileIO.FileObjWriteOptions.VcsFormat

You can track the progress of this here. https://mcneel.myjetbrains.com/youtrack/issue/RH-80953/Case-where-VCs-are-read-wrong-from-an-OBJ-file…

Thanks a lot @tim this was really helpful!

I believe the numeric range for VCs option is new in R8 both for the export menu and for RC, that’s why I hadn’t seen it (many of my students are still in R7).

Your fix will be in the first 8.6 RC.

1 Like

RH-80953 is fixed in Rhino 8 Service Release 6 Release Candidate

1 Like