imwithye commited on
Commit
e95d66b
·
1 Parent(s): fc3783e

add cube piece

Browse files
src/app/page.tsx CHANGED
@@ -1,34 +1,9 @@
1
- "use client";
2
 
3
- import { useControls } from "leva";
4
- import { Canvas } from "@react-three/fiber";
5
- import {
6
- Center,
7
- } from "@react-three/drei";
8
-
9
- import { Env } from "../components/env";
10
-
11
- export default function App() {
12
- return (
13
- <Canvas shadows camera={{ position: [0, 0, 4.5], fov: 50 }}>
14
- <group position={[0, -0.65, 0]}>
15
- <Sphere />
16
- </group>
17
- <Env />
18
- </Canvas>
19
- );
20
- }
21
-
22
- function Sphere() {
23
- const { roughness } = useControls({
24
- roughness: { value: 1, min: 0, max: 1 },
25
- });
26
  return (
27
- <Center top>
28
- <mesh castShadow>
29
- <sphereGeometry args={[0.75, 64, 64]} />
30
- <meshStandardMaterial metalness={1} roughness={roughness} />
31
- </mesh>
32
- </Center>
33
  );
34
  }
 
1
+ import { Canvas } from "@/components/canvas";
2
 
3
+ export default function Home() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  return (
5
+ <>
6
+ <Canvas />
7
+ </>
 
 
 
8
  );
9
  }
src/components/canvas.tsx ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use client";
2
+
3
+ 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} />
17
+ <Env />
18
+ </ThreeCanvas>
19
+ );
20
+ };
src/components/cube-piece.tsx ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { RoundedBox } from "@react-three/drei";
2
+
3
+ type CubePieceProps = {
4
+ roughness: number;
5
+ };
6
+
7
+ export const CubePiece = ({ roughness }: CubePieceProps) => {
8
+ return (
9
+ <mesh>
10
+ <RoundedBox args={[0.95, 0.95, 0.95]} radius={0.05} smoothness={4}>
11
+ <meshStandardMaterial
12
+ color="#2a2a2a"
13
+ metalness={1}
14
+ roughness={roughness}
15
+ />
16
+ </RoundedBox>
17
+ </mesh>
18
+ );
19
+ };
src/components/env.tsx CHANGED
@@ -26,8 +26,8 @@ export const Env = () => {
26
  enableZoom={true}
27
  minDistance={4}
28
  maxDistance={10}
29
- minPolarAngle={Math.PI / 2.1}
30
- maxPolarAngle={Math.PI / 2.1}
31
  />
32
  <Environment preset={preset} background blur={1} />
33
  </>
 
26
  enableZoom={true}
27
  minDistance={4}
28
  maxDistance={10}
29
+ minPolarAngle={-Math.PI}
30
+ maxPolarAngle={Math.PI}
31
  />
32
  <Environment preset={preset} background blur={1} />
33
  </>