Browse Source

Integrating recent fixes (mostly for Chrome)

David Catuhe 10 years ago
parent
commit
345409202a

+ 1 - 1
Babylon/Loading/Plugins/babylon.babylonFileLoader.js

@@ -916,7 +916,7 @@ var BABYLON;
                 }
                 if (binaryInfo.colorsAttrDesc && binaryInfo.colorsAttrDesc.count > 0) {
                     var colorsData = new Float32Array(parsedGeometry, binaryInfo.colorsAttrDesc.offset, binaryInfo.colorsAttrDesc.count);
-                    mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colorsData, false);
+                    mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colorsData, false, binaryInfo.colorsAttrDesc.stride);
                 }
                 if (binaryInfo.matricesIndicesAttrDesc && binaryInfo.matricesIndicesAttrDesc.count > 0) {
                     var matricesIndicesData = new Int32Array(parsedGeometry, binaryInfo.matricesIndicesAttrDesc.offset, binaryInfo.matricesIndicesAttrDesc.count);

+ 1 - 1
Babylon/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -1132,7 +1132,7 @@
 
             if (binaryInfo.colorsAttrDesc && binaryInfo.colorsAttrDesc.count > 0) {
                 var colorsData = new Float32Array(parsedGeometry, binaryInfo.colorsAttrDesc.offset, binaryInfo.colorsAttrDesc.count);
-                mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colorsData, false);
+                mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colorsData, false, binaryInfo.colorsAttrDesc.stride);
             }
 
             if (binaryInfo.matricesIndicesAttrDesc && binaryInfo.matricesIndicesAttrDesc.count > 0) {

+ 9 - 0
Babylon/Loading/babylon.sceneLoader.js

@@ -48,6 +48,8 @@ var BABYLON;
                 BABYLON.Tools.Error("Wrong sceneFilename parameter");
                 return;
             }
+            var loadingToken = {};
+            scene._addPendingData(loadingToken);
             var manifestChecked = function (success) {
                 scene.database = database;
                 var plugin = SceneLoader._getPluginForFilename(sceneFilename);
@@ -60,6 +62,7 @@ var BABYLON;
                             if (onerror) {
                                 onerror(scene, 'unable to load the scene');
                             }
+                            scene._removePendingData(loadingToken);
                             return;
                         }
                     }
@@ -67,11 +70,13 @@ var BABYLON;
                         if (onerror) {
                             onerror(scene, e);
                         }
+                        scene._removePendingData(loadingToken);
                         return;
                     }
                     if (onsuccess) {
                         scene.importedMeshesFiles.push(rootUrl + sceneFilename);
                         onsuccess(meshes, particleSystems, skeletons);
+                        scene._removePendingData(loadingToken);
                     }
                 };
                 if (sceneFilename.substr && sceneFilename.substr(0, 5) === "data:") {
@@ -108,6 +113,8 @@ var BABYLON;
             }
             var plugin = this._getPluginForFilename(sceneFilename.name || sceneFilename);
             var database;
+            var loadingToken = {};
+            scene._addPendingData(loadingToken);
             if (SceneLoader.ShowLoadingScreen) {
                 scene.getEngine().displayLoadingUI();
             }
@@ -117,12 +124,14 @@ var BABYLON;
                     if (onerror) {
                         onerror(scene);
                     }
+                    scene._removePendingData(loadingToken);
                     scene.getEngine().hideLoadingUI();
                     return;
                 }
                 if (onsuccess) {
                     onsuccess(scene);
                 }
+                scene._removePendingData(loadingToken);
                 if (SceneLoader.ShowLoadingScreen) {
                     scene.executeWhenReady(function () {
                         scene.getEngine().hideLoadingUI();

+ 11 - 2
Babylon/Loading/babylon.sceneLoader.ts

@@ -63,6 +63,9 @@
                 return;
             }
 
+            var loadingToken = {};
+            scene._addPendingData(loadingToken);
+
             var manifestChecked = success => {
                 scene.database = database;
 
@@ -78,14 +81,14 @@
                             if (onerror) {
                                 onerror(scene, 'unable to load the scene');
                             }
-
+                            scene._removePendingData(loadingToken);
                             return;
                         }
                     } catch (e) {
                         if (onerror) {
                             onerror(scene, e);
                         }
-
+                        scene._removePendingData(loadingToken);
                         return;
                     }
 
@@ -93,6 +96,7 @@
                     if (onsuccess) {
                         scene.importedMeshesFiles.push(rootUrl + sceneFilename);
                         onsuccess(meshes, particleSystems, skeletons);
+                        scene._removePendingData(loadingToken);
                     }
                 };
 
