Customise name of mtl file and color information of object in it

I have a few questions and concerns regarding the mtl and obj files created using the code: FileObj.Write(meshFilePath, doc, new FileObjWriteOptions(new FileWriteOptions())). Here are my concerns:

  1. Can we control the mtl file name under the “newmtl -” entry in the generated mtl file?
  2. The mtl file is not capturing the color information that we are assigning to the mesh in Rhino.
  3. Is there a way to skip the mtl file creation and only generate the obj file?
  4. Is there a method available in the Rhino API that allows us to specify the guid as part of the mtl file name?

image
image

HI,

Currently, the mtl file takes the same filename as the obj file. It could be made to take a different name for the mtl file though. When you say color information what exactly do you mean? Are you talking about vertex colors or something else? I’ll look today but I don’t think obj has support for vertex colors, only normals and texture coordinates. There is a checkbox in the UI, under formatting (seems like not the most apparent placer to look) named “Export material definitions”. If you uncheck that you won’t get an mtl file, at least that’s the idea. It’s a bug if you do. For the last one, the material name is used if there is one and something generic is used if there isn’t. I suppose it would be possible to use the ID of the material but I don’t know if that’s something you can set in the API. I could hook up using the ID in OBJ but I wouldn’t know about setting it on the Rhino material itself.

I’ll watch this post and try to answer additional questions if you have them.

Tim

1 Like

Hi @tim
Thanks for your response on this.

Yeah, mtll and obj file are taking same name currently but I am talking about the name under "newmtl which is diffuse_o inspite of giveing display/layer color to the object in Rhino.
And I am talking about the display color.color by layer which we have as options to provide color to the solids/mesh.
Couldd you please tell in details that if not by api then how can we we set guid as the name of mtl file under newmtl?

I see, so your objects have no material, you’re using the “Use display color with no materials” setting and you have the display color set to “by layer” for the object in Rhino. Additionally, you want to use a guid as the name for usemtl/newmtl in the output. Is this correct? Is this supposed to be a guid you supply or can it be the object id of the layer that the color comes from?

If you want to use the object id of the layer I can do what I said above in code and I can add an option in the export OBJ API options. I’m not going to add UI for this because what you’re asking is a super corner case and I can only imagine you using it. If it turns out I’m wrong I’ll add UI to 9, not 8, and only to use a layer name as the material name, not anything having to do with using a guid.

It you want to use your own guid, then you’ll have to name the layer with that guid (in Rhino, prior to the export) and I’ll use the layer name to set the usemtl/newmtl in the output file.

Let me know what you want and I’ll write up a feature report and add it here so you can monitor progress.

Cheers,
Tim

Yeah, you got it right.
We are trying to set color by setting dispaly color as “by layer” or directly some color there only.
So currently in mtl file we are having “newmtl diffuse_0” and in obj file its “usemtl diffuse_0” and while doing so we are unable to create data excahnge with color but when we relase in obj file as "usemtl “object id’” then its woking as expected. So we got a way that we can try this way.

if you could suggest some other alternative also for this then it would be a great help.

Thanks