Browse Source

Merge pull request #8066 from RaananW/globalRenderingGroupIdWebXR

[XR] rendering group id for all default XR assets
David Catuhe 5 years ago
parent
commit
49019a6fb6

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

@@ -89,6 +89,7 @@
 - Pointer Selection feature now uses `selectstart` and `selectend` events when gamepad and motion controller are not present ([#7989](https://github.com/BabylonJS/Babylon.js/issues/7989)) ([RaananW](https://github.com/RaananW))
 - Removed forced `autoClear` = false settings ([RaananW](https://github.com/RaananW))
 - Added a warning that WebXR can only be served over HTTPS ([RaananW](https://github.com/RaananW))
+- Default (XR-global) rendering group ID can be defined when initializing a default experience ([RaananW](https://github.com/RaananW))
 - Added support for (experimental) haptic actuators ([#8068](https://github.com/BabylonJS/Babylon.js/issues/8068)) ([RaananW](https://github.com/RaananW))
 
 ### Collisions

+ 21 - 7
src/XR/webXRDefaultExperience.ts

@@ -1,12 +1,12 @@
 import { WebXRExperienceHelper } from "./webXRExperienceHelper";
 import { Scene } from '../scene';
 import { WebXRInput, IWebXRInputOptions } from './webXRInput';
-import { WebXRControllerPointerSelection } from './features/WebXRControllerPointerSelection';
+import { WebXRControllerPointerSelection, IWebXRControllerPointerSelectionOptions } from './features/WebXRControllerPointerSelection';
 import { WebXRRenderTarget } from './webXRTypes';
 import { WebXREnterExitUI, WebXREnterExitUIOptions } from './webXREnterExitUI';
 import { AbstractMesh } from '../Meshes/abstractMesh';
 import { WebXRManagedOutputCanvasOptions } from './webXRManagedOutputCanvas';
-import { WebXRMotionControllerTeleportation } from './features/WebXRControllerTeleportation';
+import { WebXRMotionControllerTeleportation, IWebXRTeleportationOptions } from './features/WebXRControllerTeleportation';
 import { Logger } from '../Misc/logger';
 
 /**
@@ -47,6 +47,11 @@ export class WebXRDefaultExperienceOptions {
      * When loading teleportation and pointer select, use stable versions instead of latest.
      */
     public useStablePlugins?: boolean;
+
+    /**
+     * An optional rendering group id that will be set globally for teleportation, pointer selection and default controller meshes
+     */
+    public renderingGroupId?: number;
 }
 
 /**
@@ -99,16 +104,25 @@ export class WebXRDefaultExperience {
             }
 
             // Add controller support
-            result.input = new WebXRInput(xrHelper.sessionManager, xrHelper.camera, options.inputOptions);
-            result.pointerSelection = <WebXRControllerPointerSelection>result.baseExperience.featuresManager.enableFeature(WebXRControllerPointerSelection.Name, options.useStablePlugins ? "stable" : "latest", {
-                xrInput: result.input
+            result.input = new WebXRInput(xrHelper.sessionManager, xrHelper.camera, {
+                controllerOptions: {
+                    renderingGroupId: options.renderingGroupId
+                },
+                ...(options.inputOptions || {})
+            });
+            result.pointerSelection = <WebXRControllerPointerSelection>result.baseExperience.featuresManager.enableFeature(WebXRControllerPointerSelection.Name, options.useStablePlugins ? "stable" : "latest",
+            <IWebXRControllerPointerSelectionOptions>{
+                xrInput: result.input,
+                renderingGroupId: options.renderingGroupId
             });
 
             // Add default teleportation, including rotation
             if (!options.disableTeleportation) {
-                result.teleportation = <WebXRMotionControllerTeleportation>result.baseExperience.featuresManager.enableFeature(WebXRMotionControllerTeleportation.Name, options.useStablePlugins ? "stable" : "latest", {
+                result.teleportation = <WebXRMotionControllerTeleportation>result.baseExperience.featuresManager.enableFeature(WebXRMotionControllerTeleportation.Name, options.useStablePlugins ? "stable" : "latest",
+                <IWebXRTeleportationOptions>{
                     floorMeshes: options.floorMeshes,
-                    xrInput: result.input
+                    xrInput: result.input,
+                    renderingGroupId: options.renderingGroupId
                 });
                 result.teleportation.setSelectionFeature(result.pointerSelection);
             }

+ 7 - 1
src/XR/webXRInput.ts

@@ -1,7 +1,7 @@
 import { Nullable } from "../types";
 import { Observer, Observable } from "../Misc/observable";
 import { IDisposable } from "../scene";
-import { WebXRInputSource } from './webXRInputSource';
+import { WebXRInputSource, IWebXRControllerOptions } from './webXRInputSource';
 import { WebXRSessionManager } from './webXRSessionManager';
 import { WebXRCamera } from './webXRCamera';
 import { WebXRMotionControllerManager } from './motionController/webXRMotionControllerManager';
@@ -38,6 +38,11 @@ export interface IWebXRInputOptions {
      * Should the controller model's components not move according to the user input
      */
     disableControllerAnimation?: boolean;
+
+    /**
+     * Optional options to pass to the controller. Will be overridden by the Input options where applicable
+     */
+    controllerOptions?: IWebXRControllerOptions;
 }
 /**
  * XR input used to track XR inputs such as controllers/rays
@@ -115,6 +120,7 @@ export class WebXRInput implements IDisposable {
         for (let input of addInputs) {
             if (sources.indexOf(input) === -1) {
                 let controller = new WebXRInputSource(this.xrSessionManager.scene, input, {
+                    ...(this.options.controllerOptions || {}),
                     forceControllerProfile: this.options.forceInputProfile,
                     doNotLoadControllerMesh: this.options.doNotLoadControllerMeshes,
                     disableMotionControllerAnimation: this.options.disableControllerAnimation

+ 14 - 4
src/XR/webXRInputSource.ts

@@ -26,6 +26,11 @@ export interface IWebXRControllerOptions {
      * This can be used when creating your own profile or when testing different controllers
      */
     forceControllerProfile?: string;
+    /**
+     * Defines a rendering group ID for meshes that will be loaded.
+     * This is for the default controllers only.
+     */
+    renderingGroupId?: number;
 }
 
 /**
@@ -97,10 +102,15 @@ export class WebXRInputSource {
                 // should the model be loaded?
                 if (!this._options.doNotLoadControllerMesh) {
                     this.motionController.loadModel().then((success) => {
-                        if (success) {
-                            this.onMeshLoadedObservable.notifyObservers(this.motionController!.rootMesh!);
-                            this.motionController!.rootMesh!.parent = this.grip || this.pointer;
-                            this.motionController!.disableAnimation = !!this._options.disableMotionControllerAnimation;
+                        if (success && this.motionController && this.motionController.rootMesh) {
+                            if (this._options.renderingGroupId) {
+                                // anything other than 0?
+                                this.motionController.rootMesh.renderingGroupId = this._options.renderingGroupId;
+                                this.motionController.rootMesh.getChildMeshes(false).forEach((mesh) => mesh.renderingGroupId = this._options.renderingGroupId!);
+                            }
+                            this.onMeshLoadedObservable.notifyObservers(this.motionController.rootMesh);
+                            this.motionController.rootMesh.parent = this.grip || this.pointer;
+                            this.motionController.disableAnimation = !!this._options.disableMotionControllerAnimation;
                         }
                     });
                 }