@@ -137,6 +141,9 @@
             var plugin = this._getPluginForFilename(sceneFilename.name || sceneFilename);
             var database;
 
+            var loadingToken = {};
+            scene._addPendingData(loadingToken);
+
             if (SceneLoader.ShowLoadingScreen) {
                 scene.getEngine().displayLoadingUI();
             }
@@ -149,6 +156,7 @@
                         onerror(scene);
                     }
 
+                    scene._removePendingData(loadingToken);
                     scene.getEngine().hideLoadingUI();
                     return;
                 }
@@ -156,6 +164,7 @@
                 if (onsuccess) {
                     onsuccess(scene);
                 }
+                scene._removePendingData(loadingToken);
 
                 if (SceneLoader.ShowLoadingScreen) {
                     scene.executeWhenReady(() => {

+ 15 - 3
Babylon/Materials/babylon.effect.js

@@ -122,7 +122,7 @@ var BABYLON;
                 return;
             }
             var vertexShaderUrl;
-            if (vertex[0] === ".") {
+            if (vertex[0] === "." || vertex[0] === "/") {
                 vertexShaderUrl = vertex;
             }
             else {
@@ -148,7 +148,7 @@ var BABYLON;
                 return;
             }
             var fragmentShaderUrl;
-            if (fragment[0] === ".") {
+            if (fragment[0] === "." || fragment[0] === "/") {
                 fragmentShaderUrl = fragment;
             }
             else {
@@ -194,7 +194,19 @@ var BABYLON;
                     this._prepareEffect(vertexSourceCode, fragmentSourceCode, attributesNames, defines, fallbacks);
                 }
                 else {
-                    BABYLON.Tools.Error("Unable to compile effect: " + this.name);
+                    BABYLON.Tools.Error("Unable to compile effect: ");
+                    if (this.name.vertexElement) {
+                        BABYLON.Tools.Error("Vertex shader:" + this.name.vertexElement);
+                        BABYLON.Tools.Error("Fragment shader:" + this.name.fragmentElement);
+                    }
+                    else if (this.name.vertex) {
+                        BABYLON.Tools.Error("Vertex shader:" + this.name.vertex);
+                        BABYLON.Tools.Error("Fragment shader:" + this.name.fragment);
+                    }
+                    else {
+                        BABYLON.Tools.Error("Vertex shader:" + this.name);
+                        BABYLON.Tools.Error("Fragment shader:" + this.name);
+                    }
                     BABYLON.Tools.Error("Defines: " + defines);
                     BABYLON.Tools.Error("Error: " + e.message);
                     this._compilationError = e.message;

+ 13 - 3
Babylon/Materials/babylon.effect.ts

@@ -160,7 +160,7 @@
 
             var vertexShaderUrl;
 
-            if (vertex[0] === ".") {
+            if (vertex[0] === "." || vertex[0] === "/") {
                 vertexShaderUrl = vertex;
             } else {
                 vertexShaderUrl = Engine.ShadersRepository + vertex;
@@ -191,7 +191,7 @@
 
             var fragmentShaderUrl;
 
-            if (fragment[0] === ".") {
+            if (fragment[0] === "." || fragment[0] === "/") {
                 fragmentShaderUrl = fragment;
             } else {
                 fragmentShaderUrl = Engine.ShadersRepository + fragment;
@@ -244,7 +244,17 @@
                     defines = fallbacks.reduce(defines);
                     this._prepareEffect(vertexSourceCode, fragmentSourceCode, attributesNames, defines, fallbacks);
                 } else { // Sorry we did everything we can
-                    Tools.Error("Unable to compile effect: " + this.name);
+                    Tools.Error("Unable to compile effect: ");
+                    if (this.name.vertexElement) {
+                        Tools.Error("Vertex shader:" + this.name.vertexElement);
+                        Tools.Error("Fragment shader:" + this.name.fragmentElement);
+                    } else if (this.name.vertex) {
+                        Tools.Error("Vertex shader:" + this.name.vertex);
+                        Tools.Error("Fragment shader:" + this.name.fragment);
+                    } else {
+                        Tools.Error("Vertex shader:" + this.name);
+                        Tools.Error("Fragment shader:" + this.name);
+                    }
                     Tools.Error("Defines: " + defines);
                     Tools.Error("Error: " + e.message);
                     this._compilationError = e.message;

+ 15 - 2
Babylon/Mesh/babylon.abstractMesh.js

@@ -25,7 +25,6 @@ var BABYLON;
             this.showBoundingBox = false;
             this.showSubMeshesBoundingBox = false;
             this.onDispose = null;
-            this.checkCollisions = false;
             this.isBlocker = false;
             this.renderingGroupId = 0;
             this.receiveShadows = false;
@@ -46,6 +45,7 @@ var BABYLON;
             // Physics
             this._physicImpostor = BABYLON.PhysicsEngine.NoImpostor;
             // Collisions
+            this._checkCollisions = false;
             this.ellipsoid = new BABYLON.Vector3(0.5, 1, 0.5);
             this.ellipsoidOffset = new BABYLON.Vector3(0, 0, 0);
             this._collider = new BABYLON.Collider();
@@ -614,7 +614,20 @@ var BABYLON;
             }
             this.getScene().getPhysicsEngine()._updateBodyPosition(this);
         };
-        // Collisions
+        Object.defineProperty(AbstractMesh.prototype, "checkCollisions", {
+            // Collisions
+            get: function () {
+                return this._checkCollisions;
+            },
+            set: function (collisionEnabled) {
+                this._checkCollisions = collisionEnabled;
+                if (this.getScene().workerCollisions) {
+                    this.getScene().collisionCoordinator.onMeshUpdated(this);
+                }
+            },
+            enumerable: true,
+            configurable: true
+        });
         AbstractMesh.prototype.moveWithCollisions = function (velocity) {
             var globalPosition = this.getAbsolutePosition();
             globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPositionForCollisions);

+ 13 - 2
Babylon/Mesh/babylon.abstractMesh.ts

@@ -42,7 +42,6 @@
         public showBoundingBox = false;
         public showSubMeshesBoundingBox = false;
         public onDispose = null;
-        public checkCollisions = false;
         public isBlocker = false;
         public skeleton: Skeleton;
         public renderingGroupId = 0;
@@ -74,6 +73,7 @@
         public _physicRestitution: number;
 
         // Collisions
+        private _checkCollisions = false;
         public ellipsoid = new Vector3(0.5, 1, 0.5);
         public ellipsoidOffset = new Vector3(0, 0, 0);
         private _collider = new Collider();
@@ -710,6 +710,18 @@
 
 
         // Collisions
+
+        public get checkCollisions() : boolean {
+            return this._checkCollisions;
+        }
+
+        public set checkCollisions(collisionEnabled: boolean) {
+            this._checkCollisions = collisionEnabled;
+            if (this.getScene().workerCollisions) {
+                this.getScene().collisionCoordinator.onMeshUpdated(this);
+            }
+        }
+
         public moveWithCollisions(velocity: Vector3): void {
             var globalPosition = this.getAbsolutePosition();
 
@@ -966,4 +978,3 @@
         }
     }
 }
-

+ 3 - 3
Babylon/Mesh/babylon.polygonmesh.js

@@ -179,9 +179,9 @@ var BABYLON;
                     _this.addSide(positions, normals, uvs, indices, bounds, hole, depth, true);
                 });
             }
-            result.setVerticesData(positions, BABYLON.VertexBuffer.PositionKind, updatable);
-            result.setVerticesData(normals, BABYLON.VertexBuffer.NormalKind, updatable);
-            result.setVerticesData(uvs, BABYLON.VertexBuffer.UVKind, updatable);
+            result.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions, updatable);
+            result.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals, updatable);
+            result.setVerticesData(BABYLON.VertexBuffer.UVKind, uvs, updatable);
             result.setIndices(indices);
             return result;
         };

