fdeng Posted November 6, 2018 Share Posted November 6, 2018 Hi everyone, In the obj file, when an object has multi-material, the obj file loader will create several meshes. I want to only create one mesh with multi-material, but got the wrong result: I attached the obj file and the new obj file loader I modified(objFileLoader_new.js ), can anybody help to have a look why it is wrong. It troubled me a whole day now. obj.rar Quote Link to comment Share on other sites More sharing options...
Guest Posted November 6, 2018 Share Posted November 6, 2018 Pinging @kcoley Quote Link to comment Share on other sites More sharing options...
kcoley Posted November 7, 2018 Share Posted November 7, 2018 Hi @fdeng. Unfortunately, multi-materials on a single mesh is currently not supported in Babylon.js. The current way to get the obj to load would be to create multiple meshes with different material assignments. Quote Link to comment Share on other sites More sharing options...
fdeng Posted November 8, 2018 Author Share Posted November 8, 2018 @kcoley What I want is not a really a single mesh, but a mesh with BABYLON.MultiMaterial, it will have multiple submesh. my code is like: if (handledMesh.materials.length > 1) { babylonMesh.subMeshes = []; var multimat = new BABYLON.MultiMaterial("multi", scene); babylonMesh.material = multimat; for (var i = 0; i < handledMesh.materials.length; i++) { var submat = materialsFromMTLFile.materials[handledMesh.materials]; multimat.subMaterials.push(submat); var submesh = new BABYLON.SubMesh(i, 0, handledMesh.positions.length/3, handledMesh.spans[0], handledMesh.spans[1], babylonMesh); } } else { babylonMesh.material = materialsFromMTLFile.materials[handledMesh.materials[0]]; } You can have a look of my entire code in the attachment in the top post Quote Link to comment Share on other sites More sharing options...
kcoley Posted November 8, 2018 Share Posted November 8, 2018 @fdeng, gotcha, multiple submeshes makes sense. I'll take a look at your version. Quote Link to comment Share on other sites More sharing options...
kcoley Posted November 8, 2018 Share Posted November 8, 2018 @fdeng I took a quick read-through and one thing that seems to be missing is adding the submesh to the your handledMesh array: Something like this: handledMesh.subMeshes.push(submesh); This playground may be a good reference in getting MultiMaterials to work with multiple submeshes if you haven't seen this one yet. https://www.babylonjs-playground.com/#28EUMN#21 Let me know if that helps. Quote Link to comment Share on other sites More sharing options...
fdeng Posted November 8, 2018 Author Share Posted November 8, 2018 Hi @kcoley It seems not the reason, when create a submesh like below, var submesh = new BABYLON.SubMesh(..., mesh); Actually the created submesh will be pushed to subMeshes array of the parent mesh automatically. You can verify it in this new PG: https://www.babylonjs-playground.com/#28EUMN#24 I removed these push actions: sphere.subMeshes.push(submesh1); sphere.subMeshes.push(submesh2); sphere.subMeshes.push(submesh3); sphere.subMeshes.push(submesh4); sphere.subMeshes.push(submesh5); sphere.subMeshes.push(submesh6); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.