add heal test
This commit is contained in:
parent
f891caa99d
commit
c86c90d915
6 changed files with 46 additions and 10 deletions
|
|
@ -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});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue