Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/r3f/components/CameraTransition.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { forwardRef, useEffect, useMemo } from 'react';
import { useFrame, useThree } from '@react-three/fiber';
import { CameraTransitionManager } from '3d-tiles-renderer';
import { useDeepOptions } from '../utilities/useOptions';
import { useDeepOptions } from '../utilities/useOptions.jsx';

export const CameraTransition = forwardRef( function CameraTransition( props, ref ) {

const { mode = 'perspective', perspectiveCamera, orthographicCamera, ...options } = props;
const {
mode = 'perspective',
onBeforeToggle,
perspectiveCamera,
orthographicCamera,
...options
} = props;
const [ set, get, invalidate, controls, camera, size ] = useThree( state => [ state.set, state.get, state.invalidate, state.controls, state.camera, state.size ] );

// create the manager
Expand All @@ -32,7 +38,7 @@

// only respect the camera initially so the default camera settings are automatically used

}, [] );

Check warning on line 41 in src/r3f/components/CameraTransition.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

React Hook useMemo has missing dependencies: 'camera' and 'mode'. Either include them or remove the dependency array

Check warning on line 41 in src/r3f/components/CameraTransition.jsx

View workflow job for this annotation

GitHub Actions / build (20.x)

React Hook useMemo has missing dependencies: 'camera' and 'mode'. Either include them or remove the dependency array

useEffect( () => {

Expand Down Expand Up @@ -109,10 +115,20 @@

if ( mode !== manager.mode ) {

// calculate the camera being toggled to. Because "toggle" has not yet been
// called this will select the camera that is being transitioned to.
const targetCamera = mode === 'orthographic' ? manager.perspectiveCamera : manager.orthographicCamera;
if ( controls && controls.isEnvironmentControls ) {

controls.getPivotPoint( manager.fixedPoint );
manager.syncCameras();

if ( onBeforeToggle ) {

onBeforeToggle( manager, targetCamera );

}

controls.adjustCamera( manager.perspectiveCamera );
controls.adjustCamera( manager.orthographicCamera );

Expand All @@ -125,6 +141,12 @@
.add( manager.camera.position );
manager.syncCameras();

if ( onBeforeToggle ) {

onBeforeToggle( manager, targetCamera );

}

}

manager.toggle();
Expand All @@ -132,7 +154,7 @@

}

}, [ mode, manager, invalidate, controls ] );

Check warning on line 157 in src/r3f/components/CameraTransition.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

React Hook useEffect has a missing dependency: 'onBeforeToggle'. Either include it or remove the dependency array

Check warning on line 157 in src/r3f/components/CameraTransition.jsx

View workflow job for this annotation

GitHub Actions / build (20.x)

React Hook useEffect has a missing dependency: 'onBeforeToggle'. Either include it or remove the dependency array

// rerender the frame when the transition animates
useEffect( () => {
Expand Down
Loading