Jump to content

Optimizing scene: MergeMeshes makes a copy


Recommended Posts



I have an array of boxes (which are all cloned from an initial box), placed next to each other (as one long box). I want to merge these boxes together.


Using the following function, I've managed to merge them together (as far as I know):

var newMesh = BABYLON.Mesh.MergeMeshes(sceneObjects.boxes, false, false,false); 

My questions are:


1. If I move this newMesh (e.g. newMesh.position.x = 100), I see my old boxes at the exact same position too. How can I remove these ''old'' boxes?


2. I quote this wiki: https://github.com/BabylonJS/Babylon.js/wiki/How-to-merge-meshes:




Note: Careful, when you merge cloned mesh, you need to update the world matrix of the mesh with computeWorldMatrix before calling the function.

So if I understand correctly, I need to call computeWorldMatrix() on the mesh I clone? Not on the newMesh object?

Link to comment
Share on other sites

Hi Threedy and welcome to the forum!


As you can see here http://doc.babylonjs.com/classes/2.2/Mesh#static-mergemeshes-meshes-disposesource-allow32bitsindices-meshsubclass-rarr-mesh-classes-2-2-mesh- the second parameter is about disposing the source meshes. So just try to use it with the second parameter true:

var newMesh = BABYLON.Mesh.MergeMeshes(sceneObjects.boxes, true, false, false); 

By the way: do you know the babylon playground: http://www.babylonjs-playground.com/


You can create examples there and show us directly what problem you have and we can edit the code and try things out to help you solve your problem. I made a playground that shows your problem: http://www.babylonjs-playground.com/#1GCRKJ#0


Try it out and switch between line 36 and 37 to see the difference. Hope that helps :) Let us know if that answered your question or if we can help you with anything else!

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...