瀏覽代碼

added hasChanges to save processing time

Raanan Weber 5 年之前
父節點
當前提交
29b925cb32

+ 10 - 0
src/Cameras/XR/motionController/webXRControllerComponent.ts

@@ -91,6 +91,13 @@ export class WebXRControllerComponent implements IDisposable {
         y: 0
     };
     private _changes: IWebXRMotionControllerComponentChanges = {};
+    private _hasChanges: boolean = false;
+    /**
+     * Return whether or not the component changed the last frame
+     */
+    public get hasChanges(): boolean {
+        return this._hasChanges;
+    }
 
     /**
      * Creates a new component for a motion controller.
@@ -173,6 +180,7 @@ export class WebXRControllerComponent implements IDisposable {
     public update(nativeController: IMinimalMotionControllerObject) {
         let buttonUpdated = false;
         let axesUpdate = false;
+        this._hasChanges = false;
         this._changes = {};
 
         if (this.isButton()) {
@@ -244,9 +252,11 @@ export class WebXRControllerComponent implements IDisposable {
         }
 
         if (buttonUpdated) {
+            this._hasChanges = true;
             this.onButtonStateChanged.notifyObservers(this);
         }
         if (axesUpdate) {
+            this._hasChanges = true;
             this.onAxisValueChanged.notifyObservers(this._axes);
         }
     }

+ 1 - 0
src/Cameras/XR/motionController/webXRProfiledMotionController.ts

@@ -106,6 +106,7 @@ export class WebXRProfiledMotionController extends WebXRAbstractMotionController
         }
         this.getComponentTypes().forEach((type) => {
             const component = this.getComponent(type);
+            if (!component.hasChanges) { return; }
             const meshes = this._buttonMeshMapping[type];
             const componentInLayout = this.layout.components[type];
             Object.keys(componentInLayout.visualResponses).forEach((visualResponseKey) => {