Dad72 Posted February 16, 2016 Share Posted February 16, 2016 Is it possible to verify that two objects can be merged before the merged. for exemple: if(BABYLON.Mesh.isMerged(myGroupObjets) == true) { // merge possible BABYLON.Mesh.MergeMeshes(myGroupObjets); } I can not find isMerged or equivalent function. I think this could be an interesting feature to check that the object can be merged together because we merge objects that share the same textures. Quote Link to comment Share on other sites More sharing options...
Temechon Posted February 16, 2016 Share Posted February 16, 2016 Not, it's not possible. However, it would be very easy to do it with tags: http://doc.babylonjs.com/tutorials/How_to_use_the_Tags_System Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted February 16, 2016 Share Posted February 16, 2016 I have written a heterogeneous merge for Dialog extension. Was assembling a "string" of Letter mesh clones, then would combine them until the material of the next letter was different. Start a new merge after that. If you did not care that they be "sequential" meshes, you could do a first pass to get all the unique materials first. Then merge. If someone is loading the same texture over and over in different materials, they need to start with just better organization. If it helps, I made sure if a name of a material matches one already loaded, the reference to the first material is returned, skipping the 2nd load / material. This is helpful for cross .babylon sharing of Materials. For Blender exporter at least, the name of the .babylon file is prefixed, "filename.material", to avoid collision by default. There is an option to over ride namespace. If namespace was over ridden to be "shared", material would be "shared.material". I think the function checking whether a single merge is possible is kind of a crutch. This kind of thing should be known at the design time, or you should just do them in batches, like I do. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 16, 2016 Author Share Posted February 16, 2016 I will try to create a function that checks whether the textures used by the object are identical. Thank you for your ideas. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted February 16, 2016 Share Posted February 16, 2016 Just remember that meshes are sub meshed by material not texture. You cannot merge 2 meshes with the same texture, only material. You could have more than one texture per mesh. If you found a texture match, assign one's material to the other before merge. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 16, 2016 Author Share Posted February 16, 2016 ah, yes, the same material . I noted. thank you JC Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 17, 2016 Author Share Posted February 17, 2016 I made this function. do you think this is enough? var isMerged = function(listeMeshes) { var result = false; for(var i = 0; i < listeMeshes.length; i++) { if(listeMeshes[0].material == listeMeshes.material) { result = true; continue; } else { result = false; break; } } return result; }; Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted February 17, 2016 Share Posted February 17, 2016 Might be the language problem, but I think you mean "isMergeable". The concept is right, but think there is are bugs in your program. First, you never reference i. Your test asks "is the reference of material of mesh 0 the same as the reference to the material of an array of meshes. I do not write javascript for this reason. This would never compile in Typescript. My javascript is not good, but something like this should work: var isMergeable = function(listMeshes) { var result = listMeshes.length > 1; var mat = listMeshes[0].material; for(var i = 1; i < listMeshes.length; i++) { if(listMeshes.material != mat) { result = false; break; } } return result; }; Dad72 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 17, 2016 Author Share Posted February 17, 2016 Yes I forget i Thank you for the fix. I think you also you never reference i if(listMeshes.material != mat) { => if(listMeshes.material != mat) { 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.