From eccdabf64dc1f2d0f29737b3fef6e0c2e312f7b9 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Tue, 28 Oct 2025 05:23:08 +0000 Subject: [PATCH] Fix cube coloring interaction --- src/components/CubeColoring.tsx | 64 ++++++++++++--------------------- 1 file changed, 23 insertions(+), 41 deletions(-) diff --git a/src/components/CubeColoring.tsx b/src/components/CubeColoring.tsx index 06c468a..f751d4b 100644 --- a/src/components/CubeColoring.tsx +++ b/src/components/CubeColoring.tsx @@ -26,17 +26,18 @@ const colorPalette = [ const faceNames = ['Top', 'Bottom', 'Front', 'Back', 'Right', 'Left']; // Rotation definitions: each rotation maps face indices [0,1,2,3,4,5] to new positions +// Also includes actual 3D rotation values for visualization const rotations = [ - { name: 'Identity', permutation: [0, 1, 2, 3, 4, 5], description: 'No rotation' }, - { name: 'Y-90° (vertical)', permutation: [0, 1, 4, 5, 3, 2], description: 'Front→Right→Back→Left' }, - { name: 'Y-180°', permutation: [0, 1, 3, 2, 5, 4], description: 'Front↔Back, Right↔Left' }, - { name: 'Y-270°', permutation: [0, 1, 5, 4, 2, 3], description: 'Front→Left→Back→Right' }, - { name: 'X-90° (horizontal)', permutation: [2, 3, 1, 0, 4, 5], description: 'Top→Front→Bottom→Back' }, - { name: 'X-180°', permutation: [1, 0, 3, 2, 4, 5], description: 'Top↔Bottom, Front↔Back' }, - { name: 'X-270°', permutation: [3, 2, 0, 1, 4, 5], description: 'Top→Back→Bottom→Front' }, - { name: 'Z-90° (front-back)', permutation: [4, 5, 2, 3, 1, 0], description: 'Top→Right→Bottom→Left' }, - { name: 'Z-180°', permutation: [1, 0, 2, 3, 5, 4], description: 'Top↔Bottom, Right↔Left' }, - { name: 'Z-270°', permutation: [5, 4, 2, 3, 0, 1], description: 'Top→Left→Bottom→Right' }, + { name: 'Identity', permutation: [0, 1, 2, 3, 4, 5], description: 'No rotation', rotation: [0, 0, 0] }, + { name: 'Y-90° (vertical)', permutation: [0, 1, 4, 5, 3, 2], description: 'Front→Right→Back→Left', rotation: [0, Math.PI / 2, 0] }, + { name: 'Y-180°', permutation: [0, 1, 3, 2, 5, 4], description: 'Front↔Back, Right↔Left', rotation: [0, Math.PI, 0] }, + { name: 'Y-270°', permutation: [0, 1, 5, 4, 2, 3], description: 'Front→Left→Back→Right', rotation: [0, -Math.PI / 2, 0] }, + { name: 'X-90° (horizontal)', permutation: [2, 3, 1, 0, 4, 5], description: 'Top→Front→Bottom→Back', rotation: [Math.PI / 2, 0, 0] }, + { name: 'X-180°', permutation: [1, 0, 3, 2, 4, 5], description: 'Top↔Bottom, Front↔Back', rotation: [Math.PI, 0, 0] }, + { name: 'X-270°', permutation: [3, 2, 0, 1, 4, 5], description: 'Top→Back→Bottom→Front', rotation: [-Math.PI / 2, 0, 0] }, + { name: 'Z-90° (front-back)', permutation: [4, 5, 2, 3, 1, 0], description: 'Top→Right→Bottom→Left', rotation: [0, 0, Math.PI / 2] }, + { name: 'Z-180°', permutation: [1, 0, 2, 3, 5, 4], description: 'Top↔Bottom, Right↔Left', rotation: [0, 0, Math.PI] }, + { name: 'Z-270°', permutation: [5, 4, 2, 3, 0, 1], description: 'Top→Left→Bottom→Right', rotation: [0, 0, -Math.PI / 2] }, ]; interface PaintableCubeProps { @@ -47,12 +48,6 @@ interface PaintableCubeProps { function PaintableCube({ colors, onFaceClick }: PaintableCubeProps) { const meshRef = useRef(null); - useFrame(() => { - if (meshRef.current) { - meshRef.current.rotation.y += 0.005; - } - }); - return ( @@ -63,33 +58,14 @@ function PaintableCube({ colors, onFaceClick }: PaintableCubeProps) { ); } -function PermutationCube({ permutation }: { permutation: number[] }) { +function RotatedCube({ colors, rotation }: { colors: string[], rotation: number[] }) { const meshRef = useRef(null); - useFrame(() => { - if (meshRef.current) { - meshRef.current.rotation.y += 0.005; - } - }); - - // Create materials based on permutation - const baseMaterials = [ - new THREE.MeshStandardMaterial({ color: '#ef4444' }), // red - top - new THREE.MeshStandardMaterial({ color: '#3b82f6' }), // blue - bottom - new THREE.MeshStandardMaterial({ color: '#22c55e' }), // green - front - new THREE.MeshStandardMaterial({ color: '#eab308' }), // yellow - back - new THREE.MeshStandardMaterial({ color: '#a855f7' }), // purple - right - new THREE.MeshStandardMaterial({ color: '#f97316' }), // orange - left - ]; - - // Apply permutation: materials[i] shows the color that should be at position i - const permutedMaterials = permutation.map(originalIndex => baseMaterials[originalIndex]); - return ( - + - {permutedMaterials.map((material, i) => ( - + {colors.map((color, i) => ( + ))} ); @@ -246,7 +222,10 @@ const CubeColoring = ({ showSocialShare = false, shareUrl }: CubeColoringProps) - + @@ -320,7 +299,10 @@ const CubeColoring = ({ showSocialShare = false, shareUrl }: CubeColoringProps) - +