imwithye commited on
Commit
f3bc628
·
1 Parent(s): f7605e1

org controls

Browse files
src/components/canvas.tsx CHANGED
@@ -1,21 +1,35 @@
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 { RubiksCube } from "./rubiks-cube";
 
 
8
 
9
  export const Canvas = () => {
 
 
 
 
10
  const { cubeRoughness, cubeSpeed } = useControls({
11
  cubeRoughness: { value: 0.5, min: 0.2, max: 0.8 },
12
  cubeSpeed: { value: 2, min: 1, max: 10 },
 
 
 
 
 
13
  });
14
 
15
  return (
16
- <ThreeCanvas shadows camera={{ position: [0, 0, 4.5], fov: 50 }}>
17
- <RubiksCube cubeRoughness={cubeRoughness} cubeSpeed={cubeSpeed} />
18
- <Env />
19
- </ThreeCanvas>
 
 
 
20
  );
21
  };
 
1
  "use client";
2
 
3
+ import { useControls, Leva } from "leva";
4
  import { Canvas as ThreeCanvas } from "@react-three/fiber";
5
 
6
  import { Env } from "../components/env";
7
  import { RubiksCube } from "./rubiks-cube";
8
+ import { useState, useTransition } from "react";
9
+ import { PresetsType } from "@react-three/drei/helpers/environment-assets";
10
 
11
  export const Canvas = () => {
12
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
13
+ const [_, startTransition] = useTransition();
14
+ const [background, setBackground] = useState<PresetsType>("sunset");
15
+
16
  const { cubeRoughness, cubeSpeed } = useControls({
17
  cubeRoughness: { value: 0.5, min: 0.2, max: 0.8 },
18
  cubeSpeed: { value: 2, min: 1, max: 10 },
19
+ background: {
20
+ value: background,
21
+ options: ["sunset", "dawn", "forest"],
22
+ onChange: (value) => startTransition(() => setBackground(value)),
23
+ },
24
  });
25
 
26
  return (
27
+ <>
28
+ <Leva />
29
+ <ThreeCanvas shadows camera={{ position: [0, 0, 4.5], fov: 50 }}>
30
+ <RubiksCube cubeRoughness={cubeRoughness} cubeSpeed={cubeSpeed} />
31
+ <Env background={background} />
32
+ </ThreeCanvas>
33
+ </>
34
  );
35
  };
src/components/consts.tsx CHANGED
@@ -14,3 +14,21 @@ export const Rotations: Record<FacingDirection, [number, number, number]> = {
14
  top: [-Math.PI / 2, 0, 0],
15
  bottom: [Math.PI / 2, 0, 0],
16
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  top: [-Math.PI / 2, 0, 0],
15
  bottom: [Math.PI / 2, 0, 0],
16
  };
17
+
18
+ export const Actions: Array<{
19
+ faceDirection: FacingDirection;
20
+ direction: "clockwise" | "counter-clockwise";
21
+ }> = [
22
+ { faceDirection: "front", direction: "clockwise" },
23
+ { faceDirection: "front", direction: "counter-clockwise" },
24
+ { faceDirection: "right", direction: "clockwise" },
25
+ { faceDirection: "right", direction: "counter-clockwise" },
26
+ { faceDirection: "left", direction: "clockwise" },
27
+ { faceDirection: "left", direction: "counter-clockwise" },
28
+ { faceDirection: "back", direction: "clockwise" },
29
+ { faceDirection: "back", direction: "counter-clockwise" },
30
+ { faceDirection: "top", direction: "clockwise" },
31
+ { faceDirection: "top", direction: "counter-clockwise" },
32
+ { faceDirection: "bottom", direction: "clockwise" },
33
+ { faceDirection: "bottom", direction: "counter-clockwise" },
34
+ ];
src/components/env.tsx CHANGED
@@ -1,24 +1,15 @@
1
  "ue client";
2
 
3
- import { useState, useTransition } from "react";
4
  import { Environment, CameraControls } from "@react-three/drei";
5
  import { PresetsType } from "@react-three/drei/helpers/environment-assets";
6
- import { useControls } from "leva";
7
  import { CameraControlsImpl } from "@react-three/drei";
8
  const { ACTION } = CameraControlsImpl;
9
 
10
- export const Env = () => {
11
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
- const [_, startTransition] = useTransition();
13
 
14
- const [background, setBackground] = useState<PresetsType>("sunset");
15
- useControls({
16
- background: {
17
- value: background,
18
- options: ["sunset", "dawn", "forest"],
19
- onChange: (value) => startTransition(() => setBackground(value)),
20
- },
21
- });
22
  return (
23
  <>
24
  <CameraControls
@@ -27,6 +18,7 @@ export const Env = () => {
27
  azimuthAngle={0.8}
28
  maxPolarAngle={Math.PI / 1.2}
29
  minPolarAngle={-Math.PI / 1.2}
 
30
  maxDistance={10}
31
  minDistance={4}
32
  mouseButtons={{
 
1
  "ue client";
2
 
 
3
  import { Environment, CameraControls } from "@react-three/drei";
4
  import { PresetsType } from "@react-three/drei/helpers/environment-assets";
 
5
  import { CameraControlsImpl } from "@react-three/drei";
6
  const { ACTION } = CameraControlsImpl;
7
 
8
+ type EnvProps = {
9
+ background: PresetsType;
10
+ };
11
 
12
+ export const Env = ({ background }: EnvProps) => {
 
 
 
 
 
 
 
13
  return (
14
  <>
15
  <CameraControls
 
18
  azimuthAngle={0.8}
19
  maxPolarAngle={Math.PI / 1.2}
20
  minPolarAngle={-Math.PI / 1.2}
21
+ distance={10}
22
  maxDistance={10}
23
  minDistance={4}
24
  mouseButtons={{