Browse Source

Adding AssetsManager.addImageTask

David Catuhe 11 years ago
parent
commit
9aad3dee68

+ 1 - 0
Babylon/.gitignore

@@ -0,0 +1 @@
+*.d.ts

+ 1 - 1
Babylon/Lights/Shadows/babylon.shadowGenerator.js

@@ -38,7 +38,7 @@
                     return;
                 }
 
-                var hardwareInstancedRendering = (engine.getCaps().instancedArrays !== null) && (batch.visibleInstances !== null);
+                var hardwareInstancedRendering = (engine.getCaps().instancedArrays !== null) && (batch.visibleInstances[subMesh._id] !== null);
 
                 if (_this.isReady(subMesh, hardwareInstancedRendering)) {
                     engine.enableEffect(_this._effect);

+ 1 - 1
Babylon/Lights/Shadows/babylon.shadowGenerator.ts

@@ -77,7 +77,7 @@
                     return;
                 }
 
-                var hardwareInstancedRendering = (engine.getCaps().instancedArrays !== null) && (batch.visibleInstances !== null);
+                var hardwareInstancedRendering = (engine.getCaps().instancedArrays !== null) && (batch.visibleInstances[subMesh._id] !== null);
 
                 if (this.isReady(subMesh, hardwareInstancedRendering)) {
                     engine.enableEffect(this._effect);

+ 1 - 1
Babylon/Shaders/default.fragment.fx

@@ -128,7 +128,7 @@ uniform sampler2D specularSampler;
 #ifdef FRESNEL
 float computeFresnelTerm(vec3 viewDirection, vec3 worldNormal, float bias, float power)
 {
-	float fresnelTerm = pow(bias + dot(viewDirection, worldNormal), power);
+	float fresnelTerm = pow(bias + abs(dot(viewDirection, worldNormal)), power);
 	return clamp(fresnelTerm, 0., 1.);
 }
 #endif

+ 1 - 1
Babylon/Shaders/legacydefault.fragment.fx

@@ -126,7 +126,7 @@ uniform sampler2D specularSampler;
 #ifdef FRESNEL
 float computeFresnelTerm(vec3 viewDirection, vec3 worldNormal, float bias, float power)
 {
-	float fresnelTerm = pow(bias + dot(viewDirection, worldNormal), power);
+	float fresnelTerm = pow(bias + abs(dot(viewDirection, worldNormal)), power);
 	return clamp(fresnelTerm, 0., 1.);
 }
 #endif

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

@@ -92,6 +92,39 @@
     })();
     BABYLON.BinaryFileAssetTask = BinaryFileAssetTask;
 
