cubing 0.63.2 → 0.63.3

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 (62) hide show
  1. package/dist/bin/chunks/{chunk-52ODPET6.js → chunk-OI3YIXMQ.js} +2 -2
  2. package/dist/bin/order.js +1 -1
  3. package/dist/bin/puzzle-geometry-bin.js +1 -1
  4. package/dist/bin/scramble.js +1 -1
  5. package/dist/lib/cubing/{PuzzleLoader-R-puDLmC.d.ts → PuzzleLoader-Bp8zngUn.d.ts} +10 -0
  6. package/dist/lib/cubing/alg/index.d.ts +2 -2
  7. package/dist/lib/cubing/bluetooth/index.d.ts +2 -2
  8. package/dist/lib/cubing/chunks/chunk-44CFF24P.js +239 -0
  9. package/dist/lib/cubing/chunks/chunk-44CFF24P.js.map +7 -0
  10. package/dist/lib/cubing/chunks/chunk-DQGYYYHZ.js +1180 -0
  11. package/dist/lib/cubing/chunks/chunk-DQGYYYHZ.js.map +7 -0
  12. package/dist/lib/cubing/chunks/chunk-FTE3QI5X.js +1074 -0
  13. package/dist/lib/cubing/chunks/chunk-FTE3QI5X.js.map +7 -0
  14. package/dist/lib/cubing/chunks/chunk-FZBKZ5ZB.js +265 -0
  15. package/dist/lib/cubing/chunks/chunk-FZBKZ5ZB.js.map +7 -0
  16. package/dist/lib/cubing/chunks/chunk-OUM32GEA.js +239 -0
  17. package/dist/lib/cubing/chunks/chunk-OUM32GEA.js.map +7 -0
  18. package/dist/lib/cubing/chunks/chunk-SGJ5WPE4.js +1074 -0
  19. package/dist/lib/cubing/chunks/chunk-SGJ5WPE4.js.map +7 -0
  20. package/dist/lib/cubing/chunks/chunk-TAVR35KU.js +265 -0
  21. package/dist/lib/cubing/chunks/chunk-TAVR35KU.js.map +7 -0
  22. package/dist/lib/cubing/chunks/chunk-VRTKWZPL.js +10084 -0
  23. package/dist/lib/cubing/chunks/chunk-VRTKWZPL.js.map +7 -0
  24. package/dist/lib/cubing/chunks/chunk-VSMFYTG6.js +10086 -0
  25. package/dist/lib/cubing/chunks/chunk-VSMFYTG6.js.map +7 -0
  26. package/dist/lib/cubing/chunks/inside-IHWQVDVU.js +564 -0
  27. package/dist/lib/cubing/chunks/inside-IHWQVDVU.js.map +7 -0
  28. package/dist/lib/cubing/chunks/inside-L2JI2BEY.js +564 -0
  29. package/dist/lib/cubing/chunks/inside-L2JI2BEY.js.map +7 -0
  30. package/dist/lib/cubing/chunks/search-dynamic-sgs-side-events-MXHP7O4R.js +1890 -0
  31. package/dist/lib/cubing/chunks/search-dynamic-sgs-side-events-MXHP7O4R.js.map +7 -0
  32. package/dist/lib/cubing/chunks/search-dynamic-sgs-side-events-XFECDWOF.js +1890 -0
  33. package/dist/lib/cubing/chunks/search-dynamic-sgs-side-events-XFECDWOF.js.map +7 -0
  34. package/dist/lib/cubing/chunks/search-dynamic-sgs-unofficial-CM33KT7L.js +1267 -0
  35. package/dist/lib/cubing/chunks/search-dynamic-sgs-unofficial-CM33KT7L.js.map +7 -0
  36. package/dist/lib/cubing/chunks/search-dynamic-sgs-unofficial-Q4LLHL2O.js +1267 -0
  37. package/dist/lib/cubing/chunks/search-dynamic-sgs-unofficial-Q4LLHL2O.js.map +7 -0
  38. package/dist/lib/cubing/chunks/search-dynamic-solve-4x4x4-COSEVJBV.js +2922 -0
  39. package/dist/lib/cubing/chunks/search-dynamic-solve-4x4x4-COSEVJBV.js.map +7 -0
  40. package/dist/lib/cubing/chunks/search-dynamic-solve-4x4x4-NANDMURR.js +2922 -0
  41. package/dist/lib/cubing/chunks/search-dynamic-solve-4x4x4-NANDMURR.js.map +7 -0
  42. package/dist/lib/cubing/chunks/twisty-dynamic-3d-5NZRNZ7C.js +1881 -0
  43. package/dist/lib/cubing/chunks/twisty-dynamic-3d-5NZRNZ7C.js.map +7 -0
  44. package/dist/lib/cubing/chunks/twisty-dynamic-3d-VGZIQ64W.js +1927 -0
  45. package/dist/lib/cubing/chunks/twisty-dynamic-3d-VGZIQ64W.js.map +7 -0
  46. package/dist/lib/cubing/chunks/twisty-dynamic-3d-XLUOPCLN.js +1881 -0
  47. package/dist/lib/cubing/chunks/twisty-dynamic-3d-XLUOPCLN.js.map +7 -0
  48. package/dist/lib/cubing/{events-IfSwQLYm.d.ts → events-CewDA1aS.d.ts} +1 -1
  49. package/dist/lib/cubing/{index-btIxbuNp.d.ts → index-DabjED-w.d.ts} +1 -1
  50. package/dist/lib/cubing/kpuzzle/index.d.ts +1 -1
  51. package/dist/lib/cubing/notation/index.d.ts +1 -1
  52. package/dist/lib/cubing/protocol/index.d.ts +1 -1
  53. package/dist/lib/cubing/puzzle-geometry/index.d.ts +2 -2
  54. package/dist/lib/cubing/puzzles/index.d.ts +1 -1
  55. package/dist/lib/cubing/scramble/index.d.ts +2 -2
  56. package/dist/lib/cubing/search/index.d.ts +3 -3
  57. package/dist/lib/cubing/stream/index.d.ts +3 -3
  58. package/dist/lib/cubing/twisty/index.d.ts +2 -2
  59. package/dist/lib/cubing/twisty/index.js +37 -4
  60. package/dist/lib/cubing/twisty/index.js.map +3 -3
  61. package/package.json +1 -1
  62. /package/dist/bin/chunks/{chunk-52ODPET6.js.map → chunk-OI3YIXMQ.js.map} +0 -0
