mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-25 18:39:55 +08:00
Viewer refactor with state sync (#212)
* initial commit for viewer refactor * updating name change to nerfactory * adding headers * making the rendering fix which broke from a merge * things are starting to work. removing old commands now * removed prints * cleanup * updating state works now even for nested dictionaries * updating state in redux. listening for state changes. trying to draw three.js now * added drawing functionality. need to fix translation of frustums and image planes * images and frustums drawn correctly * fixing lint * github actions * back to npm * fixing eslint * remove package.json from root * new favicon * some viewer cleanup * notebook * fixed camera drawings speed to avoid redraw * trying to get Leva to update * quick fix * synced config panel * adding notebook * fixing output print error
This commit is contained in:
1 parent
966374474d
commit
73fedc7593
67 files changed
+2510
-14057
No files matched your search
@@ -0,0 +1,27 @@
|
||||
.WebRTCVideo {
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
right: 0px;
|
||||
bottom: 0px;
|
||||
left: 0px;
|
||||
}
|
||||
|
||||
.WebRTCVideo-video {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: fill;
|
||||
}
|
||||
|
||||
.canvas-container-main {
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
right: 0px;
|
||||
bottom: 0px;
|
||||
left: 0px;
|
||||
}
|
||||
|
||||
.canvas-container-main canvas {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
import './ViewerWindow.css';
|
||||
|
||||
import * as THREE from 'three';
|
||||
|
||||
import React, { useContext, useEffect, useRef } from 'react';
|
||||
import { useSelector } from 'react-redux';
|
||||
|
||||
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
|
||||
import WebRtcWindow from '../WebRtcWindow/WebRtcWindow';
|
||||
import { WebSocketContext } from '../WebSocket/WebSocket';
|
||||
|
||||
const msgpack = require('msgpack-lite');
|
||||
|
||||
// manages a camera and the web rtc stream...
|
||||
export default function ViewerWindow(props) {
|
||||
// eslint-disable-next-line react/prop-types
|
||||
const scene = props.scene;
|
||||
let cameraControls = null;
|
||||
const myRef = useRef(null);
|
||||
const websocket = useContext(WebSocketContext).socket;
|
||||
const field_of_view = useSelector(
|
||||
(state) => state.renderingState.field_of_view,
|
||||
);
|
||||
|
||||
const getViewportWidth = () => {
|
||||
return window.innerWidth - (window.innerWidth % 2);
|
||||
};
|
||||
|
||||
const getViewportHeight = () => {
|
||||
return window.innerHeight;
|
||||
};
|
||||
|
||||
let viewportWidth = getViewportWidth();
|
||||
let viewportHeight = getViewportHeight();
|
||||
|
||||
const camera = new THREE.PerspectiveCamera(
|
||||
field_of_view,
|
||||
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);
|
||||
|
||||
const renderer = new THREE.WebGLRenderer({
|
||||
antialias: true,
|
||||
alpha: true,
|
||||
});
|
||||
renderer.setPixelRatio(window.devicePixelRatio);
|
||||
renderer.setSize(viewportWidth, viewportHeight);
|
||||
renderer.domElement.style.border = '1px solid black';
|
||||
|
||||
const handleResize = () => {
|
||||
viewportWidth = getViewportWidth();
|
||||
viewportHeight = getViewportHeight();
|
||||
camera.aspect = viewportWidth / viewportHeight;
|
||||
camera.updateProjectionMatrix();
|
||||
renderer.setSize(viewportWidth, viewportHeight);
|
||||
};
|
||||
|
||||
const sendCamera = () => {
|
||||
// update the camera information in the python server
|
||||
if (websocket.readyState === WebSocket.OPEN) {
|
||||
const cmd = 'write';
|
||||
const path = 'renderingState/camera';
|
||||
const data = {
|
||||
type: cmd,
|
||||
path,
|
||||
data: camera.toJSON(),
|
||||
};
|
||||
const message = msgpack.encode(data);
|
||||
websocket.send(message);
|
||||
}
|
||||
};
|
||||
|
||||
const update = () => {
|
||||
handleResize();
|
||||
camera.updateProjectionMatrix();
|
||||
cameraControls.update();
|
||||
requestAnimationFrame(update);
|
||||
renderer.render(scene, camera);
|
||||
sendCamera();
|
||||
};
|
||||
|
||||
// similar to componentDidMount
|
||||
useEffect(() => {
|
||||
myRef.current.append(renderer.domElement);
|
||||
// add camera controls
|
||||
cameraControls = new OrbitControls(camera, renderer.domElement);
|
||||
cameraControls.rotateSpeed = 2.0;
|
||||
cameraControls.zoomSpeed = 0.3;
|
||||
cameraControls.panSpeed = 0.2;
|
||||
cameraControls.target.set(0, 0, 0); // focus point of the controls
|
||||
cameraControls.autoRotate = false;
|
||||
cameraControls.enableDamping = true;
|
||||
cameraControls.dampingFactor = 1.0;
|
||||
cameraControls.update();
|
||||
update();
|
||||
}, []);
|
||||
|
||||
// useEffect(() => {
|
||||
// camera.fov = field_of_view;
|
||||
// console.log(field_of_view);
|
||||
// camera.updateProjectionMatrix();
|
||||
// }, [field_of_view]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* the webrtc viewer needs to know the camera pose */}
|
||||
<WebRtcWindow />
|
||||
<div className="canvas-container-main" ref={myRef} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Whitespace-only changes.
Reference in new issue
Block a user