Skip to content

Commit f3c5054

Browse files
authored
Merge pull request #267 from xyz-tools/fix/toggle-single-layer
Fix toggle single layer
2 parents e34cd90 + 70b9761 commit f3c5054

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

demo/js/app.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ export const app = (window.app = createApp({
216216
watchEffect(() => {
217217
preview.startLayer = +settings.value.startLayer;
218218
preview.endLayer = +settings.value.endLayer;
219+
});
220+
221+
watchEffect(() => {
219222
preview.singleLayerMode = settings.value.singleLayerMode;
220223
});
221224
});

src/webgl-preview.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export class WebGLPreview {
9797
private minPlane = new Plane(new Vector3(0, 1, 0), 0.6);
9898
private maxPlane = new Plane(new Vector3(0, -1, 0), 0.1);
9999
private clippingPlanes: Plane[] = [];
100+
private prevStartLayer = 0;
100101

101102
// colors
102103
private _backgroundColor = new Color(0xe0e0e0);
@@ -263,7 +264,7 @@ export class WebGLPreview {
263264
if (this.countLayers > 1 && value > 0) {
264265
this._endLayer = value;
265266
if (this._singleLayerMode === true) {
266-
this.startLayer = this._endLayer;
267+
this.startLayer = this._endLayer - 1;
267268
}
268269
if (value <= this.countLayers) {
269270
const layer = this.job.layers[value - 1];
@@ -276,10 +277,16 @@ export class WebGLPreview {
276277
}
277278
}
278279

280+
get singleLayerMode(): boolean {
281+
return this._singleLayerMode;
282+
}
279283
set singleLayerMode(value: boolean) {
280284
this._singleLayerMode = value;
281285
if (value) {
282-
this.startLayer = this.endLayer - 1;
286+
this.prevStartLayer = this._startLayer;
287+
this.startLayer = this._endLayer - 1;
288+
} else {
289+
this.startLayer = this.prevStartLayer;
283290
}
284291
}
285292

@@ -468,18 +475,24 @@ export class WebGLPreview {
468475
}
469476

470477
private renderPathsAsLines(paths: Path[], color: Color): void {
471-
console.log(this.clippingPlanes);
472478
const material = new LineMaterial({
473479
color: Number(color.getHex()),
474480
linewidth: this.lineWidth,
475481
clippingPlanes: this.clippingPlanes
476482
});
477483

478484
const lineVertices: number[] = [];
485+
486+
// lines need to be offset.
487+
// The gcode specifies the nozzle height which is the top of the extrusion.
488+
// The line doesn't have a constant height in world coords so it should be rendered at horizontal midplane of the extrusion layer.
489+
// Otherwise the line will be clipped by the clipping plane.
490+
const offset = -this.lineHeight / 2;
491+
479492
paths.forEach((path) => {
480493
for (let i = 0; i < path.vertices.length - 3; i += 3) {
481-
lineVertices.push(path.vertices[i], path.vertices[i + 1], path.vertices[i + 2]);
482-
lineVertices.push(path.vertices[i + 3], path.vertices[i + 4], path.vertices[i + 5]);
494+
lineVertices.push(path.vertices[i], path.vertices[i + 1] - 0.1, path.vertices[i + 2] + offset);
495+
lineVertices.push(path.vertices[i + 3], path.vertices[i + 4] - 0.1, path.vertices[i + 5] + offset);
483496
}
484497
});
485498

0 commit comments

Comments
 (0)