Selaa lähdekoodia

Added ```Mesh.onLODLevelSelection(distance: number, mesh: Mesh, selectedLevel: Mesh)``` callback

David Catuhe 10 vuotta sitten
vanhempi
commit
96d885f17c
4 muutettua tiedostoa jossa 83 lisäystä ja 56 poistoa
  1. 10 1
      Babylon/Mesh/babylon.mesh.js
  2. 11 2
      Babylon/Mesh/babylon.mesh.ts
  3. 58 49
      babylon.2.1-alpha.debug.js
  4. 4 4
      babylon.2.1-alpha.js

+ 10 - 1
Babylon/Mesh/babylon.mesh.js

@@ -169,6 +169,9 @@ var BABYLON;
             }
             var distanceToCamera = (boundingSphere ? boundingSphere : this.getBoundingInfo().boundingSphere).centerWorld.subtract(camera.position).length();
             if (this._LODLevels[this._LODLevels.length - 1].distance > distanceToCamera) {
+                if (this.onLODLevelSelection) {
+                    this.onLODLevelSelection(distanceToCamera, this, this._LODLevels[this._LODLevels.length - 1].mesh);
+                }
                 return this;
             }
             for (var index = 0; index < this._LODLevels.length; index++) {
@@ -178,9 +181,15 @@ var BABYLON;
                         level.mesh._preActivate();
                         level.mesh._updateSubMeshesBoundingInfo(this.worldMatrixFromCache);
                     }
+                    if (this.onLODLevelSelection) {
+                        this.onLODLevelSelection(distanceToCamera, this, level.mesh);
+                    }
                     return level.mesh;
                 }
             }
+            if (this.onLODLevelSelection) {
+                this.onLODLevelSelection(distanceToCamera, this, this);
+            }
             return this;
         };
         Object.defineProperty(Mesh.prototype, "geometry", {
@@ -1116,7 +1125,6 @@ var BABYLON;
             return tube;
         };
         // Decals
-        // Inspired by https://github.com/mrdoob/three.js/blob/eee231960882f6f3b6113405f524956145148146/examples/js/geometries/DecalGeometry.js
         Mesh.CreateDecal = function (name, sourceMesh, position, normal, size, angle) {
             if (angle === void 0) { angle = 0; }
             var indices = sourceMesh.getIndices();
@@ -1153,6 +1161,7 @@ var BABYLON;
                 result.normal = new BABYLON.Vector3(normals[vertexId * 3], normals[vertexId * 3 + 1], normals[vertexId * 3 + 2]);
                 return result;
             };
+            // Inspired by https://github.com/mrdoob/three.js/blob/eee231960882f6f3b6113405f524956145148146/examples/js/geometries/DecalGeometry.js
             var clip = function (vertices, axis) {
                 if (vertices.length === 0) {
                     return vertices;

+ 11 - 2
Babylon/Mesh/babylon.mesh.ts

@@ -28,13 +28,13 @@
             return Mesh._DEFAULTSIDE;
         }
 
-
         // Members
         public delayLoadState = Engine.DELAYLOADSTATE_NONE;
         public instances = new Array<InstancedMesh>();
         public delayLoadingFile: string;
         public _binaryInfo: any;
         private _LODLevels = new Array<Internals.MeshLODLevel>();
+        public onLODLevelSelection: (distance: number, mesh: Mesh, selectedLevel: Mesh) => void;
 
         // Private
         public _geometry: Geometry;
@@ -187,6 +187,9 @@
             var distanceToCamera = (boundingSphere ? boundingSphere : this.getBoundingInfo().boundingSphere).centerWorld.subtract(camera.position).length();
 
             if (this._LODLevels[this._LODLevels.length - 1].distance > distanceToCamera) {
+                if (this.onLODLevelSelection) {
+                    this.onLODLevelSelection(distanceToCamera, this, this._LODLevels[this._LODLevels.length - 1].mesh);
+                }
                 return this;
             }
 
@@ -194,15 +197,21 @@
                 var level = this._LODLevels[index];
 
                 if (level.distance < distanceToCamera) {
-
                     if (level.mesh) {
                         level.mesh._preActivate();
                         level.mesh._updateSubMeshesBoundingInfo(this.worldMatrixFromCache);
                     }
+
+                    if (this.onLODLevelSelection) {
+                        this.onLODLevelSelection(distanceToCamera, this, level.mesh);
+                    }
                     return level.mesh;
                 }
             }
 
+            if (this.onLODLevelSelection) {
+                this.onLODLevelSelection(distanceToCamera, this, this);
+            }
             return this;
         }
 

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 58 - 49
babylon.2.1-alpha.debug.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 4 - 4
babylon.2.1-alpha.js