checkpoint rendering refactor. still broken beyond slicing
This commit is contained in:
parent
64380b6ef6
commit
9a3cf79c8b
11 changed files with 1099 additions and 1228 deletions
|
|
@ -26,94 +26,13 @@
|
|||
});
|
||||
}
|
||||
|
||||
CAM.renderSlice = function(slice) {
|
||||
let group = new THREE.Group();
|
||||
let render = slice.render;
|
||||
let view = slice.view;
|
||||
|
||||
function addPoly(vertices, poly) {
|
||||
const points = poly.points, len = points.length;
|
||||
for (let i=1; i<len; i++) {
|
||||
const p1 = points[i-1], p2 = points[i];
|
||||
vertices.push(new THREE.Vector3(p1.x, p1.y, p1.z));
|
||||
vertices.push(new THREE.Vector3(p2.x, p2.y, p2.z));
|
||||
}
|
||||
if (!poly.open) {
|
||||
const p1 = points[len - 1], p2 = points[0];
|
||||
vertices.push(new THREE.Vector3(p1.x, p1.y, p1.z));
|
||||
vertices.push(new THREE.Vector3(p2.x, p2.y, p2.z));
|
||||
}
|
||||
}
|
||||
|
||||
for (const [layer, data] of Object.entries(render.layers)) {
|
||||
const { polys, lines, faces, paths } = data;
|
||||
if (polys.length || lines.length) {
|
||||
const mat = new THREE.LineBasicMaterial({ color: data.color.line });
|
||||
const geo = new THREE.Geometry(), vert = geo.vertices;
|
||||
for (let i=0, il=polys.length; i<il; i++) {
|
||||
addPoly(vert, polys[i]);
|
||||
}
|
||||
for (let i=0, il=lines.length; i<il; i++) {
|
||||
const p = lines[i];
|
||||
vert.push(new THREE.Vector3(p.x, p.y, p.z));
|
||||
}
|
||||
if (vert.length) {
|
||||
group.add(new THREE.LineSegments(geo, mat));
|
||||
}
|
||||
}
|
||||
if (faces.length) {
|
||||
const mat = new THREE.MeshPhongMaterial({
|
||||
transparent: true,
|
||||
shininess: 100,
|
||||
specular: 0x181818,
|
||||
opacity: 1,
|
||||
color: data.color.face,
|
||||
side: THREE.DoubleSide
|
||||
});
|
||||
const geo = new THREE.BufferGeometry();
|
||||
geo.setAttribute('position', new THREE.BufferAttribute(faces, 3));
|
||||
geo.computeFaceNormals();
|
||||
geo.computeVertexNormals();
|
||||
const mesh = new THREE.Mesh(geo, mat);
|
||||
mesh.castShadow = true;
|
||||
mesh.receiveShadow = true;
|
||||
group.add(mesh);
|
||||
}
|
||||
if (paths.length) {
|
||||
const mat = new THREE.MeshPhongMaterial({
|
||||
transparent: true,
|
||||
shininess: 100,
|
||||
specular: 0x181818,
|
||||
opacity: 1,
|
||||
color: data.color.face,
|
||||
side: THREE.DoubleSide
|
||||
});
|
||||
paths.forEach((path, i) => {
|
||||
const { index, faces, z } = path;
|
||||
const geo = new THREE.BufferGeometry();
|
||||
geo.setAttribute('position', new THREE.BufferAttribute(faces, 3));
|
||||
geo.setIndex(index);
|
||||
geo.computeFaceNormals();
|
||||
geo.computeVertexNormals();
|
||||
const mesh = new THREE.Mesh(geo, mat);
|
||||
mesh.position.z = z;
|
||||
mesh.castShadow = true;
|
||||
mesh.receiveShadow = true;
|
||||
group.add(mesh);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
slice.view.add(group);
|
||||
};
|
||||
|
||||
CAM.sliceRender = function(widget) {
|
||||
return KIRI.Layer.renderSetup().renderSlices(widget.slices);
|
||||
|
||||
let slices = widget.slices;
|
||||
if (!slices) return;
|
||||
|
||||
slices.forEach(function(slice) {
|
||||
if (slice.render) return CAM.renderSlice(slice);
|
||||
|
||||
let tops = slice.tops,
|
||||
layers = slice.layers,
|
||||
outline = layers.outline,
|
||||
|
|
|
|||
|
|
@ -136,11 +136,6 @@
|
|||
sliceDrillReg(settings, sliceAll, zThru);
|
||||
}
|
||||
|
||||
if (procDrill) {
|
||||
maxToolDiam = Math.max(maxToolDiam, drillToolDiam);
|
||||
sliceDrill(drillTool, tslices, sliceAll);
|
||||
}
|
||||
|
||||
// identify through holes
|
||||
thruHoles = tshadow.map(p => p.inner || []).flat();
|
||||
|
||||
|
|
@ -156,7 +151,9 @@
|
|||
slice.z = z;
|
||||
slice.index = sliceIndex++;
|
||||
slice.camMode = PRO.LEVEL;
|
||||
slice.tops[0].traces = POLY.setZ(facing.clone(), slice.z);
|
||||
slice.output()
|
||||
.setLayer("facing", {face: 0, line: 0})
|
||||
.addPolys(POLY.setZ(facing.clone(true), slice.z));
|
||||
sliceAll.push(slice);
|
||||
}
|
||||
}
|
||||
|
|
@ -226,7 +223,9 @@
|
|||
}
|
||||
});
|
||||
|
||||
slice.tops[0].traces = offset;
|
||||
slice.output()
|
||||
.setLayer("roughing", {face: 0, line: 0})
|
||||
.addPolys(offset);
|
||||
slice.index = sliceIndex++;
|
||||
updateOp(index, slices.length);
|
||||
});
|
||||
|
|
@ -299,12 +298,14 @@
|
|||
}
|
||||
}
|
||||
|
||||
slice.tops[0].traces = offset;
|
||||
slice.index = sliceIndex++;
|
||||
|
||||
if (addTabsOutline && slice.z <= zMin + tabHeight) {
|
||||
addCutoutTabs(slice, outlineToolDiam, tabWidth, proc.camTabsCount, proc.camTabsAngle);
|
||||
offset = addCutoutTabs(offset, slice.z, outlineToolDiam, tabWidth, proc.camTabsCount, proc.camTabsAngle);
|
||||
}
|
||||
|
||||
slice.index = sliceIndex++;
|
||||
slice.output()
|
||||
.setLayer("outline", {face: 0, line: 0})
|
||||
.addPolys(offset);
|
||||
});
|
||||
|
||||
sliceAll.appendAll(slices);
|
||||
|
|
@ -337,6 +338,11 @@
|
|||
}
|
||||
}
|
||||
|
||||
if (procDrill) {
|
||||
maxToolDiam = Math.max(maxToolDiam, drillToolDiam);
|
||||
sliceDrill(drillTool, tslices, sliceAll);
|
||||
}
|
||||
|
||||
// used in printSetup()
|
||||
widget.terrain = terrain;
|
||||
widget.maxToolDiam = maxToolDiam;
|
||||
|
|
@ -347,7 +353,7 @@
|
|||
// drilling op
|
||||
function sliceDrill(tool, slices, output) {
|
||||
let drills = [],
|
||||
drillToolDiam = tool.flueDiameter(),
|
||||
drillToolDiam = tool.fluteDiameter(),
|
||||
centerDiff = drillToolDiam * 0.1,
|
||||
area = (drillToolDiam/2) * (drillToolDiam/2) * Math.PI,
|
||||
areaDelta = area * 0.05;
|
||||
|
|
@ -388,7 +394,9 @@
|
|||
point.y = center.y;
|
||||
});
|
||||
slice.camMode = PRO.DRILL;
|
||||
slice.addTop(null).traces = [ drill ];
|
||||
slice.output()
|
||||
.setLayer("drill", {face: 0, line: 0})
|
||||
.addPolys(drill);
|
||||
output.append(slice);
|
||||
});
|
||||
}
|
||||
|
|
@ -425,21 +433,23 @@
|
|||
.append(point.clone().setZ(bounds.max.z - stock.z - mz)));
|
||||
});
|
||||
slice.camMode = PRO.DRILL;
|
||||
slice.addTop(null).traces = polys;
|
||||
slice.output()
|
||||
.setLayer("register", {face: 0, line: 0})
|
||||
.addPolys(polys);
|
||||
output.append(slice);
|
||||
}
|
||||
}
|
||||
|
||||
// cut outside traces at the right points
|
||||
function addCutoutTabs(slice, toolDiam, tabWidth, tabCount, tabAngle) {
|
||||
function addCutoutTabs(offset, z, toolDiam, tabWidth, tabCount, tabAngle) {
|
||||
// skip if no tops | traces
|
||||
if (slice.tops.length === 0) return;
|
||||
if (offset.length === 0) return offset;
|
||||
|
||||
let notabs = 0;
|
||||
let nutrace = [];
|
||||
|
||||
// find trace with greatest area
|
||||
slice.tops[0].traces.forEach(function(trace, index) {
|
||||
offset.forEach(function(trace, index) {
|
||||
|
||||
// required to match computed order of cutouts
|
||||
trace.setClockwise();
|
||||
|
|
@ -447,7 +457,7 @@
|
|||
let count = tabCount,
|
||||
angle = tabAngle,
|
||||
angle_inc = 360 / count,
|
||||
center = trace.bounds.center(slice.z),
|
||||
center = trace.bounds.center(z),
|
||||
offset = (tabWidth + toolDiam) / 2,
|
||||
ints = [],
|
||||
segs = [];
|
||||
|
|
@ -498,7 +508,7 @@
|
|||
console.log(`unable to compute tabs for ${notabs} traces @ z=${slice.z}`);
|
||||
}
|
||||
|
||||
slice.tops[0].traces = nutrace;
|
||||
return nutrace;
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@
|
|||
slice.lines = newlines = [];
|
||||
newtop = slice.addTop(newPolygon().setOpen()).poly;
|
||||
newtrace = newPolygon().setOpen();
|
||||
sliceout = slice.tops[0].traces = [ ];
|
||||
sliceout = [];
|
||||
for (y = minY; y < maxY; y += resolution) {
|
||||
if (pocketOnly && (data[gridx * stepsy + gridy] || 0) === 0) {
|
||||
end_poly();
|
||||
|
|
@ -224,6 +224,9 @@
|
|||
end_poly();
|
||||
if (sliceout.length > 0) {
|
||||
newslices.push(slice);
|
||||
slice.output()
|
||||
.setLayer("contour x", {face: 0, line: 0})
|
||||
.addPolys(sliceout);
|
||||
}
|
||||
onupdate(++stepsTaken, stepsTotal, "contour x");
|
||||
}
|
||||
|
|
@ -241,7 +244,7 @@
|
|||
slice.lines = newlines = [];
|
||||
newtop = slice.addTop(newPolygon().setOpen()).poly;
|
||||
newtrace = newPolygon().setOpen();
|
||||
sliceout = slice.tops[0].traces = [ ];
|
||||
sliceout = [];
|
||||
for (x = minX; x <= maxX; x += resolution) {
|
||||
if (pocketOnly && (data[gridx * stepsy + gridy] || 0) === 0) {
|
||||
end_poly();
|
||||
|
|
@ -281,6 +284,9 @@
|
|||
end_poly();
|
||||
if (sliceout.length > 0) {
|
||||
newslices.push(slice);
|
||||
slice.output()
|
||||
.setLayer("contour y", {face: 0, line: 0})
|
||||
.addPolys(sliceout);
|
||||
}
|
||||
onupdate(++stepsTaken, stepsTotal, "contour y");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue