|
1058 | 1058 | return self; |
1059 | 1059 | } |
1060 | 1060 |
|
| 1061 | + function _unsupportedIterableToArray(o, minLen) { |
| 1062 | + if (!o) return; |
| 1063 | + if (typeof o === "string") return _arrayLikeToArray(o, minLen); |
| 1064 | + var n = Object.prototype.toString.call(o).slice(8, -1); |
| 1065 | + if (n === "Object" && o.constructor) n = o.constructor.name; |
| 1066 | + if (n === "Map" || n === "Set") return Array.from(o); |
| 1067 | + if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); |
| 1068 | + } |
| 1069 | + |
| 1070 | + function _arrayLikeToArray(arr, len) { |
| 1071 | + if (len == null || len > arr.length) len = arr.length; |
| 1072 | + |
| 1073 | + for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; |
| 1074 | + |
| 1075 | + return arr2; |
| 1076 | + } |
| 1077 | + |
| 1078 | + function _createForOfIteratorHelperLoose(o, allowArrayLike) { |
| 1079 | + var it; |
| 1080 | + |
| 1081 | + if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { |
| 1082 | + if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { |
| 1083 | + if (it) o = it; |
| 1084 | + var i = 0; |
| 1085 | + return function () { |
| 1086 | + if (i >= o.length) return { |
| 1087 | + done: true |
| 1088 | + }; |
| 1089 | + return { |
| 1090 | + done: false, |
| 1091 | + value: o[i++] |
| 1092 | + }; |
| 1093 | + }; |
| 1094 | + } |
| 1095 | + |
| 1096 | + throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); |
| 1097 | + } |
| 1098 | + |
| 1099 | + it = o[Symbol.iterator](); |
| 1100 | + return it.next.bind(it); |
| 1101 | + } |
| 1102 | + |
1061 | 1103 | /** |
1062 | 1104 | * https://github.com/mrdoob/eventdispatcher.js/ |
1063 | 1105 | */ |
@@ -17068,24 +17110,10 @@ |
17068 | 17110 | this._hand = new Group(); |
17069 | 17111 | this._hand.matrixAutoUpdate = false; |
17070 | 17112 | this._hand.visible = false; |
17071 | | - this._hand.joints = []; |
| 17113 | + this._hand.joints = {}; |
17072 | 17114 | this._hand.inputState = { |
17073 | 17115 | pinching: false |
17074 | 17116 | }; |
17075 | | - |
17076 | | - if (window.XRHand) { |
17077 | | - for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) { |
17078 | | - // The transform of this joint will be updated with the joint pose on each frame |
17079 | | - var joint = new Group(); |
17080 | | - joint.matrixAutoUpdate = false; |
17081 | | - joint.visible = false; |
17082 | | - |
17083 | | - this._hand.joints.push(joint); // ?? |
17084 | | - |
17085 | | - |
17086 | | - this._hand.add(joint); |
17087 | | - } |
17088 | | - } |
17089 | 17117 | } |
17090 | 17118 |
|
17091 | 17119 | return this._hand; |
@@ -17155,43 +17183,55 @@ |
17155 | 17183 | if (hand && inputSource.hand) { |
17156 | 17184 | handPose = true; |
17157 | 17185 |
|
17158 | | - for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) { |
17159 | | - if (inputSource.hand[i]) { |
17160 | | - // Update the joints groups with the XRJoint poses |
17161 | | - var jointPose = frame.getJointPose(inputSource.hand[i], referenceSpace); |
17162 | | - var joint = hand.joints[i]; |
| 17186 | + for (var _iterator = _createForOfIteratorHelperLoose(inputSource.hand.values()), _step; !(_step = _iterator()).done;) { |
| 17187 | + var inputjoint = _step.value; |
| 17188 | + // Update the joints groups with the XRJoint poses |
| 17189 | + var jointPose = frame.getJointPose(inputjoint, referenceSpace); |
17163 | 17190 |
|
17164 | | - if (jointPose !== null) { |
17165 | | - joint.matrix.fromArray(jointPose.transform.matrix); |
17166 | | - joint.matrix.decompose(joint.position, joint.rotation, joint.scale); |
17167 | | - joint.jointRadius = jointPose.radius; |
17168 | | - } |
| 17191 | + if (hand.joints[inputjoint.jointName] === undefined) { |
| 17192 | + // The transform of this joint will be updated with the joint pose on each frame |
| 17193 | + var _joint = new Group(); |
17169 | 17194 |
|
17170 | | - joint.visible = jointPose !== null; // Custom events |
17171 | | - // Check pinch |
17172 | | - |
17173 | | - var indexTip = hand.joints[window.XRHand.INDEX_PHALANX_TIP]; |
17174 | | - var thumbTip = hand.joints[window.XRHand.THUMB_PHALANX_TIP]; |
17175 | | - var distance = indexTip.position.distanceTo(thumbTip.position); |
17176 | | - var distanceToPinch = 0.02; |
17177 | | - var threshold = 0.005; |
17178 | | - |
17179 | | - if (hand.inputState.pinching && distance > distanceToPinch + threshold) { |
17180 | | - hand.inputState.pinching = false; |
17181 | | - this.dispatchEvent({ |
17182 | | - type: 'pinchend', |
17183 | | - handedness: inputSource.handedness, |
17184 | | - target: this |
17185 | | - }); |
17186 | | - } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) { |
17187 | | - hand.inputState.pinching = true; |
17188 | | - this.dispatchEvent({ |
17189 | | - type: 'pinchstart', |
17190 | | - handedness: inputSource.handedness, |
17191 | | - target: this |
17192 | | - }); |
17193 | | - } |
| 17195 | + _joint.matrixAutoUpdate = false; |
| 17196 | + _joint.visible = false; |
| 17197 | + hand.joints[inputjoint.jointName] = _joint; // ?? |
| 17198 | + |
| 17199 | + hand.add(_joint); |
17194 | 17200 | } |
| 17201 | + |
| 17202 | + var joint = hand.joints[inputjoint.jointName]; |
| 17203 | + |
| 17204 | + if (jointPose !== null) { |
| 17205 | + joint.matrix.fromArray(jointPose.transform.matrix); |
| 17206 | + joint.matrix.decompose(joint.position, joint.rotation, joint.scale); |
| 17207 | + joint.jointRadius = jointPose.radius; |
| 17208 | + } |
| 17209 | + |
| 17210 | + joint.visible = jointPose !== null; |
| 17211 | + } // Custom events |
| 17212 | + // Check pinchz |
| 17213 | + |
| 17214 | + |
| 17215 | + var indexTip = hand.joints['index-finger-tip']; |
| 17216 | + var thumbTip = hand.joints['thumb-tip']; |
| 17217 | + var distance = indexTip.position.distanceTo(thumbTip.position); |
| 17218 | + var distanceToPinch = 0.02; |
| 17219 | + var threshold = 0.005; |
| 17220 | + |
| 17221 | + if (hand.inputState.pinching && distance > distanceToPinch + threshold) { |
| 17222 | + hand.inputState.pinching = false; |
| 17223 | + this.dispatchEvent({ |
| 17224 | + type: 'pinchend', |
| 17225 | + handedness: inputSource.handedness, |
| 17226 | + target: this |
| 17227 | + }); |
| 17228 | + } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) { |
| 17229 | + hand.inputState.pinching = true; |
| 17230 | + this.dispatchEvent({ |
| 17231 | + type: 'pinchstart', |
| 17232 | + handedness: inputSource.handedness, |
| 17233 | + target: this |
| 17234 | + }); |
17195 | 17235 | } |
17196 | 17236 | } else { |
17197 | 17237 | if (targetRay !== null) { |
|
36824 | 36864 |
|
36825 | 36865 | } |
36826 | 36866 |
|
36827 | | - if (window) { |
| 36867 | + if (typeof window !== 'undefined') { |
36828 | 36868 | if (window.__THREE__) { |
36829 | 36869 | console.warn('WARNING: Multiple instances of Three.js being imported.'); |
36830 | 36870 | } else { |
|
0 commit comments