brilliantsole 0.0.27 → 0.0.28
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/assets/3d/anchor.glb +0 -0
- package/assets/3d/coin.glb +0 -0
- package/assets/3d/glasses.glb +0 -0
- package/assets/audio/bounceMedium.wav +0 -0
- package/assets/audio/bounceStrong.wav +0 -0
- package/assets/audio/bounceWeak.wav +0 -0
- package/assets/audio/coin.wav +0 -0
- package/assets/audio/getUp.wav +0 -0
- package/assets/audio/grab.wav +0 -0
- package/assets/audio/kick.wav +0 -0
- package/assets/audio/platterFadeIn old.wav +0 -0
- package/assets/audio/platterFadeIn.wav +0 -0
- package/assets/audio/platterFadeOut.wav +0 -0
- package/assets/audio/punch.wav +0 -0
- package/assets/audio/punchSqueak.wav +0 -0
- package/assets/audio/purr.wav +0 -0
- package/assets/audio/purrFadeOut.wav +0 -0
- package/assets/audio/release.wav +0 -0
- package/assets/audio/splat.wav +0 -0
- package/assets/audio/stomp.wav +0 -0
- package/build/brilliantsole.cjs +2627 -775
- package/build/brilliantsole.cjs.map +1 -1
- package/build/brilliantsole.js +2273 -721
- package/build/brilliantsole.js.map +1 -1
- package/build/brilliantsole.ls.js +2096 -535
- package/build/brilliantsole.ls.js.map +1 -1
- package/build/brilliantsole.min.js +1 -1
- package/build/brilliantsole.min.js.map +1 -1
- package/build/brilliantsole.module.d.ts +235 -65
- package/build/brilliantsole.module.js +2266 -722
- package/build/brilliantsole.module.js.map +1 -1
- package/build/brilliantsole.module.min.d.ts +235 -65
- package/build/brilliantsole.module.min.js +1 -1
- package/build/brilliantsole.module.min.js.map +1 -1
- package/build/brilliantsole.node.module.d.ts +229 -62
- package/build/brilliantsole.node.module.js +2619 -776
- package/build/brilliantsole.node.module.js.map +1 -1
- package/build/dts/BS-output.d.ts +10 -0
- package/build/dts/BS.d.ts +20 -8
- package/build/dts/CameraManager.d.ts +72 -0
- package/build/dts/Device.d.ts +46 -13
- package/build/dts/DeviceInformationManager.d.ts +4 -4
- package/build/dts/DeviceManager.d.ts +2 -0
- package/build/dts/FileTransferManager.d.ts +18 -8
- package/build/dts/InformationManager.d.ts +2 -0
- package/build/dts/TfliteManager.d.ts +22 -2
- package/build/dts/WifiManager.d.ts +61 -0
- package/build/dts/connection/BaseConnectionManager.d.ts +35 -3
- package/build/dts/connection/ClientConnectionManager.d.ts +7 -2
- package/build/dts/connection/bluetooth/NobleConnectionManager.d.ts +2 -1
- package/build/dts/connection/bluetooth/WebBluetoothConnectionManager.d.ts +1 -0
- package/build/dts/connection/bluetooth/bluetoothUUIDs.d.ts +2 -2
- package/build/dts/connection/udp/UDPConnectionManager.d.ts +28 -0
- package/build/dts/connection/webSocket/WebSocketConnectionManager.d.ts +25 -0
- package/build/dts/devicePair/DevicePair.d.ts +5 -5
- package/build/dts/scanner/BaseScanner.d.ts +4 -1
- package/build/dts/scanner/NobleScanner.d.ts +2 -1
- package/build/dts/sensor/MotionSensorDataManager.d.ts +5 -2
- package/build/dts/sensor/SensorDataManager.d.ts +5 -4
- package/build/dts/server/BaseClient.d.ts +5 -3
- package/build/dts/server/ServerUtils.d.ts +1 -1
- package/build/dts/server/websocket/WebSocketUtils.d.ts +1 -1
- package/build/dts/utils/Console.d.ts +2 -0
- package/build/dts/utils/ThrottleUtils.d.ts +2 -0
- package/build/dts/vibration/VibrationManager.d.ts +19 -2
- package/build/index.d.ts +232 -62
- package/build/index.node.d.ts +226 -59
- package/examples/3d/scene.html +19 -5
- package/examples/3d-generic/index.html +144 -0
- package/examples/3d-generic/script.js +266 -0
- package/examples/basic/index.html +211 -16
- package/examples/basic/script.js +731 -105
- package/examples/edge-impulse/script.js +135 -44
- package/examples/edge-impulse-test/README.md +11 -0
- package/examples/edge-impulse-test/edge-impulse-standalone.js +7228 -0
- package/examples/edge-impulse-test/edge-impulse-standalone.wasm +0 -0
- package/examples/edge-impulse-test/index.html +75 -0
- package/examples/edge-impulse-test/run-impulse.js +135 -0
- package/examples/edge-impulse-test/script.js +200 -0
- package/examples/gloves/edge-impulse-standalone.js +7228 -0
- package/examples/gloves/edge-impulse-standalone.wasm +0 -0
- package/examples/gloves/index.html +4 -1
- package/examples/gloves/run-impulse.js +135 -0
- package/examples/gloves/script.js +367 -51
- package/examples/graph/script.js +94 -37
- package/examples/punch/index.html +135 -0
- package/examples/punch/punch.tflite +0 -0
- package/examples/punch/script.js +169 -0
- package/examples/server/index.html +98 -22
- package/examples/server/script.js +317 -109
- package/examples/ukaton-firmware-update/merged-firmware.bin +0 -0
- package/examples/utils/aframe/aframe-master.min.js +2 -0
- package/examples/utils/aframe/bs-vibration.js +150 -0
- package/examples/utils/aframe/force-pushable.js +80 -0
- package/examples/utils/aframe/grabbable-anchor.js +46 -0
- package/examples/utils/aframe/grabbable-listener.js +31 -0
- package/examples/utils/aframe/grabbable-physics-body.js +190 -0
- package/examples/utils/aframe/grow-shrink.js +25 -0
- package/examples/utils/aframe/hand-punch.js +119 -0
- package/examples/utils/aframe/my-obb-collider.js +293 -0
- package/examples/utils/aframe/occlude-hand-tracking-controls.js +47 -0
- package/examples/utils/aframe/occlude-mesh.js +42 -0
- package/examples/utils/aframe/palm-up-detector.js +47 -0
- package/examples/utils/aframe/shadow-material.js +20 -0
- package/examples/utils/aframe/soft-shadow-light.js +9 -0
- package/examples/webxr-2/assets/3d/soccerBall.glb +0 -0
- package/examples/webxr-2/assets/audio/shellBounce.wav +0 -0
- package/examples/webxr-2/assets/audio/shellHit.wav +0 -0
- package/examples/webxr-2/assets/audio/shellKick.wav +0 -0
- package/examples/webxr-2/assets/audio/soccerBounce.wav +0 -0
- package/examples/webxr-2/assets/audio/soccerKick.mp3 +0 -0
- package/examples/webxr-2/assets/images/shellTexture.png +0 -0
- package/examples/webxr-2/components/bs-ankle.js +337 -0
- package/examples/webxr-2/components/coin.js +84 -0
- package/examples/webxr-2/components/custom-wrap.js +17 -0
- package/examples/webxr-2/components/goomba.js +3250 -0
- package/examples/webxr-2/components/init-shell-material.js +215 -0
- package/examples/webxr-2/components/platter.js +172 -0
- package/examples/webxr-2/components/shell.js +374 -0
- package/examples/webxr-2/components/soccer-ball.js +250 -0
- package/examples/webxr-2/components/squashed-goomba.js +249 -0
- package/examples/webxr-2/edge-impulse-standalone.js +7228 -0
- package/examples/webxr-2/edge-impulse-standalone.wasm +0 -0
- package/examples/webxr-2/index.html +996 -0
- package/examples/webxr-2/kick.tflite +0 -0
- package/examples/webxr-2/kick2.tflite +0 -0
- package/examples/webxr-2/run-impulse.js +135 -0
- package/examples/webxr-2/script.js +384 -0
- package/package.json +2 -1
- package/src/.prettierrc +4 -0
- package/src/BS.ts +70 -8
- package/src/CameraManager.ts +499 -0
- package/src/Device.ts +581 -86
- package/src/DeviceInformationManager.ts +19 -10
- package/src/DeviceManager.ts +85 -25
- package/src/FileTransferManager.ts +145 -20
- package/src/InformationManager.ts +40 -15
- package/src/TfliteManager.ts +171 -25
- package/src/WifiManager.ts +323 -0
- package/src/connection/BaseConnectionManager.ts +128 -30
- package/src/connection/ClientConnectionManager.ts +34 -10
- package/src/connection/bluetooth/BluetoothConnectionManager.ts +8 -2
- package/src/connection/bluetooth/NobleConnectionManager.ts +147 -41
- package/src/connection/bluetooth/WebBluetoothConnectionManager.ts +99 -34
- package/src/connection/bluetooth/bluetoothUUIDs.ts +40 -13
- package/src/connection/udp/UDPConnectionManager.ts +356 -0
- package/src/connection/websocket/WebSocketConnectionManager.ts +282 -0
- package/src/devicePair/DevicePair.ts +95 -25
- package/src/devicePair/DevicePairPressureSensorDataManager.ts +27 -7
- package/src/scanner/BaseScanner.ts +49 -11
- package/src/scanner/NobleScanner.ts +76 -14
- package/src/sensor/MotionSensorDataManager.ts +21 -6
- package/src/sensor/PressureSensorDataManager.ts +37 -8
- package/src/sensor/SensorConfigurationManager.ts +73 -22
- package/src/sensor/SensorDataManager.ts +104 -23
- package/src/server/BaseClient.ts +150 -36
- package/src/server/BaseServer.ts +50 -2
- package/src/server/ServerUtils.ts +39 -9
- package/src/server/udp/UDPServer.ts +73 -22
- package/src/server/udp/UDPUtils.ts +9 -2
- package/src/server/websocket/WebSocketClient.ts +27 -7
- package/src/server/websocket/WebSocketUtils.ts +4 -2
- package/src/utils/Console.ts +62 -9
- package/src/utils/ParseUtils.ts +24 -5
- package/src/utils/ThrottleUtils.ts +62 -0
- package/src/utils/Timer.ts +1 -1
- package/src/vibration/VibrationManager.ts +166 -40
package/examples/graph/script.js
CHANGED
|
@@ -12,7 +12,9 @@ window.device = device;
|
|
|
12
12
|
// GET DEVICES
|
|
13
13
|
|
|
14
14
|
/** @type {HTMLTemplateElement} */
|
|
15
|
-
const availableDeviceTemplate = document.getElementById(
|
|
15
|
+
const availableDeviceTemplate = document.getElementById(
|
|
16
|
+
"availableDeviceTemplate"
|
|
17
|
+
);
|
|
16
18
|
const availableDevicesContainer = document.getElementById("availableDevices");
|
|
17
19
|
/** @param {BS.Device[]} availableDevices */
|
|
18
20
|
function onAvailableDevices(availableDevices) {
|
|
@@ -24,19 +26,24 @@ function onAvailableDevices(availableDevices) {
|
|
|
24
26
|
const availableDeviceContainer = availableDeviceTemplate.content
|
|
25
27
|
.cloneNode(true)
|
|
26
28
|
.querySelector(".availableDevice");
|
|
27
|
-
availableDeviceContainer.querySelector(".name").innerText =
|
|
28
|
-
|
|
29
|
+
availableDeviceContainer.querySelector(".name").innerText =
|
|
30
|
+
availableDevice.name;
|
|
31
|
+
availableDeviceContainer.querySelector(".type").innerText =
|
|
32
|
+
availableDevice.type;
|
|
29
33
|
|
|
30
34
|
/** @type {HTMLButtonElement} */
|
|
31
|
-
const toggleConnectionButton =
|
|
35
|
+
const toggleConnectionButton =
|
|
36
|
+
availableDeviceContainer.querySelector(".toggleConnection");
|
|
32
37
|
toggleConnectionButton.addEventListener("click", () => {
|
|
33
38
|
device.connectionManager = availableDevice.connectionManager;
|
|
34
39
|
device.reconnect();
|
|
35
40
|
});
|
|
36
41
|
device.addEventListener("connectionStatus", () => {
|
|
37
|
-
toggleConnectionButton.disabled =
|
|
42
|
+
toggleConnectionButton.disabled =
|
|
43
|
+
device.connectionStatus != "notConnected";
|
|
38
44
|
});
|
|
39
|
-
toggleConnectionButton.disabled =
|
|
45
|
+
toggleConnectionButton.disabled =
|
|
46
|
+
device.connectionStatus != "notConnected";
|
|
40
47
|
|
|
41
48
|
availableDevicesContainer.appendChild(availableDeviceContainer);
|
|
42
49
|
});
|
|
@@ -75,7 +82,9 @@ device.addEventListener("connectionStatus", () => {
|
|
|
75
82
|
case "connected":
|
|
76
83
|
case "notConnected":
|
|
77
84
|
toggleConnectionButton.disabled = false;
|
|
78
|
-
toggleConnectionButton.innerText = device.isConnected
|
|
85
|
+
toggleConnectionButton.innerText = device.isConnected
|
|
86
|
+
? "disconnect"
|
|
87
|
+
: "connect";
|
|
79
88
|
break;
|
|
80
89
|
case "connecting":
|
|
81
90
|
case "disconnecting":
|
|
@@ -99,15 +108,20 @@ function onConnectedDevice(connectedDevice) {
|
|
|
99
108
|
// SENSOR CONFIGURATION
|
|
100
109
|
|
|
101
110
|
/** @type {HTMLTemplateElement} */
|
|
102
|
-
const sensorTypeConfigurationTemplate = document.getElementById(
|
|
111
|
+
const sensorTypeConfigurationTemplate = document.getElementById(
|
|
112
|
+
"sensorTypeConfigurationTemplate"
|
|
113
|
+
);
|
|
103
114
|
BS.ContinuousSensorTypes.forEach((sensorType) => {
|
|
104
|
-
const sensorTypeConfigurationContainer =
|
|
105
|
-
.
|
|
106
|
-
|
|
107
|
-
|
|
115
|
+
const sensorTypeConfigurationContainer =
|
|
116
|
+
sensorTypeConfigurationTemplate.content
|
|
117
|
+
.cloneNode(true)
|
|
118
|
+
.querySelector(".sensorTypeConfiguration");
|
|
119
|
+
sensorTypeConfigurationContainer.querySelector(".sensorType").innerText =
|
|
120
|
+
sensorType;
|
|
108
121
|
|
|
109
122
|
/** @type {HTMLInputElement} */
|
|
110
|
-
const sensorRateInput =
|
|
123
|
+
const sensorRateInput =
|
|
124
|
+
sensorTypeConfigurationContainer.querySelector(".sensorRate");
|
|
111
125
|
sensorRateInput.value = 0;
|
|
112
126
|
sensorRateInput.max = BS.MaxSensorRate;
|
|
113
127
|
sensorRateInput.step = BS.SensorRateStep;
|
|
@@ -117,15 +131,20 @@ BS.ContinuousSensorTypes.forEach((sensorType) => {
|
|
|
117
131
|
device.setSensorConfiguration({ [sensorType]: sensorRate });
|
|
118
132
|
});
|
|
119
133
|
|
|
120
|
-
sensorTypeConfigurationTemplate.parentElement.appendChild(
|
|
134
|
+
sensorTypeConfigurationTemplate.parentElement.appendChild(
|
|
135
|
+
sensorTypeConfigurationContainer
|
|
136
|
+
);
|
|
121
137
|
sensorTypeConfigurationContainer.dataset.sensorType = sensorType;
|
|
122
138
|
});
|
|
123
139
|
/** @param {BS.Device} device */
|
|
124
140
|
function onSensorConfiguration(device) {
|
|
125
|
-
|
|
126
|
-
const sensorRate = device.sensorConfiguration[sensorType];
|
|
141
|
+
BS.SensorTypes.forEach((sensorType) => {
|
|
142
|
+
const sensorRate = device.sensorConfiguration[sensorType] ?? 0;
|
|
143
|
+
|
|
127
144
|
/** @type {HTMLInputElement?} */
|
|
128
|
-
const input = document.querySelector(
|
|
145
|
+
const input = document.querySelector(
|
|
146
|
+
`.sensorTypeConfiguration[data-sensor-type="${sensorType}"] .input`
|
|
147
|
+
);
|
|
129
148
|
if (input) {
|
|
130
149
|
input.value = sensorRate;
|
|
131
150
|
}
|
|
@@ -146,17 +165,21 @@ function onSensorConfiguration(device) {
|
|
|
146
165
|
chartContainer.style.display = display;
|
|
147
166
|
});
|
|
148
167
|
}
|
|
149
|
-
}
|
|
168
|
+
});
|
|
150
169
|
}
|
|
151
170
|
/** @param {BS.Device} device */
|
|
152
171
|
function updateSensorRateInputs(device) {
|
|
153
|
-
|
|
172
|
+
BS.SensorTypes.forEach((sensorType) => {
|
|
154
173
|
/** @type {HTMLInputElement?} */
|
|
155
|
-
const input = document.querySelector(
|
|
174
|
+
const input = document.querySelector(
|
|
175
|
+
`[data-sensor-type="${sensorType}"] .input`
|
|
176
|
+
);
|
|
156
177
|
if (input) {
|
|
157
|
-
|
|
178
|
+
const containsSensorType = sensorType in device.sensorConfiguration;
|
|
179
|
+
input.closest("label").style.display = containsSensorType ? "" : "none";
|
|
180
|
+
input.disabled = !device.isConnected || !containsSensorType;
|
|
158
181
|
}
|
|
159
|
-
}
|
|
182
|
+
});
|
|
160
183
|
}
|
|
161
184
|
|
|
162
185
|
// GRAPHING
|
|
@@ -276,7 +299,9 @@ window.chartContainers = chartContainers;
|
|
|
276
299
|
/** @type {HTMLTemplateElement} */
|
|
277
300
|
const chartTemplate = document.getElementById("chartTemplate");
|
|
278
301
|
BS.ContinuousSensorTypes.forEach((sensorType) => {
|
|
279
|
-
const chartContainer = chartTemplate.content
|
|
302
|
+
const chartContainer = chartTemplate.content
|
|
303
|
+
.cloneNode(true)
|
|
304
|
+
.querySelector(".chart");
|
|
280
305
|
chartsContainer.appendChild(chartContainer);
|
|
281
306
|
chartContainers[sensorType] = chartContainer;
|
|
282
307
|
|
|
@@ -299,6 +324,12 @@ BS.ContinuousSensorTypes.forEach((sensorType) => {
|
|
|
299
324
|
case "rotation":
|
|
300
325
|
axesLabels = ["x", "y", "z", "w"];
|
|
301
326
|
break;
|
|
327
|
+
case "orientation":
|
|
328
|
+
axesLabels = ["heading", "pitch", "roll"];
|
|
329
|
+
break;
|
|
330
|
+
case "barometer":
|
|
331
|
+
axesLabels = ["barometer"];
|
|
332
|
+
break;
|
|
302
333
|
default:
|
|
303
334
|
console.warn(`uncaught sensorType "${sensorType}"`);
|
|
304
335
|
return;
|
|
@@ -323,36 +354,53 @@ BS.ContinuousSensorTypes.forEach((sensorType) => {
|
|
|
323
354
|
yRange = { min: -360, max: 360 };
|
|
324
355
|
break;
|
|
325
356
|
case "magnetometer":
|
|
326
|
-
|
|
357
|
+
yRange = { min: -100, max: 100 };
|
|
327
358
|
break;
|
|
328
359
|
case "gameRotation":
|
|
329
360
|
case "rotation":
|
|
330
361
|
yRange = { min: -1, max: 1 };
|
|
331
362
|
break;
|
|
363
|
+
case "orientation":
|
|
364
|
+
yRange = { min: -360, max: 360 };
|
|
365
|
+
break;
|
|
332
366
|
}
|
|
333
367
|
|
|
334
368
|
switch (sensorType) {
|
|
335
369
|
case "gameRotation":
|
|
336
370
|
case "rotation":
|
|
337
371
|
{
|
|
338
|
-
const eulerChartContainer = chartTemplate.content
|
|
372
|
+
const eulerChartContainer = chartTemplate.content
|
|
373
|
+
.cloneNode(true)
|
|
374
|
+
.querySelector(".chart");
|
|
339
375
|
chartsContainer.appendChild(eulerChartContainer);
|
|
340
376
|
chartContainers[`${sensorType}.euler`] = eulerChartContainer;
|
|
341
|
-
createChart(
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
377
|
+
createChart(
|
|
378
|
+
eulerChartContainer.querySelector("canvas"),
|
|
379
|
+
sensorType + "Euler",
|
|
380
|
+
["yaw", "pitch", "roll"],
|
|
381
|
+
{
|
|
382
|
+
min: -Math.PI,
|
|
383
|
+
max: Math.PI,
|
|
384
|
+
}
|
|
385
|
+
);
|
|
345
386
|
}
|
|
346
387
|
break;
|
|
347
388
|
case "pressure":
|
|
348
389
|
{
|
|
349
|
-
const pressureMetadataChartContainer = chartTemplate.content
|
|
390
|
+
const pressureMetadataChartContainer = chartTemplate.content
|
|
391
|
+
.cloneNode(true)
|
|
392
|
+
.querySelector(".chart");
|
|
350
393
|
chartsContainer.appendChild(pressureMetadataChartContainer);
|
|
351
394
|
chartContainers["pressureMetadata"] = pressureMetadataChartContainer;
|
|
352
|
-
createChart(
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
395
|
+
createChart(
|
|
396
|
+
pressureMetadataChartContainer.querySelector("canvas"),
|
|
397
|
+
"pressureMetadata",
|
|
398
|
+
["sum", "x", "y"],
|
|
399
|
+
{
|
|
400
|
+
min: 0,
|
|
401
|
+
max: 1,
|
|
402
|
+
}
|
|
403
|
+
);
|
|
356
404
|
}
|
|
357
405
|
break;
|
|
358
406
|
}
|
|
@@ -361,7 +409,12 @@ BS.ContinuousSensorTypes.forEach((sensorType) => {
|
|
|
361
409
|
const euler = new THREE.Euler();
|
|
362
410
|
euler.reorder("YXZ");
|
|
363
411
|
|
|
364
|
-
createChart(
|
|
412
|
+
createChart(
|
|
413
|
+
chartContainer.querySelector("canvas"),
|
|
414
|
+
sensorType,
|
|
415
|
+
axesLabels,
|
|
416
|
+
yRange
|
|
417
|
+
);
|
|
365
418
|
});
|
|
366
419
|
|
|
367
420
|
/** @param {BS.Device} device */
|
|
@@ -437,12 +490,16 @@ if (false)
|
|
|
437
490
|
|
|
438
491
|
const websocketClient = new BS.WebSocketClient();
|
|
439
492
|
/** @type {HTMLButtonElement} */
|
|
440
|
-
const toggleServerConnectionButton = document.getElementById(
|
|
493
|
+
const toggleServerConnectionButton = document.getElementById(
|
|
494
|
+
"toggleServerConnection"
|
|
495
|
+
);
|
|
441
496
|
toggleServerConnectionButton.addEventListener("click", () => {
|
|
442
497
|
websocketClient.toggleConnection();
|
|
443
498
|
});
|
|
444
499
|
websocketClient.addEventListener("isConnected", () => {
|
|
445
|
-
toggleServerConnectionButton.innerText = websocketClient.isConnected
|
|
500
|
+
toggleServerConnectionButton.innerText = websocketClient.isConnected
|
|
501
|
+
? "disconnect from server"
|
|
502
|
+
: "connect to server";
|
|
446
503
|
});
|
|
447
504
|
websocketClient.addEventListener("connectionStatus", () => {
|
|
448
505
|
let disabled;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<head>
|
|
3
|
+
<title>Punch | BrilliantSole JavaScript SDK</title>
|
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
5
|
+
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
|
|
6
|
+
<script type="module" src="./script.js"></script>
|
|
7
|
+
<script src="https://aframe.io/releases/1.6.0/aframe.min.js"></script>
|
|
8
|
+
<script src="../utils/aframe/force-pushable.js"></script>
|
|
9
|
+
<script src="https://cdn.jsdelivr.net/gh/c-frame/aframe-physics-system@v4.2.3/dist/aframe-physics-system.min.js"></script>
|
|
10
|
+
</head>
|
|
11
|
+
<style>
|
|
12
|
+
#scene {
|
|
13
|
+
width: 700px;
|
|
14
|
+
height: 700px;
|
|
15
|
+
margin: auto;
|
|
16
|
+
border-radius: 2rem;
|
|
17
|
+
overflow: hidden;
|
|
18
|
+
border: solid black;
|
|
19
|
+
box-sizing: border-box;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#title {
|
|
23
|
+
margin: auto;
|
|
24
|
+
height: 70px;
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-direction: row;
|
|
27
|
+
align-items: center;
|
|
28
|
+
justify-content: center;
|
|
29
|
+
|
|
30
|
+
font-size: xx-large;
|
|
31
|
+
}
|
|
32
|
+
</style>
|
|
33
|
+
<body>
|
|
34
|
+
<nav>
|
|
35
|
+
<a href="../../">home</a>
|
|
36
|
+
</nav>
|
|
37
|
+
|
|
38
|
+
<h1>Punch | BrilliantSole JavaScript SDK</h1>
|
|
39
|
+
|
|
40
|
+
<button id="toggleConnection">connect</button>
|
|
41
|
+
|
|
42
|
+
<progress value="0" id="fileTransferProgress"></progress>
|
|
43
|
+
|
|
44
|
+
<label>
|
|
45
|
+
is model ready <input type="checkbox" disabled id="isModelReady" />
|
|
46
|
+
</label>
|
|
47
|
+
|
|
48
|
+
<div id="title">
|
|
49
|
+
<h1 id="maxClass">Punch</h1>
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
<a-scene
|
|
53
|
+
id="scene"
|
|
54
|
+
physics="debug: false"
|
|
55
|
+
embedded
|
|
56
|
+
xr-mode-ui="enabled: false;"
|
|
57
|
+
device-orientation-permission-ui="enabled: false"
|
|
58
|
+
>
|
|
59
|
+
<a-assets></a-assets>
|
|
60
|
+
|
|
61
|
+
<a-camera
|
|
62
|
+
id="camera"
|
|
63
|
+
look-controls="enabled: false;"
|
|
64
|
+
wasd-controls="enabled: false"
|
|
65
|
+
position="0 0.2 0.65"
|
|
66
|
+
rotation="-20 0 0"
|
|
67
|
+
></a-camera>
|
|
68
|
+
<a-sky></a-sky>
|
|
69
|
+
|
|
70
|
+
<a-entity position="0 -0.55 0">
|
|
71
|
+
<a-sphere
|
|
72
|
+
id="punchingBag2"
|
|
73
|
+
class="punchingBag 2"
|
|
74
|
+
data-section="2"
|
|
75
|
+
radius="0.125"
|
|
76
|
+
color="#777"
|
|
77
|
+
position="0 0.75 0"
|
|
78
|
+
dynamic-body
|
|
79
|
+
force-pushable
|
|
80
|
+
constraint="type: coneTwist;
|
|
81
|
+
target: #punchingBag1;
|
|
82
|
+
pivot: 0 -0.13 0;
|
|
83
|
+
targetPivot: 0 0.13 0;
|
|
84
|
+
axis: 0 1 0;
|
|
85
|
+
targetAxis: 0 1 0"
|
|
86
|
+
></a-sphere>
|
|
87
|
+
<a-box
|
|
88
|
+
id="punchingBag1"
|
|
89
|
+
class="punchingBag 1"
|
|
90
|
+
data-section="1"
|
|
91
|
+
width="0.5"
|
|
92
|
+
height="0.25"
|
|
93
|
+
depth="0.25"
|
|
94
|
+
color="#B00"
|
|
95
|
+
position="0 0.5 0"
|
|
96
|
+
dynamic-body
|
|
97
|
+
force-pushable
|
|
98
|
+
constraint="type: coneTwist;
|
|
99
|
+
target: #punchingBag0;
|
|
100
|
+
pivot: 0 -0.13 0;
|
|
101
|
+
targetPivot: 0 0.13 0;
|
|
102
|
+
axis: 0 1 0;
|
|
103
|
+
targetAxis: 0 1 0"
|
|
104
|
+
>
|
|
105
|
+
</a-box>
|
|
106
|
+
<a-box
|
|
107
|
+
id="punchingBag0"
|
|
108
|
+
class="punchingBag"
|
|
109
|
+
data-section="0"
|
|
110
|
+
width="0.25"
|
|
111
|
+
height="0.25"
|
|
112
|
+
depth="0.25"
|
|
113
|
+
color="#F00"
|
|
114
|
+
position="0 0.25 0"
|
|
115
|
+
dynamic-body
|
|
116
|
+
force-pushable
|
|
117
|
+
constraint="type: coneTwist;
|
|
118
|
+
target: #punchingBagBase;
|
|
119
|
+
pivot: 0 -0.125 0;
|
|
120
|
+
targetPivot: 0 0.125 0;
|
|
121
|
+
axis: 0 1 0;
|
|
122
|
+
targetAxis: 0 1 0"
|
|
123
|
+
>
|
|
124
|
+
</a-box>
|
|
125
|
+
<a-sphere
|
|
126
|
+
id="punchingBagBase"
|
|
127
|
+
radius="0.125"
|
|
128
|
+
color="#777"
|
|
129
|
+
position="0 0 0"
|
|
130
|
+
static-body
|
|
131
|
+
></a-sphere>
|
|
132
|
+
</a-entity>
|
|
133
|
+
</a-scene>
|
|
134
|
+
</body>
|
|
135
|
+
</html>
|
|
Binary file
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import * as BS from "../../build/brilliantsole.module.js";
|
|
2
|
+
window.BS = BS;
|
|
3
|
+
console.log(BS);
|
|
4
|
+
|
|
5
|
+
// DEVICE
|
|
6
|
+
|
|
7
|
+
const device = new BS.Device();
|
|
8
|
+
console.log({ device });
|
|
9
|
+
window.device = device;
|
|
10
|
+
|
|
11
|
+
// CONNECT
|
|
12
|
+
|
|
13
|
+
const toggleConnectionButton = document.getElementById("toggleConnection");
|
|
14
|
+
toggleConnectionButton.addEventListener("click", () =>
|
|
15
|
+
device.toggleConnection()
|
|
16
|
+
);
|
|
17
|
+
device.addEventListener("connectionStatus", () => {
|
|
18
|
+
let disabled = false;
|
|
19
|
+
let innerText = device.connectionStatus;
|
|
20
|
+
switch (device.connectionStatus) {
|
|
21
|
+
case "notConnected":
|
|
22
|
+
innerText = "connect";
|
|
23
|
+
break;
|
|
24
|
+
case "connected":
|
|
25
|
+
innerText = "disconnect";
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
toggleConnectionButton.disabled = disabled;
|
|
29
|
+
toggleConnectionButton.innerText = innerText;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// FILE TRANSFER
|
|
33
|
+
/** @type {HTMLProgressElement} */
|
|
34
|
+
const fileTransferProgress = document.getElementById("fileTransferProgress");
|
|
35
|
+
device.addEventListener("fileTransferProgress", (event) => {
|
|
36
|
+
const progress = event.message.progress;
|
|
37
|
+
console.log({ progress });
|
|
38
|
+
fileTransferProgress.value = progress == 1 ? 0 : progress;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// MODEL
|
|
42
|
+
/** @type {HTMLInputElement} */
|
|
43
|
+
const isModelReadyCheckbox = document.getElementById("isModelReady");
|
|
44
|
+
device.addEventListener("getTfliteInferencingEnabled", () => {
|
|
45
|
+
isModelReadyCheckbox.checked = device.tfliteInferencingEnabled;
|
|
46
|
+
});
|
|
47
|
+
device.addEventListener("fileTransferStatus", () => {
|
|
48
|
+
if (device.fileTransferStatus == "idle") {
|
|
49
|
+
fileTransferProgress.value = 0;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/** @type {HTMLSpanElement} */
|
|
54
|
+
const maxClassSpan = document.getElementById("maxClass");
|
|
55
|
+
let gestureTimeout;
|
|
56
|
+
device.addEventListener("tfliteInference", (event) => {
|
|
57
|
+
maxClassSpan.innerText =
|
|
58
|
+
event.message.tfliteInference.maxClass.toUpperCase() + "!";
|
|
59
|
+
if (gestureTimeout) {
|
|
60
|
+
clearTimeout(gestureTimeout);
|
|
61
|
+
}
|
|
62
|
+
gestureTimeout = setTimeout(() => {
|
|
63
|
+
maxClassSpan.innerText = "";
|
|
64
|
+
}, 600);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// GLOVE
|
|
68
|
+
/** @type {BS.TfliteFileConfiguration} */
|
|
69
|
+
const punchConfiguration = {
|
|
70
|
+
name: "punch",
|
|
71
|
+
task: "classification",
|
|
72
|
+
sensorTypes: ["gyroscope", "linearAcceleration"],
|
|
73
|
+
sampleRate: 20,
|
|
74
|
+
captureDelay: 200,
|
|
75
|
+
classes: ["idle", "punch", "hook", "uppercut"],
|
|
76
|
+
};
|
|
77
|
+
fetch("./punch.tflite")
|
|
78
|
+
.then((response) => response.arrayBuffer())
|
|
79
|
+
.then((buffer) => {
|
|
80
|
+
punchConfiguration.file = buffer;
|
|
81
|
+
console.log("updated punchModelConfiguration", punchConfiguration);
|
|
82
|
+
})
|
|
83
|
+
.catch((err) => {
|
|
84
|
+
console.error("Error loading punch model:", err);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
device.addEventListener("connected", async () => {
|
|
88
|
+
if (device.type != "rightGlove") {
|
|
89
|
+
console.error("expected right glove");
|
|
90
|
+
device.disconnect();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
device.sendTfliteConfiguration(punchConfiguration);
|
|
94
|
+
});
|
|
95
|
+
device.addEventListener("tfliteIsReady", () => {
|
|
96
|
+
if (device.tfliteIsReady) {
|
|
97
|
+
device.enableTfliteInferencing();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// GAME
|
|
102
|
+
device.addEventListener("tfliteInference", (event) => {
|
|
103
|
+
switch (event.message.tfliteInference.maxClass) {
|
|
104
|
+
case "punch":
|
|
105
|
+
punch();
|
|
106
|
+
break;
|
|
107
|
+
case "hook":
|
|
108
|
+
hook();
|
|
109
|
+
break;
|
|
110
|
+
case "uppercut":
|
|
111
|
+
uppercut();
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// PHYSICS
|
|
117
|
+
const punchingBagBaseEntity = document.getElementById("punchingBagBase");
|
|
118
|
+
const punchingBagEntities = Array.from(
|
|
119
|
+
document.querySelectorAll(".punchingBag")
|
|
120
|
+
).sort((a, b) => a.dataset.section - b.dataset.section);
|
|
121
|
+
|
|
122
|
+
const forces = {
|
|
123
|
+
punch: new THREE.Vector3(0, 0, -110),
|
|
124
|
+
hook: new THREE.Vector3(-30, 0, -20),
|
|
125
|
+
uppercut: new THREE.Vector3(-10, 0, -70),
|
|
126
|
+
};
|
|
127
|
+
function punch() {
|
|
128
|
+
window.force = forces.punch;
|
|
129
|
+
punchingBagEntities[1].click();
|
|
130
|
+
triggerWaveformEffect("strongClick100");
|
|
131
|
+
}
|
|
132
|
+
function hook() {
|
|
133
|
+
window.force = forces.hook;
|
|
134
|
+
punchingBagEntities[2].click();
|
|
135
|
+
triggerWaveformEffect("strongBuzz100");
|
|
136
|
+
}
|
|
137
|
+
function uppercut() {
|
|
138
|
+
window.force = forces.uppercut;
|
|
139
|
+
punchingBagEntities[2].click();
|
|
140
|
+
triggerWaveformEffect("pulsingStrong100");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** @param {BS.VibrationWaveformEffect} waveformEffect */
|
|
144
|
+
function triggerWaveformEffect(waveformEffect) {
|
|
145
|
+
if (!device.isConnected) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
device.triggerVibration([
|
|
149
|
+
{
|
|
150
|
+
type: "waveformEffect",
|
|
151
|
+
locations: ["rear"],
|
|
152
|
+
segments: [{ effect: waveformEffect }],
|
|
153
|
+
},
|
|
154
|
+
]);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
document.addEventListener("keydown", (event) => {
|
|
158
|
+
switch (event.key) {
|
|
159
|
+
case "p":
|
|
160
|
+
punch();
|
|
161
|
+
break;
|
|
162
|
+
case "h":
|
|
163
|
+
hook();
|
|
164
|
+
break;
|
|
165
|
+
case "u":
|
|
166
|
+
uppercut();
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
});
|