Jump to content

Instances vs. merging and merging instances


styxxx
 Share

Recommended Posts

Hi,

 

I have some ground tiles that I use. Currently I'm only using one "real" object and a lot of instances of it. But I'm wondering if it's more efficient to actually create a (bigger) merged mesh? Usually I'd assume the instances to be the better solution since it's a mesh with just a few vertices that will be referenced to. But while testing I noticed a higher fps after I merges some of the instances which seems to be possible. 
But merging instances strips the material. So how can I merge instances and keep it or reassign it afterwards? Does it even make sense or should I stick to the current solution?  :rolleyes: 

Also some interesting thing: merging only works with the code posted here https://github.com/BabylonJS/Babylon.js/wiki/How-to-merge-meshes
Using BABYLON.Mesh.MergeMeshes skyrockets the memory consumption until the whole browser tab crashes. This is a bug and shouldn't happen. Even if you're not supposed to merge instances using gigabytes of memory and freezing the tab - of course without error message in the console - seems like a rather wrong reaction ;)

Link to comment
Share on other sites

Hello,

 

ah, I noticed that the merged instances are new meshes now. It works, but the result isn't an instance, it's a new mesh. So draw calls have increased. Interesting effect. 

Still BABYLON.Mesh.MergeMeshes shouldn't crash the whole browser/tab. The developers should fix it. Maybe something like "if parameter is not a mesh throw errror in console and do nothing". Seems like you can feed anything to such functions with various results. Makes it really hard finding some error in the own code. 

After doing more research I think it's more efficient to use lots of instances of smaller floor parts than to use one huge merged floor object since one large mesh has to be completely rendered/handled if just a small part is visibe. But with lots of small parts only those visible parts need to be calculated. Right?

Link to comment
Share on other sites

 

 

Using BABYLON.Mesh.MergeMeshes skyrockets the memory consumption until the whole browser tab crashes. This is a bug and shouldn't happen. Even if you're not supposed to merge instances using gigabytes of memory and freezing the tab - of course without error message in the console - seems like a rather wrong reaction

Most of us can be pretty upset when reading this. Do you remember this is a FREE community based open source project?

 

Furthermore, if you want to be useful, please at least provide a repro case so we can fix this unworthy behavior

Link to comment
Share on other sites

Sorry, wasn't meant to sound rude or demanding. Just wanted to be helpful by pointing out some probably bug.

I created a playground, you'll need to enable the merge statement to see the effect. Since the meshes are rather simple it's not as severe as in "real life". Doesnt' have to bee 200 meshes, 
Tested it with firefox and chrome. Firefox just freezes and then reports that a script isn't working right. With chrome the tab crashes after all available memory on the machine is gone (edit: not all, but a lot; Just tested with more free mem). 

http://www.babylonjs-playground.com/#2EGQ6C#0

Just noticed that it also happens with just 2 objects. Doesn't need to be 200 like in the playground example.

Link to comment
Share on other sites

  • 1 year later...

This thread is the only way I figured out how to use instances. DK's playground there: http://www.babylonjs-playground.com/#2EGQ6C#1    ...is useful for us newbies that don't know how to use an instance properly.

    var matForStars = new BABYLON.StandardMaterial("starMat", scene);
    matForStars.emissiveColor = new BABYLON.Color3(1, 1, 1);
    matForStars.specularColor = new BABYLON.Color3(0, 0, 0);
    matForStars.diffuseColor = new BABYLON.Color3(0, 0, 0);

    var star = BABYLON.Mesh.CreateSphere("star", 1, 0.5, scene);
    star.material = matForStars;
    star.position.z = 150;
                
    // Create some instances, make a bunch of stars
    var stars = new Array();
    for (var i = 0; i < 1000; i++) {
        var random1 = (Math.random() - 0.5) * 300;		
        var random2 = (Math.random() - 0.5) * 300;
        var random3 = (Math.random() - 0.5) * 300;
                
        var magnitudeStar = Math.sqrt(random1 * random1 + random2 * random2 + random3 * random3);
                
        if (magnitudeStar < 100 || magnitudeStar > 150 ) {
            i--;
        }
        else {
            stars[i] = star.createInstance('Instance' + i);
            stars[i].position.x = random1;
            stars[i].position.y = random2;
            stars[i].position.z = random3;
        }
    }

This is a simplified version of what I ended up with.

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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