mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-22 05:37:55 +01:00
store gcode as blob instead of string
Less prone to crashing
This commit is contained in:
parent
61722a6985
commit
701d736cc0
@ -181,7 +181,13 @@ export async function slice(action, name, mesh, settings, updateProgress) {
|
||||
.multiply(new THREE.Matrix4().makeRotationY(-Math.PI / 2.0))
|
||||
.multiply(mesh.matrix);
|
||||
|
||||
const { gcode } = await sliceGeometry(settings, mesh.geometry, mesh.material, matrix, false, false, ({ progress }) => {
|
||||
const { gcode } = await sliceGeometry({
|
||||
...settings,
|
||||
name: `${name}.gcode`,
|
||||
printer: { type: settings.printers, title: printerSettings[settings.printer].title },
|
||||
material: { type: settings.material, title: materialSettings[settings.material].title },
|
||||
quality: { type: settings.quality, title: qualitySettings[settings.quality].title }
|
||||
}, mesh.geometry, mesh.material, matrix, false, false, ({ progress }) => {
|
||||
updateProgress({
|
||||
action: progress.action,
|
||||
percentage: (currentStep + progress.done / progress.total) / steps
|
||||
@ -193,16 +199,14 @@ export async function slice(action, name, mesh, settings, updateProgress) {
|
||||
|
||||
switch (action.target) {
|
||||
case 'DOWNLOAD': {
|
||||
const file = new Blob([gcode], { type: 'text/plain' });
|
||||
fileSaver.saveAs(file, `${name}.gcode`);
|
||||
fileSaver.saveAs(gcode, `${name}.gcode`);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'WIFI_PRINT': {
|
||||
if (settings.printer === 'doodle3d_printer') {
|
||||
const body = new FormData();
|
||||
const file = new Blob([gcode], { type: 'plain/text' });
|
||||
body.append('file', file, 'doodle.gcode');
|
||||
body.append('file', gcode, 'doodle.gcode');
|
||||
|
||||
// because fetch has no way of retrieving progress we fake progress
|
||||
let loaded = 0;
|
||||
@ -236,14 +240,7 @@ export async function slice(action, name, mesh, settings, updateProgress) {
|
||||
body.append(key, fields[key]);
|
||||
}
|
||||
|
||||
const file = new Blob([`;${JSON.stringify({
|
||||
...settings,
|
||||
name: `${name}.gcode`,
|
||||
printer: { type: settings.printers, title: printerSettings[settings.printer].title },
|
||||
material: { type: settings.material, title: materialSettings[settings.material].title },
|
||||
quality: { type: settings.quality, title: qualitySettings[settings.quality].title }
|
||||
}).trim()}\n${gcode}`]);
|
||||
body.append('file', file, 'doodle.gcode');
|
||||
body.append('file', gcode, 'doodle.gcode');
|
||||
|
||||
await fetchProgress(url, { method: 'POST', body }, progress => {
|
||||
updateProgress({
|
||||
@ -259,14 +256,7 @@ export async function slice(action, name, mesh, settings, updateProgress) {
|
||||
}
|
||||
case 'CUSTOM_UPLOAD': {
|
||||
const body = new FormData();
|
||||
const file = new Blob([`;${JSON.stringify({
|
||||
...settings,
|
||||
name: `${name}.gcode`,
|
||||
printer: { type: settings.printers, title: printerSettings[settings.printer].title },
|
||||
material: { type: settings.material, title: materialSettings[settings.material].title },
|
||||
quality: { type: settings.quality, title: qualitySettings[settings.quality].title }
|
||||
}).trim()}\n${gcode}`]);
|
||||
body.append('file', file, 'doodle.gcode');
|
||||
body.append('file', gcode, 'doodle.gcode');
|
||||
|
||||
await fetchProgress(action.url, { method: 'POST', body }, progress => {
|
||||
updateProgress({
|
||||
|
@ -11,9 +11,12 @@ export const POSITION_Y = 'Y';
|
||||
export const POSITION_Z = 'Z';
|
||||
|
||||
export default class GCode {
|
||||
constructor(layerHeight) {
|
||||
constructor(settings) {
|
||||
this._nozzleToFilamentRatio = 1;
|
||||
this._gcode = [`; Generated with Doodle3D Slicer V${VERSION}`];
|
||||
this._gcode = [
|
||||
`; ${JSON.stringify(settings).trim()}`,
|
||||
`; Generated with Doodle3D Slicer V${VERSION}`
|
||||
];
|
||||
this._currentValues = {};
|
||||
this._nozzlePosition = { x: 0, y: 0 };
|
||||
this._extruder = 0.0;
|
||||
|
@ -1,15 +0,0 @@
|
||||
export function stringToTypedArray(string) {
|
||||
const array = new Uint8Array(string.length);
|
||||
for (let i = 0; i < string.length; i ++) {
|
||||
array[i] = string.charCodeAt(i);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
export function typedArrayToString(array) {
|
||||
let string = '';
|
||||
for (let i = 0; i < array.length; i ++) {
|
||||
string += String.fromCharCode(array[i]);
|
||||
}
|
||||
return string;
|
||||
}
|
@ -65,7 +65,8 @@ export default function(settings, geometry, openObjectIndexes, constructLinePrev
|
||||
|
||||
if (constructLinePreview) gcode.linePreview = createGcodeGeometry(gcode.gcode);
|
||||
|
||||
gcode.gcode = gcodeToString(gcode.gcode);
|
||||
gcode.gcode = new Blob([gcodeToString(gcode.gcode)], { type: 'text/plain' });
|
||||
|
||||
return gcode;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ export default function slicesToGCode(slices, settings) {
|
||||
combing
|
||||
} = settings;
|
||||
|
||||
const gcode = new GCode();
|
||||
const gcode = new GCode(settings);
|
||||
gcode.updateLayerHeight(Z_OFFSET, nozzleDiameter, filamentThickness)
|
||||
|
||||
if (settings.startCode) gcode.addGCode(settings.startCode, settings);
|
||||
|
@ -1,7 +1,6 @@
|
||||
import * as THREE from 'three';
|
||||
import slice from './sliceActions/slice.js';
|
||||
import SlicerWorker from './slicer.worker.js';
|
||||
import { typedArrayToString } from './sliceActions/helpers/binary.js';
|
||||
|
||||
export function sliceMesh(settings, mesh, sync = false, constructLinePreview = false, onProgress) {
|
||||
if (!mesh || !mesh.isMesh) {
|
||||
@ -91,7 +90,6 @@ function sliceAsync(settings, geometry, openObjectIndexes, constructLinePreview,
|
||||
slicerWorker.terminate();
|
||||
|
||||
const { gcode } = data;
|
||||
gcode.gcode = typedArrayToString(gcode.gcode);
|
||||
if (gcode.linePreview) gcode.linePreview = constructLineGeometry(gcode.linePreview);
|
||||
|
||||
resolve(gcode);
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'core-js'; // polyfills
|
||||
import slice from './sliceActions/slice.js';
|
||||
import { stringToTypedArray } from './sliceActions/helpers/binary.js';
|
||||
|
||||
const onProgress = progress => {
|
||||
self.postMessage({
|
||||
@ -16,9 +15,8 @@ self.addEventListener('message', (event) => {
|
||||
const { settings, geometry, constructLinePreview, openObjectIndexes } = data;
|
||||
|
||||
const gcode = slice(settings, geometry, openObjectIndexes, constructLinePreview, onProgress);
|
||||
gcode.gcode = stringToTypedArray(gcode.gcode);
|
||||
|
||||
const buffers = [gcode.gcode.buffer];
|
||||
const buffers = [];
|
||||
if (gcode.linePreview) {
|
||||
buffers.push(gcode.linePreview.positions.buffer);
|
||||
buffers.push(gcode.linePreview.colors.buffer);
|
||||
|
Loading…
Reference in New Issue
Block a user