|
@@ -2419,7 +2419,7 @@ function onEdges(oc, bodies, feature, what, make, report, retry) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (report) {
|
|
if (report) {
|
|
|
- // a chamfer that was cut (cutChamfer) knows its new faces itself
|
|
|
|
|
|
|
+ // a chamfer made of wedges (wedgeChamfer) knows its new faces itself
|
|
|
report.fresh[index] = maker.fresh ? maker.fresh() : freshFaces(oc, maker, body, made);
|
|
report.fresh[index] = maker.fresh ? maker.fresh() : freshFaces(oc, maker, body, made);
|
|
|
}
|
|
}
|
|
|
return made;
|
|
return made;
|
|
@@ -2543,7 +2543,7 @@ export function chamfer(oc, bodies, feature, report) {
|
|
|
if (mode === 'angle' && !(angle > 0 && angle < 90)) {
|
|
if (mode === 'angle' && !(angle > 0 && angle < 90)) {
|
|
|
throw new Error('The chamfer angle must be between 0 and 90 degrees');
|
|
throw new Error('The chamfer angle must be between 0 and 90 degrees');
|
|
|
}
|
|
}
|
|
|
- // What building the chamfer of `edges` on `body` needs (cutChamfer):
|
|
|
|
|
|
|
+ // What building the chamfer of `edges` on `body` needs (wedgeChamfer):
|
|
|
// { build(scale), sizes(i, faces, between), free() }
|
|
// { build(scale), sizes(i, faces, between), free() }
|
|
|
const plan = function (body, edges) {
|
|
const plan = function (body, edges) {
|
|
|
// Two distances or an angle are measured from one of the edge's two
|
|
// Two distances or an angle are measured from one of the edge's two
|
|
@@ -2630,11 +2630,11 @@ export function chamfer(oc, bodies, feature, report) {
|
|
|
free: free
|
|
free: free
|
|
|
};
|
|
};
|
|
|
};
|
|
};
|
|
|
- // The builder's chamfer; cut (cutChamfer) when the builder refuses it
|
|
|
|
|
|
|
+ // The builder's chamfer; made of wedges (wedgeChamfer) when it refuses
|
|
|
const make = function (body, edges) {
|
|
const make = function (body, edges) {
|
|
|
const p = plan(body, edges);
|
|
const p = plan(body, edges);
|
|
|
try {
|
|
try {
|
|
|
- const maker = p.build(1) || cutChamfer(oc, body, edges, p.sizes, p.build);
|
|
|
|
|
|
|
+ const maker = p.build(1) || wedgeChamfer(oc, body, edges, p.sizes, p.build);
|
|
|
if (!maker) {
|
|
if (!maker) {
|
|
|
throw new Error('The chamfer could not be built on these edges. Try a smaller distance');
|
|
throw new Error('The chamfer could not be built on these edges. Try a smaller distance');
|
|
|
}
|
|
}
|
|
@@ -2644,11 +2644,11 @@ export function chamfer(oc, bodies, feature, report) {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
// The builder may also say done and leave the face it should take away
|
|
// The builder may also say done and leave the face it should take away
|
|
|
- // as a broken sliver (the end of a rib standing on a plate): cut it then
|
|
|
|
|
|
|
+ // as a broken sliver (the end of a rib standing on a plate): wedges then
|
|
|
const retry = function (body, edges) {
|
|
const retry = function (body, edges) {
|
|
|
const p = plan(body, edges);
|
|
const p = plan(body, edges);
|
|
|
try {
|
|
try {
|
|
|
- return cutChamfer(oc, body, edges, p.sizes, p.build);
|
|
|
|
|
|
|
+ return wedgeChamfer(oc, body, edges, p.sizes, p.build);
|
|
|
} finally {
|
|
} finally {
|
|
|
p.free();
|
|
p.free();
|
|
|
}
|
|
}
|
|
@@ -2658,19 +2658,20 @@ export function chamfer(oc, bodies, feature, report) {
|
|
|
|
|
|
|
|
/* ---- a chamfer that takes a whole face away ---- */
|
|
/* ---- a chamfer that takes a whole face away ---- */
|
|
|
// OpenCascade's chamfer builder refuses a bevel that ends exactly on the far
|
|
// OpenCascade's chamfer builder refuses a bevel that ends exactly on the far
|
|
|
-// edge of a face next to the edge: a 10 mm chamfer on the end of a 10 mm
|
|
|
|
|
-// plate, which takes the end face away, fails while 9.99 builds (and so do
|
|
|
|
|
-// two chamfers that meet in a ridge), or it says done and leaves the face as
|
|
|
|
|
-// a broken sliver. On straight edges between flat faces a
|
|
|
|
|
-// chamfer is the same as cutting a wedge off along the edge, so that is what
|
|
|
|
|
-// is done then. The cut is only kept when it takes off what the builder's
|
|
|
|
|
-// own chamfers a hair smaller say it should: their volumes, carried on to
|
|
|
|
|
-// the full size. A wedge that bites into something past the end of an edge
|
|
|
|
|
-// (a wall the edge runs into) fails that check, and the chamfer fails as it
|
|
|
|
|
-// did before.
|
|
|
|
|
|
|
+// edge of a face next to the edge, so that the face goes away: a 10 mm
|
|
|
|
|
+// chamfer on the end of a 10 mm plate, or in the inside corner of a 10 mm
|
|
|
|
|
+// step (which fills the step up into a ramp), fails while 9.99 builds; so do
|
|
|
|
|
+// two chamfers that meet in a ridge. Or it says done and leaves the face as
|
|
|
|
|
+// a broken sliver. On straight edges between flat faces a chamfer is a
|
|
|
|
|
+// wedge along the edge, cut off at an outside corner and added in an inside
|
|
|
|
|
+// one, so that is what is built then (wedgeChamfer). It is only kept when it
|
|
|
|
|
+// changes the volume as much as the builder's own chamfers a hair smaller
|
|
|
|
|
+// say it should, carried on to the full size: a wedge that reaches
|
|
|
|
|
+// something past the end of an edge fails that check, and the chamfer fails
|
|
|
|
|
+// as it did before.
|
|
|
|
|
|
|
|
// how much smaller (as a fraction) the builder's chamfers for the check are
|
|
// how much smaller (as a fraction) the builder's chamfers for the check are
|
|
|
-const CUT_CHECK_STEP = 1e-3;
|
|
|
|
|
|
|
+const WEDGE_CHECK_STEP = 1e-3;
|
|
|
|
|
|
|
|
function vSub(a, b) {
|
|
function vSub(a, b) {
|
|
|
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
@@ -2693,10 +2694,12 @@ function vUnit(a) {
|
|
|
return l > 1e-12 ? [a[0] / l, a[1] / l, a[2] / l] : null;
|
|
return l > 1e-12 ? [a[0] / l, a[1] / l, a[2] / l] : null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// A straight edge between two flat faces that meet at an outside corner:
|
|
|
|
|
-// { start, e: unit direction, length, faces: [face, face] (facesOfEdge
|
|
|
|
|
-// order, the caller's to delete), u: per face the direction across it away
|
|
|
|
|
-// from the edge, between: the angle between the two in radians }, or null.
|
|
|
|
|
|
|
+// A straight edge between two flat faces: { start, e: unit direction,
|
|
|
|
|
+// length, faces: [face, face] (facesOfEdge order, the caller's to delete),
|
|
|
|
|
+// convex: an outside corner (else inside), u: per face the direction across
|
|
|
|
|
+// it away from the edge, between: the angle between the two in radians
|
|
|
|
|
+// (the open side of an inside corner), open: per end, whether the material
|
|
|
|
|
+// stops there }, or null.
|
|
|
function bevelSite(oc, body, edge) {
|
|
function bevelSite(oc, body, edge) {
|
|
|
const curve = new oc.BRepAdaptor_Curve(edge);
|
|
const curve = new oc.BRepAdaptor_Curve(edge);
|
|
|
let ends = null;
|
|
let ends = null;
|
|
@@ -2732,16 +2735,20 @@ function bevelSite(oc, body, edge) {
|
|
|
return drop();
|
|
return drop();
|
|
|
}
|
|
}
|
|
|
// An outside corner: a step off the edge across one face and under the
|
|
// An outside corner: a step off the edge across one face and under the
|
|
|
- // other is out of the material (as edgeSignature)
|
|
|
|
|
|
|
+ // other is out of the material (as edgeSignature); inside it at an
|
|
|
|
|
+ // inside corner
|
|
|
const off = vUnit(vSub(normals[0], normals[1]));
|
|
const off = vUnit(vSub(normals[0], normals[1]));
|
|
|
- if (!off || isInside(oc, body, vAdd(mid, off, 0.01))) {
|
|
|
|
|
- return drop();
|
|
|
|
|
|
|
+ if (!off) {
|
|
|
|
|
+ return drop(); // the faces lie on one plane: no corner
|
|
|
}
|
|
}
|
|
|
|
|
+ const convex = !isInside(oc, body, vAdd(mid, off, 0.01));
|
|
|
// Across a face away from the edge is in the face's plane, square to the
|
|
// Across a face away from the edge is in the face's plane, square to the
|
|
|
- // edge, and (at an outside corner) against the other face's normal
|
|
|
|
|
|
|
+ // edge, against the other face's normal at an outside corner and along
|
|
|
|
|
+ // it at an inside one
|
|
|
const u = [0, 1].map(function (k) {
|
|
const u = [0, 1].map(function (k) {
|
|
|
const across = vUnit(vCross(normals[k], e));
|
|
const across = vUnit(vCross(normals[k], e));
|
|
|
- return across && vDot(across, normals[1 - k]) > 0 ? across.map(function (c) {
|
|
|
|
|
|
|
+ const along = across ? vDot(across, normals[1 - k]) : 0;
|
|
|
|
|
+ return across && (convex ? along > 0 : along < 0) ? across.map(function (c) {
|
|
|
return -c;
|
|
return -c;
|
|
|
}) : across;
|
|
}) : across;
|
|
|
});
|
|
});
|
|
@@ -2749,11 +2756,15 @@ function bevelSite(oc, body, edge) {
|
|
|
return drop();
|
|
return drop();
|
|
|
}
|
|
}
|
|
|
// Per end, does the material stop there? Every other face through the
|
|
// Per end, does the material stop there? Every other face through the
|
|
|
- // end looks away from the edge (the end of a box): the wedge may run on
|
|
|
|
|
- // past it. A face that looks back at the edge (the plate a rib stands
|
|
|
|
|
- // on) carries the material on: the wedge stops at the end.
|
|
|
|
|
|
|
+ // end looks away from the edge (the end of a box): a cut may run on past
|
|
|
|
|
+ // it. A face that looks back at the edge (the plate a rib stands on)
|
|
|
|
|
+ // carries the material on: the cut stops at the end. Only a cut asks:
|
|
|
|
|
+ // a wedge that is added always stops at the ends.
|
|
|
const open = [false, false];
|
|
const open = [false, false];
|
|
|
[0, 1].forEach(function (k) {
|
|
[0, 1].forEach(function (k) {
|
|
|
|
|
+ if (!convex) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
const end = ends[k];
|
|
const end = ends[k];
|
|
|
const away = k === 0 ? e.map(function (c) {
|
|
const away = k === 0 ? e.map(function (c) {
|
|
|
return -c;
|
|
return -c;
|
|
@@ -2771,7 +2782,7 @@ function bevelSite(oc, body, edge) {
|
|
|
explorer.delete();
|
|
explorer.delete();
|
|
|
open[k] = stops;
|
|
open[k] = stops;
|
|
|
});
|
|
});
|
|
|
- return { start: ends[0], e: e, length: length, faces: faces, u: u, open: open, between: Math.acos(Math.max(-1, Math.min(1, vDot(u[0], u[1])))) };
|
|
|
|
|
|
|
+ return { start: ends[0], e: e, length: length, faces: faces, convex: convex, u: u, open: open, between: Math.acos(Math.max(-1, Math.min(1, vDot(u[0], u[1])))) };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// A solid: the triangle `corners` swept by `sweep`
|
|
// A solid: the triangle `corners` swept by `sweep`
|
|
@@ -2795,11 +2806,23 @@ function wedgeSolid(oc, corners, sweep) {
|
|
|
return outward(oc, solid);
|
|
return outward(oc, solid);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// The chamfer of `edges` (on `body`) cut as wedges. sizes(i, faces,
|
|
|
|
|
-// between): the distances on the two faces of edge i; build(scale): the
|
|
|
|
|
-// builder's chamfer with every distance times scale, or null. Returns a
|
|
|
|
|
-// stand-in for the builder ({ Shape, fresh, delete }) or null.
|
|
|
|
|
-function cutChamfer(oc, body, edges, sizes, build) {
|
|
|
|
|
|
|
+// Join `solid` into `tool` (null: none yet); null when the join fails
|
|
|
|
|
+function gather(oc, tool, solid) {
|
|
|
|
|
+ if (!tool) {
|
|
|
|
|
+ return solid;
|
|
|
|
|
+ }
|
|
|
|
|
+ const joined = boolean(oc, 'join', tool, solid);
|
|
|
|
|
+ tool.delete();
|
|
|
|
|
+ solid.delete();
|
|
|
|
|
+ return joined;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// The chamfer of `edges` (on `body`) as wedges, cut off at outside corners
|
|
|
|
|
+// and added in inside ones. sizes(i, faces, between): the distances on the
|
|
|
|
|
+// two faces of edge i; build(scale): the builder's chamfer with every
|
|
|
|
|
+// distance times scale, or null. Returns a stand-in for the builder
|
|
|
|
|
+// ({ Shape, fresh, delete }) or null.
|
|
|
|
|
+function wedgeChamfer(oc, body, edges, sizes, build) {
|
|
|
const sites = [];
|
|
const sites = [];
|
|
|
const free = function () {
|
|
const free = function () {
|
|
|
sites.forEach(function (site) {
|
|
sites.forEach(function (site) {
|
|
@@ -2808,10 +2831,12 @@ function cutChamfer(oc, body, edges, sizes, build) {
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
- let tool = null;
|
|
|
|
|
- let cut = null;
|
|
|
|
|
|
|
+ let cutTool = null;
|
|
|
|
|
+ let fillTool = null;
|
|
|
|
|
+ let result = null;
|
|
|
try {
|
|
try {
|
|
|
const bevels = [];
|
|
const bevels = [];
|
|
|
|
|
+ let nominal = 0; // the volume of the wedges, for the check
|
|
|
for (let i = 0; i < edges.length; i++) {
|
|
for (let i = 0; i < edges.length; i++) {
|
|
|
const site = bevelSite(oc, body, edges[i]);
|
|
const site = bevelSite(oc, body, edges[i]);
|
|
|
if (!site) {
|
|
if (!site) {
|
|
@@ -2823,55 +2848,69 @@ function cutChamfer(oc, body, edges, sizes, build) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
// The cross section: the bevel from one face to the other, and a
|
|
// The cross section: the bevel from one face to the other, and a
|
|
|
- // corner off the material so no side lies on a face of the body.
|
|
|
|
|
- // Run on past an end where the material stops, so it clears the
|
|
|
|
|
- // face there (the end of a box may lean); else stop at the end.
|
|
|
|
|
|
|
+ // third corner so no side lies on a face of the body: off the
|
|
|
|
|
+ // material for a cut, a little into it for a wedge that is added.
|
|
|
|
|
+ // A cut runs on past an end where the material stops, so it
|
|
|
|
|
+ // clears the face there (the end of a box may lean); otherwise
|
|
|
|
|
+ // the wedge stops at the end.
|
|
|
const a = site.u[0].map(function (c) {
|
|
const a = site.u[0].map(function (c) {
|
|
|
return c * d[0];
|
|
return c * d[0];
|
|
|
});
|
|
});
|
|
|
const b = site.u[1].map(function (c) {
|
|
const b = site.u[1].map(function (c) {
|
|
|
return c * d[1];
|
|
return c * d[1];
|
|
|
});
|
|
});
|
|
|
- const outside = vUnit(vAdd(site.u[0], site.u[1], 1));
|
|
|
|
|
- if (!outside) {
|
|
|
|
|
|
|
+ const into = vUnit(vAdd(site.u[0], site.u[1], 1)); // towards the open side of an inside corner
|
|
|
|
|
+ if (!into) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
const past = 2 * Math.max(d[0], d[1]);
|
|
const past = 2 * Math.max(d[0], d[1]);
|
|
|
const head = site.open[0] ? past : 0;
|
|
const head = site.open[0] ? past : 0;
|
|
|
const tail = site.open[1] ? past : 0;
|
|
const tail = site.open[1] ? past : 0;
|
|
|
const base = vAdd(site.start, site.e, -head);
|
|
const base = vAdd(site.start, site.e, -head);
|
|
|
- const corners = [vAdd(base, a, 1), vAdd(base, b, 1), vAdd(base, outside, -0.5 * Math.min(d[0], d[1]))];
|
|
|
|
|
|
|
+ const back = (site.convex ? 0.5 : 0.1) * Math.min(d[0], d[1]);
|
|
|
|
|
+ const corners = [vAdd(base, a, 1), vAdd(base, b, 1), vAdd(base, into, -back)];
|
|
|
const solid = wedgeSolid(oc, corners, site.e.map(function (c) {
|
|
const solid = wedgeSolid(oc, corners, site.e.map(function (c) {
|
|
|
return c * (site.length + head + tail);
|
|
return c * (site.length + head + tail);
|
|
|
}));
|
|
}));
|
|
|
- const joined = tool ? boolean(oc, 'join', tool, solid) : solid;
|
|
|
|
|
- if (tool) {
|
|
|
|
|
- tool.delete();
|
|
|
|
|
- solid.delete();
|
|
|
|
|
|
|
+ if (site.convex) {
|
|
|
|
|
+ cutTool = gather(oc, cutTool, solid);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ fillTool = gather(oc, fillTool, solid);
|
|
|
}
|
|
}
|
|
|
- tool = joined;
|
|
|
|
|
- if (!tool) {
|
|
|
|
|
|
|
+ if (!(site.convex ? cutTool : fillTool)) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- // the bevel's plane, its normal pointing out of the material
|
|
|
|
|
|
|
+ nominal += 0.5 * d[0] * d[1] * Math.sin(site.between) * site.length;
|
|
|
|
|
+ // the bevel's plane, its normal pointing out of the material:
|
|
|
|
|
+ // towards the edge after a cut, away from it after a fill
|
|
|
let normal = vUnit(vCross(vSub(b, a), site.e));
|
|
let normal = vUnit(vCross(vSub(b, a), site.e));
|
|
|
- if (vDot(normal, outside) > 0) {
|
|
|
|
|
|
|
+ if (vDot(normal, into) * (site.convex ? 1 : -1) > 0) {
|
|
|
normal = normal.map(function (c) {
|
|
normal = normal.map(function (c) {
|
|
|
return -c;
|
|
return -c;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
bevels.push({ point: vAdd(site.start, a, 1), normal: normal });
|
|
bevels.push({ point: vAdd(site.start, a, 1), normal: normal });
|
|
|
}
|
|
}
|
|
|
- cut = boolean(oc, 'cut', body, tool);
|
|
|
|
|
- if (!cut || isEmpty(oc, cut)) {
|
|
|
|
|
|
|
+ result = cutTool ? boolean(oc, 'cut', body, cutTool) : body;
|
|
|
|
|
+ if (result && fillTool) {
|
|
|
|
|
+ const filled = boolean(oc, 'join', result, fillTool);
|
|
|
|
|
+ if (result !== body) {
|
|
|
|
|
+ result.delete();
|
|
|
|
|
+ }
|
|
|
|
|
+ result = filled;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!result || result === body || isEmpty(oc, result)) {
|
|
|
|
|
+ if (result === body) {
|
|
|
|
|
+ result = null;
|
|
|
|
|
+ }
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- // The check: the material the builder takes off at 1 - h and 1 - 2h
|
|
|
|
|
- // of the size, carried on to the full size (a chamfer takes off an
|
|
|
|
|
- // amount that grows smoothly with its size: square, plus a cube
|
|
|
|
|
- // part where bevels meet at a corner, so the error is tiny)
|
|
|
|
|
|
|
+ // The check: the volume the builder's chamfers change at 1 - h and
|
|
|
|
|
+ // 1 - 2h of the size, carried on to the full size. That change
|
|
|
|
|
+ // grows smoothly with the size (square, plus a cube part where
|
|
|
|
|
+ // bevels meet at a corner), so the error is tiny next to the wedges.
|
|
|
const before = volume(oc, body);
|
|
const before = volume(oc, body);
|
|
|
- const taken = [1 - CUT_CHECK_STEP, 1 - 2 * CUT_CHECK_STEP].map(function (scale) {
|
|
|
|
|
|
|
+ const change = [1 - WEDGE_CHECK_STEP, 1 - 2 * WEDGE_CHECK_STEP].map(function (scale) {
|
|
|
const maker = build(scale);
|
|
const maker = build(scale);
|
|
|
if (!maker) {
|
|
if (!maker) {
|
|
|
return null;
|
|
return null;
|
|
@@ -2880,18 +2919,18 @@ function cutChamfer(oc, body, edges, sizes, build) {
|
|
|
const v = volume(oc, shape);
|
|
const v = volume(oc, shape);
|
|
|
shape.delete();
|
|
shape.delete();
|
|
|
maker.delete();
|
|
maker.delete();
|
|
|
- return before - v;
|
|
|
|
|
|
|
+ return v - before;
|
|
|
});
|
|
});
|
|
|
- if (taken[0] === null || taken[1] === null) {
|
|
|
|
|
|
|
+ if (change[0] === null || change[1] === null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- const expected = 2 * taken[0] - taken[1];
|
|
|
|
|
- const got = before - volume(oc, cut);
|
|
|
|
|
- if (!(expected > 0) || !(Math.abs(got - expected) <= Math.max(expected * 1e-4, Math.abs(before) * 1e-9))) {
|
|
|
|
|
|
|
+ const expected = 2 * change[0] - change[1];
|
|
|
|
|
+ const got = volume(oc, result) - before;
|
|
|
|
|
+ if (!(Math.abs(got - expected) <= Math.max(nominal * 1e-4, Math.abs(before) * 1e-9))) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- const shape = cut;
|
|
|
|
|
- cut = null;
|
|
|
|
|
|
|
+ const shape = result;
|
|
|
|
|
+ result = null;
|
|
|
return {
|
|
return {
|
|
|
Shape: function () {
|
|
Shape: function () {
|
|
|
return shape;
|
|
return shape;
|
|
@@ -2915,12 +2954,11 @@ function cutChamfer(oc, body, edges, sizes, build) {
|
|
|
};
|
|
};
|
|
|
} finally {
|
|
} finally {
|
|
|
free();
|
|
free();
|
|
|
- if (tool) {
|
|
|
|
|
- tool.delete();
|
|
|
|
|
- }
|
|
|
|
|
- if (cut) {
|
|
|
|
|
- cut.delete();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ [cutTool, fillTool, result].forEach(function (shape) {
|
|
|
|
|
+ if (shape && shape !== body) {
|
|
|
|
|
+ shape.delete();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|