diff --git a/src/main/mesh.js b/src/main/mesh.js index 6765cc2e..f3d015f8 100644 --- a/src/main/mesh.js +++ b/src/main/mesh.js @@ -167,21 +167,27 @@ function ui_build() { return h.bind(selectlist, []); } // map selection to divs - let h_grp = s_grp.map(g => h.div([ - h.button({ _: `group`, title: g.id, xclass: [ "group" ], }), + 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_id = s_grp.map(g => g.id).join(' '); + let h_grp = [h.div([ + h.button({ _: `group`, title: g_id, xclass: [ "group" ], }), grid( - util.extract(g.object.position, map), - util.extract(g.object.rotation, map) ) - ])); - let h_mdl = s_mdl.map(m => h.div([ - h.button({ _: `model`, title: m.id, xclass: [ "model" ], }), + util.extract(g_pos, map), + util.extract(g_rot, map) ) + ])]; + let m_pos = util.average(s_mdl.map(m => m.object.position)); + let m_rot = util.average(s_mdl.map(m => m.object.rotation)); + let m_id = s_mdl.map(m => m.id).join(' '); + let h_mdl = [h.div([ + h.button({ _: `model`, title: m_id, xclass: [ "model" ], }), grid( - util.extract(m.object.position, map), - util.extract(m.object.rotation, map) ) - ])); + util.extract(m_pos, map), + util.extract(m_rot, map) ) + ])]; let bounds = util.bounds(s_mdl); let h_bnd = [h.div([ - h.button({ _: `box`, title: s_mdl[0].id, xclass: [ "box" ], }), + h.button({ _: `box`, title: m_id, xclass: [ "box" ], }), grid( util.extract(bounds.min, map), util.extract(bounds.max, map), @@ -189,7 +195,7 @@ function ui_build() { ) ])]; let h_ara = [h.div([ - h.button({ _: `area`, title: s_mdl[0].id, xclass: [ "area" ], }), + h.button({ _: `area`, title: m_id, xclass: [ "area" ], }), grid( util.extract(bounds.center, map), util.extract(bounds.size, map), diff --git a/src/mesh/api.js b/src/mesh/api.js index 4a02332d..672b0661 100644 --- a/src/mesh/api.js +++ b/src/mesh/api.js @@ -96,7 +96,7 @@ let selection = { }, clear() { - for (let s of selected) { + for (let s of selection.list()) { selection.remove(s); } }, @@ -362,6 +362,20 @@ let util = mesh.util = { array.push(v); } return array; + }, + + average(array, opt = {}) { + let fields = opt.fields || ['x', 'y', 'z']; + let avg = {}; + for (let e of array) { + for (let f of fields) { + avg[f] = (avg[f] || 0) + e[f]; + } + } + for (let f of fields) { + avg[f] = (avg[f] || 0) / array.length; + } + return avg; } }; diff --git a/src/mesh/model.js b/src/mesh/model.js index deef7992..db887076 100644 --- a/src/mesh/model.js +++ b/src/mesh/model.js @@ -127,6 +127,18 @@ mesh.model = class MeshModel extends mesh.object { this._group = gv; } + get attributes() { + return this.mesh.geometry.attributes; + } + + get vertices() { + return this.attributes.vertices.count; + } + + get faces() { + return this.vertices / 3; + } + opacity(ov) { let mat = this.mesh.material; if (ov === undefined) {