cubing 0.63.3 → 0.63.5

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