use fat lines for trace selection and rendering. fix trace offset when toggling in/out to none
This commit is contained in:
parent
9731f910f9
commit
e3f1c9c52e
4 changed files with 31 additions and 13 deletions
|
|
@ -1005,7 +1005,7 @@ CAM.init = function(kiri, api) {
|
||||||
widget.traces.forEach(poly => {
|
widget.traces.forEach(poly => {
|
||||||
let match = areas.filter(arr => poly.matches(arr));
|
let match = areas.filter(arr => poly.matches(arr));
|
||||||
let layers = new kiri.Layers();
|
let layers = new kiri.Layers();
|
||||||
layers.setLayer("trace", {line: 0xaaaa55}, false).addPoly(poly);
|
layers.setLayer("trace", {line: 0xaaaa55, fat:4, order:-10}, false).addPoly(poly);
|
||||||
stack.addLayers(layers);
|
stack.addLayers(layers);
|
||||||
stack.new_meshes.forEach(mesh => {
|
stack.new_meshes.forEach(mesh => {
|
||||||
mesh.trace = {widget, poly};
|
mesh.trace = {widget, poly};
|
||||||
|
|
@ -1070,7 +1070,7 @@ CAM.init = function(kiri, api) {
|
||||||
});
|
});
|
||||||
func.traceHover = function(data) {
|
func.traceHover = function(data) {
|
||||||
if (lastTrace) {
|
if (lastTrace) {
|
||||||
let { color, colorSave } = lastTrace.material[0];
|
let { color, colorSave } = lastTrace.material[0] || lastTrace.material;
|
||||||
color.r = colorSave.r;
|
color.r = colorSave.r;
|
||||||
color.g = colorSave.g;
|
color.g = colorSave.g;
|
||||||
color.b = colorSave.b;
|
color.b = colorSave.b;
|
||||||
|
|
@ -1091,7 +1091,7 @@ CAM.init = function(kiri, api) {
|
||||||
let { clientX, clientY } = event;
|
let { clientX, clientY } = event;
|
||||||
let { offsetWidth, offsetHeight } = target;
|
let { offsetWidth, offsetHeight } = target;
|
||||||
}
|
}
|
||||||
let material = lastTrace.material[0];
|
let material = lastTrace.material[0] || lastTrace.material;
|
||||||
let color = material.color;
|
let color = material.color;
|
||||||
let {r, g, b} = color;
|
let {r, g, b} = color;
|
||||||
material.colorSave = {r, g, b};
|
material.colorSave = {r, g, b};
|
||||||
|
|
@ -1114,7 +1114,7 @@ CAM.init = function(kiri, api) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
func.traceToggle = function(obj, skip) {
|
func.traceToggle = function(obj, skip) {
|
||||||
let material = obj.material[0];
|
let material = obj.material[0] || obj.material;
|
||||||
if (!material) return;
|
if (!material) return;
|
||||||
let { color, colorSave } = material;
|
let { color, colorSave } = material;
|
||||||
let { widget, poly } = obj.trace;
|
let { widget, poly } = obj.trace;
|
||||||
|
|
|
||||||
|
|
@ -1089,7 +1089,7 @@ class OpTrace extends CamOp {
|
||||||
routed.push(poly);
|
routed.push(poly);
|
||||||
});
|
});
|
||||||
for (let poly of POLY.nest(routed)) {
|
for (let poly of POLY.nest(routed)) {
|
||||||
let offdist = offover;
|
let offdist = offset !== 'none' ? offover : 0;
|
||||||
if (!offdist)
|
if (!offdist)
|
||||||
switch (offset) {
|
switch (offset) {
|
||||||
case "outside": offdist = traceOffset; break;
|
case "outside": offdist = traceOffset; break;
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ class Layers {
|
||||||
rotation: this.rotation,
|
rotation: this.rotation,
|
||||||
position: this.position,
|
position: this.position,
|
||||||
off: off === true,
|
off: off === true,
|
||||||
lines: [],
|
lines: [], // basic line segments
|
||||||
polys: [], // colors are an attribute on polygons
|
polys: [], // colors are an attribute on polygons
|
||||||
faces: [], // triangles for areas and flats
|
faces: [], // triangles for areas and flats
|
||||||
norms: undefined, // flats vertex normals
|
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)
|
paths: undefined, // 3d extrusion / tube paths (used to be an array, now merged - FIX)
|
||||||
cpath: undefined, // path colors indices
|
cpath: undefined, // path colors indices
|
||||||
color: colors || {
|
color: colors || {
|
||||||
check: 0, // unused?
|
fat: 0, // render polys & lines with thickness
|
||||||
line: 0,
|
line: 0,
|
||||||
face: 0,
|
face: 0,
|
||||||
opacity: 1
|
opacity: 1
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ class Stack {
|
||||||
|
|
||||||
const { polys, lines, faces, cface, paths, cpath } = layer;
|
const { polys, lines, faces, cface, paths, cpath } = layer;
|
||||||
const { color, off, norms, rotation, position } = layer;
|
const { color, off, norms, rotation, position } = layer;
|
||||||
const { opacity } = color;
|
const { fat, order, opacity } = color;
|
||||||
const meshes = [];
|
const meshes = [];
|
||||||
const defstate = !off;
|
const defstate = !off;
|
||||||
const mats = [];
|
const mats = [];
|
||||||
|
|
@ -118,7 +118,7 @@ class Stack {
|
||||||
const vert = []; // vertexes
|
const vert = []; // vertexes
|
||||||
const mat = []; // materials
|
const mat = []; // materials
|
||||||
const grp = []; // material groups
|
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
|
// map all the poly and line colors for re-use
|
||||||
const cmap = {}
|
const cmap = {}
|
||||||
let cidx = 0;
|
let cidx = 0;
|
||||||
|
|
@ -129,7 +129,10 @@ class Stack {
|
||||||
addPoly(vert, poly);
|
addPoly(vert, poly);
|
||||||
const pc = poly.color !== undefined ? { line: poly.color, opacity } : color;
|
const pc = poly.color !== undefined ? { line: poly.color, opacity } : color;
|
||||||
const pk = pc.line;
|
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 (last !== pk) {
|
||||||
if (grp.length) {
|
if (grp.length) {
|
||||||
// rewrite counts for last group
|
// rewrite counts for last group
|
||||||
|
|
@ -154,10 +157,19 @@ class Stack {
|
||||||
const g = grp[i];
|
const g = grp[i];
|
||||||
geo.addGroup(g[0], g[1], g[2]);
|
geo.addGroup(g[0], g[1], g[2]);
|
||||||
}
|
}
|
||||||
geo.setFromPoints(vert);
|
if (fat) {
|
||||||
const segs = new THREE.LineSegments(geo, mat);
|
// 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 (rotation) segs.rotation.set(rotation.x, rotation.y, rotation.z);
|
||||||
if (position) segs.position.set(position.x, position.y, position.z);
|
if (position) segs.position.set(position.x, position.y, position.z);
|
||||||
|
if (order !== undefined) segs.renderOrder = order;
|
||||||
meshes.push(segs);
|
meshes.push(segs);
|
||||||
group.add(segs);
|
group.add(segs);
|
||||||
mats.appendAll(mat);
|
mats.appendAll(mat);
|
||||||
|
|
@ -244,7 +256,13 @@ let shininess = 15,
|
||||||
|
|
||||||
function createLineMaterial(color, array) {
|
function createLineMaterial(color, array) {
|
||||||
const opacity = color.lopacity || color.opacity || 1;
|
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,
|
transparent: true,
|
||||||
opacity: opacity,
|
opacity: opacity,
|
||||||
color: color.line
|
color: color.line
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue