brilliantsole 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +21 -0
- package/build/brilliantsole.cjs +5957 -0
- package/build/brilliantsole.cjs.map +1 -0
- package/build/brilliantsole.js +5448 -0
- package/build/brilliantsole.js.map +1 -0
- package/build/brilliantsole.ls.js +4872 -0
- package/build/brilliantsole.ls.js.map +1 -0
- package/build/brilliantsole.min.js +6 -0
- package/build/brilliantsole.min.js.map +1 -0
- package/build/brilliantsole.module.d.ts +908 -0
- package/build/brilliantsole.module.js +5412 -0
- package/build/brilliantsole.module.js.map +1 -0
- package/build/brilliantsole.module.min.d.ts +908 -0
- package/build/brilliantsole.module.min.js +6 -0
- package/build/brilliantsole.module.min.js.map +1 -0
- package/build/brilliantsole.node.module.d.ts +908 -0
- package/build/brilliantsole.node.module.js +5906 -0
- package/build/brilliantsole.node.module.js.map +1 -0
- package/build/dts/BS.d.ts +25 -0
- package/build/dts/Device.d.ts +136 -0
- package/build/dts/DeviceInformationManager.d.ts +56 -0
- package/build/dts/DeviceManager.d.ts +67 -0
- package/build/dts/FileTransferManager.d.ts +84 -0
- package/build/dts/FirmwareManager.d.ts +71 -0
- package/build/dts/InformationManager.d.ts +66 -0
- package/build/dts/TfliteManager.d.ts +92 -0
- package/build/dts/connection/BaseConnectionManager.d.ts +59 -0
- package/build/dts/connection/ClientConnectionManager.d.ts +23 -0
- package/build/dts/connection/WebSocketClientConnectionManager.d.ts +23 -0
- package/build/dts/connection/bluetooth/BluetoothConnectionManager.d.ts +10 -0
- package/build/dts/connection/bluetooth/NobleConnectionManager.d.ts +42 -0
- package/build/dts/connection/bluetooth/WebBluetoothConnectionManager.d.ts +20 -0
- package/build/dts/connection/bluetooth/bluetoothUUIDs.d.ts +14 -0
- package/build/dts/connection/webSocket/ClientConnectionManager.d.ts +23 -0
- package/build/dts/connection/webSocket/WebSocketClientConnectionManager.d.ts +23 -0
- package/build/dts/devicePair/DevicePair.d.ts +60 -0
- package/build/dts/devicePair/DevicePairPressureSensorDataManager.d.ts +25 -0
- package/build/dts/devicePair/DevicePairSensorDataManager.d.ts +33 -0
- package/build/dts/scanner/BaseScanner.d.ts +66 -0
- package/build/dts/scanner/NobleScanner.d.ts +17 -0
- package/build/dts/scanner/Scanner.d.ts +3 -0
- package/build/dts/sensor/BarometerSensorDataManager.d.ts +16 -0
- package/build/dts/sensor/MotionSensorDataManager.d.ts +69 -0
- package/build/dts/sensor/PressureSensorDataManager.d.ts +36 -0
- package/build/dts/sensor/SensorConfigurationManager.d.ts +44 -0
- package/build/dts/sensor/SensorDataManager.d.ts +40 -0
- package/build/dts/server/BaseClient.d.ts +85 -0
- package/build/dts/server/BaseServer.d.ts +48 -0
- package/build/dts/server/ServerUtils.d.ts +23 -0
- package/build/dts/server/udp/UDPServer.d.ts +11 -0
- package/build/dts/server/udp/UDPUtils.d.ts +9 -0
- package/build/dts/server/websocket/WebSocketClient.d.ts +17 -0
- package/build/dts/server/websocket/WebSocketServer.d.ts +13 -0
- package/build/dts/server/websocket/WebSocketUtils.d.ts +9 -0
- package/build/dts/utils/ArrayBufferUtils.d.ts +7 -0
- package/build/dts/utils/ArrayUtils.d.ts +2 -0
- package/build/dts/utils/CenterOfPressureHelper.d.ts +15 -0
- package/build/dts/utils/Console.d.ts +34 -0
- package/build/dts/utils/EventDispatcher.d.ts +50 -0
- package/build/dts/utils/EventUtils.d.ts +6 -0
- package/build/dts/utils/MathUtils.d.ts +21 -0
- package/build/dts/utils/ParseUtils.d.ts +5 -0
- package/build/dts/utils/RangeHelper.d.ts +8 -0
- package/build/dts/utils/Text.d.ts +6 -0
- package/build/dts/utils/Timer.d.ts +14 -0
- package/build/dts/utils/TypeScriptUtils.d.ts +19 -0
- package/build/dts/utils/cbor.d.ts +6 -0
- package/build/dts/utils/checksum.d.ts +3 -0
- package/build/dts/utils/environment.d.ts +13 -0
- package/build/dts/utils/mcumgr.d.ts +88 -0
- package/build/dts/utils/stringUtils.d.ts +2 -0
- package/build/dts/vibration/VibrationManager.d.ts +45 -0
- package/build/dts/vibration/VibrationWaveformEffects.d.ts +2 -0
- package/build/index.d.ts +908 -0
- package/build/index.node.d.ts +908 -0
- package/examples/3d/index.html +109 -0
- package/examples/3d/scene.html +57 -0
- package/examples/3d/script.js +419 -0
- package/examples/balance/index.html +138 -0
- package/examples/balance/script.js +243 -0
- package/examples/basic/index.html +327 -0
- package/examples/basic/script.js +1093 -0
- package/examples/center-of-pressure/index.html +132 -0
- package/examples/center-of-pressure/script.js +207 -0
- package/examples/device-pair/index.html +72 -0
- package/examples/device-pair/script.js +187 -0
- package/examples/edge-impulse/index.html +94 -0
- package/examples/edge-impulse/script.js +1033 -0
- package/examples/graph/index.html +83 -0
- package/examples/graph/script.js +469 -0
- package/examples/machine-learning/index.html +366 -0
- package/examples/machine-learning/script.js +1774 -0
- package/examples/pressure/index.html +145 -0
- package/examples/pressure/script.js +201 -0
- package/examples/recording/index.html +187 -0
- package/examples/recording/script.js +736 -0
- package/examples/server/index.html +266 -0
- package/examples/server/script.js +925 -0
- package/examples/utils/aframe/fingertip-button-component.js +201 -0
- package/examples/utils/aframe/fingertip-collider-target-component.js +102 -0
- package/examples/utils/aframe/fingertip-colliders-component.js +147 -0
- package/examples/utils/three/three.module.min.js +24846 -0
- package/examples/webxr/index.html +221 -0
- package/examples/webxr/script.js +1127 -0
- package/package.json +83 -0
- package/src/BS.ts +68 -0
- package/src/Device.ts +734 -0
- package/src/DeviceInformationManager.ts +146 -0
- package/src/DeviceManager.ts +354 -0
- package/src/FileTransferManager.ts +452 -0
- package/src/FirmwareManager.ts +357 -0
- package/src/InformationManager.ts +283 -0
- package/src/TfliteManager.ts +450 -0
- package/src/connection/BaseConnectionManager.ts +255 -0
- package/src/connection/ClientConnectionManager.ts +120 -0
- package/src/connection/bluetooth/BluetoothConnectionManager.ts +34 -0
- package/src/connection/bluetooth/NobleConnectionManager.ts +302 -0
- package/src/connection/bluetooth/WebBluetoothConnectionManager.ts +269 -0
- package/src/connection/bluetooth/bluetoothUUIDs.ts +218 -0
- package/src/devicePair/DevicePair.ts +253 -0
- package/src/devicePair/DevicePairPressureSensorDataManager.ts +82 -0
- package/src/devicePair/DevicePairSensorDataManager.ts +90 -0
- package/src/scanner/BaseScanner.ts +189 -0
- package/src/scanner/NobleScanner.ts +195 -0
- package/src/scanner/Scanner.ts +16 -0
- package/src/sensor/BarometerSensorDataManager.ts +41 -0
- package/src/sensor/MotionSensorDataManager.ts +151 -0
- package/src/sensor/PressureSensorDataManager.ts +112 -0
- package/src/sensor/SensorConfigurationManager.ts +177 -0
- package/src/sensor/SensorDataManager.ts +166 -0
- package/src/server/BaseClient.ts +368 -0
- package/src/server/BaseServer.ts +344 -0
- package/src/server/ServerUtils.ts +93 -0
- package/src/server/udp/UDPServer.ts +229 -0
- package/src/server/udp/UDPUtils.ts +20 -0
- package/src/server/websocket/WebSocketClient.ts +179 -0
- package/src/server/websocket/WebSocketServer.ts +184 -0
- package/src/server/websocket/WebSocketUtils.ts +20 -0
- package/src/utils/ArrayBufferUtils.ts +88 -0
- package/src/utils/ArrayUtils.ts +15 -0
- package/src/utils/CenterOfPressureHelper.ts +39 -0
- package/src/utils/Console.ts +156 -0
- package/src/utils/EventDispatcher.ts +153 -0
- package/src/utils/EventUtils.ts +41 -0
- package/src/utils/MathUtils.ts +53 -0
- package/src/utils/ParseUtils.ts +46 -0
- package/src/utils/RangeHelper.ts +38 -0
- package/src/utils/Text.ts +30 -0
- package/src/utils/Timer.ts +72 -0
- package/src/utils/TypeScriptUtils.ts +22 -0
- package/src/utils/cbor.js +429 -0
- package/src/utils/checksum.ts +41 -0
- package/src/utils/environment.ts +46 -0
- package/src/utils/mcumgr.js +444 -0
- package/src/utils/stringUtils.ts +11 -0
- package/src/vibration/VibrationManager.ts +308 -0
- package/src/vibration/VibrationWaveformEffects.ts +128 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
AFRAME.registerComponent("fingertip-button", {
|
|
2
|
+
schema: {
|
|
3
|
+
hands: { default: ["left", "right"] },
|
|
4
|
+
fingers: { default: ["index"] },
|
|
5
|
+
|
|
6
|
+
color: { type: "color", default: "white" },
|
|
7
|
+
|
|
8
|
+
text: { type: "string", default: "hello world!" },
|
|
9
|
+
textColor: { type: "color", default: "black" },
|
|
10
|
+
subtitle: { type: "string", default: "" },
|
|
11
|
+
|
|
12
|
+
disabled: { default: false },
|
|
13
|
+
disabledColor: { type: "color", default: "grey" },
|
|
14
|
+
|
|
15
|
+
scale: { default: 0.15 },
|
|
16
|
+
rotation: { type: "vec3" },
|
|
17
|
+
|
|
18
|
+
height: { type: "number", default: 0.2 },
|
|
19
|
+
width: { type: "number", default: 1.4 },
|
|
20
|
+
depth: { type: "number", default: 0.3 },
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
init: function () {
|
|
24
|
+
this.box3 = new THREE.Box3();
|
|
25
|
+
this.matrix4 = new THREE.Matrix4();
|
|
26
|
+
|
|
27
|
+
this.container = document.createElement("a-entity");
|
|
28
|
+
this.el.appendChild(this.container);
|
|
29
|
+
|
|
30
|
+
this.box = document.createElement("a-box");
|
|
31
|
+
this.container.appendChild(this.box);
|
|
32
|
+
|
|
33
|
+
// causes an error if the box with text nodes is used for obb-collider
|
|
34
|
+
this.colliderBox = document.createElement("a-box");
|
|
35
|
+
//this.colliderBox.setAttribute("obb-collider", "");
|
|
36
|
+
this.colliderBox.hideCollider = () => this.colliderBox?.components?.["obb-collider"]?.hideCollider?.();
|
|
37
|
+
this.colliderBox.setAttribute("material", "opacity: 0;");
|
|
38
|
+
this.container.appendChild(this.colliderBox);
|
|
39
|
+
|
|
40
|
+
this.text = document.createElement("a-text");
|
|
41
|
+
this.text.setAttribute("rotation", "-90 0 0");
|
|
42
|
+
this.text.setAttribute("align", "center");
|
|
43
|
+
this.text.setAttribute("width", "5");
|
|
44
|
+
this.box.appendChild(this.text);
|
|
45
|
+
|
|
46
|
+
this.subtitle = document.createElement("a-text");
|
|
47
|
+
this.subtitle.setAttribute("align", "center");
|
|
48
|
+
this.subtitle.setAttribute("scale", "0.7 0.7 0.7");
|
|
49
|
+
this.subtitle.setAttribute("baseline", "bottom");
|
|
50
|
+
this.box.appendChild(this.subtitle);
|
|
51
|
+
|
|
52
|
+
this.el.setAttribute("fingertip-collider-target", {
|
|
53
|
+
hands: this.data.hands,
|
|
54
|
+
fingers: this.data.fingers,
|
|
55
|
+
maxTouches: 1,
|
|
56
|
+
disabled: this.data.disabled,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
this.el.addEventListener("touchstarted", () => {
|
|
60
|
+
this.el.dispatchEvent(new Event("click"));
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
calculateTextSize: function (textEntity) {
|
|
65
|
+
const mesh = textEntity.components?.text?.mesh;
|
|
66
|
+
if (!mesh) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const box3 = this.box3;
|
|
70
|
+
box3.setFromObject(mesh);
|
|
71
|
+
this.matrix4.makeRotationFromQuaternion(this.box.object3D.quaternion);
|
|
72
|
+
this.matrix4.invert();
|
|
73
|
+
box3.applyMatrix4(this.matrix4);
|
|
74
|
+
|
|
75
|
+
let width = box3.max.x - box3.min.x;
|
|
76
|
+
width *= 8;
|
|
77
|
+
|
|
78
|
+
let height = box3.max.z - box3.min.z;
|
|
79
|
+
height *= 8;
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
width,
|
|
83
|
+
height,
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
update: function (oldData) {
|
|
88
|
+
const diff = AFRAME.utils.diff(oldData, this.data);
|
|
89
|
+
|
|
90
|
+
const diffKeys = Object.keys(diff);
|
|
91
|
+
|
|
92
|
+
//console.log({ diffKeys });
|
|
93
|
+
|
|
94
|
+
diffKeys.forEach((diffKey) => {
|
|
95
|
+
switch (diffKey) {
|
|
96
|
+
case "text":
|
|
97
|
+
this.text.setAttribute("value", this.data.text);
|
|
98
|
+
let text = this.data.text;
|
|
99
|
+
let timeoutId = setInterval(() => {
|
|
100
|
+
if (this.data.text != text) {
|
|
101
|
+
clearInterval(timeoutId);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const textSize = this.calculateTextSize(this.text);
|
|
106
|
+
if (textSize) {
|
|
107
|
+
const { width, height } = textSize;
|
|
108
|
+
clearInterval(timeoutId);
|
|
109
|
+
this.el.setAttribute("fingertip-button", "width", width);
|
|
110
|
+
this.el.setAttribute("fingertip-button", "depth", height);
|
|
111
|
+
this.updateCollider();
|
|
112
|
+
}
|
|
113
|
+
}, 10);
|
|
114
|
+
break;
|
|
115
|
+
case "subtitle":
|
|
116
|
+
this.subtitle.setAttribute("value", this.data.subtitle);
|
|
117
|
+
break;
|
|
118
|
+
case "textColor":
|
|
119
|
+
this.text.setAttribute("color", this.data.textColor);
|
|
120
|
+
this.subtitle.setAttribute("color", this.data.textColor);
|
|
121
|
+
break;
|
|
122
|
+
case "color":
|
|
123
|
+
if (this.data.disabled) {
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
this.box.setAttribute("color", this.data.color);
|
|
127
|
+
break;
|
|
128
|
+
case "disabledColor":
|
|
129
|
+
if (!this.data.disabled) {
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
this.box.setAttribute("color", this.data.disabledColor);
|
|
133
|
+
break;
|
|
134
|
+
case "disabled":
|
|
135
|
+
if (this.data.disabled) {
|
|
136
|
+
this.colliderBox.removeAttribute("obb-collider");
|
|
137
|
+
this.box.classList.remove("clickable");
|
|
138
|
+
} else {
|
|
139
|
+
this.colliderBox.setAttribute("obb-collider", "");
|
|
140
|
+
this.box.classList.add("clickable");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
this.el.setAttribute("fingertip-collider-target", { disabled: this.data.disabled });
|
|
144
|
+
this.box.setAttribute("color", this.data.disabled ? this.data.disabledColor : this.data.color);
|
|
145
|
+
break;
|
|
146
|
+
case "width":
|
|
147
|
+
this.box.setAttribute("width", this.data.width);
|
|
148
|
+
this.colliderBox.setAttribute("width", this.data.width);
|
|
149
|
+
this.updateCollider();
|
|
150
|
+
break;
|
|
151
|
+
case "depth":
|
|
152
|
+
this.box.setAttribute("depth", this.data.depth);
|
|
153
|
+
this.colliderBox.setAttribute("depth", this.data.depth);
|
|
154
|
+
this.updateCollider();
|
|
155
|
+
break;
|
|
156
|
+
case "height":
|
|
157
|
+
this.box.setAttribute("height", this.data.height);
|
|
158
|
+
this.colliderBox.setAttribute("height", this.data.height);
|
|
159
|
+
|
|
160
|
+
this.box.setAttribute("position", `0 ${(this.data.height * this.data.scale) / 2} 0`);
|
|
161
|
+
this.colliderBox.setAttribute("position", `0 ${(this.data.height * this.data.scale) / 2} 0`);
|
|
162
|
+
|
|
163
|
+
this.text.setAttribute("position", `0 ${this.data.height / 2} 0`);
|
|
164
|
+
this.subtitle.setAttribute("position", `0 ${-this.data.height / 2} ${this.data.depth / 2}`);
|
|
165
|
+
|
|
166
|
+
this.updateCollider();
|
|
167
|
+
break;
|
|
168
|
+
case "scale":
|
|
169
|
+
{
|
|
170
|
+
const scaleString = new Array(3).fill(this.data.scale).join(" ");
|
|
171
|
+
this.box.setAttribute("scale", scaleString);
|
|
172
|
+
this.colliderBox.setAttribute("scale", scaleString);
|
|
173
|
+
this.updateCollider();
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
case "rotation":
|
|
177
|
+
{
|
|
178
|
+
const rotationString = AFRAME.utils.coordinates.stringify(this.data.rotation);
|
|
179
|
+
this.box.setAttribute("rotation", rotationString);
|
|
180
|
+
this.colliderBox.setAttribute("rotation", rotationString);
|
|
181
|
+
this.updateCollider();
|
|
182
|
+
}
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
updateCollider: function () {
|
|
189
|
+
if (this.data.disabled) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
setTimeout(() => {
|
|
193
|
+
this.colliderBox.components["obb-collider"]?.updateCollider();
|
|
194
|
+
}, 0);
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
remove: function () {
|
|
198
|
+
this.el.removeAttribute("fingertip-collider-target");
|
|
199
|
+
this.box.remove();
|
|
200
|
+
},
|
|
201
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
AFRAME.registerComponent("fingertip-collider-target", {
|
|
2
|
+
schema: {
|
|
3
|
+
hands: { default: ["left", "right"] },
|
|
4
|
+
fingers: { default: ["index"] },
|
|
5
|
+
maxTouches: { default: 1 },
|
|
6
|
+
disabled: { default: false },
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
init: function () {
|
|
10
|
+
this.touches = []; // [...{hand, finger}]
|
|
11
|
+
|
|
12
|
+
this.checkTouches = AFRAME.utils.throttle(this.checkTouches, 20, this);
|
|
13
|
+
this.onFingertipTouchStarted = AFRAME.utils.throttle(this.onFingertipTouchStarted, 300, this);
|
|
14
|
+
|
|
15
|
+
this.boundOnFingertipTouch = this.onFingertipTouch.bind(this);
|
|
16
|
+
this.el.addEventListener("fingertiptouchstarted", this.boundOnFingertipTouch);
|
|
17
|
+
this.el.addEventListener("fingertiptouchended", this.boundOnFingertipTouch);
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
onFingertipTouch: function (event) {
|
|
21
|
+
if (this.data.disabled) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//console.log(event);
|
|
26
|
+
const isTouchStart = event.type == "fingertiptouchstarted";
|
|
27
|
+
const { target } = event;
|
|
28
|
+
const { hand, finger, getJointAPI } = event.detail;
|
|
29
|
+
|
|
30
|
+
const touch = { hand, finger, getJointAPI, target };
|
|
31
|
+
//console.log(touch);
|
|
32
|
+
|
|
33
|
+
if (!this.data.hands.includes(hand)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!this.data.fingers.includes(finger)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (isTouchStart) {
|
|
41
|
+
this.onFingertipTouchStarted(touch);
|
|
42
|
+
} else {
|
|
43
|
+
this.onFingertipTouchEnded(touch);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
event.stopPropagation();
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
getExistingTouch: function (touch) {
|
|
50
|
+
return this.touches.find(({ hand, finger }) => touch.hand == hand && touch.finger == finger);
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
onFingertipTouchStarted: function (touch) {
|
|
54
|
+
const existingTouch = this.getExistingTouch(touch);
|
|
55
|
+
if (existingTouch) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (this.touches.length >= this.data.maxTouches) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.touches.push(Object.assign({}, touch));
|
|
62
|
+
this.el.emit("touchstarted", touch);
|
|
63
|
+
},
|
|
64
|
+
onFingertipTouchEnded: function (touch) {
|
|
65
|
+
const existingTouch = this.getExistingTouch(touch);
|
|
66
|
+
if (!existingTouch) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.touches.splice(this.touches.indexOf(existingTouch), 1);
|
|
70
|
+
this.el.emit("touchended", existingTouch);
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
tick: function (time, timeDelta) {
|
|
74
|
+
this.checkTouches(time, timeDelta);
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
checkTouches: function (time, timeDelta) {
|
|
78
|
+
this.touches.forEach((touch) => {
|
|
79
|
+
const { hand, finger, getJointAPI, target } = touch;
|
|
80
|
+
const position = getJointAPI().getPosition();
|
|
81
|
+
// FILL - get normalized position within collider
|
|
82
|
+
//console.log(position);
|
|
83
|
+
this.el.emit("touchmoved", { hand, finger, position, target });
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
update: function (oldData) {
|
|
88
|
+
const diff = AFRAME.utils.diff(oldData, this.data);
|
|
89
|
+
|
|
90
|
+
const diffKeys = Object.keys(diff);
|
|
91
|
+
|
|
92
|
+
diffKeys.forEach((diffKey) => {
|
|
93
|
+
switch (diffKey) {
|
|
94
|
+
case "disabled":
|
|
95
|
+
if (this.data.disabled) {
|
|
96
|
+
this.touches.forEach((touch) => this.onFingertipTouchEnded(touch));
|
|
97
|
+
}
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
});
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// requires hand-tracking-controls-extras (https://github.com/gftruj/aframe-hand-tracking-controls-extras)
|
|
2
|
+
|
|
3
|
+
AFRAME.registerComponent("fingertip-colliders", {
|
|
4
|
+
schema: {
|
|
5
|
+
fingers: { default: ["index"] }, // ["thumb", "index", "middle", "ring", "little"]
|
|
6
|
+
},
|
|
7
|
+
|
|
8
|
+
init: function () {
|
|
9
|
+
console.log(this);
|
|
10
|
+
|
|
11
|
+
if (!this.el.hasAttribute("hand-tracking-extras")) {
|
|
12
|
+
this.el.setAttribute("hand-tracking-extras", "");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
this.isHandVisible = false;
|
|
16
|
+
|
|
17
|
+
this.isInVR = false;
|
|
18
|
+
this.el.sceneEl.addEventListener("enter-vr", () => {
|
|
19
|
+
this.isInVR = true;
|
|
20
|
+
});
|
|
21
|
+
this.el.sceneEl.addEventListener("exit-vr", () => {
|
|
22
|
+
this.isInVR = false;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
this.hand = this.el.components["hand-tracking-controls"].data.hand;
|
|
26
|
+
|
|
27
|
+
/** @type {Object.<string, HTMLElement>} */
|
|
28
|
+
this.fingertipEntities = {};
|
|
29
|
+
|
|
30
|
+
this.boundOnOBBCollision = this.onOBBCollision.bind(this);
|
|
31
|
+
this.obbColliderAttributeValue = "size: 0.015 0.015 0.015;";
|
|
32
|
+
|
|
33
|
+
const onHandTrackingExtrasReady = () => {
|
|
34
|
+
console.log("jointsAPI", this.hand, this.jointsAPI);
|
|
35
|
+
const clearHand = () => {
|
|
36
|
+
const material = this.el.components["hand-tracking-controls"]?.skinnedMesh?.material;
|
|
37
|
+
if (material) {
|
|
38
|
+
console.log(material);
|
|
39
|
+
material.colorWrite = false;
|
|
40
|
+
clearInterval(intervalId);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
let intervalId = setInterval(() => {
|
|
44
|
+
clearHand();
|
|
45
|
+
}, 1000);
|
|
46
|
+
|
|
47
|
+
this.data.fingers.forEach((finger) => {
|
|
48
|
+
const capitalizedfinger = this.capitalizeFirstLetter(finger);
|
|
49
|
+
|
|
50
|
+
const fingertipEntity = document.createElement("a-entity");
|
|
51
|
+
|
|
52
|
+
fingertipEntity.dataset.finger = finger;
|
|
53
|
+
fingertipEntity.dataset.hand = this.hand;
|
|
54
|
+
|
|
55
|
+
fingertipEntity.getJointAPI = () => this.jointsAPI[`get${capitalizedfinger}Tip`]();
|
|
56
|
+
//fingertipEntity.setAttribute("obb-collider", this.obbColliderAttributeValue);
|
|
57
|
+
|
|
58
|
+
fingertipEntity.addEventListener("obbcollisionstarted", this.boundOnOBBCollision);
|
|
59
|
+
fingertipEntity.addEventListener("obbcollisionended", this.boundOnOBBCollision);
|
|
60
|
+
|
|
61
|
+
this.fingertipEntities[finger] = fingertipEntity;
|
|
62
|
+
this.el.sceneEl.appendChild(fingertipEntity);
|
|
63
|
+
});
|
|
64
|
+
clearHand();
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
this.jointsAPI = this.el?.components?.["hand-tracking-extras"]?.HandData?.jointAPI;
|
|
68
|
+
if (this.jointsAPI) {
|
|
69
|
+
onHandTrackingExtrasReady();
|
|
70
|
+
} else {
|
|
71
|
+
this.el.addEventListener(
|
|
72
|
+
"hand-tracking-extras-ready",
|
|
73
|
+
(event) => {
|
|
74
|
+
this.jointsAPI = event.detail.data.jointAPI;
|
|
75
|
+
onHandTrackingExtrasReady();
|
|
76
|
+
},
|
|
77
|
+
{ once: true }
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
this.updateFingertipEntities = AFRAME.utils.throttle(this.updateFingertipEntities, 20, this);
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
onOBBCollision: function (event) {
|
|
85
|
+
//console.log(event);
|
|
86
|
+
const isCollisionStart = event.type == "obbcollisionstarted";
|
|
87
|
+
const fingerTipEntity = event.target;
|
|
88
|
+
const finger = fingerTipEntity.dataset.finger;
|
|
89
|
+
const withEl = event.detail.withEl;
|
|
90
|
+
const withFinger = withEl.dataset.finger;
|
|
91
|
+
const onSameHand = withFinger && withEl.dataset.hand == this.hand;
|
|
92
|
+
|
|
93
|
+
//console.log({ finger, withEl, withFinger, onSameHand });
|
|
94
|
+
|
|
95
|
+
const eventType = `fingertiptouch${isCollisionStart ? "started" : "ended"}`;
|
|
96
|
+
this.el.emit(eventType, { finger, withEl, withFinger, onSameHand });
|
|
97
|
+
if (!withFinger) {
|
|
98
|
+
const { getJointAPI } = fingerTipEntity;
|
|
99
|
+
withEl.emit(eventType, { finger, hand: this.hand, getJointAPI });
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
/** @param {string} string */
|
|
104
|
+
capitalizeFirstLetter: function (string) {
|
|
105
|
+
return string[0].toUpperCase() + string.slice(1);
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
tick: function (time, timeDelta) {
|
|
109
|
+
if (!this.isInVR) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
this.updateFingertipEntities(time, timeDelta);
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
checkIfHandIsVisible: function () {
|
|
116
|
+
const isHandVisible = this.getIsHandVisible();
|
|
117
|
+
if (this.isHandVisible != isHandVisible) {
|
|
118
|
+
this.isHandVisible = isHandVisible;
|
|
119
|
+
Object.entries(this.fingertipEntities).forEach(([finger, fingertipEntity]) => {
|
|
120
|
+
if (this.isHandVisible) {
|
|
121
|
+
fingertipEntity.setAttribute("obb-collider", this.obbColliderAttributeValue);
|
|
122
|
+
} else {
|
|
123
|
+
//fingertipEntity.removeAttribute("obb-collider");
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
getIsHandVisible: function () {
|
|
129
|
+
return this.el.components["hand-tracking-controls"]?.mesh?.visible;
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
updateFingertipEntities: function (time, timeDelta) {
|
|
133
|
+
if (!this.jointsAPI) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
this.checkIfHandIsVisible();
|
|
137
|
+
if (!this.isHandVisible) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
Object.entries(this.fingertipEntities).forEach(([finger, fingertipEntity]) => {
|
|
142
|
+
const jointAPI = fingertipEntity.getJointAPI();
|
|
143
|
+
const fingertipPosition = jointAPI.getPosition();
|
|
144
|
+
fingertipEntity.object3D.position.copy(fingertipPosition);
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
});
|