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

View file

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

View file

@ -248,7 +248,7 @@ api.settings = function() {
h.label(''), h.label(''),
h.label('normals'), h.label('normals'),
h.label('length'), 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) onchange: ev => call.set_normals_length(ev.target.value)
}), }),
h.label('color'), h.label('color'),
@ -262,11 +262,13 @@ api.settings = function() {
h.label(''), h.label(''),
h.label('surface'), h.label('surface'),
h.label('radians'), 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) onchange: ev => call.set_surface_radians(ev.target.value)
}), }),
h.label(' '), h.label('radius'),
h.label(' ') 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 ] )); 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 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 { point, face } = int;
let { x, y, z } = point; let { x, y, z } = point;
let { a, b, c } = face; let { a, b, c } = face;
@ -597,7 +598,7 @@ mesh.model = class MeshModel extends mesh.object {
mesh.api.log.emit("matching surface").pin(); mesh.api.log.emit("matching surface").pin();
}, 150); }, 150);
worker.model_select({ 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 => { }).then(data => {
if (timer) { if (timer) {
clearTimeout(timer); clearTimeout(timer);

View file

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