background healing in the worker

This commit is contained in:
Stewart Allen 2021-09-08 11:04:57 -04:00
commit 3d9564c1d0
4 changed files with 36 additions and 19 deletions

View file

@ -126,6 +126,12 @@ KIRI.work = {
}); });
}, },
heal: function(vertices, callback) {
send("heal", {vertices}, function(output) {
callback(output);
});
},
config: function(obj) { config: function(obj) {
send("config", obj, function(reply) { }); send("config", obj, function(reply) { });
}, },

View file

@ -858,23 +858,20 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
let widgets = API.widgets.all(); let widgets = API.widgets.all();
let marker; let marker;
if (widgets.length) { if (widgets.length) {
marker = API.show.alert("Analyzing objects"); marker = API.show.alert("Analyzing objects", 100000);
} else { } else {
return; return;
} }
setTimeout(() => { setTimeout(() => {
let healed = 0; Promise.all(widgets.map(w => w.heal())).then(mod => {
for (let w of widgets) { API.hide.alert(marker);
if (w.heal()) { let healed = mod.map(m => m).length;
healed++; if (healed) {
API.show.alert(`${healed} Object${healed ? 's':''} healed`);
} else {
API.show.alert('Nothing found to heal');
} }
} });
API.hide.alert(marker);
if (healed) {
API.show.alert(`${healed} Object${healed ? 's':''} healed`);
} else {
API.show.alert('Nothing found to heal');
}
}, 1); }, 1);
} }

View file

@ -307,9 +307,8 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
}; };
PRO.heal = function(debug) { PRO.heal = function(debug) {
let mesh = this.debugMesh();
mesh.heal();
if (debug) { if (debug) {
let mesh = this.debugMesh().heal();
let verts = mesh.vertices; let verts = mesh.vertices;
let edges = mesh.edges; let edges = mesh.edges;
let split = mesh.edges.filter(l => l.split); let split = mesh.edges.filter(l => l.split);
@ -342,11 +341,15 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
stack.addLayers(layrz); stack.addLayers(layrz);
return { mesh, layrz, stack }; return { mesh, layrz, stack };
} }
if (mesh.newFaces) { return new Promise((resolve, reject) => {
this.loadVertices(mesh.unrolled().toFloat32()); KIRI.client.heal(this.getVertices().array, data => {
return this.modified = true; if (data.vertices) {
} this.loadVertices(data.vertices);
return false; this.modified = true;
}
resolve(this.modified);
});
});
}; };
PRO.debugMesh = function(precision) { PRO.debugMesh = function(precision) {

View file

@ -202,6 +202,17 @@ KIRI.worker = {
send.done(vertices); send.done(vertices);
}, },
heal: function(data, send) {
let { vertices } = data;
let mesh = new base.Mesh({vertices}).heal();
if (mesh.newFaces) {
vertices = mesh.unrolled().toFloat32();
send.done({vertices}, [vertices]);
} else {
send.done({});
}
},
snap: function(data, send) { snap: function(data, send) {
current.snap = data; current.snap = data;
send.done(); send.done();