Spaces:
Sleeping
Sleeping
make sure the order is correct
Browse files
src/components/rotation-controller.ts
CHANGED
|
@@ -58,7 +58,7 @@ export class RotationController {
|
|
| 58 |
return false;
|
| 59 |
}
|
| 60 |
|
| 61 |
-
private
|
| 62 |
const faces = mesh.children.filter((child) => child.userData.isFace);
|
| 63 |
let axis: 'x' | 'y' | 'z' = 'x';
|
| 64 |
switch (faceDirection) {
|
|
@@ -86,8 +86,16 @@ export class RotationController {
|
|
| 86 |
maxFace = face as Mesh;
|
| 87 |
}
|
| 88 |
}
|
| 89 |
-
if (!maxFace) return -1; // this should never happen
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
}
|
| 92 |
|
| 93 |
static getInstance() {
|
|
@@ -138,8 +146,8 @@ export class RotationController {
|
|
| 138 |
return ['front', 'back', 'right', 'left', 'top', 'bottom'].map((f) => {
|
| 139 |
const faceDirection = f as FacingDirection;
|
| 140 |
const cubes = this.getCubes(faceDirection);
|
| 141 |
-
const indices = cubes.map((cube) => this.
|
| 142 |
-
return indices;
|
| 143 |
});
|
| 144 |
}
|
| 145 |
|
|
|
|
| 58 |
return false;
|
| 59 |
}
|
| 60 |
|
| 61 |
+
private getCubeFaceData(mesh: Mesh, faceDirection: FacingDirection) {
|
| 62 |
const faces = mesh.children.filter((child) => child.userData.isFace);
|
| 63 |
let axis: 'x' | 'y' | 'z' = 'x';
|
| 64 |
switch (faceDirection) {
|
|
|
|
| 86 |
maxFace = face as Mesh;
|
| 87 |
}
|
| 88 |
}
|
| 89 |
+
if (!maxFace) return { colorIndex: -1, worldPosition: new Vector3(), rank: Infinity }; // this should never happen
|
| 90 |
+
const worldPosition = new Vector3();
|
| 91 |
+
maxFace.getWorldPosition(worldPosition);
|
| 92 |
+
const axis2 = ['x', 'y', 'z'].filter((x) => x !== axis) as Array<'x' | 'y' | 'z'>;
|
| 93 |
+
const rank = worldPosition[axis2[0]] * 100 + worldPosition[axis2[1]] * 10;
|
| 94 |
+
return {
|
| 95 |
+
colorIndex: maxFace.userData.faceColorIndex,
|
| 96 |
+
worldPosition: worldPosition,
|
| 97 |
+
rank: rank,
|
| 98 |
+
};
|
| 99 |
}
|
| 100 |
|
| 101 |
static getInstance() {
|
|
|
|
| 146 |
return ['front', 'back', 'right', 'left', 'top', 'bottom'].map((f) => {
|
| 147 |
const faceDirection = f as FacingDirection;
|
| 148 |
const cubes = this.getCubes(faceDirection);
|
| 149 |
+
const indices = cubes.map((cube) => this.getCubeFaceData(cube, faceDirection)).sort((a, b) => a.rank - b.rank);
|
| 150 |
+
return indices.map((i) => i.colorIndex);
|
| 151 |
});
|
| 152 |
}
|
| 153 |
|