浏览代码

Merge pull request #7620 from RaananW/component-type-id

XR - Small changes and small fix
David Catuhe 5 年之前
父节点
当前提交
e7b11f1215

+ 2 - 0
Playground/debug.html

@@ -6,6 +6,8 @@
         <meta charset='utf-8' />
         <meta charset='utf-8' />
         <meta name="viewport" content="width=device-width, user-scalable=no">
         <meta name="viewport" content="width=device-width, user-scalable=no">
         <link rel="shortcut icon" href="https://www.babylonjs.com/favicon.ico">
         <link rel="shortcut icon" href="https://www.babylonjs.com/favicon.ico">
+        <meta name="description" content="Babylon.js playground online debug">
+        <meta name="keywords" content="Babylon.js,WebGL,3D, debug">
 
 
         <link rel="apple-touch-icon" sizes="57x57" href="https://www.babylonjs.com/img/favicon/apple-icon-57x57.png">
         <link rel="apple-touch-icon" sizes="57x57" href="https://www.babylonjs.com/img/favicon/apple-icon-57x57.png">
         <link rel="apple-touch-icon" sizes="60x60" href="https://www.babylonjs.com/img/favicon/apple-icon-60x60.png">
         <link rel="apple-touch-icon" sizes="60x60" href="https://www.babylonjs.com/img/favicon/apple-icon-60x60.png">

+ 2 - 0
Playground/index-local.html

@@ -6,6 +6,8 @@
         <meta charset='utf-8' />
         <meta charset='utf-8' />
         <meta name="viewport" content="width=device-width, user-scalable=no">
         <meta name="viewport" content="width=device-width, user-scalable=no">
         <link rel="shortcut icon" href="https://www.babylonjs.com/favicon.ico">
         <link rel="shortcut icon" href="https://www.babylonjs.com/favicon.ico">
+        <meta name="description" content="Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes">
+        <meta name="keywords" content="Babylon.js,WebGL,3D">
 
 
         <link rel="stylesheet" href="https://use.typekit.net/cta4xsb.css" />
         <link rel="stylesheet" href="https://use.typekit.net/cta4xsb.css" />
         <link rel="stylesheet"
         <link rel="stylesheet"

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

