-
-
Notifications
You must be signed in to change notification settings - Fork 152
Open
Labels
Description
Hi,
I just noticed that when I make a drawing in LibreCAD and read it in CAMotics, only the first bit of the spline is rendered, so I started digging into dxf.tpl and found that it's not running the Catmull-Rom 2D on all the control points.
The quick hack below makes the shapes appear more or less in the right place, but there are some gaps.
I'll try to find some time to fix the spline rendering and submit a change :-)
--- dxf.tpl 2022-05-23 20:44:54.000000000 +0200
+++ dxf_orig.tpl 2022-05-23 19:43:01.000000000 +0200
@@ -382,31 +382,16 @@ module.exports = extend({
},
- spline_cut: function(s, zSafe, zCut, res) {
+ spline_cut: function(s, res) {
if (typeof res == 'undefined') res = units() == METRIC ? 1 : 1 / 25.4;
if (s.degree == 2) {
- for(var seg=0; seg<s.ctrlPts.length; seg++)
- {
- var segment = [];
- segment.push(s.ctrlPts[(s.ctrlPts.length+seg-1)%s.ctrlPts.length]);
- segment.push(s.ctrlPts[(s.ctrlPts.length+seg+0)%s.ctrlPts.length]);
- segment.push(s.ctrlPts[(s.ctrlPts.length+seg+1)%s.ctrlPts.length]);
-
- var steps = Math.ceil(quad_bezier_length(segment) / res);
- var delta = 1 / steps;
-
- rapid({z: zSafe});
- for (var i = 0; i < steps; i++) {
- v = quad_bezier(segment, delta * (i + 1));
- if(i<=0) {
- rapid (v.x/2.0+segment[1].x/2.0, v.y/2.0+segment[1].y/2.0);
- cut({z: zCut});
- }
- cut(v.x/2.0+segment[1].x/2.0, v.y/2.0+segment[1].y/2.0);
- }
- rapid({z: zSafe});
+ var steps = Math.ceil(quad_bezier_length(s.ctrlPts) / res);
+ var delta = 1 / steps;
+ for (var i = 0; i < steps; i++) {
+ v = quad_bezier(s.ctrlPts, delta * (i + 1));
+ cut(v.x, v.y);
}
@@ -425,13 +410,13 @@ module.exports = extend({
},
- element_cut: function(e, zSafe, zCut, res) {
+ element_cut: function(e, res) {
switch (e.type) {
case _dxf.POINT: return;
case _dxf.LINE: return this.line_cut(e);
case _dxf.ARC: return this.arc_cut(e);
case _dxf.POLYLINE: return this.polyline_cut(e);
- case _dxf.SPLINE: return this.spline_cut(e, zSafe, zCut, res);
+ case _dxf.SPLINE: return this.spline_cut(e, res);
default: throw 'Unsupported DXF element type ' + e.type;
}
},
@@ -459,7 +444,7 @@ module.exports = extend({
cut({z: zCut});
cut(v.x, v.y);
- this.element_cut(e, zSafe, zCut, res);
+ this.element_cut(e, res);
layer.splice(match.i, 1);
}