@@ -7,7 +7,12 @@ import {
77 Sphere ,
88 StatsGl ,
99} from "@react-three/drei" ;
10- import { BackSide , MeshBasicMaterial as ThreeMeshBasicMaterial } from "three" ;
10+ import {
11+ BackSide ,
12+ MeshBasicMaterial as ThreeMeshBasicMaterial ,
13+ OrthographicCamera as ThreeOrthographicCamera ,
14+ PerspectiveCamera as ThreePerspectiveCamera ,
15+ } from "three" ;
1116import { Bot } from "./bot" ;
1217import { AddPlantProps , Bed } from "./bed" ;
1318import {
@@ -111,6 +116,9 @@ export const GardenModel = (props: GardenModelProps) => {
111116 const topDown = addPlantProps ?. designer . threeDTopDownView ;
112117 const topDownMobile = topDown && isMobile ( ) ;
113118 const camera = getCamera ( config , props . activeFocus , cameraInit ( ! ! topDown ) ) ;
119+ const [ controlsCamera , setControlsCamera ] =
120+ // eslint-disable-next-line no-null/no-null
121+ React . useState < ThreePerspectiveCamera | ThreeOrthographicCamera | null > ( null ) ;
114122
115123 const showPlants = ! addPlantProps
116124 || ! ! addPlantProps . getConfigValue ( BooleanSetting . show_plants ) ;
@@ -163,24 +171,29 @@ export const GardenModel = (props: GardenModelProps) => {
163171 </ Sphere >
164172 < AnimatedGroup
165173 scale = { props . activeFocus ? 1 : scale } >
166- < Camera makeDefault = { true } name = { "camera" }
174+ < Camera
175+ ref = { setControlsCamera }
176+ makeDefault = { true }
177+ name = { "camera" }
167178 fov = { 40 } near = { 10 } far = { BigDistance . far }
168179 position = { camera . position }
169180 rotation = { [ 0 , 0 , 0 ] }
170181 zoom = { topDown ? 0.25 : 1 }
171182 up = { [ 0 , 0 , 1 ] } />
172183 </ AnimatedGroup >
173- < OrbitControls
174- maxPolarAngle = { Math . PI / 2 }
175- minAzimuthAngle = { topDownMobile ? Math . PI / 2 : undefined }
176- maxAzimuthAngle = { topDownMobile ? Math . PI / 2 : undefined }
177- enableRotate = { config . rotate }
178- enableZoom = { config . zoom }
179- enablePan = { config . pan }
180- dampingFactor = { 0.2 }
181- target = { camera . target }
182- minDistance = { config . lightsDebug ? 50 : 500 }
183- maxDistance = { config . lightsDebug ? BigDistance . devZoom : BigDistance . zoom } />
184+ { controlsCamera &&
185+ < OrbitControls
186+ camera = { controlsCamera }
187+ maxPolarAngle = { Math . PI / 2 }
188+ minAzimuthAngle = { topDownMobile ? Math . PI / 2 : undefined }
189+ maxAzimuthAngle = { topDownMobile ? Math . PI / 2 : undefined }
190+ enableRotate = { config . rotate }
191+ enableZoom = { config . zoom }
192+ enablePan = { config . pan }
193+ dampingFactor = { 0.2 }
194+ target = { camera . target }
195+ minDistance = { config . lightsDebug ? 50 : 500 }
196+ maxDistance = { config . lightsDebug ? BigDistance . devZoom : BigDistance . zoom } /> }
184197 < AxesHelper args = { [ 5000 ] } visible = { config . threeAxes } />
185198 { config . viewCube && < GizmoHelper > < GizmoViewcube /> </ GizmoHelper > }
186199 < Sun
0 commit comments