Fixed crash when camera looping is on, but no cameras (#922)

Fixed camera cycle crash
This commit is contained in:
Abhik Ahuja authored and GitHub committed 2022-11-07 22:45:00 -08:00
1 parent c325e90a8e
commit 3a056ed622
2 files changed
+55 -32

No files matched your search

@@ -87,16 +87,19 @@ function FovSelector(props) {
const new_focal_len = camera.getFocalLength(); const new_focal_len = camera.getFocalLength();
camera.fov = old_fov; camera.fov = old_fov;
const label = Math.round( const label = Math.round(
fovLabel === FOV_LABELS.FOV fovLabel === FOV_LABELS.FOV ? globalFov : new_focal_len * camera.aspect,
? globalFov
: new_focal_len * camera.aspect,
); );
return label; return label;
}; };
const [UIFieldOfView, setUIFieldOfView] = React.useState(isGlobal ? globalFov : getFovLabel()); const [UIFieldOfView, setUIFieldOfView] = React.useState(
isGlobal ? globalFov : getFovLabel(),
);
useEffect(() => setUIFieldOfView(getFovLabel()), [camera, fovLabel, globalFov]); useEffect(
() => setUIFieldOfView(getFovLabel()),
[camera, fovLabel, globalFov],
);
const setFOV = (val) => { const setFOV = (val) => {
if (!isGlobal) { if (!isGlobal) {
@@ -109,10 +112,10 @@ function FovSelector(props) {
setGlobalFov(val); setGlobalFov(val);
} else { } else {
const old_fov = camera.fov; const old_fov = camera.fov;
camera.setFocalLength(val / camera.aspect); camera.setFocalLength(val / camera.aspect);
const new_fov = camera.getEffectiveFOV(); const new_fov = camera.getEffectiveFOV();
camera.fov = old_fov; camera.fov = old_fov;
setGlobalFov(new_fov); setGlobalFov(new_fov);
} }
if (applyAll) { if (applyAll) {
@@ -178,8 +181,10 @@ function FovSelector(props) {
}} }}
sx={{ sx={{
input: { input: {
"-webkit-text-fill-color": `${disabled ? "#24B6FF" : "#EBEBEB"} !important`, '-webkit-text-fill-color': `${
color: `${disabled ? "#24B6FF" : "#EBEBEB"} !important`, disabled ? '#24B6FF' : '#EBEBEB'
} !important`,
color: `${disabled ? '#24B6FF' : '#EBEBEB'} !important`,
}, },
}} }}
value={UIFieldOfView} value={UIFieldOfView}
@@ -391,21 +396,22 @@ function CameraList(props) {
</Stack> </Stack>
</AccordionSummary> </AccordionSummary>
<AccordionDetails> <AccordionDetails>
{isAnimated('FOV') && {isAnimated('FOV') && (
<FovSelector <FovSelector
fovLabel={fovLabel} fovLabel={fovLabel}
setFovLabel={setFovLabel} setFovLabel={setFovLabel}
camera={camera} camera={camera}
dispatch={dispatch} dispatch={dispatch}
disabled={!isAnimated('FOV')} disabled={!isAnimated('FOV')}
isGlobal={false} isGlobal={false}
changeMain={false} changeMain={false}
/>} />
{!isAnimated('FOV') && )}
<p style={{ fontSize: 'smaller', color: '#999999' }}> {!isAnimated('FOV') && (
<p style={{ fontSize: 'smaller', color: '#999999' }}>
Animated camera properties will show up here! Animated camera properties will show up here!
</p> </p>
} )}
</AccordionDetails> </AccordionDetails>
</Accordion> </Accordion>
); );
@@ -721,7 +727,7 @@ export default function CameraPanel(props) {
values.push(is_cycle ? time * ratio : time); values.push(is_cycle ? time * ratio : time);
}); });
if (is_cycle) { if (is_cycle && cameras.length !== 0) {
values.push(1.0); values.push(1.0);
} }
@@ -1110,12 +1116,27 @@ export default function CameraPanel(props) {
onClick={() => { onClick={() => {
toggleAnimate('FOV'); toggleAnimate('FOV');
}} }}
style={{maxWidth: '20px', maxHeight: '20px', minWidth: '20px', minHeight: '20px', position: 'relative', top: '22px'}} style={{
maxWidth: '20px',
maxHeight: '20px',
minWidth: '20px',
minHeight: '20px',
position: 'relative',
top: '22px',
}}
sx={{ sx={{
mt: 1, mt: 1,
}} }}
> >
<Animation style={{color: isAnimated('FOV') ? "#24B6FF" : "#EBEBEB", maxWidth: '20px', maxHeight: '20px', minWidth: '20px', minHeight: '20px'}}/> <Animation
style={{
color: isAnimated('FOV') ? '#24B6FF' : '#EBEBEB',
maxWidth: '20px',
maxHeight: '20px',
minWidth: '20px',
minHeight: '20px',
}}
/>
</Button> </Button>
</Tooltip> </Tooltip>
<FovSelector <FovSelector
@@ -1222,6 +1243,9 @@ export default function CameraPanel(props) {
step={step_size} step={step_size}
valueLabelDisplay="auto" valueLabelDisplay="auto"
valueLabelFormat={(value, i) => { valueLabelFormat={(value, i) => {
if (cameras.length === 0) {
return '';
}
if (i === cameras.length && is_cycle) { if (i === cameras.length && is_cycle) {
return `${cameras[0].properties.get('NAME')} @ ${parseFloat( return `${cameras[0].properties.get('NAME')} @ ${parseFloat(
(value * seconds).toFixed(2), (value * seconds).toFixed(2),
@@ -19,6 +19,9 @@ export function get_curve_object_from_cameras(
is_cycle, is_cycle,
smoothness_value, smoothness_value,
) { ) {
if (cameras.length === 0) {
return null;
}
// interpolate positions, lookat directions, and ups // interpolate positions, lookat directions, and ups
// similar to // similar to
// https://github.com/google-research/multinerf/blob/1c8b1c552133cdb2de1c1f3c871b2813f6662265/internal/camera_utils.py#L281 // https://github.com/google-research/multinerf/blob/1c8b1c552133cdb2de1c1f3c871b2813f6662265/internal/camera_utils.py#L281
@@ -64,11 +67,7 @@ export function get_curve_object_from_cameras(
let curve_ups = null; let curve_ups = null;
let curve_fovs = null; let curve_fovs = null;
curve_positions = get_catmull_rom_curve( curve_positions = get_catmull_rom_curve(positions, false, smoothness_value);
positions,
false,
smoothness_value,
);
curve_lookats = get_catmull_rom_curve(lookats, false, smoothness_value); curve_lookats = get_catmull_rom_curve(lookats, false, smoothness_value);
curve_ups = get_catmull_rom_curve(ups, false, smoothness_value); curve_ups = get_catmull_rom_curve(ups, false, smoothness_value);
curve_fovs = get_catmull_rom_curve(fovs, false, 0.05); curve_fovs = get_catmull_rom_curve(fovs, false, 0.05);