add raw vertex input in devel mode. stub in slice connect shadow test for performance over plain face union

This commit is contained in:
Stewart Allen 2022-05-03 09:02:09 -04:00
commit 9454eeb287
7 changed files with 55 additions and 10 deletions

View file

@ -828,7 +828,8 @@ function removeDuplicateLines(lines) {
gapp.overlay(base, {
slice,
sliceZ,
slicePost: {}
slicePost: {},
sliceConnect
});
});

View file

@ -6,12 +6,13 @@
// dep: geo.paths
// dep: geo.point
// dep: geo.polygons
// dep: geo.slicer
// dep: kiri.slice
// use: kiri-mode.cam.topo
gapp.register("kiri-mode.cam.ops", [], (root, exports) => {
const { base, kiri } = root;
const { paths, polygons, newPoint, newPolygon } = base;
const { paths, polygons, newPoint, newPolygon, sliceConnect } = base;
const { poly2polyEmit, tip2tipEmit } = paths;
const { driver, newSlice } = kiri;
const { CAM } = driver;
@ -1383,6 +1384,7 @@ CAM.shadowAt = function(widget, z, ztop) {
const n = THREE.computeFaceNormal(a,b,c);
if (n.z > 0.001) {
faces.push(a,b,c);
// faces.push(newPoint(...a), newPoint(...b), newPoint(...c));
}
}
widget._shadow_faces = faces;
@ -1415,9 +1417,7 @@ CAM.shadowAt = function(widget, z, ztop) {
let line = intersectPoints(where.over, where.under, z);
if (line.length === 2) {
if (where.over.length === 2) {
found.push([where.over[0], line[0], line[1]]);
found.push([where.over[1], line[0], line[1]]);
found.push([where.over[0], where.over[1], line[1]]);
found.push([where.over[0], where.over[1], line[0]]);
} else {
found.push([where.over[0], line[0], line[1]]);
@ -1428,13 +1428,35 @@ CAM.shadowAt = function(widget, z, ztop) {
}
}
}
// const lines = {};
// function addline(p1, p2) {
// let key = p1.key < p2.key ? p1.key + ',' + p2.key : p2.key + ',' + p1.key;
// let rec = lines[key];
// if (rec) {
// rec.count++;
// } else {
// lines[key] = { p1, p2, count: 1 };
// }
// }
// for (let face of found) {
// addline(face[0], face[1]);
// addline(face[1], face[2]);
// addline(face[2], face[0]);
// }
// const singles = Object.entries(lines).filter(a => a[1].count === 1).map(a => a[1]);
// const loops = POLY.nest(sliceConnect(singles, z));
let polys = found.map(a => {
return newPolygon()
.add(a[0].x,a[0].y,a[0].z)
.add(a[1].x,a[1].y,a[1].z)
.add(a[2].x,a[2].y,a[2].z);
});
return POLY.union(polys, 0.0001, true);
polys = POLY.union(polys, 0.001, true);
// console.log({z, loops, polys});
// return loops;
return polys;
};
CAM.OPS = CamOp.MAP = {

View file

@ -129,7 +129,7 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
// const merge = shadow.length;
// const plus = shadows[minZabove].length;
// const mark = Date.now();
shadow = POLY.union([...shadow, ...shadows[minZabove]], 0.0011, true);
shadow = POLY.union([...shadow, ...shadows[minZabove]], 0.001, true);
// console.log({merge, plus, equals: shadow.length, time: Date.now() - mark});
}
return shadows[z] = POLY.setZ(shadow, z);

View file

@ -264,6 +264,23 @@ let model = {
};
let add = {
input() {
api.modal.dialog({
title: "vertices",
body: [ h.div({ class: "addact" }, [
h.textarea({ value: '', size: 5, id: "genvrt" }),
h.button({ _: "create", onclick() {
const vert = (api.modal.bound.genvrt.value)
.split(',').map(v => parseFloat(v)).toFloat32();
const nmdl = new mesh.model({ file: "input", mesh: vert });
const ngrp = group.new([ nmdl ]);
api.modal.hide();
} })
]) ]
});
api.modal.bound.genvrt.focus();
},
cube() {
const box = new THREE.BoxGeometry(1,1,1).toNonIndexed();
const vert = box.attributes.position.array;
@ -290,7 +307,7 @@ let add = {
} else {
api.modal.dialog({
title: "cylinder",
body: [ h.div({ class: "cylinder" }, [
body: [ h.div({ class: "addact" }, [
h.label('facets'),
h.input({ value: opt.facets || 30, size: 5, id: "gencyl" }),
h.button({ _: "create", onclick() {

View file

@ -10,6 +10,7 @@ gapp.register("mesh.build", [], (root, exports) => {
const { broker } = gapp;
const { mesh } = root;
const { api, util } = mesh;
const devel = api.isDebug;
let call = broker.send;
let rad = 180 / Math.PI;
@ -372,6 +373,7 @@ function ui_build() {
h.div({ class: "pop"}, [
h.button({ _: 'cylinder', onclick: add.cylinder }),
h.button({ _: 'cube', onclick: add.cube }),
devel ? h.button({ _: 'input', onclick: add.input }) : undefined
])
]),
h.div([

View file

@ -9,6 +9,9 @@ gapp.register("moto.webui", [], (root, exports) => {
let nextid = 1;
function build(data, context) {
if (!data) {
return [];
}
if (Array.isArray(data)) {
let html = [];
for (let d of data) {
@ -126,7 +129,7 @@ gapp.overlay(root, {
});
// add common element types
["a", "i", "hr", "div", "span", "label", "input", "button", "svg"].forEach(type => {
["a", "i", "hr", "div", "span", "label", "input", "button", "svg", "textarea"].forEach(type => {
h[type] = (attr, innr) => {
return h.el(type, attr, innr);
}

View file

@ -221,11 +221,11 @@ button:hover {
padding: 4px;
}
.cylinder {
.addact {
gap: 4px;
}
.cylinder input {
.addact input {
text-align: center;
}