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.
Files changed (167) hide show
  1. package/assets/3d/anchor.glb +0 -0
  2. package/assets/3d/coin.glb +0 -0
  3. package/assets/3d/glasses.glb +0 -0
  4. package/assets/audio/bounceMedium.wav +0 -0
  5. package/assets/audio/bounceStrong.wav +0 -0
  6. package/assets/audio/bounceWeak.wav +0 -0
  7. package/assets/audio/coin.wav +0 -0
  8. package/assets/audio/getUp.wav +0 -0
  9. package/assets/audio/grab.wav +0 -0
  10. package/assets/audio/kick.wav +0 -0
  11. package/assets/audio/platterFadeIn old.wav +0 -0
  12. package/assets/audio/platterFadeIn.wav +0 -0
  13. package/assets/audio/platterFadeOut.wav +0 -0
  14. package/assets/audio/punch.wav +0 -0
  15. package/assets/audio/punchSqueak.wav +0 -0
  16. package/assets/audio/purr.wav +0 -0
  17. package/assets/audio/purrFadeOut.wav +0 -0
  18. package/assets/audio/release.wav +0 -0
  19. package/assets/audio/splat.wav +0 -0
  20. package/assets/audio/stomp.wav +0 -0
  21. package/build/brilliantsole.cjs +2627 -775
  22. package/build/brilliantsole.cjs.map +1 -1
  23. package/build/brilliantsole.js +2273 -721
  24. package/build/brilliantsole.js.map +1 -1
  25. package/build/brilliantsole.ls.js +2096 -535
  26. package/build/brilliantsole.ls.js.map +1 -1
  27. package/build/brilliantsole.min.js +1 -1
  28. package/build/brilliantsole.min.js.map +1 -1
  29. package/build/brilliantsole.module.d.ts +235 -65
  30. package/build/brilliantsole.module.js +2266 -722
  31. package/build/brilliantsole.module.js.map +1 -1
  32. package/build/brilliantsole.module.min.d.ts +235 -65
  33. package/build/brilliantsole.module.min.js +1 -1
  34. package/build/brilliantsole.module.min.js.map +1 -1
  35. package/build/brilliantsole.node.module.d.ts +229 -62
  36. package/build/brilliantsole.node.module.js +2619 -776
  37. package/build/brilliantsole.node.module.js.map +1 -1
  38. package/build/dts/BS-output.d.ts +10 -0
  39. package/build/dts/BS.d.ts +20 -8
  40. package/build/dts/CameraManager.d.ts +72 -0
  41. package/build/dts/Device.d.ts +46 -13
  42. package/build/dts/DeviceInformationManager.d.ts +4 -4
  43. package/build/dts/DeviceManager.d.ts +2 -0
  44. package/build/dts/FileTransferManager.d.ts +18 -8
  45. package/build/dts/InformationManager.d.ts +2 -0
  46. package/build/dts/TfliteManager.d.ts +22 -2
  47. package/build/dts/WifiManager.d.ts +61 -0
  48. package/build/dts/connection/BaseConnectionManager.d.ts +35 -3
  49. package/build/dts/connection/ClientConnectionManager.d.ts +7 -2
  50. package/build/dts/connection/bluetooth/NobleConnectionManager.d.ts +2 -1
  51. package/build/dts/connection/bluetooth/WebBluetoothConnectionManager.d.ts +1 -0
  52. package/build/dts/connection/bluetooth/bluetoothUUIDs.d.ts +2 -2
  53. package/build/dts/connection/udp/UDPConnectionManager.d.ts +28 -0
  54. package/build/dts/connection/webSocket/WebSocketConnectionManager.d.ts +25 -0
  55. package/build/dts/devicePair/DevicePair.d.ts +5 -5
  56. package/build/dts/scanner/BaseScanner.d.ts +4 -1
  57. package/build/dts/scanner/NobleScanner.d.ts +2 -1
  58. package/build/dts/sensor/MotionSensorDataManager.d.ts +5 -2
  59. package/build/dts/sensor/SensorDataManager.d.ts +5 -4
  60. package/build/dts/server/BaseClient.d.ts +5 -3
  61. package/build/dts/server/ServerUtils.d.ts +1 -1
  62. package/build/dts/server/websocket/WebSocketUtils.d.ts +1 -1
  63. package/build/dts/utils/Console.d.ts +2 -0
  64. package/build/dts/utils/ThrottleUtils.d.ts +2 -0
  65. package/build/dts/vibration/VibrationManager.d.ts +19 -2
  66. package/build/index.d.ts +232 -62
  67. package/build/index.node.d.ts +226 -59
  68. package/examples/3d/scene.html +19 -5
  69. package/examples/3d-generic/index.html +144 -0
  70. package/examples/3d-generic/script.js +266 -0
  71. package/examples/basic/index.html +211 -16
  72. package/examples/basic/script.js +731 -105
  73. package/examples/edge-impulse/script.js +135 -44
  74. package/examples/edge-impulse-test/README.md +11 -0
  75. package/examples/edge-impulse-test/edge-impulse-standalone.js +7228 -0
  76. package/examples/edge-impulse-test/edge-impulse-standalone.wasm +0 -0
  77. package/examples/edge-impulse-test/index.html +75 -0
  78. package/examples/edge-impulse-test/run-impulse.js +135 -0
  79. package/examples/edge-impulse-test/script.js +200 -0
  80. package/examples/gloves/edge-impulse-standalone.js +7228 -0
  81. package/examples/gloves/edge-impulse-standalone.wasm +0 -0
  82. package/examples/gloves/index.html +4 -1
  83. package/examples/gloves/run-impulse.js +135 -0
  84. package/examples/gloves/script.js +367 -51
  85. package/examples/graph/script.js +94 -37
  86. package/examples/punch/index.html +135 -0
  87. package/examples/punch/punch.tflite +0 -0
  88. package/examples/punch/script.js +169 -0
  89. package/examples/server/index.html +98 -22
  90. package/examples/server/script.js +317 -109
  91. package/examples/ukaton-firmware-update/merged-firmware.bin +0 -0
  92. package/examples/utils/aframe/aframe-master.min.js +2 -0
  93. package/examples/utils/aframe/bs-vibration.js +150 -0
  94. package/examples/utils/aframe/force-pushable.js +80 -0
  95. package/examples/utils/aframe/grabbable-anchor.js +46 -0
  96. package/examples/utils/aframe/grabbable-listener.js +31 -0
  97. package/examples/utils/aframe/grabbable-physics-body.js +190 -0
  98. package/examples/utils/aframe/grow-shrink.js +25 -0
  99. package/examples/utils/aframe/hand-punch.js +119 -0
  100. package/examples/utils/aframe/my-obb-collider.js +293 -0
  101. package/examples/utils/aframe/occlude-hand-tracking-controls.js +47 -0
  102. package/examples/utils/aframe/occlude-mesh.js +42 -0
  103. package/examples/utils/aframe/palm-up-detector.js +47 -0
  104. package/examples/utils/aframe/shadow-material.js +20 -0
  105. package/examples/utils/aframe/soft-shadow-light.js +9 -0
  106. package/examples/webxr-2/assets/3d/soccerBall.glb +0 -0
  107. package/examples/webxr-2/assets/audio/shellBounce.wav +0 -0
  108. package/examples/webxr-2/assets/audio/shellHit.wav +0 -0
  109. package/examples/webxr-2/assets/audio/shellKick.wav +0 -0
  110. package/examples/webxr-2/assets/audio/soccerBounce.wav +0 -0
  111. package/examples/webxr-2/assets/audio/soccerKick.mp3 +0 -0
  112. package/examples/webxr-2/assets/images/shellTexture.png +0 -0
  113. package/examples/webxr-2/components/bs-ankle.js +337 -0
  114. package/examples/webxr-2/components/coin.js +84 -0
  115. package/examples/webxr-2/components/custom-wrap.js +17 -0
  116. package/examples/webxr-2/components/goomba.js +3250 -0
  117. package/examples/webxr-2/components/init-shell-material.js +215 -0
  118. package/examples/webxr-2/components/platter.js +172 -0
  119. package/examples/webxr-2/components/shell.js +374 -0
  120. package/examples/webxr-2/components/soccer-ball.js +250 -0
  121. package/examples/webxr-2/components/squashed-goomba.js +249 -0
  122. package/examples/webxr-2/edge-impulse-standalone.js +7228 -0
  123. package/examples/webxr-2/edge-impulse-standalone.wasm +0 -0
  124. package/examples/webxr-2/index.html +996 -0
  125. package/examples/webxr-2/kick.tflite +0 -0
  126. package/examples/webxr-2/kick2.tflite +0 -0
  127. package/examples/webxr-2/run-impulse.js +135 -0
  128. package/examples/webxr-2/script.js +384 -0
  129. package/package.json +2 -1
  130. package/src/.prettierrc +4 -0
  131. package/src/BS.ts +70 -8
  132. package/src/CameraManager.ts +499 -0
  133. package/src/Device.ts +581 -86
  134. package/src/DeviceInformationManager.ts +19 -10
  135. package/src/DeviceManager.ts +85 -25
  136. package/src/FileTransferManager.ts +145 -20
  137. package/src/InformationManager.ts +40 -15
  138. package/src/TfliteManager.ts +171 -25
  139. package/src/WifiManager.ts +323 -0
  140. package/src/connection/BaseConnectionManager.ts +128 -30
  141. package/src/connection/ClientConnectionManager.ts +34 -10
  142. package/src/connection/bluetooth/BluetoothConnectionManager.ts +8 -2
  143. package/src/connection/bluetooth/NobleConnectionManager.ts +147 -41
  144. package/src/connection/bluetooth/WebBluetoothConnectionManager.ts +99 -34
  145. package/src/connection/bluetooth/bluetoothUUIDs.ts +40 -13
  146. package/src/connection/udp/UDPConnectionManager.ts +356 -0
  147. package/src/connection/websocket/WebSocketConnectionManager.ts +282 -0
  148. package/src/devicePair/DevicePair.ts +95 -25
  149. package/src/devicePair/DevicePairPressureSensorDataManager.ts +27 -7
  150. package/src/scanner/BaseScanner.ts +49 -11
  151. package/src/scanner/NobleScanner.ts +76 -14
  152. package/src/sensor/MotionSensorDataManager.ts +21 -6
  153. package/src/sensor/PressureSensorDataManager.ts +37 -8
  154. package/src/sensor/SensorConfigurationManager.ts +73 -22
  155. package/src/sensor/SensorDataManager.ts +104 -23
  156. package/src/server/BaseClient.ts +150 -36
  157. package/src/server/BaseServer.ts +50 -2
  158. package/src/server/ServerUtils.ts +39 -9
  159. package/src/server/udp/UDPServer.ts +73 -22
  160. package/src/server/udp/UDPUtils.ts +9 -2
  161. package/src/server/websocket/WebSocketClient.ts +27 -7
  162. package/src/server/websocket/WebSocketUtils.ts +4 -2
  163. package/src/utils/Console.ts +62 -9
  164. package/src/utils/ParseUtils.ts +24 -5
  165. package/src/utils/ThrottleUtils.ts +62 -0
  166. package/src/utils/Timer.ts +1 -1
  167. package/src/vibration/VibrationManager.ts +166 -40
