فهرست منبع

Added Camera.ForceAttachControlToAlwaysPreventDefault

David Catuhe 9 سال پیش
والد
کامیت
2cc0021ca6

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 13 - 13
dist/preview release/babylon.core.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 941 - 930
dist/preview release/babylon.d.ts


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 14 - 14
dist/preview release/babylon.js


+ 27 - 10
dist/preview release/babylon.max.js

@@ -7173,39 +7173,49 @@ var BABYLON;
             }
             return false;
         };
-        Node.prototype._getDescendants = function (list, results, directDecendantsOnly) {
+        /**
+         * Evaluate a list of nodes and determine if they should be considered as descendants considering the given criterias
+         * @param {BABYLON.Node[]} list the input array of nodes to evaluate
+         * @param {BABYLON.Node[]} results the result array containing the nodes matching the given criterias
+         * @param {boolean} directDecendantsOnly if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered.
+         * @param predicate: an optional predicate that will be called on every evaluated children, the predicate must return true for a given child to be part of the result, otherwise it will be ignored.
+         */
+        Node.prototype._getDescendants = function (list, results, directDecendantsOnly, predicate) {
             if (directDecendantsOnly === void 0) { directDecendantsOnly = false; }
             for (var index = 0; index < list.length; index++) {
                 var item = list[index];
-                if ((directDecendantsOnly && item.parent === this) || (!directDecendantsOnly && item.isDescendantOf(this))) {
+                if (((directDecendantsOnly && item.parent === this) || (!directDecendantsOnly && item.isDescendantOf(this))) && (predicate === null || predicate(item))) {
                     results.push(item);
                 }
             }
         };
         /**
          * Will return all nodes that have this node as parent.
+         * @param {boolean} directDecendantsOnly if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered.
+         * @param predicate: an optional predicate that will be called on every evaluated children, the predicate must return true for a given child to be part of the result, otherwise it will be ignored.
          * @return {BABYLON.Node[]} all children nodes of all types.
          */
-        Node.prototype.getDescendants = function (directDecendantsOnly) {
+        Node.prototype.getDescendants = function (directDecendantsOnly, predicate) {
             var results = [];
-            this._getDescendants(this._scene.meshes, results, directDecendantsOnly);
-            this._getDescendants(this._scene.lights, results, directDecendantsOnly);
-            this._getDescendants(this._scene.cameras, results, directDecendantsOnly);
+            this._getDescendants(this._scene.meshes, results, directDecendantsOnly, predicate);
+            this._getDescendants(this._scene.lights, results, directDecendantsOnly, predicate);
+            this._getDescendants(this._scene.cameras, results, directDecendantsOnly, predicate);
             return results;
         };
         /**
+         * @param predicate: an optional predicate that will be called on every evaluated children, the predicate must return true for a given child to be part of the result, otherwise it will be ignored.
          * @Deprecated, legacy support.
          * use getDecendants instead.
          */
-        Node.prototype.getChildren = function () {
-            return this.getDescendants(true);
+        Node.prototype.getChildren = function (predicate) {
+            return this.getDescendants(true, predicate);
         };
         /**
          * Get all child-meshes of this node.
          */
-        Node.prototype.getChildMeshes = function (directDecendantsOnly) {
+        Node.prototype.getChildMeshes = function (directDecendantsOnly, predicate) {
             var results = [];
-            this._getDescendants(this._scene.meshes, results, directDecendantsOnly);
+            this._getDescendants(this._scene.meshes, results, directDecendantsOnly, predicate);
             return results;
         };
         Node.prototype._setReady = function (state) {
@@ -10973,6 +10983,7 @@ var BABYLON;
         Camera._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED = 12;
         Camera._RIG_MODE_STEREOSCOPIC_OVERUNDER = 13;
         Camera._RIG_MODE_VR = 20;
+        Camera.ForceAttachControlToAlwaysPreventDefault = false;
         __decorate([
             BABYLON.serializeAsVector3()
         ], Camera.prototype, "position", void 0);
@@ -11344,6 +11355,7 @@ var BABYLON;
                 return;
             }
             this._attachedElement = element;
+            noPreventDefault = BABYLON.Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
             if (this._onMouseDown === undefined) {
                 this._onMouseDown = function (evt) {
                     previousPosition = {
@@ -11687,6 +11699,7 @@ var BABYLON;
             if (this._attachedCanvas) {
                 return;
             }
+            noPreventDefault = BABYLON.Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
             if (this._onPointerDown === undefined) {
                 this._onPointerDown = function (evt) {
                     if (evt.pointerType === "mouse") {
@@ -11943,6 +11956,7 @@ var BABYLON;
                 return;
             }
             this._attachedElement = element;
+            noPreventDefault = BABYLON.Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
             var engine = this.getEngine();
             if (this._onPointerDown === undefined) {
                 this._onPointerDown = function (evt) {
@@ -34106,6 +34120,7 @@ var BABYLON;
         };
         VRDeviceOrientationFreeCamera.prototype.attachControl = function (element, noPreventDefault) {
             _super.prototype.attachControl.call(this, element, noPreventDefault);
+            noPreventDefault = BABYLON.Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
             window.addEventListener("deviceorientation", this._deviceOrientationHandler);
         };
         VRDeviceOrientationFreeCamera.prototype.detachControl = function (element) {
@@ -34179,6 +34194,7 @@ var BABYLON;
         };
         WebVRFreeCamera.prototype.attachControl = function (element, noPreventDefault) {
             _super.prototype.attachControl.call(this, element, noPreventDefault);
+            noPreventDefault = BABYLON.Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
             if (navigator.getVRDevices) {
                 navigator.getVRDevices().then(this._getWebVRDevices);
             }
@@ -35523,6 +35539,7 @@ var BABYLON;
                 return;
             }
             this._attachedCanvas = canvas;
+            noPreventDefault = BABYLON.Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
             if (!this._orientationChanged) {
                 this._orientationChanged = function (evt) {
                     if (!_this._initialOrientationGamma) {

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 22 - 22
dist/preview release/babylon.noworker.js


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

@@ -9,6 +9,7 @@
     - Animations blending. See [demo here](http://www.babylonjs-playground.com/#2BLI9T#3). More [info here](NEED DOC!) ([deltakosh](https://github.com/deltakosh))
     - New debuger tool: SkeletonViewer. See [demo here](Demo available here: http://www.babylonjs-playground.com/#1BZJVJ#8) (Adam & [deltakosh](https://github.com/deltakosh))
   - **Updates**
+    - Added Camera.ForceAttachControlToAlwaysPreventDefault to help embedding Babylon.js in iFrames ([deltakosh](https://github.com/deltakosh))
     - Support for Layer.alphaTest ([deltakosh](https://github.com/deltakosh))
     - New scene.pointerDownPredicate, scene.pointerMovePredicate, scene.pointerUpPredicate to define your own predicates for meshes picking selection ([deltakosh](https://github.com/deltakosh))
     - New OnPickTrigger support for spritesManager ([deltakosh](https://github.com/deltakosh))

+ 1 - 0
src/Cameras/VR/babylon.vrDeviceOrientationCamera.js

@@ -35,6 +35,7 @@ var BABYLON;
         };
         VRDeviceOrientationFreeCamera.prototype.attachControl = function (element, noPreventDefault) {
             _super.prototype.attachControl.call(this, element, noPreventDefault);
+            noPreventDefault = BABYLON.Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
             window.addEventListener("deviceorientation", this._deviceOrientationHandler);
         };
         VRDeviceOrientationFreeCamera.prototype.detachControl = function (element) {

+ 2 - 0
src/Cameras/VR/babylon.vrDeviceOrientationCamera.ts

@@ -38,6 +38,8 @@ module BABYLON {
         public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
             super.attachControl(element, noPreventDefault);
 
+            noPreventDefault = Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
+
             window.addEventListener("deviceorientation", this._deviceOrientationHandler);
         }
 

+ 1 - 0
src/Cameras/VR/babylon.webVRCamera.js

@@ -56,6 +56,7 @@ var BABYLON;
         };
         WebVRFreeCamera.prototype.attachControl = function (element, noPreventDefault) {
             _super.prototype.attachControl.call(this, element, noPreventDefault);
+            noPreventDefault = BABYLON.Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
             if (navigator.getVRDevices) {
                 navigator.getVRDevices().then(this._getWebVRDevices);
             }

+ 2 - 0
src/Cameras/VR/babylon.webVRCamera.ts

@@ -65,6 +65,8 @@ module BABYLON {
         public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
             super.attachControl(element, noPreventDefault);
 
+            noPreventDefault = Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
+
             if (navigator.getVRDevices) {
                 navigator.getVRDevices().then(this._getWebVRDevices);
             }

+ 1 - 0
src/Cameras/babylon.arcRotateCamera.js

@@ -160,6 +160,7 @@ var BABYLON;
                 return;
             }
             this._attachedElement = element;
+            noPreventDefault = BABYLON.Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
             var engine = this.getEngine();
             if (this._onPointerDown === undefined) {
                 this._onPointerDown = function (evt) {

+ 2 - 0
src/Cameras/babylon.arcRotateCamera.ts

@@ -204,6 +204,8 @@
             }
             this._attachedElement = element;
 
+            noPreventDefault = Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
+
             var engine = this.getEngine();
 
             if (this._onPointerDown === undefined) {

+ 1 - 0
src/Cameras/babylon.camera.js

@@ -558,6 +558,7 @@ var BABYLON;
         Camera._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED = 12;
         Camera._RIG_MODE_STEREOSCOPIC_OVERUNDER = 13;
         Camera._RIG_MODE_VR = 20;
+        Camera.ForceAttachControlToAlwaysPreventDefault = false;
         __decorate([
             BABYLON.serializeAsVector3()
         ], Camera.prototype, "position", void 0);

+ 2 - 0
src/Cameras/babylon.camera.ts

@@ -53,6 +53,8 @@
         public static get RIG_MODE_VR(): number {
             return Camera._RIG_MODE_VR;
         }
+
+        public static ForceAttachControlToAlwaysPreventDefault = false;
         
         // Members
         @serializeAsVector3()

+ 1 - 0
src/Cameras/babylon.deviceOrientationCamera.js

@@ -35,6 +35,7 @@ var BABYLON;
                 return;
             }
             this._attachedCanvas = canvas;
+            noPreventDefault = BABYLON.Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
             if (!this._orientationChanged) {
                 this._orientationChanged = function (evt) {
                     if (!_this._initialOrientationGamma) {

+ 2 - 1
src/Cameras/babylon.deviceOrientationCamera.ts

@@ -24,11 +24,12 @@ module BABYLON {
             }, false);
         }
 
-        public attachControl(canvas: HTMLCanvasElement, noPreventDefault: boolean): void {
+        public attachControl(canvas: HTMLCanvasElement, noPreventDefault?: boolean): void {
             if (this._attachedCanvas) {
                 return;
             }
             this._attachedCanvas = canvas;
+            noPreventDefault = Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
 
             if (!this._orientationChanged) {
                 this._orientationChanged = (evt) => {

+ 1 - 0
src/Cameras/babylon.freeCamera.js

@@ -61,6 +61,7 @@ var BABYLON;
                 return;
             }
             this._attachedElement = element;
+            noPreventDefault = BABYLON.Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
             if (this._onMouseDown === undefined) {
                 this._onMouseDown = function (evt) {
                     previousPosition = {

+ 1 - 0
src/Cameras/babylon.freeCamera.ts

@@ -60,6 +60,7 @@
                 return;
             }
             this._attachedElement = element;
+            noPreventDefault = Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
 
             if (this._onMouseDown === undefined) {
                 this._onMouseDown = evt => {

+ 1 - 0
src/Cameras/babylon.touchCamera.js

@@ -34,6 +34,7 @@ var BABYLON;
             if (this._attachedCanvas) {
                 return;
             }
+            noPreventDefault = BABYLON.Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
             if (this._onPointerDown === undefined) {
                 this._onPointerDown = function (evt) {
                     if (evt.pointerType === "mouse") {

+ 1 - 0
src/Cameras/babylon.touchCamera.ts

@@ -32,6 +32,7 @@ module BABYLON {
             if (this._attachedCanvas) {
                 return;
             }
+            noPreventDefault = Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
 
             if (this._onPointerDown === undefined) {
 

+ 2 - 2
src/babylon.node.js

@@ -142,7 +142,7 @@ var BABYLON;
             if (directDecendantsOnly === void 0) { directDecendantsOnly = false; }
             for (var index = 0; index < list.length; index++) {
                 var item = list[index];
-                if (((directDecendantsOnly && item.parent === this) || (!directDecendantsOnly && item.isDescendantOf(this))) && (predicate == null || predicate(item))) {
+                if (((directDecendantsOnly && item.parent === this) || (!directDecendantsOnly && item.isDescendantOf(this))) && (predicate === null || predicate(item))) {
                     results.push(item);
                 }
             }
@@ -260,6 +260,6 @@ var BABYLON;
             BABYLON.serialize()
         ], Node.prototype, "state", void 0);
         return Node;
-    }());
+    })();
     BABYLON.Node = Node;
 })(BABYLON || (BABYLON = {}));

+ 2 - 2
src/babylon.node.ts

@@ -186,7 +186,7 @@
         public _getDescendants(list: Node[], results: Node[], directDecendantsOnly: boolean = false, predicate?: (node: Node) => boolean): void {
             for (var index = 0; index < list.length; index++) {
                 var item = list[index];
-                if (((directDecendantsOnly && item.parent === this) || (!directDecendantsOnly && item.isDescendantOf(this))) && (predicate==null || predicate(item))) {
+                if (((directDecendantsOnly && item.parent === this) || (!directDecendantsOnly && item.isDescendantOf(this))) && (predicate === null || predicate(item))) {
                     results.push(item);
                 }
             }
@@ -309,4 +309,4 @@
             }
         }
     }
-} 
+}