add support for open poly line width and miter distances
This commit is contained in:
parent
f04fb3a813
commit
50e7ef906a
5 changed files with 21 additions and 12 deletions
|
|
@ -1701,9 +1701,10 @@ class Polygon {
|
||||||
* @param {'square'|'round'|'miter'} type
|
* @param {'square'|'round'|'miter'} type
|
||||||
* @returns {Polygon[]}
|
* @returns {Polygon[]}
|
||||||
*/
|
*/
|
||||||
offset_open(distance, type = 'miter') {
|
offset_open(distance, type = 'miter', miterLimit = 2) {
|
||||||
if (this.isOpen()) {
|
if (this.isOpen()) {
|
||||||
let coff = new ClipperOffset(),
|
let coff = new ClipperOffset(),
|
||||||
|
dudd = (coff.MiterLimit = miterLimit),
|
||||||
tree = new PolyTree(),
|
tree = new PolyTree(),
|
||||||
entt = {
|
entt = {
|
||||||
'square' : EndType.etOpenSquare,
|
'square' : EndType.etOpenSquare,
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ function parse(text, opt = { soup: true }) {
|
||||||
let path = paths[i];
|
let path = paths[i];
|
||||||
let shapes = path.toShapes(true);
|
let shapes = path.toShapes(true);
|
||||||
let type = path.userData?.node?.nodeName;
|
let type = path.userData?.node?.nodeName;
|
||||||
|
let width = path.userData?.style?.strokeWidth;
|
||||||
|
let miter = path.userData?.style?.strokeMiterLimit;
|
||||||
if (fromSoup) {
|
if (fromSoup) {
|
||||||
for (let node of shapes) {
|
for (let node of shapes) {
|
||||||
let { shape, holes } = node.extractPoints();
|
let { shape, holes } = node.extractPoints();
|
||||||
|
|
@ -39,6 +41,8 @@ function parse(text, opt = { soup: true }) {
|
||||||
let poly = base.newPolygon().addPoints(path.map(p => base.newPoint(p.x, -p.y, 0)));
|
let poly = base.newPolygon().addPoints(path.map(p => base.newPoint(p.x, -p.y, 0)));
|
||||||
if (poly.appearsClosed()) poly.points.pop();
|
if (poly.appearsClosed()) poly.points.pop();
|
||||||
if (type === 'polyline') poly.setOpen(true);
|
if (type === 'polyline') poly.setOpen(true);
|
||||||
|
if (width) poly.width = width;
|
||||||
|
if (miter) poly.miter = miter;
|
||||||
polys.push(poly);
|
polys.push(poly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -466,7 +466,7 @@ let sketch = {
|
||||||
h.button({ _: "create", onclick() {
|
h.button({ _: "create", onclick() {
|
||||||
const { _height, _chamtop, _chambot } = api.modal.bound;
|
const { _height, _chamtop, _chambot } = api.modal.bound;
|
||||||
sketch.extrude({
|
sketch.extrude({
|
||||||
selection: sketch.selected.count() > 0,
|
selection: sketch.selection.count() > 0,
|
||||||
...opt,
|
...opt,
|
||||||
height: parseFloat(_height.value),
|
height: parseFloat(_height.value),
|
||||||
chamfer_top: parseFloat(_chamtop.value),
|
chamfer_top: parseFloat(_chamtop.value),
|
||||||
|
|
@ -1271,7 +1271,7 @@ const prefs = {
|
||||||
select: []
|
select: []
|
||||||
},
|
},
|
||||||
sketch: {
|
sketch: {
|
||||||
close_poly: false,
|
open_close: false,
|
||||||
open_thick: 1,
|
open_thick: 1,
|
||||||
open_type: 'miter'
|
open_type: 'miter'
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -317,12 +317,12 @@ api.settings = function() {
|
||||||
h.label({ class: "header", _: 'open poly'}),
|
h.label({ class: "header", _: 'open poly'}),
|
||||||
h.label('auto close'),
|
h.label('auto close'),
|
||||||
h.input({ type: "checkbox",
|
h.input({ type: "checkbox",
|
||||||
onchange: ev => prefs.save( (sketch.close_poly = !sketch.close_poly) && srr() ),
|
onchange: ev => prefs.save( ((sketch.open_close = !sketch.open_close) || true) && srr() ),
|
||||||
[ sketch.close_poly === true ? 'checked' : 'unchecked' ] : 1
|
[ sketch.open_close === true ? 'checked' : 'unchecked' ] : 1
|
||||||
}),
|
}),
|
||||||
h.label('thickness'),
|
h.label('width'),
|
||||||
h.input({ type: "text", size: 5, value: parseFloat(sketch.open_thick || 1),
|
h.input({ type: "text", size: 5, value: parseFloat(sketch.open_width || 1),
|
||||||
onchange: ev => prefs.save( (sketch.open_thick = parseFloat(ev.target.value)) && srr() )
|
onchange: ev => prefs.save( (sketch.open_width = parseFloat(ev.target.value)) && srr() )
|
||||||
}),
|
}),
|
||||||
h.label('type'),
|
h.label('type'),
|
||||||
h.select({ type: "text", value: sketch.open_type,
|
h.select({ type: "text", value: sketch.open_type,
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ mesh.sketch = class MeshSketch extends mesh.object {
|
||||||
},
|
},
|
||||||
|
|
||||||
count() {
|
count() {
|
||||||
return sketch.selection.mesh_items().length;
|
return sketch.items.filter(i => i.selected).length;
|
||||||
},
|
},
|
||||||
|
|
||||||
all() {
|
all() {
|
||||||
|
|
@ -431,6 +431,8 @@ mesh.sketch = class MeshSketch extends mesh.object {
|
||||||
delete opt.poly;
|
delete opt.poly;
|
||||||
this.add_item({
|
this.add_item({
|
||||||
type: "polygon",
|
type: "polygon",
|
||||||
|
width: poly.width,
|
||||||
|
miter: poly.miter,
|
||||||
selected: true,
|
selected: true,
|
||||||
...Object.assign({}, { center: {x:0, y:0, z:0} }, opt),
|
...Object.assign({}, { center: {x:0, y:0, z:0} }, opt),
|
||||||
...poly.toObject()
|
...poly.toObject()
|
||||||
|
|
@ -529,8 +531,8 @@ class SketchItem {
|
||||||
let bump = 0.0025;
|
let bump = 0.0025;
|
||||||
let { item, sketch, order } = this;
|
let { item, sketch, order } = this;
|
||||||
let { material } = mesh;
|
let { material } = mesh;
|
||||||
let { type, center, width, height, radius, points, spacing, poly, selected } = item;
|
let { type, center, width, height, miter, radius, points, spacing, poly, selected } = item;
|
||||||
let { close_poly, open_thick, open_type } = api.prefs.map.sketch;
|
let { open_close, open_width, open_type } = api.prefs.map.sketch;
|
||||||
if (type === 'circle') {
|
if (type === 'circle') {
|
||||||
let circumference = 2 * Math.PI * radius;
|
let circumference = 2 * Math.PI * radius;
|
||||||
points = points || Math.floor(circumference / (spacing || 1));
|
points = points || Math.floor(circumference / (spacing || 1));
|
||||||
|
|
@ -540,7 +542,9 @@ class SketchItem {
|
||||||
} else if (type === 'polygon') {
|
} else if (type === 'polygon') {
|
||||||
poly = newPolygon().fromObject(item);
|
poly = newPolygon().fromObject(item);
|
||||||
poly.move(center);
|
poly.move(center);
|
||||||
if (poly.isOpen() && !close_poly) poly = poly.offset_open(open_thick, open_type)[0];
|
if (poly.isOpen() && open_close !== true) {
|
||||||
|
poly = poly.offset_open(width || open_width || 1, open_type, miter)[0];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw `invalid sketch type: ${type}`;
|
throw `invalid sketch type: ${type}`;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue