4
0
mirror of https://github.com/nerfstudio-project/nerfstudio.git synced 2026-11-11 02:24:38 +08:00

Switch to orbit controls

This commit is contained in:
Matt Tancik 2022-07-13 15:21:18 -07:00 committed by Matthew Tancik
parent 0f779c2885
commit c35bf43255
3 changed files with 45 additions and 27 deletions

View File

@ -1,6 +1,6 @@
import React, { Component } from "react";
import * as THREE from "three";
import { TrackballControls } from "three/examples/jsm/controls/TrackballControls";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
import Stats from "three/examples/jsm/libs/stats.module.js";
import { GUI } from "dat.gui";
import { split_path } from "./utils";
@ -115,25 +115,9 @@ export class Viewer extends Component {
}
set_object(path, object) {
this.state.scene_tree.find(path.concat(["<object>"])).set_object(object);
// add controls if object is a camera
if (object instanceof THREE.Camera) {
this.state.controls_main = new TrackballControls(
object,
this.state.renderer_main.domElement
);
this.state.controls_main.rotateSpeed = 2.0;
this.state.controls_main.zoomSpeed = 0.3;
this.state.controls_main.panSpeed = 0.2;
this.state.controls_main.staticMoving = false; // false is default
this.state.controls_main.target.set(0, 0, 0); // focus point of the controls
this.state.controls_main.autoRotate = false;
this.state.controls_main.dynamicDampingFactor = 1.0;
this.state.controls_main.update();
// this.send_camera_over_websocket();
// this.state.controls_main.addEventListener("change", () => {
// this.send_camera_over_websocket();
// });
if (!(object instanceof THREE.Camera)) {
this.state.scene_tree.find(path.concat(["<object>"])).set_object(object);
}
}
@ -367,7 +351,23 @@ export class Viewer extends Component {
this.state.camera_main.position.y = -5;
this.state.camera_main.position.z = 5;
this.state.camera_main.up = new THREE.Vector3(0, 0, 1);
this.set_object(["Cameras", "Main Camera"], this.state.camera_main);
this.state.controls_main = new OrbitControls(
this.state.camera_main,
this.state.renderer_main.domElement
);
this.state.controls_main.rotateSpeed = 2.0;
this.state.controls_main.zoomSpeed = 0.3;
this.state.controls_main.panSpeed = 0.2;
this.state.controls_main.target.set(0, 0, 0); // focus point of the controls
this.state.controls_main.autoRotate = false;
this.state.controls_main.enableDamping = true;
this.state.controls_main.dampingFactor = 1.0;
this.state.controls_main.update();
let path = ["Cameras", "Main Camera"];
this.state.scene_tree.find(path.concat(["<object>"])).set_object(this.state.camera_main);
// Axes display
let axes = new THREE.AxesHelper(5);

View File

@ -15,7 +15,7 @@
import numpy as np
import torch
from pyrad.cameras.cameras import Camera, get_camera, get_intrinsics_from_intrinsics_matrix
from pyrad.cameras.cameras import get_camera, get_intrinsics_from_intrinsics_matrix
def get_chunks(lst, num_chunks=None, size_of_chunk=None):
@ -49,6 +49,15 @@ def get_intrinsics_matrix_and_camera_to_world_h(camera_object, image_height):
# extrinsics
camera_to_world_h = torch.tensor(get_chunks(camera_object["matrix"], size_of_chunk=4)).T.float()
camera_to_world_h = torch.stack(
[
camera_to_world_h[0, :],
camera_to_world_h[2, :],
camera_to_world_h[1, :],
camera_to_world_h[3, :],
],
dim=0,
)
return intrinsics_matrix, camera_to_world_h

View File

@ -24,19 +24,20 @@ import time
from typing import List
import numpy as np
from pyrad.data.image_dataset import ImageDataset
from pyrad.data.structs import DatasetInputs
from pyrad.graphs.base import Graph
import torch
import pyrad.viewer.server.cameras as c
import pyrad.viewer.server.geometry as g
from pyrad.cameras.cameras import Camera, get_camera, get_intrinsics_from_intrinsics_matrix
from pyrad.cameras.rays import RayBundle
from pyrad.data.image_dataset import ImageDataset
from pyrad.data.structs import DatasetInputs
from pyrad.graphs.base import Graph
from pyrad.utils import profiler
from pyrad.utils.config import ViewerConfig
from pyrad.viewer.server.visualizer import Viewer
from pyrad.viewer.server.utils import get_intrinsics_matrix_and_camera_to_world_h
from pyrad.viewer.server.transformations import get_translation_matrix
from pyrad.viewer.server.utils import get_intrinsics_matrix_and_camera_to_world_h
from pyrad.viewer.server.visualizer import Viewer
class IOChangeException(Exception):
@ -228,6 +229,14 @@ class VisualizerState:
)
camera_to_world = camera_to_world_h[:3, :]
camera_to_world = torch.stack(
[
camera_to_world[0, :],
camera_to_world[2, :],
camera_to_world[1, :],
],
dim=0,
)
intrinsics = get_intrinsics_from_intrinsics_matrix(intrinsics_matrix)
camera = get_camera(intrinsics, camera_to_world)
camera_ray_bundle = camera.get_camera_ray_bundle(device=graph.get_device())