ソースを参照

new TextureAssetTask

David Catuhe 11 年 前
コミット
14eaf8be6d

+ 3 - 0
Babylon/Actions/babylon.action.js

@@ -45,6 +45,9 @@
             this._nextActiveAction.execute(evt);
 
             if (this._nextActiveAction._child) {
+                if (!this._nextActiveAction._child._actionManager) {
+                    this._nextActiveAction._child._actionManager = this._actionManager;
+                }
                 this._nextActiveAction = this._nextActiveAction._child;
             } else {
                 this._nextActiveAction = this;

+ 4 - 0
Babylon/Actions/babylon.action.ts

@@ -53,6 +53,10 @@
             this._nextActiveAction.execute(evt);
 
             if (this._nextActiveAction._child) {
+
+                if (!this._nextActiveAction._child._actionManager) {
+                    this._nextActiveAction._child._actionManager = this._actionManager
+                }
                 this._nextActiveAction = this._nextActiveAction._child;
             } else {
                 this._nextActiveAction = this;

+ 4 - 2
Babylon/Materials/textures/babylon.texture.js

@@ -8,8 +8,10 @@ var BABYLON;
 (function (BABYLON) {
     var Texture = (function (_super) {
         __extends(Texture, _super);
-        function Texture(url, scene, noMipmap, invertY, samplingMode) {
+        function Texture(url, scene, noMipmap, invertY, samplingMode, onLoad, onError) {
             if (typeof samplingMode === "undefined") { samplingMode = Texture.TRILINEAR_SAMPLINGMODE; }
+            if (typeof onLoad === "undefined") { onLoad = null; }
+            if (typeof onError === "undefined") { onError = null; }
             _super.call(this, scene);
             this.uOffset = 0;
             this.vOffset = 0;
@@ -33,7 +35,7 @@ var BABYLON;
 
             if (!this._texture) {
                 if (!scene.useDelayedTextureLoading) {
-                    this._texture = scene.getEngine().createTexture(url, noMipmap, invertY, scene, this._samplingMode);
+                    this._texture = scene.getEngine().createTexture(url, noMipmap, invertY, scene, this._samplingMode, onLoad, onError);
                 } else {
                     this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
                 }

+ 2 - 2
Babylon/Materials/textures/babylon.texture.ts

@@ -45,7 +45,7 @@
         private _cachedCoordinatesMode: number;
         private _samplingMode: number;
 
-        constructor(url: string, scene: Scene, noMipmap?: boolean, invertY?: boolean, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE) {
+        constructor(url: string, scene: Scene, noMipmap?: boolean, invertY?: boolean, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE, onLoad: () => void = null, onError: () => void = null) {
             super(scene);
 
             this.name = url;
@@ -62,7 +62,7 @@
 
             if (!this._texture) {
                 if (!scene.useDelayedTextureLoading) {
-                    this._texture = scene.getEngine().createTexture(url, noMipmap, invertY, scene, this._samplingMode);
+                    this._texture = scene.getEngine().createTexture(url, noMipmap, invertY, scene, this._samplingMode, onLoad, onError);
                 } else {
                     this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
                 }

+ 4 - 0
Babylon/Mesh/babylon.mesh.js

@@ -570,6 +570,10 @@ var BABYLON;
                 results.push(this.material);
             }
 
+            if (this.skeleton) {
+                results.push(this.skeleton);
+            }
+
             return results;
         };
 

+ 4 - 0
Babylon/Mesh/babylon.mesh.ts

@@ -576,6 +576,10 @@
                 results.push(this.material);
             }
 
+            if (this.skeleton) {
+                results.push(this.skeleton);
+            }
+
             return results;
         }
 

+ 0 - 2
Babylon/Shaders/oculusDistortionCorrection.fragment.fx

@@ -18,8 +18,6 @@ vec2 HmdWarp(vec2 in01) {
 	return LensCenter + Scale * rvector;
 }
 
-
-
 void main(void)
 {
 	vec2 tc = HmdWarp(vUV);

+ 44 - 0
Babylon/Tools/babylon.assetsManager.js

@@ -127,6 +127,42 @@
     })();
     BABYLON.ImageAssetTask = ImageAssetTask;
 
+    var TextureAssetTask = (function () {
+        function TextureAssetTask(name, url, noMipmap, invertY, samplingMode) {
+            if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
+            this.name = name;
+            this.url = url;
+            this.noMipmap = noMipmap;
+            this.invertY = invertY;
+            this.samplingMode = samplingMode;
+            this.isCompleted = false;
+        }
+        TextureAssetTask.prototype.run = function (scene, onSuccess, onError) {
+            var _this = this;
+            var onload = function () {
+                _this.isCompleted = true;
+
+                if (_this.onSuccess) {
+                    _this.onSuccess(_this);
+                }
+
+                onSuccess();
+            };
+
+            var onerror = function () {
+                if (_this.onError) {
+                    _this.onError(_this);
+                }
+
+                onError();
+            };
+
+            this.texture = new BABYLON.Texture(this.url, scene, this.noMipmap, this.invertY, this.samplingMode, onload, onError);
+        };
+        return TextureAssetTask;
+    })();
+    BABYLON.TextureAssetTask = TextureAssetTask;
+
     var AssetsManager = (function () {
         function AssetsManager(scene) {
             this._tasks = new Array();
@@ -162,6 +198,14 @@
             return task;
         };
 
+        AssetsManager.prototype.addTextureTask = function (taskName, url, noMipmap, invertY, samplingMode) {
+            if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
+            var task = new TextureAssetTask(taskName, url, noMipmap, invertY, samplingMode);
+            this._tasks.push(task);
+
+            return task;
+        };
+
         AssetsManager.prototype._decreaseWaitingTasksCount = function () {
             this._waitingTasksCount--;
 

+ 41 - 0
Babylon/Tools/babylon.assetsManager.ts

@@ -143,6 +143,40 @@
         }
     }
 
+    export class TextureAssetTask implements IAssetTask {
+        public onSuccess: (task: IAssetTask) => void;
+        public onError: (task: IAssetTask) => void;
+
+        public isCompleted = false;
+        public texture: Texture;
+
+        constructor(public name: string, public url: string, public noMipmap?: boolean, public invertY?: boolean, public samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE) {
+        }
+
+        public run(scene: Scene, onSuccess: () => void, onError: () => void) {
+
+            var onload = () => {
+                this.isCompleted = true;
+
+                if (this.onSuccess) {
+                    this.onSuccess(this);
+                }
+
+                onSuccess();
+            };
+
+            var onerror = () => {
+                if (this.onError) {
+                    this.onError(this);
+                }
+
+                onError();
+            };
+
+            this.texture = new BABYLON.Texture(this.url, scene, this.noMipmap, this.invertY, this.samplingMode, onload, onError);
+        }
+    }
+
     export class AssetsManager {
         private _tasks = new Array<IAssetTask>();
         private _scene: Scene;
@@ -187,6 +221,13 @@
             return task;
         }
 
+        public addTextureTask(taskName: string, url: string, noMipmap?: boolean, invertY?: boolean, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE): IAssetTask {
+            var task = new TextureAssetTask(taskName, url, noMipmap, invertY, samplingMode);
+            this._tasks.push(task);
+
+            return task;
+        }
+
         private _decreaseWaitingTasksCount(): void {
             this._waitingTasksCount--;
 

+ 25 - 8
Babylon/babylon.engine.js

@@ -1186,9 +1186,11 @@
             gl.bindTexture(gl.TEXTURE_2D, null);
         };
 
-        Engine.prototype.createTexture = function (url, noMipmap, invertY, scene, samplingMode) {
+        Engine.prototype.createTexture = function (url, noMipmap, invertY, scene, samplingMode, onLoad, onError) {
             var _this = this;
             if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
+            if (typeof onLoad === "undefined") { onLoad = null; }
+            if (typeof onError === "undefined") { onError = null; }
             var texture = this._gl.createTexture();
 
             var extension = url.substr(url.length - 4, 4).toLowerCase();
@@ -1201,6 +1203,14 @@
             texture.references = 1;
             this._loadedTexturesCache.push(texture);
 
+            var onerror = function () {
+                scene._removePendingData(texture);
+
+                if (onError) {
+                    onError();
+                }
+            };
+
             if (isTGA) {
                 BABYLON.Tools.LoadFile(url, function (arrayBuffer) {
                     var data = new Uint8Array(arrayBuffer);
@@ -1209,18 +1219,25 @@
 
                     prepareWebGLTexture(texture, _this._gl, scene, header.width, header.height, invertY, noMipmap, false, function () {
                         BABYLON.Internals.TGATools.UploadContent(_this._gl, data);
+
+                        if (onLoad) {
+                            onLoad();
+                        }
                     }, samplingMode);
-                }, null, scene.database, true);
+                }, onerror, scene.database, true);
             } else if (isDDS) {
                 BABYLON.Tools.LoadFile(url, function (data) {
                     var info = BABYLON.Internals.DDSTools.GetDDSInfo(data);
 
                     var loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && !noMipmap && ((info.width >> (info.mipmapCount - 1)) == 1);
                     prepareWebGLTexture(texture, _this._gl, scene, info.width, info.height, invertY, !loadMipmap, info.isFourCC, function () {
-                        console.log("loading " + url);
                         BABYLON.Internals.DDSTools.UploadDDSLevels(_this._gl, _this.getCaps().s3tc, data, info, loadMipmap, 1);
+
+                        if (onLoad) {
+                            onLoad();
+                        }
                     }, samplingMode);
-                }, null, scene.database, true);
+                }, onerror, scene.database, true);
             } else {
                 var onload = function (img) {
                     prepareWebGLTexture(texture, _this._gl, scene, img.width, img.height, invertY, noMipmap, false, function (potWidth, potHeight) {
@@ -1233,11 +1250,11 @@
                         }
 
                         _this._gl.texImage2D(_this._gl.TEXTURE_2D, 0, _this._gl.RGBA, _this._gl.RGBA, _this._gl.UNSIGNED_BYTE, isPot ? img : _this._workingCanvas);
-                    }, samplingMode);
-                };
 
-                var onerror = function () {
-                    scene._removePendingData(texture);
+                        if (onLoad) {
+                            onLoad();
+                        }
+                    }, samplingMode);
                 };
 
                 BABYLON.Tools.LoadImage(url, onload, onerror, scene.database);

+ 23 - 7
Babylon/babylon.engine.ts

@@ -1198,7 +1198,7 @@
             gl.bindTexture(gl.TEXTURE_2D, null);
         }
 
-        public createTexture(url: string, noMipmap: boolean, invertY: boolean, scene: Scene, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE): WebGLTexture {
+        public createTexture(url: string, noMipmap: boolean, invertY: boolean, scene: Scene, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE, onLoad: () => void = null, onError: () => void = null): WebGLTexture {
             var texture = this._gl.createTexture();
 
             var extension = url.substr(url.length - 4, 4).toLowerCase();
@@ -1211,6 +1211,14 @@
             texture.references = 1;
             this._loadedTexturesCache.push(texture);
 
+            var onerror = () => {
+                scene._removePendingData(texture);
+
+                if (onError) {
+                    onError();
+                }
+            };
+
             if (isTGA) {
                 BABYLON.Tools.LoadFile(url, arrayBuffer => {
                     var data = new Uint8Array(arrayBuffer);
@@ -1219,18 +1227,26 @@
 
                     prepareWebGLTexture(texture, this._gl, scene, header.width, header.height, invertY, noMipmap, false, () => {
                         Internals.TGATools.UploadContent(this._gl, data);
+
+                        if (onLoad) {
+                            onLoad();
+                        }
                     }, samplingMode);
-                }, null, scene.database, true);
+                }, onerror, scene.database, true);
             } else if (isDDS) {
                 BABYLON.Tools.LoadFile(url, data => {
                     var info = BABYLON.Internals.DDSTools.GetDDSInfo(data);
 
                     var loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && !noMipmap && ((info.width >> (info.mipmapCount -1)) == 1);
                     prepareWebGLTexture(texture, this._gl, scene, info.width, info.height, invertY, !loadMipmap, info.isFourCC, () => {
-                        console.log("loading " + url);
+
                         Internals.DDSTools.UploadDDSLevels(this._gl, this.getCaps().s3tc, data, info, loadMipmap, 1);
+
+                        if (onLoad) {
+                            onLoad();
+                        }
                     }, samplingMode);
-                }, null, scene.database, true);
+                }, onerror, scene.database, true);
             } else {
                 var onload = (img) => {
                     prepareWebGLTexture(texture, this._gl, scene, img.width, img.height, invertY, noMipmap, false, (potWidth, potHeight) => {
@@ -1244,12 +1260,12 @@
 
                         this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, isPot ? img : this._workingCanvas);
 
+                        if (onLoad) {
+                            onLoad();
+                        }
                     }, samplingMode);
                 };
 
-                var onerror = () => {
-                    scene._removePendingData(texture);
-                };
 
                 BABYLON.Tools.LoadImage(url, onload, onerror, scene.database);
             }

