11import * as THREE from 'three' ;
2+ import { Box3 } from 'three/src/math/Box3.js' ;
3+ import { Matrix4 } from 'three/src/math/Matrix4.js' ;
4+ import { Scene } from 'three/src/scenes/Scene.js' ;
5+ import { PerspectiveCamera } from 'three/src/cameras/PerspectiveCamera.js' ;
6+ import { AmbientLight } from 'three/src/lights/AmbientLight.js' ;
7+ import { DirectionalLight } from 'three/src/lights/DirectionalLight.js' ;
8+ import { MeshPhongMaterial } from 'three/src/materials/MeshPhongMaterial.js' ;
9+ import { BoxGeometry } from 'three/src/geometries/BoxGeometry.js' ;
10+ import { Mesh } from 'three/src/objects/Mesh.js' ;
11+ import { BoxHelper } from 'three/src/helpers/BoxHelper.js' ;
12+ import { WebGLRenderer } from 'three/src/renderers/WebGLRenderer.js' ;
13+ import { DoubleSide } from 'three/src/constants.js' ;
214import 'three/examples/js/controls/EditorControls' ;
315import printerSettings from '../settings/printer.yml' ;
416import materialSettings from '../settings/material.yml' ;
@@ -8,7 +20,7 @@ import React from 'react';
820import PropTypes from 'prop-types' ;
921
1022export function placeOnGround ( mesh ) {
11- const boundingBox = new THREE . Box3 ( ) . setFromObject ( mesh ) ;
23+ const boundingBox = new Box3 ( ) . setFromObject ( mesh ) ;
1224
1325 mesh . position . y -= boundingBox . min . y ;
1426 mesh . updateMatrix ( ) ;
@@ -21,30 +33,30 @@ export function createScene(canvas, props, state) {
2133 // center geometry
2234 geometry . computeBoundingBox ( ) ;
2335 const center = geometry . boundingBox . getCenter ( ) ;
24- geometry . applyMatrix ( new THREE . Matrix4 ( ) . makeTranslation ( - center . x , - center . y , - center . z ) ) ;
36+ geometry . applyMatrix ( new Matrix4 ( ) . makeTranslation ( - center . x , - center . y , - center . z ) ) ;
2537
26- const scene = new THREE . Scene ( ) ;
38+ const scene = new Scene ( ) ;
2739
28- const camera = new THREE . PerspectiveCamera ( 50 , 1 , 1 , 10000 ) ;
40+ const camera = new PerspectiveCamera ( 50 , 1 , 1 , 10000 ) ;
2941 camera . position . set ( 0 , 400 , 300 ) ;
3042
31- const directionalLightA = new THREE . DirectionalLight ( 0xa2a2a2 ) ;
43+ const directionalLightA = new DirectionalLight ( 0xa2a2a2 ) ;
3244 directionalLightA . position . set ( 1 , 1 , 1 ) ;
3345 scene . add ( directionalLightA ) ;
3446
35- const directionalLightB = new THREE . DirectionalLight ( 0xa2a2a2 ) ;
47+ const directionalLightB = new DirectionalLight ( 0xa2a2a2 ) ;
3648 directionalLightB . position . set ( - 1 , 1 , - 1 ) ;
3749 scene . add ( directionalLightB ) ;
3850
39- const light = new THREE . AmbientLight ( 0x656565 ) ;
51+ const light = new AmbientLight ( 0x656565 ) ;
4052 scene . add ( light ) ;
4153
42- const material = new THREE . MeshPhongMaterial ( { color : 0x2194ce , side : THREE . DoubleSide , specular : 0xc5c5c5 , shininess : 5 } ) ;
43- const mesh = new THREE . Mesh ( geometry , material ) ;
54+ const material = new MeshPhongMaterial ( { color : 0x2194ce , side : DoubleSide , specular : 0xc5c5c5 , shininess : 5 } ) ;
55+ const mesh = new Mesh ( geometry , material ) ;
4456 placeOnGround ( mesh ) ;
4557 scene . add ( mesh ) ;
4658
47- const box = new THREE . BoxHelper ( new THREE . Mesh ( new THREE . BoxGeometry ( 1 , 1 , 1 ) . applyMatrix ( new THREE . Matrix4 ( ) . makeTranslation ( 0 , 0.5 , 0 ) ) ) , 0x72bcd4 ) ;
59+ const box = new BoxHelper ( new Mesh ( new BoxGeometry ( 1 , 1 , 1 ) . applyMatrix ( new Matrix4 ( ) . makeTranslation ( 0 , 0.5 , 0 ) ) ) , 0x72bcd4 ) ;
4860 scene . add ( box ) ;
4961
5062 const { dimensions } = settings ;
@@ -66,7 +78,7 @@ export function createScene(canvas, props, state) {
6678 const updateCanvas = ( canvas ) => {
6779 if ( ! renderer || renderer . domElement !== canvas ) {
6880 if ( renderer ) renderer . dispose ( ) ;
69- renderer = new THREE . WebGLRenderer ( { canvas, alpha : true , antialias : true } ) ;
81+ renderer = new WebGLRenderer ( { canvas, alpha : true , antialias : true } ) ;
7082 renderer . setClearColor ( 0xffffff , 0 ) ;
7183 }
7284 if ( ! editorControls || editorControls . domElement !== canvas ) {
@@ -106,14 +118,16 @@ const GCODE_SERVER_URL = 'https://gcodeserver.doodle3d.com';
106118const CONNECT_URL = 'http://connect.doodle3d.com/' ;
107119
108120export async function slice ( name , mesh , settings , printers , quality , material , updateProgress ) {
121+ if ( ! printers ) throw new Error ( 'Please select a printer' ) ;
122+
109123 const { dimensions } = settings ;
110124 const centerX = dimensions . x / 2 ;
111125 const centerY = dimensions . y / 2 ;
112126
113127 const geometry = mesh . geometry . clone ( ) ;
114128 mesh . updateMatrix ( ) ;
115129
116- const matrix = new THREE . Matrix4 ( ) . makeTranslation ( centerY , 0 , centerX ) . multiply ( mesh . matrix ) ;
130+ const matrix = new Matrix4 ( ) . makeTranslation ( centerY , 0 , centerX ) . multiply ( mesh . matrix ) ;
117131 const { gcode } = await sliceGeometry ( settings , geometry , matrix , false , false , ( { progress } ) => {
118132 updateProgress ( {
119133 action : progress . action ,
0 commit comments