maca134 Posted July 20, 2015 Share Posted July 20, 2015 So im pretty new to babylonjs, getting my head around most of it but i wanted to ask for some "good practices" advice. Im creating a map preview for a game, i have the actual map working nicely but wanted to know the best way to create 1000s of small, cuboid shapes to represent buildings. I found when i simply dumped the meshes on the map, fps dropped massively. Are there any existing approaches to this kind of problem around? Cheers Quote Link to comment Share on other sites More sharing options...
iiceman Posted July 20, 2015 Share Posted July 20, 2015 Hi maca and welcome to the forum. Did you already have a look at octrees (http://www.babylonjs.com/?OCTREE) and instances (http://www.babylonjs.com/?INSTANCES)? That should help you creating alot of meshes. Let us know how it is working for you. Maybe you could create a playground (www.babylonjs-playground.com) to illustrate the fps drop and people can help you directly by editing your code and playing around with it. Quote Link to comment Share on other sites More sharing options...
jerome Posted July 20, 2015 Share Posted July 20, 2015 SPS could be a good option to set 1000s of cubic shapes in a single mesh : https://github.com/BabylonJSX/SolidParticleSystem Quote Link to comment Share on other sites More sharing options...
davrous Posted July 20, 2015 Share Posted July 20, 2015 Hello, If your small meshes are static (i.e you don't need to update them individually), you can group them to boost a lot the performance like described in my article: http://blogs.msdn.com/b/davrous/archive/2014/02/19/coding4fun-tutorial-creating-a-3d-webgl-procedural-qrcode-maze-with-babylon-js.aspx Bye, David Quote Link to comment Share on other sites More sharing options...
davrous Posted July 20, 2015 Share Posted July 20, 2015 Link to the doc: http://doc.babylonjs.com/page.php?p=22451 Quote Link to comment Share on other sites More sharing options...
Temechon Posted July 20, 2015 Share Posted July 20, 2015 You also have this function : http://doc.babylonjs.com/page.php?p=25147static MergeMeshes(meshes, disposeSource, allow32BitsIndices, meshSubclass) → Mesh Quote Link to comment Share on other sites More sharing options...
jerome Posted July 20, 2015 Share Posted July 20, 2015 here is a quick example with SPS : http://www.babylonjs-playground.com/#2KSQ1R#565000 random buildings set once, 1 mesh only just change line 36 the var fact to space them maca134 and iiceman 2 Quote Link to comment Share on other sites More sharing options...
maca134 Posted July 20, 2015 Author Share Posted July 20, 2015 Thats seems to be what im looking for, thank you very much Quote Link to comment Share on other sites More sharing options...
jerome Posted July 20, 2015 Share Posted July 20, 2015 really big city (compared to my 2800 people village here) : http://www.babylonjs-playground.com/#2KSQ1R#57 20000 buildings, normals and world matrix recomputed each frame : 60 fps on my office laptop here maca134 1 Quote Link to comment Share on other sites More sharing options...
maca134 Posted July 21, 2015 Author Share Posted July 21, 2015 The only problem im having now is the particles disappear when the cam gets too close. Quote Link to comment Share on other sites More sharing options...
jerome Posted July 21, 2015 Share Posted July 21, 2015 disappearing when cam too close ?I just can't reproduce the problem here. Maybe is it a matter of the mesh bounding box size (just. In this case you could set this size once like explained here : http://www.html5gamedevs.com/topic/15255-is-it-possible-to-set-the-size-of-the-bounding-box/?p=86456 In the last PG example, the bounding box size could be (1500, 10, 1500) for instance. You could check it by displaying the debug layer and mark the "bounding box" menu. Quote Link to comment Share on other sites More sharing options...
maca134 Posted July 21, 2015 Author Share Posted July 21, 2015 Here is a playground that show the problemhttp://www.babylonjs-playground.com/#V78LIFixed: http://www.babylonjs-playground.com/#V78LI#3 If you move around abit the red blocks disappear Wingnut 1 Quote Link to comment Share on other sites More sharing options...
maca134 Posted July 21, 2015 Author Share Posted July 21, 2015 nvm fixed it It was the mesh bounding boxmesh.getBoundingInfo()._update(BABYLON.Matrix.Scaling(new BABYLON.Vector3(820, 100, 820)));Playground also updated for anyone in the future jerome 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 21, 2015 Share Posted July 21, 2015 Hi Maca... welcome to the forum. I see the issue. It seems to be caused by a problem or characteristic with the freeCamera. I changed to an ArcRotate, and no more disappearing parti-buildings. http://www.babylonjs-playground.com/#V78LI#4 I'll try to put some time into figuring out why this is happening... soon. Others will, too. Be well. I'm sure Jerome has started on the newest SPS feature... you know... groundHeight-sensing particle-positioning with automatic mountain and water avoidance. Yep, we're beginning a whole new world of particle positioning funcs. Might just as well (mizewell) start collecting them, because there will be 100 various SPS positioning funcs by the end of the year. You know, cloud shaped, spherical, pyramidal, stack-o-boxes, bowl-o-cheerios, etc. Oooh, how about a positioner that accepts a 3D model, and then places the PSP particles in the shape of the volume of that model? wow! 3dsMax has an 'array' thing that is very similar to one of these positioners (stacker/spreader/distributor). Sounds like farming gear, eh? Quote Link to comment Share on other sites More sharing options...
maca134 Posted July 21, 2015 Author Share Posted July 21, 2015 The block disappear when the bounding box (the black cube) here (there are 2 objects there):Goes out of shot, im presuming the engine thinks the blocks dont need rendering anymore. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 21, 2015 Share Posted July 21, 2015 Yep the rendering of a mesh is controlled by its bounding box visibility. BUT you can also ask the engine to always draw your mesh even if the engine thinks it is out of shot: mesh.alwaysSelectAsActiveMesh = true jerome 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted July 21, 2015 Share Posted July 21, 2015 didn't even know this such useful feature existed !!! DellaFree 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted July 22, 2015 Share Posted July 22, 2015 with y random rotation : http://www.babylonjs-playground.com/#2KSQ1R#58 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.