From d53b53db475d22dddf23e4a5d0d3da4437167b48 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Wed, 15 Apr 2020 15:20:02 -0400 Subject: [PATCH] complete sla hollow feature --- js/kiri-driver-sla.js | 49 ++++++++++++++++++++++++++++++------------- js/kiri-init.js | 6 +++++- js/kiri-slice.js | 9 ++++---- js/kiri.js | 13 +++++++++--- js/license.js | 2 +- js/moto-space.js | 11 ++++++++-- 6 files changed, 64 insertions(+), 26 deletions(-) diff --git a/js/kiri-driver-sla.js b/js/kiri-driver-sla.js index f4bb3626..9c426981 100644 --- a/js/kiri-driver-sla.js +++ b/js/kiri-driver-sla.js @@ -45,8 +45,8 @@ let gs_kiri_sla = exports; // for each slice, performe a function and call doupdate() function forSlices(slices, from, to, fn, msg) { - slices.forEach(function(slice) { - fn(slice); + slices.forEach(function(slice,index) { + fn(slice,index); doupdate(slices, slice.index, from, to, msg) }); } @@ -54,7 +54,7 @@ let gs_kiri_sla = exports; SLICER.sliceWidget(widget, { height: process.slaSlice || 0.05 }, function(slices) { - widget.slices = slices; + widget.slices = slices.filter(slice => slice.tops.length); // reset for solids and support projections slices.forEach(function(slice) { slice.invalidateFill(); @@ -62,20 +62,35 @@ let gs_kiri_sla = exports; slice.invalidateSupports(); slice.isSolidFill = false; }); - forSlices(slices, 0.0, 0.2, (slice) => { - slice.doShells(1, 0); - // slice.tops.forEach(top => { top.solids = [] }); + let solidLayers = Math.round(process.slaShell / process.slaSlice); + forSlices(slices, 0.0, 0.2, (slice,index) => { + if (process.slaShell) { + slice.doShells(2, 0, process.slaShell); + } else { + slice.doShells(1, 0); + } }, "slice"); forSlices(slices, 0.2, 0.4, (slice) => { slice.doDiff(0.00001, 0.005, true); }, "delta"); - forSlices(slices, 0.4, 0.5, (slice) => { - slice.projectFlats(process.slaSolids || 5); - slice.projectBridges(process.slaSolids || 5); - }, "project"); - forSlices(slices, 0.5, 0.6, (slice) => { - slice.doSolidsFill(undefined, undefined, 0.00001); - }, "solid"); + if (solidLayers) { + forSlices(slices, 0.4, 0.5, (slice) => { + slice.projectFlats(solidLayers); + slice.projectBridges(solidLayers); + }, "project"); + forSlices(slices, 0.5, 0.6, (slice) => { + slice.doSolidsFill(undefined, undefined, 0.001); + let traces = POLY.nest(POLY.flatten(slice.gatherTraces([]))); + let trims = slice.solids.trimmed || []; + traces.appendAll(trims); + let union = POLY.union(traces); + slice.solids.unioned = union; + }, "solid"); + } else { + forSlices(slices, 0.4, 0.6, (slice) => { + slice.solids.unioned = slice.gatherTopPolys([]); + }) + } ondone(); }, function(update) { return onupdate(0.0 + update * 0.5); @@ -124,7 +139,9 @@ let gs_kiri_sla = exports; widgets.forEach(widget => { let slice = widget.slices[index]; if (slice) { - slice.tops.map(top => top.poly).forEach(poly => { + let traces = POLY.flatten(slice.gatherTraces([])); + let polys = slice.solids.unioned; + polys.forEach(poly => { ctx.beginPath(); polyout(poly.setClockwise(), ctx); if (poly.inner) { @@ -183,7 +200,9 @@ let gs_kiri_sla = exports; if (!slice) { return; } - slice.tops.map(top => top.poly).forEach(poly => { + // let polys = slice.gatherTraces([]); + let polys = slice.solids.unioned; + polys.forEach(poly => { layer.poly(poly, 0x888888, true, false); count++; }); diff --git a/js/kiri-init.js b/js/kiri-init.js index 5d305315..757e340f 100644 --- a/js/kiri-init.js +++ b/js/kiri-init.js @@ -1438,7 +1438,7 @@ var gs_kiri_init = exports; // SLA slaProc: UC.newGroup('slice', null, {modes:SLA, group:"sla-slice"}), slaSlice: UC.newInput('layer height', {title:'slice height', convert:UC.toFloat, modes:SLA}), - slaShell: UC.newInput('hollow shell', {title:'shell thickness in mm\nuse multiple of layer height\nuse 0 for solid', convert:UC.toInt, modes:SLA}), + slaShell: UC.newInput('hollow shell', {title:'shell thickness in mm\nuse multiple of layer height\nuse 0 for solid', convert:UC.toFloat, modes:SLA}), slaOpenTop: UC.newBoolean('open top', onBooleanClick, {title:'solid layers', modes:SLA}), slaOpenBase: UC.newBoolean('open base', onBooleanClick, {title:'bottom layers', modes:SLA}), slaOutput: UC.newGroup('output', null, {modes:SLA, group:"sla-output"}), @@ -1695,6 +1695,8 @@ var gs_kiri_init = exports; let current = settings(), control = current.controller; + SPACE.scene.freeze(true); + platform.deselect(); CATALOG.addFileListener(updateCatalog); SPACE.view.setZoom(control.reverseZoom, control.zoomSpeed); @@ -1801,6 +1803,8 @@ var gs_kiri_init = exports; // send init-done event API.event.emit('init-done', STATS); + + SPACE.scene.freeze(false); } // if a language needs to load, the script is injected and loaded diff --git a/js/kiri-slice.js b/js/kiri-slice.js index 69b66c7e..b8b54d6c 100644 --- a/js/kiri-slice.js +++ b/js/kiri-slice.js @@ -442,8 +442,7 @@ let gs_kiri_slice = exports; // top.thinner = []; top.traces = []; top.inner = []; - let last = [], - z = top.poly.getZ(); + let last = [], z = top.poly.getZ(); if (opt.thin) { top.thin_fill = []; @@ -451,7 +450,7 @@ let gs_kiri_slice = exports; if (count) { // permit offset of 0 for laser - if (offset1 === 0) { + if (offset1 === 0 && count === 1) { last = top_poly.clone(true); top.traces = last; } else { @@ -925,7 +924,9 @@ let gs_kiri_slice = exports; }); // for SLA to bypass line infill - if (isSLA) return true; + if (isSLA) { + return true; + } // create empty filled line array for each top tops.forEach(function(top) { diff --git a/js/kiri.js b/js/kiri.js index e57299ff..96b72c53 100644 --- a/js/kiri.js +++ b/js/kiri.js @@ -924,18 +924,20 @@ self.kiri.copyright = exports.COPYRIGHT; } function platformUpdateSize() { + let frozen = SPACE.scene.freeze(true); let dev = settings.device, width, depth, height = Math.round(Math.max(dev.bedHeight, dev.bedWidth/100, dev.bedDepth/100)); SPACE.platform.setRound(dev.bedRound); - SPACE.platform.setGZOff(height/2 - 0.1); SPACE.platform.setSize( width = parseInt(dev.bedWidth), depth = parseInt(dev.bedDepth), height = parseFloat(dev.bedHeight) ); + SPACE.platform.setGZOff(height/2 - 0.1); SPACE.platform.setHidden(width > 500 || depth > 500); platform.update_origin(); + SPACE.scene.freeze(frozen); } function platformUpdateBounds() { @@ -1520,9 +1522,14 @@ self.kiri.copyright = exports.COPYRIGHT; platform.update_size(); platform.update_stock(); + let fz = SPACE.scene.freeze(true); SPACE.view.reset(); - if (camera) SPACE.view.load(camera); - else setTimeout(SPACE.view.home, 100); + if (camera) { + SPACE.view.load(camera); + } else { + SPACE.view.home(); + } + SPACE.scene.freeze(fz); if (skip_widget_load) return; diff --git a/js/license.js b/js/license.js index 64650efc..abe7fea9 100644 --- a/js/license.js +++ b/js/license.js @@ -1,7 +1,7 @@ var exports = { COPYRIGHT:"Copyright (C) Stewart Allen - All Rights Reserved", LICENSE:"See the license.md file included with the source distribution", - VERSION:"1.8.4" + VERSION:"1.8.5" }; if (!module) var module = {}; module.exports = exports; diff --git a/js/moto-space.js b/js/moto-space.js index 0c7ffee9..90b73452 100644 --- a/js/moto-space.js +++ b/js/moto-space.js @@ -63,6 +63,7 @@ var MOTO = window.moto = window.moto || {}; camera, renderer, container, + freeze = false, isRound = false, platformMaterial = new THREE.MeshPhongMaterial({ color: 0xcccccc, @@ -198,8 +199,8 @@ var MOTO = window.moto = window.moto || {}; } function setGrid(unitMajor, unitMinor, colorMajor, colorMinor) { - if (gridView) Space.scene.remove(gridView); if (!unitMajor) return; + let oldGridView = gridView; gridView = new THREE.Group(); gridUnitMajor = unitMajor; gridUnitMinor = unitMinor; @@ -233,6 +234,7 @@ var MOTO = window.moto = window.moto || {}; } gridView.add(makeLinesFromPoints(majors, gridColorMajor || 0x999999, 1)); if (minors) gridView.add(makeLinesFromPoints(minors, gridColorMinor || 0xcccccc, 1)); + if (oldGridView) Space.scene.remove(oldGridView); Space.scene.add(gridView); } @@ -560,6 +562,11 @@ var MOTO = window.moto = window.moto || {}; }, remove: function (o) { return SCENE.remove(o); + }, + freeze: function (b) { + let fz = freeze; + freeze = b; + return fz; } }, @@ -737,7 +744,7 @@ var MOTO = window.moto = window.moto || {}; function animate() { requestAnimationFrame(animate); - renderer.render(SCENE, camera); + if (!freeze) renderer.render(SCENE, camera); } animate();