improve object cleaning
This commit is contained in:
parent
08f67a0ea6
commit
8f8483058d
6 changed files with 37 additions and 39 deletions
|
|
@ -1097,7 +1097,6 @@ const tool = {
|
|||
let promises = [];
|
||||
let mcore = new Matrix4().makeRotationX(Math.PI / 2);
|
||||
for (let m of models) {
|
||||
// todo - translate vertices with source model's matrix
|
||||
let p = worker.model_analyze({ id: m.id, opt }).then(data => {
|
||||
let { areas, edges } = data.mapped;
|
||||
let nm = areas.map(area => new mesh.model({
|
||||
|
|
@ -1161,7 +1160,7 @@ const tool = {
|
|||
let p = worker.model_heal({
|
||||
id: m.id, opt
|
||||
}).then(data => {
|
||||
data?.length && m.reload(data.vertices);
|
||||
data?.vertices && m.reload(data.vertices);
|
||||
});
|
||||
promises.push(p);
|
||||
}
|
||||
|
|
@ -1181,7 +1180,12 @@ const tool = {
|
|||
|
||||
clean(models) {
|
||||
models = fallback(models);
|
||||
tool.heal(models, { merge: false }).then(() => {
|
||||
tool.heal(models, {
|
||||
merge: false,
|
||||
precision: 2,
|
||||
dedup: true,
|
||||
clean: true
|
||||
}).then(() => {
|
||||
log('cleaning complete').unpin();
|
||||
util.defer(selection.update);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -133,11 +133,12 @@ const log = api.log = {
|
|||
let { age, data, lines, render } = log;
|
||||
let now = Date.now();
|
||||
data.push({
|
||||
objs: [ dbug.since(), '|', ...arguments ],
|
||||
text: `${dbug.since()} | ${[...arguments].join(' ')}`,
|
||||
time: now
|
||||
});
|
||||
if (api.isDebug) {
|
||||
console.log(data.peek().text);
|
||||
console.log(...data.peek().objs);
|
||||
}
|
||||
while (!log.pinned && data.length && (data.length > lines || now - data[0].time > age)) {
|
||||
data.shift();
|
||||
|
|
|
|||
|
|
@ -90,12 +90,14 @@ let edges = {
|
|||
|
||||
async add() {
|
||||
if (selected.length === 2 && selected[0].object === selected[1].object) {
|
||||
let model = selected[0].object.model;
|
||||
let pos = new Vector3().fromArray(model.meta.pos);
|
||||
let verts = selected.map(s => [ s.side.p0, s.side.p1 ]).flat();
|
||||
// clean up floating point cruft for comparison
|
||||
for (let v of verts) {
|
||||
v.x = v.x.round(3);
|
||||
v.y = v.y.round(3);
|
||||
v.z = v.z.round(3);
|
||||
v.x = (v.x - pos.x).round(3);
|
||||
v.y = (v.y - pos.z).round(3);
|
||||
v.z = (v.z + pos.y).round(3);
|
||||
}
|
||||
// sort points so dups show up next to each other
|
||||
let sort = verts.sort((a,b) => {
|
||||
|
|
@ -112,7 +114,6 @@ let edges = {
|
|||
point.y !== arr[index - 1].y ||
|
||||
point.z !== arr[index - 1].z;
|
||||
});
|
||||
let model = selected[0].object.model;
|
||||
if (sort.length === 3) {
|
||||
await model.duplicate({ append: [
|
||||
sort[0].x, -sort[0].z, sort[0].y,
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@
|
|||
gapp.register("mesh.model", [], (root, exports) => {
|
||||
|
||||
const { MeshPhongMaterial, MeshBasicMaterial, LineBasicMaterial } = THREE;
|
||||
const { BufferGeometry, BufferAttribute, DoubleSide, Mesh} = THREE;
|
||||
const { Quaternion, Box3, Vector3 } = THREE;
|
||||
const { BufferGeometry, BufferAttribute, DoubleSide, Mesh, Vector3 } = THREE;
|
||||
const { mesh, moto } = root;
|
||||
const { space } = moto;
|
||||
const { api } = mesh;
|
||||
|
|
@ -132,21 +131,21 @@ mesh.model = class MeshModel extends mesh.object {
|
|||
return this.bounds.translate(this.position());
|
||||
}
|
||||
|
||||
get world_positions() {
|
||||
let pos = this.position();
|
||||
return this.geometry
|
||||
.clone()
|
||||
.translate(pos.x,pos.y,pos.z)
|
||||
.attributes.position.array;
|
||||
}
|
||||
// get world_positions() {
|
||||
// let pos = this.position();
|
||||
// return this.geometry
|
||||
// .clone()
|
||||
// .translate(pos.x,pos.y,pos.z)
|
||||
// .attributes.position.array;
|
||||
// }
|
||||
|
||||
get positions() {
|
||||
return this.geometry.attributes.position.array;
|
||||
}
|
||||
|
||||
get matrix() {
|
||||
return this.mesh.matrixWorld.elements;
|
||||
}
|
||||
// get matrix() {
|
||||
// return this.matrixWorld.elements;
|
||||
// }
|
||||
|
||||
get matrixWorld() {
|
||||
return this.mesh.matrixWorld;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
// use: mesh.util
|
||||
gapp.register("mesh.object", [], (root, exports) => {
|
||||
|
||||
const { Matrix4, Vector3, Box3, Box3Helper, Quaternion, Euler } = THREE;
|
||||
const { Matrix4, Vector3, Box3, Box3Helper, Quaternion } = THREE;
|
||||
const { mesh, moto } = root;
|
||||
const { space } = moto;
|
||||
|
||||
|
|
@ -27,14 +27,14 @@ mesh.object = class MeshObject {
|
|||
|
||||
constructor(id) {
|
||||
this.id = id || mesh.util.uuid();
|
||||
worker.object_create({id: this.id, type: this.type});
|
||||
this.log('NEW');
|
||||
worker.object_create({ id: this.id, type: this.type });
|
||||
// storage location for meta data like position, scale, rotation
|
||||
this.meta = {};
|
||||
this.meta = { pos: [0,0,0] };
|
||||
this.log('NEW');
|
||||
}
|
||||
|
||||
log() {
|
||||
// mesh.api.log.emit(this.id, this.type, ...arguments);
|
||||
mesh.api.log.emit(this.id, this.type, ...arguments);
|
||||
}
|
||||
|
||||
get type() {
|
||||
|
|
@ -63,7 +63,7 @@ mesh.object = class MeshObject {
|
|||
// used during state restoration
|
||||
applyMeta(meta = {}) {
|
||||
this.log('apply-meta', meta);
|
||||
this.applyMatrix(meta.matrix);
|
||||
if (meta.pos) this.position(...meta.pos);
|
||||
this.visible(meta.visible ?? true);
|
||||
this.metaChanged(meta);
|
||||
return this;
|
||||
|
|
@ -199,7 +199,7 @@ mesh.object = class MeshObject {
|
|||
this.updateBoundsBox();
|
||||
space.update();
|
||||
Object.assign(this.meta, values, {
|
||||
matrix: this.object.matrix.elements
|
||||
// matrix: this.object.matrix.elements
|
||||
});
|
||||
worker.object_meta({ id: this.id, meta: this.meta });
|
||||
publish.meta({ id: this.id, meta: this.meta });
|
||||
|
|
|
|||
|
|
@ -50,17 +50,11 @@ function cacheUpdate(id, data) {
|
|||
// translate original mesh vertices into UI world view (PI/2 rotation on X)
|
||||
function translate_encode(id) {
|
||||
let rec = cache[id];
|
||||
let { pos, matrix } = rec;
|
||||
let mkey = matrix.map(v => v.round(6)).join('-');
|
||||
let { pos } = rec;
|
||||
let mkey = pos.map(v => v.round(6)).join('-');
|
||||
// re-translate on missing cache or changed matrix
|
||||
if (!rec || !rec.trans || rec.mkey !== mkey) {
|
||||
let geo = rec.geo.clone();
|
||||
if (pos) {
|
||||
geo.translate(new Vector3().fromArray(pos));
|
||||
} else {
|
||||
let mat = core_matrix.clone().multiply(new Matrix4().fromArray(matrix));
|
||||
geo.applyMatrix4(mat);
|
||||
}
|
||||
let geo = rec.geo.clone().translate(new Vector3().fromArray(pos));
|
||||
rec.mkey = mkey;
|
||||
rec.trans = geo.attributes.position.array
|
||||
}
|
||||
|
|
@ -71,13 +65,13 @@ function analyze(id, opt = {}) {
|
|||
let rec = cache[id];
|
||||
let { geo, tool } = rec;
|
||||
if (!tool) {
|
||||
tool = rec.tool = new mesh.tool();
|
||||
tool = rec.tool = new mesh.tool(opt);
|
||||
}
|
||||
if (tool.faces) {
|
||||
log(`${id} | analysis cached`);
|
||||
} else {
|
||||
log(`${id} | analyzing...`);
|
||||
tool.generateFaces(geo.attributes.position.array);
|
||||
tool.generateFaces(geo.attributes.position.array, opt);
|
||||
log(`${id} | patching...`);
|
||||
tool.patch(opt);
|
||||
}
|
||||
|
|
@ -382,7 +376,6 @@ let object = {
|
|||
meta(data) {
|
||||
let { id, meta } = data;
|
||||
cacheUpdate(id, meta);
|
||||
console.log('object_meta', data);
|
||||
},
|
||||
|
||||
create(data) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue