I wrote a Python script to import a .OBJ file for a mesh. It parses the .OBJ file and creates vertices, faces and vertex colors and vertex textures for the mesh. The script skips the mtllib and usemtl lines near the top of the file. After the import is complete, I switch to rendered mode and all the texture is properly displayed.
My Question: How in the world did Rhino manage to find the .mtl and the JPG texture files for this mesh??
I have been using Rhino’s Import tool up until now for my .OBJ files and that has been working fine. I just wanted to see if I could create a faster importer for the .OBJ files. I recently did this for .XYZRGB point cloud files and got a 15X speedup over Rhino’s Import tool. So I thought I would try this same approach for .OBJ files to see how much speedup is possible. I can already see from the early timings that a 2X speedup may be possible but not 15X. Apparently Rhino’s point cloud importer has been worked on a lot less than the .OBJ file importer.
The .OBJ file import was done in a new Rhino session. I did use another Rhino session to time Rhino’s Import tool to import the same mesh. Do the Rhino sessions talk to each other with respect to what .mtl file and PNG files for textures are active? Is this how the new Rhino session with the Python script was able to access these files? At some point I will restart my computer and see if the first Rhino session can find these files. But perhaps you know already?
There’s no magic code in Rhino. Check your situation. Did you replace an object that already had a material assigned to it? Did you make a file import plugin or something else? If you aren’t creating materials yourself, and you’re not replacing objects already in the doc, then maybe you’re not actually running the code you think you are. Sorry, that’s all I can think of.
in order for the texture to show up on the mesh? Are these attributes I need to attach to the mesh? I am pretty sure this needs to include the path to the .mtl and .png files associated with the mesh.
Materials are not my forte. Looking for a little help on what to do with the mtllib file and .jpg in order to get textures to appear on my mesh imported with a script.
I searched the forum but have not yet discovered how to do this.
I am writing my own .obj file imported for Rhino. Parts of it are working but I do not understand how to use the script in order to get Rhino to use the mtllib and .jpg files associated with the mesh in order for the texture to be displayed. I can manually add the texture and then it is displayed but there should be a way to do this from the script as this is essentially what Rhino’s Import tool does.
When you use Rhino’s Import tool it automatically looks in the same folder as the .obj and uses them to create texture for the mesh. Somehow it gets Rhino to create a material using these files.
Pretty much lost and so far not getting help from McNeel or finding useful information with a Forum search.
Thanks for your help. I understand how to apply the material index to the object in Rhino. But I am not clear on how to assign the .png when generating the material using something like these lines in the link you provided:
def AddMaterial():
# materials are stored in the document's material table
index = scriptcontext.doc.Materials.Add()
mat = scriptcontext.doc.Materials[index]
mat.DiffuseColor = System.Drawing.Color.Chocolate
mat.SpecularColor = System.Drawing.Color.CadetBlue
mat.CommitChanges()
When I add the .png manually, I add a custom material and then click on Color and assign it to the .pgn file and the textures show up. What would be the right lines to use in the material definition lines above to accomplish this in the script?