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

+59
View File
@@ -0,0 +1,59 @@
import { split_path } from './utils';
const initialState = {
// the websocket connection state
websocketState: {
isConnected: false,
},
// the webrtc connection state
webrtcState: {
isConnected: false,
},
// the rendering state
renderingState: {
camera: null, // the camera object used to render the three.js scene
isTraining: true,
output_options: ['rgb'], // populated by the possible Graph outputs
output_choice: 'rgb', // the selected output
minResolution: 50,
maxResolution: 512,
field_of_view: 80
},
// the scene state
sceneState: {
sceneBounds: null,
cameras: null,
},
// ------------------------------------------------------------------------
// which of the state keys to synchronize with the bridge server
sync_keys: ['renderingState', 'sceneState'],
};
function setData(newState, state, path, data) {
if (path.length === 1) {
newState[path[0]] = data; // eslint-disable-line no-param-reassign
} else {
newState[path[0]] = { ...state[path[0]] }; // eslint-disable-line no-param-reassign
setData(newState[path[0]], state[path[0]], path.slice(1), data);
}
}
// Use the initialState as a default value
// eslint-disable-next-line default-param-last
export default function rootReducer(state = initialState, action) {
// The reducer normally looks at the action type field to decide what happens
switch (action.type) {
case 'write': {
const path = split_path(action.path); // convert string with "/"s to a list
const data = action.data;
const newState = { ...state };
setData(newState, state, path, data);
return newState;
}
default:
// If this reducer doesn't recognize the action type, or doesn't
// care about this specific action, return the existing state unchanged
return state;
}
}