David Catuhe 11 år sedan
förälder
incheckning
31681b34f2

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

@@ -8,12 +8,12 @@ var BABYLON;
 (function (BABYLON) {
     var Texture = (function (_super) {
         __extends(Texture, _super);
-
         function Texture(url, scene, noMipmap, invertY, samplingMode, onLoad, onError, buffer, deleteBuffer) {
-
             if (typeof samplingMode === "undefined") { samplingMode = Texture.TRILINEAR_SAMPLINGMODE; }
             if (typeof onLoad === "undefined") { onLoad = null; }
             if (typeof onError === "undefined") { onError = null; }
+            if (typeof buffer === "undefined") { buffer = null; }
+            if (typeof deleteBuffer === "undefined") { deleteBuffer = false; }
             _super.call(this, scene);
             this.uOffset = 0;
             this.vOffset = 0;
@@ -39,12 +39,10 @@ var BABYLON;
 
             if (!this._texture) {
                 if (!scene.useDelayedTextureLoading) {
-
                     this._texture = scene.getEngine().createTexture(url, noMipmap, invertY, scene, this._samplingMode, onLoad, onError, this._buffer);
-					if (deleteBuffer) {
+                    if (deleteBuffer) {
                         delete this._buffer;
                     }
-
                 } else {
                     this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
                 }
@@ -171,7 +169,7 @@ var BABYLON;
         };
 
         Texture.prototype.clone = function () {
-            var newTexture = new BABYLON.Texture(this._texture.url, this.getScene(), this._noMipmap, this._invertY, this._samplingMode, this._buffer, this._deleteBuffer);
+            var newTexture = new BABYLON.Texture(this._texture.url, this.getScene(), this._noMipmap, this._invertY);
 
             // Base texture
             newTexture.hasAlpha = this.hasAlpha;

+ 4 - 4
Babylon/Math/babylon.math.ts

@@ -290,7 +290,7 @@
             return new Vector2(-this.x, -this.y);
         }
 
-        public scaleInPlace(scale: number): void {
+        public scaleInPlace(scale: number): Vector2 {
             this.x *= scale;
             this.y *= scale;
             return this;
@@ -314,7 +314,7 @@
         }
 
         // Methods
-        public normalize(): void {
+        public normalize(): Vector2 {
             var len = this.length();
 
             if (len === 0)
@@ -515,7 +515,7 @@
             return new Vector3(-this.x, -this.y, -this.z);
         }
 
-        public scaleInPlace(scale: number): void {
+        public scaleInPlace(scale: number): Vector3 {
             this.x *= scale;
             this.y *= scale;
             this.z *= scale;
@@ -598,7 +598,7 @@
         }
 
         // Methods
-        public normalize(): void {
+        public normalize(): Vector3 {
             var len = this.length();
 
             if (len === 0)

+ 1 - 1
Babylon/Tools/babylon.tools.js

@@ -160,7 +160,7 @@
             url = Tools.CleanUrl(url);
 
             var img = new Image();
-            
+
             if (url.substr(0, 5) != "data:")
                 img.crossOrigin = 'anonymous';
 

+ 1 - 1
Babylon/Tools/babylon.tools.ts

@@ -185,7 +185,7 @@
 
             var img = new Image();
 
-			if (url.substr(0, 5) != "data:")
+            if (url.substr(0, 5) != "data:")
                 img.crossOrigin = 'anonymous';
 
             img.onload = () => {

+ 12 - 10
Babylon/babylon.engine.js

@@ -1172,18 +1172,18 @@
 
             gl.bindTexture(gl.TEXTURE_2D, null);
         };
-
-        Engine.prototype.createTexture = function (url, noMipmap, invertY, scene, samplingMode, onLoad, onError, buffer) {
+
+        Engine.prototype.createTexture = function (url, noMipmap, invertY, scene, samplingMode, onLoad, onError, buffer) {
             var _this = this;
             if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             if (typeof onLoad === "undefined") { onLoad = null; }
             if (typeof onError === "undefined") { onError = null; }
+            if (typeof buffer === "undefined") { buffer = null; }
             var texture = this._gl.createTexture();
+
             var extension;
             var fromData = false;
-
             if (url.substr(0, 5) === "data:") {
-                // data: -- name
                 fromData = true;
             }
 
@@ -1225,14 +1225,15 @@
                         if (onLoad) {
                             onLoad();
                         }
-                    }, samplingMode);
+                    }, samplingMode);
                 };
 
                 if (!(fromData instanceof Array))
-                    BABYLON.Tools.LoadFile(url, callback, onerror, scene.database, true);
+                    BABYLON.Tools.LoadFile(url, function (arrayBuffer) {
+                        callback(arrayBuffer);
+                    }, onerror, scene.database, true);
                 else
                     callback(buffer);
-
             } else if (isDDS) {
                 var callback = function (data) {
                     var info = BABYLON.Internals.DDSTools.GetDDSInfo(data);
@@ -1244,14 +1245,15 @@
                         if (onLoad) {
                             onLoad();
                         }
-                    }, samplingMode);
+                    }, samplingMode);
                 };
 
                 if (!(fromData instanceof Array))
-                    BABYLON.Tools.LoadFile(url, callback, onerror, scene.database, true);
+                    BABYLON.Tools.LoadFile(url, function (data) {
+                        callback(data);
+                    }, onerror, scene.database, true);
                 else
                     callback(buffer);
-
             } else {
                 var onload = function (img) {
                     prepareWebGLTexture(texture, _this._gl, scene, img.width, img.height, invertY, noMipmap, false, function (potWidth, potHeight) {

+ 15 - 15
Babylon/babylon.engine.ts

@@ -11,7 +11,7 @@
         private _depthFunc: number;
         private _cull: boolean;
         private _cullFace: number;
-        
+
 
         public get isDirty(): boolean {
             return this._isDepthFuncDirty || this._isDepthTestDirty || this._isDepthMaskDirty || this._isCullFaceDirty || this._isCullDirty;
@@ -172,14 +172,14 @@
                 this._blendFunctionParameters[1] === value1 &&
                 this._blendFunctionParameters[2] === value2 &&
                 this._blendFunctionParameters[3] === value3
-            ) {
+                ) {
                 return;
             }
 
-            this._blendFunctionParameters[0] = value0;                
-            this._blendFunctionParameters[1] = value1;                
-            this._blendFunctionParameters[2] = value2;                
-            this._blendFunctionParameters[3] = value3;                
+            this._blendFunctionParameters[0] = value0;
+            this._blendFunctionParameters[1] = value1;
+            this._blendFunctionParameters[2] = value2;
+            this._blendFunctionParameters[3] = value3;
 
             this._isBlendFunctionParametersDirty = true;
         }
@@ -189,7 +189,7 @@
             this._blendFunctionParameters[0] = null;
             this._blendFunctionParameters[1] = null;
             this._blendFunctionParameters[2] = null;
-            this._blendFunctionParameters[3] = null;   
+            this._blendFunctionParameters[3] = null;
 
             this._isAlphaBlendDirty = true;
             this._isBlendFunctionParametersDirty = false;
@@ -394,7 +394,7 @@
         private _gl: WebGLRenderingContext;
         private _renderingCanvas: HTMLCanvasElement;
         private _windowIsBackground = false;
-        
+
         private _onBlur: () => void;
         private _onFocus: () => void;
         private _onFullscreenChange: () => void;
@@ -893,7 +893,7 @@
         public draw(useTriangles: boolean, indexStart: number, indexCount: number, instancesCount?: number): void {
             // Apply states
             this.applyStates();
-            
+
             // Render
             if (instancesCount) {
                 this._caps.instancedArrays.drawElementsInstancedANGLE(useTriangles ? this._gl.TRIANGLES : this._gl.LINES, indexCount, this._gl.UNSIGNED_SHORT, indexStart * 2, instancesCount);
@@ -930,7 +930,7 @@
             return effect;
         }
 
-        public createEffectForParticles(fragmentName: string, uniformsNames: string[]= [], samplers: string[] = [], defines = "", fallbacks?: EffectFallbacks,
+        public createEffectForParticles(fragmentName: string, uniformsNames: string[]= [], samplers: string[]= [], defines = "", fallbacks?: EffectFallbacks,
             onCompiled?: (effect: Effect) => void, onError?: (effect: Effect, errors: string) => void): Effect {
 
             return this.createEffect(
@@ -1185,17 +1185,17 @@
             gl.bindTexture(gl.TEXTURE_2D, null);
         }
 
-        public createTexture(url: string, noMipmap: boolean, invertY: boolean, scene: Scene, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE, onLoad: () => void = null, onError: () => void = null, buffer:any = null): WebGLTexture {
+        public createTexture(url: string, noMipmap: boolean, invertY: boolean, scene: Scene, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE, onLoad: () => void = null, onError: () => void = null, buffer: any = null): WebGLTexture {
 
             var texture = this._gl.createTexture();
 
             var extension: string;
-			var fromData: any = false;
-			if (url.substr(0, 5) === "data:") {
+            var fromData: any = false;
+            if (url.substr(0, 5) === "data:") {
                 fromData = true;
             }
 
-			if (!fromData)
+            if (!fromData)
                 extension = url.substr(url.length - 4, 4).toLowerCase();
             else {
                 var oldUrl = url;
@@ -1736,7 +1736,7 @@
 
             var onTransitionEnd = () => {
                 deg += 360;
-                imgBack.style.transform = "rotateZ(" + deg + "deg)"; 
+                imgBack.style.transform = "rotateZ(" + deg + "deg)";
                 imgBack.style.webkitTransform = "rotateZ(" + deg + "deg)";
             }
 

+ 70 - 11
babylon.1.14-RC-debug.js

@@ -327,6 +327,7 @@ var BABYLON;
         Vector2.prototype.scaleInPlace = function (scale) {
             this.x *= scale;
             this.y *= scale;
+            return this;
         };
 
         Vector2.prototype.scale = function (scale) {
@@ -357,6 +358,8 @@ var BABYLON;
 
             this.x *= num;
             this.y *= num;
+
+            return this;
         };
 
         Vector2.prototype.clone = function () {
@@ -549,6 +552,7 @@ var BABYLON;
             this.x *= scale;
             this.y *= scale;
             this.z *= scale;
+            return this;
         };
 
         Vector3.prototype.scale = function (scale) {
@@ -642,6 +646,8 @@ var BABYLON;
             this.x *= num;
             this.y *= num;
             this.z *= num;
+
+            return this;
         };
 
         Vector3.prototype.clone = function () {
@@ -2316,7 +2322,9 @@ var BABYLON;
             url = Tools.CleanUrl(url);
 
             var img = new Image();
-            img.crossOrigin = 'anonymous';
+
+            if (url.substr(0, 5) != "data:")
+                img.crossOrigin = 'anonymous';
 
             img.onload = function () {
                 onload(img);
@@ -2410,6 +2418,15 @@ var BABYLON;
             }
         };
 
+        Tools.ReadFileAsDataURL = function (fileToLoad, callback, progressCallback) {
+            var reader = new FileReader();
+            reader.onload = function (e) {
+                callback(e.target.result);
+            };
+            reader.onprogress = progressCallback;
+            reader.readAsDataURL(fileToLoad);
+        };
+
         Tools.ReadFile = function (fileToLoad, callback, progressCallBack, useArrayBuffer) {
             var reader = new FileReader();
             reader.onload = function (e) {
@@ -3999,14 +4016,29 @@ var BABYLON;
             gl.bindTexture(gl.TEXTURE_2D, null);
         };
 
-        Engine.prototype.createTexture = function (url, noMipmap, invertY, scene, samplingMode, onLoad, onError) {
+        Engine.prototype.createTexture = function (url, noMipmap, invertY, scene, samplingMode, onLoad, onError, buffer) {
             var _this = this;
             if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             if (typeof onLoad === "undefined") { onLoad = null; }
             if (typeof onError === "undefined") { onError = null; }
+            if (typeof buffer === "undefined") { buffer = null; }
             var texture = this._gl.createTexture();
 
-            var extension = url.substr(url.length - 4, 4).toLowerCase();
+            var extension;
+            var fromData = false;
+            if (url.substr(0, 5) === "data:") {
+                fromData = true;
+            }
+
+            if (!fromData)
+                extension = url.substr(url.length - 4, 4).toLowerCase();
+            else {
+                var oldUrl = url;
+                fromData = oldUrl.split(':');
+                url = oldUrl;
+                extension = fromData[1].substr(fromData[1].length - 4, 4).toLowerCase();
+            }
+
             var isDDS = this.getCaps().s3tc && (extension === ".dds");
             var isTGA = (extension === ".tga");
 
@@ -4025,7 +4057,7 @@ var BABYLON;
             };
 
             if (isTGA) {
-                BABYLON.Tools.LoadFile(url, function (arrayBuffer) {
+                var callback = function (arrayBuffer) {
                     var data = new Uint8Array(arrayBuffer);
 
                     var header = BABYLON.Internals.TGATools.GetTGAHeader(data);
@@ -4037,9 +4069,16 @@ var BABYLON;
                             onLoad();
                         }
                     }, samplingMode);
-                }, onerror, scene.database, true);
+                };
+
+                if (!(fromData instanceof Array))
+                    BABYLON.Tools.LoadFile(url, function (arrayBuffer) {
+                        callback(arrayBuffer);
+                    }, onerror, scene.database, true);
+                else
+                    callback(buffer);
             } else if (isDDS) {
-                BABYLON.Tools.LoadFile(url, function (data) {
+                var callback = 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);
@@ -4050,7 +4089,14 @@ var BABYLON;
                             onLoad();
                         }
                     }, samplingMode);
-                }, onerror, scene.database, true);
+                };
+
+                if (!(fromData instanceof Array))
+                    BABYLON.Tools.LoadFile(url, function (data) {
+                        callback(data);
+                    }, onerror, scene.database, true);
+                else
+                    callback(buffer);
             } else {
                 var onload = function (img) {
                     prepareWebGLTexture(texture, _this._gl, scene, img.width, img.height, invertY, noMipmap, false, function (potWidth, potHeight) {
@@ -4070,7 +4116,10 @@ var BABYLON;
                     }, samplingMode);
                 };
 
-                BABYLON.Tools.LoadImage(url, onload, onerror, scene.database);
+                if (!(fromData instanceof Array))
+                    BABYLON.Tools.LoadImage(url, onload, onerror, scene.database);
+                else
+                    BABYLON.Tools.LoadImage(buffer, onload, onerror, scene.database);
             }
 
             return texture;
@@ -11750,10 +11799,12 @@ var BABYLON;
 (function (BABYLON) {
     var Texture = (function (_super) {
         __extends(Texture, _super);
-        function Texture(url, scene, noMipmap, invertY, samplingMode, onLoad, onError) {
+        function Texture(url, scene, noMipmap, invertY, samplingMode, onLoad, onError, buffer, deleteBuffer) {
             if (typeof samplingMode === "undefined") { samplingMode = Texture.TRILINEAR_SAMPLINGMODE; }
             if (typeof onLoad === "undefined") { onLoad = null; }
             if (typeof onError === "undefined") { onError = null; }
+            if (typeof buffer === "undefined") { buffer = null; }
+            if (typeof deleteBuffer === "undefined") { deleteBuffer = false; }
             _super.call(this, scene);
             this.uOffset = 0;
             this.vOffset = 0;
@@ -11768,6 +11819,8 @@ var BABYLON;
             this._noMipmap = noMipmap;
             this._invertY = invertY;
             this._samplingMode = samplingMode;
+            this._buffer = buffer;
+            this._deleteBuffer = deleteBuffer;
 
             if (!url) {
                 return;
@@ -11777,7 +11830,10 @@ var BABYLON;
 
             if (!this._texture) {
                 if (!scene.useDelayedTextureLoading) {
-                    this._texture = scene.getEngine().createTexture(url, noMipmap, invertY, scene, this._samplingMode, onLoad, onError);
+                    this._texture = scene.getEngine().createTexture(url, noMipmap, invertY, scene, this._samplingMode, onLoad, onError, this._buffer);
+                    if (deleteBuffer) {
+                        delete this._buffer;
+                    }
                 } else {
                     this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
                 }
@@ -11792,7 +11848,10 @@ var BABYLON;
             this._texture = this._getFromCache(this.url, this._noMipmap);
 
             if (!this._texture) {
-                this._texture = this.getScene().getEngine().createTexture(this.url, this._noMipmap, this._invertY, this.getScene(), this._samplingMode);
+                this._texture = this.getScene().getEngine().createTexture(this.url, this._noMipmap, this._invertY, this.getScene(), this._samplingMode, null, null, this._buffer);
+                if (this._deleteBuffer) {
+                    delete this._buffer;
+                }
             }
         };
 

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 6 - 6
babylon.1.14-RC.js


+ 9 - 6
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, onLoad?: () => void, onError?: () => void): WebGLTexture;
+        public createTexture(url: string, noMipmap: boolean, invertY: boolean, scene: Scene, samplingMode?: number, onLoad?: () => void, onError?: () => void, buffer?: any): 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,9 @@ declare module BABYLON {
         private _cachedWAng;
         private _cachedCoordinatesMode;
         private _samplingMode;
-        constructor(url: string, scene: Scene, noMipmap?: boolean, invertY?: boolean, samplingMode?: number, onLoad?: () => void, onError?: () => void);
+        private _buffer;
+        private _deleteBuffer;
+        constructor(url: string, scene: Scene, noMipmap?: boolean, invertY?: boolean, samplingMode?: number, onLoad?: () => void, onError?: () => void, buffer?: any, deleteBuffer?: boolean);
         public delayLoad(): void;
         private _prepareRowForTextureGeneration(x, y, z, t);
         public getTextureMatrix(): Matrix;
@@ -1881,12 +1883,12 @@ declare module BABYLON {
         public divide(otherVector: Vector2): Vector2;
         public divideToRef(otherVector: Vector2, result: Vector2): void;
         public negate(): Vector2;
-        public scaleInPlace(scale: number): void;
+        public scaleInPlace(scale: number): Vector2;
         public scale(scale: number): Vector2;
         public equals(otherVector: Vector2): boolean;
         public length(): number;
         public lengthSquared(): number;
-        public normalize(): void;
+        public normalize(): Vector2;
         public clone(): Vector2;
         static Zero(): Vector2;
         static FromArray(array: number[], offset?: number): Vector2;
@@ -1920,7 +1922,7 @@ declare module BABYLON {
         public subtractFromFloats(x: number, y: number, z: number): Vector3;
         public subtractFromFloatsToRef(x: number, y: number, z: number, result: Vector3): void;
         public negate(): Vector3;
-        public scaleInPlace(scale: number): void;
+        public scaleInPlace(scale: number): Vector3;
         public scale(scale: number): Vector3;
         public scaleToRef(scale: number, result: Vector3): void;
         public equals(otherVector: Vector3): boolean;
@@ -1936,7 +1938,7 @@ declare module BABYLON {
         public MaximizeInPlace(other: Vector3): void;
         public length(): number;
         public lengthSquared(): number;
-        public normalize(): void;
+        public normalize(): Vector3;
         public clone(): Vector3;
         public copyFrom(source: Vector3): void;
         public copyFromFloats(x: number, y: number, z: number): void;
@@ -3494,6 +3496,7 @@ declare module BABYLON {
         static CleanUrl(url: string): string;
         static LoadImage(url: string, onload: any, onerror: any, database: any): HTMLImageElement;
         static LoadFile(url: string, callback: (data: any) => void, progressCallBack?: () => void, database?: any, useArrayBuffer?: boolean, onError?: () => void): void;
+        static ReadFileAsDataURL(fileToLoad: any, callback: any, progressCallback: any): void;
         static ReadFile(fileToLoad: any, callback: any, progressCallBack: any, useArrayBuffer?: boolean): void;
         static CheckExtends(v: Vector3, min: Vector3, max: Vector3): void;
         static WithinEpsilon(a: number, b: number): boolean;