瀏覽代碼

Initial Promise drop

David Catuhe 7 年之前
父節點
當前提交
fcdbaf933a

文件差異過大導致無法顯示
+ 2793 - 2519
Playground/babylon.d.txt


+ 1 - 0
Tools/Gulp/config.json

@@ -177,6 +177,7 @@
                 "../../src/Tools/babylon.observable.js",
                 "../../src/Tools/babylon.smartArray.js",
                 "../../src/Tools/babylon.tools.js",
+                "../../src/Tools/babylon.promise.js",
                 "../../src/States/babylon.alphaCullingState.js",
                 "../../src/States/babylon.depthCullingState.js",
                 "../../src/States/babylon.stencilState.js",

文件差異過大導致無法顯示
+ 9156 - 8877
dist/preview release/babylon.d.ts


文件差異過大導致無法顯示
+ 44 - 44
dist/preview release/babylon.js


+ 350 - 43
dist/preview release/babylon.max.js

@@ -8274,6 +8274,136 @@ var BABYLON;
 
 var BABYLON;
 (function (BABYLON) {
+    var PromiseStates;
+    (function (PromiseStates) {
+        PromiseStates[PromiseStates["Pending"] = 0] = "Pending";
+        PromiseStates[PromiseStates["Fulfilled"] = 1] = "Fulfilled";
+        PromiseStates[PromiseStates["Rejected"] = 2] = "Rejected";
+    })(PromiseStates || (PromiseStates = {}));
+    var InternalPromise = /** @class */ (function () {
+        function InternalPromise(resolver) {
+            var _this = this;
+            this._state = PromiseStates.Pending;
+            if (!resolver) {
+                return;
+            }
+            try {
+                resolver(function (value) {
+                    _this._resolve(value);
+                }, function (reason) {
+                    _this._reject(reason);
+                });
+            }
+            catch (e) {
+                this._reject(e.message);
+            }
+        }
+        Object.defineProperty(InternalPromise.prototype, "state", {
+            get: function () {
+                return this._state;
+            },
+            enumerable: true,
+            configurable: true
+        });
+        InternalPromise.prototype.isFulfilled = function () {
+            return this._state === PromiseStates.Fulfilled;
+        };
+        InternalPromise.prototype.isRejected = function () {
+            return this._state === PromiseStates.Rejected;
+        };
+        InternalPromise.prototype.isPending = function () {
+            return this._state === PromiseStates.Pending;
+        };
+        InternalPromise.prototype.value = function () {
+            if (!this.isFulfilled()) {
+                throw new Error("Promise is not fulfilled");
+            }
+            return this._result;
+        };
+        InternalPromise.prototype.reason = function () {
+            if (!this.isRejected()) {
+                throw new Error("Promise is not rejected");
+            }
+            return this._reason;
+        };
+        InternalPromise.prototype.catch = function (onRejected) {
+            return this.then(undefined, onRejected);
+        };
+        InternalPromise.prototype.then = function (onFulfilled, onRejected) {
+            var newPromise = new InternalPromise();
+            newPromise._onFulfilled = onFulfilled;
+            newPromise._onRejected = onRejected;
+            // Composition
+            this._child = newPromise;
+            switch (this._state) {
+                case PromiseStates.Fulfilled:
+                    var returnedPromise = newPromise._resolve(this._result);
+                    if (returnedPromise) {
+                        newPromise._child = returnedPromise;
+                        newPromise = returnedPromise;
+                    }
+                    break;
+                case PromiseStates.Rejected:
+                    newPromise._reject(this._reason);
+                    newPromise._state = PromiseStates.Fulfilled;
+                    break;
+            }
+            return newPromise;
+        };
+        InternalPromise.prototype._resolve = function (value) {
+            try {
+                this._state = PromiseStates.Fulfilled;
+                this._result = value;
+                var returnedPromise = null;
+                if (this._onFulfilled) {
+                    returnedPromise = this._onFulfilled(value);
+                }
+                if (this._child) {
+                    this._child._resolve(value);
+                }
+                return returnedPromise;
+            }
+            catch (e) {
+                this._reject(e.message);
+            }
+            return null;
+        };
+        InternalPromise.prototype._reject = function (reason) {
+            this._state = PromiseStates.Rejected;
+            this._reason = reason;
+            if (this._onRejected) {
+                this._onRejected(reason);
+            }
+            if (this._child) {
+                this._child._resolve(null);
+            }
+        };
+        InternalPromise.resolve = function (value) {
+            var newPromise = new InternalPromise();
+            newPromise._resolve(value);
+            return newPromise;
+        };
+        return InternalPromise;
+    }());
+    var PromisePolyfill = /** @class */ (function () {
+        function PromisePolyfill() {
+        }
+        PromisePolyfill.Apply = function (force) {
+            if (force === void 0) { force = false; }
+            if (force || typeof Promise === 'undefined') {
+                var root = window;
+                root.Promise = InternalPromise;
+            }
+        };
+        return PromisePolyfill;
+    }());
+    BABYLON.PromisePolyfill = PromisePolyfill;
+})(BABYLON || (BABYLON = {}));
+
+//# sourceMappingURL=babylon.promise.js.map
+
+var BABYLON;
+(function (BABYLON) {
     var _AlphaState = /** @class */ (function () {
         /**
          * Initializes the state.
@@ -9106,6 +9236,8 @@ var BABYLON;
                 }
             };
             this._boundUniforms = {};
+            // Register promises
+            BABYLON.PromisePolyfill.Apply();
             var canvas = null;
             Engine.Instances.push(this);
             if (!canvasOrContext) {
@@ -74923,13 +75055,31 @@ var BABYLON;
 
 var BABYLON;
 (function (BABYLON) {
+    /**
+     * This represents a WebVR camera.
+     * The WebVR camera is Babylon's simple interface to interaction with Windows Mixed Reality, HTC Vive and Oculus Rift.
+     * @example http://doc.babylonjs.com/how_to/webvr_camera
+     */
     var WebVRFreeCamera = /** @class */ (function (_super) {
         __extends(WebVRFreeCamera, _super);
+        /**
+         * Instantiates a WebVRFreeCamera.
+         * @param name The name of the WebVRFreeCamera
+         * @param position The starting anchor position for the camera
+         * @param scene The scene the camera belongs to
+         * @param webVROptions a set of customizable options for the webVRCamera
+         */
         function WebVRFreeCamera(name, position, scene, webVROptions) {
             if (webVROptions === void 0) { webVROptions = {}; }
             var _this = _super.call(this, name, position, scene) || this;
             _this.webVROptions = webVROptions;
+            /**
+             * The vrDisplay tied to the camera. See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay
+             */
             _this._vrDevice = null;
+            /**
+             * The rawPose of the vrDevice.
+             */
             _this.rawPose = null;
             _this._specsVersion = "1.1";
             _this._attached = false;
@@ -74938,52 +75088,37 @@ var BABYLON;
             _this._deviceRoomPosition = BABYLON.Vector3.Zero();
             _this._deviceRoomRotationQuaternion = BABYLON.Quaternion.Identity();
             _this._standingMatrix = null;
-            // Represents device position and rotation in babylon space
+            /**
+             * Represents device position in babylon space.
+             */
             _this.devicePosition = BABYLON.Vector3.Zero();
+            /**
+             * Represents device rotation in babylon space.
+             */
             _this.deviceRotationQuaternion = BABYLON.Quaternion.Identity();
+            /**
+             * The scale of the device to be used when translating from device space to babylon space.
+             */
             _this.deviceScaleFactor = 1;
             _this._deviceToWorld = BABYLON.Matrix.Identity();
             _this._worldToDevice = BABYLON.Matrix.Identity();
+            /**
+             * References to the webVR controllers for the vrDevice.
+             */
             _this.controllers = [];
+            /**
+             * Emits an event when a controller is attached.
+             */
             _this.onControllersAttachedObservable = new BABYLON.Observable();
+            /**
+             * Emits an event when a controller's mesh has been loaded;
+             */
             _this.onControllerMeshLoadedObservable = new BABYLON.Observable();
-            _this.rigParenting = true; // should the rig cameras be used as parent instead of this camera.
+            /**
+             * If the rig cameras be used as parent instead of this camera.
+             */
+            _this.rigParenting = true;
             _this._defaultHeight = undefined;
-            _this.deviceDistanceToRoomGround = function () {
-                if (_this._standingMatrix && _this._defaultHeight === undefined) {
-                    // Add standing matrix offset to get real offset from ground in room
-                    _this._standingMatrix.getTranslationToRef(_this._workingVector);
-                    return _this._deviceRoomPosition.y + _this._workingVector.y;
-                }
-                //If VRDisplay does not inform stage parameters and no default height is set we fallback to zero.
-                return _this._defaultHeight || 0;
-            };
-            _this.useStandingMatrix = function (callback) {
-                if (callback === void 0) { callback = function (bool) { }; }
-                // Use standing matrix if availible
-                if (!navigator || !navigator.getVRDisplays) {
-                    callback(false);
-                }
-                else {
-                    navigator.getVRDisplays().then(function (displays) {
-                        if (!displays || !displays[0] || !displays[0].stageParameters || !displays[0].stageParameters.sittingToStandingTransform) {
-                            callback(false);
-                        }
-                        else {
-                            _this._standingMatrix = new BABYLON.Matrix();
-                            BABYLON.Matrix.FromFloat32ArrayToRefScaled(displays[0].stageParameters.sittingToStandingTransform, 0, 1, _this._standingMatrix);
-                            if (!_this.getScene().useRightHandedSystem) {
-                                [2, 6, 8, 9, 14].forEach(function (num) {
-                                    if (_this._standingMatrix) {
-                                        _this._standingMatrix.m[num] *= -1;
-                                    }
-                                });
-                            }
-                            callback(true);
-                        }
-                    });
-                }
-            };
             _this._workingVector = BABYLON.Vector3.Zero();
             _this._oneVector = BABYLON.Vector3.One();
             _this._workingMatrix = BABYLON.Matrix.Identity();
@@ -75063,10 +75198,62 @@ var BABYLON;
             });
             return _this;
         }
+        /**
+         * Gets the device distance from the ground.
+         * @returns the distance from the vrDevice to ground in device space. If standing matrix is not supported for the vrDevice 0 is returned.
+         */
+        WebVRFreeCamera.prototype.deviceDistanceToRoomGround = function () {
+            if (this._standingMatrix && this._defaultHeight === undefined) {
+                // Add standing matrix offset to get real offset from ground in room
+                this._standingMatrix.getTranslationToRef(this._workingVector);
+                return this._deviceRoomPosition.y + this._workingVector.y;
+            }
+            //If VRDisplay does not inform stage parameters and no default height is set we fallback to zero.
+            return this._defaultHeight || 0;
+        };
+        /**
+         * Enables the standing matrix when supported. This can be used to position the user's view the correct height from the ground.
+         * @param callback will be called when the standing matrix is set. Callback parameter is if the standing matrix is supported.
+         */
+        WebVRFreeCamera.prototype.useStandingMatrix = function (callback) {
+            var _this = this;
+            if (callback === void 0) { callback = function (bool) { }; }
+            // Use standing matrix if available
+            if (!navigator || !navigator.getVRDisplays) {
+                callback(false);
+            }
+            else {
+                navigator.getVRDisplays().then(function (displays) {
+                    if (!displays || !displays[0] || !displays[0].stageParameters || !displays[0].stageParameters.sittingToStandingTransform) {
+                        callback(false);
+                    }
+                    else {
+                        _this._standingMatrix = new BABYLON.Matrix();
+                        BABYLON.Matrix.FromFloat32ArrayToRefScaled(displays[0].stageParameters.sittingToStandingTransform, 0, 1, _this._standingMatrix);
+                        if (!_this.getScene().useRightHandedSystem) {
+                            [2, 6, 8, 9, 14].forEach(function (num) {
+                                if (_this._standingMatrix) {
+                                    _this._standingMatrix.m[num] *= -1;
+                                }
+                            });
+                        }
+                        callback(true);
+                    }
+                });
+            }
+        };
+        /**
+         * Disposes the camera
+         */
         WebVRFreeCamera.prototype.dispose = function () {
             this.getEngine().onVRRequestPresentComplete.removeCallback(this._onVREnabled);
             _super.prototype.dispose.call(this);
         };
+        /**
+         * Gets a vrController by name.
+         * @param name The name of the controller to retreive
+         * @returns the controller matching the name specified or null if not found
+         */
         WebVRFreeCamera.prototype.getControllerByName = function (name) {
             for (var _i = 0, _a = this.controllers; _i < _a.length; _i++) {
                 var gp = _a[_i];
@@ -75077,6 +75264,9 @@ var BABYLON;
             return null;
         };
         Object.defineProperty(WebVRFreeCamera.prototype, "leftController", {
+            /**
+             * The controller corrisponding to the users left hand.
+             */
             get: function () {
                 if (!this._leftController) {
                     this._leftController = this.getControllerByName("left");
@@ -75088,6 +75278,9 @@ var BABYLON;
         });
         ;
         Object.defineProperty(WebVRFreeCamera.prototype, "rightController", {
+            /**
+             * The controller corrisponding to the users right hand.
+             */
             get: function () {
                 if (!this._rightController) {
                     this._rightController = this.getControllerByName("right");
@@ -75098,6 +75291,11 @@ var BABYLON;
             configurable: true
         });
         ;
+        /**
+         * Casts a ray forward from the vrCamera's gaze.
+         * @param length Length of the ray (default: 100)
+         * @returns the ray corrisponding to the gaze
+         */
         WebVRFreeCamera.prototype.getForwardRay = function (length) {
             if (length === void 0) { length = 100; }
             if (this.leftCamera) {
@@ -75108,6 +75306,9 @@ var BABYLON;
                 return _super.prototype.getForwardRay.call(this, length);
             }
         };
+        /**
+         * Updates the camera based on device's frame data
+         */
         WebVRFreeCamera.prototype._checkInputs = function () {
             if (this._vrDevice && this._vrDevice.isPresenting) {
                 this._vrDevice.getFrameData(this._frameData);
@@ -75115,6 +75316,10 @@ var BABYLON;
             }
             _super.prototype._checkInputs.call(this);
         };
+        /**
+         * Updates the poseControlled values based on the input device pose.
+         * @param poseData Pose coming from the device
+         */
         WebVRFreeCamera.prototype.updateFromDevice = function (poseData) {
             if (poseData && poseData.orientation) {
                 this.rawPose = poseData;
@@ -75137,10 +75342,8 @@ var BABYLON;
          * within a user-interaction callback. Example:
          * <pre> scene.onPointerDown = function() { camera.attachControl(canvas); }</pre>
          *
-         * @param {HTMLElement} element
-         * @param {boolean} [noPreventDefault]
-         *
-         * @memberOf WebVRFreeCamera
+         * @param element html element to attach the vrDevice to
+         * @param noPreventDefault prevent the default html element operation when attaching the vrDevice
          */
         WebVRFreeCamera.prototype.attachControl = function (element, noPreventDefault) {
             _super.prototype.attachControl.call(this, element, noPreventDefault);
@@ -75150,6 +75353,11 @@ var BABYLON;
                 this.getEngine().enableVR();
             }
         };
+        /**
+         * Detaches the camera from the html element and disables VR
+         *
+         * @param element html element to detach from
+         */
         WebVRFreeCamera.prototype.detachControl = function (element) {
             this.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver);
             this.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver);
@@ -75157,14 +75365,24 @@ var BABYLON;
             this._attached = false;
             this.getEngine().disableVR();
         };
+        /**
+         * @returns the name of this class
+         */
         WebVRFreeCamera.prototype.getClassName = function () {
             return "WebVRFreeCamera";
         };
+        /**
+         * Calls resetPose on the vrDisplay
+         * See: https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/resetPose
+         */
         WebVRFreeCamera.prototype.resetToCurrentRotation = function () {
             //uses the vrDisplay's "resetPose()".
             //pitch and roll won't be affected.
             this._vrDevice.resetPose();
         };
+        /**
+         * Updates the rig cameras (left and right eye)
+         */
         WebVRFreeCamera.prototype._updateRigCameras = function () {
             var camLeft = this._rigCameras[0];
             var camRight = this._rigCameras[1];
@@ -75173,6 +75391,10 @@ var BABYLON;
             camLeft.position.copyFrom(this._deviceRoomPosition);
             camRight.position.copyFrom(this._deviceRoomPosition);
         };
+        /**
+         * Updates the cached values of the camera
+         * @param ignoreParentClass ignores updating the parent class's cache (default: false)
+         */
         WebVRFreeCamera.prototype._updateCache = function (ignoreParentClass) {
             var _this = this;
             if (!this.rotationQuaternion.equals(this._cache.rotationQuaternion) || !this.position.equals(this._cache.position)) {
@@ -75206,6 +75428,9 @@ var BABYLON;
             }
             this.updateCacheCalled = false;
         };
+        /**
+         * Updates the current device position and rotation in the babylon world
+         */
         WebVRFreeCamera.prototype.update = function () {
             // Get current device position in babylon world
             BABYLON.Vector3.TransformCoordinatesToRef(this._deviceRoomPosition, this._deviceToWorld, this.devicePosition);
@@ -75215,6 +75440,10 @@ var BABYLON;
             BABYLON.Quaternion.FromRotationMatrixToRef(this._workingMatrix, this.deviceRotationQuaternion);
             _super.prototype.update.call(this);
         };
+        /**
+         * Gets the view matrix of this camera (Always set to identity as left and right eye cameras contain the actual view matrix)
+         * @returns an identity matrix
+         */
         WebVRFreeCamera.prototype._getViewMatrix = function () {
             return BABYLON.Matrix.Identity();
         };
@@ -75267,6 +75496,9 @@ var BABYLON;
             }
             return this._projectionMatrix;
         };
+        /**
+         * Initializes the controllers and their meshes
+         */
         WebVRFreeCamera.prototype.initControllers = function () {
             var _this = this;
             this.controllers = [];
@@ -75608,8 +75840,18 @@ var BABYLON;
 
 var BABYLON;
 (function (BABYLON) {
+    /**
+     * Helps to quickly add VR support to an existing scene.
+     * See http://doc.babylonjs.com/how_to/webvr_helper
+     */
     var VRExperienceHelper = /** @class */ (function () {
-        function VRExperienceHelper(scene, webVROptions) {
+        /**
+         * Instantiates a VRExperienceHelper.
+         * Helps to quickly add VR support to an existing scene.
+         * @param scene The scene the VRExperienceHelper belongs to.
+         * @param webVROptions Options to modify the vr experience helper's behavior.
+         */
+        function VRExperienceHelper(scene, /** Options to modify the vr experience helper's behavior. */ webVROptions) {
             if (webVROptions === void 0) { webVROptions = {}; }
             var _this = this;
             this.webVROptions = webVROptions;
@@ -75985,9 +76227,15 @@ var BABYLON;
             configurable: true
         });
         Object.defineProperty(VRExperienceHelper.prototype, "teleportationTarget", {
+            /**
+             * The mesh used to display where the user is going to teleport.
+             */
             get: function () {
                 return this._teleportationTarget;
             },
+            /**
+             * Sets the mesh to be used to display where the user is going to teleport.
+             */
             set: function (value) {
                 if (value) {
                     value.name = "teleportationTarget";
@@ -75999,9 +76247,15 @@ var BABYLON;
             configurable: true
         });
         Object.defineProperty(VRExperienceHelper.prototype, "displayGaze", {
+            /**
+             * If the ray of the gaze should be displayed.
+             */
             get: function () {
                 return this._displayGaze;
             },
+            /**
+             * Sets if the ray of the gaze should be displayed.
+             */
             set: function (value) {
                 this._displayGaze = value;
                 if (!value) {
@@ -76012,9 +76266,15 @@ var BABYLON;
             configurable: true
         });
         Object.defineProperty(VRExperienceHelper.prototype, "displayLaserPointer", {
+            /**
+             * If the ray of the LaserPointer should be displayed.
+             */
             get: function () {
                 return this._displayLaserPointer;
             },
+            /**
+             * Sets if the ray of the LaserPointer should be displayed.
+             */
             set: function (value) {
                 this._displayLaserPointer = value;
                 if (!value) {
@@ -76038,6 +76298,9 @@ var BABYLON;
             configurable: true
         });
         Object.defineProperty(VRExperienceHelper.prototype, "deviceOrientationCamera", {
+            /**
+             * The deviceOrientationCamera used as the camera when not in VR.
+             */
             get: function () {
                 return this._deviceOrientationCamera;
             },
@@ -76045,7 +76308,9 @@ var BABYLON;
             configurable: true
         });
         Object.defineProperty(VRExperienceHelper.prototype, "currentVRCamera", {
-            // Based on the current WebVR support, returns the current VR camera used
+            /**
+             * Based on the current WebVR support, returns the current VR camera used.
+             */
             get: function () {
                 if (this._webVRready) {
                     return this._webVRCamera;
@@ -76058,6 +76323,9 @@ var BABYLON;
             configurable: true
         });
         Object.defineProperty(VRExperienceHelper.prototype, "webVRCamera", {
+            /**
+             * The webVRCamera which is used when in VR.
+             */
             get: function () {
                 return this._webVRCamera;
             },
@@ -76065,6 +76333,9 @@ var BABYLON;
             configurable: true
         });
         Object.defineProperty(VRExperienceHelper.prototype, "vrDeviceOrientationCamera", {
+            /**
+             * The deviceOrientationCamera that is used as a fallback when vr device is not connected.
+             */
             get: function () {
                 return this._vrDeviceOrientationCamera;
             },
@@ -76215,9 +76486,15 @@ var BABYLON;
             }
         };
         Object.defineProperty(VRExperienceHelper.prototype, "position", {
+            /**
+             * The position of the vr experience helper.
+             */
             get: function () {
                 return this._position;
             },
+            /**
+             * Sets the position of the vr experience helper.
+             */
             set: function (value) {
                 this._position = value;
                 if (this._scene.activeCamera) {
@@ -76227,6 +76504,9 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        /**
+         * Enables controllers and user interactions suck as selecting and object or clicking on an object.
+         */
         VRExperienceHelper.prototype.enableInteractions = function () {
             var _this = this;
             if (!this._interactionsEnabled) {
@@ -76267,6 +76547,10 @@ var BABYLON;
             }
             return false;
         };
+        /**
+         * Adds a floor mesh to be used for teleportation.
+         * @param floorMesh the mesh to be used for teleportation.
+         */
         VRExperienceHelper.prototype.addFloorMesh = function (floorMesh) {
             if (!this._floorMeshesCollection) {
                 return;
@@ -76276,6 +76560,10 @@ var BABYLON;
             }
             this._floorMeshesCollection.push(floorMesh);
         };
+        /**
+         * Removes a floor mesh from being used for teleportation.
+         * @param floorMesh the mesh to be removed.
+         */
         VRExperienceHelper.prototype.removeFloorMesh = function (floorMesh) {
             if (!this._floorMeshesCollection) {
                 return;
@@ -76285,6 +76573,10 @@ var BABYLON;
                 this._floorMeshesCollection.splice(meshIndex, 1);
             }
         };
+        /**
+         * Enables interactions and teleportation using the VR controllers and gaze.
+         * @param vrTeleportationOptions options to modify teleportation behavior.
+         */
         VRExperienceHelper.prototype.enableTeleportation = function (vrTeleportationOptions) {
             if (vrTeleportationOptions === void 0) { vrTeleportationOptions = {}; }
             if (!this._teleportationInitialized) {
@@ -76917,6 +77209,10 @@ var BABYLON;
                 this.changeLaserColor(new BABYLON.Color3(0.7, 0.7, 0.7));
             }
         };
+        /**
+         * Sets the color of the laser ray from the vr controllers.
+         * @param color new color for the ray.
+         */
         VRExperienceHelper.prototype.changeLaserColor = function (color) {
             if (this._leftLaserPointer && this._leftLaserPointer.material) {
                 this._leftLaserPointer.material.emissiveColor = color;
@@ -76925,11 +77221,18 @@ var BABYLON;
                 this._rightLaserPointer.material.emissiveColor = color;
             }
         };
+        /**
+         * Sets the color of the ray from the vr headsets gaze.
+         * @param color new color for the ray.
+         */
         VRExperienceHelper.prototype.changeGazeColor = function (color) {
             if (this._gazeTracker.material) {
                 this._gazeTracker.material.emissiveColor = color;
             }
         };
+        /**
+         * Exits VR and disposes of the vr experience helper
+         */
         VRExperienceHelper.prototype.dispose = function () {
             if (this.isInVRMode) {
                 this.exitVR();
@@ -76974,6 +77277,10 @@ var BABYLON;
             this._scene.gamepadManager.onGamepadDisconnectedObservable.removeCallback(this._onNewGamepadDisconnected);
             this._scene.unregisterBeforeRender(this.beforeRender);
         };
+        /**
+         * Gets the name of the VRExperienceHelper class
+         * @returns "VRExperienceHelper"
+         */
         VRExperienceHelper.prototype.getClassName = function () {
             return "VRExperienceHelper";
         };

文件差異過大導致無法顯示
+ 44 - 44
dist/preview release/babylon.worker.js


文件差異過大導致無法顯示
+ 1469 - 1195
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


文件差異過大導致無法顯示
+ 44 - 44
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


+ 350 - 43
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -8274,6 +8274,136 @@ var BABYLON;
 
 var BABYLON;
 (function (BABYLON) {
+    var PromiseStates;
+    (function (PromiseStates) {
+        PromiseStates[PromiseStates["Pending"] = 0] = "Pending";
+        PromiseStates[PromiseStates["Fulfilled"] = 1] = "Fulfilled";
+        PromiseStates[PromiseStates["Rejected"] = 2] = "Rejected";
+    })(PromiseStates || (PromiseStates = {}));
+    var Promise = /** @class */ (function () {
+        function Promise(resolver) {
+            var _this = this;
+            this._state = PromiseStates.Pending;
+            if (!resolver) {
+                return;
+            }
+            try {
+                resolver(function (value) {
+                    _this._resolve(value);
+                }, function (reason) {
+                    _this._reject(reason);
+                });
+            }
+            catch (e) {
+                this._reject(e.message);
+            }
+        }
+        Object.defineProperty(Promise.prototype, "state", {
+            get: function () {
+                return this._state;
+            },
+            enumerable: true,
+            configurable: true
+        });
+        Promise.prototype.isFulfilled = function () {
+            return this._state === PromiseStates.Fulfilled;
+        };
+        Promise.prototype.isRejected = function () {
+            return this._state === PromiseStates.Rejected;
+        };
+        Promise.prototype.isPending = function () {
+            return this._state === PromiseStates.Pending;
+        };
+        Promise.prototype.value = function () {
+            if (!this.isFulfilled()) {
+                throw new Error("Promise is not fulfilled");
+            }
+            return this._result;
+        };
+        Promise.prototype.reason = function () {
+            if (!this.isRejected()) {
+                throw new Error("Promise is not rejected");
+            }
+            return this._reason;
+        };
+        Promise.prototype.catch = function (onRejected) {
+            return this.then(undefined, onRejected);
+        };
+        Promise.prototype.then = function (onFulfilled, onRejected) {
+            var newPromise = new Promise();
+            newPromise._onFulfilled = onFulfilled;
+            newPromise._onRejected = onRejected;
+            // Composition
+            this._child = newPromise;
+            switch (this._state) {
+                case PromiseStates.Fulfilled:
+                    var returnedPromise = newPromise._resolve(this._result);
+                    if (returnedPromise) {
+                        newPromise._child = returnedPromise;
+                        newPromise = returnedPromise;
+                    }
+                    break;
+                case PromiseStates.Rejected:
+                    newPromise._reject(this._reason);
+                    newPromise._state = PromiseStates.Fulfilled;
+                    break;
+            }
+            return newPromise;
+        };
+        Promise.prototype._resolve = function (value) {
+            try {
+                this._state = PromiseStates.Fulfilled;
+                this._result = value;
+                var returnedPromise = null;
+                if (this._onFulfilled) {
+                    returnedPromise = this._onFulfilled(value);
+                }
+                if (this._child) {
+                    this._child._resolve(value);
+                }
+                return returnedPromise;
+            }
+            catch (e) {
+                this._reject(e.message);
+            }
+            return null;
+        };
+        Promise.prototype._reject = function (reason) {
+            this._state = PromiseStates.Rejected;
+            this._reason = reason;
+            if (this._onRejected) {
+                this._onRejected(reason);
+            }
+            if (this._child) {
+                this._child._resolve(null);
+            }
+        };
+        Promise.resolve = function (value) {
+            var newPromise = new Promise();
+            newPromise._resolve(value);
+            return newPromise;
+        };
+        return Promise;
+    }());
+    var PromisePolyfill = /** @class */ (function () {
+        function PromisePolyfill() {
+        }
+        PromisePolyfill.Apply = function (force) {
+            if (force === void 0) { force = false; }
+            if (force || typeof Promise === 'undefined') {
+                var root = window;
+                root.Promise = Promise;
+            }
+        };
+        return PromisePolyfill;
+    }());
+    BABYLON.PromisePolyfill = PromisePolyfill;
+})(BABYLON || (BABYLON = {}));
+
+//# sourceMappingURL=babylon.promise.js.map
+
+var BABYLON;
+(function (BABYLON) {
     var _AlphaState = /** @class */ (function () {
         /**
          * Initializes the state.
@@ -9106,6 +9236,8 @@ var BABYLON;
                 }
             };
             this._boundUniforms = {};
+            // Register promises
+            BABYLON.PromisePolyfill.Apply();
             var canvas = null;
             Engine.Instances.push(this);
             if (!canvasOrContext) {
@@ -74717,13 +74849,31 @@ var BABYLON;
 
 var BABYLON;
 (function (BABYLON) {
+    /**
+     * This represents a WebVR camera.
+     * The WebVR camera is Babylon's simple interface to interaction with Windows Mixed Reality, HTC Vive and Oculus Rift.
+     * @example http://doc.babylonjs.com/how_to/webvr_camera
+     */
     var WebVRFreeCamera = /** @class */ (function (_super) {
         __extends(WebVRFreeCamera, _super);
+        /**
+         * Instantiates a WebVRFreeCamera.
+         * @param name The name of the WebVRFreeCamera
+         * @param position The starting anchor position for the camera
+         * @param scene The scene the camera belongs to
+         * @param webVROptions a set of customizable options for the webVRCamera
+         */
         function WebVRFreeCamera(name, position, scene, webVROptions) {
             if (webVROptions === void 0) { webVROptions = {}; }
             var _this = _super.call(this, name, position, scene) || this;
             _this.webVROptions = webVROptions;
+            /**
+             * The vrDisplay tied to the camera. See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay
+             */
             _this._vrDevice = null;
+            /**
+             * The rawPose of the vrDevice.
+             */
             _this.rawPose = null;
             _this._specsVersion = "1.1";
             _this._attached = false;
@@ -74732,52 +74882,37 @@ var BABYLON;
             _this._deviceRoomPosition = BABYLON.Vector3.Zero();
             _this._deviceRoomRotationQuaternion = BABYLON.Quaternion.Identity();
             _this._standingMatrix = null;
-            // Represents device position and rotation in babylon space
+            /**
+             * Represents device position in babylon space.
+             */
             _this.devicePosition = BABYLON.Vector3.Zero();
+            /**
+             * Represents device rotation in babylon space.
+             */
             _this.deviceRotationQuaternion = BABYLON.Quaternion.Identity();
+            /**
+             * The scale of the device to be used when translating from device space to babylon space.
+             */
             _this.deviceScaleFactor = 1;
             _this._deviceToWorld = BABYLON.Matrix.Identity();
             _this._worldToDevice = BABYLON.Matrix.Identity();
+            /**
+             * References to the webVR controllers for the vrDevice.
+             */
             _this.controllers = [];
+            /**
+             * Emits an event when a controller is attached.
+             */
             _this.onControllersAttachedObservable = new BABYLON.Observable();
+            /**
+             * Emits an event when a controller's mesh has been loaded;
+             */
             _this.onControllerMeshLoadedObservable = new BABYLON.Observable();
-            _this.rigParenting = true; // should the rig cameras be used as parent instead of this camera.
+            /**
+             * If the rig cameras be used as parent instead of this camera.
+             */
+            _this.rigParenting = true;
             _this._defaultHeight = undefined;
-            _this.deviceDistanceToRoomGround = function () {
-                if (_this._standingMatrix && _this._defaultHeight === undefined) {
-                    // Add standing matrix offset to get real offset from ground in room
-                    _this._standingMatrix.getTranslationToRef(_this._workingVector);
-                    return _this._deviceRoomPosition.y + _this._workingVector.y;
-                }
-                //If VRDisplay does not inform stage parameters and no default height is set we fallback to zero.
-                return _this._defaultHeight || 0;
-            };
-            _this.useStandingMatrix = function (callback) {
-                if (callback === void 0) { callback = function (bool) { }; }
-                // Use standing matrix if availible
-                if (!navigator || !navigator.getVRDisplays) {
-                    callback(false);
-                }
-                else {
-                    navigator.getVRDisplays().then(function (displays) {
-                        if (!displays || !displays[0] || !displays[0].stageParameters || !displays[0].stageParameters.sittingToStandingTransform) {
-                            callback(false);
-                        }
-                        else {
-                            _this._standingMatrix = new BABYLON.Matrix();
-                            BABYLON.Matrix.FromFloat32ArrayToRefScaled(displays[0].stageParameters.sittingToStandingTransform, 0, 1, _this._standingMatrix);
-                            if (!_this.getScene().useRightHandedSystem) {
-                                [2, 6, 8, 9, 14].forEach(function (num) {
-                                    if (_this._standingMatrix) {
-                                        _this._standingMatrix.m[num] *= -1;
-                                    }
-                                });
-                            }
-                            callback(true);
-                        }
-                    });
-                }
-            };
             _this._workingVector = BABYLON.Vector3.Zero();
             _this._oneVector = BABYLON.Vector3.One();
             _this._workingMatrix = BABYLON.Matrix.Identity();
@@ -74857,10 +74992,62 @@ var BABYLON;
             });
             return _this;
         }
+        /**
+         * Gets the device distance from the ground.
+         * @returns the distance from the vrDevice to ground in device space. If standing matrix is not supported for the vrDevice 0 is returned.
+         */
+        WebVRFreeCamera.prototype.deviceDistanceToRoomGround = function () {
+            if (this._standingMatrix && this._defaultHeight === undefined) {
+                // Add standing matrix offset to get real offset from ground in room
+                this._standingMatrix.getTranslationToRef(this._workingVector);
+                return this._deviceRoomPosition.y + this._workingVector.y;
+            }
+            //If VRDisplay does not inform stage parameters and no default height is set we fallback to zero.
+            return this._defaultHeight || 0;
+        };
+        /**
+         * Enables the standing matrix when supported. This can be used to position the user's view the correct height from the ground.
+         * @param callback will be called when the standing matrix is set. Callback parameter is if the standing matrix is supported.
+         */
+        WebVRFreeCamera.prototype.useStandingMatrix = function (callback) {
+            var _this = this;
+            if (callback === void 0) { callback = function (bool) { }; }
+            // Use standing matrix if available
+            if (!navigator || !navigator.getVRDisplays) {
+                callback(false);
+            }
+            else {
+                navigator.getVRDisplays().then(function (displays) {
+                    if (!displays || !displays[0] || !displays[0].stageParameters || !displays[0].stageParameters.sittingToStandingTransform) {
+                        callback(false);
+                    }
+                    else {
+                        _this._standingMatrix = new BABYLON.Matrix();
+                        BABYLON.Matrix.FromFloat32ArrayToRefScaled(displays[0].stageParameters.sittingToStandingTransform, 0, 1, _this._standingMatrix);
+                        if (!_this.getScene().useRightHandedSystem) {
+                            [2, 6, 8, 9, 14].forEach(function (num) {
+                                if (_this._standingMatrix) {
+                                    _this._standingMatrix.m[num] *= -1;
+                                }
+                            });
+                        }
+                        callback(true);
+                    }
+                });
+            }
+        };
+        /**
+         * Disposes the camera
+         */
         WebVRFreeCamera.prototype.dispose = function () {
             this.getEngine().onVRRequestPresentComplete.removeCallback(this._onVREnabled);
             _super.prototype.dispose.call(this);
         };
+        /**
+         * Gets a vrController by name.
+         * @param name The name of the controller to retreive
+         * @returns the controller matching the name specified or null if not found
+         */
         WebVRFreeCamera.prototype.getControllerByName = function (name) {
             for (var _i = 0, _a = this.controllers; _i < _a.length; _i++) {
                 var gp = _a[_i];
@@ -74871,6 +75058,9 @@ var BABYLON;
             return null;
         };
         Object.defineProperty(WebVRFreeCamera.prototype, "leftController", {
+            /**
+             * The controller corrisponding to the users left hand.
+             */
             get: function () {
                 if (!this._leftController) {
                     this._leftController = this.getControllerByName("left");
@@ -74882,6 +75072,9 @@ var BABYLON;
         });
         ;
         Object.defineProperty(WebVRFreeCamera.prototype, "rightController", {
+            /**
+             * The controller corrisponding to the users right hand.
+             */
             get: function () {
                 if (!this._rightController) {
                     this._rightController = this.getControllerByName("right");
@@ -74892,6 +75085,11 @@ var BABYLON;
             configurable: true
         });
         ;
+        /**
+         * Casts a ray forward from the vrCamera's gaze.
+         * @param length Length of the ray (default: 100)
+         * @returns the ray corrisponding to the gaze
+         */
         WebVRFreeCamera.prototype.getForwardRay = function (length) {
             if (length === void 0) { length = 100; }
             if (this.leftCamera) {
@@ -74902,6 +75100,9 @@ var BABYLON;
                 return _super.prototype.getForwardRay.call(this, length);
             }
         };
+        /**
+         * Updates the camera based on device's frame data
+         */
         WebVRFreeCamera.prototype._checkInputs = function () {
             if (this._vrDevice && this._vrDevice.isPresenting) {
                 this._vrDevice.getFrameData(this._frameData);
@@ -74909,6 +75110,10 @@ var BABYLON;
             }
             _super.prototype._checkInputs.call(this);
         };
+        /**
+         * Updates the poseControlled values based on the input device pose.
+         * @param poseData Pose coming from the device
+         */
         WebVRFreeCamera.prototype.updateFromDevice = function (poseData) {
             if (poseData && poseData.orientation) {
                 this.rawPose = poseData;
@@ -74931,10 +75136,8 @@ var BABYLON;
          * within a user-interaction callback. Example:
          * <pre> scene.onPointerDown = function() { camera.attachControl(canvas); }</pre>
          *
-         * @param {HTMLElement} element
-         * @param {boolean} [noPreventDefault]
-         *
-         * @memberOf WebVRFreeCamera
+         * @param element html element to attach the vrDevice to
+         * @param noPreventDefault prevent the default html element operation when attaching the vrDevice
          */
         WebVRFreeCamera.prototype.attachControl = function (element, noPreventDefault) {
             _super.prototype.attachControl.call(this, element, noPreventDefault);
@@ -74944,6 +75147,11 @@ var BABYLON;
                 this.getEngine().enableVR();
             }
         };
+        /**
+         * Detaches the camera from the html element and disables VR
+         *
+         * @param element html element to detach from
+         */
         WebVRFreeCamera.prototype.detachControl = function (element) {
             this.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver);
             this.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver);
@@ -74951,14 +75159,24 @@ var BABYLON;
             this._attached = false;
             this.getEngine().disableVR();
         };
+        /**
+         * @returns the name of this class
+         */
         WebVRFreeCamera.prototype.getClassName = function () {
             return "WebVRFreeCamera";
         };
+        /**
+         * Calls resetPose on the vrDisplay
+         * See: https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/resetPose
+         */
         WebVRFreeCamera.prototype.resetToCurrentRotation = function () {
             //uses the vrDisplay's "resetPose()".
             //pitch and roll won't be affected.
             this._vrDevice.resetPose();
         };
+        /**
+         * Updates the rig cameras (left and right eye)
+         */
         WebVRFreeCamera.prototype._updateRigCameras = function () {
             var camLeft = this._rigCameras[0];
             var camRight = this._rigCameras[1];
@@ -74967,6 +75185,10 @@ var BABYLON;
             camLeft.position.copyFrom(this._deviceRoomPosition);
             camRight.position.copyFrom(this._deviceRoomPosition);
         };
+        /**
+         * Updates the cached values of the camera
+         * @param ignoreParentClass ignores updating the parent class's cache (default: false)
+         */
         WebVRFreeCamera.prototype._updateCache = function (ignoreParentClass) {
             var _this = this;
             if (!this.rotationQuaternion.equals(this._cache.rotationQuaternion) || !this.position.equals(this._cache.position)) {
@@ -75000,6 +75222,9 @@ var BABYLON;
             }
             this.updateCacheCalled = false;
         };
+        /**
+         * Updates the current device position and rotation in the babylon world
+         */
         WebVRFreeCamera.prototype.update = function () {
             // Get current device position in babylon world
             BABYLON.Vector3.TransformCoordinatesToRef(this._deviceRoomPosition, this._deviceToWorld, this.devicePosition);
@@ -75009,6 +75234,10 @@ var BABYLON;
             BABYLON.Quaternion.FromRotationMatrixToRef(this._workingMatrix, this.deviceRotationQuaternion);
             _super.prototype.update.call(this);
         };
+        /**
+         * Gets the view matrix of this camera (Always set to identity as left and right eye cameras contain the actual view matrix)
+         * @returns an identity matrix
+         */
         WebVRFreeCamera.prototype._getViewMatrix = function () {
             return BABYLON.Matrix.Identity();
         };
@@ -75061,6 +75290,9 @@ var BABYLON;
             }
             return this._projectionMatrix;
         };
+        /**
+         * Initializes the controllers and their meshes
+         */
         WebVRFreeCamera.prototype.initControllers = function () {
             var _this = this;
             this.controllers = [];
@@ -75402,8 +75634,18 @@ var BABYLON;
 
 var BABYLON;
 (function (BABYLON) {
+    /**
+     * Helps to quickly add VR support to an existing scene.
+     * See http://doc.babylonjs.com/how_to/webvr_helper
+     */
     var VRExperienceHelper = /** @class */ (function () {
-        function VRExperienceHelper(scene, webVROptions) {
+        /**
+         * Instantiates a VRExperienceHelper.
+         * Helps to quickly add VR support to an existing scene.
+         * @param scene The scene the VRExperienceHelper belongs to.
+         * @param webVROptions Options to modify the vr experience helper's behavior.
+         */
+        function VRExperienceHelper(scene, /** Options to modify the vr experience helper's behavior. */ webVROptions) {
             if (webVROptions === void 0) { webVROptions = {}; }
             var _this = this;
             this.webVROptions = webVROptions;
@@ -75779,9 +76021,15 @@ var BABYLON;
             configurable: true
         });
         Object.defineProperty(VRExperienceHelper.prototype, "teleportationTarget", {
+            /**
+             * The mesh used to display where the user is going to teleport.
+             */
             get: function () {
                 return this._teleportationTarget;
             },
+            /**
+             * Sets the mesh to be used to display where the user is going to teleport.
+             */
             set: function (value) {
                 if (value) {
                     value.name = "teleportationTarget";
@@ -75793,9 +76041,15 @@ var BABYLON;
             configurable: true
         });
         Object.defineProperty(VRExperienceHelper.prototype, "displayGaze", {
+            /**
+             * If the ray of the gaze should be displayed.
+             */
             get: function () {
                 return this._displayGaze;
             },
+            /**
+             * Sets if the ray of the gaze should be displayed.
+             */
             set: function (value) {
                 this._displayGaze = value;
                 if (!value) {
@@ -75806,9 +76060,15 @@ var BABYLON;
             configurable: true
         });
         Object.defineProperty(VRExperienceHelper.prototype, "displayLaserPointer", {
+            /**
+             * If the ray of the LaserPointer should be displayed.
+             */
             get: function () {
                 return this._displayLaserPointer;
             },
+            /**
+             * Sets if the ray of the LaserPointer should be displayed.
+             */
             set: function (value) {
                 this._displayLaserPointer = value;
                 if (!value) {
@@ -75832,6 +76092,9 @@ var BABYLON;
             configurable: true
         });
         Object.defineProperty(VRExperienceHelper.prototype, "deviceOrientationCamera", {
+            /**
+             * The deviceOrientationCamera used as the camera when not in VR.
+             */
             get: function () {
                 return this._deviceOrientationCamera;
             },
@@ -75839,7 +76102,9 @@ var BABYLON;
             configurable: true
         });
         Object.defineProperty(VRExperienceHelper.prototype, "currentVRCamera", {
-            // Based on the current WebVR support, returns the current VR camera used
+            /**
+             * Based on the current WebVR support, returns the current VR camera used.
+             */
             get: function () {
                 if (this._webVRready) {
                     return this._webVRCamera;
@@ -75852,6 +76117,9 @@ var BABYLON;
             configurable: true
         });
         Object.defineProperty(VRExperienceHelper.prototype, "webVRCamera", {
+            /**
+             * The webVRCamera which is used when in VR.
+             */
             get: function () {
                 return this._webVRCamera;
             },
@@ -75859,6 +76127,9 @@ var BABYLON;
             configurable: true
         });
         Object.defineProperty(VRExperienceHelper.prototype, "vrDeviceOrientationCamera", {
+            /**
+             * The deviceOrientationCamera that is used as a fallback when vr device is not connected.
+             */
             get: function () {
                 return this._vrDeviceOrientationCamera;
             },
@@ -76009,9 +76280,15 @@ var BABYLON;
             }
         };
         Object.defineProperty(VRExperienceHelper.prototype, "position", {
+            /**
+             * The position of the vr experience helper.
+             */
             get: function () {
                 return this._position;
             },
+            /**
+             * Sets the position of the vr experience helper.
+             */
             set: function (value) {
                 this._position = value;
                 if (this._scene.activeCamera) {
@@ -76021,6 +76298,9 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        /**
+         * Enables controllers and user interactions suck as selecting and object or clicking on an object.
+         */
         VRExperienceHelper.prototype.enableInteractions = function () {
             var _this = this;
             if (!this._interactionsEnabled) {
@@ -76061,6 +76341,10 @@ var BABYLON;
             }
             return false;
         };
+        /**
+         * Adds a floor mesh to be used for teleportation.
+         * @param floorMesh the mesh to be used for teleportation.
+         */
         VRExperienceHelper.prototype.addFloorMesh = function (floorMesh) {
             if (!this._floorMeshesCollection) {
                 return;
@@ -76070,6 +76354,10 @@ var BABYLON;
             }
             this._floorMeshesCollection.push(floorMesh);
         };
+        /**
+         * Removes a floor mesh from being used for teleportation.
+         * @param floorMesh the mesh to be removed.
+         */
         VRExperienceHelper.prototype.removeFloorMesh = function (floorMesh) {
             if (!this._floorMeshesCollection) {
                 return;
@@ -76079,6 +76367,10 @@ var BABYLON;
                 this._floorMeshesCollection.splice(meshIndex, 1);
             }
         };
+        /**
+         * Enables interactions and teleportation using the VR controllers and gaze.
+         * @param vrTeleportationOptions options to modify teleportation behavior.
+         */
         VRExperienceHelper.prototype.enableTeleportation = function (vrTeleportationOptions) {
             if (vrTeleportationOptions === void 0) { vrTeleportationOptions = {}; }
             if (!this._teleportationInitialized) {
@@ -76711,6 +77003,10 @@ var BABYLON;
                 this.changeLaserColor(new BABYLON.Color3(0.7, 0.7, 0.7));
             }
         };
+        /**
+         * Sets the color of the laser ray from the vr controllers.
+         * @param color new color for the ray.
+         */
         VRExperienceHelper.prototype.changeLaserColor = function (color) {
             if (this._leftLaserPointer && this._leftLaserPointer.material) {
                 this._leftLaserPointer.material.emissiveColor = color;
@@ -76719,11 +77015,18 @@ var BABYLON;
                 this._rightLaserPointer.material.emissiveColor = color;
             }
         };
+        /**
+         * Sets the color of the ray from the vr headsets gaze.
+         * @param color new color for the ray.
+         */
         VRExperienceHelper.prototype.changeGazeColor = function (color) {
             if (this._gazeTracker.material) {
                 this._gazeTracker.material.emissiveColor = color;
             }
         };
+        /**
+         * Exits VR and disposes of the vr experience helper
+         */
         VRExperienceHelper.prototype.dispose = function () {
             if (this.isInVRMode) {
                 this.exitVR();
@@ -76768,6 +77071,10 @@ var BABYLON;
             this._scene.gamepadManager.onGamepadDisconnectedObservable.removeCallback(this._onNewGamepadDisconnected);
             this._scene.unregisterBeforeRender(this.beforeRender);
         };
+        /**
+         * Gets the name of the VRExperienceHelper class
+         * @returns "VRExperienceHelper"
+         */
         VRExperienceHelper.prototype.getClassName = function () {
             return "VRExperienceHelper";
         };

文件差異過大導致無法顯示
+ 352 - 45
dist/preview release/customConfigurations/minimalGLTFViewer/es6.js


文件差異過大導致無法顯示
+ 352 - 45
dist/preview release/es6.js


文件差異過大導致無法顯示
+ 58 - 58
dist/preview release/viewer/babylon.viewer.js


+ 4 - 0
src/Engine/babylon.engine.ts

@@ -825,6 +825,10 @@
          * @param adaptToDeviceRatio defines whether to adapt to the device's viewport characteristics (default: false)
          */
         constructor(canvasOrContext: Nullable<HTMLCanvasElement | WebGLRenderingContext>, antialias?: boolean, options?: EngineOptions, adaptToDeviceRatio: boolean = false) {
+
+            // Register promises
+            PromisePolyfill.Apply();
+
             let canvas: Nullable<HTMLCanvasElement> = null;
             Engine.Instances.push(this);
 

+ 149 - 34
src/Tools/babylon.promise.ts

@@ -1,34 +1,149 @@
-// module BABYLON {
-//     export class Promise<T> {
-//         public constructor(resolver: (
-//                 resolve:(value:T) => void, 
-//                 reject: (reason: string) => void
-//             ) => void) {
-
-//             try {
-
-//             } catch(e) {
-//                 this._reject((<Error>e).message);
-//             }
-//         }
-
-//         public catch(onRejected: (reason: string) => void): Promise<T> {
-//             return this.then(undefined, onRejected);
-//         }
-
-//         public then(onFulfilled?: (fulfillment: T) => void, onRejected?: (reason: string) => void): Promise<T> {
-//             return this;
-//         }        
-
-//         private _reject(reason: string): void {
-            
-//         }
-
-//         // public static resolve(): Promise<T> {
-            
-//         // }
-//         // public static reject(reason: string): Promise<T> {
-//         //     let newPromise = 
-//         // }
-//     }
-// }
+module BABYLON {
+
+    enum PromiseStates {
+        Pending,
+        Fulfilled,
+        Rejected
+    }
+
+    class InternalPromise<T> {
+        private _state = PromiseStates.Pending;
+        private _result?: Nullable<T>;
+        private _reason: string;
+        private _child: InternalPromise<T>;
+        private _onFulfilled?: (fulfillment?: Nullable<T>) => Nullable<InternalPromise<T>>;
+        private _onRejected?: (reason: string) => void;
+
+        public get state(): PromiseStates {
+            return this._state;
+        }
+
+        public isFulfilled(): boolean {
+            return this._state === PromiseStates.Fulfilled;
+        }            
+
+        public isRejected(): boolean {
+            return this._state === PromiseStates.Rejected;
+        }
+    
+        public isPending(): boolean {
+            return this._state === PromiseStates.Pending;
+        }
+    
+        public value(): Nullable<T> | undefined {
+            if (!this.isFulfilled()) {
+                throw new Error("Promise is not fulfilled");
+            }
+            return this._result;
+        }     
+        
+        public reason(): string {
+            if (!this.isRejected()) {
+                throw new Error("Promise is not rejected");
+            }
+            return this._reason;
+        }            
+
+        public constructor(resolver?: (
+            resolve:(value?: Nullable<T>) => void, 
+            reject: (reason: string) => void
+        ) => void) {
+
+            if (!resolver) {
+                return;
+            }
+
+            try {
+                resolver((value?: Nullable<T>) => {
+                    this._resolve(value);
+                }, (reason: string) => {
+                    this._reject(reason);
+                });
+            } catch(e) {
+                this._reject((<Error>e).message);
+            }
+        }
+
+        public catch(onRejected: (reason: string) => void): InternalPromise<T> {
+            return this.then(undefined, onRejected);
+        }
+
+        public then(onFulfilled?: (fulfillment?: Nullable<T>) => Nullable<InternalPromise<T>>, onRejected?: (reason: string) => void): InternalPromise<T> {
+            let newPromise = new InternalPromise<T>();
+            newPromise._onFulfilled = onFulfilled;
+            newPromise._onRejected = onRejected;
+
+            // Composition
+            this._child = newPromise;
+
+            switch (this._state) {
+                case PromiseStates.Fulfilled:
+                    let returnedPromise = newPromise._resolve(this._result);
+
+                    if (returnedPromise) {
+                        newPromise._child = returnedPromise;
+                        newPromise = returnedPromise;
+                    }
+                    break;
+                case PromiseStates.Rejected:
+                    newPromise._reject(this._reason);
+                    newPromise._state = PromiseStates.Fulfilled;
+                    break;
+            }
+
+            return newPromise;
+        }       
+        
+        private _resolve(value?: Nullable<T>): Nullable<InternalPromise<T>> {
+            try {
+                this._state = PromiseStates.Fulfilled;
+                this._result = value;
+                let returnedPromise: Nullable<InternalPromise<T>> = null;
+
+                if (this._onFulfilled) {
+                    returnedPromise = this._onFulfilled(value);
+                }
+
+                if (this._child) {
+                    this._child._resolve(value);
+                }                
+
+                return returnedPromise;
+            } catch(e) {
+                this._reject((<Error>e).message);
+            }
+
+            return null;
+        }
+
+        private _reject(reason: string): void {
+            this._state = PromiseStates.Rejected;
+            this._reason = reason;
+
+            if (this._onRejected) {
+                this._onRejected(reason);
+            }
+
+            if (this._child) {
+                this._child._resolve(null);
+            }                
+        }
+
+        public static resolve<T>(value: T): InternalPromise<T> {
+            let newPromise = new InternalPromise<T>();
+
+            newPromise._resolve(value);
+
+            return newPromise;
+        }
+    }
+
+    export class PromisePolyfill {
+        public static Apply(force = false) {
+            if (force || typeof Promise === 'undefined') {
+                let root:any = window;
+                root.Promise = InternalPromise;
+            }
+        }
+    }
+}

+ 7 - 0
src/babylon.mixins.ts

@@ -169,3 +169,10 @@ interface EXT_disjoint_timer_query {
 interface WebGLUniformLocation {
     _currentState: any;
 }
+
+interface Promise<T> {
+    new (executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
+    then(onFulfilled?: (fulfillment?: BABYLON.Nullable<T>) => BABYLON.Nullable<Promise<T>>, onRejected?: (reason: string) => void): Promise<T>
+}
+
+declare var Promise: Promise<any>;

+ 61 - 0
tests/unit/babylon/promises/babylon.promises.tests.ts

@@ -0,0 +1,61 @@
+/**
+ * Describes the test suite.
+ */
+describe('Babylon.Promise', () => {
+    var subject : BABYLON.Engine;
+
+    /**
+     * Loads the dependencies.
+     */
+    before(function (done) {
+        this.timeout(180000);
+        (BABYLONDEVTOOLS).Loader
+            .useDist()
+            .load(function () {
+                BABYLON.PromisePolyfill.Apply(true);
+                done();
+            });
+    });
+
+    /**
+     * Create a nu engine subject before each test.
+     */
+    beforeEach(function () {
+        subject = new BABYLON.NullEngine({
+            renderHeight: 256,
+            renderWidth: 256,
+            textureSize: 256,
+            deterministicLockstep: false,
+            lockstepMaxSteps: 1
+        });
+    });
+
+    /**
+     * This test is more an integration test than a regular unit test but highlights how to rely
+     * on the BABYLON.NullEngine in order to create complex test cases.
+     */
+    describe('#Composition', () => {
+        it('should chain promises correctly', (done) => {
+            mocha.timeout(10000);
+            var tempString = "";
+            var p1 = new Promise((resolve, reject) => {
+                tempString = "Initial";
+            
+                resolve();
+            })
+            .then(() => {
+                tempString += " message";
+            })
+            .then(() => {
+                throw new Error('Something failed');
+            })
+            .catch(() => {
+                tempString += " to check promises";
+            })
+            .then(() => {
+                expect(tempString).to.eq("Initial message to check promises");
+                done();
+            });
+        });
+    });
+});