make surface selection a bit sharper, add radius value on face-only selection

This commit is contained in:
Stewart Allen 2022-04-01 10:21:02 -04:00
commit 2663a5ca5f
5 changed files with 28 additions and 14 deletions

View file

@ -428,13 +428,14 @@ function space_init(data) {
selection.update();
} else {
let { modes } = api;
let radians = 0;
let { surface } = api.prefs.map;
let opt = { radians: 0, radius: surface.radius };
switch(api.mode.get()) {
case modes.object:
selection.toggle(shiftKey ? model : model.group);
break;
case modes.surface:
radians = api.prefs.map.surface.radians;
opt.radians = surface.radians;
case modes.face:
case modes.line:
case modes.vertex:
@ -442,7 +443,7 @@ function space_init(data) {
model.find(int,
altKey ? { toggle: true } :
shiftKey ? { clear: true } : { select: true },
radians);
opt);
break;
}
}
@ -553,7 +554,13 @@ function set_normals_color(color) {
function set_surface_radians(radians) {
let { prefs } = mesh.api;
prefs.map.surface.radians = radians || 0.1;
prefs.map.surface.radians = parseFloat(radians || 0.1);
prefs.save();
}
function set_surface_radius(radius) {
let { prefs } = mesh.api;
prefs.map.surface.radius = parseFloat(radius || 0.2);
prefs.save();
}
@ -568,7 +575,8 @@ broker.listeners({
set_darkmode,
set_normals_color,
set_normals_length,
set_surface_radians
set_surface_radians,
set_surface_radius
});
// remove version cache bust from url

View file

@ -542,7 +542,8 @@ const prefs = {
color_dark: 0x00ffff
},
surface: {
radians: 0.1
radians: 0.1,
radius: 0.2
}
},

View file

@ -248,7 +248,7 @@ api.settings = function() {
h.label(''),
h.label('normals'),
h.label('length'),
h.input({ type: "text", size: 5, value: normals.length,
h.input({ type: "text", size: 5, value: parseFloat(normals.length),
onchange: ev => call.set_normals_length(ev.target.value)
}),
h.label('color'),
@ -262,11 +262,13 @@ api.settings = function() {
h.label(''),
h.label('surface'),
h.label('radians'),
h.input({ type: "text", size: 5, value: surface.radians,
h.input({ type: "text", size: 5, value: parseFloat(surface.radians),
onchange: ev => call.set_surface_radians(ev.target.value)
}),
h.label(' '),
h.label(' ')
h.label('radius'),
h.input({ type: "text", size: 5, value: parseFloat(surface.radius || 0.2),
onchange: ev => call.set_surface_radius(ev.target.value)
}),
]);
modal.show('settings', h.div({ class: "settings" }, [ col1, col2, col3 ] ));

View file

@ -588,7 +588,8 @@ mesh.model = class MeshModel extends mesh.object {
}
// find adjacent faces to clicked point/line on a face
find(int, action, radians = 0) {
find(int, action, opt) {
let { radians, radius } = opt;
let { point, face } = int;
let { x, y, z } = point;
let { a, b, c } = face;
@ -597,7 +598,7 @@ mesh.model = class MeshModel extends mesh.object {
mesh.api.log.emit("matching surface").pin();
}, 150);
worker.model_select({
id: this.id, x, y:-z, z:y, a, b, c, matrix: this.matrix, radians
id: this.id, x, y:-z, z:y, a, b, c, matrix: this.matrix, radians, radius
}).then(data => {
if (timer) {
clearTimeout(timer);

View file

@ -282,7 +282,7 @@ let model = {
// given model and point, locate matching vertices, lines, and faces
select(data) {
let { id, x, y, z, a, b, c, matrix, radians } = data;
let { id, x, y, z, a, b, c, matrix, radians, radius } = data;
// translate point into mesh matrix space
let v3 = new Vector3(x,y,z).applyMatrix4(
core_matrix.clone().multiply(new Matrix4().fromArray(matrix)).invert()
@ -291,11 +291,12 @@ let model = {
const rec = cache[id];
const arr = rec.geo.attributes.position.array;
// distance tolerance for click to vertex (rough distance)
const eps = 0.25;
const eps = radius || 0.2;
const faces = [];
const verts = [];
const edges = [];
let point;
if (!radians)
for (let i=0, l=arr.length; i<l; ) {
// matches here are within radius of a vertex
// select all faces that share a matched vertex
@ -323,6 +324,7 @@ let model = {
if (faces.length === 0) {
faces.push(Math.min(a,b,c) / 3);
}
// if the geometry has indexed faces and radians are set, find surface
const tool = rec.tool;
if (tool && tool.sides && radians) {
tool.findConnectedSurface(faces, radians);