mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-03 06:18:44 +08:00
Interactable camera path (#372)
* click to add cameras * buttons for translate, rotation, and world/local * gui layout mostly done * interpolation works * slider play works * camera code mostly working
This commit is contained in:
1 parent
ad4a6c4a6f
commit
adf249b3cd
11 files changed
+650
-48
No files matched your search
@@ -26,6 +26,7 @@
|
||||
"no-console": "off",
|
||||
"prefer-destructuring": "off",
|
||||
"react/destructuring-assignment": "off",
|
||||
"react/prop-types": 0,
|
||||
"unused-imports/no-unused-imports-ts": 2
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,9 @@
|
||||
"@emotion/react": "^11.10.4",
|
||||
"@emotion/styled": "^11.10.4",
|
||||
"@mui/icons-material": "^5.10.3",
|
||||
"@mui/lab": "^5.0.0-alpha.98",
|
||||
"@mui/material": "^5.10.3",
|
||||
"@mui/x-date-pickers": "^5.0.0",
|
||||
"@reduxjs/toolkit": "^1.8.3",
|
||||
"@testing-library/jest-dom": "^5.16.4",
|
||||
"@testing-library/react": "^13.3.0",
|
||||
@@ -15,6 +17,7 @@
|
||||
"ccapture.js": "github:aceslowman/ccapture.js#npm-fix",
|
||||
"classnames": "^2.3.1",
|
||||
"dat.gui": "^0.7.9",
|
||||
"dayjs": "^1.11.5",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-unused-imports": "^2.0.0",
|
||||
"leva": "^0.9.29",
|
||||
|
||||
@@ -31,7 +31,7 @@ export default function App() {
|
||||
<BasicTabs sceneTree={sceneTree} />
|
||||
</div>
|
||||
<RenderControls />
|
||||
<ViewerWindow scene={sceneTree.object} />
|
||||
<ViewerWindow sceneTree={sceneTree} scene={sceneTree.object} />
|
||||
</div>
|
||||
</div>
|
||||
</ThemeProvider>
|
||||
|
||||
@@ -60,6 +60,10 @@ export default class SceneNode {
|
||||
return child.find(path.slice(1));
|
||||
}
|
||||
|
||||
find_object(path) {
|
||||
return this.find(path.concat(['<object>'])).object;
|
||||
}
|
||||
|
||||
set_property(property, value) {
|
||||
if (property === 'position') {
|
||||
this.object.position.set(value[0], value[1], value[2]);
|
||||
@@ -83,6 +87,10 @@ export default class SceneNode {
|
||||
);
|
||||
}
|
||||
|
||||
set_object_from_path(path, object) {
|
||||
this.find(path.concat(['<object>'])).set_object(object);
|
||||
}
|
||||
|
||||
set_object(object) {
|
||||
const parent = this.object.parent;
|
||||
this.dispose_recursive();
|
||||
|
||||
@@ -164,8 +164,59 @@ $sidebar-width: 100% !default;
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// Camera Vie
|
||||
// }
|
||||
// Camera Pane
|
||||
|
||||
.CameraPanel {
|
||||
}
|
||||
|
||||
.CameraPanel-top-button {
|
||||
display: inline-block;
|
||||
margin: 4px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.CameraPanel-slider-container {
|
||||
margin-top: 40px;
|
||||
margin-left: 20px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
.CameraPanel-slider-button-container {
|
||||
margin-bottom: 10px;
|
||||
|
||||
button {
|
||||
margin: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.CameraList-container {
|
||||
position: relative;
|
||||
height: 600px;
|
||||
overflow: scroll;
|
||||
border: solid 1px $highlight-color1;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.CameraList-row {
|
||||
padding: 4px;
|
||||
border: solid 1px $highlight-color1;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.CameraList-row-buttons {
|
||||
display: inline-block;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.CameraList-row-time-interval > div {
|
||||
display: inline-block;
|
||||
text-align: center;
|
||||
margin: 10px;
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// Viewer Window
|
||||
|
||||
.canvas-container-main,
|
||||
.WebRTCVideo {
|
||||
@@ -182,3 +233,21 @@ $sidebar-width: 100% !default;
|
||||
height: 100%;
|
||||
object-fit: fill;
|
||||
}
|
||||
|
||||
$viewer_button_size: 100px;
|
||||
|
||||
.ViewerWindow-buttons {
|
||||
position: absolute;
|
||||
margin: 10px;
|
||||
top: 0px;
|
||||
right: $SidePanel-width;
|
||||
z-index: 1000;
|
||||
width: $viewer_button_size;
|
||||
background-color: $base-color1;
|
||||
}
|
||||
|
||||
.ViewerWindow-iconbutton {
|
||||
border: solid 1px red;
|
||||
width: 100%;
|
||||
height: $viewer_button_size;
|
||||
}
|
||||
@@ -28,6 +28,10 @@ export function get_scene_tree() {
|
||||
sceneTree.delete(path);
|
||||
};
|
||||
|
||||
// Main camera
|
||||
const main_camera = new THREE.PerspectiveCamera(75, 1, 0.1, 1000);
|
||||
setObject(['Main Camera'], main_camera);
|
||||
|
||||
// Axes
|
||||
const axes = new THREE.AxesHelper(5);
|
||||
setObject(['Axes'], axes);
|
||||
|
||||
@@ -1,14 +1,310 @@
|
||||
import * as React from 'react';
|
||||
import * as THREE from 'three';
|
||||
|
||||
import { Button } from '@mui/material';
|
||||
import { Button, Slider } from '@mui/material';
|
||||
|
||||
import ArrowBackIosNewIcon from '@mui/icons-material/ArrowBackIosNew';
|
||||
import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos';
|
||||
import DeleteIcon from '@mui/icons-material/Delete';
|
||||
import FirstPageIcon from '@mui/icons-material/FirstPage';
|
||||
import LastPageIcon from '@mui/icons-material/LastPage';
|
||||
import PauseIcon from '@mui/icons-material/Pause';
|
||||
import PlayArrowIcon from '@mui/icons-material/PlayArrow';
|
||||
import TextField from '@mui/material/TextField';
|
||||
import VisibilityIcon from '@mui/icons-material/Visibility';
|
||||
import { useEffect } from 'react';
|
||||
import { get_curve_object_from_cameras } from './curve';
|
||||
|
||||
function set_camera_position(camera, matrix) {
|
||||
const mat = new THREE.Matrix4();
|
||||
mat.fromArray(matrix.elements);
|
||||
mat.decompose(camera.position, camera.quaternion, camera.scale);
|
||||
}
|
||||
|
||||
function CameraList(props) {
|
||||
const sceneTree = props.sceneTree;
|
||||
const cameras = props.cameras;
|
||||
const camera_main = props.camera_main;
|
||||
const transform_controls = props.transform_controls;
|
||||
const setCameras = props.setCameras;
|
||||
|
||||
const set_transform_controls = (index) => {
|
||||
// camera helper object so grab the camera inside
|
||||
const camera = sceneTree.find([
|
||||
'Camera Path',
|
||||
'Cameras',
|
||||
index.toString(),
|
||||
'Camera',
|
||||
'<object>',
|
||||
]).object;
|
||||
transform_controls.attach(camera);
|
||||
};
|
||||
|
||||
const delete_camera = (index) => {
|
||||
console.log('TODO: deleting camera: ', index);
|
||||
setCameras([...cameras.slice(0, index), ...cameras.slice(index + 1)]);
|
||||
};
|
||||
|
||||
const cameraList = cameras.map((camera, index) => {
|
||||
return (
|
||||
<div className="CameraList-row" key={camera.uuid}>
|
||||
<Button onClick={() => set_transform_controls(index)}>
|
||||
Camera {index}
|
||||
</Button>
|
||||
<div className="CameraList-row-buttons">
|
||||
<Button
|
||||
onClick={() => set_camera_position(camera_main, camera.matrix)}
|
||||
>
|
||||
<VisibilityIcon />
|
||||
</Button>
|
||||
<Button onClick={() => delete_camera(index)}>
|
||||
<DeleteIcon />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
return <div>{cameraList}</div>;
|
||||
}
|
||||
|
||||
export default function CameraPanel(props) {
|
||||
// unpack props
|
||||
const sceneTree = props.sceneTree;
|
||||
|
||||
// scene tree objects
|
||||
const camera_main = sceneTree.find_object(['Main Camera']);
|
||||
const transform_controls = sceneTree.find_object(['Transform Controls']);
|
||||
|
||||
// react state
|
||||
const [cameras, setCameras] = React.useState([]);
|
||||
const [slider_value, set_slider_value] = React.useState(0);
|
||||
const [is_playing, setIsPlaying] = React.useState(false);
|
||||
const [seconds, setSeconds] = React.useState(4);
|
||||
const [fps, setFps] = React.useState(24);
|
||||
const total_num_steps = seconds * fps;
|
||||
const step_size = (cameras.length - 1) / total_num_steps;
|
||||
const slider_min = 0;
|
||||
const slider_max = Math.max(0, cameras.length - 1);
|
||||
|
||||
const add_camera = () => {
|
||||
const camera_main_copy = camera_main.clone();
|
||||
camera_main_copy.far = camera_main_copy.near + 0.1;
|
||||
const new_camera_list = cameras.concat(camera_main_copy);
|
||||
setCameras(new_camera_list);
|
||||
};
|
||||
|
||||
// force a rerender if the cameras are dragged around
|
||||
let update_cameras_interval = null;
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
transform_controls.addEventListener('mouseDown', (event) => {
|
||||
// prevent multiple loops
|
||||
if (update_cameras_interval === null) {
|
||||
// hardcoded for 100 ms per udpate
|
||||
update_cameras_interval = setInterval(() => {
|
||||
setCameras(cameras);
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
transform_controls.addEventListener('mouseUp', (event) => {
|
||||
if (update_cameras_interval !== null) {
|
||||
clearInterval(update_cameras_interval);
|
||||
update_cameras_interval = null;
|
||||
}
|
||||
});
|
||||
|
||||
// draw cameras and curve to the scene
|
||||
useEffect(() => {
|
||||
// draw the cameras
|
||||
sceneTree.delete(['Camera Path', 'Cameras']); // delete old cameras, which is important
|
||||
for (let i = 0; i < cameras.length; i += 1) {
|
||||
const camera = cameras[i];
|
||||
const helper = new THREE.CameraHelper(camera);
|
||||
// camera
|
||||
sceneTree.set_object_from_path(
|
||||
['Camera Path', 'Cameras', i.toString(), 'Camera'],
|
||||
camera,
|
||||
);
|
||||
// camera helper
|
||||
sceneTree.set_object_from_path(
|
||||
['Camera Path', 'Cameras', i.toString(), 'Camera Helper'],
|
||||
helper,
|
||||
);
|
||||
}
|
||||
}, [cameras]);
|
||||
|
||||
// update the camera curve
|
||||
const curve_object = get_curve_object_from_cameras(cameras);
|
||||
if (cameras.length > 1) {
|
||||
const num_points = fps * seconds;
|
||||
const points = curve_object.curve_positions.getPoints(num_points);
|
||||
const geometry = new THREE.BufferGeometry().setFromPoints(points);
|
||||
const material = new THREE.LineBasicMaterial({ color: 0xff0000 });
|
||||
const threejs_object = new THREE.Line(geometry, material);
|
||||
sceneTree.set_object_from_path(['Camera Path', 'Curve'], threejs_object);
|
||||
}
|
||||
|
||||
const marks = [];
|
||||
for (let i = 0; i < cameras.length; i += 1) {
|
||||
marks.push({ value: i, label: i.toString() });
|
||||
}
|
||||
|
||||
// when the slider changes, update the main camera position
|
||||
useEffect(() => {
|
||||
if (cameras.length > 1) {
|
||||
// interpolate to get the points
|
||||
const position = curve_object.curve_positions.getPoint(
|
||||
slider_value / (cameras.length - 1.0),
|
||||
);
|
||||
const up = curve_object.curve_ups.getPoint(slider_value / cameras.length);
|
||||
const lookat = curve_object.curve_lookats.getPoint(
|
||||
slider_value / cameras.length,
|
||||
);
|
||||
|
||||
// create a copy of the vector up
|
||||
const up_copy = up.clone();
|
||||
const cross = up_copy.cross(lookat);
|
||||
|
||||
up.normalize();
|
||||
lookat.normalize();
|
||||
cross.normalize();
|
||||
|
||||
// create the camera transform matrix
|
||||
const mat = new THREE.Matrix4();
|
||||
mat.set(
|
||||
cross.x,
|
||||
up.x,
|
||||
lookat.x,
|
||||
position.x,
|
||||
cross.y,
|
||||
up.y,
|
||||
lookat.y,
|
||||
position.y,
|
||||
cross.z,
|
||||
up.z,
|
||||
lookat.z,
|
||||
position.z,
|
||||
);
|
||||
set_camera_position(camera_main, mat);
|
||||
}
|
||||
}, [slider_value]);
|
||||
|
||||
// call this function whenever slider state changes
|
||||
useEffect(() => {
|
||||
if (is_playing) {
|
||||
const interval = setInterval(() => {
|
||||
set_slider_value((prev) => prev + step_size);
|
||||
}, 1000 / fps);
|
||||
return () => clearInterval(interval);
|
||||
}
|
||||
return () => {};
|
||||
}, [is_playing]);
|
||||
|
||||
// make sure to pause if the slider reaches the end
|
||||
useEffect(() => {
|
||||
if (slider_value >= slider_max) {
|
||||
set_slider_value(slider_max);
|
||||
setIsPlaying(false);
|
||||
}
|
||||
}, [slider_value]);
|
||||
|
||||
export default function CameraPanel() {
|
||||
return (
|
||||
<div className="CameraPanel">
|
||||
TODO: create a camera path panel list of cameras
|
||||
<Button id="CameraPanel-add-camera-button" variant="outlined">
|
||||
Add Camera
|
||||
</Button>
|
||||
<div className="CameraPanel-top-button">
|
||||
<Button variant="outlined" onClick={add_camera}>
|
||||
Add Camera
|
||||
</Button>
|
||||
</div>
|
||||
<div className="CameraPanel-top-button">
|
||||
<Button className="CameraPanel-top-button" variant="outlined">
|
||||
Export Path
|
||||
</Button>
|
||||
</div>
|
||||
<div className="CameraPanel-slider-container">
|
||||
<Slider
|
||||
value={slider_value}
|
||||
step={step_size}
|
||||
valueLabelDisplay="on"
|
||||
marks={marks}
|
||||
min={slider_min}
|
||||
max={slider_max}
|
||||
disabled={cameras.length < 2}
|
||||
onChange={(event, value) => {
|
||||
set_slider_value(value);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="CameraPanel-slider-button-container">
|
||||
<Button
|
||||
variant="outlined"
|
||||
onClick={() => {
|
||||
setIsPlaying(false);
|
||||
set_slider_value(slider_min);
|
||||
}}
|
||||
>
|
||||
<FirstPageIcon />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outlined"
|
||||
onClick={() => set_slider_value(slider_value - step_size)}
|
||||
>
|
||||
<ArrowBackIosNewIcon />
|
||||
</Button>
|
||||
|
||||
{!is_playing ? (
|
||||
<Button
|
||||
variant="outlined"
|
||||
onClick={() => {
|
||||
setIsPlaying(true);
|
||||
}}
|
||||
>
|
||||
<PlayArrowIcon />
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
variant="outlined"
|
||||
onClick={() => {
|
||||
setIsPlaying(false);
|
||||
}}
|
||||
>
|
||||
<PauseIcon />
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="outlined"
|
||||
onClick={() => set_slider_value(slider_value + step_size)}
|
||||
>
|
||||
<ArrowForwardIosIcon />
|
||||
</Button>
|
||||
<Button variant="outlined" onClick={() => set_slider_value(slider_max)}>
|
||||
<LastPageIcon />
|
||||
</Button>
|
||||
</div>
|
||||
<div className="CameraList-row-time-interval">
|
||||
<TextField
|
||||
id="outlined-number"
|
||||
label="Seconds"
|
||||
type="number"
|
||||
onChange={(e) => setSeconds(Math.max(1, e.target.value))}
|
||||
value={seconds}
|
||||
/>
|
||||
<TextField
|
||||
id="outlined-number"
|
||||
label="FPS"
|
||||
type="number"
|
||||
onChange={(e) => setFps(Math.max(1, e.target.value))}
|
||||
value={fps}
|
||||
/>
|
||||
</div>
|
||||
<div className="CameraList-container">
|
||||
<CameraList
|
||||
sceneTree={sceneTree}
|
||||
transform_controls={transform_controls}
|
||||
camera_main={camera_main}
|
||||
cameras={cameras}
|
||||
setCameras={setCameras}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// Code for creating a curve from a set of points
|
||||
|
||||
import * as THREE from 'three';
|
||||
|
||||
function get_curve(list_of_3d_vectors) {
|
||||
// TODO: add some hyperparameters to this function
|
||||
const curve = new THREE.CatmullRomCurve3(
|
||||
list_of_3d_vectors,
|
||||
false,
|
||||
'centripetal',
|
||||
);
|
||||
return curve;
|
||||
}
|
||||
|
||||
export function get_curve_object_from_cameras(cameras) {
|
||||
// interpolate positions, lookat directions, and ups
|
||||
// similar to
|
||||
// https://github.com/google-research/multinerf/blob/1c8b1c552133cdb2de1c1f3c871b2813f6662265/internal/camera_utils.py#L281
|
||||
|
||||
const positions = [];
|
||||
const lookats = [];
|
||||
const ups = [];
|
||||
|
||||
for (let i = 0; i < cameras.length; i += 1) {
|
||||
const camera = cameras[i];
|
||||
|
||||
const up = new THREE.Vector3(0, 1, 0); // y is up in local space
|
||||
const lookat = new THREE.Vector3(0, 0, -1); // -z is forward in local space
|
||||
up.applyQuaternion(camera.quaternion);
|
||||
lookat.applyQuaternion(camera.quaternion);
|
||||
|
||||
positions.push(camera.position);
|
||||
ups.push(up);
|
||||
lookats.push(lookat);
|
||||
}
|
||||
|
||||
let curve_positions = null;
|
||||
let curve_lookats = null;
|
||||
let curve_ups = null;
|
||||
|
||||
curve_positions = get_curve(positions);
|
||||
curve_lookats = get_curve(lookats);
|
||||
curve_ups = get_curve(ups);
|
||||
|
||||
const curve_object = {
|
||||
curve_positions,
|
||||
curve_lookats,
|
||||
curve_ups,
|
||||
};
|
||||
|
||||
return curve_object;
|
||||
}
|
||||
@@ -15,7 +15,6 @@ import { Leva } from 'leva';
|
||||
import Tab from '@mui/material/Tab';
|
||||
import Tabs from '@mui/material/Tabs';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import { useEffect } from 'react';
|
||||
import Divider from '@mui/material/Divider';
|
||||
import StatusPanel from './StatusPanel';
|
||||
import SceneNode from '../../SceneNode';
|
||||
@@ -40,11 +39,9 @@ function TabPanel(props: TabPanelProps) {
|
||||
// eslint-disable-next-line react/jsx-props-no-spreading
|
||||
{...other}
|
||||
>
|
||||
{value === index && (
|
||||
<Box sx={{ p: 3, padding: 0 }}>
|
||||
<Typography component="div">{children}</Typography>
|
||||
</Box>
|
||||
)}
|
||||
<Box sx={{ p: 3, padding: 0 }}>
|
||||
<Typography component="div">{children}</Typography>
|
||||
</Box>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -121,18 +118,12 @@ interface BasicTabsProps {
|
||||
export function BasicTabs(props: BasicTabsProps) {
|
||||
const sceneTree = props.sceneTree;
|
||||
|
||||
const [value, setValue] = React.useState(0);
|
||||
const [value, setValue] = React.useState(2);
|
||||
|
||||
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
|
||||
setValue(newValue);
|
||||
};
|
||||
|
||||
// set the panel pane index
|
||||
useEffect(() => {
|
||||
const panel_index = 0;
|
||||
setValue(panel_index);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<StatusPanel sceneTree={sceneTree} />
|
||||
@@ -183,7 +174,7 @@ export function BasicTabs(props: BasicTabsProps) {
|
||||
</div>
|
||||
</TabPanel>
|
||||
<TabPanel value={value} index={2}>
|
||||
<CameraPanel />
|
||||
<CameraPanel sceneTree={sceneTree} />
|
||||
</TabPanel>
|
||||
|
||||
<TabPanel value={value} index={3}>
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
import * as THREE from 'three';
|
||||
|
||||
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
|
||||
import Stats from 'stats.js';
|
||||
import { useSelector } from 'react-redux';
|
||||
import React, { useContext, useEffect, useRef } from 'react';
|
||||
import { WebSocketContext } from '../WebSocket/WebSocket';
|
||||
|
||||
import { Button } from '@mui/material';
|
||||
import OpenWithIcon from '@mui/icons-material/OpenWith';
|
||||
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
|
||||
import PublicOffSharpIcon from '@mui/icons-material/PublicOffSharp';
|
||||
import PublicSharpIcon from '@mui/icons-material/PublicSharp';
|
||||
import Stats from 'stats.js';
|
||||
import SyncOutlinedIcon from '@mui/icons-material/SyncOutlined';
|
||||
import { TransformControls } from 'three/examples/jsm/controls/TransformControls';
|
||||
import { useSelector } from 'react-redux';
|
||||
import WebRtcWindow from '../WebRtcWindow/WebRtcWindow';
|
||||
import { WebSocketContext } from '../WebSocket/WebSocket';
|
||||
|
||||
const msgpack = require('msgpack-lite');
|
||||
|
||||
@@ -18,9 +25,54 @@ function createStats() {
|
||||
return stats;
|
||||
}
|
||||
|
||||
function TransformIcons(props) {
|
||||
const sceneTree = props.sceneTree;
|
||||
const transform_controls = sceneTree.find_object(['Transform Controls']);
|
||||
// toggle back and forth between local and global transform
|
||||
const [world, setWorld] = React.useState(true);
|
||||
|
||||
const toggleLocal = () => {
|
||||
transform_controls.setSpace(world ? 'local' : 'world');
|
||||
setWorld(!world);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Button
|
||||
className="ViewerWindow-iconbutton"
|
||||
onClick={() => {
|
||||
transform_controls.setMode('translate');
|
||||
}}
|
||||
variant="outlined"
|
||||
>
|
||||
{/* translate */}
|
||||
<OpenWithIcon />
|
||||
</Button>
|
||||
<Button
|
||||
className="ViewerWindow-iconbutton"
|
||||
onClick={() => {
|
||||
transform_controls.setMode('rotate');
|
||||
}}
|
||||
variant="outlined"
|
||||
>
|
||||
{/* rotate */}
|
||||
<SyncOutlinedIcon />
|
||||
</Button>
|
||||
<Button
|
||||
className="ViewerWindow-iconbutton"
|
||||
variant="outlined"
|
||||
onClick={toggleLocal}
|
||||
>
|
||||
{world ? <PublicSharpIcon /> : <PublicOffSharpIcon />}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// manages a camera and the web rtc stream...
|
||||
export default function ViewerWindow(props) {
|
||||
// eslint-disable-next-line react/prop-types
|
||||
const sceneTree = props.sceneTree;
|
||||
const scene = props.scene;
|
||||
|
||||
const myRef = useRef(null);
|
||||
@@ -30,13 +82,15 @@ export default function ViewerWindow(props) {
|
||||
);
|
||||
const field_of_view_ref = useRef(field_of_view);
|
||||
|
||||
const camera = useRef(null);
|
||||
let cameraControls = null;
|
||||
let transformsControls = null;
|
||||
let renderer = null;
|
||||
let viewportWidth = null;
|
||||
let viewportHeight = null;
|
||||
let stats = null;
|
||||
|
||||
const camera = sceneTree.find(['Main Camera', '<object>']).object;
|
||||
|
||||
const getViewportWidth = () => {
|
||||
const width = myRef.current.clientWidth;
|
||||
return width - (width % 2);
|
||||
@@ -49,8 +103,8 @@ export default function ViewerWindow(props) {
|
||||
const handleResize = () => {
|
||||
viewportWidth = getViewportWidth();
|
||||
viewportHeight = getViewportHeight();
|
||||
camera.current.aspect = viewportWidth / viewportHeight;
|
||||
camera.current.updateProjectionMatrix();
|
||||
camera.aspect = viewportWidth / viewportHeight;
|
||||
camera.updateProjectionMatrix();
|
||||
renderer.setSize(viewportWidth, viewportHeight);
|
||||
};
|
||||
|
||||
@@ -62,7 +116,7 @@ export default function ViewerWindow(props) {
|
||||
const data = {
|
||||
type: cmd,
|
||||
path,
|
||||
data: camera.current.toJSON(),
|
||||
data: camera.toJSON(),
|
||||
};
|
||||
const message = msgpack.encode(data);
|
||||
websocket.send(message);
|
||||
@@ -71,7 +125,7 @@ export default function ViewerWindow(props) {
|
||||
|
||||
// keep sending the camera often
|
||||
useEffect(() => {
|
||||
const fps = 60;
|
||||
const fps = 24;
|
||||
const interval = 1000 / fps;
|
||||
const refreshIntervalId = setInterval(sendCamera, interval);
|
||||
return () => {
|
||||
@@ -82,10 +136,10 @@ export default function ViewerWindow(props) {
|
||||
const update = () => {
|
||||
requestAnimationFrame(update);
|
||||
handleResize();
|
||||
camera.current.fov = field_of_view_ref.current;
|
||||
camera.current.updateProjectionMatrix();
|
||||
camera.fov = field_of_view_ref.current;
|
||||
camera.updateProjectionMatrix();
|
||||
cameraControls.update();
|
||||
renderer.render(scene, camera.current);
|
||||
renderer.render(scene, camera);
|
||||
stats.update();
|
||||
};
|
||||
|
||||
@@ -97,16 +151,16 @@ export default function ViewerWindow(props) {
|
||||
stats = createStats();
|
||||
myRef.current.append(stats.domElement);
|
||||
|
||||
camera.current = new THREE.PerspectiveCamera(
|
||||
field_of_view_ref.current,
|
||||
viewportWidth / viewportHeight,
|
||||
0.01,
|
||||
100,
|
||||
);
|
||||
camera.current.position.x = 5;
|
||||
camera.current.position.y = -5;
|
||||
camera.current.position.z = 5;
|
||||
camera.current.up = new THREE.Vector3(0, 0, 1);
|
||||
// camera = new THREE.PerspectiveCamera(
|
||||
// field_of_view_ref.current,
|
||||
// viewportWidth / viewportHeight,
|
||||
// 0.01,
|
||||
// 100,
|
||||
// );
|
||||
camera.position.x = 5;
|
||||
camera.position.y = -5;
|
||||
camera.position.z = 5;
|
||||
camera.up = new THREE.Vector3(0, 0, 1);
|
||||
|
||||
renderer = new THREE.WebGLRenderer({
|
||||
antialias: true,
|
||||
@@ -117,7 +171,7 @@ export default function ViewerWindow(props) {
|
||||
|
||||
myRef.current.append(renderer.domElement);
|
||||
// add camera controls
|
||||
cameraControls = new OrbitControls(camera.current, renderer.domElement);
|
||||
cameraControls = new OrbitControls(camera, renderer.domElement);
|
||||
cameraControls.rotateSpeed = 2.0;
|
||||
cameraControls.zoomSpeed = 0.3;
|
||||
cameraControls.panSpeed = 0.2;
|
||||
@@ -126,7 +180,16 @@ export default function ViewerWindow(props) {
|
||||
cameraControls.enableDamping = true;
|
||||
cameraControls.dampingFactor = 1.0;
|
||||
cameraControls.update();
|
||||
|
||||
transformsControls = new TransformControls(camera, renderer.domElement);
|
||||
sceneTree.set_object_from_path(['Transform Controls'], transformsControls);
|
||||
|
||||
transformsControls.addEventListener('dragging-changed', (event) => {
|
||||
cameraControls.enabled = !event.value;
|
||||
});
|
||||
|
||||
update();
|
||||
// cameraControls.addEventListener('change', update);
|
||||
}, []);
|
||||
|
||||
// updates the field of view inside the ref to avoid rerendering so often
|
||||
@@ -139,6 +202,9 @@ export default function ViewerWindow(props) {
|
||||
{/* the webrtc viewer needs to know the camera pose */}
|
||||
<WebRtcWindow />
|
||||
<div className="canvas-container-main" ref={myRef} />
|
||||
<div className="ViewerWindow-buttons">
|
||||
<TransformIcons sceneTree={sceneTree} />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1167,6 +1167,39 @@
|
||||
resolved "https://registry.yarnpkg.com/@csstools/selector-specificity/-/selector-specificity-2.0.2.tgz#1bfafe4b7ed0f3e4105837e056e0a89b108ebe36"
|
||||
integrity sha512-IkpVW/ehM1hWKln4fCA3NzJU8KwD+kIOvPZA4cqxoJHtE21CCzjyp+Kxbu0i5I4tBNOlXPL9mjwnWlL0VEG4Fg==
|
||||
|
||||
"@date-io/core@^2.15.0":
|
||||
version "2.15.0"
|
||||
resolved "https://registry.yarnpkg.com/@date-io/core/-/core-2.15.0.tgz#8133860c8ce163b8d0cca3c1caed8d5d1fbfb14e"
|
||||
integrity sha512-3CRvQUEK7aF87NUOwcTtmJ2Rc1kN0D4jFQUfRoanuAnE4o5HzHx4E2YenjaKjSPWeZYiWG6ZhDomx5hp1AaCJA==
|
||||
|
||||
"@date-io/date-fns@^2.15.0":
|
||||
version "2.15.0"
|
||||
resolved "https://registry.yarnpkg.com/@date-io/date-fns/-/date-fns-2.15.0.tgz#2541144f4fc40365efd7d0b7affa5d77dbe59102"
|
||||
integrity sha512-hkVeLm0jijHS2F9YVQcf0LSlD55w9xPvvIfuxDE0XWNXOTcRAAhqw2aqOxyeGbmHxc5U4HqyPZaqs9tfeTsomQ==
|
||||
dependencies:
|
||||
"@date-io/core" "^2.15.0"
|
||||
|
||||
"@date-io/dayjs@^2.15.0":
|
||||
version "2.15.0"
|
||||
resolved "https://registry.yarnpkg.com/@date-io/dayjs/-/dayjs-2.15.0.tgz#474a42586e67be1108a6f68b0a2e5e6088620fb6"
|
||||
integrity sha512-wgYzwaXr9KxkHNYxrOb1t8fYLfAdjIf0Q86qdVCwANObcvyGcPBm0uFtpPK7ApeE4DJUlbuG0IX75TtO+uITwQ==
|
||||
dependencies:
|
||||
"@date-io/core" "^2.15.0"
|
||||
|
||||
"@date-io/luxon@^2.15.0":
|
||||
version "2.15.0"
|
||||
resolved "https://registry.yarnpkg.com/@date-io/luxon/-/luxon-2.15.0.tgz#ad5bea9c46b46230bd780dc91413f31d1967830f"
|
||||
integrity sha512-CxTRCo5AM96ainnYaTpe1NS9GiA78SIgXBScgeAresCS20AvMcOd5XKerDj+y/KLhbSQbU6WUDqG9QcsrImXyQ==
|
||||
dependencies:
|
||||
"@date-io/core" "^2.15.0"
|
||||
|
||||
"@date-io/moment@^2.15.0":
|
||||
version "2.15.0"
|
||||
resolved "https://registry.yarnpkg.com/@date-io/moment/-/moment-2.15.0.tgz#d6c2c88b58534d0c44644abcfefc27cb32182dd8"
|
||||
integrity sha512-AcYBjl3EnEGsByaM5ir644CKbhgJsgc1iWFa9EXfdb4fQexxOC8oCdPAurK2ZDTwg62odyyKa/05YE7ElYh5ag==
|
||||
dependencies:
|
||||
"@date-io/core" "^2.15.0"
|
||||
|
||||
"@emotion/babel-plugin@^11.10.0":
|
||||
version "11.10.2"
|
||||
resolved "https://registry.yarnpkg.com/@emotion/babel-plugin/-/babel-plugin-11.10.2.tgz#879db80ba622b3f6076917a1e6f648b1c7d008c7"
|
||||
@@ -1614,6 +1647,20 @@
|
||||
prop-types "^15.8.1"
|
||||
react-is "^18.2.0"
|
||||
|
||||
"@mui/base@5.0.0-alpha.96":
|
||||
version "5.0.0-alpha.96"
|
||||
resolved "https://registry.yarnpkg.com/@mui/base/-/base-5.0.0-alpha.96.tgz#2189dd1012d0969ace69c3479b0aec2dbe9bbdc1"
|
||||
integrity sha512-GZf2YguepLFMWGG8vQNLRl7FlXPDeyxQBYgrkHxwNJYeRw55rrGrJxHzL1iCbk71VZ2IIAIs5IAxNpyHK9iqPQ==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.18.9"
|
||||
"@emotion/is-prop-valid" "^1.2.0"
|
||||
"@mui/types" "^7.2.0"
|
||||
"@mui/utils" "^5.10.3"
|
||||
"@popperjs/core" "^2.11.6"
|
||||
clsx "^1.2.1"
|
||||
prop-types "^15.8.1"
|
||||
react-is "^18.2.0"
|
||||
|
||||
"@mui/core-downloads-tracker@^5.10.3":
|
||||
version "5.10.3"
|
||||
resolved "https://registry.yarnpkg.com/@mui/core-downloads-tracker/-/core-downloads-tracker-5.10.3.tgz#e17a3cd87c7814ff35592284b19ae39ad52b85ac"
|
||||
@@ -1626,6 +1673,19 @@
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.18.9"
|
||||
|
||||
"@mui/lab@^5.0.0-alpha.98":
|
||||
version "5.0.0-alpha.98"
|
||||
resolved "https://registry.yarnpkg.com/@mui/lab/-/lab-5.0.0-alpha.98.tgz#d79ab98a24f035c13cfc4919f5aa50e0d6ad369d"
|
||||
integrity sha512-a6MJw+fMdFP5lyvrtlEgmCYoomv5lnmkcBt+LXM2hZ+RzCwEk2aTXsJFkuuyfIL0eCezcl+qN89cX1z97YQuAw==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.18.9"
|
||||
"@mui/base" "5.0.0-alpha.96"
|
||||
"@mui/system" "^5.10.4"
|
||||
"@mui/utils" "^5.10.3"
|
||||
clsx "^1.2.1"
|
||||
prop-types "^15.8.1"
|
||||
react-is "^18.2.0"
|
||||
|
||||
"@mui/material@^5.10.3":
|
||||
version "5.10.3"
|
||||
resolved "https://registry.yarnpkg.com/@mui/material/-/material-5.10.3.tgz#5497128ea7c8de1d40ba9bd95437d46d441fa1d1"
|
||||
@@ -1663,6 +1723,16 @@
|
||||
csstype "^3.1.0"
|
||||
prop-types "^15.8.1"
|
||||
|
||||
"@mui/styled-engine@^5.10.4":
|
||||
version "5.10.4"
|
||||
resolved "https://registry.yarnpkg.com/@mui/styled-engine/-/styled-engine-5.10.4.tgz#21b3ff3c18a748548b061bccff337a275e1f4861"
|
||||
integrity sha512-y29qlonPj4wndTjbePk9O6uWp/FBRNXjiMwI64oiYQ+v3E0EkLnADfDn49GAqOJAfN/r7nHbVZBlvLNIcMbgDg==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.18.9"
|
||||
"@emotion/cache" "^11.10.3"
|
||||
csstype "^3.1.0"
|
||||
prop-types "^15.8.1"
|
||||
|
||||
"@mui/system@^5.10.3":
|
||||
version "5.10.3"
|
||||
resolved "https://registry.yarnpkg.com/@mui/system/-/system-5.10.3.tgz#26f82e506af506f4fddde265c20e1100baaca03e"
|
||||
@@ -1677,12 +1747,26 @@
|
||||
csstype "^3.1.0"
|
||||
prop-types "^15.8.1"
|
||||
|
||||
"@mui/system@^5.10.4":
|
||||
version "5.10.4"
|
||||
resolved "https://registry.yarnpkg.com/@mui/system/-/system-5.10.4.tgz#4621cbae1bfc551c95e368d32850160b64034a67"
|
||||
integrity sha512-fE7LtYStPHPfq7EJXEVLQGvz23pS5YwSI7A4mWEFyyW21hHUh0c1opZXb7caHJsUTiBoC22W7R8GGfbVdSOnZA==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.18.9"
|
||||
"@mui/private-theming" "^5.10.3"
|
||||
"@mui/styled-engine" "^5.10.4"
|
||||
"@mui/types" "^7.2.0"
|
||||
"@mui/utils" "^5.10.3"
|
||||
clsx "^1.2.1"
|
||||
csstype "^3.1.0"
|
||||
prop-types "^15.8.1"
|
||||
|
||||
"@mui/types@^7.2.0":
|
||||
version "7.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@mui/types/-/types-7.2.0.tgz#91380c2d42420f51f404120f7a9270eadd6f5c23"
|
||||
integrity sha512-lGXtFKe5lp3UxTBGqKI1l7G8sE2xBik8qCfrLHD5olwP/YU0/ReWoWT7Lp1//ri32dK39oPMrJN8TgbkCSbsNA==
|
||||
|
||||
"@mui/utils@^5.10.3":
|
||||
"@mui/utils@^5.10.3", "@mui/utils@^5.9.3":
|
||||
version "5.10.3"
|
||||
resolved "https://registry.yarnpkg.com/@mui/utils/-/utils-5.10.3.tgz#ce2a96f31de2a5e717f507b5383dbabbddbc4dfc"
|
||||
integrity sha512-4jXMDPfx6bpMVuheLaOpKTjpzw39ogAZLeaLj5+RJec3E37/hAZMYjURfblLfTWMMoGoqkY03mNsZaEwNobBow==
|
||||
@@ -1693,6 +1777,24 @@
|
||||
prop-types "^15.8.1"
|
||||
react-is "^18.2.0"
|
||||
|
||||
"@mui/x-date-pickers@^5.0.0":
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@mui/x-date-pickers/-/x-date-pickers-5.0.0.tgz#e8b1dfe37e0ec611b2856e91984b76ded59c7f3c"
|
||||
integrity sha512-LcWJYFC/SdYbu0JSz6pgQcCh/cvllyoAqfpqf6iTex7jMSEk8i008pCntyrEVVcjGrx0fakDduSJthlnf0xNxQ==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.18.9"
|
||||
"@date-io/core" "^2.15.0"
|
||||
"@date-io/date-fns" "^2.15.0"
|
||||
"@date-io/dayjs" "^2.15.0"
|
||||
"@date-io/luxon" "^2.15.0"
|
||||
"@date-io/moment" "^2.15.0"
|
||||
"@mui/utils" "^5.9.3"
|
||||
"@types/react-transition-group" "^4.4.5"
|
||||
clsx "^1.2.1"
|
||||
prop-types "^15.7.2"
|
||||
react-transition-group "^4.4.5"
|
||||
rifm "^0.12.1"
|
||||
|
||||
"@nodelib/fs.scandir@2.1.5":
|
||||
version "2.1.5"
|
||||
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5"
|
||||
@@ -3994,6 +4096,11 @@ date-fns@^2.16.1:
|
||||
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.29.1.tgz#9667c2615525e552b5135a3116b95b1961456e60"
|
||||
integrity sha512-dlLD5rKaKxpFdnjrs+5azHDFOPEu4ANy/LTh04A1DTzMM7qoajmKCBc8pkKRFT41CNzw+4gQh79X5C+Jq27HAw==
|
||||
|
||||
dayjs@^1.11.5:
|
||||
version "1.11.5"
|
||||
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.5.tgz#00e8cc627f231f9499c19b38af49f56dc0ac5e93"
|
||||
integrity sha512-CAdX5Q3YW3Gclyo5Vpqkgpj8fSdLQcRuzfX6mC6Phy0nfJ0eGYOeS7m4mt2plDWLAtA4TqTakvbboHvUxfe4iA==
|
||||
|
||||
debug@2.6.9, debug@^2.2.0, debug@^2.6.0, debug@^2.6.9:
|
||||
version "2.6.9"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
|
||||
@@ -7919,7 +8026,7 @@ prompts@^2.0.1, prompts@^2.4.2:
|
||||
kleur "^3.0.3"
|
||||
sisteransi "^1.0.5"
|
||||
|
||||
prop-types@^15.6.2, prop-types@^15.8.1:
|
||||
prop-types@^15.6.2, prop-types@^15.7.2, prop-types@^15.8.1:
|
||||
version "15.8.1"
|
||||
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
|
||||
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==
|
||||
@@ -8429,6 +8536,11 @@ reusify@^1.0.4:
|
||||
resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76"
|
||||
integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==
|
||||
|
||||
rifm@^0.12.1:
|
||||
version "0.12.1"
|
||||
resolved "https://registry.yarnpkg.com/rifm/-/rifm-0.12.1.tgz#8fa77f45b7f1cda2a0068787ac821f0593967ac4"
|
||||
integrity sha512-OGA1Bitg/dSJtI/c4dh90svzaUPt228kzFsUkJbtA2c964IqEAwWXeL9ZJi86xWv3j5SMqRvGULl7bA6cK0Bvg==
|
||||
|
||||
rimraf@^3.0.0, rimraf@^3.0.2:
|
||||
version "3.0.2"
|
||||
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a"
|
||||
|
||||
Reference in new issue
Block a user