Skip to content

Commit

Permalink
Add ability to load path from file (#804)
Browse files Browse the repository at this point in the history
* Added button in camera panel to load camera path from file

* Loading camera paths not backwards compatible with old camera paths.
  • Loading branch information
origamiman72 authored Oct 19, 2022
1 parent 9bed696 commit 21eddc4
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 3 deletions.
11 changes: 9 additions & 2 deletions nerfstudio/viewer/app/src/modules/Scene/Scene.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,12 @@ export function get_scene_tree() {
mouseVector.x = 2 * (e.clientX / size.x) - 1;
mouseVector.y = 1 - 2 * ((e.clientY - BANNER_HEIGHT) / size.y);

if (mouseVector.x > 1 || mouseVector.x < -1 || mouseVector.y > 1 || mouseVector.y < -1) {
if (
mouseVector.x > 1 ||
mouseVector.x < -1 ||
mouseVector.y > 1 ||
mouseVector.y < -1
) {
if (selectedCam !== null) {
selectedCam.material.color = new THREE.Color(1, 1, 1);
selectedCam = null;
Expand All @@ -268,7 +273,9 @@ export function get_scene_tree() {
selectedCam.material.color = new THREE.Color(1, 1, 1);
selectedCam = null;
}
const filtered_intersections = intersections.filter(isect => checkVisibility(isect.object));
const filtered_intersections = intersections.filter((isect) =>
checkVisibility(isect.object),
);
if (filtered_intersections.length > 0) {
selectedCam = filtered_intersections[0].object;
selectedCam.material.color = new THREE.Color(0xfab300);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,27 @@ export default function CameraPanel(props) {
});
}

const keyframes = [];
for (let i = 0; i < cameras.length; i += 1) {
const camera = cameras[i];
keyframes.push({
matrix: JSON.stringify(camera.matrix.toArray()),
fov: camera.fov,
aspect: camera_render.aspect,
});
}

// const myData
const camera_path_object = {
keyframes: [],
keyframes,
render_height,
render_width,
camera_path,
fps,
seconds,
smoothness_value,
is_cycle,
is_linear,
};
return camera_path_object;
};
Expand Down Expand Up @@ -461,6 +474,58 @@ export default function CameraPanel(props) {
URL.revokeObjectURL(href);
};

const load_camera_path = (camera_path_object) => {
// TODO UI for getting json

const new_camera_list = [];

setRenderHeight(camera_path_object.render_height);
setUIRenderHeight(camera_path_object.render_height);
setRenderWidth(camera_path_object.render_width);
setUIRenderWidth(camera_path_object.render_width);

setFps(camera_path_object.fps);
setUIfps(camera_path_object.fps);

setSeconds(camera_path_object.seconds);
setUISeconds(camera_path_object.seconds);

set_smoothness_value(camera_path_object.smoothness_value);
setIsCycle(camera_path_object.is_cycle);
setIsLinear(camera_path_object.is_linear);

for (let i = 0; i < camera_path_object.keyframes.length; i += 1) {
const keyframe = camera_path_object.keyframes[i];
const camera = new THREE.PerspectiveCamera(
keyframe.fov,
keyframe.aspect,
0.1,
1000,
);

const mat = new THREE.Matrix4();
mat.fromArray(JSON.parse(keyframe.matrix));
// camera.matrix = mat;
set_camera_position(camera, mat);
new_camera_list.push(camera);
}

setCameras(new_camera_list);
reset_slider_render_on_add(new_camera_list);
};

const uploadCameraPath = (e) => {
const fileUpload = e.target.files[0];

const fr = new FileReader();
fr.onload = (res) => {
const camera_path_object = JSON.parse(res.target.result);
load_camera_path(camera_path_object);
};

fr.readAsText(fileUpload);
};

const copy_cmd_to_clipboard = () => {
console.log('copy_cmd_to_clipboard');

Expand Down Expand Up @@ -543,6 +608,23 @@ export default function CameraPanel(props) {
Export Path
</Button>
</div>
<div className="CameraPanel-top-button">
<Button
size="small"
className="CameraPanel-top-button"
component="label"
variant="outlined"
>
Load Path
<input
type="file"
accept=".json"
name="Camera Path"
onChange={uploadCameraPath}
hidden
/>
</Button>
</div>
<div className="CameraPanel-top-button">
<Tooltip title="Copy Cmd to Clipboard">
<IconButton onClick={copy_cmd_to_clipboard}>
Expand Down

0 comments on commit 21eddc4

Please sign in to comment.