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

update camera control

Browse files
src/components/env.tsx CHANGED
@@ -1,38 +1,47 @@
1
  "ue client";
2
 
3
  import { useState, useTransition } from "react";
4
- import { Environment, OrbitControls } from "@react-three/drei";
5
  import { PresetsType } from "@react-three/drei/helpers/environment-assets";
6
  import { useControls } from "leva";
 
 
7
 
8
  export const Env = () => {
9
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
10
  const [_, startTransition] = useTransition();
11
 
12
- const [preset, setPreset] = useState<PresetsType>("sunset");
13
- const { autoRotate } = useControls({
14
- autoRotate: {
15
- value: false,
16
- },
17
- preset: {
18
- value: preset,
19
  options: ["sunset", "dawn", "forest"],
20
- onChange: (value) => startTransition(() => setPreset(value)),
21
  },
22
  });
23
  return (
24
  <>
25
- <OrbitControls
26
- autoRotate={autoRotate}
27
- autoRotateSpeed={0.5}
28
- enablePan={false}
29
- enableZoom={true}
30
- minDistance={4}
31
  maxDistance={10}
32
- minPolarAngle={-Math.PI}
33
- maxPolarAngle={Math.PI}
 
 
 
 
 
 
 
 
 
 
34
  />
35
- <Environment preset={preset} background blur={1} />
36
  </>
37
  );
38
  };
 
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
25
+ makeDefault
26
+ polarAngle={0.8}
27
+ azimuthAngle={0.8}
28
+ maxPolarAngle={Math.PI / 1.2}
29
+ minPolarAngle={-Math.PI / 1.2}
30
  maxDistance={10}
31
+ minDistance={4}
32
+ mouseButtons={{
33
+ left: ACTION.ROTATE,
34
+ middle: ACTION.DOLLY,
35
+ right: ACTION.ROTATE,
36
+ wheel: ACTION.DOLLY,
37
+ }}
38
+ touches={{
39
+ one: ACTION.TOUCH_ROTATE,
40
+ two: ACTION.TOUCH_DOLLY,
41
+ three: ACTION.TOUCH_DOLLY,
42
+ }}
43
  />
44
+ <Environment preset={background} background blur={1} />
45
  </>
46
  );
47
  };
src/components/rotator.tsx CHANGED
@@ -4,7 +4,6 @@ import { RotationPanel } from "./rotation-panel";
4
  import { Group } from "three";
5
  import { Fragment, useRef } from "react";
6
  import { useFrame } from "@react-three/fiber";
7
- import { useControls } from "leva";
8
 
9
  type RotateArgs = {
10
  rotatingFaceDirection: FacingDirection;
 
4
  import { Group } from "three";
5
  import { Fragment, useRef } from "react";
6
  import { useFrame } from "@react-three/fiber";
 
7
 
8
  type RotateArgs = {
9
  rotatingFaceDirection: FacingDirection;