line colors
This commit is contained in:
parent
1d573b1605
commit
1fb35761c4
3 changed files with 55 additions and 33 deletions
|
|
@ -83,6 +83,7 @@
|
||||||
if (options.z !== undefined) p.setZ(options.z);
|
if (options.z !== undefined) p.setZ(options.z);
|
||||||
if (options.color) p.color = options.color;
|
if (options.color) p.color = options.color;
|
||||||
});
|
});
|
||||||
|
// if (options.color) console.log({polys, options})
|
||||||
}
|
}
|
||||||
this.current.polys.appendAll(polys);
|
this.current.polys.appendAll(polys);
|
||||||
this.stats.line_poly += polys.length;
|
this.stats.line_poly += polys.length;
|
||||||
|
|
|
||||||
|
|
@ -111,35 +111,52 @@
|
||||||
|
|
||||||
const { polys, cpoly, lines, faces, paths, cpath } = data;
|
const { polys, cpoly, lines, faces, paths, cpath } = data;
|
||||||
if (polys.length || lines.length) {
|
if (polys.length || lines.length) {
|
||||||
const mat = [];
|
const vert = []; // vertexes
|
||||||
if (cpoly) {
|
const mat = []; // materials
|
||||||
cpoly.forEach(c => { mat.push(createLineMaterial({ color: c })) });
|
const grp = []; // material groups
|
||||||
} else {
|
|
||||||
mat.push(createLineMaterial(data));
|
|
||||||
}
|
|
||||||
mat.forEach(m => m.visible = defstate);
|
|
||||||
const geo = new THREE.BufferGeometry();
|
const geo = new THREE.BufferGeometry();
|
||||||
const vert = [];
|
// map all the poly and line colors
|
||||||
|
const cmap = {}
|
||||||
|
let cidx = 0;
|
||||||
|
let last = undefined;
|
||||||
for (let i=0, il=polys.length; i<il; i++) {
|
for (let i=0, il=polys.length; i<il; i++) {
|
||||||
addPoly(vert, polys[i]);
|
const vl = vert.length;
|
||||||
|
const poly = polys[i];
|
||||||
|
addPoly(vert, poly);
|
||||||
|
const pc = poly.color ? { line: poly.color, opacity: data.color.opacity } : data.color;
|
||||||
|
const pk = pc.line;
|
||||||
|
cmap[pk] = cmap[pk] || { idx: cidx++, mat: createLineMaterial(pc, mat) };
|
||||||
|
if (last !== pk) {
|
||||||
|
if (grp.length) {
|
||||||
|
// rewrite counts for last group
|
||||||
|
const prev = grp[grp.length - 1]
|
||||||
|
prev[1] = prev[1] - vl;
|
||||||
|
}
|
||||||
|
grp.push([vl, Infinity, cidx - 1]);
|
||||||
|
last = pk;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// for now, line segments inherit the last color
|
||||||
for (let i=0, il=lines.length; i<il; i++) {
|
for (let i=0, il=lines.length; i<il; i++) {
|
||||||
const p = lines[i];
|
const p = lines[i];
|
||||||
vert.push(new THREE.Vector3(p.x, p.y, p.z));
|
vert.push(new THREE.Vector3(p.x, p.y, p.z));
|
||||||
}
|
}
|
||||||
if (vert.length) {
|
// ensure at least one group using the default color settings
|
||||||
if (cpoly) {
|
if (grp.length === 0) {
|
||||||
cpoly.forEach((c, i) => geo.addGroup(c.start, c.count, i));
|
grp.push([0, Infinity, 0]);
|
||||||
} else {
|
mat.push(createLineMaterial(data.color));
|
||||||
geo.addGroup(0, Infinity, 0);
|
|
||||||
}
|
|
||||||
group.add(new THREE.LineSegments(geo, mat));
|
|
||||||
}
|
}
|
||||||
|
mat.forEach(m => m.visible = defstate);
|
||||||
|
for (let i=0; i<grp.length; i++) {
|
||||||
|
const g = grp[i];
|
||||||
|
geo.addGroup(g[0], g[1], g[2]);
|
||||||
|
}
|
||||||
|
group.add(new THREE.LineSegments(geo, mat));
|
||||||
geo.setFromPoints(vert);
|
geo.setFromPoints(vert);
|
||||||
ctrl.group.appendAll(mat);
|
ctrl.group.appendAll(mat);
|
||||||
}
|
}
|
||||||
if (faces.length) {
|
if (faces.length) {
|
||||||
const mat = newMat(data);
|
const mat = newMat(data.color);
|
||||||
const geo = new THREE.BufferGeometry();
|
const geo = new THREE.BufferGeometry();
|
||||||
geo.setAttribute('position', new THREE.BufferAttribute(faces, 3));
|
geo.setAttribute('position', new THREE.BufferAttribute(faces, 3));
|
||||||
geo.computeFaceNormals();
|
geo.computeFaceNormals();
|
||||||
|
|
@ -154,9 +171,9 @@
|
||||||
if (paths.length) {
|
if (paths.length) {
|
||||||
const mat = [];
|
const mat = [];
|
||||||
if (cpath) {
|
if (cpath) {
|
||||||
cpath.forEach(c => { mat.push(newMat({ color: c })) });
|
cpath.forEach(c => { mat.push(newMat(c)) });
|
||||||
} else {
|
} else {
|
||||||
mat.push(newMat(data));
|
mat.push(newMat(data.color));
|
||||||
}
|
}
|
||||||
mat.forEach(m => m.visible = defstate);
|
mat.forEach(m => m.visible = defstate);
|
||||||
// const mat = newMat(data);
|
// const mat = newMat(data);
|
||||||
|
|
@ -183,33 +200,37 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function createLineMaterial(data) {
|
function createLineMaterial(color, array) {
|
||||||
return new THREE.LineBasicMaterial({
|
const mat = new THREE.LineBasicMaterial({
|
||||||
transparent: data.color.opacity != 1,
|
transparent: color.opacity != 1,
|
||||||
opacity: data.color.opacity || 1,
|
opacity: color.opacity || 1,
|
||||||
color: data.color.line
|
color: color.line
|
||||||
});
|
});
|
||||||
|
if (array) {
|
||||||
|
array.push(mat);
|
||||||
|
}
|
||||||
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createStandardMaterial(data) {
|
function createStandardMaterial(color) {
|
||||||
return new THREE.MeshStandardMaterial({
|
return new THREE.MeshStandardMaterial({
|
||||||
emissive,
|
emissive,
|
||||||
roughness,
|
roughness,
|
||||||
metalness,
|
metalness,
|
||||||
transparent: data.color.opacity != 1,
|
transparent: color.opacity != 1,
|
||||||
opacity: data.color.opacity || 1,
|
opacity: color.opacity || 1,
|
||||||
color: data.color.face,
|
color: color.face,
|
||||||
side: THREE.DoubleSide
|
side: THREE.DoubleSide
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createPhongMaterial(data) {
|
function createPhongMaterial(color) {
|
||||||
return new THREE.MeshPhongMaterial({
|
return new THREE.MeshPhongMaterial({
|
||||||
shininess,
|
shininess,
|
||||||
specular,
|
specular,
|
||||||
transparent: data.color.opacity != 1,
|
transparent: color.opacity != 1,
|
||||||
opacity: data.color.opacity || 1,
|
opacity: color.opacity || 1,
|
||||||
color: data.color.face,
|
color: color.face,
|
||||||
side: THREE.DoubleSide
|
side: THREE.DoubleSide
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -483,7 +483,7 @@
|
||||||
Object.values(prints).forEach(array => {
|
Object.values(prints).forEach(array => {
|
||||||
array.forEach(poly => { if (poly.length > 1) output
|
array.forEach(poly => { if (poly.length > 1) output
|
||||||
.setLayer(opts.action || 'print', printColor)
|
.setLayer(opts.action || 'print', printColor)
|
||||||
.addPolys([ poly ], thin ? { thin, z: opts.z } : {
|
.addPolys([ poly ], thin ? { thin, z: opts.z, color: poly.color } : {
|
||||||
offset: array.width, height, z: opts.z,
|
offset: array.width, height, z: opts.z,
|
||||||
color: { face: poly.color, line: poly.color }
|
color: { face: poly.color, line: poly.color }
|
||||||
})// & cn_len.put(poly.length) & cn_col.put(poly.color) & console.log(poly.points)
|
})// & cn_len.put(poly.length) & cn_col.put(poly.color) & console.log(poly.points)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue