Jump to content

Dynamically changing LOD distances


jdurrant
 Share

Recommended Posts

Once LOD has been automatically created with the MESH.simplify function, is it possible to change the cutoff distances? I'd like to be able to adjust these distances dynamically based on the frame rate, as an optimization strategy. Thanks!

Link to comment
Share on other sites

Seems to work! The code is pretty trivial, but in case it helps others:

function adjustLODDistances(dist1: number, dist2: number, dist3ForNull: number) {
    for (let i = 0; i < scene.meshes.length; i++) {
        let m =scene.meshes[i];

        if (m.hasLODLevels === true) {
            // Get the current LOD levels
            let CurLODDist1 = m._LODLevels[0].distance;
            let CurLODDist2 = m._LODLevels[1].distance;
            let CurLODDist3 = m._LODLevels[2].distance;

            // Get the LOD meshes at those levels.
            let lodMesh1 = m.getLODLevelAtDistance(CurLODDist1);
            let lodMesh2 = m.getLODLevelAtDistance(CurLODDist2);
            let lodMesh3 = m.getLODLevelAtDistance(CurLODDist3);

            // Remove those levels from the mesh
            m.removeLODLevel(lodMesh1);
            m.removeLODLevel(lodMesh2);
            m.removeLODLevel(lodMesh3);

            // Add them back in, with new distances
            m.addLODLevel(dist1, lodMesh1);
            m.addLODLevel(dist2, lodMesh2);
            m.addLODLevel(dist3ForNull, lodMesh3);
        }
    }
}

 

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