@@ -0,0 +1,1881 @@
1
+ import {
2
+ TAU,
3
+ bulk3DCode,
4
+ cube3x3x3,
5
+ getFaceletStickeringMask,
6
+ haveStartedSharingRenderers,
7
+ hintFaceletStyles
8
+ } from "./chunk-VSMFYTG6.js";
9
+ import "./chunk-RINY3U6G.js";
10
+ import {
11
+ Move
12
+ } from "./chunk-O6HEZXGY.js";
13
+
14
+ // src/cubing/twisty/views/3D/puzzles/Cube3D.ts
15
+ import { BackSide, DoubleSide, FrontSide } from "three/src/constants.js";
16
+ import { BufferAttribute } from "three/src/core/BufferAttribute.js";
17
+ import { BufferGeometry } from "three/src/core/BufferGeometry.js";
18
+ import { Object3D } from "three/src/core/Object3D.js";
19
+ import { BoxGeometry } from "three/src/geometries/BoxGeometry.js";
20
+ import { TextureLoader } from "three/src/loaders/TextureLoader.js";
21
+ import { MeshBasicMaterial } from "three/src/materials/MeshBasicMaterial.js";
22
+ import { Color } from "three/src/math/Color.js";
23
+ import { Euler } from "three/src/math/Euler.js";
24
+ import { Matrix4 } from "three/src/math/Matrix4.js";
25
+ import { Quaternion } from "three/src/math/Quaternion.js";
26
+ import { Vector2 } from "three/src/math/Vector2.js";
27
+ import { Vector3 } from "three/src/math/Vector3.js";
28
+ import { Group } from "three/src/objects/Group.js";
29
+ import { Mesh } from "three/src/objects/Mesh.js";
30
+
31
+ // src/cubing/twisty/controllers/easing.ts
32
+ function smootherStep(x) {
33
+ return x * x * x * (10 - x * (15 - 6 * x));
34
+ }
35
+
36
+ // src/cubing/twisty/views/3D/puzzles/Cube3D.ts
37
+ var svgLoader = new TextureLoader();
38
+ var ignoredMaterial = new MeshBasicMaterial({
39
+ color: new Color(6710886).convertLinearToSRGB()
40
+ });
41
+ var ignoredMaterialHint = new MeshBasicMaterial({
42
+ color: new Color(13421772).convertLinearToSRGB(),
43
+ side: BackSide,
44
+ transparent: true,
45
+ opacity: 0.75
46
+ });
47
+ var invisibleMaterial = new MeshBasicMaterial({
48
+ visible: false
49
+ });
50
+ var orientedMaterial = new MeshBasicMaterial({
51
+ color: 4513228
52
+ });
53
+ var orientedMaterialHint = new MeshBasicMaterial({
54
+ color: 4513228,
55
+ side: BackSide,
56
+ transparent: true,
57
+ opacity: 0.5
58
+ });
59
+ var experimentalOriented2Material = new MeshBasicMaterial({
60
+ color: 16776618
61
+ });
62
+ var experimentalOriented2MaterialHint = new MeshBasicMaterial({
63
+ color: 16775545,
64
+ side: BackSide,
65
+ transparent: true,
66
+ opacity: 0.5
67
+ });
68
+ var mysteryMaterial = new MeshBasicMaterial({
69
+ color: 15911883
70
+ });
71
+ var mysterMaterialHint = new MeshBasicMaterial({
72
+ color: 15911883,
73
+ side: BackSide,
74
+ transparent: true,
75
+ opacity: 0.5
76
+ });
77
+ var AxisInfo = class {
78
+ constructor(vector, fromZ, color, dimColor, hintOpacityScale, options) {
79
+ this.vector = vector;
80
+ this.fromZ = fromZ;
81
+ this.color = color;
82
+ this.dimColor = dimColor;
83
+ this.hintOpacityScale = hintOpacityScale;
84
+ const colorLinearSRGB = new Color(color).convertLinearToSRGB();
85
+ const dimColorLinearSRGB = new Color(dimColor).convertLinearToSRGB();
86
+ this.stickerMaterial = {
87
+ regular: new MeshBasicMaterial({
88
+ color: colorLinearSRGB,
89
+ side: FrontSide
90
+ // TODO: set to `DoubleSide` when hint facelets are disabled.
91
+ }),
92
+ dim: new MeshBasicMaterial({
93
+ color: dimColorLinearSRGB,
94
+ side: FrontSide
95
+ // TODO: set to `DoubleSide` when hint facelets are disabled.
96
+ }),
97
+ oriented: orientedMaterial,
98
+ experimentalOriented2: experimentalOriented2Material,
99
+ ignored: ignoredMaterial,
100
+ invisible: invisibleMaterial,
101
+ mystery: mysteryMaterial
102
+ };
103
+ this.hintStickerMaterial = {
104
+ regular: new MeshBasicMaterial({
105
+ color: new Color(options?.hintColor ?? color).convertLinearToSRGB(),
106
+ side: BackSide,
107
+ transparent: true,
108
+ opacity: 0.5 * hintOpacityScale
109
+ }),
110
+ dim: new MeshBasicMaterial({
111
+ color: new Color(
112
+ options?.hintDimColor ?? dimColor
113
+ ).convertLinearToSRGB(),
114
+ side: BackSide,
115
+ transparent: true,
116
+ opacity: 0.5 * hintOpacityScale
117
+ }),
118
+ oriented: orientedMaterialHint,
119
+ experimentalOriented2: experimentalOriented2MaterialHint,
120
+ ignored: ignoredMaterialHint,
121
+ invisible: invisibleMaterial,
122
+ mystery: mysterMaterialHint
123
+ };
124
+ }
125
+ stickerMaterial;
126
+ hintStickerMaterial;
127
+ };
128
+ var axesInfo = [
129
+ new AxisInfo(
130
+ new Vector3(0, 1, 0),
131
+ new Euler(-TAU / 4, 0, 0),
132
+ 16777215,
133
+ 14540253,
134
+ 1.25
135
+ ),
136
+ new AxisInfo(
137
+ new Vector3(-1, 0, 0),
138
+ new Euler(0, -TAU / 4, 0),
139
+ 16750848,
140
+ 8934656,
141
+ 1,
142
+ { hintDimColor: 8930304 }
143
+ ),
144
+ new AxisInfo(
145
+ new Vector3(0, 0, 1),
146
+ new Euler(0, 0, 0),
147
+ 65280,
148
+ 34816,
149
+ 1,
150
+ { hintDimColor: 39168 }
151
+ ),
152
+ new AxisInfo(
153
+ new Vector3(1, 0, 0),
154
+ new Euler(0, TAU / 4, 0),
155
+ 16711680,
156
+ 6684672,
157
+ 1,
158
+ { hintDimColor: 6684672 }
159
+ ),
160
+ new AxisInfo(
161
+ new Vector3(0, 0, -1),
162
+ new Euler(0, TAU / 2, 0),
163
+ 2254591,
164
+ 1127304,
165
+ 0.75,
166
+ { hintDimColor: 6246 }
167
+ ),
168
+ new AxisInfo(
169
+ new Vector3(0, -1, 0),
170
+ new Euler(TAU / 4, 0, 0),
171
+ 16776960,
172
+ 8947712,
173
+ 1.25,
174
+ { hintDimColor: 14540032 }
175
+ )
176
+ ];
177
+ var face = {
178
+ U: 0,
179
+ L: 1,
180
+ F: 2,
181
+ R: 3,
182
+ B: 4,
183
+ D: 5
184
+ };
185
+ var familyToAxis = {
186
+ U: face["U"],
187
+ u: face["U"],
188
+ Uw: face["U"],
189
+ Uv: face["U"],
190
+ y: face["U"],
191
+ L: face["L"],
192
+ l: face["L"],
193
+ Lw: face["L"],
194
+ Lv: face["L"],
195
+ M: face["L"],
196
+ F: face["F"],
197
+ f: face["F"],
198
+ Fw: face["F"],
199
+ Fv: face["F"],
200
+ S: face["F"],
201
+ z: face["F"],
202
+ R: face["R"],
203
+ r: face["R"],
204
+ Rw: face["R"],
205
+ Rv: face["R"],
206
+ x: face["R"],
207
+ B: face["B"],
208
+ b: face["B"],
209
+ Bw: face["B"],
210
+ Bv: face["B"],
211
+ D: face["D"],
212
+ d: face["D"],
213
+ Dw: face["D"],
214
+ Dv: face["D"],
215
+ E: face["D"]
216
+ };
217
+ var cubieDimensions = {
218
+ // stickerWidth: 0.85, // Now `faceletScale` in options.
219
+ stickerElevation: 0.503,
220
+ foundationWidth: 1,
221
+ hintStickerElevation: 1.45
222
+ };
223
+ var EXPERIMENTAL_PICTURE_CUBE_HINT_ELEVATION = 2;
224
+ var cube3DOptionsDefaults = {
225
+ showMainStickers: true,
226
+ hintFacelets: "floating",
227
+ showFoundation: true,
228
+ experimentalStickeringMask: void 0,
229
+ foundationSprite: null,
230
+ hintSprite: null,
231
+ initialHintFaceletsAnimation: "auto",
232
+ faceletScale: "auto"
233
+ };
234
+ var DEFAULT_STICKER_SCALE = 0.85;
235
+ function getFaceletScale(options) {
236
+ if (typeof options.faceletScale === "undefined" || options.faceletScale === "auto") {
237
+ return DEFAULT_STICKER_SCALE;
238
+ }
239
+ return options.faceletScale;
240
+ }
241
+ var blackMesh = new MeshBasicMaterial({
242
+ color: 0,
243
+ opacity: 1,
244
+ transparent: true
245
+ });
246
+ var blackTranslucentMesh = new MeshBasicMaterial({
247
+ color: 0,
248
+ opacity: 0.3,
249
+ transparent: true
250
+ });
251
+ var CubieDef = class {
252
+ // stickerFaceNames can be e.g. ["U", "F", "R"], "UFR" if every face is a single letter.
253
+ constructor(orbit, stickerFaceNames, q) {
254
+ this.orbit = orbit;
255
+ const individualStickerFaceNames = typeof stickerFaceNames === "string" ? stickerFaceNames.split("") : stickerFaceNames;
256
+ this.stickerFaces = individualStickerFaceNames.map((s) => face[s]);
257
+ this.matrix = new Matrix4();
258
+ this.matrix.setPosition(firstPiecePosition[orbit]);
259
+ this.matrix.premultiply(new Matrix4().makeRotationFromQuaternion(q));
260
+ }
261
+ matrix;
262
+ stickerFaces;
263
+ };
264
+ function t(v, t4) {
265
+ return new Quaternion().setFromAxisAngle(v, TAU * t4 / 4);
266
+ }
267
+ var r = {
268
+ O: new Vector3(0, 0, 0),
269
+ U: new Vector3(0, -1, 0),
270
+ L: new Vector3(1, 0, 0),
271
+ F: new Vector3(0, 0, -1),
272
+ R: new Vector3(-1, 0, 0),
273
+ B: new Vector3(0, 0, 1),
274
+ D: new Vector3(0, 1, 0)
275
+ };
276
+ var firstPiecePosition = {
277
+ EDGES: new Vector3(0, 1, 1),
278
+ CORNERS: new Vector3(1, 1, 1),
279
+ CENTERS: new Vector3(0, 1, 0)
280
+ };
281
+ var orientationRotation = {
282
+ EDGES: [0, 1].map(
283
+ (i) => new Matrix4().makeRotationAxis(
284
+ firstPiecePosition["EDGES"].clone().normalize(),
285
+ -i * TAU / 2
286
+ )
287
+ ),
288
+ CORNERS: [0, 1, 2].map(
289
+ (i) => new Matrix4().makeRotationAxis(
290
+ firstPiecePosition["CORNERS"].clone().normalize(),
291
+ -i * TAU / 3
292
+ )
293
+ ),
294
+ CENTERS: [0, 1, 2, 3].map(
295
+ (i) => new Matrix4().makeRotationAxis(
296
+ firstPiecePosition["CENTERS"].clone().normalize(),
297
+ -i * TAU / 4
298
+ )
299
+ )
300
+ };
301
+ var cubieStickerOrder = [face["U"], face["F"], face["R"]];
302
+ var pieceDefs = {
303
+ EDGES: [
304
+ new CubieDef("EDGES", "UF", t(r.O, 0)),
305
+ new CubieDef("EDGES", "UR", t(r.U, 3)),
306
+ new CubieDef("EDGES", "UB", t(r.U, 2)),
307
+ new CubieDef("EDGES", "UL", t(r.U, 1)),
308
+ new CubieDef("EDGES", "DF", t(r.F, 2)),
309
+ new CubieDef("EDGES", "DR", t(r.F, 2).premultiply(t(r.D, 1))),
310
+ new CubieDef("EDGES", "DB", t(r.F, 2).premultiply(t(r.D, 2))),
311
+ new CubieDef("EDGES", "DL", t(r.F, 2).premultiply(t(r.D, 3))),
312
+ new CubieDef("EDGES", "FR", t(r.U, 3).premultiply(t(r.R, 3))),
313
+ new CubieDef("EDGES", "FL", t(r.U, 1).premultiply(t(r.R, 3))),
314
+ new CubieDef("EDGES", "BR", t(r.U, 3).premultiply(t(r.R, 1))),
315
+ new CubieDef("EDGES", "BL", t(r.U, 1).premultiply(t(r.R, 1)))
316
+ ],
317
+ CORNERS: [
318
+ new CubieDef("CORNERS", "UFR", t(r.O, 0)),
319
+ new CubieDef("CORNERS", "URB", t(r.U, 3)),
320
+ new CubieDef("CORNERS", "UBL", t(r.U, 2)),
321
+ new CubieDef("CORNERS", "ULF", t(r.U, 1)),
322
+ new CubieDef("CORNERS", "DRF", t(r.F, 2).premultiply(t(r.D, 1))),
323
+ new CubieDef("CORNERS", "DFL", t(r.F, 2).premultiply(t(r.D, 0))),
324
+ new CubieDef("CORNERS", "DLB", t(r.F, 2).premultiply(t(r.D, 3))),
325
+ new CubieDef("CORNERS", "DBR", t(r.F, 2).premultiply(t(r.D, 2)))
326
+ ],
327
+ CENTERS: [
328
+ new CubieDef("CENTERS", "U", t(r.O, 0)),
329
+ new CubieDef("CENTERS", "L", t(r.R, 3).premultiply(t(r.U, 1))),
330
+ new CubieDef("CENTERS", "F", t(r.R, 3)),
331
+ new CubieDef("CENTERS", "R", t(r.R, 3).premultiply(t(r.D, 1))),
332
+ new CubieDef("CENTERS", "B", t(r.R, 3).premultiply(t(r.D, 2))),
333
+ new CubieDef("CENTERS", "D", t(r.R, 2))
334
+ ]
335
+ };
336
+ var CUBE_SCALE = 1 / 3;
337
+ var pictureStickerCoords = {
338
+ EDGES: [
339
+ [
340
+ [0, 4, 6],
341
+ [0, 4, 5]
342
+ ],
343
+ [
344
+ [3, 5, 7],
345
+ [0, 7, 5]
346
+ ],
347
+ [
348
+ [2, 4, 8],
349
+ [0, 10, 5]
350
+ ],
351
+ [
352
+ [1, 3, 7],
353
+ [0, 1, 5]
354
+ ],
355
+ [
356
+ [2, 4, 2],
357
+ [2, 4, 3]
358
+ ],
359
+ [
360
+ [3, 5, 1],
361
+ [2, 7, 3]
362
+ ],
363
+ [
364
+ [0, 4, 0],
365
+ [2, 10, 3]
366
+ ],
367
+ [
368
+ [1, 3, 1],
369
+ [2, 1, 3]
370
+ ],
371
+ [
372
+ [3, 5, 4],
373
+ [3, 6, 4]
374
+ ],
375
+ [
376
+ [1, 3, 4],
377
+ [1, 2, 4]
378
+ ],
379
+ [
380
+ [1, 9, 4],
381
+ [1, 8, 4]
382
+ ],
383
+ [
384
+ [3, 11, 4],
385
+ [3, 0, 4]
386
+ ]
387
+ ],
388
+ CORNERS: [
389
+ [
390
+ [0, 5, 6],
391
+ [0, 5, 5],
392
+ [0, 6, 5]
393
+ ],
394
+ [
395
+ [3, 5, 8],
396
+ [0, 8, 5],
397
+ [0, 9, 5]
398
+ ],
399
+ [
400
+ [2, 3, 8],
401
+ [0, 11, 5],
402
+ [0, 0, 5]
403
+ ],
404
+ [
405
+ [1, 3, 6],
406
+ [0, 2, 5],
407
+ [0, 3, 5]
408
+ ],
409
+ [
410
+ [3, 5, 2],
411
+ [2, 6, 3],
412
+ [2, 5, 3]
413
+ ],
414
+ [
415
+ [2, 3, 2],
416
+ [2, 3, 3],
417
+ [2, 2, 3]
418
+ ],
419
+ [
420
+ [1, 3, 0],
421
+ [2, 0, 3],
422
+ [2, 11, 3]
423
+ ],
424
+ [
425
+ [0, 5, 0],
426
+ [2, 9, 3],
427
+ [2, 8, 3]
428
+ ]
429
+ ],
430
+ CENTERS: [
431
+ [[0, 4, 7]],
432
+ [[0, 1, 4]],
433
+ [[0, 4, 4]],
434
+ [[0, 7, 4]],
435
+ [[0, 10, 4]],
436
+ [[0, 4, 1]]
437
+ ]
438
+ };
439
+ var sharedCubieFoundationGeometryCache = null;
440
+ function sharedCubieFoundationGeometry() {
441
+ return sharedCubieFoundationGeometryCache ?? (sharedCubieFoundationGeometryCache = new BoxGeometry(
442
+ cubieDimensions.foundationWidth,
443
+ cubieDimensions.foundationWidth,
444
+ cubieDimensions.foundationWidth
445
+ ));
446
+ }
447
+ function newStickerGeometry() {
448
+ const r2 = new BufferGeometry();
449
+ const half = 0.5;
450
+ r2.setAttribute(
451
+ "position",
452
+ new BufferAttribute(
453
+ new Float32Array([
454
+ half,
455
+ half,
456
+ 0,
457
+ -half,
458
+ half,
459
+ 0,
460
+ half,
461
+ -half,
462
+ 0,
463
+ -half,
464
+ half,
465
+ 0,
466
+ -half,
467
+ -half,
468
+ 0,
469
+ half,
470
+ -half,
471
+ 0
472
+ ]),
473
+ 3
474
+ )
475
+ );
476
+ r2.setAttribute(
477
+ "uv",
478
+ new BufferAttribute(
479
+ new Float32Array([
480
+ 1,
481
+ 1,
482
+ 0,
483
+ 1,
484
+ 1,
485
+ 0,
486
+ 0,
487
+ 1,
488
+ 0,
489
+ 0,
490
+ 1,
491
+ 0,
492
+ 0,
493
+ 1,
494
+ 0,
495
+ 0,
496
+ 1,
497
+ 1,
498
+ 0,
499
+ 0,
500
+ 1,
501
+ 0,
502
+ 1,
503
+ 1
504
+ ]),
505
+ 2
506
+ )
507
+ );
508
+ return r2;
509
+ }
510
+ var sharedStickerGeometryCache = null;
511
+ function sharedStickerGeometry() {
512
+ return sharedStickerGeometryCache ?? (sharedStickerGeometryCache = newStickerGeometry());
513
+ }
514
+ var Cube3D = class extends Object3D {
515
+ constructor(kpuzzle, scheduleRenderCallback, options = {}) {
516
+ super();
517
+ this.kpuzzle = kpuzzle;
518
+ this.scheduleRenderCallback = scheduleRenderCallback;
519
+ this.options = { ...cube3DOptionsDefaults };
520
+ Object.assign(this.options, options);
521
+ if (this.kpuzzle.name() !== "3x3x3") {
522
+ throw new Error(
523
+ `Invalid puzzle for this Cube3D implementation: ${this.kpuzzle.name()}`
524
+ );
525
+ }
526
+ if (options.foundationSprite) {
527
+ this.setSprite(options.foundationSprite);
528
+ }
529
+ if (options.hintSprite) {
530
+ this.setHintSprite(options.hintSprite);
531
+ }
532
+ this.kpuzzleFaceletInfo = {};
533
+ for (const orbit in pieceDefs) {
534
+ const orbitFaceletInfo = [];
535
+ this.kpuzzleFaceletInfo[orbit] = orbitFaceletInfo;
536
+ this.pieces[orbit] = pieceDefs[orbit].map(
537
+ this.createCubie.bind(this, orbit, orbitFaceletInfo)
538
+ );
539
+ }
540
+ this.scale.set(CUBE_SCALE, CUBE_SCALE, CUBE_SCALE);
541
+ if (this.options.experimentalStickeringMask) {
542
+ this.setStickeringMask(this.options.experimentalStickeringMask);
543
+ }
544
+ this.#animateRaiseHintFacelets();
545
+ if (this.options.faceletScale) {
546
+ this.experimentalSetFaceletScale(this.options.faceletScale);
547
+ }
548
+ }
549
+ kpuzzleFaceletInfo;
550
+ pieces = {};
551
+ options;
552
+ // TODO: Keep track of option-based meshes better.
553
+ experimentalHintStickerMeshes = [];
554
+ experimentalFoundationMeshes = [];
555
+ #setSpriteURL;
556
+ sprite = new Promise((resolve) => {
557
+ this.#setSpriteURL = (url) => {
558
+ svgLoader.load(url, resolve);
559
+ };
560
+ });
561
+ // TODO: Don't overwrite the static function.
562
+ // TODO: This doesn't work dynamically yet.
563
+ setSprite(texture) {
564
+ this.sprite = texture;
565
+ }
566
+ #setHintSpriteURL;
567
+ hintSprite = new Promise((resolve) => {
568
+ this.#setHintSpriteURL = (url) => {
569
+ svgLoader.load(url, resolve);
570
+ };
571
+ });
572
+ // TODO: Don't overwrite the static function.
573
+ // TODO: This doesn't work dynamically yet.
574
+ setHintSprite(texture) {
575
+ this.hintSprite = texture;
576
+ }
577
+ #sharedHintStickerGeometryCache = null;
578
+ #sharedHintStickerGeometry() {
579
+ return this.#sharedHintStickerGeometryCache ??= newStickerGeometry();
580
+ }
581
+ // TODO: Generalize this into an animation mechanism.
582
+ #animateRaiseHintFacelets() {
583
+ if (this.options.initialHintFaceletsAnimation === "none" || this.options.initialHintFaceletsAnimation !== "always" && haveStartedSharingRenderers()) {
584
+ return;
585
+ }
586
+ const translationRange = cubieDimensions.hintStickerElevation - cubieDimensions.stickerElevation;
587
+ this.#sharedHintStickerGeometry().translate(0, 0, -translationRange);
588
+ setTimeout(() => {
589
+ const hintStartTime = performance.now();
590
+ let lastTranslation = 0;
591
+ const translationDuration = 1e3;
592
+ function ease(x) {
593
+ return x * (2 - x);
594
+ }
595
+ const animateRaiseHintSticker = () => {
596
+ const elapsed = performance.now() - hintStartTime;
597
+ const newTranslation = ease(elapsed / translationDuration) * translationRange;
598
+ this.#sharedHintStickerGeometry().translate(
599
+ 0,
600
+ 0,
601
+ newTranslation - lastTranslation
602
+ );
603
+ lastTranslation = newTranslation;
604
+ if (elapsed < translationDuration) {
605
+ requestAnimationFrame(animateRaiseHintSticker);
606
+ this.scheduleRenderCallback?.();
607
+ }
608
+ };
609
+ animateRaiseHintSticker();
610
+ }, 500);
611
+ }
612
+ // Can only be called once.
613
+ /** @deprecated */
614
+ experimentalSetStickerSpriteURL(stickerSpriteURL) {
615
+ this.#setSpriteURL?.(stickerSpriteURL);
616
+ }
617
+ // Can only be called once.
618
+ /** @deprecated */
619
+ experimentalSetHintStickerSpriteURL(hintStickerSpriteURL) {
620
+ this.#setHintSpriteURL?.(hintStickerSpriteURL);
621
+ }
622
+ setStickeringMask(stickeringMask) {
623
+ if (stickeringMask.specialBehaviour === "picture") {
624
+ for (const pieceInfos of Object.values(this.kpuzzleFaceletInfo)) {
625
+ for (const faceletInfos of pieceInfos) {
626
+ for (const faceletInfo of faceletInfos) {
627
+ faceletInfo.facelet.material = invisibleMaterial;
628
+ const { hintFacelet } = faceletInfo;
629
+ if (hintFacelet) {
630
+ hintFacelet.material = invisibleMaterial;
631
+ }
632
+ }
633
+ }
634
+ }
635
+ return;
636
+ }
637
+ this.options.experimentalStickeringMask = stickeringMask;
638
+ for (const [orbitName, orbitStickeringMask] of Object.entries(
639
+ stickeringMask.orbits
640
+ )) {
641
+ for (let pieceIdx = 0; pieceIdx < orbitStickeringMask.pieces.length; pieceIdx++) {
642
+ const pieceStickeringMask = orbitStickeringMask.pieces[pieceIdx];
643
+ if (pieceStickeringMask) {
644
+ const pieceInfo = this.kpuzzleFaceletInfo[orbitName][pieceIdx];
645
+ for (let faceletIdx = 0; faceletIdx < pieceInfo.length; faceletIdx++) {
646
+ const faceletStickeringMask = pieceStickeringMask.facelets[faceletIdx];
647
+ if (faceletStickeringMask) {
648
+ const faceletInfo = pieceInfo[faceletIdx];
649
+ const stickeringMask2 = typeof faceletStickeringMask === "string" ? faceletStickeringMask : faceletStickeringMask?.mask;
650
+ faceletInfo.facelet.material = axesInfo[faceletInfo.faceIdx].stickerMaterial[stickeringMask2];
651
+ const hintStickeringMask = typeof faceletStickeringMask === "string" ? stickeringMask2 : faceletStickeringMask.hintMask ?? stickeringMask2;
652
+ if (faceletInfo.hintFacelet) {
653
+ faceletInfo.hintFacelet.material = axesInfo[faceletInfo.faceIdx].hintStickerMaterial[hintStickeringMask];
654
+ }
655
+ }
656
+ }
657
+ }
658
+ }
659
+ }
660
+ if (this.scheduleRenderCallback) {
661
+ this.scheduleRenderCallback();
662
+ }
663
+ }
664
+ /** @deprecated */
665
+ experimentalUpdateOptions(options) {
666
+ if ("showMainStickers" in options) {
667
+ throw new Error("Unimplemented");
668
+ }
669
+ const showFoundation = options.showFoundation;
670
+ if (typeof showFoundation !== "undefined" && this.options.showFoundation !== showFoundation) {
671
+ this.options.showFoundation = showFoundation;
672
+ for (const foundation of this.experimentalFoundationMeshes) {
673
+ foundation.visible = showFoundation;
674
+ }
675
+ }
676
+ const hintFacelets = options.hintFacelets;
677
+ if (typeof hintFacelets !== "undefined" && this.options.hintFacelets !== hintFacelets && hintFaceletStyles[hintFacelets]) {
678
+ this.options.hintFacelets = hintFacelets;
679
+ for (const hintSticker of this.experimentalHintStickerMeshes) {
680
+ hintSticker.visible = hintFacelets === "floating";
681
+ }
682
+ this.scheduleRenderCallback();
683
+ }
684
+ const { experimentalStickeringMask } = options;
685
+ if (typeof experimentalStickeringMask !== "undefined") {
686
+ this.options.experimentalStickeringMask = experimentalStickeringMask;
687
+ this.setStickeringMask(experimentalStickeringMask);
688
+ this.scheduleRenderCallback();
689
+ }
690
+ const { faceletScale } = options;
691
+ if (typeof faceletScale !== "undefined") {
692
+ this.experimentalSetFaceletScale(faceletScale);
693
+ }
694
+ }
695
+ onPositionChange(p) {
696
+ const reid333 = p.pattern;
697
+ for (const orbit in pieceDefs) {
698
+ const pieces = pieceDefs[orbit];
699
+ for (let i = 0; i < pieces.length; i++) {
700
+ const j = reid333.patternData[orbit].pieces[i];
701
+ this.pieces[orbit][j].matrix.copy(pieceDefs[orbit][i].matrix);
702
+ this.pieces[orbit][j].matrix.multiply(
703
+ orientationRotation[orbit][reid333.patternData[orbit].orientation[i]]
704
+ );
705
+ }
706
+ for (const moveProgress of p.movesInProgress) {
707
+ const move = moveProgress.move;
708
+ const turnNormal = axesInfo[familyToAxis[move.family]].vector;
709
+ const moveMatrix = new Matrix4().makeRotationAxis(
710
+ turnNormal,
711
+ -this.ease(moveProgress.fraction) * moveProgress.direction * move.amount * TAU / 4
712
+ );
713
+ for (let i = 0; i < pieces.length; i++) {
714
+ const quantumTransformation = this.kpuzzle.moveToTransformation(
715
+ move.modified({ amount: 1 })
716
+ );
717
+ const k = quantumTransformation.transformationData[orbit].permutation[i];
718
+ if (i !== k || quantumTransformation.transformationData[orbit].orientationDelta[i] !== 0) {
719
+ const j = reid333.patternData[orbit].pieces[i];
720
+ this.pieces[orbit][j].matrix.premultiply(moveMatrix);
721
+ }
722
+ }
723
+ }
724
+ }
725
+ this.scheduleRenderCallback();
726
+ }
727
+ // TODO: Always create (but sometimes hide parts) so we can show them later,
728
+ // or (better) support creating puzzle parts on demand.
729
+ createCubie(orbit, orbitFacelets, piece, orbitPieceIdx) {
730
+ const cubieFaceletInfo = [];
731
+ orbitFacelets.push(cubieFaceletInfo);
732
+ const cubie = new Group();
733
+ if (this.options.showFoundation) {
734
+ const foundation = this.createCubieFoundation();
735
+ cubie.add(foundation);
736
+ this.experimentalFoundationMeshes.push(foundation);
737
+ }
738
+ for (let i = 0; i < piece.stickerFaces.length; i++) {
739
+ const sticker = this.createSticker(
740
+ axesInfo[cubieStickerOrder[i]],
741
+ axesInfo[piece.stickerFaces[i]],
742
+ false
743
+ );
744
+ const faceletInfo = {
745
+ faceIdx: piece.stickerFaces[i],
746
+ facelet: sticker
747
+ };
748
+ cubie.add(sticker);
749
+ if (this.options.hintFacelets === "floating") {
750
+ const hintSticker = this.createSticker(
751
+ axesInfo[cubieStickerOrder[i]],
752
+ axesInfo[piece.stickerFaces[i]],
753
+ true
754
+ );
755
+ cubie.add(hintSticker);
756
+ faceletInfo.hintFacelet = hintSticker;
757
+ this.experimentalHintStickerMeshes.push(hintSticker);
758
+ }
759
+ if (this.options.experimentalStickeringMask?.specialBehaviour === "picture" && pictureStickerCoords[orbit] && pictureStickerCoords[orbit][orbitPieceIdx] && pictureStickerCoords[orbit][orbitPieceIdx][i]) {
760
+ const [rotate, offsetX, offsetY] = pictureStickerCoords[orbit][orbitPieceIdx][i];
761
+ void (async () => {
762
+ const addImageSticker = async (hint) => {
763
+ const texture = await (hint ? this.hintSprite : this.sprite);
764
+ const mesh = this.createSticker(
765
+ axesInfo[cubieStickerOrder[i]],
766
+ axesInfo[piece.stickerFaces[i]],
767
+ hint
768
+ );
769
+ mesh.material = new MeshBasicMaterial({
770
+ map: texture,
771
+ side: hint ? BackSide : DoubleSide,
772
+ transparent: true
773
+ });
774
+ const x1 = offsetX / 12;
775
+ const x2 = (offsetX + 1) / 12;
776
+ const y1 = offsetY / 9;
777
+ const y2 = (offsetY + 1) / 9;
778
+ let v1 = new Vector2(x1, y1);
779
+ let v2 = new Vector2(x1, y2);
780
+ let v3 = new Vector2(x2, y2);
781
+ let v4 = new Vector2(x2, y1);
782
+ switch (rotate) {
783
+ case 1: {
784
+ [v1, v2, v3, v4] = [v2, v3, v4, v1];
785
+ break;
786
+ }
787
+ case 2: {
788
+ [v1, v2, v3, v4] = [v3, v4, v1, v2];
789
+ break;
790
+ }
791
+ case 3: {
792
+ [v1, v2, v3, v4] = [v4, v1, v2, v3];
793
+ break;
794
+ }
795
+ }
796
+ mesh.geometry.setAttribute(
797
+ "uv",
798
+ new BufferAttribute(
799
+ new Float32Array([
800
+ v3.x,
801
+ v3.y,
802
+ v2.x,
803
+ v2.y,
804
+ v4.x,
805
+ v4.y,
806
+ v2.x,
807
+ v2.y,
808
+ v1.x,
809
+ v1.y,
810
+ v4.x,
811
+ v4.y
812
+ ]),
813
+ 2
814
+ )
815
+ );
816
+ cubie.add(mesh);
817
+ };
818
+ void addImageSticker(true);
819
+ void addImageSticker(false);
820
+ })();
821
+ }
822
+ cubieFaceletInfo.push(faceletInfo);
823
+ }
824
+ cubie.matrix.copy(piece.matrix);
825
+ cubie.matrixAutoUpdate = false;
826
+ this.add(cubie);
827
+ return cubie;
828
+ }
829
+ // TODO: Support creating only the outward-facing parts?
830
+ createCubieFoundation() {
831
+ const box = sharedCubieFoundationGeometry();
832
+ return new Mesh(
833
+ box,
834
+ this.options.experimentalStickeringMask?.specialBehaviour === "picture" ? blackMesh : blackTranslucentMesh
835
+ );
836
+ }
837
+ createSticker(posAxisInfo, materialAxisInfo, isHint) {
838
+ const geo = this.options.experimentalStickeringMask?.specialBehaviour === "picture" ? newStickerGeometry() : isHint ? this.#sharedHintStickerGeometry() : sharedStickerGeometry();
839
+ const stickerMesh = new Mesh(
840
+ geo,
841
+ isHint ? materialAxisInfo.hintStickerMaterial.regular : materialAxisInfo.stickerMaterial.regular
842
+ );
843
+ stickerMesh.setRotationFromEuler(posAxisInfo.fromZ);
844
+ stickerMesh.position.copy(posAxisInfo.vector);
845
+ stickerMesh.position.multiplyScalar(
846
+ isHint ? this.options.experimentalStickeringMask?.specialBehaviour === "picture" ? EXPERIMENTAL_PICTURE_CUBE_HINT_ELEVATION : cubieDimensions.hintStickerElevation : cubieDimensions.stickerElevation
847
+ );
848
+ stickerMesh.scale.setScalar(getFaceletScale(this.options));
849
+ return stickerMesh;
850
+ }
851
+ /** @deprecated */
852
+ experimentalSetFoundationOpacity(opacity) {
853
+ this.experimentalFoundationMeshes[0].material.opacity = opacity;
854
+ }
855
+ /** @deprecated */
856
+ experimentalSetFaceletScale(faceletScale) {
857
+ this.options.faceletScale = faceletScale;
858
+ for (const orbitInfo of Object.values(this.kpuzzleFaceletInfo)) {
859
+ for (const pieceInfo of orbitInfo) {
860
+ for (const faceletInfo of pieceInfo) {
861
+ faceletInfo.facelet.scale.setScalar(getFaceletScale(this.options));
862
+ faceletInfo.hintFacelet?.scale.setScalar(
863
+ getFaceletScale(this.options)
864
+ );
865
+ }
866
+ }
867
+ }
868
+ }
869
+ // /** @deprecated */
870
+ // experimentalSetCenterStickerWidth(width: number): void {
871
+ // for (const orbitInfo of [this.kpuzzleFaceletInfo["CENTERS"]]) {
872
+ // for (const pieceInfo of orbitInfo) {
873
+ // for (const faceletInfo of pieceInfo) {
874
+ // faceletInfo.facelet.scale.setScalar(
875
+ // width / getStickerScale(this.options),
876
+ // );
877
+ // // faceletInfo.facelet.setRotationFromAxisAngle(new Vector3(0, 1, 0), 0);
878
+ // // faceletInfo.facelet.rotateOnAxis(new Vector3(1, 0, 1), TAU / 6);
879
+ // }
880
+ // }
881
+ // }
882
+ // }
883
+ ease(fraction) {
884
+ return smootherStep(fraction);
885
+ }
886
+ };
887
+
888
+ // src/cubing/twisty/views/3D/puzzles/PG3D.ts
889
+ import { DoubleSide as DoubleSide2, FrontSide as FrontSide2 } from "three/src/constants.js";
890
+ import { BufferAttribute as BufferAttribute2 } from "three/src/core/BufferAttribute.js";
891
+ import { BufferGeometry as BufferGeometry2 } from "three/src/core/BufferGeometry.js";
892
+ import { Object3D as Object3D2 } from "three/src/core/Object3D.js";
893
+ import { MeshBasicMaterial as MeshBasicMaterial2 } from "three/src/materials/MeshBasicMaterial.js";
894
+ import { Color as Color2 } from "three/src/math/Color.js";
895
+ import { Euler as Euler2 } from "three/src/math/Euler.js";
896
+ import { Vector3 as Vector32 } from "three/src/math/Vector3.js";
897
+ import { Group as Group2 } from "three/src/objects/Group.js";
898
+ import { Mesh as Mesh2 } from "three/src/objects/Mesh.js";
899
+ var foundationMaterial = new MeshBasicMaterial2({
900
+ side: DoubleSide2,
901
+ color: 0
902
+ });
903
+ var invisMaterial = new MeshBasicMaterial2({
904
+ visible: false
905
+ });
906
+ var basicStickerMaterial = new MeshBasicMaterial2({
907
+ vertexColors: true
908
+ });
909
+ function dist(coords, a, b) {
910
+ return Math.hypot(
911
+ coords[3 * a] - coords[3 * b],
912
+ coords[3 * a + 1] - coords[3 * b + 1],
913
+ coords[3 * a + 2] - coords[3 * b + 2]
914
+ );
915
+ }
916
+ function triarea(coords, a, b, c) {
917
+ const ab = dist(coords, a, b);
918
+ const bc = dist(coords, b, c);
919
+ const ac = dist(coords, a, c);
920
+ const p = (ab + bc + ac) / 2;
921
+ return Math.sqrt(p * (p - ab) * (p - bc) * (p - ac));
922
+ }
923
+ function polyarea(coords) {
924
+ let sum = 0;
925
+ for (let i = 2; 3 * i < coords.length; i++) {
926
+ sum += triarea(coords, 0, 1, i);
927
+ }
928
+ return sum;
929
+ }
930
+ function normalize(r2) {
931
+ const m = Math.hypot(r2[0], r2[1], r2[2]);
932
+ r2[0] /= m;
933
+ r2[1] /= m;
934
+ r2[2] /= m;
935
+ return r2;
936
+ }
937
+ function cross(a, b) {
938
+ const r2 = new Array(3);
939
+ r2[0] = a[1] * b[2] - a[2] * b[1];
940
+ r2[1] = a[2] * b[0] - a[0] * b[2];
941
+ r2[2] = a[0] * b[1] - a[1] * b[0];
942
+ return r2;
943
+ }
944
+ function normal(c) {
945
+ const a = [c[3] - c[0], c[4] - c[1], c[5] - c[2]];
946
+ const b = [c[6] - c[3], c[7] - c[4], c[8] - c[5]];
947
+ const r2 = cross(a, b);
948
+ return normalize(r2);
949
+ }
950
+ function trimEdges(face2, tr) {
951
+ const r2 = [];
952
+ const A = new Array(3);
953
+ const B = new Array(3);
954
+ for (let iter = 1; iter < 10; iter++) {
955
+ for (let i = 0; i < face2.length; i += 3) {
956
+ const pi = (i + face2.length - 3) % face2.length;
957
+ const ni = (i + 3) % face2.length;
958
+ for (let k = 0; k < 3; k++) {
959
+ A[k] = face2[pi + k] - face2[i + k];
960
+ B[k] = face2[ni + k] - face2[i + k];
961
+ }
962
+ const alen = Math.hypot(A[0], A[1], A[2]);
963
+ const blen = Math.hypot(B[0], B[1], B[2]);
964
+ for (let k = 0; k < 3; k++) {
965
+ A[k] /= alen;
966
+ B[k] /= blen;
967
+ }
968
+ const d = A[0] * B[0] + A[1] * B[1] + A[2] * B[2];
969
+ const m = tr / Math.sqrt(1 - d * d);
970
+ for (let k = 0; k < 3; k++) {
971
+ r2[i + k] = face2[i + k] + (A[k] + B[k]) * m;
972
+ }
973
+ }
974
+ let good = true;
975
+ for (let i = 0; good && i < r2.length; i += 3) {
976
+ const ni = (i + 3) % face2.length;
977
+ let t2 = 0;
978
+ for (let k = 0; k < 3; k++) {
979
+ const a = face2[ni + k] - face2[i + k];
980
+ const b = r2[ni + k] - r2[i + k];
981
+ t2 += a * b;
982
+ }
983
+ if (t2 <= 0) {
984
+ good = false;
985
+ }
986
+ }
987
+ if (good) {
988
+ return r2;
989
+ }
990
+ tr /= 2;
991
+ }
992
+ return face2;
993
+ }
994
+ var Filler = class {
995
+ constructor(sz, tm) {
996
+ this.sz = sz;
997
+ this.tm = tm;
998
+ this.vertices = new Float32Array(9 * sz);
999
+ this.uvs = void 0;
1000
+ this.colors = new Uint8Array(18 * sz);
1001
+ this.ind = new Uint8Array(sz);
1002
+ this.pos = 0;
1003
+ this.ipos = 0;
1004
+ }
1005
+ pos;
1006
+ ipos;
1007
+ vertices;
1008
+ colors;
1009
+ uvs;
1010
+ ind;
1011
+ add(pt, i, c) {
1012
+ this.vertices[this.pos] = pt[3 * i + 0];
1013
+ this.vertices[this.pos + 1] = pt[3 * i + 1];
1014
+ this.vertices[this.pos + 2] = pt[3 * i + 2];
1015
+ this.colors[this.pos] = c >> 16;
1016
+ this.colors[this.pos + 1] = c >> 8 & 255;
1017
+ this.colors[this.pos + 2] = c & 255;
1018
+ this.pos += 3;
1019
+ }
1020
+ addUncolored(pt, i) {
1021
+ this.vertices[this.pos] = pt[3 * i + 0];
1022
+ this.vertices[this.pos + 1] = pt[3 * i + 1];
1023
+ this.vertices[this.pos + 2] = pt[3 * i + 2];
1024
+ this.pos += 3;
1025
+ }
1026
+ setind(i) {
1027
+ this.ind[this.ipos++] = i;
1028
+ }
1029
+ makePoly(coords, color, ind) {
1030
+ const ncoords = coords;
1031
+ for (let g = 1; 3 * (g + 1) < ncoords.length; g++) {
1032
+ this.add(ncoords, 0, color);
1033
+ this.add(ncoords, g, color);
1034
+ this.add(ncoords, g + 1, color);
1035
+ this.setind(ind);
1036
+ }
1037
+ }
1038
+ setAttributes(geo) {
1039
+ geo.setAttribute("position", new BufferAttribute2(this.vertices, 3));
1040
+ const sa2 = this.colors.subarray(0, 9 * this.sz);
1041
+ geo.setAttribute("color", new BufferAttribute2(sa2, 3, true));
1042
+ }
1043
+ makeGroups(geo) {
1044
+ geo.clearGroups();
1045
+ for (let i = 0; i < this.ipos; ) {
1046
+ const si = i++;
1047
+ const iv = this.ind[si];
1048
+ while (this.ind[i] === iv) {
1049
+ i++;
1050
+ }
1051
+ geo.addGroup(3 * si, 3 * (i - si), iv);
1052
+ }
1053
+ }
1054
+ saveOriginalColors() {
1055
+ this.colors.copyWithin(this.pos, 0, this.pos);
1056
+ }
1057
+ };
1058
+ var StickerDef = class {
1059
+ origColor;
1060
+ origColorStickeringMask;
1061
+ faceColor;
1062
+ texturePtr = void 0;
1063
+ twistVal = -1;
1064
+ stickerStart;
1065
+ stickerEnd;
1066
+ hintStart;
1067
+ hintEnd;
1068
+ foundationStart;
1069
+ foundationEnd;
1070
+ isDup;
1071
+ faceNum;
1072
+ constructor(filler, stickerDat, trim, options) {
1073
+ this.isDup = !!stickerDat.isDup;
1074
+ this.faceNum = stickerDat.face;
1075
+ this.stickerStart = filler.ipos;
1076
+ const sdColor = new Color2(stickerDat.color).getHex();
1077
+ this.origColor = sdColor;
1078
+ this.origColorStickeringMask = sdColor;
1079
+ if (options?.stickeringMask) {
1080
+ this.setStickeringMask(filler, options.stickeringMask);
1081
+ }
1082
+ this.faceColor = sdColor;
1083
+ const coords = this.stickerCoords(stickerDat.coords, trim);
1084
+ filler.makePoly(coords, this.faceColor, this.isDup ? 4 : 0);
1085
+ this.stickerEnd = filler.ipos;
1086
+ }
1087
+ stickerCoords(coords, trim) {
1088
+ return trimEdges(coords.slice(), trim);
1089
+ }
1090
+ hintCoords(coords, hintStickerHeightScale, trim, normal2) {
1091
+ coords = this.stickerCoords(coords, trim);
1092
+ normal2 = normal2.slice();
1093
+ for (let i = 0; i < 3; i++) {
1094
+ normal2[i] *= 0.5 * hintStickerHeightScale;
1095
+ }
1096
+ const hCoords = new Array(coords.length);
1097
+ for (let i = 0; 3 * i < coords.length; i++) {
1098
+ const j = coords.length / 3 - 1 - i;
1099
+ hCoords[3 * i] = coords[3 * j] + normal2[0];
1100
+ hCoords[3 * i + 1] = coords[3 * j + 1] + normal2[1];
1101
+ hCoords[3 * i + 2] = coords[3 * j + 2] + normal2[2];
1102
+ }
1103
+ return hCoords;
1104
+ }
1105
+ foundationCoords(coords) {
1106
+ const ncoords = coords.slice();
1107
+ for (let i = 0; i < coords.length; i++) {
1108
+ ncoords[i] = coords[i] * 0.999;
1109
+ }
1110
+ return ncoords;
1111
+ }
1112
+ addHint(filler, stickerDat, hintStickers, hintStickerHeightScale, trim, normal2) {
1113
+ this.hintStart = filler.ipos;
1114
+ const coords = this.hintCoords(
1115
+ stickerDat.coords,
1116
+ hintStickerHeightScale,
1117
+ trim,
1118
+ normal2
1119
+ );
1120
+ filler.makePoly(
1121
+ coords,
1122
+ this.faceColor,
1123
+ hintStickers && !this.isDup ? 2 : 4
1124
+ );
1125
+ this.hintEnd = filler.ipos;
1126
+ }
1127
+ addFoundation(filler, stickerDat, black) {
1128
+ this.foundationStart = filler.ipos;
1129
+ const coords = this.foundationCoords(stickerDat.coords);
1130
+ filler.makePoly(coords, black, this.isDup ? 4 : 6);
1131
+ this.foundationEnd = filler.ipos;
1132
+ }
1133
+ setHintStickers(filler, hintStickers) {
1134
+ const indv = this.isDup || !hintStickers ? 4 : 2;
1135
+ for (let i = this.hintStart; i < this.hintEnd; i++) {
1136
+ filler.ind[i] = indv | filler.ind[i] & 1;
1137
+ }
1138
+ }
1139
+ setStickeringMask(filler, faceletMeshStickeringMask) {
1140
+ let c = 0;
1141
+ switch (faceletMeshStickeringMask) {
1142
+ case "regular": {
1143
+ c = this.origColor;
1144
+ break;
1145
+ }
1146
+ case "dim": {
1147
+ if (this.origColor === 16777215) {
1148
+ c = 14540253;
1149
+ } else {
1150
+ c = new Color2(this.origColor).multiplyScalar(0.5).getHex();
1151
+ }
1152
+ break;
1153
+ }
1154
+ case "oriented": {
1155
+ c = 4513228;
1156
+ break;
1157
+ }
1158
+ case "experimentalOriented2": {
1159
+ c = 16776618;
1160
+ break;
1161
+ }
1162
+ case "ignored": {
1163
+ c = 4473924;
1164
+ break;
1165
+ }
1166
+ case "mystery": {
1167
+ c = 15911883;
1168
+ break;
1169
+ }
1170
+ case "invisible":
1171
+ c = this.origColor;
1172
+ }
1173
+ this.origColorStickeringMask = c;
1174
+ for (let i = 9 * this.stickerStart; i < 9 * this.stickerEnd; i += 3) {
1175
+ filler.colors[filler.pos + i] = c >> 16;
1176
+ filler.colors[filler.pos + i + 1] = c >> 8 & 255;
1177
+ filler.colors[filler.pos + i + 2] = c & 255;
1178
+ }
1179
+ for (let i = 9 * this.hintStart; i < 9 * this.hintEnd; i += 3) {
1180
+ filler.colors[filler.pos + i] = c >> 16;
1181
+ filler.colors[filler.pos + i + 1] = c >> 8 & 255;
1182
+ filler.colors[filler.pos + i + 2] = c & 255;
1183
+ }
1184
+ this.setHintStickers(
1185
+ filler,
1186
+ faceletMeshStickeringMask !== "invisible" && !this.isDup
1187
+ );
1188
+ }
1189
+ addUVs(filler) {
1190
+ const uvs = filler.uvs;
1191
+ const vert = filler.vertices;
1192
+ const coords = new Array(3);
1193
+ for (let i = 3 * this.stickerStart; i < 3 * this.stickerEnd; i++) {
1194
+ coords[0] = vert[3 * i];
1195
+ coords[1] = vert[3 * i + 1];
1196
+ coords[2] = vert[3 * i + 2];
1197
+ const uv = filler.tm.getuv(this.faceNum, coords);
1198
+ uvs[2 * i] = uv[0];
1199
+ uvs[2 * i + 1] = uv[1];
1200
+ }
1201
+ for (let i = 3 * this.hintStart; i < 3 * this.hintEnd; i++) {
1202
+ coords[0] = vert[3 * i];
1203
+ coords[1] = vert[3 * i + 1];
1204
+ coords[2] = vert[3 * i + 2];
1205
+ const uv = filler.tm.getuv(this.faceNum, coords);
1206
+ uvs[2 * i] = uv[0];
1207
+ uvs[2 * i + 1] = uv[1];
1208
+ }
1209
+ }
1210
+ setTexture(filler, sd) {
1211
+ if (this.texturePtr === sd) {
1212
+ return 0;
1213
+ }
1214
+ this.texturePtr = sd;
1215
+ const sz = 6 * filler.sz;
1216
+ filler.uvs.copyWithin(
1217
+ 6 * this.stickerStart,
1218
+ 6 * sd.stickerStart + sz,
1219
+ 6 * sd.stickerEnd + sz
1220
+ );
1221
+ filler.uvs.copyWithin(
1222
+ 6 * this.hintStart,
1223
+ // TODO: refactor to avoid non-null-assertion
1224
+ 6 * sd.hintStart + sz,
1225
+ // TODO: refactor to avoid non-null-assertion
1226
+ 6 * sd.hintEnd + sz
1227
+ // TODO: refactor to avoid non-null-assertion
1228
+ );
1229
+ return 1;
1230
+ }
1231
+ setColor(filler, sd) {
1232
+ const c = sd.origColorStickeringMask;
1233
+ if (this.faceColor !== c) {
1234
+ this.faceColor = c;
1235
+ const sz = filler.pos;
1236
+ filler.colors.copyWithin(
1237
+ 9 * this.stickerStart,
1238
+ 9 * sd.stickerStart + sz,
1239
+ 9 * sd.stickerEnd + sz
1240
+ );
1241
+ filler.colors.copyWithin(
1242
+ 9 * this.hintStart,
1243
+ // TODO: refactor to avoid non-null-assertion
1244
+ 9 * sd.hintStart + sz,
1245
+ // TODO: refactor to avoid non-null-assertion
1246
+ 9 * sd.hintEnd + sz
1247
+ // TODO: refactor to avoid non-null-assertion
1248
+ );
1249
+ return 1;
1250
+ } else {
1251
+ return 0;
1252
+ }
1253
+ }
1254
+ };
1255
+ var HitPlaneDef = class {
1256
+ cubie;
1257
+ geo;
1258
+ constructor(hitface, tm, stickerDat) {
1259
+ this.cubie = new Group2();
1260
+ const coords = hitface.coords;
1261
+ const filler = new Filler(coords.length / 3 - 2, tm);
1262
+ for (let g = 1; 3 * g + 3 < coords.length; g++) {
1263
+ filler.addUncolored(coords, 0);
1264
+ filler.addUncolored(coords, g);
1265
+ filler.addUncolored(coords, g + 1);
1266
+ }
1267
+ this.geo = new BufferGeometry2();
1268
+ filler.setAttributes(this.geo);
1269
+ const obj = new Mesh2(this.geo, invisMaterial);
1270
+ obj.userData["quantumMove"] = stickerDat.notationMapper.notationToExternal(
1271
+ new Move(hitface.name)
1272
+ );
1273
+ this.cubie.scale.setScalar(0.99);
1274
+ this.cubie.add(obj);
1275
+ }
1276
+ };
1277
+ var AxisInfo2 = class {
1278
+ axis;
1279
+ order;
1280
+ constructor(axisDat) {
1281
+ const vec = axisDat.coordinates;
1282
+ this.axis = new Vector32(vec[0], vec[1], vec[2]);
1283
+ this.order = axisDat.order;
1284
+ }
1285
+ };
1286
+ var DEFAULT_COLOR_FRACTION = 0.71;
1287
+ var PG_SCALE = 0.5;
1288
+ var PG3D = class extends Object3D2 {
1289
+ constructor(scheduleRenderCallback, kpuzzle, stickerDat, enableFoundationOpt = false, enableHintStickersOpt = false, hintStickerHeightScale = 1, faceletScale = 1, params = {}) {
1290
+ super();
1291
+ this.scheduleRenderCallback = scheduleRenderCallback;
1292
+ this.kpuzzle = kpuzzle;
1293
+ this.stickerDat = stickerDat;
1294
+ this.faceletScale = faceletScale;
1295
+ this.params = params;
1296
+ if (stickerDat.stickers.length === 0) {
1297
+ throw Error("Reuse of stickerdat from pg; please don't do that.");
1298
+ }
1299
+ this.hintMaterial = new MeshBasicMaterial2({
1300
+ vertexColors: true,
1301
+ transparent: true,
1302
+ opacity: 0.5
1303
+ });
1304
+ this.hintMaterialDisposable = true;
1305
+ this.stickerMaterial = basicStickerMaterial;
1306
+ this.stickerMaterialDisposable = false;
1307
+ this.axesInfo = {};
1308
+ const axesDef = this.stickerDat.axis;
1309
+ for (const axis of axesDef) {
1310
+ this.axesInfo[axis.quantumMove.family] = new AxisInfo2(axis);
1311
+ }
1312
+ const stickers = this.stickerDat.stickers;
1313
+ this.stickers = {};
1314
+ this.materialArray1 = new Array(8);
1315
+ this.materialArray2 = new Array(8);
1316
+ this.showFoundation(enableFoundationOpt);
1317
+ enableFoundationOpt = true;
1318
+ let triangleCount = 0;
1319
+ const multiplier = 3;
1320
+ for (const sticker of stickers) {
1321
+ const sides = sticker.coords.length / 3;
1322
+ triangleCount += multiplier * (sides - 2);
1323
+ }
1324
+ const filler = new Filler(triangleCount, stickerDat.textureMapper);
1325
+ const black = 0;
1326
+ const normals = [];
1327
+ let totArea = 0;
1328
+ for (const f of stickerDat.faces) {
1329
+ normals.push(normal(f.coords));
1330
+ totArea += polyarea(f.coords);
1331
+ }
1332
+ const colorfrac = faceletScale !== "auto" ? faceletScale * faceletScale : DEFAULT_COLOR_FRACTION;
1333
+ let nonDupStickers = 0;
1334
+ for (const sticker of stickers) {
1335
+ if (!sticker.isDup) {
1336
+ nonDupStickers++;
1337
+ }
1338
+ }
1339
+ const trim = Math.sqrt(totArea / nonDupStickers) * (1 - Math.sqrt(colorfrac)) / 2;
1340
+ for (const sticker of stickers) {
1341
+ const orbit = sticker.orbit;
1342
+ const ord = sticker.ord;
1343
+ const ori = sticker.ori;
1344
+ if (!this.stickers[orbit]) {
1345
+ this.stickers[orbit] = [];
1346
+ }
1347
+ if (!this.stickers[orbit][ori]) {
1348
+ this.stickers[orbit][ori] = [];
1349
+ }
1350
+ const options = {};
1351
+ if (params.stickeringMask) {
1352
+ options.stickeringMask = getFaceletStickeringMask(
1353
+ params.stickeringMask,
1354
+ orbit,
1355
+ ord,
1356
+ ori,
1357
+ false
1358
+ );
1359
+ }
1360
+ const stickerdef = new StickerDef(filler, sticker, trim, options);
1361
+ this.stickers[orbit][ori][ord] = stickerdef;
1362
+ }
1363
+ this.showHintStickers = enableHintStickersOpt;
1364
+ enableHintStickersOpt = true;
1365
+ for (const sticker of stickers) {
1366
+ const orbit = sticker.orbit;
1367
+ const ord = sticker.ord;
1368
+ const ori = sticker.ori;
1369
+ this.stickers[orbit][ori][ord].addHint(
1370
+ filler,
1371
+ sticker,
1372
+ enableHintStickersOpt,
1373
+ hintStickerHeightScale,
1374
+ trim,
1375
+ normals[sticker.face]
1376
+ );
1377
+ }
1378
+ this.foundationBound = filler.ipos;
1379
+ for (const sticker of stickers) {
1380
+ const orbit = sticker.orbit;
1381
+ const ord = sticker.ord;
1382
+ const ori = sticker.ori;
1383
+ if (enableFoundationOpt) {
1384
+ this.stickers[orbit][ori][ord].addFoundation(filler, sticker, black);
1385
+ }
1386
+ }
1387
+ const fixedGeo = new BufferGeometry2();
1388
+ filler.setAttributes(fixedGeo);
1389
+ filler.makeGroups(fixedGeo);
1390
+ const obj = new Mesh2(fixedGeo, this.materialArray1);
1391
+ obj.scale.set(PG_SCALE, PG_SCALE, PG_SCALE);
1392
+ this.add(obj);
1393
+ const obj2 = new Mesh2(fixedGeo, this.materialArray2);
1394
+ obj2.scale.set(PG_SCALE, PG_SCALE, PG_SCALE);
1395
+ this.add(obj2);
1396
+ const hitfaces = this.stickerDat.faces;
1397
+ this.movingObj = obj2;
1398
+ this.fixedGeo = fixedGeo;
1399
+ this.filler = filler;
1400
+ for (const hitface of hitfaces) {
1401
+ const facedef = new HitPlaneDef(
1402
+ hitface,
1403
+ stickerDat.textureMapper,
1404
+ this.stickerDat
1405
+ );
1406
+ facedef.cubie.scale.set(PG_SCALE, PG_SCALE, PG_SCALE);
1407
+ this.add(facedef.cubie);
1408
+ this.controlTargets.push(facedef.cubie.children[0]);
1409
+ }
1410
+ filler.saveOriginalColors();
1411
+ stickerDat.stickers = [];
1412
+ this.updateMaterialArrays();
1413
+ }
1414
+ stickers;
1415
+ axesInfo;
1416
+ stickerTargets = [];
1417
+ controlTargets = [];
1418
+ movingObj;
1419
+ filler;
1420
+ foundationBound;
1421
+ // before this: colored; after: black
1422
+ fixedGeo;
1423
+ lastPos;
1424
+ lastMoveTransformation;
1425
+ hintMaterial;
1426
+ stickerMaterial;
1427
+ materialArray1;
1428
+ materialArray2;
1429
+ textured = false;
1430
+ showHintStickers = false;
1431
+ showFoundations = false;
1432
+ hintMaterialDisposable;
1433
+ stickerMaterialDisposable;
1434
+ #pendingStickeringUpdate = false;
1435
+ dispose() {
1436
+ if (this.fixedGeo) {
1437
+ this.fixedGeo.dispose();
1438
+ }
1439
+ if (this.stickerMaterialDisposable) {
1440
+ this.stickerMaterial.dispose();
1441
+ this.stickerMaterial = basicStickerMaterial;
1442
+ this.stickerMaterialDisposable = false;
1443
+ }
1444
+ if (this.hintMaterialDisposable) {
1445
+ this.hintMaterial.dispose();
1446
+ this.hintMaterial = basicStickerMaterial;
1447
+ this.hintMaterialDisposable = false;
1448
+ }
1449
+ }
1450
+ experimentalGetStickerTargets() {
1451
+ return this.stickerTargets;
1452
+ }
1453
+ experimentalGetControlTargets() {
1454
+ return this.controlTargets;
1455
+ }
1456
+ #isValidMove(move) {
1457
+ try {
1458
+ this.kpuzzle.moveToTransformation(move);
1459
+ return true;
1460
+ } catch (_) {
1461
+ return false;
1462
+ }
1463
+ }
1464
+ getClosestMoveToAxis(point, transformations) {
1465
+ let closestMove = null;
1466
+ let closestMoveDotProduct = 0;
1467
+ let modify = (m) => m;
1468
+ switch (transformations.depth) {
1469
+ case "secondSlice": {
1470
+ modify = (m) => m.modified({ innerLayer: 2 });
1471
+ break;
1472
+ }
1473
+ case "rotation": {
1474
+ modify = (m) => m.modified({ family: `${m.family}v` });
1475
+ break;
1476
+ }
1477
+ }
1478
+ for (const axis of this.stickerDat.axis) {
1479
+ const product = point.dot(new Vector32(...axis.coordinates));
1480
+ if (product > closestMoveDotProduct) {
1481
+ const modified = this.stickerDat.notationMapper.notationToExternal(
1482
+ modify(axis.quantumMove)
1483
+ );
1484
+ if (!modified) {
1485
+ continue;
1486
+ }
1487
+ console.log(modified.family);
1488
+ if (modified.family === "T" && transformations.depth === "none") {
1489
+ continue;
1490
+ }
1491
+ if (this.#isValidMove(modified)) {
1492
+ closestMoveDotProduct = product;
1493
+ closestMove = modified;
1494
+ }
1495
+ }
1496
+ }
1497
+ if (!closestMove) {
1498
+ return null;
1499
+ }
1500
+ if (transformations.invert) {
1501
+ closestMove = closestMove.invert();
1502
+ }
1503
+ const order = this.kpuzzle.moveToTransformation(closestMove).repetitionOrder();
1504
+ return { move: closestMove, order };
1505
+ }
1506
+ setStickeringMask(stickeringMask) {
1507
+ this.params.stickeringMask = stickeringMask;
1508
+ if (stickeringMask.specialBehaviour !== "picture") {
1509
+ for (const orbitDefinition of this.kpuzzle.definition.orbits) {
1510
+ const { numPieces, numOrientations } = orbitDefinition;
1511
+ for (let pieceIdx = 0; pieceIdx < numPieces; pieceIdx++) {
1512
+ for (let faceletIdx = 0; faceletIdx < numOrientations; faceletIdx++) {
1513
+ const faceletStickeringMask = getFaceletStickeringMask(
1514
+ stickeringMask,
1515
+ orbitDefinition.orbitName,
1516
+ pieceIdx,
1517
+ faceletIdx,
1518
+ false
1519
+ );
1520
+ const stickerDef = this.stickers[orbitDefinition.orbitName][faceletIdx][pieceIdx];
1521
+ if (this.textured && this.hintMaterialDisposable && faceletStickeringMask === "invisible") {
1522
+ } else {
1523
+ stickerDef.setStickeringMask(this.filler, faceletStickeringMask);
1524
+ }
1525
+ }
1526
+ }
1527
+ }
1528
+ }
1529
+ this.#pendingStickeringUpdate = true;
1530
+ if (this.lastPos) {
1531
+ this.onPositionChange(this.lastPos);
1532
+ }
1533
+ }
1534
+ onPositionChange(p) {
1535
+ const { pattern } = p;
1536
+ const noRotation = new Euler2();
1537
+ this.movingObj.rotation.copy(noRotation);
1538
+ let colormods = 0;
1539
+ const filler = this.filler;
1540
+ const ind = filler.ind;
1541
+ if (!this.lastPos || this.#pendingStickeringUpdate || !this.lastPos.pattern.isIdentical(pattern)) {
1542
+ for (const orbit in this.stickers) {
1543
+ const pieces = this.stickers[orbit];
1544
+ const pos2 = pattern.patternData[orbit];
1545
+ const orin = pieces.length;
1546
+ if (orin === 1) {
1547
+ const pieces2 = pieces[0];
1548
+ for (let i = 0; i < pieces2.length; i++) {
1549
+ const ni = pos2.pieces[i];
1550
+ if (this.textured) {
1551
+ colormods += pieces2[i].setTexture(filler, pieces2[ni]);
1552
+ } else {
1553
+ colormods += pieces2[i].setColor(filler, pieces2[ni]);
1554
+ }
1555
+ }
1556
+ } else {
1557
+ for (let ori = 0; ori < orin; ori++) {
1558
+ const pieces2 = pieces[ori];
1559
+ for (let i = 0; i < pieces2.length; i++) {
1560
+ const nori = (ori + orin - pos2.orientation[i]) % orin;
1561
+ const ni = pos2.pieces[i];
1562
+ if (this.textured) {
1563
+ colormods += pieces2[i].setTexture(filler, pieces[nori][ni]);
1564
+ } else {
1565
+ colormods += pieces2[i].setColor(filler, pieces[nori][ni]);
1566
+ }
1567
+ }
1568
+ }
1569
+ }
1570
+ }
1571
+ this.lastPos = p;
1572
+ }
1573
+ let vismods = 0;
1574
+ for (const moveProgress of p.movesInProgress) {
1575
+ const externalMove = moveProgress.move;
1576
+ const unswizzled = this.stickerDat.unswizzle(externalMove);
1577
+ if (!unswizzled) {
1578
+ return;
1579
+ }
1580
+ const move = externalMove;
1581
+ let quantumTransformation;
1582
+ try {
1583
+ quantumTransformation = this.kpuzzle.moveToTransformation(
1584
+ move.modified({ amount: 1 })
1585
+ );
1586
+ } catch (e) {
1587
+ const move1 = this.stickerDat.notationMapper.notationToInternal(move);
1588
+ if (move1) {
1589
+ const move2 = this.stickerDat.notationMapper.notationToExternal(
1590
+ move1.modified({ amount: 1 })
1591
+ );
1592
+ if (move2) {
1593
+ quantumTransformation = this.kpuzzle.moveToTransformation(move2);
1594
+ }
1595
+ }
1596
+ if (!quantumTransformation) {
1597
+ console.log(e);
1598
+ throw e;
1599
+ }
1600
+ }
1601
+ const ax = this.axesInfo[unswizzled.family];
1602
+ const turnNormal = ax.axis;
1603
+ const angle = -this.ease(moveProgress.fraction) * moveProgress.direction * unswizzled.amount * TAU / ax.order;
1604
+ this.movingObj.rotateOnAxis(turnNormal, angle);
1605
+ if (this.lastMoveTransformation !== quantumTransformation) {
1606
+ for (const orbit in this.stickers) {
1607
+ const pieces = this.stickers[orbit];
1608
+ const orin = pieces.length;
1609
+ const bmv = quantumTransformation.transformationData[orbit];
1610
+ for (let ori = 0; ori < orin; ori++) {
1611
+ const pieces2 = pieces[ori];
1612
+ for (let i = 0; i < pieces2.length; i++) {
1613
+ const p2 = pieces2[i];
1614
+ const ni = bmv.permutation[i];
1615
+ let tv = 0;
1616
+ if (ni !== i || bmv.orientationDelta[i] !== 0) {
1617
+ tv = 1;
1618
+ }
1619
+ if (tv !== p2.twistVal) {
1620
+ if (tv) {
1621
+ for (let j = p2.stickerStart; j < p2.stickerEnd; j++) {
1622
+ ind[j] |= 1;
1623
+ }
1624
+ for (let j = p2.hintStart; j < p2.hintEnd; j++) {
1625
+ ind[j] |= 1;
1626
+ }
1627
+ for (let j = p2.foundationStart; j < p2.foundationEnd; j++) {
1628
+ ind[j] |= 1;
1629
+ }
1630
+ } else {
1631
+ for (let j = p2.stickerStart; j < p2.stickerEnd; j++) {
1632
+ ind[j] &= ~1;
1633
+ }
1634
+ for (let j = p2.hintStart; j < p2.hintEnd; j++) {
1635
+ ind[j] &= ~1;
1636
+ }
1637
+ for (let j = p2.foundationStart; j < p2.foundationEnd; j++) {
1638
+ ind[j] &= ~1;
1639
+ }
1640
+ }
1641
+ p2.twistVal = tv;
1642
+ vismods++;
1643
+ }
1644
+ }
1645
+ }
1646
+ }
1647
+ this.lastMoveTransformation = quantumTransformation;
1648
+ }
1649
+ }
1650
+ if (this.#pendingStickeringUpdate || vismods) {
1651
+ this.filler.makeGroups(this.fixedGeo);
1652
+ }
1653
+ if (this.#pendingStickeringUpdate || colormods) {
1654
+ if (this.textured) {
1655
+ this.fixedGeo.getAttribute("uv").addUpdateRange(
1656
+ 0,
1657
+ 6 * this.foundationBound
1658
+ );
1659
+ this.fixedGeo.getAttribute("uv").needsUpdate = true;
1660
+ }
1661
+ if (this.#pendingStickeringUpdate || !this.textured) {
1662
+ this.fixedGeo.getAttribute("color").addUpdateRange(
1663
+ 0,
1664
+ 9 * this.foundationBound
1665
+ );
1666
+ this.fixedGeo.getAttribute("color").needsUpdate = true;
1667
+ }
1668
+ }
1669
+ this.scheduleRenderCallback();
1670
+ this.#pendingStickeringUpdate = false;
1671
+ }
1672
+ ease(fraction) {
1673
+ return smootherStep(fraction);
1674
+ }
1675
+ showHintFacelets(v) {
1676
+ this.showHintStickers = v;
1677
+ }
1678
+ updateMaterialArrays() {
1679
+ for (let i = 0; i < 8; i++) {
1680
+ this.materialArray1[i] = invisMaterial;
1681
+ this.materialArray2[i] = invisMaterial;
1682
+ }
1683
+ this.materialArray1[0] = this.stickerMaterial;
1684
+ this.materialArray2[1] = this.stickerMaterial;
1685
+ if (this.showHintStickers) {
1686
+ this.materialArray1[2] = this.hintMaterial;
1687
+ this.materialArray2[3] = this.hintMaterial;
1688
+ } else {
1689
+ this.materialArray1[2] = invisMaterial;
1690
+ this.materialArray2[3] = invisMaterial;
1691
+ }
1692
+ if (this.showFoundations) {
1693
+ this.materialArray1[6] = foundationMaterial;
1694
+ this.materialArray2[7] = foundationMaterial;
1695
+ } else {
1696
+ this.materialArray1[6] = invisMaterial;
1697
+ this.materialArray2[7] = invisMaterial;
1698
+ }
1699
+ }
1700
+ showFoundation(v) {
1701
+ this.showFoundations = v;
1702
+ }
1703
+ setHintStickerOpacity(v) {
1704
+ if (this.hintMaterialDisposable) {
1705
+ this.hintMaterial.dispose();
1706
+ this.hintMaterialDisposable = false;
1707
+ }
1708
+ if (v === 0) {
1709
+ this.hintMaterial = invisMaterial;
1710
+ } else if (v === 1) {
1711
+ this.hintMaterial = this.stickerMaterial;
1712
+ } else {
1713
+ this.hintMaterial = new MeshBasicMaterial2({
1714
+ vertexColors: true,
1715
+ transparent: true,
1716
+ opacity: v
1717
+ });
1718
+ this.hintMaterialDisposable = true;
1719
+ }
1720
+ }
1721
+ experimentalUpdateOptions(options) {
1722
+ if (options.hintFacelets !== void 0) {
1723
+ this.showHintFacelets(options.hintFacelets !== "none");
1724
+ }
1725
+ if (options.showFoundation !== void 0) {
1726
+ this.showFoundation(options.showFoundation);
1727
+ }
1728
+ if (options.hintStickerOpacity !== void 0) {
1729
+ this.setHintStickerOpacity(options.hintStickerOpacity);
1730
+ }
1731
+ this.#pendingStickeringUpdate = true;
1732
+ if (this.lastPos) {
1733
+ this.onPositionChange(this.lastPos);
1734
+ }
1735
+ if (typeof options.faceletScale !== "undefined" && options.faceletScale !== this.faceletScale) {
1736
+ console.warn(
1737
+ "Dynamic facelet scale is not yet supported for PG3D. For now, re-create the TwistyPlayer to change the facelet scale."
1738
+ );
1739
+ }
1740
+ this.updateMaterialArrays();
1741
+ this.scheduleRenderCallback();
1742
+ }
1743
+ adduvs() {
1744
+ const filler = this.filler;
1745
+ if (filler.uvs) {
1746
+ return;
1747
+ }
1748
+ this.filler.uvs = new Float32Array(12 * filler.sz);
1749
+ for (const orbit in this.stickers) {
1750
+ const pieces = this.stickers[orbit];
1751
+ const orin = pieces.length;
1752
+ for (let ori = 0; ori < orin; ori++) {
1753
+ const pieces2 = pieces[ori];
1754
+ for (const piece2 of pieces2) {
1755
+ piece2.addUVs(this.filler);
1756
+ }
1757
+ }
1758
+ }
1759
+ filler.uvs.copyWithin(6 * filler.sz, 0, 6 * filler.sz);
1760
+ const sa1 = filler.uvs.subarray(0, 6 * filler.sz);
1761
+ this.fixedGeo.setAttribute("uv", new BufferAttribute2(sa1, 2, true));
1762
+ }
1763
+ experimentalUpdateTexture(enabled, stickerTexture, hintTexture) {
1764
+ if (!stickerTexture) {
1765
+ enabled = false;
1766
+ }
1767
+ if (enabled && !this.filler.uvs) {
1768
+ this.adduvs();
1769
+ }
1770
+ this.textured = enabled;
1771
+ if (this.stickerMaterialDisposable) {
1772
+ this.stickerMaterial.dispose();
1773
+ this.stickerMaterialDisposable = false;
1774
+ }
1775
+ if (enabled) {
1776
+ this.stickerMaterial = new MeshBasicMaterial2({
1777
+ map: stickerTexture,
1778
+ side: FrontSide2,
1779
+ transparent: false
1780
+ });
1781
+ this.stickerMaterialDisposable = true;
1782
+ } else {
1783
+ this.stickerMaterial = basicStickerMaterial;
1784
+ }
1785
+ if (this.hintMaterialDisposable) {
1786
+ this.hintMaterial.dispose();
1787
+ this.hintMaterialDisposable = false;
1788
+ }
1789
+ if (enabled) {
1790
+ this.hintMaterial = new MeshBasicMaterial2({
1791
+ map: hintTexture,
1792
+ side: FrontSide2,
1793
+ transparent: true
1794
+ });
1795
+ this.hintMaterialDisposable = true;
1796
+ } else {
1797
+ this.hintMaterial = basicStickerMaterial;
1798
+ }
1799
+ if (enabled) {
1800
+ this.showHintFacelets(hintTexture !== null);
1801
+ }
1802
+ this.updateMaterialArrays();
1803
+ this.#pendingStickeringUpdate = true;
1804
+ if (this.lastPos) {
1805
+ this.onPositionChange(this.lastPos);
1806
+ }
1807
+ this.scheduleRenderCallback();
1808
+ }
1809
+ };
1810
+
1811
+ // src/cubing/twisty/heavy-code-imports/dynamic-entries/twisty-dynamic-3d.ts
1812
+ import { PerspectiveCamera } from "three/src/cameras/PerspectiveCamera.js";
1813
+ import { Raycaster } from "three/src/core/Raycaster.js";
1814
+ import { TextureLoader as TextureLoader2 } from "three/src/loaders/TextureLoader.js";
1815
+ import { Spherical } from "three/src/math/Spherical.js";
1816
+ import { Vector2 as Vector22 } from "three/src/math/Vector2.js";
1817
+ import { Vector3 as Vector33 } from "three/src/math/Vector3.js";
1818
+ import { WebGLRenderer } from "three/src/renderers/WebGLRenderer.js";
1819
+ import { Scene } from "three/src/scenes/Scene.js";
1820
+
1821
+ // src/cubing/twisty/views/3D/Twisty3DScene.ts
1822
+ var Twisty3DScene = class {
1823
+ renderTargets = /* @__PURE__ */ new Set();
1824
+ twisty3Ds = /* @__PURE__ */ new Set();
1825
+ threeJSScene = (async () => new (await bulk3DCode).ThreeScene())();
1826
+ addRenderTarget(renderTarget) {
1827
+ this.renderTargets.add(renderTarget);
1828
+ }
1829
+ scheduleRender() {
1830
+ for (const renderTarget of this.renderTargets) {
1831
+ renderTarget.scheduleRender();
1832
+ }
1833
+ }
1834
+ async addTwisty3DPuzzle(twisty3DPuzzle) {
1835
+ this.twisty3Ds.add(twisty3DPuzzle);
1836
+ (await this.threeJSScene).add(twisty3DPuzzle);
1837
+ }
1838
+ async removeTwisty3DPuzzle(twisty3DPuzzle) {
1839
+ this.twisty3Ds.delete(twisty3DPuzzle);
1840
+ (await this.threeJSScene).remove(twisty3DPuzzle);
1841
+ }
1842
+ async clearPuzzles() {
1843
+ for (const puz of this.twisty3Ds) {
1844
+ (await this.threeJSScene).remove(puz);
1845
+ }
1846
+ this.twisty3Ds.clear();
1847
+ }
1848
+ };
1849
+
1850
+ // src/cubing/twisty/heavy-code-imports/dynamic-entries/twisty-dynamic-3d.ts
1851
+ console.log("dynamic");
1852
+ async function cube3DShim(renderCallback, options) {
1853
+ return new Cube3D(await cube3x3x3.kpuzzle(), renderCallback, options);
1854
+ }
1855
+ async function pg3dShim(renderCallback, puzzleLoader, hintFacelets, faceletScale, darkIgnoredOrbits) {
1856
+ return new PG3D(
1857
+ renderCallback,
1858
+ await puzzleLoader.kpuzzle(),
1859
+ (await puzzleLoader.pg()).get3d({ darkIgnoredOrbits }),
1860
+ true,
1861
+ hintFacelets === "floating",
1862
+ void 0,
1863
+ faceletScale
1864
+ );
1865
+ }
1866
+ export {
1867
+ Cube3D,
1868
+ PG3D,
1869
+ PerspectiveCamera as ThreePerspectiveCamera,
1870
+ Raycaster as ThreeRaycaster,
1871
+ Scene as ThreeScene,
1872
+ Spherical as ThreeSpherical,
1873
+ TextureLoader2 as ThreeTextureLoader,
1874
+ Vector22 as ThreeVector2,
1875
+ Vector33 as ThreeVector3,
1876
+ WebGLRenderer as ThreeWebGLRenderer,
1877
+ Twisty3DScene,
1878
+ cube3DShim,
1879
+ pg3dShim
1880
+ };
1881
+ //# sourceMappingURL=twisty-dynamic-3d-5NZRNZ7C.js.map