ファイルの差分が大きいため隠しています
+ 81 - 11
babylon.1.14-beta-debug.js


ファイルの差分が大きいため隠しています
+ 8 - 8
babylon.1.14-beta.js


+ 16 - 2
babylon.d.ts

@@ -169,7 +169,7 @@ declare module BABYLON {
         public getAlphaTesting(): boolean;
         public wipeCaches(): void;
         public setSamplingMode(texture: WebGLTexture, samplingMode: number): void;
-        public createTexture(url: string, noMipmap: boolean, invertY: boolean, scene: Scene, samplingMode?: number): WebGLTexture;
+        public createTexture(url: string, noMipmap: boolean, invertY: boolean, scene: Scene, samplingMode?: number, onLoad?: () => void, onError?: () => void): WebGLTexture;
         public createDynamicTexture(width: number, height: number, generateMipMaps: boolean, samplingMode: number): WebGLTexture;
         public updateDynamicTexture(texture: WebGLTexture, canvas: HTMLCanvasElement, invertY: boolean): void;
         public updateVideoTexture(texture: WebGLTexture, video: HTMLVideoElement, invertY: boolean): void;
@@ -1788,7 +1788,7 @@ declare module BABYLON {
         private _cachedWAng;
         private _cachedCoordinatesMode;
         private _samplingMode;
-        constructor(url: string, scene: Scene, noMipmap?: boolean, invertY?: boolean, samplingMode?: number);
+        constructor(url: string, scene: Scene, noMipmap?: boolean, invertY?: boolean, samplingMode?: number, onLoad?: () => void, onError?: () => void);
         public delayLoad(): void;
         private _prepareRowForTextureGeneration(x, y, z, t);
         public getTextureMatrix(): Matrix;
@@ -3216,6 +3216,19 @@ declare module BABYLON {
         constructor(name: string, url: string);
         public run(scene: Scene, onSuccess: () => void, onError: () => void): void;
     }
+    class TextureAssetTask implements IAssetTask {
+        public name: string;
+        public url: string;
+        public noMipmap: boolean;
+        public invertY: boolean;
+        public samplingMode: number;
+        public onSuccess: (task: IAssetTask) => void;
+        public onError: (task: IAssetTask) => void;
+        public isCompleted: boolean;
+        public texture: Texture;
+        constructor(name: string, url: string, noMipmap?: boolean, invertY?: boolean, samplingMode?: number);
+        public run(scene: Scene, onSuccess: () => void, onError: () => void): void;
+    }
     class AssetsManager {
         private _tasks;
         private _scene;
@@ -3229,6 +3242,7 @@ declare module BABYLON {
         public addTextFileTask(taskName: string, url: string): IAssetTask;
         public addBinaryFileTask(taskName: string, url: string): IAssetTask;
         public addImageTask(taskName: string, url: string): IAssetTask;
+        public addTextureTask(taskName: string, url: string, noMipmap?: boolean, invertY?: boolean, samplingMode?: number): IAssetTask;
         private _decreaseWaitingTasksCount();
         private _runTask(task);
         public reset(): AssetsManager;