浏览代码

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

David Catuhe 10 年之前
父节点
当前提交
96d885f17c
共有 4 个文件被更改,包括 83 次插入56 次删除
  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();
             var distanceToCamera = (boundingSphere ? boundingSphere : this.getBoundingInfo().boundingSphere).centerWorld.subtract(camera.position).length();
             if (this._LODLevels[this._LODLevels.length - 1].distance > distanceToCamera) {
             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;
                 return this;
             }
             }
             for (var index = 0; index < this._LODLevels.length; index++) {
             for (var index = 0; index < this._LODLevels.length; index++) {
@@ -178,9 +181,15 @@ var BABYLON;
                         level.mesh._preActivate();
                         level.mesh._preActivate();
                         level.mesh._updateSubMeshesBoundingInfo(this.worldMatrixFromCache);
                         level.mesh._updateSubMeshesBoundingInfo(this.worldMatrixFromCache);
                     }
                     }
+                    if (this.onLODLevelSelection) {
+                        this.onLODLevelSelection(distanceToCamera, this, level.mesh);
+                    }
                     return level.mesh;
                     return level.mesh;
                 }
                 }
             }
             }
+            if (this.onLODLevelSelection) {
+                this.onLODLevelSelection(distanceToCamera, this, this);
+            }
             return this;
             return this;
         };
         };
         Object.defineProperty(Mesh.prototype, "geometry", {
         Object.defineProperty(Mesh.prototype, "geometry", {
@@ -1116,7 +1125,6 @@ var BABYLON;
             return tube;
             return tube;
         };
         };
         // Decals
         // 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) {
         Mesh.CreateDecal = function (name, sourceMesh, position, normal, size, angle) {
             if (angle === void 0) { angle = 0; }
             if (angle === void 0) { angle = 0; }
             var indices = sourceMesh.getIndices();
             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]);
                 result.normal = new BABYLON.Vector3(normals[vertexId * 3], normals[vertexId * 3 + 1], normals[vertexId * 3 + 2]);
                 return result;
                 return result;
             };
             };
+            // Inspired by https://github.com/mrdoob/three.js/blob/eee231960882f6f3b6113405f524956145148146/examples/js/geometries/DecalGeometry.js
             var clip = function (vertices, axis) {
             var clip = function (vertices, axis) {
                 if (vertices.length === 0) {
                 if (vertices.length === 0) {
                     return vertices;
                     return vertices;

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

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

文件差异内容过多而无法显示
+ 58 - 49
babylon.2.1-alpha.debug.js


文件差异内容过多而无法显示
+ 4 - 4
babylon.2.1-alpha.js