add slicing on a bias

This commit is contained in:
Stewart Allen 2020-05-06 14:04:43 -04:00
commit c7d5b0b825
7 changed files with 63 additions and 14 deletions

View file

@ -122,7 +122,7 @@ var gs_kiri_codec = exports;
inner: encode(this.inner, state),
// thinner: encode(this.thinner, state),
solids: encode(this.solids, state),
fill_lines: encodePointArray(this.fill_lines),
fill_lines: encodePointArray(this.fill_lines, state),
fill_sparse: encode(this.fill_sparse, state),
polish: encode(this.polish, state)
};
@ -142,13 +142,27 @@ var gs_kiri_codec = exports;
return top;
});
function encodePointArray(points) {
function encodePointArray(points, state) {
if (!points) return null;
var array = new Float32Array(points.length * 3),
pos = 0;
points.forEach(function(point) {
if (state.rotate) {
if (state.centerz) {
point.z -= state.centerz;
}
let v = new THREE.Vector3(point.x, point.y, point.z);
v.applyMatrix4(state.rotate);
point = {x: v.x, y: v.y, z: v.z};
if (state.centerz) {
point.z += state.centerz;
}
if (state.movez) {
point.z -= state.movez;
}
}
array[pos++] = point.x;
array[pos++] = point.y;
array[pos++] = point.z;
@ -188,11 +202,11 @@ var gs_kiri_codec = exports;
return {
type: 'poly',
id: this.id,
array: encodePointArray(this.points),
array: encodePointArray(this.points, state),
open: this.isOpen(),
inner: encode(this.inner, state),
parent: encode(this.parent, state),
fills: encodePointArray(this.fills),
fills: encodePointArray(this.fills, state),
depth: this.depth
};
};

View file

@ -282,7 +282,8 @@ let gs_kiri_conf = exports;
sliceMinHeight: 0,
zHopDistance: 0.2,
antiBacklash: 1,
gcodePause: ""
gcodePause: "",
sliceRotation: 0
}
},
sla:{

View file

@ -1447,6 +1447,7 @@ var gs_kiri_init = exports;
outputShortPoly: UC.newInput(LANG.ad_spol_s, {title:LANG.ad_spol_l, bound:UC.bound(0,200), convert:UC.toFloat, modes:FDM, expert:true}),
zHopDistance: UC.newInput(LANG.ad_zhop_s, {title:LANG.ad_zhop_l, bound:UC.bound(0,3.0), convert:UC.toFloat, modes:FDM, expert:true}),
antiBacklash: UC.newInput(LANG.ad_abkl_s, {title:LANG.ad_abkl_l, bound:UC.bound(0,3), convert:UC.toInt, modes:FDM, expert:true}),
sliceRotation: UC.newInput(LANG.ad_slrt_s, {title:LANG.ad_slrt_l, bound:UC.bound(-45,45), convert:UC.toFloat, modes:FDM, expert:true}),
// detectThinWalls: UC.newBoolean("thin wall fill", onBooleanClick, {title: "detect and fill thin openings\nbetween shells walls", modes:FDM, expert:true})
gcodePauseLayers: UC.newInput(LANG.ag_paws_s, {title:LANG.ag_paws_l, modes:FDM, expert:true, comma:true}),
outputLayerRetract: UC.newBoolean(LANG.ad_lret_s, onBooleanClick, {title:LANG.ad_lret_l, modes:FDM, expert:true}),

View file

@ -532,15 +532,17 @@ let gs_kiri_widget = exports;
PRO.rotate = function(x, y, z) {
this.group.forEach(w => {
w._rotate(x, y, z);
w._rotate(x, y, z, false);
});
this.center();
};
PRO._rotate = function(x, y, z) {
this.bounds = null;
this.setWireframe(false);
this.clearSlices();
PRO._rotate = function(x, y, z, temp) {
if (!temp) {
this.bounds = null;
this.setWireframe(false);
this.clearSlices();
}
let m4 = new THREE.Matrix4();
let euler = typeof(x) === 'number';
if (euler) {
@ -549,7 +551,7 @@ let gs_kiri_widget = exports;
m4 = m4.makeRotationFromQuaternion(x);
}
this.mesh.geometry.applyMatrix4(m4);
if (euler) {
if (!temp && euler) {
let rot = this.track.rot;
rot.x += (x || 0);
rot.y += (y || 0);

View file

@ -88,8 +88,23 @@ KIRI.work = {
},
slice : function(settings, widget, callback) {
let rotation = (Math.PI/180) * (settings.process.sliceRotation || 0);
let centerz;
let movez;
if (rotation) {
let bbox1 = widget.getBoundingBox(true);
widget._rotate(0,rotation,0,true);
widget.center();
let bbox2 = widget.getBoundingBox(true);
centerz = (bbox2.max.z - bbox2.min.z)/2;
movez = centerz - (bbox1.max.z - bbox1.min.z)/2;
}
let vertices = widget.getGeoVertices().buffer.slice(0),
snapshot = KIRI.api.view.snapshot;
if (rotation) {
widget._rotate(0,-rotation,0,true);
widget.center();
}
slicing[widget.id] = callback;
send("slice", {
id: widget.id,
@ -97,7 +112,13 @@ KIRI.work = {
vertices: vertices,
position: widget.mesh.position,
tracking: widget.track,
snapshot: snapshot
snapshot: snapshot,
// for rotation / unrotation
state: {
rotation: rotation,
centerz: centerz,
movez: movez
}
}, function(reply) {
if (reply.done || reply.error) delete slicing[widget.id];
callback(reply);

View file

@ -39,7 +39,15 @@ let dispatch = {
vertices = new Float32Array(data.vertices),
position = data.position,
tracking = data.tracking,
points = Widget.verticesToPoints(vertices);
points = Widget.verticesToPoints(vertices),
state = data.state || {},
rotation = state.rotation,
centerz = state.centerz,
movez = state.movez;
if (rotation) {
state.rotate = new THREE.Matrix4().makeRotationY(-rotation);
}
send.data({update:0.05, updateStatus:"slicing"});
@ -72,7 +80,7 @@ let dispatch = {
slices: slices.length
});
slices.forEach(function(slice,index) {
send.data({index: index, slice: slice.encode()});
send.data({index: index, slice: slice.encode(state)});
})
if (self.debug && widget.polish) {
send.data({polish: kiri.codec.encode(widget.polish)});

View file

@ -376,6 +376,8 @@ kiri.lang['en-us'] = {
ad_zhop_l: "amount to raise z\non retraction moves\nin millimeters\n0 to disable",
ad_abkl_s: "anti-backlash",
ad_abkl_l: "use micro-movements to cancel\nbacklash during fills\nin millimeters",
ad_slrt_s: "slice rotation",
ad_slrt_l: "slice object on a bias\nangle in the y axis.\nuseful for extremely\nlarge format prints",
ad_lret_s: "layer retract",
ad_lret_l: "force filament retraction\nbetween layers",
ad_play_s: "polish layers",