workaround bug in threejs with non-transparent lines and material groups in a shared mesh
This commit is contained in:
parent
ad054e4b84
commit
14772b5d22
2 changed files with 22 additions and 17 deletions
17
notes.md
17
notes.md
|
|
@ -1,11 +1,16 @@
|
||||||
# Kiri:Moto todo
|
# Kiri:Moto todo
|
||||||
|
|
||||||
NEXT
|
## 2.3 remaining
|
||||||
- contour tabs support
|
* contour tabs support
|
||||||
- cap path ends
|
* path arrows, retracts, and engages
|
||||||
- path arrows, retracts, and engages
|
* cap path ends
|
||||||
- help dialog
|
* help dialog
|
||||||
- full bug reports
|
* full bug reports
|
||||||
|
|
||||||
|
## 2.4
|
||||||
|
* cnc: tracing, visualization, manual tabs
|
||||||
|
* fdm: manual supports, continuous printing
|
||||||
|
* all: 2d image to 3d part
|
||||||
|
|
||||||
## `C` cosmetic, `F` functional, `P` performance, `B` bug fix
|
## `C` cosmetic, `F` functional, `P` performance, `B` bug fix
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@
|
||||||
add: function(layer) {
|
add: function(layer) {
|
||||||
const nuview = stack.view.newGroup();
|
const nuview = stack.view.newGroup();
|
||||||
stack.layers.push(nuview);
|
stack.layers.push(nuview);
|
||||||
render(layer, nuview);
|
render(layer, nuview, name);
|
||||||
tallest = Math.max(tallest, stack.layers.length);
|
tallest = Math.max(tallest, stack.layers.length);
|
||||||
},
|
},
|
||||||
clear: function() {
|
clear: function() {
|
||||||
|
|
@ -78,7 +78,7 @@
|
||||||
max = newMax;
|
max = newMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
function render(render, group) {
|
function render(render, group, name) {
|
||||||
function addPoly(vertices, poly) {
|
function addPoly(vertices, poly) {
|
||||||
const points = poly.points, len = points.length;
|
const points = poly.points, len = points.length;
|
||||||
for (let i=1; i<len; i++) {
|
for (let i=1; i<len; i++) {
|
||||||
|
|
@ -109,14 +109,14 @@
|
||||||
|
|
||||||
ctrl.toggle.checked = defstate;
|
ctrl.toggle.checked = defstate;
|
||||||
|
|
||||||
const { polys, cpoly, lines, faces, cface, paths, cpath } = data;
|
const { polys, lines, faces, cface, paths, cpath } = data;
|
||||||
if (polys.length || lines.length) {
|
if (polys.length || lines.length) {
|
||||||
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 = 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;
|
||||||
let last = undefined;
|
let last = undefined;
|
||||||
for (let i=0, il=polys.length; i<il; i++) {
|
for (let i=0, il=polys.length; i<il; i++) {
|
||||||
|
|
@ -125,10 +125,8 @@
|
||||||
addPoly(vert, poly);
|
addPoly(vert, poly);
|
||||||
const pc = poly.color !== undefined ? { line: poly.color, opacity: data.color.opacity } : data.color;
|
const pc = poly.color !== undefined ? { line: poly.color, opacity: data.color.opacity } : data.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) };
|
||||||
const cc = { idx: cidx++, mat: createLineMaterial(pc, mat) };
|
if (last !== pk) {
|
||||||
// does not appear you can re-use material indices out of order
|
|
||||||
if (true || last !== pk) {
|
|
||||||
if (grp.length) {
|
if (grp.length) {
|
||||||
// rewrite counts for last group
|
// rewrite counts for last group
|
||||||
const prev = grp[grp.length - 1]
|
const prev = grp[grp.length - 1]
|
||||||
|
|
@ -154,7 +152,8 @@
|
||||||
geo.addGroup(g[0], g[1], g[2]);
|
geo.addGroup(g[0], g[1], g[2]);
|
||||||
}
|
}
|
||||||
geo.setFromPoints(vert);
|
geo.setFromPoints(vert);
|
||||||
group.add(new THREE.LineSegments(geo, mat));
|
const segs = new THREE.LineSegments(geo, mat);
|
||||||
|
group.add(segs);
|
||||||
ctrl.group.appendAll(mat);
|
ctrl.group.appendAll(mat);
|
||||||
}
|
}
|
||||||
if (faces.length) {
|
if (faces.length) {
|
||||||
|
|
@ -217,9 +216,10 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
function createLineMaterial(color, array) {
|
function createLineMaterial(color, array) {
|
||||||
|
const opacity = color.opacity || 1;
|
||||||
const mat = new THREE.LineBasicMaterial({
|
const mat = new THREE.LineBasicMaterial({
|
||||||
transparent: color.opacity != 1,
|
transparent: true,
|
||||||
opacity: color.opacity || 1,
|
opacity: opacity,
|
||||||
color: color.line
|
color: color.line
|
||||||
});
|
});
|
||||||
if (array) {
|
if (array) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue