add selection operators

This commit is contained in:
Stewart Allen 2022-04-19 23:03:58 -04:00
commit c279726c77
4 changed files with 46 additions and 7 deletions

View file

@ -356,11 +356,7 @@ function space_init(data) {
space.refresh() space.refresh()
} }
} else { } else {
for (let s of selection.list(true)) { selection.delete();
selection.remove(s);
s.showBounds(false);
s.remove();
}
} }
estop(evt); estop(evt);
break; break;

View file

@ -88,6 +88,15 @@ const selection = {
util.defer(selection.update); util.defer(selection.update);
}, },
// remove all
delete() {
for (let s of selection.list()) {
selection.remove(s);
s.showBounds(false);
s.remove();
}
},
// @param group {MeshObject} // @param group {MeshObject}
toggle(object) { toggle(object) {
if (selected.contains(object)) { if (selected.contains(object)) {

View file

@ -11,6 +11,7 @@ const { broker } = gapp;
const { mesh } = root; const { mesh } = root;
const { api, util } = mesh; const { api, util } = mesh;
const trash = FontAwesome.icon({ prefix: "fas", iconName: "trash" }).html[0];
const eye_open = FontAwesome.icon({ prefix: "fas", iconName: "eye" }).html[0]; const eye_open = FontAwesome.icon({ prefix: "fas", iconName: "eye" }).html[0];
const eye_closed = FontAwesome.icon({ prefix: "fas", iconName: "eye-slash" }).html[0]; const eye_closed = FontAwesome.icon({ prefix: "fas", iconName: "eye-slash" }).html[0];
@ -365,8 +366,8 @@ function ui_build() {
h.div([ h.div([
h.div({ _: "view", class: "head" }), h.div({ _: "view", class: "head" }),
h.button({ _: 'bounds', onclick() { selection.boundsBox({ toggle: true }) } }), h.button({ _: 'bounds', onclick() { selection.boundsBox({ toggle: true }) } }),
h.button({ _: 'gridlines', onclick() { api.grid() } }),
h.button({ _: 'normals', onclick() { api.normals() } }), h.button({ _: 'normals', onclick() { api.normals() } }),
h.button({ _: 'gridlines', onclick() { api.grid() } }),
h.button({ _: 'wireframe', onclick() { api.wireframe() } }), h.button({ _: 'wireframe', onclick() { api.wireframe() } }),
]), ]),
h.div([ h.div([
@ -504,6 +505,7 @@ function ui_build() {
if (s_mdl.length === 0) { if (s_mdl.length === 0) {
return h.bind(selectlist, []); return h.bind(selectlist, []);
} }
// toggle-able stat block generator // toggle-able stat block generator
let sdata = {}; let sdata = {};
function sblock(label, title, grid) { function sblock(label, title, grid) {
@ -520,6 +522,7 @@ function ui_build() {
]) ])
]; ];
} }
// map selection to divs // map selection to divs
let g_pos = util.average(s_grp.map(g => g.object.position)); let g_pos = util.average(s_grp.map(g => g.object.position));
let g_rot = util.average(s_grp.map(g => g.object.rotation)); let g_rot = util.average(s_grp.map(g => g.object.rotation));
@ -563,13 +566,31 @@ function ui_build() {
h.label({ _: util.comma(t_face) }), h.label({ _: util.comma(t_face) }),
]) ])
])]; ])];
let m_viz = !s_mdl.map(m => !m.visible()).reduce((v,b) => v || b);
let h_ops = [h.div([
h.button({ _: `ops` }),
h.div({ class: ["grid","grid1"]}, [
h.div({ class: [ 'square' ],
onclick(e) {
api.selection.visible(!m_viz);
update_selector();
}
}, [ h.raw(m_viz ? eye_open : eye_closed) ]),
h.div({ class: [ 'square' ],
onclick(e) { api.selection.delete() }
}, [ h.raw(trash) ])
])
])];
// bind elements to selectlist div // bind elements to selectlist div
let bound = h.bind(selectlist, [ let bound = h.bind(selectlist, [
...h_grp, ...h_grp,
...h_mdl, ...h_mdl,
...h_bnd, ...h_bnd,
...h_ara, ...h_ara,
...h_msh ...h_msh,
...h_ops
]); ]);
// bind rotation editable fields // bind rotation editable fields

View file

@ -574,6 +574,10 @@ button.selected:hover {
gap: 2px; gap: 2px;
} }
#selectlist > button, #selectlist > div > button {
border-radius: 3px;
}
#selectlist label { #selectlist label {
border-radius: 3px; border-radius: 3px;
font-family: monospace; font-family: monospace;
@ -606,6 +610,15 @@ button.selected:hover {
grid: min-content 1fr 1fr / min-content 1fr 1fr 1fr; grid: min-content 1fr 1fr / min-content 1fr 1fr 1fr;
} }
#selectlist .grid1 {
display: flex;
flex-grow: 1;
flex-direction: column;
justify-content: center;
align-items: center;
gap: 5px;
}
#selectlist .grid2 { #selectlist .grid2 {
grid: min-content 1fr / min-content 1fr; grid: min-content 1fr / min-content 1fr;
} }