Kaynağa Gözat

Merge pull request #388 from raananw/master

Success callback after height map created
David Catuhe 10 yıl önce
ebeveyn
işleme
1177bad1f2
2 değiştirilmiş dosya ile 23 ekleme ve 4 silme
  1. 12 2
      Babylon/Mesh/babylon.mesh.js
  2. 11 2
      Babylon/Mesh/babylon.mesh.ts

+ 12 - 2
Babylon/Mesh/babylon.mesh.js

@@ -841,7 +841,7 @@ var BABYLON;
         };
 
         // Geometric tools
-        Mesh.prototype.applyDisplacementMap = function (url, minHeight, maxHeight) {
+        Mesh.prototype.applyDisplacementMap = function (url, minHeight, maxHeight, onSuccess) {
             var _this = this;
             var scene = this.getScene();
 
@@ -860,6 +860,11 @@ var BABYLON;
                 var buffer = context.getImageData(0, 0, heightMapWidth, heightMapHeight).data;
 
                 _this.applyDisplacementMapFromBuffer(buffer, heightMapWidth, heightMapHeight, minHeight, maxHeight);
+
+                //execute success callback, if set
+                if (onSuccess) {
+                    onSuccess(_this);
+                }
             };
 
             BABYLON.Tools.LoadImage(url, onload, function () {
@@ -1167,7 +1172,7 @@ var BABYLON;
             return tiledGround;
         };
 
-        Mesh.CreateGroundFromHeightMap = function (name, url, width, height, subdivisions, minHeight, maxHeight, scene, updatable) {
+        Mesh.CreateGroundFromHeightMap = function (name, url, width, height, subdivisions, minHeight, maxHeight, scene, updatable, onReady) {
             var ground = new BABYLON.GroundMesh(name, scene);
             ground._subdivisions = subdivisions;
 
@@ -1191,6 +1196,11 @@ var BABYLON;
                 vertexData.applyToMesh(ground, updatable);
 
                 ground._setReady(true);
+
+                //execute ready callback, if set
+                if (onReady) {
+                    onReady(ground);
+                }
             };
 
             BABYLON.Tools.LoadImage(url, onload, function () {

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

@@ -844,7 +844,7 @@
         }
 
         // Geometric tools
-        public applyDisplacementMap(url: string, minHeight: number, maxHeight: number): void {
+        public applyDisplacementMap(url: string, minHeight: number, maxHeight: number, onSuccess?: (mesh: Mesh) => void): void {
             var scene = this.getScene();
 
             var onload = img => {
@@ -862,6 +862,10 @@
                 var buffer = context.getImageData(0, 0, heightMapWidth, heightMapHeight).data;
 
                 this.applyDisplacementMapFromBuffer(buffer, heightMapWidth, heightMapHeight, minHeight, maxHeight);
+                //execute success callback, if set
+                if (onSuccess) {
+                    onSuccess(this);
+                }
             };
 
             Tools.LoadImage(url, onload,() => { }, scene.database);
@@ -1171,7 +1175,7 @@
             return tiledGround;
         }
 
-        public static CreateGroundFromHeightMap(name: string, url: string, width: number, height: number, subdivisions: number, minHeight: number, maxHeight: number, scene: Scene, updatable?: boolean): GroundMesh {
+        public static CreateGroundFromHeightMap(name: string, url: string, width: number, height: number, subdivisions: number, minHeight: number, maxHeight: number, scene: Scene, updatable?: boolean, onReady?:(mesh: GroundMesh) => void): GroundMesh {
             var ground = new GroundMesh(name, scene);
             ground._subdivisions = subdivisions;
 
@@ -1195,6 +1199,11 @@
                 vertexData.applyToMesh(ground, updatable);
 
                 ground._setReady(true);
+
+                //execute ready callback, if set
+                if (onReady) {
+                    onReady(ground);
+                }
             };
 
             Tools.LoadImage(url, onload,() => { }, scene.database);