styxxx Posted November 27, 2015 Share Posted November 27, 2015 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? Also some interesting thing: merging only works with the code posted here https://github.com/BabylonJS/Babylon.js/wiki/How-to-merge-meshesUsing 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 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 27, 2015 Share Posted November 27, 2015 Hi, You can not merge the instances. Quote Link to comment Share on other sites More sharing options...
styxxx Posted November 28, 2015 Author Share Posted November 28, 2015 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? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 28, 2015 Share Posted November 28, 2015 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 reactionMost 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 Quote Link to comment Share on other sites More sharing options...
styxxx Posted November 28, 2015 Author Share Posted November 28, 2015 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#0Just noticed that it also happens with just 2 objects. Doesn't need to be 200 like in the playground example. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 28, 2015 Share Posted November 28, 2015 Ok this bug comes from the instance merge which is not supported. If you merge clones instead it works:http://www.babylonjs-playground.com/#2EGQ6C#1 Btw I will add support for instances merging in the next commit styxxx 1 Quote Link to comment Share on other sites More sharing options...
styxxx Posted November 28, 2015 Author Share Posted November 28, 2015 Quote Link to comment Share on other sites More sharing options...
Venerated1 Posted April 8, 2017 Share Posted April 8, 2017 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 10, 2017 Share Posted April 10, 2017 Can you tell me how we can improve the doc? http://doc.babylonjs.com/tutorials/how_to_use_instances It is always tough to create good documentation so please do not hesitate to comment/update it 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.