Jump to content

Philosophical question


kevinImperial
 Share

Recommended Posts

Hi everyone,

 

A bit of a babylon philosophical question here. I want to deal with a massive amount of spheres, and want to keep it as smooth as possible. I thought I would hide spheres which are no longer in the view frustum. Now that I got that code, I wonder what is the most efficient, either to hide the meshes by selecting and applying .visibility = 0, or if it is better to dispose of the meshes ?

If you're curious, in my case I only rotate the camera and don't move it, and I know what I have to show thanks to the angles within a database. 

Currently, Babylon still feels a bit too slow to my taste with many elements hidden. Should I change my code to dispose of the meshes and recreate them instead of hiding/showing ?

 

Best,

Kevin

 

Link to comment
Share on other sites

BJS manages the frustum for you and doesn't render what isn't visible. So you don't really need to set the visibility manually.

Disposing and recreating the meshes is not a good idea because this will massively trigger the garbage collector.

The best approach would be imho :

- to lower the number of sphere to the necessary amount for visibility, it is to say to recycle your spheres : when no longer visible, recycle it to another visible sphere. With dozens or hundreds of sphere only, you can then simulate the presence of dozen of thousands

- to use instances or a solid particle system, to reduce the number of draw calls

If you have a PG demo, we could help you to tweak it to achieve your goal

Link to comment
Share on other sites

Thanks guys, this is good feedback and can be very useful. 

My code is a bit massive to turn into a demo unfortunately (connection to database, etc).

Currently I use clones of one sphere because I want to give different materials to different spheres, and I understood that using instances would not allow me to give different materials.

I like the idea of moving the spheres position, but it still mean that at some point I need to set up a limited number of instances to draw...

Fenomas, currently the spheres do not rotate, but they will in the future. (I intend to have the ones close to the camera rotate, and the ones far either low quality spheres or sprites, the issue might come from colour though).

Link to comment
Share on other sites

Quote

Currently I use clones of one sphere because I want to give different materials to different spheres, and I understood that using instances would not allow me to give different materials.

If, by different materials, you mean different textures/images, you could use the SPS. The SPS uses only one material but you can assign different sub-parts from a single image (texture) to different particles like you would do with a texture atlas.

http://doc.babylonjs.com/overviews/Solid_Particle_System#uvs

Clones are an easy way to duplicate meshes but they lead to as many draw calls as the number of clones. Instances or SPS only makes one draw call.

Link to comment
Share on other sites

Alright, will have a read into this, thanks a lot :)

Will keep the idea of a limited number of spheres moving. While I'm not a big fan of a limited number of elements to display, it might have to be used as a safety net. Out of the blue, how many spheres do you believe Babylon can render at once ? And how many sprites ?

Link to comment
Share on other sites

Well, it mostly depends on your device

but BJS can easily handle dozens of thousands sprites (maybe even hundred of thousands) like you can find it in many PG from this forum.

If you use the SPS, the number of vertices per sphere will be an important factor (segments parameter http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#sphere ), but you can easily animate (translation + rotation) from 8 to 10 000 boxes for instance on a decent computer.

Link to comment
Share on other sites

Just create the sphere once, and then set the main instance of it to disabled with 

mesh.isEnabled(0); and it will drop it out of all draw stacks.

 

now when ever you need to make that sphere just do a originalMesh.clone() or copy depending on how unique you need it to be, and that will make it so it's all one draw call.

Link to comment
Share on other sites

Here is an example l with about 195000 triangles each rotating. Of course with spheres you have a lot more vertices to deal with but it will give you some idea of the power of SPS.

http://www.babylonjs-playground.com/#1LIVJD#3

Thank you Jerome for reminding me about link

Edited by JohnK
added link
Link to comment
Share on other sites

4 hours ago, jerome said:

If, by different materials, you mean different textures/images, you could use the SPS. The SPS uses only one material but you can assign different sub-parts from a single image (texture) to different particles like you would do with a texture atlas.

http://doc.babylonjs.com/overviews/Solid_Particle_System#uvs

Clones are an easy way to duplicate meshes but they lead to as many draw calls as the number of clones. Instances or SPS only makes one draw call.

I'm not sure if I understood properly, but is there a way for me to use instances and give different colours to the different instances ? e.g: planets and according to their temperature change their colours.

Thanks everyone for the feedback , it's really helpful to be pushed in some directions I would have not thought of quickly on my own :)

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