add analytic patches

This commit is contained in:
Stewart Allen 2022-01-11 21:04:24 -05:00
commit fb5e598d9e
4 changed files with 20 additions and 16 deletions

View file

@ -208,8 +208,8 @@ let group = {
},
// @param group {MeshModel[]}
new(models, id) {
return group.add(new mesh.group(models, id));
new(models, id, name) {
return group.add(new mesh.group(models, id, name));
},
// @param group {MeshGroup}
@ -295,31 +295,30 @@ let tool = {
},
analyze(models) {
let promises = [];
api.log.emit('analyzing mesh(es)...').pin();
let areas = [];
let edges = [];
let promises = [];
let newmdl = [];
let mcore = new THREE.Matrix4().makeRotationX(Math.PI / 2);
for (let m of models) {
let p = worker.model_analyze(m.id).then(data => {
areas.appendAll(data.mapped.areas);
edges.appendAll(data.mapped.edges);
let { areas, edges } = data.mapped;
let nm = areas.map(area => new mesh.model({
file: (area.length/3).toString(),
mesh: area.toFloat32()
})).map( nm => nm.applyMatrix4(mcore.multiply(m.mesh.matrixWorld)) );
newmdl.appendAll(nm);
});
promises.push(p);
}
Promise.all(promises).then(() => {
let newmdl = areas.map(area => new mesh.model({
file: (area.length/3).toString(),
mesh: area.toFloat32()
}));
mesh.api.group.new(newmdl);
console.log({ areas, edges, newmdl });
mesh.api.group.new(newmdl, undefined, "patch");
api.log.emit('analysis complete').unpin();
});
},
repair(models) {
let promises = [];
api.log.emit('repairing mesh(es)...').pin();
let promises = [];
for (let m of models) {
let p = worker.model_heal(m.id).then(data => {
if (data) {

View file

@ -263,7 +263,7 @@ function ui_build() {
// map groups to divs
let groups = api.group.list()
.map(g => h.div([
h.button({ _: `group`, title: g.id,
h.button({ _: g.name || `group`, title: g.id,
class: [ "group", selHas(g) ? 'selected' : undefined ],
onclick(e) {
e.shiftKey ? api.selection.toggle(g) : api.selection.set([g])

View file

@ -26,10 +26,11 @@ let worker = moto.client.fn;
mesh.group = class MeshGroup extends mesh.object {
// @param group {MeshModel[]}
constructor(models = [], id) {
constructor(models = [], id, name) {
super(id);
this.group3 = new THREE.Group();
this.models = [];
this.name = name;
for (let model of models) {
this.add(model);
}

View file

@ -62,6 +62,10 @@ mesh.object = class MeshObject {
return this;
}
applyMatrix4(matrix) {
return this.applyMatrix(matrix.elements);
}
focus() {
mesh.api.focus(this.object);
return this;