Jump to content

Optimizing the scene


saldukoo
 Share

Recommended Posts

I'm trying to make a huge grid of rectangles run as smoothly as possible. (BABYLON.Mesh.CreateBox)

What i've done so far:

- Make them use a single material

- Create the first mesh and clone that for the rest

- Use Mesh.setEnabled() for the ones that are far away. The increase in FPS was disappointing.  When i was disabling 2480 cubes from a grid of 2500 the fps went from 21 to 24. In comparison, if I create a scene with 20 cubes it runs at max FPS.

So what is Mesh.setEnabled doing under the hood? Is there a better way to disable the rendering of a mesh? And is there anything else i should try?

Update: As a last resort i tried calling mesh.dispose() for the far-away ones and recreate them when they're near. This gives me the huge increase in FPS i was expecting! But it's a dirty solution for such a simple thing. I have to mention that i'm doing this after a click event. Would be a different scenario with more frequent calls.

Link to comment
Share on other sites

33 minutes ago, Dad72 said:

Mesh.setEnabled(false); Should not lower your fps.

You can also try the LOD system to mask distant objects

The use of octree can also help.

addLODLevel() seems perfect. Couldn't find it in Sokrate though (hint!). I'll try it out.

I read about the octree but didn't try it out yet, will do later.

31 minutes ago, Deltakosh said:

You should think about using instances or even better having on single big object

I forgot to mention that i'm going to use lots of different materials for the grid, so instances aren't an option i guess?

Although i could try creating a bunch of meshes with each material, then create instances out of them.

 

Link to comment
Share on other sites

Tried out addLODLevel(0, null) for all meshes, which essentially disables all of them.

Also tried out creating instances instead of clones.

But no noticeable increase in FPS!

I'm gonna create the playground thing tomorrow and try an octree.

Link to comment
Share on other sites

Update! As a last resort i tried calling mesh.dispose() for the far-away ones and recreate them when they're near.

This gives me the huge increase in FPS i was expecting! But it's a dirty solution for such a simple thing. If only there was undispose() :)

I have to mention that i'm doing this after a click event. Would be a different scenario with more frequent calls.

Link to comment
Share on other sites

well, if you need rectangles, it is to say planar shapes, you probably should consider using planes or grounds (or even tiledGrounds) instead of 3D boxes

I'll have far less vertices to compute

Then use instances instead of many occurrences of the same object type.

Link to comment
Share on other sites

You're right Delta, i tried  a simple experiment in the playground and it indeed did the same.

Then i tried calling dispose() on the material when calling mesh.setEnabled(false) and the FPS increased succesfully. (had to create a new material for each mesh).

So the root of my problem is that a material is clogging up the render loop. I'm gonna try and fix this now. I think I have to start cloning materials instead of referring to a single one to make this work correctly.

EDIT: tried the same in playground, working just fine without disposing the material. I just dont know anymore.

EDIT: Okay, posting the final solution. No need to clone or dispose materials. Just setting mesh.material = null; after calling mesh.setEnabled(false) and vice versa. (This will NOT set the shared material null, as I incorrectly assumed)

Thx for all the suggestions. Case closed :)

Link to comment
Share on other sites

You should not have to use mesh.material = null; after use mesh.setEnabled(false); 

I think if Deltakosh you ask a demo on the playground is to check if an error can not be corrected on setEnabled ().

Basically, reproduce problems and show a link here. You can start with existing demo and complete with setEnabled. This kind of demo is very quick to make

Link to comment
Share on other sites

1 hour ago, Dad72 said:

You should not have to use mesh.material = null; after use mesh.setEnabled(false); 

I think if Deltakosh you ask a demo on the playground is to check if an error can not be corrected on setEnabled ().

Basically, reproduce problems and show a link here. You can start with existing demo and complete with setEnabled. This kind of demo is very quick to make

I tried but couldn't reproduce it in the playground. Im out of ideas here. Will make sure to use the playground next time.

 

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