Skip to content

Commit

Permalink
Show FOV and zoom info
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueAlien99 committed Nov 29, 2021
1 parent 4a85d4f commit 73a820d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@
--- NOW

- Select component
- show info (fov, zoom)
- Readme!
9 changes: 7 additions & 2 deletions src/components/GenericView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import { SupportedViewIds } from 'features/screenshot/dimensions';
import ScreenshotManager from './three/ScreenshotManager';
import CameraManager from './three/CameraManager';

const ViewStyles = styled.div<{ textColor: string }>`
const ViewStyles = styled.div<{ textColor: string; backgroundColor: string }>`
position: relative;
min-width: 0;
min-height: 0;
.overlay {
position: absolute;
color: ${props => props.textColor};
background-color: ${props => props.backgroundColor};
opacity: 0.2;
z-index: 100;
Expand Down Expand Up @@ -73,7 +74,11 @@ function GenericView({ viewId, label, controlsProps, className, children }: Prop
const ContextBridge = useContextBridge(ReactReduxContext);

return (
<ViewStyles className={className} textColor={style.overlayColor}>
<ViewStyles
className={className}
textColor={style.overlayColor}
backgroundColor={style.clearColor}
>
<div className="overlay camera" ref={setCameraControlsContainer} />
<span className="overlay label">{label}</span>
<div className="overlay actions">
Expand Down
13 changes: 12 additions & 1 deletion src/components/three/CameraManager.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Size, useThree } from '@react-three/fiber';
import { Size, useFrame, useThree } from '@react-three/fiber';
import { useCallback, useState } from 'react';
import { OrthographicCamera, PerspectiveCamera } from 'three';
import { render } from 'react-dom';
Expand Down Expand Up @@ -99,10 +99,21 @@ function CameraManager({ cameraControlsContainer, orbitControls }: Props): null
invalidate();
};

const getCameraStats = () => ({
fov: camera instanceof PerspectiveCamera ? camera.fov : 0,
zoom: camera.zoom.toFixed(2),
});

const [cameraStats, setCameraStats] = useState(getCameraStats());

useFrame(() => setCameraStats(getCameraStats()));

if (cameraControlsContainer) {
render(
<ControlsStyles>
<span className="panel-label">Camera controls</span>
{camera instanceof PerspectiveCamera && <div>FOV: {cameraStats.fov} deg</div>}
{camera instanceof OrthographicCamera && <div>Zoom: {cameraStats.zoom}x</div>}
<div className="btn-pair">
<button type="button" onClick={handleSave}>
Save
Expand Down

0 comments on commit 73a820d

Please sign in to comment.