Skip to content

Commit

Permalink
alter square 1 geometry a bit to help the order the faces are rendere…
Browse files Browse the repository at this point in the history
…d in. It's not perfect but It works pretty well for the default angle that the 3d square 1 is viewed at.
  • Loading branch information
tdecker91 committed Mar 1, 2022
1 parent a33a2b3 commit a0fb74e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sr-puzzlegen",
"version": "1.0.3-beta.19",
"version": "1.0.3-beta.22",
"description": "",
"main": "dist/lib/index.js",
"types": "dist/lib/index.d.ts",
Expand Down
2 changes: 0 additions & 2 deletions src/algorithms/square1.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Square1Move } from "./../simulator/square1/square1Simulator";
import { Square1Turns } from "../simulator/square1/square1Simulator";
import { Turn } from "./algorithm";

const square1TurnRegex = /((\()?(-?\d)\s*,\s*(-?\d)(\))?)|(\/)/g;

Expand Down
2 changes: 1 addition & 1 deletion src/puzzles/square1/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PIECE_TYPE } from "./enum";
import { Sqaure1Piece } from "./interface";
import { vec3 } from "gl-matrix";

export const ROTATION_VECTOR: vec3 = [0.96875, -0.24803, 0];
export const ROTATION_VECTOR: vec3 = [0.92875, -0.24803, 0];

export const TOP_COLOR: IColor = YELLOW;
export const BOTTOM_COLOR: IColor = WHITE;
Expand Down
44 changes: 33 additions & 11 deletions src/puzzles/square1/square1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { vec3 } from "gl-matrix";
import { IColor } from "./../../geometry/color";
import { Group } from "../../geometry/group";

const INNER_FACE_COLOR = { value: '#333', stroke: '#333' };

export class Square1 extends Square1Builder {
constructor(
topLayer: Sqaure1Piece[] = SOLVED_TOP_PIECES,
Expand Down Expand Up @@ -47,13 +49,18 @@ export class Square1 extends Square1Builder {
// they show gray when the cube is scrambled. But they are overlapping sometimes
// with outward sticker faces. removing them for now, but it'd be nice to
// fix this.
// new Face([4, 5, 6, 7], points, { value: '#333' }),
// new Face([0, 1, 5, 4], points, { value: '#333' }),
new Face([4, 5, 6, 7], points, INNER_FACE_COLOR),
new Face([0, 1, 5, 4], points, INNER_FACE_COLOR),
new Face([2, 3, 7, 6], points, side1),
new Face([1, 2, 6, 5], points, side2),
// new Face([0, 3, 7, 4], points, { value: '#333' }),
new Face([0, 3, 7, 4], points, INNER_FACE_COLOR),
];

const innerCentroid = vec3.fromValues(this.halfSide / 2, this.halfSide / 2, this.halfSide / 2);
faces[1].centroid = innerCentroid;
faces[2].centroid = innerCentroid;
faces[5].centroid = innerCentroid;

return new Geometry(points, faces);
}

Expand Down Expand Up @@ -102,12 +109,24 @@ export class Square1 extends Square1Builder {

const faces: IFace[] = [
new Face([0, 1, 2], points, top),
// new Face([3, 4, 5], points, { value: '#333' }),
new Face([3, 4, 5], points, INNER_FACE_COLOR),
new Face([1, 2, 5, 4], points, side),
// new Face([0, 1, 4, 3], points, { value: '#333' }),
// new Face([0, 2, 5, 3], points, { value: '#333' }),
new Face([0, 1, 4, 3], points, INNER_FACE_COLOR),
new Face([0, 2, 5, 3], points, INNER_FACE_COLOR),
];

const innerFaceCentroid = vec3.rotateZ(
vec3.create(),
[0, this.halfSide / 2, this.halfSide / 2],
[0, 0, 0],
DEG_30_RADIANS
);

// Override centroid to avoid drawing over outside stickers
faces[1].centroid = innerFaceCentroid;
faces[3].centroid = innerFaceCentroid;
faces[4].centroid = innerFaceCentroid;

return new Geometry(points, faces);
}

Expand All @@ -129,10 +148,17 @@ export class Square1 extends Square1Builder {
new Face([4, 5, 6, 7], vertices, { value: "#333" }),
new Face([0, 1, 5, 4], vertices, side),
new Face([1, 2, 6, 5], vertices, back),
new Face([2, 3, 7, 6], vertices, { value: "#333" }),
// new Face([2, 3, 7, 6], vertices, { value: "#333" }),
new Face([0, 3, 7, 4], vertices, front),
];

const innerFaceCentroid = vec3.fromValues(-this.halfSide / 2, 0, 0);

// Override centroid to avoid drawing over outside stickers
faces[0].centroid = innerFaceCentroid;
faces[1].centroid = innerFaceCentroid;
faces[2].centroid = vec3.fromValues(-(this.halfSide + (this.halfSide * .45)), 0, 0);

return new Geometry(vertices, faces);
}

Expand All @@ -144,10 +170,6 @@ export class Square1 extends Square1Builder {
const topLayer = new Group(this.makeLayer(top));
const bottomLayer = new Group(this.makeLayer(bottom));

// Prevent overlapping faces
topLayer.translate([0, 0, 0.005]);
bottomLayer.translate([0, 0, -0.005]);

bottomLayer.rotate(Math.PI, [1, 0, 0]);
bottomLayer.rotate(DEG_30_RADIANS, [0, 0, 1]);

Expand Down

0 comments on commit a0fb74e

Please sign in to comment.