Enable rendering with crop (#1295)

This commit is contained in:
Matthew Tancik authored and GitHub committed 2023-01-26 14:22:43 -08:00
1 parent f0c102ca58
commit b5031dd814
5 files changed
+162 -54

No files matched your search

+1 -1
View File
@@ -314,7 +314,7 @@ class Cameras(TensorDataclass):
distortion_params_delta: Optional[TensorType["num_rays":..., 6]] = None,
keep_shape: Optional[bool] = None,
disable_distortion: bool = False,
aabb_box: SceneBox = None,
aabb_box: Optional[SceneBox] = None,
) -> RayBundle:
"""Generates rays for the given camera indices.
@@ -47,8 +47,11 @@ export function RenderControls() {
const crop_enabled = useSelector(
(state) => state.renderingState.crop_enabled,
);
console.log('crop_enabled_config panel', crop_enabled);
const crop_bg_color = useSelector((state) => state.renderingState.crop_bg_color);
const crop_bg_color = useSelector(
(state) => state.renderingState.crop_bg_color,
);
const crop_scale = useSelector((state) => state.renderingState.crop_scale);
@@ -154,11 +157,12 @@ export function RenderControls() {
'2048px': () => setControls({ max_resolution: 2048 }),
}),
// Enable Crop
crop_options: {
crop_enabled: {
label: 'Crop Viewport',
value: crop_enabled,
hint: 'Crop the viewport to the selected box',
onChange: (value) => {
console.log('dispact value', value);
dispatch_and_send(
websocket,
dispatch,
@@ -170,7 +174,7 @@ export function RenderControls() {
crop_bg_color: {
label: '| Background Color',
value: crop_bg_color,
render: (get) => get('crop_options'),
render: (get) => get('crop_enabled'),
onChange: (v) => {
dispatch_and_send(
websocket,
@@ -186,7 +190,7 @@ export function RenderControls() {
min: 0,
max: 10,
step: 0.05,
render: (get) => get('crop_options'),
render: (get) => get('crop_enabled'),
onChange: (v) => {
dispatch_and_send(
websocket,
@@ -202,7 +206,7 @@ export function RenderControls() {
min: -10,
max: 10,
step: 0.05,
render: (get) => get('crop_options'),
render: (get) => get('crop_enabled'),
onChange: (v) => {
dispatch_and_send(
websocket,
@@ -251,6 +255,10 @@ export function RenderControls() {
setControls({ max_resolution });
setControls({ output_options: outputChoice });
setControls({ colormap_options: colormapChoice });
setControls({ crop_enabled });
setControls({ crop_bg_color });
setControls({ crop_scale });
setControls({ crop_center });
}, [
setControls,
outputOptions,
@@ -260,6 +268,10 @@ export function RenderControls() {
max_resolution,
target_train_util,
render_time,
crop_enabled,
crop_bg_color,
crop_scale,
crop_center,
display_render_time,
]);
@@ -63,7 +63,6 @@ function set_camera_position(camera, matrix) {
mat.decompose(camera.position, camera.quaternion, camera.scale);
}
function RenderTimeSelector(props) {
const disabled = props.disabled;
const isGlobal = props.isGlobal;
@@ -79,7 +78,7 @@ function RenderTimeSelector(props) {
if (!isGlobal) {
return camera.renderTime;
}
camera.renderTime = globalRenderTime
camera.renderTime = globalRenderTime;
return globalRenderTime;
};
@@ -118,7 +117,7 @@ function RenderTimeSelector(props) {
const handleValidation = (e) => {
const valueFloat = parseFloat(e.target.value);
let valueStr = String(valueFloat);
if (e.target.value >= 0 && e.target.value <= 1){
if (e.target.value >= 0 && e.target.value <= 1) {
setValid(true);
if (valueFloat === 1.0) {
valueStr = '1.0';
@@ -135,7 +134,7 @@ function RenderTimeSelector(props) {
return (
<TextField
label='Render Time'
label="Render Time"
InputLabelProps={{
style: { color: '#8E8E8E' },
}}
@@ -556,9 +555,7 @@ export default function CameraPanel(props) {
]);
// redux store state
const export_path = useSelector(
(state) => state.renderingState.export_path,
);
const export_path = useSelector((state) => state.renderingState.export_path);
const websocket = useContext(WebSocketContext).socket;
const DEFAULT_FOV = 50;
@@ -577,7 +574,8 @@ export default function CameraPanel(props) {
const [render_modal_open, setRenderModalOpen] = React.useState(false);
const [animate, setAnimate] = React.useState(new Set());
const [globalFov, setGlobalFov] = React.useState(DEFAULT_FOV);
const [globalRenderTime, setGlobalRenderTime] = React.useState(DEFAULT_RENDER_TIME);
const [globalRenderTime, setGlobalRenderTime] =
React.useState(DEFAULT_RENDER_TIME);
// leva store
const cameraPropsStore = useCreateStore();
@@ -603,15 +601,24 @@ export default function CameraPanel(props) {
);
const camera_type = useSelector((state) => state.renderingState.camera_type);
const crop_enabled = useSelector(
(state) => state.renderingState.crop_enabled,
);
const crop_bg_color = useSelector(
(state) => state.renderingState.crop_bg_color,
);
const crop_center = useSelector((state) => state.renderingState.crop_center);
const crop_scale = useSelector((state) => state.renderingState.crop_scale);
const [display_render_time, set_display_render_time] = React.useState(false);
const receive_temporal_dist = e => {
const receive_temporal_dist = (e) => {
const msg = msgpack.decode(new Uint8Array(e.data));
if (msg.path === "/model/has_temporal_distortion") {
set_display_render_time(msg.data === "true");
websocket.removeEventListener("message", receive_temporal_dist);
if (msg.path === '/model/has_temporal_distortion') {
set_display_render_time(msg.data === 'true');
websocket.removeEventListener('message', receive_temporal_dist);
}
}
};
websocket.addEventListener('message', receive_temporal_dist);
const setRenderHeight = (value) => {
@@ -645,6 +652,40 @@ export default function CameraPanel(props) {
});
};
const setCropEnabled = (value) => {
console.log('setting the crop enabled value to: ', value);
dispatch({
type: 'write',
path: 'renderingState/crop_enabled',
data: value,
});
console.log('crop enabled value is now: ', crop_enabled);
};
const serCropBgColor = (value) => {
dispatch({
type: 'write',
path: 'renderingState/crop_bg_color',
data: value,
});
};
const setCropCenter = (value) => {
dispatch({
type: 'write',
path: 'renderingState/crop_center',
data: value,
});
};
const setCropScale = (value) => {
dispatch({
type: 'write',
path: 'renderingState/crop_scale',
data: value,
});
};
const setRenderTime = (value) => {
dispatch({
type: 'write',
@@ -669,7 +710,7 @@ export default function CameraPanel(props) {
if (new_camera_list.length >= 1) {
set_camera_position(camera_render, new_camera_list[0].matrix);
setFieldOfView(new_camera_list[0].fov);
setRenderTime(new_camera_list[0].renderTime)
setRenderTime(new_camera_list[0].renderTime);
set_slider_value(slider_min);
}
};
@@ -989,6 +1030,15 @@ export default function CameraPanel(props) {
});
}
let crop = null;
if (crop_enabled) {
crop = {
crop_bg_color,
crop_center,
crop_scale,
};
}
// const myData
const camera_path_object = {
keyframes,
@@ -1000,6 +1050,7 @@ export default function CameraPanel(props) {
seconds,
smoothness_value,
is_cycle,
crop,
};
return camera_path_object;
};
@@ -1066,6 +1117,14 @@ export default function CameraPanel(props) {
setCameraProperties(new_properties);
setCameras(new_camera_list);
reset_slider_render_on_add(new_camera_list);
if ('crop' in camera_path_object && camera_path_object.crop !== null) {
console.log('crop' in camera_path_object);
setCropEnabled(true);
serCropBgColor(camera_path_object.crop.crop_bg_color);
setCropCenter(camera_path_object.crop.crop_center);
setCropScale(camera_path_object.crop.crop_scale);
}
};
const uploadCameraPath = (e) => {
@@ -1160,6 +1219,7 @@ export default function CameraPanel(props) {
variant="outlined"
startIcon={<FileDownloadOutlinedIcon />}
onClick={export_camera_path}
disabled={cameras.length === 0}
>
Export Path
</Button>
@@ -1172,6 +1232,7 @@ export default function CameraPanel(props) {
size="small"
startIcon={<VideoCameraBackIcon />}
onClick={open_render_modal}
disabled={cameras.length === 0}
>
Render
</Button>
@@ -18,13 +18,9 @@ const msgpack = require('msgpack-lite');
function CameraToggle() {
const dispatch = useDispatch();
const websocket = useContext(WebSocketContext).socket;
const camera_choice = useSelector(
(state) => state.renderingState.camera_choice,
);
const crop_enabled = useSelector(
(state) => state.renderingState.crop_enabled,
);
const set_camera_choice = (event: SelectChangeEvent, value: string[]) => {
if (value != null) {
dispatch({
@@ -32,21 +28,6 @@ function CameraToggle() {
path: 'renderingState/camera_choice',
data: value,
});
if (websocket.readyState === WebSocket.OPEN) {
const path = 'renderingState/crop_enabled';
const data = {
type: 'write',
path,
data: false,
};
if (value === 'Render Camera') {
data.data = false;
} else {
data.data = crop_enabled;
}
const message = msgpack.encode(data);
websocket.send(message);
}
}
};