add heal test

This commit is contained in:
Stewart Allen 2022-01-03 22:57:19 -05:00
commit c86c90d915
6 changed files with 46 additions and 10 deletions

View file

@ -67,10 +67,11 @@ function init() {
function restore_space() {
mesh.db.space.iterate({ map: true }).then(cached => {
let loaded = false;
for (let [id, data] of Object.entries(cached)) {
// restore group
if (Array.isArray(data)) {
let models = data.map(id => {
let models = loaded = data.map(id => {
let md = cached[id];
return new mesh.model(md, id);
});
@ -81,6 +82,10 @@ function restore_space() {
.focus();
}
}
if (loaded) {
let space = moto.Space;
space.view.load(space.preset.top);
}
})
}
@ -188,7 +193,15 @@ function space_init(data) {
space.view.home();
break;
case 'KeyF':
space.view.front();
for (let m of selection.models()) {
moto.client.fn.model_heal(m.id)
.then(data => {
if (data) {
m.wireframe(false);
m.reload(data.vertices.toFloat32());
}
});
}
break;
case 'KeyT':
space.view.top();

View file

@ -95,7 +95,6 @@ mesh.model = class MeshModel extends mesh.object {
geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
let meh = new THREE.Mesh(geo, materials.unselected);
geo.computeVertexNormals();
// geo.computeFaceNormals();
meh.receiveShadow = true;
meh.castShadow = true;
meh.renderOrder = 1;
@ -108,15 +107,13 @@ mesh.model = class MeshModel extends mesh.object {
reload(vertices, indices) {
let geo = this.mesh.geometry;
geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
geo.attributes.position.array = vertices;
geo.attributes.position.needsUpdate = true;
geo.setAttribute('normal', undefined);
if (indices) {
geo.setIndex(new THREE.BufferAttribute(indices, 1));
geo.attributes.index.needsUpdate = true;
}
geo.attributes.position.needsUpdate = true;
geo.computeVertexNormals();
// geo.computeFaceNormals();
worker.model_load({id: this.id, name: this.name, vertices, indices});
}

View file

@ -13,6 +13,7 @@ if (mesh.tool) return;
/** tool for identiying defects and healing them **/
mesh.tool = class MeshTool {
constructor(params = {}) {
this.debug = params.debug;
this.precision = Math.pow(10, params.precision || 6);
if (params.vertices) {
this.setData(params.vertices, params.faces);
@ -37,6 +38,7 @@ mesh.tool = class MeshTool {
if (vertices.length % 3 !== 0) {
throw "invalid vertices";
}
let TEST = this.debug;
// when face/index data is missing, vertices need to be normalized
if (!faces) {
if (TEST) console.time('generate faces');
@ -110,6 +112,7 @@ mesh.tool = class MeshTool {
* connect lines into polys. earcut polys into new faces.
*/
heal() {
let TEST = this.debug;
if (TEST) console.time('heal');
let vertices = this.vertices;

View file

@ -32,7 +32,6 @@ let model = {
let { vertices, name, id } = data;
let geo = new THREE.BufferGeometry();
geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
geo.computeVertexNormals();
cacheUpdate(id, { name, geo, matrix: core_matrix.clone() });
},
@ -44,6 +43,20 @@ let model = {
geo.applyMatrix4(m4);
// for debugging state / matrix ops
return geo.attributes.position.array;
},
heal(id) {
dbug.log({healing: id});
let tool = new mesh.tool({
vertices: cache[id].geo.attributes.position.array
});
dbug.log('...imported data');
tool.heal();
dbug.log('...healed');
dbug.log(tool);
return tool.newFaces ? {
vertices: tool.unrolled(),
} : 0;
}
};

View file

@ -71,11 +71,12 @@ let client = moto.client = {
let ondata, ondone, onerror = reject;
if (!stream) {
let accum = [];
let simple = options.simple !== false;
ondata = (data) => {
accum.push(data);
};
ondone = () => {
resolve(accum);
resolve(simple && accum.length === 1 ? accum[0] : accum);
};
} else {
ondata = stream;

View file

@ -1019,6 +1019,15 @@
get world() { throw "platform.world deprecated" }
},
preset: {
top: {left: home, up: 0, panX, panY, panZ},
back: {left: PI, up: PI2, panX, panY, panZ},
home: {left: home, up, panX, panY, panZ},
front: {left: 0, up: PI2, panX, panY, panZ},
right: {left: PI2, up: PI2, panX, panY, panZ},
left: {left: -PI2, up: PI2, panX, panY, panZ},
},
view: {
top: (then) => { tweenCam({left: home, up: 0, panX, panY, panZ, then}) },
back: (then) => { tweenCam({left: PI, up: PI2, panX, panY, panZ, then}) },
@ -1027,7 +1036,7 @@
right: (then) => { tweenCam({left: PI2, up: PI2, panX, panY, panZ, then}) },
left: (then) => { tweenCam({left: -PI2, up: PI2, panX, panY, panZ, then}) },
reset: () => { viewControl.reset(); requestRefresh() },
load: (cam) => { viewControl.setPosition(cam) },
load: (cam) => { viewControl.setPosition(cam); requestRefresh() },
save: () => { return viewControl.getPosition(true) },
panTo: (x,y,z) => { tweenCamPan(x,y,z) },
setZoom: (r,v) => { viewControl.setZoom(r,v) },