Browse Source

Fixing loading bugs
Release candidate

David Catuhe 11 năm trước cách đây
mục cha
commit
abc9760177

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

@@ -48,6 +48,7 @@
                 if (!this._nextActiveAction._child._actionManager) {
                     this._nextActiveAction._child._actionManager = this._actionManager;
                 }
+
                 this._nextActiveAction = this._nextActiveAction._child;
             } else {
                 this._nextActiveAction = this;

+ 2 - 1
Babylon/Actions/babylon.action.ts

@@ -55,8 +55,9 @@
             if (this._nextActiveAction._child) {
 
                 if (!this._nextActiveAction._child._actionManager) {
-                    this._nextActiveAction._child._actionManager = this._actionManager
+                    this._nextActiveAction._child._actionManager = this._actionManager;
                 }
+
                 this._nextActiveAction = this._nextActiveAction._child;
             } else {
                 this._nextActiveAction = this;

+ 1 - 1
Babylon/Cameras/babylon.camera.ts

@@ -24,7 +24,7 @@
         public _projectionMatrix = new BABYLON.Matrix();
         private _worldMatrix: Matrix;
         public _postProcesses = new Array<PostProcess>();
-        public _postProcessesTakenIndices = [];
+        public _postProcessesTakenIndices = [];               
 
         constructor(name: string, public position: Vector3, scene: Scene) {
             super(name, scene);

+ 2 - 0
Babylon/Cameras/babylon.targetCamera.ts

@@ -21,6 +21,8 @@
 
         public _reset:() => void;
 
+        public _waitingLockedTargetId:string;
+
         constructor(name:string, position:Vector3, scene:Scene) {
             super(name, position, scene);
         }

+ 1 - 2
Babylon/Cameras/babylon.webVRCamera.js

@@ -26,8 +26,7 @@ var BABYLON;
             this._sensorDevice = null;
             this._hmdDevice = null;
 
-            // Search for a HmdDevice.
-            while (i < size && this._hmdDevice === null) { 
+            while (i < size && this._hmdDevice === null) {
                 if (devices[i] instanceof HMDVRDevice) {
                     this._hmdDevice = devices[i];
                 }

+ 1 - 1
Babylon/Cameras/babylon.webVRCamera.ts

@@ -24,7 +24,7 @@ module BABYLON {
             this._hmdDevice = null;
 
             // Search for a HmdDevice.
-            while (i < size && this._hmdDevice === null) { 
+            while (i < size && this._hmdDevice === null) {
                 if (devices[i] instanceof HMDVRDevice) {
                     this._hmdDevice = devices[i];
                 }

+ 73 - 23
Babylon/Loading/Plugins/babylon.babylonFileLoader.js

@@ -354,7 +354,54 @@
         };
 
         var parseCamera = function (parsedCamera, scene) {
-            var camera = new BABYLON.FreeCamera(parsedCamera.name, BABYLON.Vector3.FromArray(parsedCamera.position), scene);
+            var camera;
+            var position = BABYLON.Vector3.FromArray(parsedCamera.position);
+            var lockedTargetMesh = (parsedCamera.lockedTargetId) ? scene.getLastMeshByID(parsedCamera.lockedTargetId) : null;
+
+            if (parsedCamera.type === "AnaglyphArcRotateCamera" || parsedCamera.type === "ArcRotateCamera") {
+                var alpha = parsedCamera.alpha;
+                var beta = parsedCamera.beta;
+                var radius = parsedCamera.radius;
+                if (parsedCamera.type === "AnaglyphArcRotateCamera") {
+                    var eye_space = parsedCamera.eye_space;
+                    camera = new BABYLON.AnaglyphArcRotateCamera(parsedCamera.name, alpha, beta, radius, lockedTargetMesh, eye_space, scene);
+                } else {
+                    camera = new BABYLON.ArcRotateCamera(parsedCamera.name, alpha, beta, radius, lockedTargetMesh, scene);
+                }
+            } else if (parsedCamera.type === "AnaglyphFreeCamera") {
+                var eye_space = parsedCamera.eye_space;
+                camera = new BABYLON.AnaglyphFreeCamera(parsedCamera.name, position, eye_space, scene);
+            } else if (parsedCamera.type === "DeviceOrientationCamera") {
+                camera = new BABYLON.DeviceOrientationCamera(parsedCamera.name, position, scene);
+            } else if (parsedCamera.type === "FollowCamera") {
+                camera = new BABYLON.FollowCamera(parsedCamera.name, position, scene);
+                camera.heightOffset = parsedCamera.heightOffset;
+                camera.radius = parsedCamera.radius;
+                camera.rotationOffset = parsedCamera.rotationOffset;
+                if (lockedTargetMesh)
+                    camera.target = lockedTargetMesh;
+            } else if (parsedCamera.type === "GamepadCamera") {
+                camera = new BABYLON.GamepadCamera(parsedCamera.name, position, scene);
+            } else if (parsedCamera.type === "OculusCamera") {
+                camera = new BABYLON.OculusCamera(parsedCamera.name, position, scene);
+            } else if (parsedCamera.type === "TouchCamera") {
+                camera = new BABYLON.TouchCamera(parsedCamera.name, position, scene);
+            } else if (parsedCamera.type === "VirtualJoysticksCamera") {
+                camera = new BABYLON.VirtualJoysticksCamera(parsedCamera.name, position, scene);
+            } else if (parsedCamera.type === "WebVRCamera") {
+                camera = new BABYLON.WebVRCamera(parsedCamera.name, position, scene);
+            } else if (parsedCamera.type === "VRDeviceOrientationCamera") {
+                camera = new BABYLON.VRDeviceOrientationCamera(parsedCamera.name, position, scene);
+            } else {
+                // Free Camera is the default value
+                camera = new BABYLON.FreeCamera(parsedCamera.name, position, scene);
+            }
+
+            // Test for lockedTargetMesh & FreeCamera outside of if-else-if nest, since things like GamepadCamera extend FreeCamera
+            if (lockedTargetMesh && camera instanceof BABYLON.FreeCamera) {
+                camera.lockedTarget = lockedTargetMesh;
+            }
+
             camera.id = parsedCamera.id;
 
             BABYLON.Tags.AddTagsTo(camera, parsedCamera.tags);
@@ -371,11 +418,6 @@
                 camera.rotation = BABYLON.Vector3.FromArray(parsedCamera.rotation);
             }
 
-            // Locked target
-            if (parsedCamera.lockedTargetId) {
-                camera._waitingLockedTargetId = parsedCamera.lockedTargetId;
-            }
-
             camera.fov = parsedCamera.fov;
             camera.minZ = parsedCamera.minZ;
             camera.maxZ = parsedCamera.maxZ;
@@ -599,7 +641,7 @@
 
             // Parent
             if (parsedMesh.parentId) {
-                mesh.parent = scene.getLastEntryByID(parsedMesh.parentId);
+                mesh._waitingParentId = parsedMesh.parentId;
             }
 
             // Geometry
@@ -990,6 +1032,14 @@
                     }
                 }
 
+                for (index = 0; index < scene.meshes.length; index++) {
+                    var currentMesh = scene.meshes[index];
+                    if (currentMesh._waitingParentId) {
+                        currentMesh.parent = scene.getLastEntryByID(currentMesh._waitingParentId);
+                        currentMesh._waitingParentId = undefined;
+                    }
+                }
+
                 // Particles
                 if (parsedData.particleSystems) {
                     for (index = 0; index < parsedData.particleSystems.length; index++) {
@@ -1027,15 +1077,6 @@
                     parseLight(parsedLight, scene);
                 }
 
-                for (index = 0; index < parsedData.cameras.length; index++) {
-                    var parsedCamera = parsedData.cameras[index];
-                    parseCamera(parsedCamera, scene);
-                }
-
-                if (parsedData.activeCameraID) {
-                    scene.setActiveCameraByID(parsedData.activeCameraID);
-                }
-
                 // Materials
                 if (parsedData.materials) {
                     for (index = 0; index < parsedData.materials.length; index++) {
@@ -1140,19 +1181,28 @@
                     parseMesh(parsedMesh, scene, rootUrl);
                 }
 
+                for (index = 0; index < parsedData.cameras.length; index++) {
+                    var parsedCamera = parsedData.cameras[index];
+                    parseCamera(parsedCamera, scene);
+                }
+
+                if (parsedData.activeCameraID) {
+                    scene.setActiveCameraByID(parsedData.activeCameraID);
+                }
+
                 for (index = 0; index < scene.cameras.length; index++) {
                     var camera = scene.cameras[index];
                     if (camera._waitingParentId) {
                         camera.parent = scene.getLastEntryByID(camera._waitingParentId);
-                        delete camera._waitingParentId;
+                        camera._waitingParentId = undefined;
                     }
+                }
 
-                    if (camera instanceof BABYLON.FreeCamera) {
-                        var freecamera = camera;
-                        if (freecamera._waitingLockedTargetId) {
-                            freecamera.lockedTarget = scene.getLastEntryByID(freecamera._waitingLockedTargetId);
-                            delete freecamera._waitingLockedTargetId;
-                        }
+                for (index = 0; index < scene.meshes.length; index++) {
+                    var mesh = scene.meshes[index];
+                    if (mesh._waitingParentId) {
+                        mesh.parent = scene.getLastEntryByID(mesh._waitingParentId);
+                        mesh._waitingParentId = undefined;
                     }
                 }
 

+ 62 - 48
Babylon/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -352,57 +352,64 @@
         }
     };
 
-    var parseCamera = (parsedCamera, scene) => {
+    var parseCamera = (parsedCamera, scene: Scene) => {
         var camera;
         var position = Vector3.FromArray(parsedCamera.position);
-        var lockedTargetMesh = (parsedCamera.lockedTargetId) ? scene.getMeshByID(parsedCamera.lockedTargetId) : null; // cannot use getLastEntryByID due to FollowCamera
-        
-        if (parsedCamera.type === "AnaglyphArcRotateCamera" || parsedCamera.type === "ArcRotateCamera"){
+        var lockedTargetMesh = (parsedCamera.lockedTargetId) ? scene.getLastMeshByID(parsedCamera.lockedTargetId) : null;
+
+        if (parsedCamera.type === "AnaglyphArcRotateCamera" || parsedCamera.type === "ArcRotateCamera") {
             var alpha = parsedCamera.alpha;
             var beta = parsedCamera.beta;
             var radius = parsedCamera.radius;
-            if (parsedCamera.type === "AnaglyphArcRotateCamera"){
+            if (parsedCamera.type === "AnaglyphArcRotateCamera") {
                 var eye_space = parsedCamera.eye_space;
                 camera = new AnaglyphArcRotateCamera(parsedCamera.name, alpha, beta, radius, lockedTargetMesh, eye_space, scene);
-            }else{
+            } else {
                 camera = new ArcRotateCamera(parsedCamera.name, alpha, beta, radius, lockedTargetMesh, scene);
             }
-                     
-        }else if (parsedCamera.type === "AnaglyphFreeCamera"){
+
+        } else if (parsedCamera.type === "AnaglyphFreeCamera") {
             var eye_space = parsedCamera.eye_space;
             camera = new AnaglyphFreeCamera(parsedCamera.name, position, eye_space, scene);
-            
-        }else if (parsedCamera.type === "DeviceOrientationCamera"){
+
+        } else if (parsedCamera.type === "DeviceOrientationCamera") {
             camera = new DeviceOrientationCamera(parsedCamera.name, position, scene);
-            
-        }else if (parsedCamera.type === "FollowCamera"){
+
+        } else if (parsedCamera.type === "FollowCamera") {
             camera = new FollowCamera(parsedCamera.name, position, scene);
             camera.heightOffset = parsedCamera.heightOffset;
             camera.radius = parsedCamera.radius;
             camera.rotationOffset = parsedCamera.rotationOffset;
             if (lockedTargetMesh)
                 (<FollowCamera>camera).target = lockedTargetMesh;
-            
-        }else if (parsedCamera.type === "GamepadCamera"){
+
+        } else if (parsedCamera.type === "GamepadCamera") {
             camera = new GamepadCamera(parsedCamera.name, position, scene);
-            
-        }else if (parsedCamera.type === "OculusCamera"){
+
+        } else if (parsedCamera.type === "OculusCamera") {
             camera = new OculusCamera(parsedCamera.name, position, scene);
-            
-        }else if (parsedCamera.type === "TouchCamera"){
+
+        } else if (parsedCamera.type === "TouchCamera") {
             camera = new TouchCamera(parsedCamera.name, position, scene);
-            
-        }else if (parsedCamera.type === "VirtualJoysticksCamera"){
+
+        } else if (parsedCamera.type === "VirtualJoysticksCamera") {
             camera = new VirtualJoysticksCamera(parsedCamera.name, position, scene);
 
-        }else{
-            // Free Camera is not tested for due to some exporters that may not set a 'type'
+        } else if (parsedCamera.type === "WebVRCamera") {
+            camera = new WebVRCamera(parsedCamera.name, position, scene);
+
+        } else if (parsedCamera.type === "VRDeviceOrientationCamera") {
+            camera = new VRDeviceOrientationCamera(parsedCamera.name, position, scene);
+
+        } else {
+            // Free Camera is the default value
             camera = new FreeCamera(parsedCamera.name, position, scene);
         }
-        
-        // test for lockedTargetMesh & FreeCamera outside of if-else-if nest, since things like GamepadCamera extend FreeCamera
-        if (lockedTargetMesh && camera instanceof FreeCamera)
-             (<FreeCamera>camera).lockedTarget = lockedTargetMesh;
+
+        // Test for lockedTargetMesh & FreeCamera outside of if-else-if nest, since things like GamepadCamera extend FreeCamera
+        if (lockedTargetMesh && camera instanceof FreeCamera) {
+            (<FreeCamera>camera).lockedTarget = lockedTargetMesh;
+        }
 
         camera.id = parsedCamera.id;
 
@@ -410,7 +417,7 @@
 
         // Parent
         if (parsedCamera.parentId) {
-            camera.parentId = parsedCamera.parentId;
+            camera._waitingParentId = parsedCamera.parentId;
         }
 
         // Target
@@ -598,12 +605,7 @@
     };
 
     var parseMesh = (parsedMesh, scene, rootUrl) => {
-         var mesh : any;
-        if (parsedMesh.isAutomaton){
-            mesh = new BABYLON.Automaton(parsedMesh.name, scene);
-        }else{
-            mesh = new BABYLON.Mesh(parsedMesh.name, scene);
-        }
+        var mesh = new BABYLON.Mesh(parsedMesh.name, scene);
         mesh.id = parsedMesh.id;
 
         BABYLON.Tags.AddTagsTo(mesh, parsedMesh.tags);
@@ -648,7 +650,7 @@
 
         // Parent
         if (parsedMesh.parentId) {
-            mesh.parent = scene.getLastEntryByID(parsedMesh.parentId);
+            mesh._waitingParentId = parsedMesh.parentId;
         }
 
         // Geometry
@@ -733,20 +735,6 @@
             mesh.layerMask = 0xFFFFFFFF;
         }
 
-        // shape key groups
-        if (parsedMesh.shapeKeyGroups) {
-            var shapeKeyGroup : BABYLON.ShapeKeyGroup;
-            for (var index = 0; index < parsedMesh.shapeKeyGroups.length; index++) {
-                var parsedShapeKeyGroup = parsedMesh.shapeKeyGroups[index];
-                shapeKeyGroup = new BABYLON.ShapeKeyGroup(mesh, parsedShapeKeyGroup.group, parsedShapeKeyGroup.affectedIndices, parsedShapeKeyGroup.basisState);
-                for (var stateIdx = 0; stateIdx < parsedShapeKeyGroup.states.length; stateIdx++) {
-                    var parsedState = parsedShapeKeyGroup.states[stateIdx];
-                    shapeKeyGroup.addShapeKey(parsedState.stateName, parsedState.state);
-                }
-                mesh.addShapeKeyGroup(shapeKeyGroup);
-            }
-        }
-        
         // Instances
         if (parsedMesh.instances) {
             for (var index = 0; index < parsedMesh.instances.length; index++) {
@@ -1057,6 +1045,15 @@
                 }
             }
 
+            // Connecting parents
+            for (index = 0; index < scene.meshes.length; index++) {
+                var currentMesh = scene.meshes[index];
+                if (currentMesh._waitingParentId) {
+                    currentMesh.parent = scene.getLastEntryByID(currentMesh._waitingParentId);
+                    currentMesh._waitingParentId = undefined;
+                }
+            }
+
             // Particles
             if (parsedData.particleSystems) {
                 for (index = 0; index < parsedData.particleSystems.length; index++) {
@@ -1210,6 +1207,23 @@
                 scene.setActiveCameraByID(parsedData.activeCameraID);
             }
 
+            // Connecting parents
+            for (index = 0; index < scene.cameras.length; index++) {
+                var camera = scene.cameras[index];
+                if (camera._waitingParentId) {
+                    camera.parent = scene.getLastEntryByID(camera._waitingParentId);
+                    camera._waitingParentId = undefined;
+                }
+            }
+
+            for (index = 0; index < scene.meshes.length; index++) {
+                var mesh = scene.meshes[index];
+                if (mesh._waitingParentId) {
+                    mesh.parent = scene.getLastEntryByID(mesh._waitingParentId);
+                    mesh._waitingParentId = undefined;
+                }
+            }
+
             // Particles Systems
             if (parsedData.particleSystems) {
                 for (index = 0; index < parsedData.particleSystems.length; index++) {

+ 1 - 1
Babylon/Mesh/babylon.abstractMesh.js

@@ -346,7 +346,7 @@ var BABYLON;
             this._localPivotScaling.multiplyToRef(this._localRotation, this._localPivotScalingRotation);
 
             // Billboarding
-            if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE) {
+            if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE && this.getScene().activeCamera) {
                 var localPosition = this.position.clone();
                 var zero = this.getScene().activeCamera.position.clone();
 

+ 1 - 1
Babylon/Mesh/babylon.abstractMesh.ts

@@ -340,7 +340,7 @@
             this._localPivotScaling.multiplyToRef(this._localRotation, this._localPivotScalingRotation);
 
             // Billboarding
-            if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE) {
+            if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE && this.getScene().activeCamera) {
                 var localPosition = this.position.clone();
                 var zero = this.getScene().activeCamera.position.clone();
 

+ 7 - 2
Babylon/PostProcess/babylon.postProcess.js

@@ -34,8 +34,13 @@
             camera = camera || this._camera;
 
             var scene = camera.getScene();
-            var desiredWidth = (sourceTexture ? sourceTexture._width : this._engine.getRenderingCanvas().width) * this._renderRatio;
-            var desiredHeight = (sourceTexture ? sourceTexture._height : this._engine.getRenderingCanvas().height) * this._renderRatio;
+            var maxSize = camera.getEngine().getCaps().maxTextureSize;
+            var desiredWidth = ((sourceTexture ? sourceTexture._width : this._engine.getRenderingCanvas().width) * this._renderRatio) | 0;
+            var desiredHeight = ((sourceTexture ? sourceTexture._height : this._engine.getRenderingCanvas().height) * this._renderRatio) | 0;
+
+            desiredWidth = BABYLON.Tools.GetExponantOfTwo(desiredWidth, maxSize);
+            desiredHeight = BABYLON.Tools.GetExponantOfTwo(desiredHeight, maxSize);
+
             if (this.width !== desiredWidth || this.height !== desiredHeight) {
                 if (this._textures.length > 0) {
                     for (var i = 0; i < this._textures.length; i++) {

+ 7 - 2
Babylon/PostProcess/babylon.postProcess.ts

@@ -48,8 +48,13 @@
             camera = camera || this._camera;
 
             var scene = camera.getScene();
-            var desiredWidth =  (sourceTexture ? sourceTexture._width : this._engine.getRenderingCanvas().width) * this._renderRatio;
-            var desiredHeight = (sourceTexture ? sourceTexture._height : this._engine.getRenderingCanvas().height) * this._renderRatio;
+            var maxSize = camera.getEngine().getCaps().maxTextureSize;
+            var desiredWidth = ((sourceTexture ? sourceTexture._width : this._engine.getRenderingCanvas().width) * this._renderRatio) | 0;
+            var desiredHeight = ((sourceTexture ? sourceTexture._height : this._engine.getRenderingCanvas().height) * this._renderRatio) | 0;
+
+            desiredWidth = Tools.GetExponantOfTwo(desiredWidth, maxSize);
+            desiredHeight = Tools.GetExponantOfTwo(desiredHeight, maxSize);
+
             if (this.width !== desiredWidth || this.height !== desiredHeight) {
                 if (this._textures.length > 0) {
                     for (var i = 0; i < this._textures.length; i++) {

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

@@ -641,6 +641,19 @@
         });
         Tools.BaseUrl = "";
 
+        Tools.GetExponantOfTwo = function (value, max) {
+            var count = 1;
+
+            do {
+                count *= 2;
+            } while(count < value);
+
+            if (count > max)
+                count = max;
+
+            return count;
+        };
+
         Tools._NoneLogLevel = 0;
         Tools._MessageLogLevel = 1;
         Tools._WarningLogLevel = 2;

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

@@ -36,6 +36,19 @@
     export class Tools {
         public static BaseUrl = "";
 
+        public static GetExponantOfTwo = (value: number, max: number): number => {
+            var count = 1;
+
+            do {
+                count *= 2;
+            } while (count < value);
+
+            if (count > max)
+                count = max;
+
+            return count;
+        };
+
         public static GetFilename(path: string): string {
             var index = path.lastIndexOf("/");
             if (index < 0)
@@ -265,7 +278,7 @@
             else {
                 // Caching all files
                 if (database && database.enableSceneOffline) {
-                    database.openAsync(loadFromIndexedDB, noIndexedDB);                    
+                    database.openAsync(loadFromIndexedDB, noIndexedDB);
                 }
                 else {
                     noIndexedDB();

+ 5 - 18
Babylon/babylon.engine.js

@@ -289,24 +289,11 @@
         };
     };
 
-    var getExponantOfTwo = function (value, max) {
-        var count = 1;
-
-        do {
-            count *= 2;
-        } while(count < value);
-
-        if (count > max)
-            count = max;
-
-        return count;
-    };
-
     var prepareWebGLTexture = function (texture, gl, scene, width, height, invertY, noMipmap, isCompressed, processFunction, samplingMode) {
         if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
         var engine = scene.getEngine();
-        var potWidth = getExponantOfTwo(width, engine.getCaps().maxTextureSize);
-        var potHeight = getExponantOfTwo(height, engine.getCaps().maxTextureSize);
+        var potWidth = BABYLON.Tools.GetExponantOfTwo(width, engine.getCaps().maxTextureSize);
+        var potHeight = BABYLON.Tools.GetExponantOfTwo(height, engine.getCaps().maxTextureSize);
 
         gl.bindTexture(gl.TEXTURE_2D, texture);
         gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
@@ -1266,8 +1253,8 @@
         Engine.prototype.createDynamicTexture = function (width, height, generateMipMaps, samplingMode) {
             var texture = this._gl.createTexture();
 
-            width = getExponantOfTwo(width, this._caps.maxTextureSize);
-            height = getExponantOfTwo(height, this._caps.maxTextureSize);
+            width = BABYLON.Tools.GetExponantOfTwo(width, this._caps.maxTextureSize);
+            height = BABYLON.Tools.GetExponantOfTwo(height, this._caps.maxTextureSize);
 
             this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
 
@@ -1443,7 +1430,7 @@
                 }, null, null, true);
             } else {
                 cascadeLoad(rootUrl, 0, [], scene, function (imgs) {
-                    var width = getExponantOfTwo(imgs[0].width, _this._caps.maxCubemapTextureSize);
+                    var width = BABYLON.Tools.GetExponantOfTwo(imgs[0].width, _this._caps.maxCubemapTextureSize);
                     var height = width;
 
                     _this._workingCanvas.width = width;

+ 5 - 18
Babylon/babylon.engine.ts

@@ -264,24 +264,11 @@
         }
     }
 
-    var getExponantOfTwo = (value: number, max: number): number => {
-        var count = 1;
-
-        do {
-            count *= 2;
-        } while (count < value);
-
-        if (count > max)
-            count = max;
-
-        return count;
-    };
-
     var prepareWebGLTexture = (texture: WebGLTexture, gl: WebGLRenderingContext, scene: Scene, width: number, height: number, invertY: boolean, noMipmap: boolean, isCompressed: boolean,
         processFunction: (width: number, height: number) => void, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE) => {
         var engine = scene.getEngine();
-        var potWidth = getExponantOfTwo(width, engine.getCaps().maxTextureSize);
-        var potHeight = getExponantOfTwo(height, engine.getCaps().maxTextureSize);
+        var potWidth = Tools.GetExponantOfTwo(width, engine.getCaps().maxTextureSize);
+        var potHeight = Tools.GetExponantOfTwo(height, engine.getCaps().maxTextureSize);
 
         gl.bindTexture(gl.TEXTURE_2D, texture);
         gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
@@ -1276,8 +1263,8 @@
         public createDynamicTexture(width: number, height: number, generateMipMaps: boolean, samplingMode: number): WebGLTexture {
             var texture = this._gl.createTexture();
 
-            width = getExponantOfTwo(width, this._caps.maxTextureSize);
-            height = getExponantOfTwo(height, this._caps.maxTextureSize);
+            width = Tools.GetExponantOfTwo(width, this._caps.maxTextureSize);
+            height = Tools.GetExponantOfTwo(height, this._caps.maxTextureSize);
 
             this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
 
@@ -1450,7 +1437,7 @@
                 }, null, null, true);
             } else {
                 cascadeLoad(rootUrl, 0, [], scene, imgs => {
-                    var width = getExponantOfTwo(imgs[0].width, this._caps.maxCubemapTextureSize);
+                    var width = Tools.GetExponantOfTwo(imgs[0].width, this._caps.maxCubemapTextureSize);
                     var height = width;
 
                     this._workingCanvas.width = width;

+ 2 - 0
Babylon/babylon.node.ts

@@ -14,6 +14,8 @@
         private _isReady = true;
         public _currentRenderId = -1;
 
+        public _waitingParentId: string;
+
         private _scene: Scene;
         public _cache;
 

+ 102 - 46
babylon.1.14-beta-debug.js

@@ -2797,6 +2797,19 @@ var BABYLON;
         });
         Tools.BaseUrl = "";
 
+        Tools.GetExponantOfTwo = function (value, max) {
+            var count = 1;
+
+            do {
+                count *= 2;
+            } while(count < value);
+
+            if (count > max)
+                count = max;
+
+            return count;
+        };
+
         Tools._NoneLogLevel = 0;
         Tools._MessageLogLevel = 1;
         Tools._WarningLogLevel = 2;
@@ -3102,24 +3115,11 @@ var BABYLON;
         };
     };
 
-    var getExponantOfTwo = function (value, max) {
-        var count = 1;
-
-        do {
-            count *= 2;
-        } while(count < value);
-
-        if (count > max)
-            count = max;
-
-        return count;
-    };
-
     var prepareWebGLTexture = function (texture, gl, scene, width, height, invertY, noMipmap, isCompressed, processFunction, samplingMode) {
         if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
         var engine = scene.getEngine();
-        var potWidth = getExponantOfTwo(width, engine.getCaps().maxTextureSize);
-        var potHeight = getExponantOfTwo(height, engine.getCaps().maxTextureSize);
+        var potWidth = BABYLON.Tools.GetExponantOfTwo(width, engine.getCaps().maxTextureSize);
+        var potHeight = BABYLON.Tools.GetExponantOfTwo(height, engine.getCaps().maxTextureSize);
 
         gl.bindTexture(gl.TEXTURE_2D, texture);
         gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
@@ -4079,8 +4079,8 @@ var BABYLON;
         Engine.prototype.createDynamicTexture = function (width, height, generateMipMaps, samplingMode) {
             var texture = this._gl.createTexture();
 
-            width = getExponantOfTwo(width, this._caps.maxTextureSize);
-            height = getExponantOfTwo(height, this._caps.maxTextureSize);
+            width = BABYLON.Tools.GetExponantOfTwo(width, this._caps.maxTextureSize);
+            height = BABYLON.Tools.GetExponantOfTwo(height, this._caps.maxTextureSize);
 
             this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
 
@@ -4256,7 +4256,7 @@ var BABYLON;
                 }, null, null, true);
             } else {
                 cascadeLoad(rootUrl, 0, [], scene, function (imgs) {
-                    var width = getExponantOfTwo(imgs[0].width, _this._caps.maxCubemapTextureSize);
+                    var width = BABYLON.Tools.GetExponantOfTwo(imgs[0].width, _this._caps.maxCubemapTextureSize);
                     var height = width;
 
                     _this._workingCanvas.width = width;
@@ -9514,7 +9514,7 @@ var BABYLON;
             this._localPivotScaling.multiplyToRef(this._localRotation, this._localPivotScalingRotation);
 
            
-            if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE) {
+            if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE && this.getScene().activeCamera) {
                 var localPosition = this.position.clone();
                 var zero = this.getScene().activeCamera.position.clone();
 
@@ -15733,8 +15733,13 @@ var BABYLON;
             camera = camera || this._camera;
 
             var scene = camera.getScene();
-            var desiredWidth = (sourceTexture ? sourceTexture._width : this._engine.getRenderingCanvas().width) * this._renderRatio;
-            var desiredHeight = (sourceTexture ? sourceTexture._height : this._engine.getRenderingCanvas().height) * this._renderRatio;
+            var maxSize = camera.getEngine().getCaps().maxTextureSize;
+            var desiredWidth = ((sourceTexture ? sourceTexture._width : this._engine.getRenderingCanvas().width) * this._renderRatio) | 0;
+            var desiredHeight = ((sourceTexture ? sourceTexture._height : this._engine.getRenderingCanvas().height) * this._renderRatio) | 0;
+
+            desiredWidth = BABYLON.Tools.GetExponantOfTwo(desiredWidth, maxSize);
+            desiredHeight = BABYLON.Tools.GetExponantOfTwo(desiredHeight, maxSize);
+
             if (this.width !== desiredWidth || this.height !== desiredHeight) {
                 if (this._textures.length > 0) {
                     for (var i = 0; i < this._textures.length; i++) {
@@ -18260,7 +18265,54 @@ var BABYLON;
         };
 
         var parseCamera = function (parsedCamera, scene) {
-            var camera = new BABYLON.FreeCamera(parsedCamera.name, BABYLON.Vector3.FromArray(parsedCamera.position), scene);
+            var camera;
+            var position = BABYLON.Vector3.FromArray(parsedCamera.position);
+            var lockedTargetMesh = (parsedCamera.lockedTargetId) ? scene.getLastMeshByID(parsedCamera.lockedTargetId) : null;
+
+            if (parsedCamera.type === "AnaglyphArcRotateCamera" || parsedCamera.type === "ArcRotateCamera") {
+                var alpha = parsedCamera.alpha;
+                var beta = parsedCamera.beta;
+                var radius = parsedCamera.radius;
+                if (parsedCamera.type === "AnaglyphArcRotateCamera") {
+                    var eye_space = parsedCamera.eye_space;
+                    camera = new BABYLON.AnaglyphArcRotateCamera(parsedCamera.name, alpha, beta, radius, lockedTargetMesh, eye_space, scene);
+                } else {
+                    camera = new BABYLON.ArcRotateCamera(parsedCamera.name, alpha, beta, radius, lockedTargetMesh, scene);
+                }
+            } else if (parsedCamera.type === "AnaglyphFreeCamera") {
+                var eye_space = parsedCamera.eye_space;
+                camera = new BABYLON.AnaglyphFreeCamera(parsedCamera.name, position, eye_space, scene);
+            } else if (parsedCamera.type === "DeviceOrientationCamera") {
+                camera = new BABYLON.DeviceOrientationCamera(parsedCamera.name, position, scene);
+            } else if (parsedCamera.type === "FollowCamera") {
+                camera = new BABYLON.FollowCamera(parsedCamera.name, position, scene);
+                camera.heightOffset = parsedCamera.heightOffset;
+                camera.radius = parsedCamera.radius;
+                camera.rotationOffset = parsedCamera.rotationOffset;
+                if (lockedTargetMesh)
+                    camera.target = lockedTargetMesh;
+            } else if (parsedCamera.type === "GamepadCamera") {
+                camera = new BABYLON.GamepadCamera(parsedCamera.name, position, scene);
+            } else if (parsedCamera.type === "OculusCamera") {
+                camera = new BABYLON.OculusCamera(parsedCamera.name, position, scene);
+            } else if (parsedCamera.type === "TouchCamera") {
+                camera = new BABYLON.TouchCamera(parsedCamera.name, position, scene);
+            } else if (parsedCamera.type === "VirtualJoysticksCamera") {
+                camera = new BABYLON.VirtualJoysticksCamera(parsedCamera.name, position, scene);
+            } else if (parsedCamera.type === "WebVRCamera") {
+                camera = new BABYLON.WebVRCamera(parsedCamera.name, position, scene);
+            } else if (parsedCamera.type === "VRDeviceOrientationCamera") {
+                camera = new BABYLON.VRDeviceOrientationCamera(parsedCamera.name, position, scene);
+            } else {
+               
+                camera = new BABYLON.FreeCamera(parsedCamera.name, position, scene);
+            }
+
+           
+            if (lockedTargetMesh && camera instanceof BABYLON.FreeCamera) {
+                camera.lockedTarget = lockedTargetMesh;
+            }
+
             camera.id = parsedCamera.id;
 
             BABYLON.Tags.AddTagsTo(camera, parsedCamera.tags);
@@ -18277,11 +18329,6 @@ var BABYLON;
                 camera.rotation = BABYLON.Vector3.FromArray(parsedCamera.rotation);
             }
 
-           
-            if (parsedCamera.lockedTargetId) {
-                camera._waitingLockedTargetId = parsedCamera.lockedTargetId;
-            }
-
             camera.fov = parsedCamera.fov;
             camera.minZ = parsedCamera.minZ;
             camera.maxZ = parsedCamera.maxZ;
@@ -18505,7 +18552,7 @@ var BABYLON;
 
            
             if (parsedMesh.parentId) {
-                mesh.parent = scene.getLastEntryByID(parsedMesh.parentId);
+                mesh._waitingParentId = parsedMesh.parentId;
             }
 
            
@@ -18896,6 +18943,14 @@ var BABYLON;
                     }
                 }
 
+                for (index = 0; index < scene.meshes.length; index++) {
+                    var currentMesh = scene.meshes[index];
+                    if (currentMesh._waitingParentId) {
+                        currentMesh.parent = scene.getLastEntryByID(currentMesh._waitingParentId);
+                        currentMesh._waitingParentId = undefined;
+                    }
+                }
+
                
                 if (parsedData.particleSystems) {
                     for (index = 0; index < parsedData.particleSystems.length; index++) {
@@ -18933,15 +18988,6 @@ var BABYLON;
                     parseLight(parsedLight, scene);
                 }
 
-                for (index = 0; index < parsedData.cameras.length; index++) {
-                    var parsedCamera = parsedData.cameras[index];
-                    parseCamera(parsedCamera, scene);
-                }
-
-                if (parsedData.activeCameraID) {
-                    scene.setActiveCameraByID(parsedData.activeCameraID);
-                }
-
                
                 if (parsedData.materials) {
                     for (index = 0; index < parsedData.materials.length; index++) {
@@ -19046,19 +19092,28 @@ var BABYLON;
                     parseMesh(parsedMesh, scene, rootUrl);
                 }
 
+                for (index = 0; index < parsedData.cameras.length; index++) {
+                    var parsedCamera = parsedData.cameras[index];
+                    parseCamera(parsedCamera, scene);
+                }
+
+                if (parsedData.activeCameraID) {
+                    scene.setActiveCameraByID(parsedData.activeCameraID);
+                }
+
                 for (index = 0; index < scene.cameras.length; index++) {
                     var camera = scene.cameras[index];
                     if (camera._waitingParentId) {
                         camera.parent = scene.getLastEntryByID(camera._waitingParentId);
-                        delete camera._waitingParentId;
+                        camera._waitingParentId = undefined;
                     }
+                }
 
-                    if (camera instanceof BABYLON.FreeCamera) {
-                        var freecamera = camera;
-                        if (freecamera._waitingLockedTargetId) {
-                            freecamera.lockedTarget = scene.getLastEntryByID(freecamera._waitingLockedTargetId);
-                            delete freecamera._waitingLockedTargetId;
-                        }
+                for (index = 0; index < scene.meshes.length; index++) {
+                    var mesh = scene.meshes[index];
+                    if (mesh._waitingParentId) {
+                        mesh.parent = scene.getLastEntryByID(mesh._waitingParentId);
+                        mesh._waitingParentId = undefined;
                     }
                 }
 
@@ -23408,6 +23463,7 @@ var BABYLON;
                 if (!this._nextActiveAction._child._actionManager) {
                     this._nextActiveAction._child._actionManager = this._actionManager;
                 }
+
                 this._nextActiveAction = this._nextActiveAction._child;
             } else {
                 this._nextActiveAction = this;
@@ -25751,7 +25807,7 @@ var BABYLON;
             this._sensorDevice = null;
             this._hmdDevice = null;
 
-            while (i > 0 && this._hmdDevice === null) {
+            while (i < size && this._hmdDevice === null) {
                 if (devices[i] instanceof HMDVRDevice) {
                     this._hmdDevice = devices[i];
                 }
@@ -25760,7 +25816,7 @@ var BABYLON;
 
             i = 0;
 
-            while (i > 0 && this._sensorDevice === null) {
+            while (i < size && this._sensorDevice === null) {
                 if (devices[i] instanceof PositionSensorVRDevice && (!this._hmdDevice || devices[i].hardwareUnitId === this._hmdDevice.hardwareUnitId)) {
                     this._sensorDevice = devices[i];
                 }

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 17 - 0
babylon.1.14-RC.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 17
babylon.1.14-beta.js


+ 2 - 1
babylon.d.ts

@@ -284,6 +284,7 @@ declare module BABYLON {
         private _isEnabled;
         private _isReady;
         public _currentRenderId: number;
+        public _waitingParentId: string;
         private _scene;
         public _cache: any;
         constructor(name: string, scene: any);
@@ -913,7 +914,6 @@ declare module BABYLON {
         private _worldMatrix;
         public _postProcesses: PostProcess[];
         public _postProcessesTakenIndices: any[];
-        public _waitingParentId: string;
         constructor(name: string, position: Vector3, scene: Scene);
         public _initCache(): void;
         public _updateCache(ignoreParentClass?: boolean): void;
@@ -3473,6 +3473,7 @@ declare module BABYLON {
     }
     class Tools {
         static BaseUrl: string;
+        static GetExponantOfTwo: (value: number, max: number) => number;
         static GetFilename(path: string): string;
         static GetDOMTextContent(element: HTMLElement): string;
         static ToDegrees(angle: number): number;