add setFocus() and multi-use 'v' key to refocus on center of all widgets

This commit is contained in:
Stewart Allen 2021-01-22 10:41:04 -05:00
commit cbc9fb8da3
4 changed files with 48 additions and 8 deletions

View file

@ -327,7 +327,8 @@
reload: reload,
restore: restoreWorkspace,
clear: clearWorkspace,
save: saveWorkspace
save: saveWorkspace,
set_focus: setFocus
},
tweak,
util: {
@ -368,6 +369,25 @@
work: KIRI.work
};
function setFocus(widgets) {
if (widgets === undefined) {
widgets = WIDGETS;
} else if (!Array.isArray) {
widgets = [ widgets ];
}
let pos = { x:0, y:0, z:0 };
for (let widget of widgets) {
pos.x += widget.track.pos.x;
pos.y += widget.track.pos.y;
pos.z += widget.track.pos.z;
}
pos.x /= widgets.length;
pos.y /= widgets.length;
pos.z /= widgets.length;
SPACE.platform.setCenter(pos.x, -pos.y, pos.z);
SPACE.view.setFocus(new THREE.Vector3(pos.x, pos.z, -pos.y));
}
function reload() {
API.event.emit('reload');
do_reload(100);