+ 3 - 3
Babylon/Mesh/babylon.polygonmesh.ts

@@ -199,9 +199,9 @@ module BABYLON {
                 });                               
             }
 
-            result.setVerticesData(positions, VertexBuffer.PositionKind, updatable);
-            result.setVerticesData(normals, VertexBuffer.NormalKind, updatable);
-            result.setVerticesData(uvs, VertexBuffer.UVKind, updatable);
+            result.setVerticesData(VertexBuffer.PositionKind, positions, updatable);
+            result.setVerticesData(VertexBuffer.NormalKind, normals, updatable);
+            result.setVerticesData(VertexBuffer.UVKind, uvs, updatable);
             result.setIndices(indices);
 
             return result;

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

@@ -2,7 +2,7 @@
 precision highp float;
 #endif
 
-#if defined(ALPHATEST) || defined(BASIC_RENDER) || defined(OPACITY)
+#if defined(ALPHATEST) || defined(NEED_UV)
 varying vec2 vUV;
 #endif
 

+ 10 - 5
Babylon/Tools/babylon.database.js

@@ -12,12 +12,16 @@ var BABYLON;
             this.manifestVersionFound = 0;
             this.mustUpdateRessources = false;
             this.hasReachedQuota = false;
-            this.checkManifestFile();
+            if (!Database.IDBStorageEnabled) {
+                this.callbackManifestChecked(true);
+            }
+            else {
+                this.checkManifestFile();
+            }
         }
         Database.prototype.checkManifestFile = function () {
             var _this = this;
             function noManifestFile() {
-                //BABYLON.Tools.Log("Valid manifest file not found. Scene & textures will be loaded directly from the web server.");
                 that.enableSceneOffline = false;
                 that.enableTexturesOffline = false;
                 that.callbackManifestChecked(false);
@@ -186,7 +190,7 @@ var BABYLON;
                     }
                     image.src = blobTextureURL;
                 };
