This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutils.js
95 lines (84 loc) · 1.93 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* @fileoverview ThreeJS scene utilities
*/
//Imports
import {state} from '@/assets/scene';
import GCodeParser from '@/assets/gcode-parser';
/**
* Update various scene properties
*/
const update = {
/**
* @function Update bed
*/
bed: bed =>
{
const {X, Y} = bed;
state.plane.scale.set(X, Y, 1);
},
/**
* @function Update GCODE
* @param {String} raw Raw GCODE
* @param {Object} theme Theme
* @returns {Promise<void>}
*/
gcode: async (raw, theme) =>
{
const parser = new GCodeParser(
theme.extrusionColor,
theme.pathColor
);
const object = await parser.parse(raw);
//Add to scene
state.scene.add(object.extrusion);
state.scene.add(object.path);
//Save for later manipulation
state.object = object;
},
/**
* @function Update object position
* @param {Object} position Position
*/
position: position =>
{
const {X, Y, Z} = position;
state.object.extrusion.position.set(X, Y, Z);
state.object.path.position.set(X, Y, Z);
},
/**
* @function Update object rotation
* @param {Object} rotation Rotation
*/
rotation: rotation =>
{
let {X, Y, Z} = rotation;
X *= Math.PI / 180;
Y *= Math.PI / 180;
Z *= Math.PI / 180;
state.object.extrusion.rotation.set(X, Y, Z);
state.object.path.rotation.set(X, Y, Z);
},
/**
* @function Update object scale
* @param {Object} scale Scale
*/
scale: scale =>
{
const {X, Y, Z} = scale;
state.object.extrusion.scale.set(Z, X, Y);
state.object.path.scale.set(Z, X, Y);
},
/**
* @function Update scene theme
* @param {Object} theme Theme
*/
theme: theme =>
{
state.object.extrusion.material.color.set(theme.extrusionColor);
state.object.path.material.color.set(theme.pathColor);
state.plane.material.color.set(theme.bedColor);
state.scene.background.set(theme.backgroundColor);
}
};
//Export
export default {update};