Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OculusHandPointerModel: cleanup on disconnect, implement dispose #26262

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 };