disable line priview

This commit is contained in:
casperlamboo 2018-02-11 23:28:25 +01:00
parent 774289895e
commit 5944153de7
3 changed files with 58 additions and 58 deletions

View File

@ -1,4 +1,4 @@
import * as THREE from 'three'; // import * as THREE from 'three';
import calculateLayersIntersections from './calculateLayersIntersections.js'; import calculateLayersIntersections from './calculateLayersIntersections.js';
import createLines from './createLines.js'; import createLines from './createLines.js';
import generateInfills from './generateInfills.js'; import generateInfills from './generateInfills.js';
@ -64,9 +64,9 @@ export default function(settings, geometry, openObjectIndexes, constructLinePrev
updateProgress('Finished'); updateProgress('Finished');
if (constructLinePreview) gcode.linePreview = createGcodeGeometry(gcode.gcode); // if (constructLinePreview) gcode.linePreview = createGcodeGeometry(gcode.gcode);
gcode.gcode = gcodeToString(gcode.gcode); // gcode.gcode = gcodeToString(gcode.gcode);
return gcode; // return gcode;
} }
const PRECISION_INVERSE = 1 / PRECISION; const PRECISION_INVERSE = 1 / PRECISION;
@ -98,39 +98,39 @@ function gcodeToString(gcode) {
}, ''); }, '');
} }
const MAX_SPEED = 100 * 60; // const MAX_SPEED = 100 * 60;
const COLOR = new THREE.Color(); // const COLOR = new THREE.Color();
function createGcodeGeometry(gcode) { // function createGcodeGeometry(gcode) {
const positions = []; // const positions = [];
const colors = []; // const colors = [];
//
let lastPoint = [0, 0, 0]; // let lastPoint = [0, 0, 0];
for (let i = 0; i < gcode.length; i ++) { // for (let i = 0; i < gcode.length; i ++) {
const command = gcode[i]; // const command = gcode[i];
if (typeof command === 'string') continue; // if (typeof command === 'string') continue;
//
const { G, F, X, Y, Z } = command; // const { G, F, X, Y, Z } = command;
//
if (X || Y || Z) { // if (X || Y || Z) {
if (G === 1) { // if (G === 1) {
positions.push(lastPoint.Y, lastPoint.Z, lastPoint.X); // positions.push(lastPoint.Y, lastPoint.Z, lastPoint.X);
positions.push(Y, Z, X); // positions.push(Y, Z, X);
//
const color = (G === 0) ? COLOR.setHex(0x00ff00) : COLOR.setHSL(F / MAX_SPEED, 0.5, 0.5); // const color = (G === 0) ? COLOR.setHex(0x00ff00) : COLOR.setHSL(F / MAX_SPEED, 0.5, 0.5);
colors.push(color.r, color.g, color.b); // colors.push(color.r, color.g, color.b);
colors.push(color.r, color.g, color.b); // colors.push(color.r, color.g, color.b);
} // }
lastPoint = { X, Y, Z }; // lastPoint = { X, Y, Z };
} // }
} // }
//
const geometry = new THREE.BufferGeometry(); // const geometry = new THREE.BufferGeometry();
//
geometry.addAttribute('position', new THREE.BufferAttribute(new Float32Array(positions), 3)); // geometry.addAttribute('position', new THREE.BufferAttribute(new Float32Array(positions), 3));
geometry.addAttribute('color', new THREE.BufferAttribute(new Float32Array(colors), 3)); // geometry.addAttribute('color', new THREE.BufferAttribute(new Float32Array(colors), 3));
//
const material = new THREE.LineBasicMaterial({ vertexColors: THREE.VertexColors }); // const material = new THREE.LineBasicMaterial({ vertexColors: THREE.VertexColors });
const linePreview = new THREE.LineSegments(geometry, material); // const linePreview = new THREE.LineSegments(geometry, material);
//
return linePreview; // return linePreview;
} // }

View File

@ -70,18 +70,18 @@ function sliceAsync(settings, geometry, openObjectIndexes, constructLinePreview,
case 'SLICE': { case 'SLICE': {
slicerWorker.terminate(); slicerWorker.terminate();
if (data.gcode.linePreview) { // if (data.gcode.linePreview) {
const geometry = new THREE.BufferGeometry(); // const geometry = new THREE.BufferGeometry();
//
const { position, color } = data.gcode.linePreview; // const { position, color } = data.gcode.linePreview;
geometry.addAttribute('position', new THREE.BufferAttribute(new Float32Array(position), 3)); // geometry.addAttribute('position', new THREE.BufferAttribute(new Float32Array(position), 3));
geometry.addAttribute('color', new THREE.BufferAttribute(new Float32Array(color), 3)); // geometry.addAttribute('color', new THREE.BufferAttribute(new Float32Array(color), 3));
//
const material = new THREE.LineBasicMaterial({ vertexColors: THREE.VertexColors }); // const material = new THREE.LineBasicMaterial({ vertexColors: THREE.VertexColors });
const linePreview = new THREE.LineSegments(geometry, material); // const linePreview = new THREE.LineSegments(geometry, material);
//
data.gcode.linePreview = linePreview; // data.gcode.linePreview = linePreview;
} // }
resolve(data.gcode); resolve(data.gcode);
break; break;

View File

@ -21,12 +21,12 @@ self.addEventListener('message', (event) => {
const gcode = slice(settings, geometry, openObjectIndexes, constructLinePreview, onProgress); const gcode = slice(settings, geometry, openObjectIndexes, constructLinePreview, onProgress);
const buffers = []; const buffers = [];
if (gcode.linePreview) { // if (gcode.linePreview) {
const position = gcode.linePreview.geometry.getAttribute('position').array; // const position = gcode.linePreview.geometry.getAttribute('position').array;
const color = gcode.linePreview.geometry.getAttribute('color').array; // const color = gcode.linePreview.geometry.getAttribute('color').array;
buffers.push(position.buffer, color.buffer); // buffers.push(position.buffer, color.buffer);
gcode.linePreview = { position, color }; // gcode.linePreview = { position, color };
} // }
self.postMessage({ self.postMessage({
message: 'SLICE', message: 'SLICE',