Explorar el Código

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David Catuhe hace 7 años
padre
commit
9f14dfcdd3

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

@@ -19,6 +19,7 @@
 - Added webVR constructor options: disable laser pointer toggle, teleportation floor meshes ([TrevorDev](https://github.com/TrevorDev))
 - Added webVR constructor options: disable laser pointer toggle, teleportation floor meshes ([TrevorDev](https://github.com/TrevorDev))
 - Get a root mesh from an asset container, load a mesh from a file with a single string url ([TrevorDev](https://github.com/TrevorDev))
 - Get a root mesh from an asset container, load a mesh from a file with a single string url ([TrevorDev](https://github.com/TrevorDev))
 - UtilityLayer class to render another scene as a layer on top of an existing scene ([TrevorDev](https://github.com/TrevorDev))
 - UtilityLayer class to render another scene as a layer on top of an existing scene ([TrevorDev](https://github.com/TrevorDev))
+- AnimationGroup has now onAnimationGroupEnd observable ([RaananW](https://github.com/RaananW))
 
 
 ### glTF Loader
 ### glTF Loader
 
 
@@ -35,6 +36,7 @@
 - Support for model drag and drop onto the canvas ([RaananW](https://github.com/RaananW))
 - Support for model drag and drop onto the canvas ([RaananW](https://github.com/RaananW))
 
 
 ## Bug fixes
 ## Bug fixes
+- VR experience helper will now fire pointer events even when no mesh is currently hit ([TrevorDev](https://github.com/TrevorDev))
 
 
 ### Core Engine
 ### Core Engine
 
 

+ 1 - 3
src/Animations/babylon.animatable.ts

@@ -195,7 +195,7 @@
             this._paused = false;
             this._paused = false;
         }
         }
 
 
-        private _raiseOnAnimationEnd() {            
+        private _raiseOnAnimationEnd() {
             if (this.onAnimationEnd) {
             if (this.onAnimationEnd) {
                 this.onAnimationEnd();
                 this.onAnimationEnd();
             }
             }
@@ -299,9 +299,7 @@
                 for (index = 0; index < runtimeAnimations.length; index++) {
                 for (index = 0; index < runtimeAnimations.length; index++) {
                     runtimeAnimations[index].dispose();
                     runtimeAnimations[index].dispose();
                 }
                 }
-            }
 
 
-            if (!running) {
                 this._raiseOnAnimationEnd();
                 this._raiseOnAnimationEnd();
                 this.onAnimationEnd = null
                 this.onAnimationEnd = null
                 this.onAnimationEndObservable.clear();
                 this.onAnimationEndObservable.clear();

+ 28 - 4
src/Animations/babylon.animationGroup.ts

@@ -23,12 +23,17 @@ module BABYLON {
         public onAnimationEndObservable = new Observable<TargetedAnimation>();
         public onAnimationEndObservable = new Observable<TargetedAnimation>();
 
 
         /**
         /**
+         * This observable will notify when all animations have ended.
+         */
+        public onAnimationGroupEndObservable = new Observable<AnimationGroup>();
+
+        /**
          * Gets the first frame
          * Gets the first frame
          */
          */
         public get from(): number {
         public get from(): number {
             return this._from;
             return this._from;
         }
         }
-        
+
         /**
         /**
          * Gets the last frame
          * Gets the last frame
          */
          */
@@ -171,9 +176,12 @@ module BABYLON {
             }
             }
 
 
             for (const targetedAnimation of this._targetedAnimations) {
             for (const targetedAnimation of this._targetedAnimations) {
-                this._animatables.push(this._scene.beginDirectAnimation(targetedAnimation.target, [targetedAnimation.animation], from !== undefined ? from : this._from, to !== undefined ? to : this._to, loop, speedRatio, () => {
+                let animatable = this._scene.beginDirectAnimation(targetedAnimation.target, [targetedAnimation.animation], from !== undefined ? from : this._from, to !== undefined ? to : this._to, loop, speedRatio);
+                animatable.onAnimationEnd = () => {
                     this.onAnimationEndObservable.notifyObservers(targetedAnimation);
                     this.onAnimationEndObservable.notifyObservers(targetedAnimation);
-                }));
+                    this._checkAnimationGroupEnded(animatable);
+                }
+                this._animatables.push(animatable);
             }
             }
 
 
             this._speedRatio = speedRatio;
             this._speedRatio = speedRatio;
@@ -205,7 +213,8 @@ module BABYLON {
          * @param loop defines if animations must loop
          * @param loop defines if animations must loop
          */
          */
         public play(loop?: boolean): AnimationGroup {
         public play(loop?: boolean): AnimationGroup {
-            if (this.isStarted) {
+            // only if all animatables are ready and exist
+            if (this.isStarted && this._animatables.length === this._targetedAnimations.length) {
                 if (loop !== undefined) {
                 if (loop !== undefined) {
                     for (var index = 0; index < this._animatables.length; index++) {
                     for (var index = 0; index < this._animatables.length; index++) {
                         let animatable = this._animatables[index];
                         let animatable = this._animatables[index];
@@ -214,6 +223,7 @@ module BABYLON {
                 }
                 }
                 this.restart();
                 this.restart();
             } else {
             } else {
+                this.stop();
                 this.start(loop, this._speedRatio);
                 this.start(loop, this._speedRatio);
             }
             }
 
 
@@ -331,5 +341,19 @@ module BABYLON {
                 this._scene.animationGroups.splice(index, 1);
                 this._scene.animationGroups.splice(index, 1);
             }
             }
         }
         }
+
+        private _checkAnimationGroupEnded(animatable: Animatable) {
+            // animatable should be taken out of the array
+            let idx = this._animatables.indexOf(animatable);
+            if (idx > -1) {
+                this._animatables.splice(idx, 1);
+            }
+
+            // all animatables were removed? animation group ended!
+            if (this._animatables.length === 0) {
+                this._isStarted = false;
+                this.onAnimationGroupEndObservable.notifyObservers(this);
+            }
+        }
     }
     }
 }
 }

+ 13 - 10
src/Cameras/VR/babylon.vrExperienceHelper.ts

@@ -83,13 +83,13 @@ module BABYLON {
 
 
         public _selectionPointerDown() {
         public _selectionPointerDown() {
             this._pointerDownOnMeshAsked = true;
             this._pointerDownOnMeshAsked = true;
-            if (this._currentMeshSelected && this._currentHit) {
+            if (this._currentHit) {
                 this.scene.simulatePointerDown(this._currentHit, {pointerId: this._id});
                 this.scene.simulatePointerDown(this._currentHit, {pointerId: this._id});
             }
             }
         }
         }
 
 
         public _selectionPointerUp() {
         public _selectionPointerUp() {
-            if (this._currentMeshSelected && this._currentHit) {
+            if (this._currentHit) {
                 this.scene.simulatePointerUp(this._currentHit, {pointerId: this._id});
                 this.scene.simulatePointerUp(this._currentHit, {pointerId: this._id});
             }
             }
             this._pointerDownOnMeshAsked = false;
             this._pointerDownOnMeshAsked = false;
@@ -679,7 +679,7 @@ module BABYLON {
             //create easing functions
             //create easing functions
             this._circleEase = new CircleEase();
             this._circleEase = new CircleEase();
             this._circleEase.setEasingMode(EasingFunction.EASINGMODE_EASEINOUT);
             this._circleEase.setEasingMode(EasingFunction.EASINGMODE_EASEINOUT);
-
+            
             if(this.webVROptions.floorMeshes){
             if(this.webVROptions.floorMeshes){
                 this.enableTeleportation({floorMeshes: this.webVROptions.floorMeshes});
                 this.enableTeleportation({floorMeshes: this.webVROptions.floorMeshes});
             }
             }
@@ -1581,9 +1581,17 @@ module BABYLON {
              
              
             var ray = gazer._getForwardRay(this._rayLength);
             var ray = gazer._getForwardRay(this._rayLength);
             var hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);
             var hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);
+            if(hit){
+                // Populate the contrllers mesh that can be used for drag/drop
+                if((<any>gazer)._laserPointer){
+                    hit.originMesh = (<any>gazer)._laserPointer.parent;
+                }
+                this._scene.simulatePointerMove(hit, {pointerId: gazer._id});
+            }
+            gazer._currentHit = hit;
 
 
             // Moving the gazeTracker on the mesh face targetted
             // Moving the gazeTracker on the mesh face targetted
-            if (hit && hit.pickedPoint) {
+            if (hit && hit.pickedPoint) {                
                 if (this._displayGaze) {
                 if (this._displayGaze) {
                     let multiplier = 1;
                     let multiplier = 1;
 
 
@@ -1634,12 +1642,8 @@ module BABYLON {
                 gazer._updatePointerDistance();   
                 gazer._updatePointerDistance();   
                 gazer._gazeTracker.isVisible = false;
                 gazer._gazeTracker.isVisible = false;
             }
             }
-
+            
             if (hit && hit.pickedMesh) {
             if (hit && hit.pickedMesh) {
-                gazer._currentHit = hit;
-                if (gazer._pointerDownOnMeshAsked) {
-                    this._scene.simulatePointerMove(gazer._currentHit, {pointerId: gazer._id});
-                }
                 // The object selected is the floor, we're in a teleportation scenario
                 // The object selected is the floor, we're in a teleportation scenario
                 if (this._teleportationInitialized && this._isTeleportationFloor(hit.pickedMesh) && hit.pickedPoint) {
                 if (this._teleportationInitialized && this._isTeleportationFloor(hit.pickedMesh) && hit.pickedPoint) {
                     // Moving the teleportation area to this targetted point
                     // Moving the teleportation area to this targetted point
@@ -1687,7 +1691,6 @@ module BABYLON {
                 }
                 }
             }
             }
             else {
             else {
-                gazer._currentHit = null;
                 this._notifySelectedMeshUnselected(gazer._currentMeshSelected);
                 this._notifySelectedMeshUnselected(gazer._currentMeshSelected);
                 gazer._currentMeshSelected = null;
                 gazer._currentMeshSelected = null;
                 //this._teleportationAllowed = false;
                 //this._teleportationAllowed = false;

+ 40 - 2
src/Collisions/babylon.pickingInfo.ts

@@ -7,18 +7,52 @@
         }
         }
     }
     }
 
 
+    /**
+     * Information about the result of picking within a scene
+     * See https://doc.babylonjs.com/babylon101/picking_collisions
+     */
     export class PickingInfo {
     export class PickingInfo {
+        /**
+         * If the pick collided with an object
+         */
         public hit = false;
         public hit = false;
+        /**
+         * Distance away where the pick collided
+         */
         public distance = 0;
         public distance = 0;
+        /**
+         * The location of pick collision
+         */
         public pickedPoint: Nullable<Vector3> = null;
         public pickedPoint: Nullable<Vector3> = null;
+        /**
+         * The mesh corrisponding the the pick collision
+         */
         public pickedMesh: Nullable<AbstractMesh> = null;
         public pickedMesh: Nullable<AbstractMesh> = null;
+        /** (See getTextureCoordinates) The barycentric U coordinate that is used when calulating the texture coordinates of the collision.*/
         public bu = 0;
         public bu = 0;
+        /** (See getTextureCoordinates) The barycentric V coordinate that is used when calulating the texture coordinates of the collision.*/
         public bv = 0;
         public bv = 0;
+        /** The id of the face on the mesh that was picked  */
         public faceId = -1;
         public faceId = -1;
+        /** Id of the the submesh that was picked */
         public subMeshId = 0;
         public subMeshId = 0;
+        /** If a sprite was picked, this will be the sprite the pick collided with */
         public pickedSprite: Nullable<Sprite> = null;
         public pickedSprite: Nullable<Sprite> = null;
-
-        // Methods
+        /**
+         * If a mesh was used to do the picking (eg. 6dof controller) this will be populated.
+         */
+        public originMesh: Nullable<AbstractMesh> = null;
+        /**
+         * The ray that was used to perform the picking.
+         */
+        public ray: Nullable<Ray> = null;
+
+        /**
+         * Gets the normal corrispodning to the face the pick collided with
+         * @param useWorldCoordinates If the resulting normal should be relative to the world (default: false)
+         * @param useVerticesNormals If the vertices normals should be used to calculate the normal instead of the normal map
+         * @returns The normal corrispodning to the face the pick collided with
+         */
         public getNormal(useWorldCoordinates = false, useVerticesNormals = true): Nullable<Vector3> {
         public getNormal(useWorldCoordinates = false, useVerticesNormals = true): Nullable<Vector3> {
             if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {
             if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {
                 return null;
                 return null;
@@ -64,6 +98,10 @@
             return Vector3.Normalize(result);
             return Vector3.Normalize(result);
         }
         }
 
 
+        /**
+         * Gets the texture coordinates of where the pick occured
+         * @returns the vector containing the coordnates of the texture
+         */
         public getTextureCoordinates(): Nullable<Vector2> {
         public getTextureCoordinates(): Nullable<Vector2> {
             if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
             if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
                 return null;
                 return null;

+ 5 - 1
src/babylon.scene.ts

@@ -5716,7 +5716,7 @@
          * @returns a PickingInfo
          * @returns a PickingInfo
          */
          */
         public pickWithRay(ray: Ray, predicate: (mesh: AbstractMesh) => boolean, fastCheck?: boolean): Nullable<PickingInfo> {
         public pickWithRay(ray: Ray, predicate: (mesh: AbstractMesh) => boolean, fastCheck?: boolean): Nullable<PickingInfo> {
-            return this._internalPick(world => {
+            var result = this._internalPick(world => {
                 if (!this._pickWithRayInverseMatrix) {
                 if (!this._pickWithRayInverseMatrix) {
                     this._pickWithRayInverseMatrix = Matrix.Identity();
                     this._pickWithRayInverseMatrix = Matrix.Identity();
                 }
                 }
@@ -5729,6 +5729,10 @@
                 Ray.TransformToRef(ray, this._pickWithRayInverseMatrix, this._cachedRayForTransform);
                 Ray.TransformToRef(ray, this._pickWithRayInverseMatrix, this._cachedRayForTransform);
                 return this._cachedRayForTransform;
                 return this._cachedRayForTransform;
             }, predicate, fastCheck);
             }, predicate, fastCheck);
+            if(result){
+                result.ray = ray;
+            }
+            return result;
         }
         }
 
 
         /**
         /**