+    var ImageAssetTask = (function () {
+        function ImageAssetTask(name, url) {
+            this.name = name;
+            this.url = url;
+            this.isCompleted = false;
+        }
+        ImageAssetTask.prototype.run = function (scene, onSuccess, onError) {
+            var _this = this;
+            var img = new Image();
+
+            img.onload = function () {
+                _this.image = img;
+                _this.isCompleted = true;
+
+                if (_this.onSuccess) {
+                    _this.onSuccess(_this);
+                }
+
+                onSuccess();
+            };
+
+            img.onerror = function () {
+                if (_this.onError) {
+                    _this.onError(_this);
+                }
+
+                onError();
+            };
+        };
+        return ImageAssetTask;
+    })();
+    BABYLON.ImageAssetTask = ImageAssetTask;
+
     var AssetsManager = (function () {
         function AssetsManager(scene) {
             this._tasks = new Array();
@@ -120,6 +153,13 @@
             return task;
         };
 
+        AssetsManager.prototype.addImageTask = function (taskName, url) {
+            var task = new ImageAssetTask(taskName, url);
+            this._tasks.push(task);
+
+            return task;
+        };
+
         AssetsManager.prototype._decreaseWaitingTasksCount = function () {
             this._waitingTasksCount--;
 

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

@@ -107,6 +107,40 @@
         }
     }
 
+    export class ImageAssetTask implements IAssetTask {
+        public onSuccess: (task: IAssetTask) => void;
+        public onError: (task: IAssetTask) => void;
+
+        public isCompleted = false;
+        public image: HTMLImageElement;
+
+        constructor(public name: string, public url: string) {
+        }
+
+        public run(scene: Scene, onSuccess: () => void, onError: () => void) {
+            var img = new Image();
+
+            img.onload = () => {
+                this.image = img;
+                this.isCompleted = true;
+
+                if (this.onSuccess) {
+                    this.onSuccess(this);
+                }
+
+                onSuccess();
+            };
+
+            img.onerror = () => {
+                if (this.onError) {
+                    this.onError(this);
+                }
+
+                onError();
+            };
+        }
+    }
+
     export class AssetsManager {
         private _tasks = new Array<IAssetTask>();
         private _scene: Scene;
@@ -144,6 +178,13 @@
             return task;
         }
 
+        public addImageTask(taskName: string, url: string): IAssetTask {
+            var task = new ImageAssetTask(taskName, url);
+            this._tasks.push(task);
+
+            return task;
+        }
+
         private _decreaseWaitingTasksCount(): void {
             this._waitingTasksCount--;
 

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

@@ -98,7 +98,7 @@ var BABYLON;
                     var localOffset = 0;
                     var pixels = new Uint8Array(pixel_size);
 
-                    while (offset < pixel_total) {
+                    while (offset < pixel_total && localOffset < pixel_total) {
                         c = data[offset++];
                         count = (c & 0x7f) + 1;
 

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

@@ -111,7 +111,7 @@ module BABYLON.Internals {
                 var localOffset = 0;
                 var pixels = new Uint8Array(pixel_size);
 
-                while (offset < pixel_total) {
+                while (offset < pixel_total && localOffset < pixel_total) {
                     c = data[offset++];
                     count = (c & 0x7f) + 1;
 

+ 7 - 0
Babylon/babylon.engine.js

@@ -1672,6 +1672,7 @@
             imgBack.style.marginLeft = "-50px";
             imgBack.style.marginTop = "-50px";
             imgBack.style.transition = "transform 1.0s ease";
+            imgBack.style.webkitTransition = "-webkit-transform 1.0s ease";
 
             var deg = 360;
 
@@ -1680,6 +1681,11 @@
                 imgBack.style.transform = "rotateZ(" + deg + "deg)";
             });
 
+            imgBack.addEventListener("webkitTransitionEnd", function () {
+                deg += 360;
+                imgBack.style.webkitTransform = "rotateZ(" + deg + "deg)";
+            });
+
             this._loadingDiv.appendChild(imgBack);
 
             // front image
@@ -1713,6 +1719,7 @@
             setTimeout(function () {
                 _this._loadingDiv.style.opacity = "1";
                 imgBack.style.transform = "rotateZ(360deg)";
+                imgBack.style.webkitTransform = "rotateZ(360deg)";
             }, 0);
         };
 

+ 9 - 1
Babylon/babylon.engine.ts

@@ -1680,6 +1680,7 @@
             imgBack.style.marginLeft = "-50px";
             imgBack.style.marginTop = "-50px";
             imgBack.style.transition = "transform 1.0s ease";
+            imgBack.style.webkitTransition = "-webkit-transform 1.0s ease";
 
             var deg = 360;
 
@@ -1688,6 +1689,12 @@
                 imgBack.style.transform = "rotateZ(" + deg + "deg)";
             });
 
+            imgBack.addEventListener("webkitTransitionEnd", () => {
+                deg += 360;
+                imgBack.style.webkitTransform = "rotateZ(" + deg + "deg)";
+            });
+
+
             this._loadingDiv.appendChild(imgBack);
 
             // front image
@@ -1721,6 +1728,7 @@
             setTimeout(() => {
                 this._loadingDiv.style.opacity = "1";
                 imgBack.style.transform = "rotateZ(360deg)";
+                imgBack.style.webkitTransform = "rotateZ(360deg)";
             }, 0);
         }
 
@@ -1777,4 +1785,4 @@
             }
         }
     }
-} 
+}

+ 5 - 0
Babylon/babylon.mixins.ts

@@ -78,4 +78,9 @@ interface MouseEvent {
     webkitMovementY: number;
     msMovementX: number;
     msMovementY: number;
+}
+
+interface MSStyleCSSProperties {
+    webkitTransform: string;
+    webkitTransition: string;
 }

File diff suppressed because it is too large
+ 51 - 4
babylon.1.14-beta-debug.js


File diff suppressed because it is too large
+ 8 - 8
babylon.1.14-beta.js


+ 15 - 0
babylon.d.ts

@@ -263,6 +263,10 @@ interface MouseEvent {
     msMovementX: number;
     msMovementY: number;
 }
+interface MSStyleCSSProperties {
+    webkitTransform: string;
+    webkitTransition: string;
+}
 declare module BABYLON {
     class Node {
         public parent: Node;
@@ -3158,6 +3162,16 @@ declare module BABYLON {
         constructor(name: string, url: string);
         public run(scene: Scene, onSuccess: () => void, onError: () => void): void;
     }
+    class ImageAssetTask implements IAssetTask {
+        public name: string;
+        public url: string;
+        public onSuccess: (task: IAssetTask) => void;
+        public onError: (task: IAssetTask) => void;
+        public isCompleted: boolean;
+        public image: HTMLImageElement;
+        constructor(name: string, url: string);
+        public run(scene: Scene, onSuccess: () => void, onError: () => void): void;
+    }
     class AssetsManager {
         private _tasks;
         private _scene;
@@ -3170,6 +3184,7 @@ declare module BABYLON {
         public addMeshTask(taskName: string, meshesNames: any, rootUrl: string, sceneFilename: string): IAssetTask;
         public addTextFileTask(taskName: string, url: string): IAssetTask;
         public addBinaryFileTask(taskName: string, url: string): IAssetTask;
+        public addImageTask(taskName: string, url: string): IAssetTask;
         private _decreaseWaitingTasksCount();
         private _runTask(task);
         public reset(): AssetsManager;