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:
Ethan Weber authored and GitHub committed 2022-08-02 16:02:07 -05:00
1 parent 966374474d
commit 73fedc7593
67 files changed
+2510 -14057

No files matched your search

+34 -33
View File
@@ -1,12 +1,14 @@
import * as THREE from "three";
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-restricted-syntax */
import * as THREE from 'three';
const dat = require("dat.gui");
const dat = require('dat.gui');
function remove_folders(gui) {
for (let name of Object.keys(gui.__folders)) {
let folder = gui.__folders[name];
for (const name of Object.keys(gui.__folders)) {
const folder = gui.__folders[name];
remove_folders(folder);
dat.dom.dom.unbind(window, "resize", folder.__resizeHandler);
dat.dom.dom.unbind(window, 'resize', folder.__resizeHandler);
gui.removeFolder(folder);
}
}
@@ -20,7 +22,7 @@ function dispose(object) {
}
if (object.material) {
if (Array.isArray(object.material)) {
for (let material of object.material) {
for (const material of object.material) {
if (material.map) {
material.map.dispose();
}
@@ -35,42 +37,41 @@ function dispose(object) {
}
}
export class SceneNode {
export default class SceneNode {
constructor(object, folder) {
this.object = object;
this.folder = folder;
this.children = {};
this.create_controls();
for (let c of this.object.children) {
for (const c of this.object.children) {
this.add_child(c);
}
}
add_child(object) {
let f = this.folder.addFolder(object.name);
let node = new SceneNode(object, f);
const f = this.folder.addFolder(object.name);
const node = new SceneNode(object, f);
this.children[object.name] = node;
return node;
}
create_child(name) {
let obj = new THREE.Group();
const obj = new THREE.Group();
obj.name = name;
this.object.add(obj);
return this.add_child(obj);
}
find(path) {
if (path.length == 0) {
if (path.length === 0) {
return this;
} else {
let name = path[0];
let child = this.children[name];
if (child === undefined) {
child = this.create_child(name);
}
return child.find(path.slice(1));
}
const name = path[0];
let child = this.children[name];
if (child === undefined) {
child = this.create_child(name);
}
return child.find(path.slice(1));
}
create_controls() {
@@ -79,19 +80,19 @@ export class SceneNode {
}
this.vis_controller = new dat.controllers.BooleanController(
this.object,
"visible"
'visible',
);
this.folder.domElement.prepend(this.vis_controller.domElement);
this.vis_controller.domElement.style.height = "0";
this.vis_controller.domElement.style.float = "right";
this.vis_controller.domElement.style.height = '0';
this.vis_controller.domElement.style.float = 'right';
}
set_property(property, value) {
if (property === "position") {
if (property === 'position') {
this.object.position.set(value[0], value[1], value[2]);
} else if (property === "quaternion") {
} else if (property === 'quaternion') {
this.object.quaternion.set(value[0], value[1], value[2], value[3]);
} else if (property === "scale") {
} else if (property === 'scale') {
this.object.scale.set(value[0], value[1], value[2]);
} else {
this.object[property] = value;
@@ -100,17 +101,17 @@ export class SceneNode {
}
set_transform(matrix) {
let mat = new THREE.Matrix4();
const mat = new THREE.Matrix4();
mat.fromArray(matrix);
mat.decompose(
this.object.position,
this.object.quaternion,
this.object.scale
this.object.scale,
);
}
set_object(object) {
let parent = this.object.parent;
const parent = this.object.parent;
this.dispose_recursive();
this.object.parent.remove(this.object);
this.object = object;
@@ -119,19 +120,19 @@ export class SceneNode {
}
dispose_recursive() {
for (let name of Object.keys(this.children)) {
for (const name of Object.keys(this.children)) {
this.children[name].dispose_recursive();
}
dispose(this.object);
}
delete(path) {
if (path.length == 0) {
if (path.length === 0) {
console.error("Can't delete an empty path");
} else {
let parent = this.find(path.slice(0, path.length - 1));
let name = path[path.length - 1];
let child = parent.children[name];
const parent = this.find(path.slice(0, path.length - 1));
const name = path[path.length - 1];
const child = parent.children[name];
if (child !== undefined) {
child.dispose_recursive();
parent.object.remove(child.object);