brilliantsole 0.0.27 → 0.0.29
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 +3091 -741
- package/build/brilliantsole.cjs.map +1 -1
- package/build/brilliantsole.js +2759 -709
- package/build/brilliantsole.js.map +1 -1
- package/build/brilliantsole.ls.js +2602 -543
- 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 +295 -65
- package/build/brilliantsole.module.js +2749 -710
- package/build/brilliantsole.module.js.map +1 -1
- package/build/brilliantsole.module.min.d.ts +295 -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 +289 -62
- package/build/brilliantsole.node.module.js +3080 -742
- package/build/brilliantsole.node.module.js.map +1 -1
- package/build/dts/BS-output.d.ts +10 -0
- package/build/dts/BS.d.ts +21 -8
- package/build/dts/CameraManager.d.ts +72 -0
- package/build/dts/Device.d.ts +64 -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/MicrophoneManager.d.ts +88 -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/AudioUtils.d.ts +2 -0
- 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 +292 -62
- package/build/index.node.d.ts +286 -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 +267 -17
- package/examples/basic/script.js +958 -105
- package/examples/camera/barcode-detector.js +109 -0
- package/examples/camera/depth-estimation.js +71 -0
- package/examples/camera/face-detector.js +119 -0
- package/examples/camera/face-landmark.js +111 -0
- package/examples/camera/gesture-recognition.js +97 -0
- package/examples/camera/hand-landmark.js +74 -0
- package/examples/camera/image-segmentation.js +98 -0
- package/examples/camera/image-to-text.js +43 -0
- package/examples/camera/image-upscale.js +75 -0
- package/examples/camera/index.html +129 -0
- package/examples/camera/object-detection.js +98 -0
- package/examples/camera/pose-landmark.js +60 -0
- package/examples/camera/script.js +316 -0
- package/examples/camera/utils.js +165 -0
- package/examples/camera/yolo-tiny.js +54 -0
- package/examples/camera/yolo.js +119 -0
- package/examples/edge-impulse/script.js +157 -48
- 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/glasses-gestures/README.md +11 -0
- package/examples/glasses-gestures/edge-impulse-standalone.js +7228 -0
- package/examples/glasses-gestures/edge-impulse-standalone.wasm +0 -0
- package/examples/glasses-gestures/index.html +69 -0
- package/examples/glasses-gestures/run-impulse.js +135 -0
- package/examples/glasses-gestures/script.js +226 -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/microphone/gender.js +54 -0
- package/examples/microphone/index.html +102 -0
- package/examples/microphone/script.js +394 -0
- package/examples/microphone/utils.js +45 -0
- package/examples/microphone/whisper-realtime.js +166 -0
- package/examples/microphone/whisper.js +132 -0
- 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/examples/webxr-3/components/bs-camera.js +65 -0
- package/examples/webxr-3/index.html +134 -0
- package/examples/webxr-3/script.js +432 -0
- package/package.json +2 -1
- package/src/.prettierrc +4 -0
- package/src/BS.ts +79 -8
- package/src/CameraManager.ts +497 -0
- package/src/Device.ts +691 -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/MicrophoneManager.ts +599 -0
- package/src/TfliteManager.ts +171 -25
- package/src/WifiManager.ts +323 -0
- package/src/connection/BaseConnectionManager.ts +130 -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 +109 -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/AudioUtils.ts +65 -0
- 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/3d/scene.html
CHANGED
|
@@ -22,8 +22,14 @@
|
|
|
22
22
|
renderer="colorManagement: true;"
|
|
23
23
|
>
|
|
24
24
|
<a-assets>
|
|
25
|
-
<a-asset-item
|
|
26
|
-
|
|
25
|
+
<a-asset-item
|
|
26
|
+
id="leftInsole"
|
|
27
|
+
src="../../assets/3d/leftInsole.glb"
|
|
28
|
+
></a-asset-item>
|
|
29
|
+
<a-asset-item
|
|
30
|
+
id="rightInsole"
|
|
31
|
+
src="../../assets/3d/rightInsole.glb"
|
|
32
|
+
></a-asset-item>
|
|
27
33
|
</a-assets>
|
|
28
34
|
<a-light type="directional" position="2 2 -2" target=".target"></a-light>
|
|
29
35
|
<a-light type="directional" position="-2 2 2" target=".target"></a-light>
|
|
@@ -51,7 +57,11 @@
|
|
|
51
57
|
<a-entity class="target">
|
|
52
58
|
<a-entity class="rotation">
|
|
53
59
|
<a-entity class="position" position="0 0 0.005">
|
|
54
|
-
<a-entity
|
|
60
|
+
<a-entity
|
|
61
|
+
class="insole"
|
|
62
|
+
gltf-model="#rightInsole"
|
|
63
|
+
visible="true"
|
|
64
|
+
></a-entity>
|
|
55
65
|
</a-entity>
|
|
56
66
|
</a-entity>
|
|
57
67
|
</a-entity>
|
|
@@ -65,8 +75,12 @@
|
|
|
65
75
|
const isDark = params.has("dark");
|
|
66
76
|
if (isDark) {
|
|
67
77
|
document.querySelector("a-sky").setAttribute("color", "black");
|
|
68
|
-
document
|
|
69
|
-
|
|
78
|
+
document
|
|
79
|
+
.querySelector("a-camera")
|
|
80
|
+
.setAttribute("orbit-controls", "enableRotate", "false");
|
|
81
|
+
document
|
|
82
|
+
.querySelector("a-camera")
|
|
83
|
+
.setAttribute("orbit-controls", "enableRotate", "false");
|
|
70
84
|
document.querySelector("a-camera").setAttribute("position", "0 0 1");
|
|
71
85
|
}
|
|
72
86
|
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<head>
|
|
3
|
+
<title>3D | 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 src="https://aframe.io/releases/1.5.0/aframe.min.js"></script> -->
|
|
7
|
+
<script src="https://aframe.io/releases/1.6.0/aframe.min.js"></script>
|
|
8
|
+
<!-- required to get aframe-orbit-controls-component to work -->
|
|
9
|
+
<script>
|
|
10
|
+
THREE.Quaternion.prototype.inverse = THREE.Quaternion.prototype.invert;
|
|
11
|
+
THREE.Math = THREE.MathUtils;
|
|
12
|
+
</script>
|
|
13
|
+
<!-- https://github.com/tizzle/aframe-orbit-controls-component -->
|
|
14
|
+
<script src="https://cdn.rawgit.com/tizzle/aframe-orbit-controls-component/v0.1.14/dist/aframe-orbit-controls-component.min.js"></script>
|
|
15
|
+
<script type="module" src="./script.js"></script>
|
|
16
|
+
</head>
|
|
17
|
+
|
|
18
|
+
<style>
|
|
19
|
+
a-scene {
|
|
20
|
+
width: 500px;
|
|
21
|
+
height: 500px;
|
|
22
|
+
margin: auto;
|
|
23
|
+
border-radius: 2rem;
|
|
24
|
+
overflow: hidden;
|
|
25
|
+
border: solid black;
|
|
26
|
+
box-sizing: border-box;
|
|
27
|
+
}
|
|
28
|
+
</style>
|
|
29
|
+
|
|
30
|
+
<body>
|
|
31
|
+
<nav>
|
|
32
|
+
<a href="../../">home</a>
|
|
33
|
+
</nav>
|
|
34
|
+
|
|
35
|
+
<h1>3D (generic) | BrilliantSole JavaScript SDK</h1>
|
|
36
|
+
|
|
37
|
+
<button id="toggleConnection">connect</button>
|
|
38
|
+
|
|
39
|
+
<p>
|
|
40
|
+
<select class="orientation" disabled>
|
|
41
|
+
<optgroup label="orientation">
|
|
42
|
+
<option value="none">no orientation</option>
|
|
43
|
+
<option>gameRotation</option>
|
|
44
|
+
<option>rotation</option>
|
|
45
|
+
<option>orientation</option>
|
|
46
|
+
<option>gyroscope</option>
|
|
47
|
+
</optgroup>
|
|
48
|
+
</select>
|
|
49
|
+
<button disabled class="resetOrientation">reset orientation</button>
|
|
50
|
+
<br />
|
|
51
|
+
<select class="position" disabled>
|
|
52
|
+
<optgroup label="position">
|
|
53
|
+
<option value="none">no position</option>
|
|
54
|
+
<option>acceleration</option>
|
|
55
|
+
<option>gravity</option>
|
|
56
|
+
<option>linearAcceleration</option>
|
|
57
|
+
</optgroup>
|
|
58
|
+
</select>
|
|
59
|
+
</p>
|
|
60
|
+
|
|
61
|
+
<a-scene
|
|
62
|
+
embedded
|
|
63
|
+
xr-mode-ui="enabled: false;"
|
|
64
|
+
device-orientation-permission-ui="enabled: false"
|
|
65
|
+
renderer="colorManagement: true;"
|
|
66
|
+
>
|
|
67
|
+
<a-assets>
|
|
68
|
+
<a-asset-item
|
|
69
|
+
id="leftInsoleModel"
|
|
70
|
+
src="../../assets/3d/leftInsole.glb"
|
|
71
|
+
></a-asset-item>
|
|
72
|
+
<a-asset-item
|
|
73
|
+
id="rightInsoleModel"
|
|
74
|
+
src="../../assets/3d/rightInsole.glb"
|
|
75
|
+
></a-asset-item>
|
|
76
|
+
<a-asset-item
|
|
77
|
+
id="rightHandModel"
|
|
78
|
+
src="../../assets/3d/rightHand.glb"
|
|
79
|
+
></a-asset-item>
|
|
80
|
+
<a-asset-item
|
|
81
|
+
id="glassesModel"
|
|
82
|
+
src="../../assets/3d/glasses.glb"
|
|
83
|
+
></a-asset-item>
|
|
84
|
+
</a-assets>
|
|
85
|
+
<a-light type="directional" position="2 2 -2" target=".target"></a-light>
|
|
86
|
+
<a-light type="directional" position="-2 2 2" target=".target"></a-light>
|
|
87
|
+
<a-light type="directional" position="2 -2 2" target=".target"></a-light>
|
|
88
|
+
|
|
89
|
+
<a-entity light="color: #BBB; type: ambient;"></a-entity>
|
|
90
|
+
|
|
91
|
+
<a-camera
|
|
92
|
+
class="camera"
|
|
93
|
+
camera="fov: 50; zoom: 3.2;"
|
|
94
|
+
position="0 0 1"
|
|
95
|
+
orbit-controls="
|
|
96
|
+
enableZoom: true;
|
|
97
|
+
autoRotate: false;
|
|
98
|
+
|
|
99
|
+
target: .target;
|
|
100
|
+
enableDamping: true;
|
|
101
|
+
dampingFactor: 0.125;
|
|
102
|
+
rotateSpeed:0.25;
|
|
103
|
+
minDistance:0.75;
|
|
104
|
+
maxDistance:2;
|
|
105
|
+
"
|
|
106
|
+
></a-camera>
|
|
107
|
+
|
|
108
|
+
<a-sky></a-sky>
|
|
109
|
+
|
|
110
|
+
<a-entity class="target">
|
|
111
|
+
<a-entity class="rotation">
|
|
112
|
+
<a-entity class="position" position="0 0 0.005">
|
|
113
|
+
<a-entity
|
|
114
|
+
gltf-model="#rightInsoleModel"
|
|
115
|
+
visible="false"
|
|
116
|
+
data-type="rightInsole"
|
|
117
|
+
></a-entity>
|
|
118
|
+
<a-entity
|
|
119
|
+
gltf-model="#leftInsoleModel"
|
|
120
|
+
visible="false"
|
|
121
|
+
data-type="leftInsole"
|
|
122
|
+
></a-entity>
|
|
123
|
+
<a-entity
|
|
124
|
+
gltf-model="#glassesModel"
|
|
125
|
+
visible="false"
|
|
126
|
+
data-type="glasses"
|
|
127
|
+
></a-entity>
|
|
128
|
+
<a-entity
|
|
129
|
+
gltf-model="#rightHandModel"
|
|
130
|
+
visible="false"
|
|
131
|
+
data-type="rightGlove"
|
|
132
|
+
></a-entity>
|
|
133
|
+
<a-entity
|
|
134
|
+
gltf-model="#rightHandModel"
|
|
135
|
+
visible="false"
|
|
136
|
+
scale="-1 1 1"
|
|
137
|
+
data-type="leftGlove"
|
|
138
|
+
></a-entity>
|
|
139
|
+
</a-entity>
|
|
140
|
+
</a-entity>
|
|
141
|
+
</a-entity>
|
|
142
|
+
</a-scene>
|
|
143
|
+
</body>
|
|
144
|
+
</html>
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import * as BS from "../../build/brilliantsole.module.js";
|
|
2
|
+
window.BS = BS;
|
|
3
|
+
console.log({ BS });
|
|
4
|
+
//BS.setAllConsoleLevelFlags({ log: false });
|
|
5
|
+
|
|
6
|
+
// DEVICE
|
|
7
|
+
|
|
8
|
+
const device = new BS.Device();
|
|
9
|
+
console.log({ device });
|
|
10
|
+
window.device = device;
|
|
11
|
+
|
|
12
|
+
// CONNECT
|
|
13
|
+
|
|
14
|
+
const toggleConnectionButton = document.getElementById("toggleConnection");
|
|
15
|
+
toggleConnectionButton.addEventListener("click", () =>
|
|
16
|
+
device.toggleConnection()
|
|
17
|
+
);
|
|
18
|
+
device.addEventListener("connectionStatus", () => {
|
|
19
|
+
let disabled = false;
|
|
20
|
+
let innerText = device.connectionStatus;
|
|
21
|
+
switch (device.connectionStatus) {
|
|
22
|
+
case "notConnected":
|
|
23
|
+
innerText = "connect";
|
|
24
|
+
break;
|
|
25
|
+
case "connected":
|
|
26
|
+
innerText = "disconnect";
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
toggleConnectionButton.disabled = disabled;
|
|
30
|
+
toggleConnectionButton.innerText = innerText;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// 3D VISUALIZATION
|
|
34
|
+
|
|
35
|
+
/** @typedef {import("../utils/three/three.module.min.js").Vector3} TVector3 */
|
|
36
|
+
/** @typedef {import("../utils/three/three.module.min.js").Quaternion} TQuaternion */
|
|
37
|
+
/** @typedef {import("../utils/three/three.module.min.js").Euler} TEuler */
|
|
38
|
+
|
|
39
|
+
window.sensorRate = 20;
|
|
40
|
+
window.interpolationSmoothing = 0.4;
|
|
41
|
+
window.positionScalar = 0.1;
|
|
42
|
+
|
|
43
|
+
const scene = document.querySelector("a-scene");
|
|
44
|
+
const targetEntity = scene.querySelector(".target");
|
|
45
|
+
const targetPositionEntity = targetEntity.querySelector(".position");
|
|
46
|
+
const targetRotationEntity = targetEntity.querySelector(".rotation");
|
|
47
|
+
const modelEntities = Array.from(targetEntity.querySelectorAll("[gltf-model]"));
|
|
48
|
+
|
|
49
|
+
device.addEventListener("connected", () => {
|
|
50
|
+
modelEntities.forEach((entity) => {
|
|
51
|
+
entity.setAttribute("visible", entity.dataset.type == device.type);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/** @type {HTMLSelectElement} */
|
|
56
|
+
const orientationSelect = document.querySelector(".orientation");
|
|
57
|
+
orientationSelect.addEventListener("input", () => {
|
|
58
|
+
/** @type {BS.SensorConfiguration} */
|
|
59
|
+
const configuration = {
|
|
60
|
+
gameRotation: 0,
|
|
61
|
+
rotation: 0,
|
|
62
|
+
gyroscope: 0,
|
|
63
|
+
orientation: 0,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
switch (orientationSelect.value) {
|
|
67
|
+
case "none":
|
|
68
|
+
break;
|
|
69
|
+
case "gameRotation":
|
|
70
|
+
configuration.gameRotation = sensorRate;
|
|
71
|
+
break;
|
|
72
|
+
case "rotation":
|
|
73
|
+
configuration.rotation = sensorRate;
|
|
74
|
+
break;
|
|
75
|
+
case "orientation":
|
|
76
|
+
configuration.orientation = sensorRate;
|
|
77
|
+
break;
|
|
78
|
+
case "gyroscope":
|
|
79
|
+
configuration.gyroscope = sensorRate;
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
console.error(
|
|
83
|
+
`uncaught orientationSelect value "${orientationSelect.value}"`
|
|
84
|
+
);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
device.setSensorConfiguration(configuration);
|
|
89
|
+
});
|
|
90
|
+
device.addEventListener("connected", () => {
|
|
91
|
+
orientationSelect.querySelectorAll("option").forEach((option) => {
|
|
92
|
+
option.hidden =
|
|
93
|
+
BS.SensorTypes.includes(option.value) &&
|
|
94
|
+
!device.sensorTypes.includes(option.value);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
/** @type {HTMLButtonElement} */
|
|
99
|
+
const resetOrientationButton = document.querySelector(".resetOrientation");
|
|
100
|
+
resetOrientationButton.addEventListener("click", () => {
|
|
101
|
+
resetOrientation();
|
|
102
|
+
});
|
|
103
|
+
device.addEventListener("isConnected", () => {
|
|
104
|
+
resetOrientationButton.disabled = !device.isConnected;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
/** @type {HTMLSelectElement} */
|
|
108
|
+
const positionSelect = document.querySelector(".position");
|
|
109
|
+
positionSelect.addEventListener("input", () => {
|
|
110
|
+
/** @type {BS.SensorConfiguration} */
|
|
111
|
+
const configuration = {
|
|
112
|
+
acceleration: 0,
|
|
113
|
+
gravity: 0,
|
|
114
|
+
linearAcceleration: 0,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
switch (positionSelect.value) {
|
|
118
|
+
case "none":
|
|
119
|
+
break;
|
|
120
|
+
case "acceleration":
|
|
121
|
+
configuration.acceleration = sensorRate;
|
|
122
|
+
break;
|
|
123
|
+
case "gravity":
|
|
124
|
+
configuration.gravity = sensorRate;
|
|
125
|
+
break;
|
|
126
|
+
case "linearAcceleration":
|
|
127
|
+
configuration.linearAcceleration = sensorRate;
|
|
128
|
+
break;
|
|
129
|
+
default:
|
|
130
|
+
console.error(`uncaught positionSelect value "${positionSelect.value}"`);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
console.log({ configuration });
|
|
135
|
+
|
|
136
|
+
device.setSensorConfiguration(configuration);
|
|
137
|
+
});
|
|
138
|
+
device.addEventListener("connected", () => {
|
|
139
|
+
positionSelect.querySelectorAll("option").forEach((option) => {
|
|
140
|
+
option.hidden =
|
|
141
|
+
BS.SensorTypes.includes(option.value) &&
|
|
142
|
+
!device.sensorTypes.includes(option.value);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
device.addEventListener("isConnected", () => {
|
|
147
|
+
orientationSelect.disabled = !device.isConnected;
|
|
148
|
+
positionSelect.disabled = !device.isConnected;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
device.addEventListener("getSensorConfiguration", () => {
|
|
152
|
+
let newOrientationSelectValue = "none";
|
|
153
|
+
let newPositionSelectValue = "none";
|
|
154
|
+
|
|
155
|
+
for (const key in device.sensorConfiguration) {
|
|
156
|
+
/** @type {BS.SensorType} */
|
|
157
|
+
const sensorType = key;
|
|
158
|
+
if (device.sensorConfiguration[sensorType] > 0) {
|
|
159
|
+
switch (sensorType) {
|
|
160
|
+
case "gameRotation":
|
|
161
|
+
case "rotation":
|
|
162
|
+
case "orientation":
|
|
163
|
+
case "gyroscope":
|
|
164
|
+
newOrientationSelectValue = sensorType;
|
|
165
|
+
break;
|
|
166
|
+
case "acceleration":
|
|
167
|
+
case "gravity":
|
|
168
|
+
case "linearAcceleration":
|
|
169
|
+
newPositionSelectValue = sensorType;
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
orientationSelect.value = newOrientationSelectValue;
|
|
176
|
+
positionSelect.value = newPositionSelectValue;
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
/** @type {TVector3} */
|
|
180
|
+
const _position = new THREE.Vector3();
|
|
181
|
+
|
|
182
|
+
/** @param {BS.Vector3} position */
|
|
183
|
+
const updatePosition = (position) => {
|
|
184
|
+
_position.copy(position).multiplyScalar(window.positionScalar);
|
|
185
|
+
targetPositionEntity.object3D.position.lerp(
|
|
186
|
+
_position,
|
|
187
|
+
window.interpolationSmoothing
|
|
188
|
+
);
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
device.addEventListener("acceleration", (event) => {
|
|
192
|
+
const acceleration = event.message.acceleration;
|
|
193
|
+
updatePosition(acceleration);
|
|
194
|
+
});
|
|
195
|
+
device.addEventListener("gravity", () => {
|
|
196
|
+
const gravity = event.message.gravity;
|
|
197
|
+
updatePosition(gravity);
|
|
198
|
+
});
|
|
199
|
+
device.addEventListener("linearAcceleration", (event) => {
|
|
200
|
+
const linearAcceleration = event.message.linearAcceleration;
|
|
201
|
+
updatePosition(linearAcceleration);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
/** @type {TQuaternion} */
|
|
205
|
+
const offsetQuaternion = new THREE.Quaternion();
|
|
206
|
+
const resetOrientation = () => {
|
|
207
|
+
offsetQuaternion.copy(_quaternion).invert();
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
/** @type {TQuaternion} */
|
|
211
|
+
const _quaternion = new THREE.Quaternion();
|
|
212
|
+
/** @type {TQuaternion} */
|
|
213
|
+
const targetQuaternion = new THREE.Quaternion();
|
|
214
|
+
/**
|
|
215
|
+
* @param {BS.Quaternion} quaternion
|
|
216
|
+
* @param {boolean} applyOffset
|
|
217
|
+
*/
|
|
218
|
+
const updateQuaternion = (quaternion, applyOffset = false) => {
|
|
219
|
+
_quaternion.copy(quaternion);
|
|
220
|
+
targetQuaternion.copy(_quaternion);
|
|
221
|
+
if (applyOffset) {
|
|
222
|
+
targetQuaternion.premultiply(offsetQuaternion);
|
|
223
|
+
}
|
|
224
|
+
targetRotationEntity.object3D.quaternion.slerp(
|
|
225
|
+
targetQuaternion,
|
|
226
|
+
window.interpolationSmoothing
|
|
227
|
+
);
|
|
228
|
+
};
|
|
229
|
+
device.addEventListener("gameRotation", (event) => {
|
|
230
|
+
let gameRotation = event.message.gameRotation;
|
|
231
|
+
updateQuaternion(gameRotation, true);
|
|
232
|
+
});
|
|
233
|
+
device.addEventListener("rotation", (event) => {
|
|
234
|
+
const rotation = event.message.rotation;
|
|
235
|
+
updateQuaternion(rotation, true);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
/** @type {TVector3} */
|
|
239
|
+
const orientationVector3 = new THREE.Vector3();
|
|
240
|
+
/** @type {TEuler} */
|
|
241
|
+
const orientationEuler = new THREE.Euler(0, 0, 0, "YXZ");
|
|
242
|
+
/** @type {TQuaternion} */
|
|
243
|
+
const orientationQuaternion = new THREE.Quaternion();
|
|
244
|
+
device.addEventListener("orientation", (event) => {
|
|
245
|
+
const orientation = event.message.orientation;
|
|
246
|
+
orientationVector3
|
|
247
|
+
.set(orientation.pitch, orientation.heading, orientation.roll)
|
|
248
|
+
.multiplyScalar(THREE.MathUtils.DEG2RAD);
|
|
249
|
+
orientationEuler.setFromVector3(orientationVector3);
|
|
250
|
+
orientationQuaternion.setFromEuler(orientationEuler);
|
|
251
|
+
updateQuaternion(orientationQuaternion);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
/** @type {TVector3} */
|
|
255
|
+
const gyroscopeVector3 = new THREE.Vector3();
|
|
256
|
+
/** @type {TEuler} */
|
|
257
|
+
const gyroscopeEuler = new THREE.Euler();
|
|
258
|
+
/** @type {TQuaternion} */
|
|
259
|
+
const gyroscopeQuaternion = new THREE.Quaternion();
|
|
260
|
+
device.addEventListener("gyroscope", (event) => {
|
|
261
|
+
const gyroscope = event.message.gyroscope;
|
|
262
|
+
gyroscopeVector3.copy(gyroscope).multiplyScalar(Math.PI / 180);
|
|
263
|
+
gyroscopeEuler.setFromVector3(gyroscopeVector3);
|
|
264
|
+
gyroscopeQuaternion.setFromEuler(gyroscopeEuler);
|
|
265
|
+
updateQuaternion(gyroscopeQuaternion);
|
|
266
|
+
});
|