Nodragem Posted November 23, 2018 Share Posted November 23, 2018 So basically, I am importing meshes from a babylon file; they are tiles for a maze. I clone them to create several rotation-wise clones of these tiles and obtain the full set of tiles. Then based on the results of a maze generator I clone the tiles of my full set of tiles in the right positions to make my maze. Here the results before merge (sorry for the ugly materials and textures, I was testing stuffs): And here is the hierarchy: So now, I am going through all the meshes of the maze, and I skip the meshes with 0 vertices while putting the meshes with same material in the same group, then I merge the different group of meshes: MergeMeshes(){ let groupedMeshes: IDictionary = {} let children = this.root.getChildMeshes(false); for (let mesh of children){ if(mesh.getTotalVertices() == 0) continue; // go to next mesh if(mesh.material){ if(!(mesh.material.name in groupedMeshes) ) groupedMeshes[mesh.material.name] = [] groupedMeshes[mesh.material.name].push(mesh); } } for (let key in groupedMeshes){ let newMesh = BABYLON.Mesh.MergeMeshes(groupedMeshes[key], true); if (newMesh) newMesh.parent = this.root; } let exparents = this.root.getChildTransformNodes(); for(let parent of exparents){ if(!parent.name.endsWith('merged')) parent.dispose(); } } And I get my meshes merged into that: But good news, the grouping by material did worked: I cannot find out what I am doing wrong! ? my code was working with mock tiles I was generating with code. Hence I have one main suspect: - the fact that I clone clones! (I make clones of my tiles to create the full tileset, then I clone these tiles, which can be original meshes or clones, to make the maze) I believe that when I merge clones of clones, the merge function is taking into account the position of the first clone (which here was [0,0,0]), explaining the results above. To test my hypothesis, I set the position of the clones of my tileset in a particular fashion to see if the resulting merged mesh will be different / dependent on these new positions. Here are the positions that I used for the tileset clones (instead of having them all at [0,0,0]) (the top row are original meshes, while the other rows are rotated clones): Now here is the results of the mergeMeshes() function when it tries to merge the same maze as on the first screenshot: I think that there is obviously something weird happening when merging clones of clones. It seems that the merge function is mixing the position of the tiles in the tilesets and the position of the tiles in the maze. I think that a simple solution would be to transform the clones in my tileset into real meshes. Any idea of how to transform a clone into a real mesh? Quote Link to comment Share on other sites More sharing options...
Sebavan Posted November 23, 2018 Share Posted November 23, 2018 you can call makeGeometryUnique I guess top ensures each piece of geometry is unique. Quote Link to comment Share on other sites More sharing options...
Nodragem Posted November 24, 2018 Author Share Posted November 24, 2018 Yeah!! I was so sure there was some function like that and I was playing around without success with the auto-completion yesterday writing things like "unique", "makeUnique". I am happy to know that I was not crazy after all, gonna have another try today and let you know if it worked. NOTE for others: It looks like that the issue I have with merging clones of clones happens also when making instances of clones. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Nodragem Posted November 24, 2018 Author Share Posted November 24, 2018 mmmhh, does not seem to solve the problem. My second suspect is that I have empty meshes instead of transform nodes as parent of my tiles... Quote Link to comment Share on other sites More sharing options...
Nodragem Posted November 24, 2018 Author Share Posted November 24, 2018 I made it works!! Finally! So this is definitely because my tile's parents were exported as meshes and not as transform nodes! I replaced the parent Mesh of my tiles with a TransformNode like so: if(newtile.getChildMeshes()[0]){ // NOTE that it works without making the Geometry Unique! newtile = newtile.getChildMeshes()[0] //.makeGeometryUnique(); } let root_tile = new BABYLON.TransformNode('root.'+name, newtile.getScene()); newtile.parent = root_tile; And it worked! Hence, I guess there are two things that might be asked: - is that normal that the merge works when I use TransformNodes as parent of my tiles but fails (i.e. does weird things) when using Meshes as parent of my tiles? - could the Blender exporter export the Empty as TransformNode? It seems to make sense. Quote Link to comment Share on other sites More sharing options...
Sebavan Posted November 25, 2018 Share Posted November 25, 2018 On 11/24/2018 at 6:17 PM, Nodragem said: is that normal that the merge works when I use TransformNodes as parent of my tiles but fails (i.e. does weird things) when using Meshes as parent of my tiles? I guess it depends of the code and it might also be cloning from the clone as moving to a new transformNode kind of break the clone of clone ? On 11/24/2018 at 6:17 PM, Nodragem said: could the Blender exporter export the Empty as TransformNode? It seems to make sense. Sounds like a nice plan but not sure you would not have the same clone troubles ??? Quote Link to comment Share on other sites More sharing options...
Nodragem Posted November 29, 2018 Author Share Posted November 29, 2018 @Sebavan to change the empty mesh for a transform node solves my problem, hence yes I believe that if the Blender exporter was exporting Empty objects into Transform Nodes I would have not experienced the problem. At this stage, I do not think that the problem is due to clones of clones any more. Quote Link to comment Share on other sites More sharing options...
Sebavan Posted November 29, 2018 Share Posted November 29, 2018 Thanks 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.