Browse Source

Merge pull request #6057 from BabylonJS/master

Nightly
David Catuhe 6 years ago
parent
commit
8e2328c21a

+ 2 - 2
Playground/babylon.d.txt

@@ -24460,8 +24460,8 @@ declare module BABYLON {
         private _isParentEnabled;
         private _isReady;
         /** @hidden */
currentRenderId: number;
-        private _parentRenderId;
-        protected _childRenderId: number;
+        private _parentUpdateId;
+        protected _childUpdateId: number;
         /** @hidden */
waitingParentId: Nullable<string>;
         /** @hidden */
scene: Scene;
         /** @hidden */
cache: any;

+ 2 - 2
dist/preview release/babylon.d.ts

@@ -24867,8 +24867,8 @@ declare module BABYLON {
         private _isReady;
         /** @hidden */
         _currentRenderId: number;
-        private _parentRenderId;
-        protected _childRenderId: number;
+        private _parentUpdateId;
+        protected _childUpdateId: number;
         /** @hidden */
         _waitingParentId: Nullable<string>;
         /** @hidden */

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/babylon.js


File diff suppressed because it is too large
+ 65 - 52
dist/preview release/babylon.max.js


File diff suppressed because it is too large
+ 1 - 1
dist/preview release/babylon.max.js.map


+ 4 - 4
dist/preview release/babylon.module.d.ts

@@ -25513,8 +25513,8 @@ declare module "babylonjs/node" {
         private _isReady;
         /** @hidden */
         _currentRenderId: number;
-        private _parentRenderId;
-        protected _childRenderId: number;
+        private _parentUpdateId;
+        protected _childUpdateId: number;
         /** @hidden */
         _waitingParentId: Nullable<string>;
         /** @hidden */
@@ -83818,8 +83818,8 @@ declare module BABYLON {
         private _isReady;
         /** @hidden */
         _currentRenderId: number;
-        private _parentRenderId;
-        protected _childRenderId: number;
+        private _parentUpdateId;
+        protected _childUpdateId: number;
         /** @hidden */
         _waitingParentId: Nullable<string>;
         /** @hidden */

+ 1 - 1
dist/preview release/packagesSizeBaseLine.json

@@ -1 +1 @@
-{"engineOnly":309116,"sceneOnly":551531,"minGridMaterial":674533,"minStandardMaterial":773388}
+{"engineOnly":309267,"sceneOnly":551634,"minGridMaterial":674636,"minStandardMaterial":773491}

+ 4 - 4
dist/preview release/viewer/babylon.module.d.ts

@@ -25513,8 +25513,8 @@ declare module "babylonjs/node" {
         private _isReady;
         /** @hidden */
         _currentRenderId: number;
-        private _parentRenderId;
-        protected _childRenderId: number;
+        private _parentUpdateId;
+        protected _childUpdateId: number;
         /** @hidden */
         _waitingParentId: Nullable<string>;
         /** @hidden */
@@ -83818,8 +83818,8 @@ declare module BABYLON {
         private _isReady;
         /** @hidden */
         _currentRenderId: number;
-        private _parentRenderId;
-        protected _childRenderId: number;
+        private _parentUpdateId;
+        protected _childUpdateId: number;
         /** @hidden */
         _waitingParentId: Nullable<string>;
         /** @hidden */

+ 4 - 4
dist/preview release/viewer/babylon.viewer.d.ts

@@ -197,11 +197,11 @@ declare module BabylonViewer {
                 * Mainly used for help and errors
                 * @param subScreen the name of the subScreen. Those can be defined in the configuration object
                 */
-            showOverlayScreen(subScreen: string): Promise<Template> | Promise<string>;
+            showOverlayScreen(subScreen: string): Promise<string> | Promise<Template>;
             /**
                 * Hide the overlay screen.
                 */
-            hideOverlayScreen(): Promise<Template> | Promise<string>;
+            hideOverlayScreen(): Promise<string> | Promise<Template>;
             /**
                 * show the viewer (in case it was hidden)
                 *
@@ -218,11 +218,11 @@ declare module BabylonViewer {
                 * Show the loading screen.
                 * The loading screen can be configured using the configuration object
                 */
-            showLoadingScreen(): Promise<Template> | Promise<string>;
+            showLoadingScreen(): Promise<string> | Promise<Template>;
             /**
                 * Hide the loading screen
                 */
-            hideLoadingScreen(): Promise<Template> | Promise<string>;
+            hideLoadingScreen(): Promise<string> | Promise<Template>;
             dispose(): void;
             protected _onConfigurationLoaded(configuration: ViewerConfiguration): void;
     }

File diff suppressed because it is too large
+ 11 - 11
dist/preview release/viewer/babylon.viewer.js


File diff suppressed because it is too large
+ 1 - 1
dist/preview release/viewer/babylon.viewer.max.js


+ 4 - 4
dist/preview release/viewer/babylon.viewer.module.d.ts

@@ -230,11 +230,11 @@ declare module 'babylonjs-viewer/viewer/defaultViewer' {
                 * Mainly used for help and errors
                 * @param subScreen the name of the subScreen. Those can be defined in the configuration object
                 */
-            showOverlayScreen(subScreen: string): Promise<Template> | Promise<string>;
+            showOverlayScreen(subScreen: string): Promise<string> | Promise<Template>;
             /**
                 * Hide the overlay screen.
                 */
-            hideOverlayScreen(): Promise<Template> | Promise<string>;
+            hideOverlayScreen(): Promise<string> | Promise<Template>;
             /**
                 * show the viewer (in case it was hidden)
                 *
@@ -251,11 +251,11 @@ declare module 'babylonjs-viewer/viewer/defaultViewer' {
                 * Show the loading screen.
                 * The loading screen can be configured using the configuration object
                 */
-            showLoadingScreen(): Promise<Template> | Promise<string>;
+            showLoadingScreen(): Promise<string> | Promise<Template>;
             /**
                 * Hide the loading screen
                 */
-            hideLoadingScreen(): Promise<Template> | Promise<string>;
+            hideLoadingScreen(): Promise<string> | Promise<Template>;
             dispose(): void;
             protected _onConfigurationLoaded(configuration: ViewerConfiguration): void;
     }

+ 2 - 0
dist/preview release/what's new.md

@@ -207,6 +207,7 @@
 - Add missing dependencies for files to support including them from a direct path (eg. import "@babylonjs/core/Helpers/sceneHelpers";) ([TrevorDev](https://github.com/TrevorDev))
 - AssetContainer should not dispose objects it doesn't contain, Support for environmentTexture ([TrevorDev](https://github.com/TrevorDev))
 - Fix `mesh.visibility` not working properly when certain material properties are set that changes the interpretation of alpha (e.g. refraction, specular over alpha, etc.) ([bghgary](https://github.com/bghgary))
+- Fix material and texture leak when loading/removing GLTF with AssetContainer ([TrevorDev](https://github.com/TrevorDev))
 
 ### Core Engine
 - Fixed a bug with `mesh.alwaysSelectAsActiveMesh` preventing layerMask to be taken in account ([Deltakosh](https://github.com/deltakosh))
@@ -231,6 +232,7 @@
 - PointerDragBehavior validateDrag predicate to stop dragging to specific points ([TrevorDev](https://github.com/TrevorDev))
 - Auto Update Touch Action [#5674](https://github.com/BabylonJS/Babylon.js/issues/5674)([Sebavan](https://github.com/Sebavan))
 - Add hemispheric lighting to gizmos to avoid flat look ([TrevorDev](https://github.com/TrevorDev))
+- Fix a bug causing `WebRequest.open` to crash if `WebRequest.CustomRequestHeaders` are set [#6055](https://github.com/BabylonJS/Babylon.js/issues/6055)([susares](https://github.com/susares))
 
 ### Viewer
 

+ 13 - 0
loaders/src/glTF/glTFFileLoader.ts

@@ -503,12 +503,25 @@ export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISc
         return this._parseAsync(scene, data, rootUrl, fileName).then((loaderData) => {
             this._log(`Loading ${fileName || ""}`);
             this._loader = this._getLoader(loaderData);
+
+            // Get materials/textures when loading to add to container
+            let materials: Array<Material> = [];
+            this.onMaterialLoadedObservable.add((material) => {
+                materials.push(material);
+            });
+            let textures: Array<BaseTexture> = [];
+            this.onTextureLoadedObservable.add((texture) => {
+                textures.push(texture);
+            });
+
             return this._loader.importMeshAsync(null, scene, loaderData, rootUrl, onProgress, fileName).then((result) => {
                 const container = new AssetContainer(scene);
                 Array.prototype.push.apply(container.meshes, result.meshes);
                 Array.prototype.push.apply(container.particleSystems, result.particleSystems);
                 Array.prototype.push.apply(container.skeletons, result.skeletons);
                 Array.prototype.push.apply(container.animationGroups, result.animationGroups);
+                Array.prototype.push.apply(container.materials, materials);
+                Array.prototype.push.apply(container.textures, textures);
                 container.removeAllFromScene();
                 return container;
             });

+ 1 - 1
src/Bones/bone.ts

@@ -365,7 +365,7 @@ export class Bone extends Node {
      */
     public markAsDirty(): void {
         this._currentRenderId++;
-        this._childRenderId++;
+        this._childUpdateId++;
         this._skeleton._markAsDirty();
     }
 

+ 20 - 4
src/Cameras/Inputs/freeCameraMouseInput.ts

@@ -1,4 +1,4 @@
-import { Observer, EventState } from "../../Misc/observable";
+import { Observer, EventState, Observable } from "../../Misc/observable";
 import { serialize } from "../../Misc/decorators";
 import { Nullable } from "../../types";
 import { ICameraInput, CameraInputTypes } from "../../Cameras/cameraInputsManager";
@@ -32,6 +32,15 @@ export class FreeCameraMouseInput implements ICameraInput<FreeCamera> {
     private previousPosition: Nullable<{ x: number, y: number }> = null;
 
     /**
+     * Observable for when a pointer move event occurs containing the move offset
+     */
+    public onPointerMovedObservable = new Observable<{ offsetX: number, offsetY: number }>();
+    /**
+     * @hidden
+     * If the camera should be rotated automatically based on pointer movement
+     */
+    public _allowCameraRotation = true;
+    /**
      * Manage the mouse inputs to control the movement of a free camera.
      * @see http://doc.babylonjs.com/how_to/customizing_camera_inputs
      * @param touchEnabled Defines if touch is enabled or not
@@ -105,12 +114,15 @@ export class FreeCameraMouseInput implements ICameraInput<FreeCamera> {
                     }
 
                     var offsetX = evt.clientX - this.previousPosition.x;
+                    var offsetY = evt.clientY - this.previousPosition.y;
                     if (this.camera.getScene().useRightHandedSystem) { offsetX *= -1; }
                     if (this.camera.parent && this.camera.parent._getWorldMatrixDeterminant() < 0) { offsetX *= -1; }
-                    this.camera.cameraRotation.y += offsetX / this.angularSensibility;
 
-                    var offsetY = evt.clientY - this.previousPosition.y;
-                    this.camera.cameraRotation.x += offsetY / this.angularSensibility;
+                    if (this._allowCameraRotation) {
+                        this.camera.cameraRotation.y += offsetX / this.angularSensibility;
+                        this.camera.cameraRotation.x += offsetY / this.angularSensibility;
+                    }
+                    this.onPointerMovedObservable.notifyObservers({offsetX: offsetX, offsetY: offsetY});
 
                     this.previousPosition = {
                         x: evt.clientX,
@@ -179,6 +191,10 @@ export class FreeCameraMouseInput implements ICameraInput<FreeCamera> {
                 element.removeEventListener("contextmenu", <EventListener>this.onContextMenu);
             }
 
+            if (this.onPointerMovedObservable) {
+                this.onPointerMovedObservable.clear();
+            }
+
             this._observer = null;
             this._onMouseMove = null;
             this.previousPosition = null;

+ 4 - 4
src/Cameras/camera.ts

@@ -258,10 +258,10 @@ export class Camera extends Node {
      */
     public _resizeOrCreateMultiviewTexture(width: number, height: number) {
         if (!this._multiviewTexture) {
-            this._multiviewTexture = new MultiviewRenderTarget(this.getScene(), {width: width, height: height});
-        }else if (this._multiviewTexture.getRenderWidth() != width || this._multiviewTexture.getRenderHeight() != height) {
+            this._multiviewTexture = new MultiviewRenderTarget(this.getScene(), { width: width, height: height });
+        } else if (this._multiviewTexture.getRenderWidth() != width || this._multiviewTexture.getRenderHeight() != height) {
             this._multiviewTexture.dispose();
-            this._multiviewTexture = new MultiviewRenderTarget(this.getScene(), {width: width, height: height});
+            this._multiviewTexture = new MultiviewRenderTarget(this.getScene(), { width: width, height: height });
         }
     }
 
@@ -670,7 +670,7 @@ export class Camera extends Node {
         this.updateCache();
         this._computedViewMatrix = this._getViewMatrix();
         this._currentRenderId = this.getScene().getRenderId();
-        this._childRenderId = this._currentRenderId;
+        this._childUpdateId++;
 
         this._refreshFrustumPlanes = true;
 

+ 23 - 1
src/Cameras/deviceOrientationCamera.ts

@@ -18,6 +18,7 @@ export class DeviceOrientationCamera extends FreeCamera {
 
     private _initialQuaternion: Quaternion;
     private _quaternionCache: Quaternion;
+    private _tmpDragQuaternion = new Quaternion();
 
     /**
      * Creates a new device orientation camera
@@ -33,11 +34,32 @@ export class DeviceOrientationCamera extends FreeCamera {
         // When the orientation sensor fires it's first event, disable mouse input
         if (this.inputs._deviceOrientationInput) {
             this.inputs._deviceOrientationInput._onDeviceOrientationChangedObservable.addOnce(() => {
-                this.inputs.removeMouse();
+                if (this.inputs._mouseInput) {
+                    this.inputs._mouseInput._allowCameraRotation = false;
+                    this.inputs._mouseInput.onPointerMovedObservable.add((e) => {
+                        if (this._dragFactor != 0) {
+                            if (!this._initialQuaternion) {
+                                this._initialQuaternion = new Quaternion();
+                            }
+                            // Rotate the initial space around the y axis to allow users to "turn around" via touch/mouse
+                            Quaternion.FromEulerAnglesToRef(0, e.offsetX * this._dragFactor, 0, this._tmpDragQuaternion);
+                            this._initialQuaternion.multiplyToRef(this._tmpDragQuaternion, this._initialQuaternion);
+                        }
+                    });
+                }
             });
         }
     }
 
+    private _dragFactor = 0;
+    /**
+     * Enabled turning on the y axis when the orientation sensor is active
+     * @param dragFactor the factor that controls the turn speed (default: 1/300)
+     */
+    public enableHorizontalDragging(dragFactor= 1 / 300) {
+        this._dragFactor = dragFactor;
+    }
+
     /**
      * Gets the current instance class name ("DeviceOrientationCamera").
      * This helps avoiding instanceof at run time.

+ 24 - 10
src/Engines/engine.ts

@@ -3411,13 +3411,6 @@ export class Engine {
         gl.shaderSource(shader, source);
         gl.compileShader(shader);
 
-        if (!this._caps.parallelShaderCompile && !gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
-            let log = gl.getShaderInfoLog(shader);
-            if (log) {
-                throw new Error(log);
-            }
-        }
-
         return shader;
     }
 
@@ -3509,7 +3502,24 @@ export class Engine {
 
         var linked = context.getProgramParameter(shaderProgram, context.LINK_STATUS);
 
-        if (!linked) {
+        if (!linked) { // Get more info
+
+            // Vertex
+            if (!this._gl.getShaderParameter(vertexShader, this._gl.COMPILE_STATUS)) {
+                let log = this._gl.getShaderInfoLog(vertexShader);
+                if (log) {
+                    throw new Error(log);
+                }
+            }
+
+            // Fragment
+            if (!this._gl.getShaderParameter(fragmentShader, this._gl.COMPILE_STATUS)) {
+                let log = this._gl.getShaderInfoLog(fragmentShader);
+                if (log) {
+                    throw new Error(log);
+                }
+            }
+
             var error = context.getProgramInfoLog(shaderProgram);
             if (error) {
                 throw new Error(error);
@@ -5801,8 +5811,12 @@ export class Engine {
                 if (loader.supportCascades) {
                     this._cascadeLoadFiles(scene, onloaddata, files, onError);
                 }
-                else if (onError) {
-                    onError("Textures type does not support cascades.");
+                else {
+                    if (onError) {
+                        onError("Textures type does not support cascades.");
+                    } else {
+                        Logger.Warn("Texture loader does not support cascades.");
+                    }
                 }
             }
             else {

+ 1 - 1
src/Meshes/transformNode.ts

@@ -872,7 +872,7 @@ export class TransformNode extends Node {
         this._cache.billboardMode = this.billboardMode;
         this._cache.infiniteDistance = this.infiniteDistance;
         this._currentRenderId = this.getScene().getRenderId();
-        this._childRenderId = this.getScene().getRenderId();
+        this._childUpdateId++;
         this._isDirty = false;
 
         // Scaling

+ 4 - 4
src/Misc/webRequest.ts

@@ -112,6 +112,10 @@ export class WebRequest {
      * @param body defines an optional request body
      */
     public send(body?: Document | BodyInit | null): void {
+        if (WebRequest.CustomRequestHeaders) {
+            this._injectCustomRequestHeaders();
+        }
+
         this._xhr.send(body);
     }
 
@@ -121,10 +125,6 @@ export class WebRequest {
      * @param url defines the url to connect with
      */
     public open(method: string, url: string): void {
-        if (WebRequest.CustomRequestHeaders) {
-            this._injectCustomRequestHeaders();
-        }
-
         for (var update of WebRequest.CustomRequestModifiers) {
             update(this._xhr);
         }

+ 4 - 4
src/node.ts

@@ -124,8 +124,8 @@ export class Node implements IBehaviorAware<Node> {
     private _isReady = true;
     /** @hidden */
     public _currentRenderId = -1;
-    private _parentRenderId = -1;
-    protected _childRenderId = -1;
+    private _parentUpdateId = -1;
+    protected _childUpdateId = -1;
 
     /** @hidden */
     public _waitingParentId: Nullable<string>;
@@ -435,7 +435,7 @@ export class Node implements IBehaviorAware<Node> {
     /** @hidden */
     public _markSyncedWithParent() {
         if (this._parentNode) {
-            this._parentRenderId = this._parentNode._childRenderId;
+            this._parentUpdateId = this._parentNode._childUpdateId;
         }
     }
 
@@ -445,7 +445,7 @@ export class Node implements IBehaviorAware<Node> {
             return true;
         }
 
-        if (this._parentRenderId !== this._parentNode._childRenderId) {
+        if (this._parentUpdateId !== this._parentNode._childUpdateId) {
             return false;
         }