瀏覽代碼

Merge pull request #9396 from RaananW/handFlag

allow disabling the default hand mesh
David Catuhe 4 年之前
父節點
當前提交
3ce1fbf798
共有 1 個文件被更改,包括 12 次插入5 次删除
  1. 12 5
      src/XR/features/WebXRHandTracking.ts

+ 12 - 5
src/XR/features/WebXRHandTracking.ts

@@ -21,7 +21,7 @@ import { Material } from "../../Materials/material";
 import { Engine } from "../../Engines/engine";
 import { Tools } from "../../Misc/tools";
 import { Axis } from "../../Maths/math.axis";
-import { TransformNode } from '../../Meshes/transformNode';
+import { TransformNode } from "../../Meshes/transformNode";
 
 declare const XRHand: XRHand;
 
@@ -72,7 +72,7 @@ export interface IWebXRHandTrackingOptions {
          */
         physicsProps?: { friction?: number; restitution?: number; impostorType?: number };
         /**
-         * Should the default hand mesh be disabled. In this case, the spheres will be visible.
+         * Should the default hand mesh be disabled. In this case, the spheres will be visible (unless set invisible).
          */
         disableDefaultHandMesh?: boolean;
         /**
@@ -155,6 +155,7 @@ export class WebXRHand implements IDisposable {
      * @param trackedMeshes the meshes to be used to track the hand joints
      * @param _handMesh an optional hand mesh. if not provided, ours will be used
      * @param _rigMapping an optional rig mapping for the hand mesh. if not provided, ours will be used
+     * @param disableDefaultHandMesh should the default mesh creation be disabled
      */
     constructor(
         /** the controller to which the hand correlates */
@@ -162,14 +163,17 @@ export class WebXRHand implements IDisposable {
         /** the meshes to be used to track the hand joints */
         public readonly trackedMeshes: AbstractMesh[],
         private _handMesh?: AbstractMesh,
-        private _rigMapping?: string[]
+        private _rigMapping?: string[],
+        disableDefaultHandMesh?: boolean
     ) {
         this.handPartsDefinition = this.generateHandPartsDefinition(xrController.inputSource.hand!);
         this._scene = trackedMeshes[0].getScene();
         if (this._handMesh && this._rigMapping) {
             this._defaultHandMesh = false;
         } else {
-            this._generateDefaultHandMesh();
+            if (!disableDefaultHandMesh) {
+                this._generateDefaultHandMesh();
+            }
         }
 
         // hide the motion controller, if available/loaded
@@ -507,13 +511,16 @@ export class WebXRHandTracking extends WebXRAbstractFeature {
                 newInstance.physicsImpostor = new PhysicsImpostor(newInstance, type, { mass: 0, ...props });
             }
             newInstance.rotationQuaternion = new Quaternion();
+            if (this.options.jointMeshes?.invisible) {
+                newInstance.isVisible = false;
+            }
             trackedMeshes.push(newInstance);
         }
 
         const handedness = xrController.inputSource.handedness === "right" ? "right" : "left";
         const handMesh = this.options.jointMeshes?.handMeshes && this.options.jointMeshes?.handMeshes[handedness];
         const rigMapping = this.options.jointMeshes?.rigMapping && this.options.jointMeshes?.rigMapping[handedness];
-        const webxrHand = new WebXRHand(xrController, trackedMeshes, handMesh, rigMapping);
+        const webxrHand = new WebXRHand(xrController, trackedMeshes, handMesh, rigMapping, this.options.jointMeshes?.disableDefaultHandMesh);
 
         // get two new meshes
         this._hands[xrController.uniqueId] = {