imwithye commited on
Commit
a6e23da
·
1 Parent(s): 1bc1cd0
src/components/canvas.tsx CHANGED
@@ -4,16 +4,16 @@ import { useControls } from "leva";
4
  import { Canvas as ThreeCanvas } from "@react-three/fiber";
5
 
6
  import { Env } from "../components/env";
7
- import { CubePiece } from "@/components/cube-piece";
8
 
9
  export const Canvas = () => {
10
  const { roughness } = useControls({
11
- roughness: { value: 1, min: 0, max: 1 },
12
  });
13
 
14
  return (
15
  <ThreeCanvas shadows camera={{ position: [0, 0, 4.5], fov: 50 }}>
16
- <CubePiece roughness={roughness} position={[0, 0, 1]} />
17
  <Env />
18
  </ThreeCanvas>
19
  );
 
4
  import { Canvas as ThreeCanvas } from "@react-three/fiber";
5
 
6
  import { Env } from "../components/env";
7
+ import { RubiksCube } from "./rubiks-cube";
8
 
9
  export const Canvas = () => {
10
  const { roughness } = useControls({
11
+ roughness: { value: 0.5, min: 0.2, max: 0.8 },
12
  });
13
 
14
  return (
15
  <ThreeCanvas shadows camera={{ position: [0, 0, 4.5], fov: 50 }}>
16
+ <RubiksCube roughness={roughness} />
17
  <Env />
18
  </ThreeCanvas>
19
  );
src/components/rubiks-cube.tsx ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { CubePiece } from "./cube-piece";
2
+
3
+ const CUBE_POSITIONS: Array<[number, number, number]> = [];
4
+ for (let x = -0.5; x <= 0.5; x++) {
5
+ for (let y = -0.5; y <= 0.5; y++) {
6
+ for (let z = -0.5; z <= 0.5; z++) {
7
+ CUBE_POSITIONS.push([x, y, z]);
8
+ }
9
+ }
10
+ }
11
+
12
+ type RubiksCubeProps = {
13
+ roughness: number;
14
+ };
15
+
16
+ export const RubiksCube = ({ roughness }: RubiksCubeProps) => {
17
+ return (
18
+ <group>
19
+ {CUBE_POSITIONS.map((position) => (
20
+ <CubePiece
21
+ key={position.join(",")}
22
+ position={position}
23
+ roughness={roughness}
24
+ />
25
+ ))}
26
+ </group>
27
+ );
28
+ };