@@ -5,19 +5,21 @@ import Shape from 'clipper-js';
55export default function generateInfills ( slices , settings ) {
66 let {
77 layerHeight,
8- fill : { gridSize : fillGridSize } ,
9- bottom : { thickness : bottomThickness } ,
10- top : { thickness : topThickness } ,
8+ innerInfill : { gridSize : infillGridSize } ,
9+ thickness : {
10+ top : topThickness ,
11+ bottom : bottomThickness
12+ } ,
1113 nozzleDiameter
1214 } = settings ;
1315
14- fillGridSize /= PRECISION ;
16+ infillGridSize /= PRECISION ;
1517 nozzleDiameter /= PRECISION ;
1618
1719 const bottomSkinCount = Math . ceil ( bottomThickness / layerHeight ) ;
1820 const topSkinCount = Math . ceil ( topThickness / layerHeight ) ;
1921 const nozzleRadius = nozzleDiameter / 2 ;
20- const hightemplateSize = Math . sqrt ( 2 * Math . pow ( nozzleDiameter , 2 ) ) ;
22+ const outerFillTemplateSize = Math . sqrt ( 2 * Math . pow ( nozzleDiameter , 2 ) ) ;
2123
2224 for ( let layer = 0 ; layer < slices . length ; layer ++ ) {
2325 const slice = slices [ layer ] ;
@@ -32,39 +34,35 @@ export default function generateInfills(slices, settings) {
3234 for ( let i = 0 ; i < slice . parts . length ; i ++ ) {
3335 const part = slice . parts [ i ] ;
3436
35- if ( ! part . shape . closed ) {
36- continue ;
37- }
37+ if ( ! part . closed ) continue ;
3838
39- const outerLine = part . outerLine ;
39+ const innerShell = part . shell [ part . shell . length - 1 ] ;
4040
41- if ( outerLine . paths . length > 0 ) {
42- const inset = ( part . innerLines . length > 0 ) ? part . innerLines [ part . innerLines . length - 1 ] : outerLine ;
41+ if ( innerShell . paths . length === 0 ) continue ;
4342
44- const fillArea = inset . offset ( - nozzleRadius ) ;
45- let lowFillArea ;
46- let highFillArea ;
47- if ( surroundingLayer ) {
48- highFillArea = fillArea . difference ( surroundingLayer ) . intersect ( fillArea ) ;
49- lowFillArea = fillArea . difference ( highFillArea ) ;
50- } else {
51- highFillArea = fillArea ;
52- }
43+ const fillArea = innerShell . offset ( - nozzleRadius ) ;
44+ let innerFillArea ;
45+ let outerFillArea ;
46+ if ( surroundingLayer ) {
47+ outerFillArea = fillArea . difference ( surroundingLayer ) . intersect ( fillArea ) ;
48+ innerFillArea = fillArea . difference ( outerFillArea ) ;
49+ } else {
50+ outerFillArea = fillArea ;
51+ }
5352
54- if ( lowFillArea && lowFillArea . paths . length > 0 ) {
55- const bounds = lowFillArea . shapeBounds ( ) ;
56- const lowFillTemplate = getFillTemplate ( bounds , fillGridSize , true , true ) ;
53+ if ( innerFillArea && innerFillArea . paths . length > 0 ) {
54+ const bounds = innerFillArea . shapeBounds ( ) ;
55+ const innerFillTemplate = getFillTemplate ( bounds , infillGridSize , true , true ) ;
5756
58- part . fill . join ( lowFillTemplate . intersect ( lowFillArea ) ) ;
59- }
57+ part . innerFill . join ( innerFillTemplate . intersect ( innerFillArea ) ) ;
58+ }
6059
61- if ( highFillArea . paths . length > 0 ) {
62- const bounds = highFillArea . shapeBounds ( ) ;
63- const even = ( layer % 2 === 0 ) ;
64- const highFillTemplate = getFillTemplate ( bounds , hightemplateSize , even , ! even ) ;
60+ if ( outerFillArea . paths . length > 0 ) {
61+ const bounds = outerFillArea . shapeBounds ( ) ;
62+ const even = ( layer % 2 === 0 ) ;
63+ const outerFillTemplate = getFillTemplate ( bounds , outerFillTemplateSize , even , ! even ) ;
6564
66- part . fill . join ( highFillTemplate . intersect ( highFillArea ) ) ;
67- }
65+ part . outerFill . join ( outerFillTemplate . intersect ( outerFillArea ) ) ;
6866 }
6967 }
7068 }
0 commit comments