Browse Source

Add custom LOD selector

David Catuhe 6 years ago
parent
commit
cb986439ad
2 changed files with 8 additions and 1 deletions
  1. 1 0
      dist/preview release/what's new.md
  2. 7 1
      src/scene.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -46,6 +46,7 @@
 
 ### Core Engine
 
+- Added support for `scene.customLODSelector` to let users define their own LOD rules ([Deltakosh](https://github.com/deltakosh))
 - Added `animatable.onAnimationLoopObservable` ([Deltakosh](https://github.com/deltakosh))
 - Added `animationGroup.onAnimationLoopObservable` ([Deltakosh](https://github.com/deltakosh))
 - Added FlyCamera for free navigation in 3D space, with a limited set of settings ([Phuein](https://github.com/phuein))

+ 7 - 1
src/scene.ts

@@ -591,6 +591,12 @@ export class Scene extends AbstractScene implements IAnimatable {
      */
     public onMeshImportedObservable = new Observable<AbstractMesh>();
 
+    /**
+     * Gets or sets a user defined funtion to select LOD from a mesh and a camera. 
+     * By default this function is undefined and Babylon.js will select LOD based on distance to camera
+     */
+    public customLODSelector: (mesh: AbstractMesh, camera: Camera) => Nullable<AbstractMesh>;
+
     // Animations
 
     /** @hidden */
@@ -3891,7 +3897,7 @@ export class Scene extends AbstractScene implements IAnimatable {
             }
 
             // Switch to current LOD
-            const meshLOD = mesh.getLOD(this.activeCamera);
+            const meshLOD = this.customLODSelector ? this.customLODSelector(mesh, this.activeCamera) : mesh.getLOD(this.activeCamera);
             if (meshLOD === undefined || meshLOD === null) {
                 continue;
             }