Skip to content

Commit

Permalink
OculusHandPointerModel: cleanup on disconnect, implement dispose (#26262
Browse files Browse the repository at this point in the history
)
  • Loading branch information
CodyJasonBennett authored Jun 20, 2023
1 parent 36243d1 commit 21b8fa1
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions examples/jsm/webxr/OculusHandPointerModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const POINTER_LENGTH = 0.035;
const POINTER_SEGMENTS = 16;
const POINTER_RINGS = 12;
const POINTER_HEMISPHERE_ANGLE = 110;
const YAXIS = new THREE.Vector3( 0, 1, 0 );
const ZAXIS = new THREE.Vector3( 0, 0, 1 );
const YAXIS = /* @__PURE__ */ new THREE.Vector3( 0, 1, 0 );
const ZAXIS = /* @__PURE__ */ new THREE.Vector3( 0, 0, 1 );

const CURSOR_RADIUS = 0.02;
const CURSOR_MAX_DISTANCE = 1.5;
Expand All @@ -27,9 +27,10 @@ class OculusHandPointerModel extends THREE.Object3D {

this.hand = hand;
this.controller = controller;

// Unused
this.motionController = null;
this.envMap = null;

this.mesh = null;

this.pointerGeometry = null;
Expand All @@ -43,24 +44,36 @@ class OculusHandPointerModel extends THREE.Object3D {

this.raycaster = null;

hand.addEventListener( 'connected', ( event ) => {
this._onConnected = this._onConnected.bind( this );
this._onDisconnected = this._onDisconnected.bind( this );
this.hand.addEventListener( 'connected', this._onConnected );
this.hand.addEventListener( 'disconnected', this._onDisconnected );

const xrInputSource = event.data;
}

if ( xrInputSource.hand ) {
_onConnected( event ) {

this.visible = true;
this.xrInputSource = xrInputSource;
const xrInputSource = event.data;
if ( xrInputSource.hand ) {

if ( this.pointerObject === null ) {
this.visible = true;
this.xrInputSource = xrInputSource;

this.createPointer();
this.createPointer();

}
}

}
}

_onDisconnected() {

} );
this.visible = false;
this.xrInputSource = null;

this.pointerGeometry.dispose();
this.pointerMesh.material.dispose();

this.clear();

}

Expand Down Expand Up @@ -387,6 +400,14 @@ class OculusHandPointerModel extends THREE.Object3D {

}

dispose() {

this._onDisconnected();
this.hand.removeEventListener( 'connected', this._onConnected );
this.hand.removeEventListener( 'disconnected', this._onDisconnected );

}

}

export { OculusHandPointerModel };

0 comments on commit 21b8fa1

Please sign in to comment.