@@ -198,7 +198,7 @@
 - New observable that triggers when a session was initialized ([RaananW](https://github.com/RaananW/))
 - New observable that triggers when a session was initialized ([RaananW](https://github.com/RaananW/))
 - WebXR teleportation can now be disabled after initialized or before created ([RaananW](https://github.com/RaananW/))
 - WebXR teleportation can now be disabled after initialized or before created ([RaananW](https://github.com/RaananW/))
 - New Features Manager for WebXR features ([RaananW](https://github.com/RaananW/))
 - New Features Manager for WebXR features ([RaananW](https://github.com/RaananW/))
-- New features - Plane detection, Hit Test, Background remover ([RaananW](https://github.com/RaananW/))
+- New features - Plane detection, Hit test, Background remover ([RaananW](https://github.com/RaananW/))
 - XR Camera's API is Babylon-conform (position, rotationQuaternion, world matrix, direction etc') ([#7239](https://github.com/BabylonJS/Babylon.js/issues/7239)) ([RaananW](https://github.com/RaananW/))
 - XR Camera's API is Babylon-conform (position, rotationQuaternion, world matrix, direction etc') ([#7239](https://github.com/BabylonJS/Babylon.js/issues/7239)) ([RaananW](https://github.com/RaananW/))
 - XR Input now using standard profiles and completely separated from the gamepad class ([#7348](https://github.com/BabylonJS/Babylon.js/issues/7348)) ([RaananW](https://github.com/RaananW/))
 - XR Input now using standard profiles and completely separated from the gamepad class ([#7348](https://github.com/BabylonJS/Babylon.js/issues/7348)) ([RaananW](https://github.com/RaananW/))
 - Teleportation and controller selection are now WebXR features. ([#7290](https://github.com/BabylonJS/Babylon.js/issues/7290)) ([RaananW](https://github.com/RaananW/))
 - Teleportation and controller selection are now WebXR features. ([#7290](https://github.com/BabylonJS/Babylon.js/issues/7290)) ([RaananW](https://github.com/RaananW/))

+ 37 - 5
src/XR/features/WebXRControllerPointerSelection.ts

@@ -66,6 +66,11 @@ export interface IWebXRControllerPointerSelectionOptions {
      * if provided, this scene will be used to render meshes.
      * if provided, this scene will be used to render meshes.
      */
      */
     customUtilityLayerScene?: Scene;
     customUtilityLayerScene?: Scene;
+
+    /**
+     *  use this rendering group id for the meshes (optional)
+     */
+    renderingGroupId?: number;
 }
 }
 
 
 /**
 /**
@@ -122,8 +127,6 @@ export class WebXRControllerPointerSelection extends WebXRAbstractFeature {
 
 
     private static _idCounter = 0;
     private static _idCounter = 0;
 
 
-    private _tmpRay = new Ray(new Vector3(), new Vector3());
-
     private _controllers: {
     private _controllers: {
         [controllerUniqueId: string]: {
         [controllerUniqueId: string]: {
             xrController: WebXRInputSource;
             xrController: WebXRInputSource;
@@ -132,8 +135,10 @@ export class WebXRControllerPointerSelection extends WebXRAbstractFeature {
             onFrameObserver?: Nullable<Observer<XRFrame>>;
             onFrameObserver?: Nullable<Observer<XRFrame>>;
             laserPointer: AbstractMesh;
             laserPointer: AbstractMesh;
             selectionMesh: AbstractMesh;
             selectionMesh: AbstractMesh;
+            meshUnderPointer: Nullable<AbstractMesh>;
             pick: Nullable<PickingInfo>;
             pick: Nullable<PickingInfo>;
             id: number;
             id: number;
+            tmpRay: Ray;
         };
         };
     } = {};
     } = {};
 
 
@@ -205,13 +210,27 @@ export class WebXRControllerPointerSelection extends WebXRAbstractFeature {
         return null;
         return null;
     }
     }
 
 
+    /**
+     * Will get the mesh under a specific pointer.
+     * `scene.meshUnderPointer` will only return one mesh - either left or right.
+     * @param controllerId the controllerId to check
+     * @returns The mesh under pointer or null if no mesh is under the pointer
+     */
+    public getMeshUnderPointer(controllerId: string): Nullable<AbstractMesh> {
+        if (this._controllers[controllerId]) {
+            return this._controllers[controllerId].meshUnderPointer;
+        } else {
+            return null;
+        }
+    }
+
     protected _onXRFrame(_xrFrame: XRFrame) {
     protected _onXRFrame(_xrFrame: XRFrame) {
         Object.keys(this._controllers).forEach((id) => {
         Object.keys(this._controllers).forEach((id) => {
             const controllerData = this._controllers[id];
             const controllerData = this._controllers[id];
 
 
             // Every frame check collisions/input
             // Every frame check collisions/input
-            controllerData.xrController.getWorldPointerRayToRef(this._tmpRay);
-            controllerData.pick = this._scene.pickWithRay(this._tmpRay);
+            controllerData.xrController.getWorldPointerRayToRef(controllerData.tmpRay);
+            controllerData.pick = this._scene.pickWithRay(controllerData.tmpRay);
 
 
             const pick = controllerData.pick;
             const pick = controllerData.pick;
 
 
@@ -226,7 +245,7 @@ export class WebXRControllerPointerSelection extends WebXRAbstractFeature {
                 controllerData.selectionMesh.scaling.z = Math.sqrt(pick.distance);
                 controllerData.selectionMesh.scaling.z = Math.sqrt(pick.distance);
 
 
                 // To avoid z-fighting
                 // To avoid z-fighting
-                let pickNormal = this._convertNormalToDirectionOfRay(pick.getNormal(true), this._tmpRay);
+                let pickNormal = this._convertNormalToDirectionOfRay(pick.getNormal(true), controllerData.tmpRay);
                 let deltaFighting = 0.001;
                 let deltaFighting = 0.001;
                 controllerData.selectionMesh.position.copyFrom(pick.pickedPoint);
                 controllerData.selectionMesh.position.copyFrom(pick.pickedPoint);
                 if (pickNormal) {
                 if (pickNormal) {
@@ -236,8 +255,10 @@ export class WebXRControllerPointerSelection extends WebXRAbstractFeature {
                     controllerData.selectionMesh.position.addInPlace(pickNormal.scale(deltaFighting));
                     controllerData.selectionMesh.position.addInPlace(pickNormal.scale(deltaFighting));
                 }
                 }
                 controllerData.selectionMesh.isVisible = true && this.displaySelectionMesh;
                 controllerData.selectionMesh.isVisible = true && this.displaySelectionMesh;
+                controllerData.meshUnderPointer = pick.pickedMesh;
             } else {
             } else {
                 controllerData.selectionMesh.isVisible = false;
                 controllerData.selectionMesh.isVisible = false;
+                controllerData.meshUnderPointer = null;
             }
             }
         });
         });
     }
     }
@@ -255,7 +276,9 @@ export class WebXRControllerPointerSelection extends WebXRAbstractFeature {
             xrController,
             xrController,
             laserPointer,
             laserPointer,
             selectionMesh,
             selectionMesh,
+            meshUnderPointer: null,
             pick: null,
             pick: null,
+            tmpRay: new Ray(new Vector3(), new Vector3()),
             id: WebXRControllerPointerSelection._idCounter++
             id: WebXRControllerPointerSelection._idCounter++
         };
         };
         switch (xrController.inputSource.targetRayMode) {
         switch (xrController.inputSource.targetRayMode) {
@@ -346,6 +369,10 @@ export class WebXRControllerPointerSelection extends WebXRAbstractFeature {
 
 
             oldPick = controllerData.pick;
             oldPick = controllerData.pick;
         });
         });
+
+        if (this._options.renderingGroupId !== undefined) {
+            discMesh.renderingGroupId = this._options.renderingGroupId;
+        }
         xrController.onDisposeObservable.addOnce(() => {
         xrController.onDisposeObservable.addOnce(() => {
             if (controllerData.pick && !this._options.disablePointerUpOnTouchOut && downTriggered) {
             if (controllerData.pick && !this._options.disablePointerUpOnTouchOut && downTriggered) {
                 this._scene.simulatePointerUp(controllerData.pick, { pointerId: controllerData.id });
                 this._scene.simulatePointerUp(controllerData.pick, { pointerId: controllerData.id });
@@ -466,6 +493,11 @@ export class WebXRControllerPointerSelection extends WebXRAbstractFeature {
         targetMat.backFaceCulling = false;
         targetMat.backFaceCulling = false;
         selectionMesh.material = targetMat;
         selectionMesh.material = targetMat;
 
 
+        if (this._options.renderingGroupId !== undefined) {
+            laserPointer.renderingGroupId = this._options.renderingGroupId;
+            selectionMesh.renderingGroupId = this._options.renderingGroupId;
+        }
+
         return {
         return {
             laserPointer,
             laserPointer,
             selectionMesh
             selectionMesh

+ 12 - 1
src/XR/features/WebXRControllerTeleportation.ts

@@ -92,6 +92,11 @@ export interface IWebXRTeleportationOptions {
      * if provided, this scene will be used to render meshes.
      * if provided, this scene will be used to render meshes.
      */
      */
     customUtilityLayerScene?: Scene;
     customUtilityLayerScene?: Scene;
+
+    /**
+     *  use this rendering group id for the meshes (optional)
+     */
+    renderingGroupId?: number;
 }
 }
 
 
 /**
 /**
@@ -345,7 +350,7 @@ export class WebXRMotionControllerTeleportation extends WebXRAbstractFeature {
         // motion controller support
         // motion controller support
         xrController.onMotionControllerInitObservable.addOnce(() => {
         xrController.onMotionControllerInitObservable.addOnce(() => {
             if (xrController.motionController) {
             if (xrController.motionController) {
-                const movementController = xrController.motionController.getComponentOfType(WebXRControllerComponent.THUMBSTICK) || xrController.motionController.getComponentOfType(WebXRControllerComponent.TOUCHPAD);
+                const movementController = xrController.motionController.getComponentOfType(WebXRControllerComponent.THUMBSTICK_TYPE) || xrController.motionController.getComponentOfType(WebXRControllerComponent.TOUCHPAD_TYPE);
                 if (!movementController || this._options.useMainComponentOnly) {
                 if (!movementController || this._options.useMainComponentOnly) {
                     // use trigger to move on long press
                     // use trigger to move on long press
                     const mainComponent = xrController.motionController.getMainComponent();
                     const mainComponent = xrController.motionController.getMainComponent();
@@ -564,6 +569,12 @@ export class WebXRMotionControllerTeleportation extends WebXRAbstractFeature {
             cone.material = torusConeMaterial;
             cone.material = torusConeMaterial;
         }
         }
 
 
+        if (this._options.renderingGroupId !== undefined) {
+            teleportationTarget.renderingGroupId = this._options.renderingGroupId;
+            torus.renderingGroupId = this._options.renderingGroupId;
+            cone.renderingGroupId = this._options.renderingGroupId;
+        }
+
         this._options.teleportationTargetMesh = teleportationTarget;
         this._options.teleportationTargetMesh = teleportationTarget;
     }
     }
 
 

+ 5 - 5
src/XR/motionController/webXRControllerComponent.ts

@@ -59,23 +59,23 @@ export class WebXRControllerComponent implements IDisposable {
     /**
     /**
      * Thumbstick component type
      * Thumbstick component type
      */
      */
-    public static THUMBSTICK: MotionControllerComponentType = "thumbstick";
+    public static THUMBSTICK_TYPE: MotionControllerComponentType = "thumbstick";
     /**
     /**
      * Touchpad component type
      * Touchpad component type
      */
      */
-    public static TOUCHPAD: MotionControllerComponentType = "touchpad";
+    public static TOUCHPAD_TYPE: MotionControllerComponentType = "touchpad";
     /**
     /**
      * trigger component type
      * trigger component type
      */
      */
-    public static TRIGGER: MotionControllerComponentType = "trigger";
+    public static TRIGGER_TYPE: MotionControllerComponentType = "trigger";
     /**
     /**
      * squeeze component type
      * squeeze component type
      */
      */
-    public static SQUEEZE: MotionControllerComponentType = "squeeze";
+    public static SQUEEZE_TYPE: MotionControllerComponentType = "squeeze";
     /**
     /**
      * button component type
      * button component type
      */
      */
-    public static BUTTON: MotionControllerComponentType = "button";
+    public static BUTTON_TYPE: MotionControllerComponentType = "button";
     /**
     /**
      * Observers registered here will be triggered when the state of a button changes
      * Observers registered here will be triggered when the state of a button changes
      * State change is either pressed / touched / value
      * State change is either pressed / touched / value

+ 2 - 2
src/XR/motionController/webXRProfiledMotionController.ts

@@ -57,12 +57,12 @@ export class WebXRProfiledMotionController extends WebXRAbstractMotionController
                     };
                     };
                 } else {
                 } else {
                     // visibility, usually for touchpads
                     // visibility, usually for touchpads
-                    const nameOfMesh = (componentInLayout.type === WebXRControllerComponent.TOUCHPAD && componentInLayout.touchPointNodeName)
+                    const nameOfMesh = (componentInLayout.type === WebXRControllerComponent.TOUCHPAD_TYPE && componentInLayout.touchPointNodeName)
                         ? componentInLayout.touchPointNodeName : visResponse.valueNodeName!;
                         ? componentInLayout.touchPointNodeName : visResponse.valueNodeName!;
                     this._buttonMeshMapping[type].states[visualResponseKey] = {
                     this._buttonMeshMapping[type].states[visualResponseKey] = {
                         valueMesh: this._getChildByName(this.rootMesh!, nameOfMesh)
                         valueMesh: this._getChildByName(this.rootMesh!, nameOfMesh)
                     };
                     };
-                    if (componentInLayout.type === WebXRControllerComponent.TOUCHPAD && !this._touchDots[visualResponseKey]) {
+                    if (componentInLayout.type === WebXRControllerComponent.TOUCHPAD_TYPE && !this._touchDots[visualResponseKey]) {
                         const dot = SphereBuilder.CreateSphere(visualResponseKey + 'dot', {
                         const dot = SphereBuilder.CreateSphere(visualResponseKey + 'dot', {
                             diameter: 0.0015,
                             diameter: 0.0015,
                             segments: 8
                             segments: 8