From 31beb8b95d758d7bfdbb6e233e0de0d9f9429a21 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期六, 11 五月 2024 11:09:01 +0800
Subject: [PATCH] #
---
src/components/ctrl.jsx | 55 +++++++++++++++++++++++++++
src/components/camera.jsx | 35 -----------------
src/pages/fiber.jsx | 2 +
3 files changed, 57 insertions(+), 35 deletions(-)
diff --git a/src/components/camera.jsx b/src/components/camera.jsx
index a740fc4..2ff0105 100644
--- a/src/components/camera.jsx
+++ b/src/components/camera.jsx
@@ -2,49 +2,14 @@
import { useThree } from '@react-three/fiber';
import {
PerspectiveCamera,
- CameraControls,
- PresentationControls,
- FlyControls,
- OrbitControls,
- FirstPersonControls,
- MapControls,
} from '@react-three/drei';
const Camera = (props) => {
const threeObj = useThree();
const camera = threeObj.camera;
- const [choiceCtrls, setChoiceCtrls] = useState(true);
-
- const ctrl = () => {
- return (
- <group>
- {/* 鐩告満鎺у埗鍣� */}
- {/* <PresentationControls /> */}
- <CameraControls />
- {/* <PointerCtrl /> */}
- </group>
- );
- };
-
- const flyCtrl = () => {
- return (
- <group>
- <FirstPersonControls
- far={100000}
- movementSpeed={100}
- activeLook={false}
- lookVertical={true}
- ></FirstPersonControls>
- {/* <OrbitControls /> */}
- <MapControls zoomSpeed={0.1} />
- </group>
- );
- };
-
return (
<>
- {choiceCtrls ? ctrl() : flyCtrl()}
<PerspectiveCamera
makeDefault
position={[-100, 200, 1000]}
diff --git a/src/components/ctrl.jsx b/src/components/ctrl.jsx
new file mode 100644
index 0000000..dca23c7
--- /dev/null
+++ b/src/components/ctrl.jsx
@@ -0,0 +1,55 @@
+import React, { useState, useEffect } from 'react';
+import {
+ PerspectiveCamera,
+ CameraControls,
+ PresentationControls,
+ FlyControls,
+ OrbitControls,
+ FirstPersonControls,
+ MapControls,
+} from '@react-three/drei';
+
+const Controls = (props) => {
+ const [choiceCtrls, setChoiceCtrls] = useState(false);
+
+ useEffect(() => {
+ if (props.fly) {
+ setChoiceCtrls(false);
+ } else {
+ setChoiceCtrls(true);
+ }
+ }, [props])
+
+ const ctrl = () => {
+ return (
+ <group>
+ {/* <PresentationControls /> */}
+ <CameraControls />
+ {/* <PointerCtrl /> */}
+ </group>
+ );
+ };
+
+ const flyCtrl = () => {
+ return (
+ <group>
+ <FirstPersonControls
+ far={100000}
+ movementSpeed={100}
+ activeLook={false}
+ lookVertical={true}
+ ></FirstPersonControls>
+ {/* <OrbitControls /> */}
+ <MapControls zoomSpeed={0.1} />
+ </group>
+ );
+ };
+
+ return (
+ <>
+ {choiceCtrls ? ctrl() : flyCtrl()}
+ </>
+ );
+};
+
+export default Controls;
diff --git a/src/pages/fiber.jsx b/src/pages/fiber.jsx
index c108f86..47f6faf 100644
--- a/src/pages/fiber.jsx
+++ b/src/pages/fiber.jsx
@@ -4,6 +4,7 @@
import Help from '../components/help'
import Lights from '../components/light'
import Camera from '../components/camera'
+import Controls from '../components/ctrl'
import Buildings from '../components/buidings'
import TreeGroup from '../components/tree-group'
import House from '../components/house'
@@ -23,6 +24,7 @@
>
<Lights />
<Camera />
+ <Controls />
<Sky distance={450000} sunPosition={[0, 1, 0]} inclination={0} azimuth={0.25} />
<Buildings />
<TreeGroup />
--
Gitblit v1.9.1