|
@@ -90,6 +90,31 @@ class WebXRController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ connect( inputSource ) {
|
|
|
+
|
|
|
+ if ( inputSource && inputSource.hand ) {
|
|
|
+
|
|
|
+ const hand = this._hand;
|
|
|
+
|
|
|
+ if ( hand ) {
|
|
|
+
|
|
|
+ for ( const inputjoint of inputSource.hand.values() ) {
|
|
|
+
|
|
|
+ // Initialize hand with joints when connected
|
|
|
+ this._getHandJoint( hand, inputjoint );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ this.dispatchEvent( { type: 'connected', data: inputSource } );
|
|
|
+
|
|
|
+ return this;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
disconnect( inputSource ) {
|
|
|
|
|
|
this.dispatchEvent( { type: 'disconnected', data: inputSource } );
|
|
@@ -137,19 +162,8 @@ class WebXRController {
|
|
|
// Update the joints groups with the XRJoint poses
|
|
|
const jointPose = frame.getJointPose( inputjoint, referenceSpace );
|
|
|
|
|
|
- if ( hand.joints[ inputjoint.jointName ] === undefined ) {
|
|
|
-
|
|
|
- // The transform of this joint will be updated with the joint pose on each frame
|
|
|
- const joint = new Group();
|
|
|
- joint.matrixAutoUpdate = false;
|
|
|
- joint.visible = false;
|
|
|
- hand.joints[ inputjoint.jointName ] = joint;
|
|
|
- // ??
|
|
|
- hand.add( joint );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- const joint = hand.joints[ inputjoint.jointName ];
|
|
|
+ // The transform of this joint will be updated with the joint pose on each frame
|
|
|
+ const joint = this._getHandJoint( hand, inputjoint );
|
|
|
|
|
|
if ( jointPose !== null ) {
|
|
|
|
|
@@ -301,6 +315,25 @@ class WebXRController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ // private method
|
|
|
+
|
|
|
+ _getHandJoint( hand, inputjoint ) {
|
|
|
+
|
|
|
+ if ( hand.joints[ inputjoint.jointName ] === undefined ) {
|
|
|
+
|
|
|
+ const joint = new Group();
|
|
|
+ joint.matrixAutoUpdate = false;
|
|
|
+ joint.visible = false;
|
|
|
+ hand.joints[ inputjoint.jointName ] = joint;
|
|
|
+
|
|
|
+ hand.add( joint );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return hand.joints[ inputjoint.jointName ];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|