@@ -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