Color tones change after OBJ export – how to preserve original shading?

@pieper The comment warns :

722. // OBJ exporter sets the same color for ambient, diffuse, specular
723. // so we scale it by 1/3 to avoid having too bright material.

but the actual behavior is the output .mtl only writes the 1/3 RGB value to the diffuse property and has 0 0 0 for ambient and specular.

# wavefront mtl file written by the visualization toolkit

newmtl mtl1
Ka 0 0 0
Kd 0.3333333333333333 0.3333333333333333 0.3333333333333333
Ks 0 0 0
Ns 3
Tr 1
illum 3

I think the most complete solution would be to set the specular, SpecularPower, ambient from the vtkProperty of the Slicer material. These are editable from UI in the models module.

But the most straight-forward interpretation should be to map the label / model ‘color’ property to the mtl diffuse property at a 1:1 ratio. I think it is reasonable to leave specular & ambient values to 0 0 0, as the exporter does now.

If you are making a change to the OBJ exporter, I would also consider altering the material name from the default value ‘mtl1’ to a unique name that matches the file output.

spleen.obj > spleen.mtl contains:
newmtl spleen

This way, the material names are unique and identifiable to the to object it is assigned. It’s difficult to manage many materials with the same name ‘mtl1’ in the external DCC application. I’ve made scripts to reassign material names in the DCC to match objects, but this would be a convenient default behavior.