From a0fb74e1648d49ac860105c0cda2a4fc6a486d20 Mon Sep 17 00:00:00 2001 From: Tyson Decker Date: Tue, 1 Mar 2022 16:13:53 -0700 Subject: [PATCH] alter square 1 geometry a bit to help the order the faces are rendered in. It's not perfect but It works pretty well for the default angle that the 3d square 1 is viewed at. --- package.json | 2 +- src/algorithms/square1.ts | 2 -- src/puzzles/square1/constants.ts | 2 +- src/puzzles/square1/square1.ts | 44 ++++++++++++++++++++++++-------- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 7971bc8..94bb61a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/algorithms/square1.ts b/src/algorithms/square1.ts index 9af137c..2bde552 100644 --- a/src/algorithms/square1.ts +++ b/src/algorithms/square1.ts @@ -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; diff --git a/src/puzzles/square1/constants.ts b/src/puzzles/square1/constants.ts index 647c1e9..3d3c87b 100644 --- a/src/puzzles/square1/constants.ts +++ b/src/puzzles/square1/constants.ts @@ -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; diff --git a/src/puzzles/square1/square1.ts b/src/puzzles/square1/square1.ts index 2637a25..dbdb0dd 100644 --- a/src/puzzles/square1/square1.ts +++ b/src/puzzles/square1/square1.ts @@ -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, @@ -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); } @@ -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); } @@ -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); } @@ -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]);