@@ -0,0 +1,337 @@
1
+ import * as BS from "../../../build/brilliantsole.module.js";
2
+
3
+ AFRAME.registerComponent("bs-ankle", {
4
+ schema: {
5
+ type: {
6
+ default: "generic",
7
+ oneOf: BS.DeviceTypes.slice(),
8
+ },
9
+ name: { default: "" },
10
+ angleThreshold: { default: THREE.MathUtils.degToRad(30) },
11
+ kickDistanceLowerThreshold: { default: 0.4 },
12
+ kickDistanceUpperThreshold: { default: 1 },
13
+ stompDistanceThreshold: { default: 0.3 },
14
+ velocityLength: { default: 2 },
15
+ velocityPitch: { default: THREE.MathUtils.degToRad(40) },
16
+ kickSoundSelector: { default: "#kickAudio" },
17
+ stompSoundSelector: { default: "#stompAudio" },
18
+ },
19
+
20
+ init() {
21
+ window.shells = window.shells || [];
22
+ window.soccerBalls = window.soccerBalls || [];
23
+
24
+ this.kickEuler = new THREE.Euler(0, 0, 0, "YXZ");
25
+
26
+ this.debugCone = this.el.sceneEl.querySelector("#debugCone");
27
+ this.debugText = this.el.sceneEl.querySelector("#debugText");
28
+ this.debug = false;
29
+ this.debugStomp = false;
30
+ this.debugKick = false;
31
+ this.debugGesture = false;
32
+ if (this.debug) {
33
+ this.debugText.setAttribute("visible", "true");
34
+ if (this.debugKick) {
35
+ setInterval(() => {
36
+ this.kick(true);
37
+ }, 100);
38
+ }
39
+ }
40
+
41
+ this.raycaster = new THREE.Raycaster();
42
+ this.ray = new THREE.Vector3(0, -1, 0);
43
+
44
+ this.cameraQuaternion = new THREE.Quaternion();
45
+ this.cameraEuler = new THREE.Euler(0, 0, 0, "YXZ");
46
+ this.cameraPosition = new THREE.Vector3();
47
+
48
+ this.camera = this.el.sceneEl.querySelector("a-camera");
49
+ this.cameraDirection = new THREE.Vector3();
50
+ this.cameraToGoomba = new THREE.Vector3();
51
+
52
+ this.onDeviceIsConnected = this.onDeviceIsConnected.bind(this);
53
+ this.onTfliteInference = this.onTfliteInference.bind(this);
54
+
55
+ BS.DeviceManager.AddEventListener(
56
+ "deviceIsConnected",
57
+ this.onDeviceIsConnected
58
+ );
59
+
60
+ this.kickSound = document.createElement("a-entity");
61
+ this.kickSound.setAttribute("sound", `src: ${this.data.kickSoundSelector}`);
62
+ this.el.sceneEl.appendChild(this.kickSound);
63
+
64
+ this.stompSound = document.createElement("a-entity");
65
+ this.stompSound.setAttribute(
66
+ "sound",
67
+ `src: ${this.data.stompSoundSelector}; volume: 0.8;`
68
+ );
69
+ this.el.sceneEl.appendChild(this.stompSound);
70
+ },
71
+
72
+ playKickSound: function (position) {
73
+ this.kickSound.object3D.position.copy(position);
74
+ this.kickSound.components.sound.playSound();
75
+ },
76
+ playStompSound: function (position) {
77
+ this.stompSound.object3D.position.copy(position);
78
+ this.stompSound.components.sound.playSound();
79
+ },
80
+
81
+ remove: function () {
82
+ BS.DeviceManager.RemoveEventListener(
83
+ "deviceIsConnected",
84
+ this.onDeviceIsConnected
85
+ );
86
+ },
87
+
88
+ /** @param {BS.DeviceManagerEventMap["deviceIsConnected"]} event */
89
+ onDeviceIsConnected(event) {
90
+ const device = event.message.device;
91
+ if (device.type != this.data.type) {
92
+ return;
93
+ }
94
+ if (this.data.name && device.name != this.data.name) {
95
+ return;
96
+ }
97
+ this.device = device;
98
+ // console.log("listening to inferences");
99
+ device.addEventListener("tfliteInference", this.onTfliteInference);
100
+ },
101
+
102
+ /** @param {BS.DeviceEventMap["tfliteInference"]} event */
103
+ onTfliteInference: function (event) {
104
+ const { maxClass, maxValue, timestamp } = event.message.tfliteInference;
105
+ if (this.debug && this.debugGesture) {
106
+ this.debugText.setAttribute("visible", "true");
107
+ this.debugText.setAttribute(
108
+ "value",
109
+ `${maxClass}\n${maxValue.toFixed(3)}`
110
+ );
111
+ }
112
+ switch (maxClass) {
113
+ case "kick":
114
+ this.kick();
115
+ break;
116
+ case "stomp":
117
+ this.stomp();
118
+ break;
119
+ default:
120
+ console.log(`uncaught class "${maxClass}"`);
121
+ break;
122
+ }
123
+ },
124
+
125
+ getFloorMetadata: function () {
126
+ const floorEntities = Array.from(
127
+ this.el.sceneEl.querySelectorAll(`[data-world-mesh="floor"]`)
128
+ ).filter(Boolean);
129
+ const floorObjects = floorEntities.map((entity) => entity.object3D);
130
+
131
+ this.camera.object3D.getWorldPosition(this.cameraPosition);
132
+
133
+ this.raycaster.set(this.cameraPosition, this.ray);
134
+ this.raycaster.near = 0;
135
+ this.raycaster.far = 5;
136
+ const intersections = this.raycaster.intersectObjects(floorObjects, true);
137
+ const intersection = intersections[0];
138
+ if (!intersection) {
139
+ return;
140
+ }
141
+ // console.log("intersection", intersection);
142
+ const { point, object } = intersection;
143
+ const floor = object.el || object.parent.el;
144
+ if (!floor) {
145
+ return;
146
+ }
147
+
148
+ const goombasOnFloor = window.goombas.filter(
149
+ (goomba) => goomba.floor == floor
150
+ );
151
+ // console.log("goombasOnFloor", goombasOnFloor);
152
+
153
+ return { point, floor, goombasOnFloor };
154
+ },
155
+
156
+ kick: function (isDebug) {
157
+ const metadata = this.getFloorMetadata();
158
+ if (!metadata) {
159
+ return;
160
+ }
161
+ const { point, floor, goombasOnFloor } = metadata;
162
+
163
+ this.camera.object3D.getWorldQuaternion(this.cameraQuaternion);
164
+ this.cameraEuler.setFromQuaternion(this.cameraQuaternion);
165
+
166
+ let cameraYaw = this.cameraEuler.y;
167
+ while (cameraYaw < 0) {
168
+ cameraYaw += 2 * Math.PI;
169
+ }
170
+
171
+ const kickOffsetEuler = new THREE.Euler(0, cameraYaw, 0);
172
+ const kickOffset = new THREE.Vector3(0, 0, -0.3);
173
+ kickOffset.applyEuler(kickOffsetEuler);
174
+
175
+ const kickPosition = new THREE.Vector3()
176
+ .addVectors(point, this.cameraPosition)
177
+ .multiplyScalar(0.5)
178
+ .add(kickOffset);
179
+
180
+ // if (goombasOnFloor.length == 0) {
181
+ // //return;
182
+ // }
183
+ // if (!window.shells[0].body && !window.soccerBalls[0].body) {
184
+ // //return;
185
+ // }
186
+
187
+ const goombaPosition = new THREE.Vector3();
188
+
189
+ const goombasToKick = [
190
+ ...goombasOnFloor,
191
+ ...window.shells,
192
+ ...window.soccerBalls,
193
+ ].filter((goomba) => {
194
+ if (goomba.el.components.shell) {
195
+ if (!goomba.el.components.shell.body) {
196
+ return false;
197
+ }
198
+ }
199
+ if (goomba.el.components["soccer-ball"]) {
200
+ if (!goomba.el.components["soccer-ball"].body) {
201
+ return false;
202
+ }
203
+ }
204
+
205
+ goomba.el.object3D.getWorldPosition(goombaPosition);
206
+ // const v = new THREE.Vector3();
207
+ // v.copy(goombaPosition);
208
+ // this.camera.object3D.worldToLocal(v);
209
+ this.cameraToGoomba.subVectors(this.cameraPosition, goombaPosition);
210
+ this.cameraToGoomba.y = 0;
211
+ const distance = this.cameraToGoomba.length();
212
+ if (distance > this.data.kickDistanceUpperThreshold) {
213
+ if (this.debugKick) {
214
+ this.debugText.setAttribute("value", `far ${distance.toFixed(2)}`);
215
+ }
216
+ return false;
217
+ }
218
+ this.cameraToGoomba.normalize();
219
+ let goombaYaw = Math.atan2(this.cameraToGoomba.x, this.cameraToGoomba.z);
220
+ while (goombaYaw < 0) {
221
+ goombaYaw += 2 * Math.PI;
222
+ }
223
+
224
+ if (distance > this.data.kickDistanceLowerThreshold) {
225
+ const angle = Math.abs(cameraYaw - goombaYaw);
226
+ if (this.debugKick) {
227
+ this.debugText.setAttribute(
228
+ "value",
229
+ [
230
+ `d: ${distance.toFixed(3)}`,
231
+ `c: ${THREE.MathUtils.radToDeg(cameraYaw).toFixed(0)}`,
232
+ `g: ${THREE.MathUtils.radToDeg(goombaYaw).toFixed(0)}`,
233
+ `a: ${THREE.MathUtils.radToDeg(angle).toFixed(0)}`,
234
+ ].join("\n")
235
+ );
236
+ }
237
+ if (angle > this.data.angleThreshold) {
238
+ return false;
239
+ }
240
+ } else {
241
+ if (this.debugKick) {
242
+ this.debugText.setAttribute("value", `${distance.toFixed(2)}`);
243
+ }
244
+ }
245
+
246
+ this.kickEuler.set(0, 0, 0);
247
+ this.kickEuler.x = this.data.velocityPitch;
248
+ if (false) {
249
+ this.kickEuler.y = goombaYaw;
250
+ } else {
251
+ this.kickEuler.y = cameraYaw;
252
+ }
253
+ const velocity = new THREE.Vector3(0, 0, -this.data.velocityLength);
254
+ velocity.applyEuler(this.kickEuler);
255
+ if (this.debugKick) {
256
+ this.debugCone.setAttribute("visible", "true");
257
+ this.debugCone.object3D.position.copy(goombaPosition);
258
+ this.debugCone.object3D.rotation.copy(this.kickEuler);
259
+ }
260
+ if (isDebug) {
261
+ return false;
262
+ }
263
+ goomba.el.emit("kick", { velocity, yaw: this.kickEuler.y });
264
+
265
+ return true;
266
+ });
267
+ // console.log("goombasToKick", goombasToKick);
268
+
269
+ if (!isDebug) {
270
+ if (goombasToKick.length > 0) {
271
+ /** @type {BS.VibrationWaveformEffect} */
272
+ let waveformEffect = "strongClick100";
273
+ this.vibrate(waveformEffect);
274
+ } else {
275
+ this.playKickSound(kickPosition);
276
+ }
277
+ }
278
+ },
279
+ stomp: function () {
280
+ /** @type {BS.VibrationWaveformEffect} */
281
+ let waveformEffect = "transitionRampDownMediumSmooth1_100";
282
+ this.vibrate(waveformEffect);
283
+
284
+ const metadata = this.getFloorMetadata();
285
+ if (!metadata) {
286
+ return;
287
+ }
288
+ let goombas = window.goombas.filter((goomba) => goomba.floor);
289
+ const { point, floor, goombasOnFloor } = metadata;
290
+ if (false) {
291
+ goombas = goombasOnFloor;
292
+ }
293
+ // console.log(point);
294
+ this.playStompSound(point);
295
+
296
+ [...goombas, ...window.shells, ...window.soccerBalls].forEach((goomba) => {
297
+ this.cameraToGoomba.subVectors(
298
+ goomba.el.object3D.position,
299
+ this.cameraPosition
300
+ );
301
+ this.cameraToGoomba.y = 0;
302
+ const direction = this.cameraToGoomba;
303
+ const distance = direction.length();
304
+ direction.normalize();
305
+ const yaw = Math.atan2(direction.x, direction.z);
306
+ let kill = false;
307
+ if (this.debugStomp) {
308
+ this.debugText.setAttribute("value", `${distance.toFixed(2)}`);
309
+ }
310
+ if (goombasOnFloor.includes(goomba)) {
311
+ kill = distance <= this.data.stompDistanceThreshold;
312
+ }
313
+ goomba.el.emit("stomp", { distance, yaw, kill });
314
+ });
315
+ },
316
+
317
+ vibrate: function (waveformEffect) {
318
+ /** @type {BS.Device?} */
319
+ const device = this.device;
320
+ if (!device?.isConnected) {
321
+ // console.log(
322
+ // `${this.side} ${this.type} not connected`,
323
+ // device,
324
+ // this.devicePair
325
+ // );
326
+ return;
327
+ }
328
+
329
+ device.triggerVibration([
330
+ {
331
+ type: "waveformEffect",
332
+ locations: ["rear"],
333
+ segments: [{ effect: waveformEffect }],
334
+ },
335
+ ]);
336
+ },
337
+ });
@@ -0,0 +1,84 @@
1
+ AFRAME.registerComponent("coin", {
2
+ schema: {
3
+ template: { default: "#coinTemplate", type: "selector" },
4
+ lifetime: { default: 800 },
5
+ },
6
+ init: function () {
7
+ this.el.addEventListener("loaded", () => {
8
+ const template = this.data.template.content
9
+ .querySelector("a-entity")
10
+ .cloneNode(true);
11
+ template.classList.forEach((_class) => {
12
+ //console.log(`adding class ${_class}`);
13
+ this.el.classList.add(_class);
14
+ });
15
+ Array.from(template.children).forEach((entity) => {
16
+ this.el.appendChild(entity);
17
+ });
18
+ this.rotationEntity = this.el.querySelector(".rotation");
19
+ this.positionEntity = this.el.querySelector(".position");
20
+ this.scaleEntity = this.el.querySelector(".scale");
21
+ this.template = template;
22
+
23
+ this.originalRotation = this.rotationEntity.object3D.rotation.clone();
24
+ this.originalPosition = this.rotationEntity.object3D.position.clone();
25
+ this.originalScale = this.rotationEntity.object3D.scale.clone();
26
+ });
27
+ },
28
+
29
+ start: function () {
30
+ this.sound = this.el.sceneEl.components["pool__coinsound"].requestEntity();
31
+ this.sound.play();
32
+ this.sound.object3D.position.copy(this.el.object3D.position);
33
+ this.sound.components.sound.playSound();
34
+
35
+ this.rotationEntity.object3D.rotation.copy(this.originalRotation);
36
+ this.rotationEntity.removeAttribute("animation__rot");
37
+ this.rotationEntity.setAttribute("animation__rot", {
38
+ property: "rotation",
39
+ to: `0 180 0`,
40
+ dur: this.data.lifetime * 0.7,
41
+ easing: "easeInOutBack",
42
+ });
43
+
44
+ const offset = new THREE.Vector3(0, 0.14, 0);
45
+ this.positionEntity.object3D.position.copy(this.originalPosition);
46
+ this.positionEntity.removeAttribute("animation__pos");
47
+ this.positionEntity.setAttribute("animation__pos", {
48
+ property: "position",
49
+ to: offset
50
+ .toArray()
51
+ .map((value) => (value < 0.0001 ? 0 : value))
52
+ .join(" "),
53
+ dur: this.data.lifetime * 0.9,
54
+ loop: 0,
55
+ dir: "alternate",
56
+ easing: "easeOutBack",
57
+ });
58
+ this.scaleEntity.object3D.scale.copy(this.originalScale);
59
+ this.scaleEntity.removeAttribute("animation__scale");
60
+ this.scaleEntity.setAttribute("animation__scale", {
61
+ property: "scale",
62
+ from: `0 0 0`,
63
+ to: `1 1 1`,
64
+ dur: this.data.lifetime * 0.2,
65
+ easing: "easeOutBack",
66
+ });
67
+
68
+ setTimeout(() => {
69
+ this.removeSelf();
70
+ }, this.data.lifetime);
71
+ },
72
+
73
+ removeSelf: function () {
74
+ this.rotationEntity.removeAttribute("animation__rot");
75
+ this.positionEntity.removeAttribute("animation__pos");
76
+ this.scaleEntity.removeAttribute("animation__scale");
77
+ this.el.sceneEl.components["pool__coinsound"].returnEntity(this.sound);
78
+ this.el.sceneEl.components["pool__coin"].returnEntity(this.el);
79
+ },
80
+
81
+ remove: function () {
82
+ this.removeSelf();
83
+ },
84
+ });
@@ -0,0 +1,17 @@
1
+ AFRAME.registerComponent("custom-wrap", {
2
+ init: function () {
3
+ this.el.addEventListener("materialtextureloaded", () => {
4
+ const mesh = this.el.getObject3D("mesh");
5
+ console.log(mesh.material.map);
6
+ if (!mesh) return;
7
+ const material = mesh.material;
8
+ if (material.map) {
9
+ const texture = material.map;
10
+ texture.wrapS = THREE.MirroredRepeatWrapping;
11
+ texture.wrapT = THREE.MirroredRepeatWrapping;
12
+ texture.needsUpdate = true;
13
+ console.log("wrapping", texture);
14
+ }
15
+ });
16
+ },
17
+ });