Jump to content

Optimize the scene


juanmajr93
 Share

Recommended Posts

Hi, 

There is nothing implemented in the framework. But it's easy to do it!

For each frame, do : 

  • For all meshes, do :
    • Compute distance between camera and the current mesh
    • if the distance is > MAX_DISTANCE, do : mesh.setEnabled(false);
    • Else, do : mesh.setEnabled(true);

"For each frame' = scene.registerBeforeRender()

"For all emshes" = scene.meshes

"Compute Distance" = BABYLON.Vector3.DistanceSquared(camera.position, mesh.position)

Good luck :)

Link to comment
Share on other sites

It sounds like we're talking about the same thing. My solution does't disable meshes. It only checks if it should be rendered depending on camera distance. 

Apart from that Babylon JS often doesn't render meshes behind the camera to save process power, so that part is already optimized. 

Perhaps you mean like a Silent Hill fog effect or how would you wish the distance to be visually shortened?

Link to comment
Share on other sites

I would suggest that you try a combination of scene fog: https://doc.babylonjs.com/tutorials/environment and LOD as I linked above. The fog doesn't exclude meshes from being rendered, but you can set for example:

    scene.fogMode = BABYLON.Scene.FOGMODE_LINEAR;

    scene.fogColor = new BABYLON.Color3(0.9, 0.9, 0.85);
    scene.fogStart = 20.0;
    scene.fogEnd = 25.0;

And on all relevant meshes run: `mesh.addLODLevel(30, null);` 

And on active camera set `camera.maxZ = 30;`

Hiding the meshes wouldn't be noticed since the fog ends before their condition is met. 

Link to comment
Share on other sites

I doubt a plane mesh would take much to render the entire of it?

If it's on a flat surface I guess you would have a plane as big as the fog ends, move it under your character and position the plane's texture with .uOffset and .vOffset, if I follow you correct. Maybe even have different planes next to each other with LOD if you have giant textures.

I could very well be misunderstanding your question now.

Okay, you can use fog and `camera.maxZ = 30;` instead of LOD on all meshes. I did not know that. 

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