-                if (Database.isUASupportingBlobStorage) {
+                if (Database.IsUASupportingBlobStorage) {
                     var xhr = new XMLHttpRequest(), blob;
                     xhr.open("GET", url, true);
                     xhr.responseType = "blob";
@@ -222,7 +226,7 @@ var BABYLON;
                             catch (ex) {
                                 // "DataCloneError" generated by Chrome when you try to inject blob into IndexedDB
                                 if (ex.code === 25) {
-                                    Database.isUASupportingBlobStorage = false;
+                                    Database.IsUASupportingBlobStorage = false;
                                 }
                                 image.src = url;
                             }
@@ -470,7 +474,8 @@ var BABYLON;
                 callback();
             }
         };
-        Database.isUASupportingBlobStorage = true;
+        Database.IsUASupportingBlobStorage = true;
+        Database.IDBStorageEnabled = true;
         Database.parseURL = function (url) {
             var a = document.createElement('a');
             a.href = url;

+ 10 - 5
Babylon/Tools/babylon.database.ts

@@ -13,7 +13,8 @@ module BABYLON {
         // Handling various flavors of prefixed version of IndexedDB
         private idbFactory = <IDBFactory> (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB);
 
-        static isUASupportingBlobStorage: boolean = true;
+        static IsUASupportingBlobStorage = true;
+        static IDBStorageEnabled = true;
 
         constructor(urlToScene: string, callbackManifestChecked: (boolean) => any) {
             this.callbackManifestChecked = callbackManifestChecked;
@@ -24,7 +25,12 @@ module BABYLON {
             this.manifestVersionFound = 0;
             this.mustUpdateRessources = false;
             this.hasReachedQuota = false;
-            this.checkManifestFile();
+
+            if (!Database.IDBStorageEnabled) {
+                this.callbackManifestChecked(true);
+            } else {
+                this.checkManifestFile();
+            }
         }
 
         static parseURL = (url: string) => {
@@ -47,7 +53,6 @@ module BABYLON {
 
         public checkManifestFile() {
             function noManifestFile() {
-                //BABYLON.Tools.Log("Valid manifest file not found. Scene & textures will be loaded directly from the web server.");
                 that.enableSceneOffline = false;
                 that.enableTexturesOffline = false;
                 that.callbackManifestChecked(false);
@@ -240,7 +245,7 @@ module BABYLON {
                     image.src = blobTextureURL;
                 };
 
-                if (Database.isUASupportingBlobStorage) { // Create XHR
+                if (Database.IsUASupportingBlobStorage) { // Create XHR
                     var xhr = new XMLHttpRequest(),
                         blob: Blob;
 
@@ -284,7 +289,7 @@ module BABYLON {
                             catch (ex) {
                                 // "DataCloneError" generated by Chrome when you try to inject blob into IndexedDB
                                 if (ex.code === 25) {
-                                    Database.isUASupportingBlobStorage = false;
+                                    Database.IsUASupportingBlobStorage = false;
                                 }
                                 image.src = url;
                             }

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

@@ -168,7 +168,7 @@ var BABYLON;
                 database.loadImageFromDB(url, img);
             };
             //ANY database to do!
-            if (database && database.enableTexturesOffline && BABYLON.Database.isUASupportingBlobStorage) {
+            if (database && database.enableTexturesOffline && BABYLON.Database.IsUASupportingBlobStorage) {
                 database.openAsync(loadFromIndexedDB, noIndexedDB);
             }
             else {

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

@@ -218,7 +218,7 @@
 
 
             //ANY database to do!
-            if (database && database.enableTexturesOffline && Database.isUASupportingBlobStorage) {
+            if (database && database.enableTexturesOffline && Database.IsUASupportingBlobStorage) {
                 database.openAsync(loadFromIndexedDB, noIndexedDB);
             }
             else {

+ 4 - 2
Babylon/babylon.engine.js

@@ -380,7 +380,6 @@ var BABYLON;
             this._compiledEffects = {};
             this._uintIndicesCurrentlySet = false;
             this._renderingCanvas = canvas;
-            this._canvasClientRect = this._renderingCanvas.getBoundingClientRect();
             options = options || {};
             options.antialias = antialias;
             // GL
@@ -793,7 +792,6 @@ var BABYLON;
         Engine.prototype.setSize = function (width, height) {
             this._renderingCanvas.width = width;
             this._renderingCanvas.height = height;
-            this._canvasClientRect = this._renderingCanvas.getBoundingClientRect();
             for (var index = 0; index < this.scenes.length; index++) {
                 var scene = this.scenes[index];
                 for (var camIndex = 0; camIndex < scene.cameras.length; camIndex++) {
@@ -1515,6 +1513,9 @@ var BABYLON;
             if (generateDepthBuffer) {
                 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthBuffer);
             }
+            if (generateMipMaps) {
+                this._gl.generateMipmap(this._gl.TEXTURE_2D);
+            }
             // Unbind
             gl.bindTexture(gl.TEXTURE_2D, null);
             gl.bindRenderbuffer(gl.RENDERBUFFER, null);
@@ -1746,6 +1747,7 @@ var BABYLON;
                 }
                 this._gl.disableVertexAttribArray(i);
             }
+            this._gl = null;
             // Events
             window.removeEventListener("blur", this._onBlur);
             window.removeEventListener("focus", this._onFocus);

+ 6 - 4
Babylon/babylon.engine.ts

@@ -532,7 +532,6 @@
         private _cachedIndexBuffer: WebGLBuffer;
         private _cachedEffectForVertexBuffers: Effect;
         private _currentRenderTarget: WebGLTexture;
-        private _canvasClientRect: ClientRect;
         private _uintIndicesCurrentlySet = false;
 
         private _workingCanvas: HTMLCanvasElement;
@@ -546,7 +545,6 @@
          */
         constructor(canvas: HTMLCanvasElement, antialias?: boolean, options?) {
             this._renderingCanvas = canvas;
-            this._canvasClientRect = this._renderingCanvas.getBoundingClientRect();
 
             options = options || {};
             options.antialias = antialias;
@@ -915,8 +913,6 @@
             this._renderingCanvas.width = width;
             this._renderingCanvas.height = height;
 
-            this._canvasClientRect = this._renderingCanvas.getBoundingClientRect();
-
             for (var index = 0; index < this.scenes.length; index++) {
                 var scene = this.scenes[index];
 
@@ -1816,6 +1812,10 @@
                 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthBuffer);
             }
 
+            if (generateMipMaps) {
+                this._gl.generateMipmap(this._gl.TEXTURE_2D);
+            }
+
             // Unbind
             gl.bindTexture(gl.TEXTURE_2D, null);
             gl.bindRenderbuffer(gl.RENDERBUFFER, null);
@@ -2100,6 +2100,8 @@
                 }
                 this._gl.disableVertexAttribArray(i);
             }
+            
+            this._gl = null;
 
             // Events
             window.removeEventListener("blur", this._onBlur);

File diff suppressed because it is too large
+ 59 - 18
babylon.2.1-rc.debug.js


File diff suppressed because it is too large
+ 22 - 21
babylon.2.1-rc.js


File diff suppressed because it is too large
+ 22 - 21
babylon.2.1-rc.noworker.js