imwithye commited on
Commit
ca23eb9
·
1 Parent(s): d0671b5

use init position

Browse files
src/components/cube-piece.tsx CHANGED
@@ -1,4 +1,7 @@
 
 
1
  import { RoundedBox } from "@react-three/drei";
 
2
 
3
  // Standard Rubik's cube colors
4
  const CUBE_COLORS = {
@@ -12,11 +15,21 @@ const CUBE_COLORS = {
12
 
13
  type CubePieceProps = {
14
  roughness: number;
15
- position: [number, number, number];
16
  };
17
 
18
- export const CubePiece = ({ roughness, position }: CubePieceProps) => {
19
- const [x, y, z] = position;
 
 
 
 
 
 
 
 
 
 
20
 
21
  return (
22
  <mesh position={position}>
@@ -28,7 +41,9 @@ export const CubePiece = ({ roughness, position }: CubePieceProps) => {
28
  />
29
  </RoundedBox>
30
 
31
- {Object.keys(CUBE_COLORS).map((face) => {
 
 
32
  const color = CUBE_COLORS[face as keyof typeof CUBE_COLORS];
33
  let stickerPosition: [number, number, number] = [0, 0, 0];
34
  let stickerRotation: [number, number, number] = [0, 0, 0];
 
1
+ "use client";
2
+
3
  import { RoundedBox } from "@react-three/drei";
4
+ import { useState } from "react";
5
 
6
  // Standard Rubik's cube colors
7
  const CUBE_COLORS = {
 
15
 
16
  type CubePieceProps = {
17
  roughness: number;
18
+ initialPosition: [number, number, number];
19
  };
20
 
21
+ export const CubePiece = ({ roughness, initialPosition }: CubePieceProps) => {
22
+ const [x, y, z] = initialPosition;
23
+ const [position] = useState<[number, number, number]>([x, y, z]);
24
+
25
+ const visibleFaces = {
26
+ front: z > 0,
27
+ back: z < 0,
28
+ right: x > 0,
29
+ left: x < 0,
30
+ top: y > 0,
31
+ bottom: y < 0,
32
+ };
33
 
34
  return (
35
  <mesh position={position}>
 
41
  />
42
  </RoundedBox>
43
 
44
+ {Object.entries(visibleFaces).map(([face, isVisible]) => {
45
+ if (!isVisible) return null;
46
+
47
  const color = CUBE_COLORS[face as keyof typeof CUBE_COLORS];
48
  let stickerPosition: [number, number, number] = [0, 0, 0];
49
  let stickerRotation: [number, number, number] = [0, 0, 0];
src/components/rubiks-cube.tsx CHANGED
@@ -19,7 +19,7 @@ export const RubiksCube = ({ roughness }: RubiksCubeProps) => {
19
  {CUBE_POSITIONS.map((position) => (
20
  <CubePiece
21
  key={position.join(",")}
22
- position={position}
23
  roughness={roughness}
24
  />
25
  ))}
 
19
  {CUBE_POSITIONS.map((position) => (
20
  <CubePiece
21
  key={position.join(",")}
22
+ initialPosition={position}
23
  roughness={roughness}
24
  />
25
  ))}