add duplication and merging
This commit is contained in:
parent
9f73e6e3c3
commit
f500ee0f5c
4 changed files with 58 additions and 15 deletions
|
|
@ -157,15 +157,15 @@ function space_init(data) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 'KeyD':
|
case 'KeyD':
|
||||||
if (shiftKey) {
|
if (shiftKey) {
|
||||||
for (let m of selection.models()) {
|
return selection.duplicate();
|
||||||
m.duplicate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'KeyC':
|
case 'KeyC':
|
||||||
return selection.centerXY().focus();
|
return selection.centerXY().focus();
|
||||||
case 'KeyF':
|
case 'KeyF':
|
||||||
return selection.floor().focus();
|
return selection.floor().focus();
|
||||||
|
case 'KeyM':
|
||||||
|
return selection.merge();
|
||||||
case 'KeyI':
|
case 'KeyI':
|
||||||
return api.file.import();
|
return api.file.import();
|
||||||
case 'KeyX':
|
case 'KeyX':
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,17 @@ let selection = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
duplicate() {
|
||||||
|
for (let m of selection.models()) {
|
||||||
|
m.duplicate();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
merge() {
|
||||||
|
tool.merge(selection.models());
|
||||||
|
},
|
||||||
|
|
||||||
|
// update material selections
|
||||||
update() {
|
update() {
|
||||||
for (let group of groups) {
|
for (let group of groups) {
|
||||||
group.material(mesh.material.unselected);
|
group.material(mesh.material.unselected);
|
||||||
|
|
@ -257,20 +268,40 @@ let file = {
|
||||||
};
|
};
|
||||||
|
|
||||||
let tool = {
|
let tool = {
|
||||||
|
merge(models) {
|
||||||
|
api.log.emit(`merging ${models.length} models`).pin();
|
||||||
|
worker.model_merge(models.map(m => {
|
||||||
|
return { id: m.id, matrix: m.matrix }
|
||||||
|
}))
|
||||||
|
.then(data => {
|
||||||
|
let group = api.group.new([new mesh.model({
|
||||||
|
file: `merged`,
|
||||||
|
mesh: data
|
||||||
|
})]).centerModels();
|
||||||
|
api.selection.set([group]);
|
||||||
|
api.log.emit('merge complete').unpin();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
analyze() {
|
analyze() {
|
||||||
|
let promises = [];
|
||||||
api.log.emit('analyzing mesh(es)...').pin();
|
api.log.emit('analyzing mesh(es)...').pin();
|
||||||
for (let m of selection.models()) {
|
for (let m of selection.models()) {
|
||||||
worker.model_analyze(m.id).then(data => {
|
let p = worker.model_analyze(m.id).then(data => {
|
||||||
console.log({data});
|
// console.log({data});
|
||||||
|
});
|
||||||
|
promises.push(p);
|
||||||
|
}
|
||||||
|
Promise.all(promises).then(() => {
|
||||||
api.log.emit('analysis complete').unpin();
|
api.log.emit('analysis complete').unpin();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
repair() {
|
repair() {
|
||||||
|
let promises = [];
|
||||||
api.log.emit('repairing mesh(es)...').pin();
|
api.log.emit('repairing mesh(es)...').pin();
|
||||||
for (let m of selection.models()) {
|
for (let m of selection.models()) {
|
||||||
worker.model_heal(m.id).then(data => {
|
let p = worker.model_heal(m.id).then(data => {
|
||||||
if (data) {
|
if (data) {
|
||||||
m.reload(
|
m.reload(
|
||||||
data.vertices,
|
data.vertices,
|
||||||
|
|
@ -278,10 +309,13 @@ let tool = {
|
||||||
data.normals
|
data.normals
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
promises.push(p);
|
||||||
|
}
|
||||||
|
Promise.all(promises).then(() => {
|
||||||
api.log.emit('repair complete').unpin();
|
api.log.emit('repair complete').unpin();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// persisted preference map
|
// persisted preference map
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,10 @@ function ui_build() {
|
||||||
h.button({ _: 'gridlines', onclick() { api.grid() } }),
|
h.button({ _: 'gridlines', onclick() { api.grid() } }),
|
||||||
h.button({ _: 'wireframe', onclick() { api.wireframe() } }),
|
h.button({ _: 'wireframe', onclick() { api.wireframe() } }),
|
||||||
h.div({ class: "vsep" }),
|
h.div({ class: "vsep" }),
|
||||||
h.button({ _: 'analyze', disabled: true }),
|
h.button({ _: 'duplicate', onclick: api.selection.duplicate }),
|
||||||
|
h.button({ _: 'merge', onclick: api.selection.merge }),
|
||||||
|
h.div({ class: "vsep" }),
|
||||||
|
h.button({ _: 'analyze', onclick: api.tool.analyze }),
|
||||||
h.button({ _: 'repair', onclick: api.tool.repair }),
|
h.button({ _: 'repair', onclick: api.tool.repair }),
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -65,12 +65,18 @@ let model = {
|
||||||
duplicate(data) {
|
duplicate(data) {
|
||||||
let { id, matrix } = data;
|
let { id, matrix } = data;
|
||||||
return translate_encode(id, matrix);
|
return translate_encode(id, matrix);
|
||||||
throw "should not here";
|
},
|
||||||
let rec = cache[id];
|
|
||||||
let geo = rec.geo.clone();
|
// merge several model vertices into a single array
|
||||||
let m4 = core_matrix.clone().multiply( new THREE.Matrix4().fromArray(matrix) );
|
merge(recs) {
|
||||||
geo.applyMatrix4(m4);
|
let arrays = recs.map(rec => translate_encode(rec.id, rec.matrix));
|
||||||
return geo.attributes.position.array;
|
let length = arrays.map(a => a.length).reduce((v,a) => v + a);
|
||||||
|
let data = new Float32Array(length);
|
||||||
|
for (let i=0, l=arrays.length, p=0; i<l; ) {
|
||||||
|
data.set(arrays[i], p);
|
||||||
|
p += arrays[i++].length;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
analyze(id) {
|
analyze(id) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue