use fat lines for trace selection and rendering. fix trace offset when toggling in/out to none

This commit is contained in:
Stewart Allen 2024-08-16 22:44:07 -04:00
commit e3f1c9c52e
4 changed files with 31 additions and 13 deletions

View file

@ -64,7 +64,7 @@ class Layers {
rotation: this.rotation,
position: this.position,
off: off === true,
lines: [],
lines: [], // basic line segments
polys: [], // colors are an attribute on polygons
faces: [], // triangles for areas and flats
norms: undefined, // flats vertex normals
@ -72,7 +72,7 @@ class Layers {
paths: undefined, // 3d extrusion / tube paths (used to be an array, now merged - FIX)
cpath: undefined, // path colors indices
color: colors || {
check: 0, // unused?
fat: 0, // render polys & lines with thickness
line: 0,
face: 0,
opacity: 1

View file

@ -108,7 +108,7 @@ class Stack {
const { polys, lines, faces, cface, paths, cpath } = layer;
const { color, off, norms, rotation, position } = layer;
const { opacity } = color;
const { fat, order, opacity } = color;
const meshes = [];
const defstate = !off;
const mats = [];
@ -118,7 +118,7 @@ class Stack {
const vert = []; // vertexes
const mat = []; // materials
const grp = []; // material groups
const geo = new THREE.BufferGeometry();
const geo = fat ? new THREE.LineSegmentsGeometry() : new THREE.BufferGeometry();
// map all the poly and line colors for re-use
const cmap = {}
let cidx = 0;
@ -129,7 +129,10 @@ class Stack {
addPoly(vert, poly);
const pc = poly.color !== undefined ? { line: poly.color, opacity } : color;
const pk = pc.line;
const cc = cmap[pk] = cmap[pk] || { idx: cidx++, mat: createLineMaterial(pc, mat) };
const cc = cmap[pk] = cmap[pk] || {
idx: cidx++,
mat: createLineMaterial(pc, mat)
};
if (last !== pk) {
if (grp.length) {
// rewrite counts for last group
@ -154,10 +157,19 @@ class Stack {
const g = grp[i];
geo.addGroup(g[0], g[1], g[2]);
}
geo.setFromPoints(vert);
const segs = new THREE.LineSegments(geo, mat);
if (fat) {
// LineSegmentsGeometry does not support setFromPoints()
geo.setPositions(vert.map(v => v.toArray()).flat());
} else {
geo.setFromPoints(vert);
}
// LineSegments2 does not support multiple materials
const segs = fat ?
new THREE.LineSegments2(geo, mat[0]) :
new THREE.LineSegments(geo, mat);
if (rotation) segs.rotation.set(rotation.x, rotation.y, rotation.z);
if (position) segs.position.set(position.x, position.y, position.z);
if (order !== undefined) segs.renderOrder = order;
meshes.push(segs);
group.add(segs);
mats.appendAll(mat);
@ -244,7 +256,13 @@ let shininess = 15,
function createLineMaterial(color, array) {
const opacity = color.lopacity || color.opacity || 1;
const mat = new THREE.LineBasicMaterial({
const mat = color.fat ? new THREE.LineMaterial({
// transparent: true,
// opacity: opacity,
color: color.line,
linewidth: color.fat,
alphaToCoverage: false
}) : new THREE.LineBasicMaterial({
transparent: true,
opacity: opacity,
color: color.line