Просмотр исходного кода

Merge branch 'master' into fullScreenGuiAR

David Catuhe 4 лет назад
Родитель
Сommit
a3b1a6dc97

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

@@ -121,6 +121,7 @@
 
 - Fixed time steps or delta time with sub time step for Oimo.js and Cannon.js ([cedricguillemet](https://github.com/cedricguillemet))
 - Ammo.js collision group and mask supported by impostor parameters ([cedricguillemet](https://github.com/cedricguillemet))
+- Contact point parameter in registerOnPhysicsCollide callback ([cedricguillemet](https://github.com/cedricguillemet))
 - `collisionResponse` flag to disable response but still get onCollide events ([cedricguillemet](https://github.com/cedricguillemet))
 - Ammo.js IDL exposed property update and raycast vehicle stablization support ([MackeyK24](https://github.com/MackeyK24))
 - Recast.js plugin nav mesh and crowd agent to ref performance optimizations. ([MackeyK24](https://github.com/MackeyK24))
@@ -207,6 +208,7 @@
 - Hit-Test results can be an empty array ([#8887](https://github.com/BabylonJS/Babylon.js/issues/8887)) ([RaananW](https://github.com/RaananW))
 - XR's main camera uses the first eye's projection matrix ([#8944](https://github.com/BabylonJS/Babylon.js/issues/8944)) ([RaananW](https://github.com/RaananW))
 - pointerX and pointerY of the scene are now updated when using the pointer selection feature ([#8879](https://github.com/BabylonJS/Babylon.js/issues/8879)) ([RaananW](https://github.com/RaananW))
+- XR tracking state was added to the camera ([#9076](https://github.com/BabylonJS/Babylon.js/issues/9076)) ([RaananW](https://github.com/RaananW))
 
 ### Collisions
 

+ 7 - 0
src/Helpers/textureDome.ts

@@ -154,6 +154,13 @@ export abstract class TextureDome<T extends Texture> extends TransformNode {
     }
 
     /**
+     * The background material of this dome.
+     */
+    public get material(): BackgroundMaterial {
+        return this._material;
+    }
+
+    /**
      * Oberserver used in Stereoscopic VR Mode.
      */
     private _onBeforeCameraRenderObserver: Nullable<Observer<Camera>> = null;

+ 11 - 3
src/Physics/Plugins/ammoJSPlugin.ts

@@ -55,6 +55,7 @@ export class AmmoJSPlugin implements IPhysicsEnginePlugin {
     private _tmpAmmoVectorRCA: any;
     private _tmpAmmoVectorRCB: any;
     private _raycastResult: PhysicsRaycastResult;
+    private _tmpContactPoint = new Vector3();
 
     private static readonly DISABLE_COLLISION_FLAG = 4;
     private static readonly KINEMATIC_FLAG = 2;
@@ -87,7 +88,14 @@ export class AmmoJSPlugin implements IPhysicsEnginePlugin {
         this.world = new this.bjsAMMO.btSoftRigidDynamicsWorld(this._dispatcher, this._overlappingPairCache, this._solver, this._collisionConfiguration, this._softBodySolver);
 
         this._tmpAmmoConcreteContactResultCallback = new this.bjsAMMO.ConcreteContactResultCallback();
-        this._tmpAmmoConcreteContactResultCallback.addSingleResult = () => { this._tmpContactCallbackResult = true; };
+        this._tmpAmmoConcreteContactResultCallback.addSingleResult = (contactPoint: any, colObj0Wrap: any, partId0: any, index0: any) => {
+            contactPoint = this.bjsAMMO.wrapPointer(contactPoint, Ammo.btManifoldPoint);
+            const worldPoint = contactPoint.getPositionWorldOnA();
+            this._tmpContactPoint.x = worldPoint.x();
+            this._tmpContactPoint.y = worldPoint.y();
+            this._tmpContactPoint.z = worldPoint.z();
+            this._tmpContactCallbackResult = true;
+        };
 
         this._raycastResult = new PhysicsRaycastResult();
 
@@ -219,8 +227,8 @@ export class AmmoJSPlugin implements IPhysicsEnginePlugin {
                         for (var otherImpostor of collideCallback.otherImpostors) {
                             if (mainImpostor.physicsBody.isActive() || otherImpostor.physicsBody.isActive()) {
                                 if (this._isImpostorPairInContact(mainImpostor, otherImpostor)) {
-                                    mainImpostor.onCollide({ body: otherImpostor.physicsBody });
-                                    otherImpostor.onCollide({ body: mainImpostor.physicsBody });
+                                    mainImpostor.onCollide({ body: otherImpostor.physicsBody, point: this._tmpContactPoint });
+                                    otherImpostor.onCollide({ body: mainImpostor.physicsBody, point: this._tmpContactPoint });
                                 }
                             }
                         }

+ 2 - 2
src/Physics/Plugins/oimoJSPlugin.ts

@@ -72,8 +72,8 @@ export class OimoJSPlugin implements IPhysicsEnginePlugin {
                 continue;
             }
 
-            mainImpostor.onCollide({ body: collidingImpostor.physicsBody });
-            collidingImpostor.onCollide({ body: mainImpostor.physicsBody });
+            mainImpostor.onCollide({ body: collidingImpostor.physicsBody, point: null});
+            collidingImpostor.onCollide({ body: mainImpostor.physicsBody, point: null });
             contact = contact.next;
         }
     }

+ 3 - 3
src/Physics/physicsImpostor.ts

@@ -222,7 +222,7 @@ export class PhysicsImpostor {
     private _onBeforePhysicsStepCallbacks = new Array<(impostor: PhysicsImpostor) => void>();
     private _onAfterPhysicsStepCallbacks = new Array<(impostor: PhysicsImpostor) => void>();
     /** @hidden */
-    public _onPhysicsCollideCallbacks: Array<{ callback: (collider: PhysicsImpostor, collidedAgainst: PhysicsImpostor) => void; otherImpostors: Array<PhysicsImpostor> }> = [];
+    public _onPhysicsCollideCallbacks: Array<{ callback: (collider: PhysicsImpostor, collidedAgainst: PhysicsImpostor, point: Nullable<Vector3>) => void; otherImpostors: Array<PhysicsImpostor> }> = [];
 
     private _deltaPosition: Vector3 = Vector3.Zero();
     private _deltaRotation: Quaternion;
@@ -885,7 +885,7 @@ export class PhysicsImpostor {
     /**
      * event and body object due to cannon's event-based architecture.
      */
-    public onCollide = (e: { body: any }) => {
+    public onCollide = (e: { body: any, point: Nullable<Vector3> }) => {
         if (!this._onPhysicsCollideCallbacks.length && !this.onCollideEvent) {
             return;
         }
@@ -904,7 +904,7 @@ export class PhysicsImpostor {
                     return obj.otherImpostors.indexOf(<PhysicsImpostor>otherImpostor) !== -1;
                 })
                 .forEach((obj) => {
-                    obj.callback(this, <PhysicsImpostor>otherImpostor);
+                    obj.callback(this, <PhysicsImpostor>otherImpostor, e.point);
                 });
         }
     };

+ 26 - 0
src/XR/webXRCamera.ts

@@ -6,6 +6,7 @@ import { TargetCamera } from "../Cameras/targetCamera";
 import { WebXRSessionManager } from "./webXRSessionManager";
 import { Viewport } from "../Maths/math.viewport";
 import { Observable } from "../Misc/observable";
+import { WebXRTrackingState } from "./webXRTypes";
 
 /**
  * WebXR Camera which holds the views for the xrSession
@@ -17,6 +18,7 @@ export class WebXRCamera extends FreeCamera {
     private _referencedPosition: Vector3 = new Vector3();
     private _xrInvPositionCache: Vector3 = new Vector3();
     private _xrInvQuaternionCache = Quaternion.Identity();
+    private _trackingState: WebXRTrackingState = WebXRTrackingState.NOT_TRACKING;
 
     /**
      * Observable raised before camera teleportation
@@ -29,6 +31,11 @@ export class WebXRCamera extends FreeCamera {
     public onAfterCameraTeleport = new Observable<Vector3>();
 
     /**
+     * Notifies when the camera's tracking state has changed.
+     * Notice - will also be triggered when tracking has started (at the beginning of the session)
+     */
+    public onTrackingStateChanged = new Observable<WebXRTrackingState>();
+    /**
      * Should position compensation execute on first frame.
      * This is used when copying the position from a native (non XR) camera
      */
@@ -75,6 +82,20 @@ export class WebXRCamera extends FreeCamera {
     }
 
     /**
+     * Get the current XR tracking state of the camera
+     */
+    public get trackingState(): WebXRTrackingState {
+        return this._trackingState;
+    }
+
+    private _setTrackingState(newState: WebXRTrackingState) {
+        if (this._trackingState !== newState) {
+            this._trackingState = newState;
+            this.onTrackingStateChanged.notifyObservers(newState);
+        }
+    }
+
+    /**
      * Return the user's height, unrelated to the current ground.
      * This will be the y position of this camera, when ground level is 0.
      */
@@ -133,9 +154,14 @@ export class WebXRCamera extends FreeCamera {
         const pose = this._xrSessionManager.currentFrame && this._xrSessionManager.currentFrame.getViewerPose(this._xrSessionManager.referenceSpace);
 
         if (!pose) {
+            this._setTrackingState(WebXRTrackingState.NOT_TRACKING);
             return;
         }
 
+        // Set the tracking state. if it didn't change it is a no-op
+        const trackingState = pose.emulatedPosition ? WebXRTrackingState.TRACKING_LOST : WebXRTrackingState.TRACKING;
+        this._setTrackingState(trackingState);
+
         if (pose.transform) {
             const pos = pose.transform.position;
             this._referencedPosition.set(pos.x, pos.y, pos.z);

+ 18 - 0
src/XR/webXRTypes.ts

@@ -24,6 +24,24 @@ export enum WebXRState {
 }
 
 /**
+ * The state of the XR camera's tracking
+ */
+export enum WebXRTrackingState {
+    /**
+     * No transformation received, device is not being tracked
+     */
+    NOT_TRACKING,
+    /**
+     * Tracking lost - using emulated position
+     */
+    TRACKING_LOST,
+    /**
+     * Transformation tracking works normally
+     */
+    TRACKING
+}
+
+/**
  * Abstraction of the XR render target
  */
 export interface WebXRRenderTarget extends IDisposable {