Deltakosh 12 years ago
parent
commit
667f2142b5

+ 7 - 0
Babylon/Culling/Octrees/babylon.octree.js

@@ -11,6 +11,13 @@
     BABYLON.Octree.prototype.update = function(worldMin, worldMax, meshes) {
         BABYLON.Octree._CreateBlocks(worldMin, worldMax, meshes, this._maxBlockCapacity, this);
     };
+    
+    BABYLON.Octree.prototype.addMesh = function (mesh) {
+        for (var index = 0; index < this.blocks.length; index++) {
+            var block = this.blocks[index];
+            block.addMesh(mesh);
+        }
+    };
 
     BABYLON.Octree.prototype.select = function(frustumPlanes) {
         this._selection.reset();

+ 23 - 12
Babylon/Culling/Octrees/babylon.octreeBlock.js

@@ -34,20 +34,24 @@
     };
 
     // Methods
-    BABYLON.OctreeBlock.prototype.addEntries = function (meshes) {
-        for (var index = 0; index < meshes.length; index++) {
-            var mesh = meshes[index];
+    BABYLON.OctreeBlock.prototype.addMesh = function (mesh) {
+        if (this.blocks) {
+            for (var index = 0; index < this.blocks.length; index++) {
+                var block = this.blocks[index];
+                block.addMesh(mesh);
+            }
+            return;
+        }
 
-            if (mesh.getBoundingInfo().boundingBox.intersectsMinMax(this._minPoint, this._maxPoint)) {
-                var localMeshIndex = this.meshes.length;
-                this.meshes.push(mesh);
+        if (mesh.getBoundingInfo().boundingBox.intersectsMinMax(this._minPoint, this._maxPoint)) {
+            var localMeshIndex = this.meshes.length;
+            this.meshes.push(mesh);
 
-                this.subMeshes[localMeshIndex] = [];
-                for (var subIndex = 0; subIndex < mesh.subMeshes.length; subIndex++) {
-                    var subMesh = mesh.subMeshes[subIndex];
-                    if (mesh.subMeshes.length === 1 || subMesh.getBoundingInfo().boundingBox.intersectsMinMax(this._minPoint, this._maxPoint)) {
-                        this.subMeshes[localMeshIndex].push(subMesh);
-                    }
+            this.subMeshes[localMeshIndex] = [];
+            for (var subIndex = 0; subIndex < mesh.subMeshes.length; subIndex++) {
+                var subMesh = mesh.subMeshes[subIndex];
+                if (mesh.subMeshes.length === 1 || subMesh.getBoundingInfo().boundingBox.intersectsMinMax(this._minPoint, this._maxPoint)) {
+                    this.subMeshes[localMeshIndex].push(subMesh);
                 }
             }
         }
@@ -57,6 +61,13 @@
         }
     };
 
+    BABYLON.OctreeBlock.prototype.addEntries = function (meshes) {
+        for (var index = 0; index < meshes.length; index++) {
+            var mesh = meshes[index];
+            this.addMesh(mesh);
+        }       
+    };
+
     BABYLON.OctreeBlock.prototype.select = function (frustumPlanes, selection) {
         if (this.blocks) {
             for (var index = 0; index < this.blocks.length; index++) {

+ 4 - 11
Babylon/Culling/babylon.boundingBox.js

@@ -1,17 +1,10 @@
 var BABYLON = BABYLON || {};
 
 (function () {
-    BABYLON.BoundingBox = function (positions, start, count) {
-        this.minimum = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
-        this.maximum = new BABYLON.Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
-
-        for (var index = start; index < start + count; index++) {
-            var current = new BABYLON.Vector3(positions[index * 3], positions[index * 3 + 1], positions[index * 3 + 2]);
-
-            this.minimum = BABYLON.Vector3.Minimize(current, this.minimum);
-            this.maximum = BABYLON.Vector3.Maximize(current, this.maximum);
-        }
-
+    BABYLON.BoundingBox = function (minimum, maximum) {
+        this.minimum = minimum;
+        this.maximum = maximum;
+        
         // Bounding vectors
         this.vectors = [];
 

+ 3 - 3
Babylon/Culling/babylon.boundingInfo.js

@@ -1,9 +1,9 @@
 var BABYLON = BABYLON || {};
 
 (function () {
-    BABYLON.BoundingInfo = function (positions, verticesStart, verticesCount) {
-        this.boundingBox = new BABYLON.BoundingBox(positions, verticesStart, verticesCount);
-        this.boundingSphere = new BABYLON.BoundingSphere(positions, verticesStart, verticesCount);
+    BABYLON.BoundingInfo = function (minimum, maximum) {
+        this.boundingBox = new BABYLON.BoundingBox(minimum, maximum);
+        this.boundingSphere = new BABYLON.BoundingSphere(minimum, maximum);
     };
 
     // Methods

+ 3 - 10
Babylon/Culling/babylon.boundingSphere.js

@@ -1,16 +1,9 @@
 var BABYLON = BABYLON || {};
 
 (function () {
-    BABYLON.BoundingSphere = function (positions, start, count) {
-        var minimum = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
-        var maximum = new BABYLON.Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
-
-        for (var index = start; index < start + count; index++) {
-            var current = new BABYLON.Vector3(positions[index * 3], positions[index * 3 + 1], positions[index * 3 + 2]);
-
-            minimum = BABYLON.Vector3.Minimize(current, minimum);
-            maximum = BABYLON.Vector3.Maximize(current, maximum);
-        }
+    BABYLON.BoundingSphere = function (minimum, maximum) {
+        this.minimum = minimum;
+        this.maximum = maximum;
         
         var distance = BABYLON.Vector3.Distance(minimum, maximum);
         

+ 8 - 9
Babylon/Materials/babylon.standardMaterial.js

@@ -47,7 +47,7 @@
     };
 
     // Methods   
-    BABYLON.StandardMaterial.prototype.isReady = function (mesh) {
+    BABYLON.StandardMaterial.prototype.isReady = function (mesh, required) {
         if (!this.checkReadyOnEveryCall) {
             if (this._renderId === this._scene.getRenderId()) {
                 return true;
@@ -59,8 +59,7 @@
 
         // Textures
         if (this.diffuseTexture) {
-
-            if (!this.diffuseTexture.isReady()) {
+            if (!this.diffuseTexture.isReady(required)) {
                 return false;
             } else {
                 defines.push("#define DIFFUSE");
@@ -68,7 +67,7 @@
         }
 
         if (this.ambientTexture) {
-            if (!this.ambientTexture.isReady()) {
+            if (!this.ambientTexture.isReady(required)) {
                 return false;
             } else {
                 defines.push("#define AMBIENT");
@@ -76,7 +75,7 @@
         }
 
         if (this.opacityTexture) {
-            if (!this.opacityTexture.isReady()) {
+            if (!this.opacityTexture.isReady(required)) {
                 return false;
             } else {
                 defines.push("#define OPACITY");
@@ -84,7 +83,7 @@
         }
 
         if (this.reflectionTexture) {
-            if (!this.reflectionTexture.isReady()) {
+            if (!this.reflectionTexture.isReady(required)) {
                 return false;
             } else {
                 defines.push("#define REFLECTION");
@@ -92,7 +91,7 @@
         }
 
         if (this.emissiveTexture) {
-            if (!this.emissiveTexture.isReady()) {
+            if (!this.emissiveTexture.isReady(required)) {
                 return false;
             } else {
                 defines.push("#define EMISSIVE");
@@ -100,7 +99,7 @@
         }
 
         if (this.specularTexture) {
-            if (!this.specularTexture.isReady()) {
+            if (!this.specularTexture.isReady(required)) {
                 return false;
             } else {
                 defines.push("#define SPECULAR");
@@ -108,7 +107,7 @@
         }
 
         if (this._scene.getEngine().getCaps().standardDerivatives && this.bumpTexture) {
-            if (!this.bumpTexture.isReady()) {
+            if (!this.bumpTexture.isReady(required)) {
                 return false;
             } else {
                 defines.push("#define BUMP");

+ 26 - 13
Babylon/Materials/textures/babylon.baseTexture.js

@@ -5,36 +5,46 @@
         this._scene = scene;
         this._scene.textures.push(this);
     };
-    
+
     // Members
+    BABYLON.BaseTexture.prototype.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
+    BABYLON.BaseTexture.prototype.hasAlpha = false;
     BABYLON.BaseTexture.prototype.hasAlpha = false;
     BABYLON.BaseTexture.prototype.level = 1;
     BABYLON.BaseTexture.prototype._texture = null;
-    
+
     BABYLON.BaseTexture.prototype.onDispose = null;
 
     // Properties
     BABYLON.BaseTexture.prototype.getInternalTexture = function () {
         return this._texture;
     };
-    
-    BABYLON.BaseTexture.prototype.isReady = function () {
-        return (this._texture !== undefined && this._texture.isReady);
+
+    BABYLON.BaseTexture.prototype.isReady = function (required) {
+        if (!required && this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
+            return true;
+        }
+
+        if (this._texture) {
+            return this._texture.isReady;
+        }
+
+        return false;
     };
 
     // Methods
-    BABYLON.BaseTexture.prototype.getSize = function() {
+    BABYLON.BaseTexture.prototype.getSize = function () {
         if (this._texture._width) {
             return { width: this._texture._width, height: this._texture._height };
         }
-                    
+
         if (this._texture._size) {
             return { width: this._texture._size, height: this._texture._size };
         }
-                        
+
         return { width: 0, height: 0 };
     };
-    
+
     BABYLON.BaseTexture.prototype.getBaseSize = function () {
         if (!this.isReady())
             return { width: 0, height: 0 };
@@ -45,7 +55,7 @@
 
         return { width: this._texture._baseWidth, height: this._texture._baseHeight };
     };
-    
+
     BABYLON.BaseTexture.prototype._getFromCache = function (url, noMipmap) {
         var texturesCache = this._scene.getEngine().getLoadedTexturesCache();
         for (var index = 0; index < texturesCache.length; index++) {
@@ -60,7 +70,10 @@
         return null;
     };
 
-    BABYLON.BaseTexture.prototype.releaseInternalTexture = function() {
+    BABYLON.BaseTexture.prototype.delayLoad = function () {
+    };
+
+    BABYLON.BaseTexture.prototype.releaseInternalTexture = function () {
         if (!this._texture) {
             return;
         }
@@ -84,11 +97,11 @@
         }
 
         this.releaseInternalTexture();
-        
+
         // Remove from scene
         var index = this._scene.textures.indexOf(this);
         this._scene.textures.splice(index, 1);
-        
+
         // Callback
         if (this.onDispose) {
             this.onDispose();

+ 20 - 1
Babylon/Materials/textures/babylon.cubeTexture.js

@@ -6,13 +6,18 @@
         this._scene.textures.push(this);
         
         this.name = rootUrl;
+        this.url = rootUrl;
         this.hasAlpha = false;
         this.coordinatesMode = BABYLON.Texture.CUBIC_MODE;
 
         this._texture = this._getFromCache(rootUrl);
         
         if (!this._texture) {
-            this._texture = scene.getEngine().createCubeTexture(rootUrl, scene);
+            if (!scene.useDelayedTextureLoading) {
+                this._texture = scene.getEngine().createCubeTexture(rootUrl, scene);
+            } else {
+                this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
+            }            
         }
         
         this.isCube = true;
@@ -22,6 +27,20 @@
 
     BABYLON.CubeTexture.prototype = Object.create(BABYLON.BaseTexture.prototype);
 
+    // Methods
+    BABYLON.CubeTexture.prototype.delayLoad = function () {
+        if (this.delayLoadState != BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
+            return;
+        }
+
+        this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
+        this._texture = this._getFromCache(this.url);
+
+        if (!this._texture) {
+            this._texture = this._scene.getEngine().createCubeTexture(this.url, this._scene);
+        }
+    };
+
     BABYLON.CubeTexture.prototype._computeReflectionTextureMatrix = function() {
         return this._textureMatrix;
     };

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

@@ -6,17 +6,22 @@
         this._scene.textures.push(this);
 
         this.name = url;
+        this.url = url;
         this._noMipmap = noMipmap;
         this._invertY = invertY;
 
         this._texture = this._getFromCache(url, noMipmap);
 
         if (!this._texture) {
-            this._texture = scene.getEngine().createTexture(url, noMipmap, invertY, scene);
+            if (!scene.useDelayedTextureLoading) {
+                this._texture = scene.getEngine().createTexture(url, noMipmap, invertY, scene);
+            } else {
+                this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
+            }
         }
 
         // Animations
-        this.animations = [];        
+        this.animations = [];
     };
 
     BABYLON.Texture.prototype = Object.create(BABYLON.BaseTexture.prototype);
@@ -47,6 +52,19 @@
     BABYLON.Texture.prototype.coordinatesMode = BABYLON.Texture.EXPLICIT_MODE;
 
     // Methods    
+    BABYLON.Texture.prototype.delayLoad = function () {
+        if (this.delayLoadState != BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
+            return;
+        }
+        
+        this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
+        this._texture = this._getFromCache(this.url, this._noMipmap);
+
+        if (!this._texture) {
+            this._texture = this._scene.getEngine().createTexture(this.url, this._noMipmap, this._invertY, this._scene);
+        }
+    };
+
     BABYLON.Texture.prototype._prepareRowForTextureGeneration = function (x, y, z, t) {
         x -= this.uOffset + 0.5;
         y -= this.vOffset + 0.5;
@@ -89,7 +107,7 @@
             this._t1 = BABYLON.Vector3.Zero();
             this._t2 = BABYLON.Vector3.Zero();
         }
-        
+
         BABYLON.Matrix.RotationYawPitchRollToRef(this.vAng, this.uAng, this.wAng, this._rowGenerationMatrix);
 
         this._prepareRowForTextureGeneration(0, 0, 0, this._t0);
@@ -157,7 +175,7 @@
         return this._cachedTextureMatrix;
     };
 
-    BABYLON.Texture.prototype.clone = function() {
+    BABYLON.Texture.prototype.clone = function () {
         var newTexture = new BABYLON.Texture(this._texture.url, this._scene, this._noMipmap, this._invertY);
 
         // Base texture

+ 7 - 1
Babylon/Materials/textures/babylon.videoTexture.js

@@ -16,9 +16,10 @@
         this.video = document.createElement("video");
         this.video.width = textureSize.width;
         this.video.height = textureSize.height;
-        this.video.autoplay = true;
+        this.video.autoplay = false;
         this.video.loop = true;
         this.video.preload = true;
+        this._autoLaunch = true;
 
         var that = this;
         this.video.addEventListener("canplaythrough", function () {
@@ -39,6 +40,11 @@
     BABYLON.VideoTexture.prototype = Object.create(BABYLON.Texture.prototype);
 
     BABYLON.VideoTexture.prototype._update = function () {
+        if (this._autoLaunch) {
+            this._autoLaunch = false;
+            this.video.play();
+        }
+        
         var now = new Date();
 
         if (now - this._lastUpdate < 15) {

+ 79 - 32
Babylon/Mesh/babylon.mesh.js

@@ -13,6 +13,7 @@
 
         this.position = new BABYLON.Vector3(0, 0, 0);
         this.rotation = new BABYLON.Vector3(0, 0, 0);
+        this.rotationQuaternion = null;
         this.scaling = new BABYLON.Vector3(1, 1, 1);
 
         this._pivotMatrix = BABYLON.Matrix.Identity();
@@ -21,7 +22,7 @@
         this.subMeshes = [];
 
         this._renderId = 0;
-
+        
         // Animations
         this.animations = [];
 
@@ -58,6 +59,7 @@
     BABYLON.Mesh.BILLBOARDMODE_ALL = 7;
 
     // Members    
+    BABYLON.Mesh.prototype.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
     BABYLON.Mesh.prototype.material = null;
     BABYLON.Mesh.prototype.parent = null;
     BABYLON.Mesh.prototype._isReady = true;
@@ -97,6 +99,10 @@
     };
 
     BABYLON.Mesh.prototype.isVerticesDataPresent = function (kind) {
+        if (!this._vertexBuffers && this._delayInfo) {            
+            return this._delayInfo.indexOf(kind) !== -1;
+        }
+
         return this._vertexBuffers[kind] !== undefined;
     };
 
@@ -136,8 +142,8 @@
         if (!this._cache.position.equals(this.position))
             return false;
 
-        if (this.rotation instanceof BABYLON.Quaternion) {
-            if (!this._cache.rotationQuaternion.equals(this.rotation))
+        if (this.rotationQuaternion) {
+            if (!this._cache.rotationQuaternion.equals(this.rotationQuaternion))
                 return false;
         } else {
             if (!this._cache.rotation.equals(this.rotation))
@@ -180,9 +186,28 @@
     BABYLON.Mesh.prototype.isDisposed = function () {
         return this._isDisposed;
     };
+    
     // Methods
-    BABYLON.Mesh.prototype.computeWorldMatrix = function () {
-        if (this.isSynchronized()) {
+    BABYLON.Mesh.prototype._updateBoundingInfo = function() {
+        if (this._boundingInfo) {
+            this._scaleFactor = Math.max(this.scaling.x, this.scaling.y);
+            this._scaleFactor = Math.max(this._scaleFactor, this.scaling.z);
+
+            if (this.parent)
+                this._scaleFactor = this._scaleFactor * this.parent._scaleFactor;
+
+            this._boundingInfo._update(this._worldMatrix, this._scaleFactor);
+
+            for (var subIndex = 0; subIndex < this.subMeshes.length; subIndex++) {
+                var subMesh = this.subMeshes[subIndex];
+
+                subMesh.updateBoundingInfo(this._worldMatrix, this._scaleFactor);
+            }
+        }
+    };
+
+    BABYLON.Mesh.prototype.computeWorldMatrix = function (force) {
+        if (!force && this.isSynchronized()) {
             this._childrenFlag = false;
             return this._worldMatrix;
         }
@@ -196,9 +221,9 @@
         BABYLON.Matrix.ScalingToRef(this.scaling.x, this.scaling.y, this.scaling.z, this._localScaling);
 
         // Rotation
-        if (this.rotation instanceof BABYLON.Quaternion) {
-            this.rotation.toRotationMatrix(this._localRotation);
-            this._cache.rotationQuaternion.copyFrom(this.rotation);
+        if (this.rotationQuaternion) {
+            this.rotationQuaternion.toRotationMatrix(this._localRotation);
+            this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion);
         } else {
             BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._localRotation);
             this._cache.rotation.copyFrom(this.rotation);
@@ -252,21 +277,7 @@
         }
 
         // Bounding info
-        if (this._boundingInfo) {
-            this._scaleFactor = Math.max(this.scaling.x, this.scaling.y);
-            this._scaleFactor = Math.max(this._scaleFactor, this.scaling.z);
-
-            if (this.parent)
-                this._scaleFactor = this._scaleFactor * this.parent._scaleFactor;
-
-            this._boundingInfo._update(this._worldMatrix, this._scaleFactor);
-
-            for (var subIndex = 0; subIndex < this.subMeshes.length; subIndex++) {
-                var subMesh = this.subMeshes[subIndex];
-
-                subMesh.updateBoundingInfo(this._worldMatrix, this._scaleFactor);
-            }
-        }
+        this._updateBoundingInfo();
 
         return this._worldMatrix;
     };
@@ -312,7 +323,8 @@
             var stride = this._vertexBuffers[kind].getStrideSize();
             this._totalVertices = data.length / stride;
 
-            this._boundingInfo = new BABYLON.BoundingInfo(data, 0, this._totalVertices);
+            var extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._totalVertices);
+            this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
 
             this._createGlobalSubMesh();
         }
@@ -443,7 +455,26 @@
     };
 
     BABYLON.Mesh.prototype.isInFrustrum = function (frustumPlanes) {
-        return this._boundingInfo.isInFrustrum(frustumPlanes);
+        if (this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADING) {
+            return false;
+        }
+
+        var result = this._boundingInfo.isInFrustrum(frustumPlanes);
+        
+        if (result && this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
+            this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADING;
+            var that = this;
+
+            this._scene._addPendingData(this);
+
+            BABYLON.Tools.LoadFile(this.delayLoadingFile, function (data) {
+                BABYLON.SceneLoader._ImportGeometry(JSON.parse(data), that);
+                that.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
+                that._scene._removePendingData(that);
+            });
+        }
+
+        return result;
     };
 
     BABYLON.Mesh.prototype.setMaterialByID = function (id) {
@@ -476,7 +507,24 @@
     };
 
     // Geometry
-    BABYLON.Mesh.prototype.applyTransform = function (transform) {
+    BABYLON.Mesh.prototype.setLocalTransation = function(vector3) {
+        this.computeWorldMatrix();
+        var worldMatrix = this._worldMatrix.clone();
+        worldMatrix.setTranslation(BABYLON.Vector3.Zero());
+
+        this.position = BABYLON.Vector3.TransformCoordinates(vector3, worldMatrix);
+    };
+    
+    BABYLON.Mesh.prototype.getLocalTransation = function () {
+        this.computeWorldMatrix();
+        var invWorldMatrix = this._worldMatrix.clone();
+        invWorldMatrix.setTranslation(BABYLON.Vector3.Zero());
+        invWorldMatrix.invert();
+
+        return BABYLON.Vector3.TransformCoordinates(this.position, invWorldMatrix);
+    };
+
+    BABYLON.Mesh.prototype.bakeTransformIntoVertices = function (transform) {
         // Position
         if (!this.isVerticesDataPresent(BABYLON.VertexBuffer.PositionKind)) {
             return;
@@ -640,7 +688,8 @@
         BABYLON.Tools.DeepCopy(this, result, ["name", "material", "skeleton"], ["_indices", "_totalVertices"]);
 
         // Bounding info
-        result._boundingInfo = new BABYLON.BoundingInfo(this.getVerticesData(BABYLON.VertexBuffer.PositionKind), 0, this._totalVertices);
+        var extend = BABYLON.Tools.ExtractMinAndMax(this.getVerticesData(BABYLON.VertexBuffer.PositionKind), 0, this._totalVertices);
+        result._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
 
         // Material
         result.material = this.material;
@@ -840,7 +889,7 @@
         return sphere;
     };
 
-    // Cylinder (Code from SharpDX.org)
+    // Cylinder and cone (Code inspired by SharpDX.org)
     BABYLON.Mesh.CreateCylinder = function (name, height, diameterTop, diameterBottom, tessellation, scene, updatable) {
         var radiusTop = diameterTop / 2;
         var radiusBottom = diameterBottom / 2;
@@ -947,9 +996,7 @@
         cylinder.setIndices(indices);
 
         return cylinder;
-    };
-    
-    // Cone
+    };    
 
     // Torus  (Code from SharpDX.org)
     BABYLON.Mesh.CreateTorus = function (name, diameter, thickness, tessellation, scene, updatable) {
@@ -1218,5 +1265,5 @@
             normals[index * 3 + 1] = normal.y;
             normals[index * 3 + 2] = normal.z;
         }
-    };
+    };   
 })();

+ 2 - 1
Babylon/Mesh/babylon.subMesh.js

@@ -10,7 +10,8 @@
         this.indexStart = indexStart;
         this.indexCount = indexCount;
         
-        this._boundingInfo = new BABYLON.BoundingInfo(this._mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind), verticesStart, verticesCount);
+        var extend = BABYLON.Tools.ExtractMinAndMax(this._mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind), verticesStart, verticesCount);
+        this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
     };
     
     //Properties

+ 6 - 0
Babylon/Tools/babylon.math.js

@@ -1101,6 +1101,12 @@
         other.m[11] = -(((l1 * l35) - (l2 * l37)) + (l4 * l39)) * l27;
         other.m[15] = (((l1 * l36) - (l2 * l38)) + (l3 * l39)) * l27;
     };
+    
+    BABYLON.Matrix.prototype.setTranslation = function (vector3) {
+        this.m[12] = vector3.x;
+        this.m[13] = vector3.y;
+        this.m[14] = vector3.z;
+    };
 
     BABYLON.Matrix.prototype.multiply = function (other) {
         var result = new BABYLON.Matrix();

+ 84 - 39
Babylon/Tools/babylon.sceneLoader.js

@@ -272,12 +272,16 @@
         light.specular = BABYLON.Color3.FromArray(parsedLight.specular);
     };
 
-    var parseMesh = function (parsedMesh, scene) {
+    var parseMesh = function (parsedMesh, scene, rootUrl) {
         var mesh = new BABYLON.Mesh(parsedMesh.name, scene);
         mesh.id = parsedMesh.id;
 
         mesh.position = BABYLON.Vector3.FromArray(parsedMesh.position);
-        mesh.rotation = (parsedMesh.rotation.length == 3) ? BABYLON.Vector3.FromArray(parsedMesh.rotation) : BABYLON.Quaternion.FromArray(parsedMesh.rotation);
+        if (parsedMesh.rotation.length == 3) {
+            mesh.rotation = BABYLON.Vector3.FromArray(parsedMesh.rotation);
+        } else {
+            mesh.rotationQuaternion = BABYLON.Quaternion.FromArray(parsedMesh.rotation);
+        }
         mesh.scaling = BABYLON.Vector3.FromArray(parsedMesh.scaling);
         
         if (parsedMesh.localMatrix) {
@@ -297,42 +301,34 @@
 
         mesh.checkCollisions = parsedMesh.checkCollisions;
 
-        if (parsedMesh.positions && parsedMesh.normals && parsedMesh.indices) {
-            mesh.setVerticesData(parsedMesh.positions, BABYLON.VertexBuffer.PositionKind, false);
-            mesh.setVerticesData(parsedMesh.normals, BABYLON.VertexBuffer.NormalKind, false);
+        if (parsedMesh.delayLoadingFile) {
+            mesh.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
+            mesh.delayLoadingFile = rootUrl + parsedMesh.delayLoadingFile;
+            mesh._boundingInfo = new BABYLON.BoundingInfo(BABYLON.Vector3.FromArray(parsedMesh.boundingBoxMinimum), BABYLON.Vector3.FromArray(parsedMesh.boundingBoxMaximum));
 
-            if (parsedMesh.uvs) {
-                mesh.setVerticesData(parsedMesh.uvs, BABYLON.VertexBuffer.UVKind, false);
+            mesh._delayInfo = [];
+            if (parsedMesh.hasUVs) {
+                mesh._delayInfo.push(BABYLON.VertexBuffer.UVKind);
             }
 
-            if (parsedMesh.uvs2) {
-                mesh.setVerticesData(parsedMesh.uvs2, BABYLON.VertexBuffer.UV2Kind, false);
+            if (parsedMesh.hasUVs2) {
+                mesh._delayInfo.push(BABYLON.VertexBuffer.UV2Kind);
             }
 
-            if (parsedMesh.colors) {
-                mesh.setVerticesData(parsedMesh.colors, BABYLON.VertexBuffer.ColorKind, false);
+            if (parsedMesh.hasColors) {
+                mesh._delayInfo.push(BABYLON.VertexBuffer.ColorKind);
             }
 
-            if (parsedMesh.matricesIndices) {
-                var floatIndices = [];
-
-                for (var i = 0; i < parsedMesh.matricesIndices.length; i++) {
-                    var matricesIndex = parsedMesh.matricesIndices[i];
-
-                    floatIndices.push(matricesIndex & 0x000000FF);
-                    floatIndices.push((matricesIndex & 0x0000FF00) >> 8);
-                    floatIndices.push((matricesIndex & 0x00FF0000) >> 16);
-                    floatIndices.push(matricesIndex >> 24);
-                }
-
-                mesh.setVerticesData(floatIndices, BABYLON.VertexBuffer.MatricesIndicesKind, false);
+            if (parsedMesh.hasMatricesIndices) {
+                mesh._delayInfo.push(BABYLON.VertexBuffer.MatricesIndicesKind);
             }
-
-            if (parsedMesh.matricesWeights) {
-                mesh.setVerticesData(parsedMesh.matricesWeights, BABYLON.VertexBuffer.MatricesWeightsKind, false);
+            
+            if (parsedMesh.hasMatricesWeights) {
+                mesh._delayInfo.push(BABYLON.VertexBuffer.MatricesWeightsKind);
             }
 
-            mesh.setIndices(parsedMesh.indices);
+        } else {
+            BABYLON.SceneLoader._ImportGeometry(parsedMesh, mesh);
         }
 
         // Parent
@@ -352,16 +348,6 @@
             mesh.skeleton = scene.getLastSkeletonByID(parsedMesh.skeletonId);
         }
 
-        // SubMeshes
-        if (parsedMesh.subMeshes) {
-            mesh.subMeshes = [];
-            for (var subIndex = 0; subIndex < parsedMesh.subMeshes.length; subIndex++) {
-                var parsedSubMesh = parsedMesh.subMeshes[subIndex];
-
-                var subMesh = new BABYLON.SubMesh(parsedSubMesh.materialIndex, parsedSubMesh.verticesStart, parsedSubMesh.verticesCount, parsedSubMesh.indexStart, parsedSubMesh.indexCount, mesh);
-            }
-        }
-
         // Animations
         if (parsedMesh.animations) {
             for (var animationIndex = 0; animationIndex < parsedMesh.animations.length; animationIndex++) {
@@ -393,6 +379,64 @@
     };
 
     BABYLON.SceneLoader = {
+        _ImportGeometry: function (parsedGeometry, mesh) {
+            // Geometry
+            if (parsedGeometry.positions && parsedGeometry.normals && parsedGeometry.indices) {
+                mesh.setVerticesData(parsedGeometry.positions, BABYLON.VertexBuffer.PositionKind, false);
+                mesh.setVerticesData(parsedGeometry.normals, BABYLON.VertexBuffer.NormalKind, false);
+
+                if (parsedGeometry.uvs) {
+                    mesh.setVerticesData(parsedGeometry.uvs, BABYLON.VertexBuffer.UVKind, false);
+                }
+
+                if (parsedGeometry.uvs2) {
+                    mesh.setVerticesData(parsedGeometry.uvs2, BABYLON.VertexBuffer.UV2Kind, false);
+                }
+
+                if (parsedGeometry.colors) {
+                    mesh.setVerticesData(parsedGeometry.colors, BABYLON.VertexBuffer.ColorKind, false);
+                }
+
+                if (parsedGeometry.matricesIndices) {
+                    var floatIndices = [];
+
+                    for (var i = 0; i < parsedGeometry.matricesIndices.length; i++) {
+                        var matricesIndex = parsedGeometry.matricesIndices[i];
+
+                        floatIndices.push(matricesIndex & 0x000000FF);
+                        floatIndices.push((matricesIndex & 0x0000FF00) >> 8);
+                        floatIndices.push((matricesIndex & 0x00FF0000) >> 16);
+                        floatIndices.push(matricesIndex >> 24);
+                    }
+
+                    mesh.setVerticesData(floatIndices, BABYLON.VertexBuffer.MatricesIndicesKind, false);
+                }
+
+                if (parsedGeometry.matricesWeights) {
+                    mesh.setVerticesData(parsedGeometry.matricesWeights, BABYLON.VertexBuffer.MatricesWeightsKind, false);
+                }
+
+                mesh.setIndices(parsedGeometry.indices);
+            }
+            
+            // SubMeshes
+            if (parsedGeometry.subMeshes) {
+                mesh.subMeshes = [];
+                for (var subIndex = 0; subIndex < parsedGeometry.subMeshes.length; subIndex++) {
+                    var parsedSubMesh = parsedGeometry.subMeshes[subIndex];
+
+                    var subMesh = new BABYLON.SubMesh(parsedSubMesh.materialIndex, parsedSubMesh.verticesStart, parsedSubMesh.verticesCount, parsedSubMesh.indexStart, parsedSubMesh.indexCount, mesh);
+                }
+            }
+            
+            // Update
+            mesh.computeWorldMatrix(true);
+
+            var scene = mesh.getScene();
+            if (scene._selectionOctree) {
+                scene._selectionOctree.addMesh(mesh);
+            }
+        },
         ImportMesh: function (meshName, rootUrl, sceneFilename, scene, then, progressCallBack) {
             // Checking if a manifest file has been set for this scene and if offline mode has been requested
             var database = new BABYLON.Database(rootUrl + sceneFilename);
@@ -487,6 +531,7 @@
                 scene.database = database;
 
                 // Scene
+                scene.useDelayedTextureLoading = parsedData.useDelayedTextureLoading;
                 scene.autoClear = parsedData.autoClear;
                 scene.clearColor = BABYLON.Color3.FromArray(parsedData.clearColor);
                 scene.ambientColor = BABYLON.Color3.FromArray(parsedData.ambientColor);
@@ -563,7 +608,7 @@
                 // Meshes
                 for (var index = 0; index < parsedData.meshes.length; index++) {
                     var parsedMesh = parsedData.meshes[index];
-                    parseMesh(parsedMesh, scene);
+                    parseMesh(parsedMesh, scene, rootUrl);
                 }
 
                 // Particles Systems

+ 17 - 0
Babylon/Tools/babylon.tools.js

@@ -3,6 +3,23 @@
 (function () {
     BABYLON.Tools = {};
 
+    BABYLON.Tools.ExtractMinAndMax = function (positions, start, count) {
+        var minimum = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
+        var maximum = new BABYLON.Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
+
+        for (var index = start; index < start + count; index++) {
+            var current = new BABYLON.Vector3(positions[index * 3], positions[index * 3 + 1], positions[index * 3 + 2]);
+
+            minimum = BABYLON.Vector3.Minimize(current, minimum);
+            maximum = BABYLON.Vector3.Maximize(current, maximum);
+        }
+
+        return {
+            minimum: minimum,
+            maximum: maximum
+        };
+    };
+
     // Smart array
     BABYLON.Tools.SmartArray = function(capacity) {
         this.data = new Array(capacity);

+ 12 - 1
Babylon/babylon.engine.js

@@ -571,7 +571,7 @@
 
         this._cachedVertexBuffers = null;
         this._cachedVertexBuffers = null;
-        _cachedEffectForVertexBuffers = null;
+        this._cachedEffectForVertexBuffers = null;
     };
 
     var getExponantOfTwo = function (value, max) {
@@ -861,6 +861,7 @@
         if (channel < 0) {
             return;
         }
+        // Not ready?
         if (!texture || !texture.isReady()) {
             if (this._activeTexturesCache[channel] != null) {
                 this._gl.activeTexture(this._gl["TEXTURE" + channel]);
@@ -871,10 +872,14 @@
             return;
         }
 
+        // Video
         if (texture instanceof BABYLON.VideoTexture) {
             if (texture._update()) {
                 this._activeTexturesCache[channel] = null;
             }
+        } else if (texture.delayLoadState == BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) { // Delay loading
+            texture.delayLoad();
+            return;
         }
 
         if (this._activeTexturesCache[channel] == texture) {
@@ -948,6 +953,12 @@
     BABYLON.Engine.ALPHA_DISABLE = 0;
     BABYLON.Engine.ALPHA_ADD = 1;
     BABYLON.Engine.ALPHA_COMBINE = 2;
+    
+    // Statics
+    BABYLON.Engine.DELAYLOADSTATE_NONE = 0;
+    BABYLON.Engine.DELAYLOADSTATE_LOADED = 1;
+    BABYLON.Engine.DELAYLOADSTATE_LOADING = 2;
+    BABYLON.Engine.DELAYLOADSTATE_NOTLOADED = 4;
 
     BABYLON.Engine.epsilon = 0.001;
     BABYLON.Engine.collisionsEpsilon = 0.001;

+ 32 - 25
Babylon/babylon.scene.js

@@ -18,6 +18,7 @@
         this._renderDuration = 0;
 
         this._renderId = 0;
+        this._executeWhenReadyTimeoutId = -1;
 
         this._toBeDisposed = new BABYLON.Tools.SmartArray(256);
 
@@ -148,32 +149,26 @@
 
     // Ready
     BABYLON.Scene.prototype.isReady = function () {
+        if (this._pendingData.length > 0) {
+            return false;
+        }
+
         for (var index = 0; index < this.meshes.length; index++) {
             var mesh = this.meshes[index];
             var mat = mesh.material;
-            if (mat && !mat.isReady(mesh)) {
+
+            if (mesh.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADING) {
                 return false;
             }
-        }
 
-        return true;
-    };
-
-    BABYLON.Scene.prototype.getWaitingItemsCount = function () {
-        return this._pendingData.length;
-    };
-
-    BABYLON.Scene.prototype.executeWhenReady = function (func) {
-        if (this.isReady()) {
-            func();
-            return;
+            if (mat) {
+                if (!mat.isReady(mesh, mesh.delayLoadState !== BABYLON.Engine.DELAYLOADSTATE_NOTLOADED)) {
+                    return false;
+                }
+            }
         }
 
-        if (this._pendingData.length === 0) {
-            func();
-            return;
-        }
-        this._onReadyCallbacks.push(func);
+        return true;
     };
 
     BABYLON.Scene.prototype.registerBeforeRender = function (func) {
@@ -197,14 +192,24 @@
 
         if (index !== -1) {
             this._pendingData.splice(index, 1);
+        }
+    };
+    
+    BABYLON.Scene.prototype.getWaitingItemsCount = function () {
+        return this._pendingData.length;
+    };
 
-            if (this._pendingData.length === 0) {
-                var that = this;
-                setTimeout(function () {
-                    that._checkIsReady();
-                }, 150);
-            }
+    BABYLON.Scene.prototype.executeWhenReady = function (func) {
+        this._onReadyCallbacks.push(func);
+
+        if (this._executeWhenReadyTimeoutId !== -1) {
+            return;
         }
+        
+        var that = this;
+        this._executeWhenReadyTimeoutId = setTimeout(function () {
+            that._checkIsReady();
+        }, 150);
     };
 
     BABYLON.Scene.prototype._checkIsReady = function () {
@@ -214,10 +219,12 @@
             });
 
             this._onReadyCallbacks = [];
+            this._executeWhenReadyTimeoutId = -1;
             return;
         }
+        
         var that = this;
-        setTimeout(function () {
+        this._executeWhenReadyTimeoutId = setTimeout(function () {
             that._checkIsReady();
         }, 150);
     };

File diff suppressed because it is too large
+ 0 - 13
babylon.1.4.2.js


File diff suppressed because it is too large
+ 13 - 0
babylon.1.4.3.js


+ 5 - 0
what's new.md

@@ -1,5 +1,10 @@
 Changes list
 ============
+- 1.4.3:
+ - **Updates**
+ - New ```mesh.setLocalTranslation``` and ```mesh.getLocalTranslation``` functions ([deltakosh](http://www.github.com/deltakosh))
+ - New ```matrix.setTranslation``` function ([deltakosh](http://www.github.com/deltakosh))
+ - ```mesh.rotation``` and ```mesh.rotationQuaternion``` are now two separated functions ([deltakosh](http://www.github.com/deltakosh)) 
 - 1.4.2:
  - **Bugfixes**
  - Fixing an issue with scene.executeWhenReady ([deltakosh](http://www.github.com/deltakosh))