@@ -20,25 +20,9 @@ Object.assign( WebXRController.prototype, {
2020 this . _hand . matrixAutoUpdate = false ;
2121 this . _hand . visible = false ;
2222
23- this . _hand . joints = [ ] ;
23+ this . _hand . joints = { } ;
2424 this . _hand . inputState = { pinching : false } ;
2525
26- if ( window . XRHand ) {
27-
28- for ( let i = 0 ; i <= window . XRHand . LITTLE_PHALANX_TIP ; i ++ ) {
29-
30- // The transform of this joint will be updated with the joint pose on each frame
31- const joint = new Group ( ) ;
32- joint . matrixAutoUpdate = false ;
33- joint . visible = false ;
34- this . _hand . joints . push ( joint ) ;
35- // ??
36- this . _hand . add ( joint ) ;
37-
38- }
39-
40- }
41-
4226 }
4327
4428 return this . _hand ;
@@ -139,55 +123,64 @@ Object.assign( WebXRController.prototype, {
139123
140124 handPose = true ;
141125
142- for ( let i = 0 ; i <= window . XRHand . LITTLE_PHALANX_TIP ; i ++ ) {
126+ for ( const inputjoint of inputSource . hand . values ( ) ) {
143127
144- if ( inputSource . hand [ i ] ) {
128+ // Update the joints groups with the XRJoint poses
129+ const jointPose = frame . getJointPose ( inputjoint , referenceSpace ) ;
145130
146- // Update the joints groups with the XRJoint poses
147- const jointPose = frame . getJointPose ( inputSource . hand [ i ] , referenceSpace ) ;
148- const joint = hand . joints [ i ] ;
131+ if ( hand . joints [ inputjoint . jointName ] === undefined ) {
149132
150- if ( jointPose !== null ) {
133+ // The transform of this joint will be updated with the joint pose on each frame
134+ const joint = new Group ( ) ;
135+ joint . matrixAutoUpdate = false ;
136+ joint . visible = false ;
137+ hand . joints [ inputjoint . jointName ] = joint ;
138+ // ??
139+ hand . add ( joint ) ;
151140
152- joint . matrix . fromArray ( jointPose . transform . matrix ) ;
153- joint . matrix . decompose ( joint . position , joint . rotation , joint . scale ) ;
154- joint . jointRadius = jointPose . radius ;
141+ }
142+
143+ const joint = hand . joints [ inputjoint . jointName ] ;
144+
145+ if ( jointPose !== null ) {
155146
156- }
147+ joint . matrix . fromArray ( jointPose . transform . matrix ) ;
148+ joint . matrix . decompose ( joint . position , joint . rotation , joint . scale ) ;
149+ joint . jointRadius = jointPose . radius ;
157150
158- joint . visible = jointPose !== null ;
151+ }
159152
160- // Custom events
153+ joint . visible = jointPose !== null ;
161154
162- // Check pinch
163- const indexTip = hand . joints [ window . XRHand . INDEX_PHALANX_TIP ] ;
164- const thumbTip = hand . joints [ window . XRHand . THUMB_PHALANX_TIP ] ;
165- const distance = indexTip . position . distanceTo ( thumbTip . position ) ;
155+ }
166156
167- const distanceToPinch = 0.02 ;
168- const threshold = 0.005 ;
157+ // Custom events
169158
170- if ( hand . inputState . pinching && distance > distanceToPinch + threshold ) {
159+ // Check pinchz
160+ const indexTip = hand . joints [ 'index-finger-tip' ] ;
161+ const thumbTip = hand . joints [ 'thumb-tip' ] ;
162+ const distance = indexTip . position . distanceTo ( thumbTip . position ) ;
171163
172- hand . inputState . pinching = false ;
173- this . dispatchEvent ( {
174- type : 'pinchend' ,
175- handedness : inputSource . handedness ,
176- target : this
177- } ) ;
164+ const distanceToPinch = 0.02 ;
165+ const threshold = 0.005 ;
178166
179- } else if ( ! hand . inputState . pinching && distance <= distanceToPinch - threshold ) {
167+ if ( hand . inputState . pinching && distance > distanceToPinch + threshold ) {
180168
181- hand . inputState . pinching = true ;
182- this . dispatchEvent ( {
183- type : 'pinchstart ' ,
184- handedness : inputSource . handedness ,
185- target : this
186- } ) ;
169+ hand . inputState . pinching = false ;
170+ this . dispatchEvent ( {
171+ type : 'pinchend ' ,
172+ handedness : inputSource . handedness ,
173+ target : this
174+ } ) ;
187175
188- }
176+ } else if ( ! hand . inputState . pinching && distance <= distanceToPinch - threshold ) {
189177
190- }
178+ hand . inputState . pinching = true ;
179+ this . dispatchEvent ( {
180+ type : 'pinchstart' ,
181+ handedness : inputSource . handedness ,
182+ target : this
183+ } ) ;
191184
192185 }
193186
0 commit comments