I am developing a MacOS program using MacOS MetalKit and ModelIO. The ultimate goal is to use the 3D model to analyze the acoustic properties of a performance space. Initially I'm just creating a visual image of the space (stage, walls, seating, etc). I create a wavefront file (.obj and accompanying .mtl file).
I can define the vertex color for every vertex in the .obj file. But I would like to use the Kd properties of the mtl file to set the color so that specific colors are associated with specific named materials in the mtl file.
I use ModelIO to create an asset and then extract both the modelio mesh and metal mesh. Here is the bit of Swift code:
// Extract both the MetalKit meshes and the original ModelIO meshes var meshes: (modelIOMeshes: [MDLMesh], metalKitMeshes: [MTKMesh]) meshes = try MTKMesh.newMeshes(asset: asset, device: device)
I see all of the mtl properties for all of the 147 submeshes in the imported modelio data.
If I specify the vertex colors in the obj file then I see all of those colors in the 147 metalKitMeshes submeshes. But if I do not specify all of the vertex colors in the obj file then all colors in the metalKitMeshes submeshes are Black (0,0,0). The colors specified in the mtl file are ignored.
The primary question: Is there a way to use the material colors in the mtl file to automatically set the metal submesh colors?
Secondary question: In the more general case, what is the best way to convey all of the material parameters from the modelio data to the shader?
I asked this on the Apple Developer forum, but got no response. I also asked on StackOverflow but then realized that this may be a more appropriate forum.
I can import my wavefront file into Blender and all of the objects in the scene are rendered with the correct colors from the materials file. So the structures of my .obj and .mtl files seem to be correct.