Skip to content

Commit

Permalink
Fix #889
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson committed Dec 21, 2024
1 parent 57ff45b commit 85fabe4
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/r3f/components/CameraTransition.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useDeepOptions } from '../utilities/useOptions';
export const CameraTransition = forwardRef( function CameraTransition( props, ref ) {

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

// create the manager
const manager = useMemo( () => {
Expand Down Expand Up @@ -164,6 +164,25 @@ export const CameraTransition = forwardRef( function CameraTransition( props, re

}

// ensure the orthographic camera size is resized correctly if the user is not
// providing their own camera.
const { camera, size } = get();
if ( ! orthographicCamera && camera === manager.orthographicCamera ) {

const aspect = size.width / size.height;
const camera = manager.orthographicCamera;
if ( aspect !== camera.right ) {

camera.bottom = - 1;
camera.top = 1;
camera.left = - aspect;
camera.right = aspect;
camera.updateProjectionMatrix();

}

}

if ( manager.animating ) {

invalidate();
Expand Down

0 comments on commit 85fabe4

Please sign in to comment.