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) {
|
||||
case 'KeyD':
|
||||
if (shiftKey) {
|
||||
for (let m of selection.models()) {
|
||||
m.duplicate();
|
||||
}
|
||||
return selection.duplicate();
|
||||
}
|
||||
break;
|
||||
case 'KeyC':
|
||||
return selection.centerXY().focus();
|
||||
case 'KeyF':
|
||||
return selection.floor().focus();
|
||||
case 'KeyM':
|
||||
return selection.merge();
|
||||
case 'KeyI':
|
||||
return api.file.import();
|
||||
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() {
|
||||
for (let group of groups) {
|
||||
group.material(mesh.material.unselected);
|
||||
|
|
@ -257,20 +268,40 @@ let file = {
|
|||
};
|
||||
|
||||
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() {
|
||||
let promises = [];
|
||||
api.log.emit('analyzing mesh(es)...').pin();
|
||||
for (let m of selection.models()) {
|
||||
worker.model_analyze(m.id).then(data => {
|
||||
console.log({data});
|
||||
api.log.emit('analysis complete').unpin();
|
||||
let p = worker.model_analyze(m.id).then(data => {
|
||||
// console.log({data});
|
||||
});
|
||||
promises.push(p);
|
||||
}
|
||||
Promise.all(promises).then(() => {
|
||||
api.log.emit('analysis complete').unpin();
|
||||
});
|
||||
},
|
||||
|
||||
repair() {
|
||||
let promises = [];
|
||||
api.log.emit('repairing mesh(es)...').pin();
|
||||
for (let m of selection.models()) {
|
||||
worker.model_heal(m.id).then(data => {
|
||||
let p = worker.model_heal(m.id).then(data => {
|
||||
if (data) {
|
||||
m.reload(
|
||||
data.vertices,
|
||||
|
|
@ -278,9 +309,12 @@ let tool = {
|
|||
data.normals
|
||||
);
|
||||
}
|
||||
api.log.emit('repair complete').unpin();
|
||||
});
|
||||
promises.push(p);
|
||||
}
|
||||
Promise.all(promises).then(() => {
|
||||
api.log.emit('repair complete').unpin();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -225,7 +225,10 @@ function ui_build() {
|
|||
h.button({ _: 'gridlines', onclick() { api.grid() } }),
|
||||
h.button({ _: 'wireframe', onclick() { api.wireframe() } }),
|
||||
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 }),
|
||||
]),
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -65,12 +65,18 @@ let model = {
|
|||
duplicate(data) {
|
||||
let { id, matrix } = data;
|
||||
return translate_encode(id, matrix);
|
||||
throw "should not here";
|
||||
let rec = cache[id];
|
||||
let geo = rec.geo.clone();
|
||||
let m4 = core_matrix.clone().multiply( new THREE.Matrix4().fromArray(matrix) );
|
||||
geo.applyMatrix4(m4);
|
||||
return geo.attributes.position.array;
|
||||
},
|
||||
|
||||
// merge several model vertices into a single array
|
||||
merge(recs) {
|
||||
let arrays = recs.map(rec => translate_encode(rec.id, rec.matrix));
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue