267 |
268 |
269 |
270 |
731 |
732 |
733 |
--------------------------------------------------------------------------------
/GCodeViewer/index.js:
--------------------------------------------------------------------------------
1 | import { registerRoute } from '../../routes';
2 | import { registerPluginContextMenuItem, ContextMenuType } from '../index.js';
3 | import GCodeViewer from './GCodeViewer.vue';
4 | import ColorPicker from './ColorPicker.vue';
5 | import Vue from 'vue';
6 | Vue.component('gcodeviewer-color-picker', ColorPicker);
7 |
8 | registerRoute(GCodeViewer, {
9 | Job: {
10 | GCodeViewer: {
11 | icon: 'mdi-rotate-3d',
12 | caption: 'GCode Viewer',
13 | path: '/GCodeViewer',
14 | },
15 | },
16 | });
17 |
18 | registerPluginContextMenuItem('View 3D', '/GCodeViewer', 'mdi-rotate-3d', 'view-3d-model', ContextMenuType.JobFileList);
19 |
--------------------------------------------------------------------------------
/GCodeViewer/viewer/X.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sindarius/DWC_GCodeViewer_Plugin/df5a25cf0e7ea563466c12c59a2059b4a03eca44/GCodeViewer/viewer/X.png
--------------------------------------------------------------------------------
/GCodeViewer/viewer/axes.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | import { DynamicTexture } from '@babylonjs/core/Materials/Textures/dynamicTexture'
4 | import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial'
5 | import { Mesh } from '@babylonjs/core/Meshes/mesh'
6 | import { Color3 } from '@babylonjs/core/Maths/math.color'
7 | import { Vector3 } from '@babylonjs/core/Maths/math.vector'
8 |
9 |
10 | export default class {
11 | constructor(scene) {
12 | this.visible = localStorage.getItem('axesVisible');
13 | if (this.visible === null) {
14 | this.visible = true;
15 | } else {
16 | this.visible = JSON.parse(this.visible);
17 | }
18 |
19 | this.scene = scene;
20 | this.registerClipIgnore = () => {};
21 | this.axesMesh;
22 | this.size = 50;
23 | this.debug = false;
24 | }
25 |
26 | show(visible) {
27 | localStorage.setItem('axesVisible', visible);
28 | if (this.axesMesh) {
29 | this.axesMesh.setEnabled(visible);
30 | }
31 | }
32 |
33 | makeTextPlane(text, color, size) {
34 | var dynamicTexture = new DynamicTexture('DynamicTexture', 50, this.scene, true);
35 | dynamicTexture.hasAlpha = true;
36 | dynamicTexture.drawText(text, 5, 40, 'bold 36px Arial', color, 'transparent', true);
37 | var plane = Mesh.CreatePlane('TextPlane', size, this.scene, true);
38 | plane.material = new StandardMaterial('TextPlaneMaterial', this.scene);
39 | plane.material.backFaceCulling = false;
40 | plane.material.specularColor = new Color3(0, 0, 0);
41 | plane.material.diffuseTexture = dynamicTexture;
42 | return plane;
43 | }
44 |
45 | resize(size) {
46 | this.size = size;
47 | this.axesMesh.dispose(false, true);
48 | this.render();
49 | }
50 |
51 | render() {
52 | if (this.debug) return;
53 | if (this.axesMesh && !this.axesMesh.isDisposed()) {
54 | return;
55 | }
56 |
57 | this.axesMesh = new Mesh('axis');
58 | this.registerClipIgnore(this.axesMesh);
59 |
60 | var axisX = Mesh.CreateLines('axisX', [Vector3.Zero(), new Vector3(this.size, 0, 0), new Vector3(this.size * 0.95, 0.05 * this.size, 0), new Vector3(this.size, 0, 0), new Vector3(this.size * 0.95, -0.05 * this.size, 0)], this.scene);
61 | axisX.color = new Color3(1, 0, 0);
62 | axisX.parent = this.axesMesh;
63 | var xChar = this.makeTextPlane('X', 'red', this.size / 10);
64 | xChar.position = new Vector3(0.9 * this.size, 0.05 * this.size, 0);
65 | xChar.parent = this.axesMesh;
66 |
67 | var axisY = Mesh.CreateLines('axisY', [Vector3.Zero(), new Vector3(0, this.size, 0), new Vector3(-0.05 * this.size, this.size * 0.95, 0), new Vector3(0, this.size, 0), new Vector3(0.05 * this.size, this.size * 0.95, 0)], this.scene);
68 | axisY.color = new Color3(0, 1, 0);
69 | axisY.parent = this.axesMesh;
70 |
71 | var yChar = this.makeTextPlane('Z', 'green', this.size / 10);
72 | yChar.position = new Vector3(0, 0.9 * this.size, -0.05 * this.size);
73 | yChar.parent = this.axesMesh;
74 |
75 | var axisZ = Mesh.CreateLines('axisZ', [Vector3.Zero(), new Vector3(0, 0, this.size), new Vector3(0, -0.05 * this.size, this.size * 0.95), new Vector3(0, 0, this.size), new Vector3(0, 0.05 * this.size, this.size * 0.95)], this.scene);
76 | axisZ.color = new Color3(0, 0, 1);
77 | axisZ.parent = this.axesMesh;
78 |
79 | var zChar = this.makeTextPlane('Y', 'blue', this.size / 10);
80 | zChar.position = new Vector3(0, 0.05 * this.size, 0.9 * this.size);
81 | zChar.parent = this.axesMesh;
82 |
83 | this.axesMesh.setEnabled(this.visible);
84 | this.axesMesh.getChildren().forEach((mesh) => this.registerClipIgnore(mesh));
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/GCodeViewer/viewer/bed.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | import { Color3, Color4 } from '@babylonjs/core/Maths/math.color'
4 | import { Vector3, Quaternion } from '@babylonjs/core/Maths/math.vector'
5 | import { Space } from '@babylonjs/core/Maths/math.axis'
6 | import {StandardMaterial } from '@babylonjs/core/Materials/standardMaterial'
7 | import { HighlightLayer } from '@babylonjs/core/Layers/highlightLayer'
8 | import { MeshBuilder} from '@babylonjs/core/Meshes/meshBuilder'
9 |
10 | import { GridMaterial } from '@babylonjs/materials/grid/gridMaterial';
11 |
12 | export const RenderBedMode = {
13 | bed: 0,
14 | box: 1,
15 | };
16 |
17 | export default class {
18 | constructor(scene) {
19 | this.buildVolume = {
20 | x: {
21 | min: 0,
22 | max: 100,
23 | },
24 | y: {
25 | min: 0,
26 | max: 100,
27 | },
28 | z: {
29 | min: 0,
30 | max: 100,
31 | },
32 | };
33 |
34 | var buildVol = localStorage.getItem('buildVolume');
35 | if (buildVol !== null) {
36 | this.buildVolume = JSON.parse(buildVol);
37 | }
38 |
39 | this.renderMode = Number.parseInt(localStorage.getItem('renderBedMode')); //0 plane 1 cube extents
40 | if (!this.renderMode) {
41 | this.renderMode = RenderBedMode.bed;
42 | }
43 |
44 | this.bedMesh;
45 | this.isDelta = false;
46 | this.scene = scene;
47 | this.registerClipIgnore = () => {};
48 | this.bedLineColor = '#0000FF';
49 |
50 | /*
51 | this.planeMaterial = new StandardMaterial('planeMaterial', this.scene);
52 | this.planeMaterial.alpha = 1;
53 | this.planeMaterial.diffuseColor = new Color3(0.25, 0.25, 0.25);
54 | this.planeMaterial.specularColor = new Color3(0.1, 0.1, 0.1);
55 | */
56 |
57 | if (!this.getBedColor()) {
58 | this.setBedColor('#0000FF');
59 | }
60 |
61 | this.planeMaterial = this.buildGridMaterial();
62 | this.boxMaterial = new StandardMaterial('bedBoxMaterial', this.scene);
63 | this.boxMaterial.alpha = 0;
64 | this.debug = false;
65 | }
66 |
67 | setRenderMode(renderBedMode) {
68 | this.renderMode = renderBedMode;
69 | localStorage.setItem('renderBedMode', this.renderMode);
70 | if (this.bedMesh) {
71 | this.scene.removeMesh(this.bedMesh);
72 | this.bedMesh.dispose(false, true);
73 | }
74 | this.buildBed();
75 | }
76 | buildBed() {
77 | if (this.debug) return;
78 | if (this.bedMesh && this.bedMesh.isDisposed()) {
79 | this.bedMesh = null;
80 | }
81 | if (this.bedMesh) return this.bedMesh;
82 |
83 | switch (this.renderMode) {
84 | case RenderBedMode.bed:
85 | this.buildFlatBed();
86 | break;
87 | case RenderBedMode.box:
88 | this.buildBox();
89 | break;
90 | }
91 | return this.bedMesh;
92 | }
93 | setDelta(isDelta) {
94 | this.isDelta = isDelta;
95 | this.setRenderMode(this.renderMode);
96 | }
97 | buildFlatBed() {
98 | let bedCenter = this.getCenter();
99 | let bedSize = this.getSize();
100 | if (this.isDelta) {
101 | let radius = Math.abs(this.buildVolume.x.max - this.buildVolume.x.min) / 2;
102 | this.bedMesh = MeshBuilder.CreateDisc('BuildPlate', { radius: radius }, this.scene);
103 | this.bedMesh.rotationQuaternion = new Quaternion.RotationAxis(new Vector3(1, 0, 0), Math.PI / 2);
104 | this.bedMesh.material = this.planeMaterial;
105 | } else {
106 | let width = bedSize.x;
107 | let depth = bedSize.y;
108 | this.bedMesh = MeshBuilder.CreatePlane('BuildPlate', { width: width, height: depth }, this.scene);
109 | this.bedMesh.material = this.planeMaterial;
110 | this.bedMesh.rotationQuaternion = new Quaternion.RotationAxis(new Vector3(1, 0, 0), Math.PI / 2);
111 | this.bedMesh.translate(new Vector3(bedCenter.x, 0, bedCenter.y), 1, Space.WORLD);
112 | }
113 | this.registerClipIgnore(this.bedMesh);
114 | }
115 | getCenter() {
116 | return {
117 | x: (this.buildVolume.x.max + this.buildVolume.x.min) / 2,
118 | y: (this.buildVolume.y.max + this.buildVolume.y.min) / 2,
119 | z: (this.buildVolume.z.max + this.buildVolume.z.min) / 2,
120 | };
121 | }
122 | getSize() {
123 | return {
124 | x: Math.abs(this.buildVolume.x.max - this.buildVolume.x.min),
125 | y: Math.abs(this.buildVolume.y.max - this.buildVolume.y.min),
126 | z: Math.abs(this.buildVolume.z.max - this.buildVolume.z.min),
127 | };
128 | }
129 | buildBox() {
130 | let bedSize = this.getSize();
131 | let bedCenter = this.getCenter();
132 | if (this.isDelta) {
133 | this.bedMesh = MeshBuilder.CreateCylinder(
134 | 'bed',
135 | {
136 | diameterTop: bedSize.x,
137 | diameterBottom: bedSize.x,
138 | height: bedSize.z,
139 | },
140 | this.scene
141 | );
142 | this.bedMesh.position.x = bedCenter.x;
143 | this.bedMesh.position.y = bedCenter.z;
144 | this.bedMesh.position.z = bedCenter.x;
145 | this.bedMesh.alpha = 0;
146 | this.bedMesh.diffuseColor = new Color4(0, 0, 0, 0);
147 | this.bedMesh.isPickable = false;
148 | this.bedMesh.enableEdgesRendering(undefined, true);
149 |
150 | this.bedMesh.renderingGroupId = 2;
151 | this.scene.setRenderingAutoClearDepthStencil(2, false, false, false);
152 |
153 | var hl = new HighlightLayer('hl', this.scene, { isStroke: true, blurTextureSizeRatio: 3 });
154 | hl.addMesh(this.bedMesh,this.getBedColor4());
155 |
156 | this.bedMesh.onBeforeRenderObservable.add(() => {
157 | this.scene.getEngine().setColorWrite(false);
158 | });
159 |
160 | this.bedMesh.onAfterRenderObservable.add(() => {
161 | this.scene.getEngine().setColorWrite(true);
162 | });
163 |
164 | this.registerClipIgnore(this.bedMesh);
165 | } else {
166 | this.bedMesh = MeshBuilder.CreateBox(
167 | 'bed',
168 | {
169 | width: bedSize.x,
170 | depth: bedSize.y,
171 | height: bedSize.z,
172 | },
173 | this.scene
174 | );
175 | let center = this.getCenter();
176 | this.bedMesh.position.x = center.x - this.buildVolume.x.min;
177 | this.bedMesh.position.y = center.z - this.buildVolume.z.min;
178 | this.bedMesh.position.z = center.y - this.buildVolume.y.min;
179 | this.bedMesh.diffuseColor = new Color4(0, 0, 0, 0);
180 | this.bedMesh.enableEdgesRendering();
181 | this.bedMesh.edgesWidth = 100;
182 | this.bedMesh.material = this.boxMaterial;
183 | this.bedMesh.isPickable = false;
184 | this.bedMesh.edgesColor = this.getBedColor4();
185 |
186 | this.registerClipIgnore(this.bedMesh);
187 | }
188 | }
189 | setVisibility(visibility) {
190 | if (this.bedMesh) {
191 | this.bedMesh.setEnabled(visibility);
192 | }
193 | }
194 | commitBedSize() {
195 | localStorage.setItem('buildVolume', JSON.stringify(this.buildVolume));
196 | this.setRenderMode(this.renderMode);
197 | }
198 | buildGridMaterial() {
199 | let gridMaterial = new GridMaterial('bedMaterial', this.scene);
200 | gridMaterial.mainColor = new Color4(0, 0, 0, 0);
201 | gridMaterial.lineColor = Color3.FromHexString(this.getBedColor());
202 | gridMaterial.gridRatio = 5;
203 | gridMaterial.opacity = 0.8;
204 | gridMaterial.majorUnitFrequency = 10;
205 | gridMaterial.minorUnitVisibility = 0.6;
206 | gridMaterial.gridOffset = new Vector3(0, 0, 0);
207 | return gridMaterial;
208 | }
209 | getBedColor() {
210 | return localStorage.getItem('bedLineColor');
211 | }
212 | setBedColor(color) {
213 | localStorage.setItem('bedLineColor', color);
214 | if (this.planeMaterial) {
215 | this.planeMaterial = this.buildGridMaterial();
216 | this.dispose();
217 | this.buildBed();
218 | }
219 | }
220 | getBedColor4(){
221 | return Color4.FromHexString(this.getBedColor().padEnd(9,'F'));
222 | }
223 | dispose() {
224 | this.bedMesh.dispose(false, true);
225 | }
226 | }
227 |
--------------------------------------------------------------------------------
/GCodeViewer/viewer/buildobjects.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | import * as d3 from 'd3';
4 |
5 | import { Vector3 } from '@babylonjs/core/Maths/math.vector'
6 | import { Color3, Color4 } from '@babylonjs/core/Maths/math.color'
7 | import { Texture } from '@babylonjs/core/Materials/Textures/texture'
8 | import { Mesh } from '@babylonjs/core/Meshes/mesh'
9 | import { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder'
10 | import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial'
11 | import { PointerEventTypes } from '@babylonjs/core/Events/pointerEvents'
12 |
13 |
14 | export default class {
15 | constructor(scene) {
16 | this.scene = scene;
17 | this.checkerBoard = 'iVBORw0KGgoAAAANSUhEUgAAAQEAAAEBCAIAAAD3joeqAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAALnSURBVHhe7dZBEYQwFAVBWBtogAv+IhIEsZd4yGG6L/lPwFRl31jqPM/neeZghd98oUoD1GmAOg1QpwHqNECdBqjTAHUaoE4D1GmAOg1QpwHqNECdBqjTAHUaoE4D1GmAOg1QpwHqNECdBqjTAHUaoE4D1GmAOg1QpwHqNECdBqjTAHUaoE4D1GmAOg1QpwHqNECdBqjTAHUaoE4D1GmAOg1QpwHqNECdBqjTAHUaoE4D1GmAOg1QpwHqNECdBqjTAHUaoE4D1GmAOg1QpwHqNECdBqjTAHUaoE4D1GmAOg1QpwHqNECdBqjTAHUaoE4D1GmAOg1QpwHqNECdBqjTAHUaoE4D1GmAOg1QpwHqNECdBqjTAHUaoE4D1GmAOg1QpwHqNECdBqjTAHUaoE4D1GmAOg1QpwHqNECdBqjTAHUaoE4D1GmAOg1QpwHqNECdBqjTAHUaoE4D1GmAOg1QpwHqNECdBqjTAHUaoE4D1GmAOg1QpwHqNECdBqjb7/ueJyscxzHGmIMV9u/75skK7/te1zUHK/gLUacB6jRAnQao0wB1GqBOA9RpgDoNUKcB6jRAnQao0wB1GqBOA9RpgDoNUKcB6jRAnQao0wB1GqBOA9RpgDoNUKcB6jRAnQao0wB1GqBOA9RpgDoNUKcB6jRAnQao0wB1GqBOA9RpgDoNUKcB6jRAnQao0wB1GqBOA9RpgDoNUKcB6jRAnQao0wB1GqBOA9RpgDoNUKcB6jRAnQao0wB1GqBOA9RpgDoNUKcB6jRAnQao0wB1GqBOA9RpgDoNUKcB6jRAnQao0wB1GqBOA9RpgDoNUKcB6jRAnQao0wB1GqBOA9RpgDoNUKcB6jRAnQao0wB1GqBOA9RpgDoNUKcB6jRAnQao0wB1GqBOA9RpgDoNUKcB6jRAnQao0wB1GqBOA9RpgDoNUKcB6jRAnQao0wB1GqBOA9RpgDoNUKcB6jRAnQao0wB1GqBOA7Rt2x+drw1hSNi5LQAAAABJRU5ErkJggg==';
18 | this.xmark = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPQAAADPCAMAAAD1TAyiAAAAkFBMVEX39/eZAAD8//+TAACWAACRAAD4+vr5/PyaAAD39fX18vLy6enr29v18PDm0dG1Y2PewMDYtbWuUFDkzc2jLy+iKSnLlpbRpKS/enrIjo6hJCTbu7u8dHSxWFi4a2vEh4eoOzudEhKdEBDPn5+pQUHq2dmsSUmnODjUqqqhJye0YGCeGRnIk5OrTEy6b2+fHh7/wUBWAAAIiElEQVR4nO2d2ULbOhRF4yNFijNAQiCBMoShhBTo7f//3bUc2kLIIOnsI6ut90v7hLS8ZCVWZJ1Op02bNm3atGnTps0fGGOsizGm6Z4kiiHqDMeT+Wo1vxwPS6IGwI2lqt3qqlf/WPH2DZnpYqnVz3SL5cXUpuWumnucL66Xp1WW14v5UUlWsDlDw0VPaV28i9aqWAyTYRsqJ8fVRdfrXlT/VP9/nvTFOkDDY/UB+Be4uhmSUKMbXRgsis990EqfD0Q6YMvz7cjrZs9Ledm2v7MLVQdG+EFO07udyC7q5UhaNk2KPV3QxSW6A/TQ3Yfs0n0QpTblsTrQgRvsRyhdHWiwln0lSG0Hp3tHWi37dASkpkMX+Y36WIzaDvVBZjeZD2HUXp5r6nMhajPw64C+R7mmC09mMeqK2cNzTX2HoaaJN7MQtRn0PJkr6q+ITy4zCGAWmc2st2dYB2gZ0GIhMJvZR3/PdQcu2a7tKkg0nrqatwM70Otz2yx7gU2Cqe1jcPuaO6/QLFQ0ljrcs2t/wJvBTXiTSGr7GMHMVW0uI0TjqKM8u+ZHnFbpOK5VDHWcZ9f6ijWBxzVaU7MXr2I9V+N7ybjk5ihudNfUJ8wHPZrGMlfUjPFt5/HQheZRc5gLNY5vmv5jNMyjpinjehf6Nf6mpu8c6Io6+r5mea5afo6/qc0Lp2WGa57nKreMmYzXcrRrpucqvXjmzsHVwMPUEa7Znqt2m4SOoeZ7Lopuo9CFvg38GYDGbM88aP4ld9SdEGoIc6HimeOesTYT5JrGgNFVJR6aviJUF/rJ2zXGc1F8Y3w5iX3I2oi3a5RnfR3/OW0fMNC+rlGeC71gfCPjf2D+7IXPbAZjLtSE8UBdgkx7ucYx81bJ6BpHfdrf3xGKXJraljPOuk3sGtm26LO9s1nQr0eHmprx1vvDl713d+V0DzVdYubtOsw1YHrFXf/K9c4RThMgM+dpuk4fdlMXe1wj7+dK9BFzTZI4y2SfssM11DPrm8lb7OG9HiEd2uYa67lQ/D0YZgjt0RbXWM+FmiF+oF5B+6RfNqZWCv4xeP/f5yyPvevVObZXdx+oaQ69pkXB/MnyV7+usdTvXWMnSjdzo3ZLWjD1b9doz2qM2xBgT2So0Z670P2hMq7hnsF7YiVc5+25pvbbH+qbajbL3bML3YBd++++9IqaSmzRBFOHbAP0iAwznhoZKeacqeWY86WWZM6VWpY5T2ppZrf5JjdqeWb4kyY7WvyFsJra9z2WJNGwZ8kD1Bm5TsWck2vcmoEHdSau03muqbNwndJzTZ2B67Se86BO7bmmvgCv3YZmmJ456B3Mv4a5YdcNMTfpWjfG3KDrBpkbc90oc0OuG2ZuwLVuntnrNBAo8/2geWZHndB1xZzHeWAJXWfDnNB1RszJXGfFnMj1xm6V5pPAtdaZMeN3Unxmzs2zC3gP3CfmL8gjqGARpd6zg7jZCFLrL5kyC1Jn69kF+U7Ce+Z8PbuIuM7as4uA68w9u9AEu2uoKJ6yZ+4Yc4Zl1qs0p88yYvpPaNMqd2pTQl/5WEf4GFZuTAn37AJ5LUMqIp5dMnYt5NlF5Upt+kKeXbp5jnCxsb1Olq7N6Ickc5auTf+LLHOGrsU9u2TmOoFnF/WaEXUSzzX1RTbUiTzX1Lm4Tua5ps7DdVLmTKjNwKeEwN9F7X+cPo666fvaDO5TMzfuOqSEAJKacQgVgLkBzzW1VMEPH+ZGPDdK3ZjnBqltc54bo7bD5J9VjVPHH7P+51JXnptPYuoMPLskpc7Cs4u6SUadiWcXwWJsm8xNo75LItfRJUFkksQ1HWXFnMR1dswJXGfILO46S2Zh15ky1+WL/jlmV75IiJoYNZXEo05E9l0hymN86Cb2cVzENU3BR6bNRi9garhrQOmXD+nOCL3cpNGu8Z4Jv0kF/Mkl4Nn9WTP6hqVG/gpgJTyvqbGuu2PYCDfg5+d32yjQrgvU2y2mDzy4v9jY9Ai+rzXqtgbWpXDZ2C5jRmfIP9/lHl3/xow9f/vTRmasa1Ydz9+BlioouvNPncK6ZlcpcKFz6OjbtmHdjDAlquog7urAkvIHssVz3UgJpOaVJK5Dr0DRWz3X1B0cNauC0jr2HtWZnZ5rapxr/vjGVcza47luCOeaU8izDi1ww27/Szc46i63+AjdYjriccw6jJpTh7lOH1ag7fAx6yhq9cCbyWC3tNdx+qZzC6keytxwZUGvi3oep286iK/5mvmrtcV8SnuXTTB0wm+QC42ZvEPKJli+azY04ot3WHkMvuscoEPLY7Af37kTGQC6G1zih+tazXkfWfx7OqasEbNUFffLiZ0xoeNKOfEK+XSZx/1YZkm+2PJVLNcvzG+hzG9k8SW76Dm6Yf6jZcmB5pQpi6fmLyJwCqzzSrNFU6s+k5kzfWtmOTqKK9AFWBiMv6k1uyRIHDViCZheIpkBJUFiRjigUG3V8CxukEHKoES4hqz1d0YxN7UClX4Jdq2vMEVbIw44xpW7CS3adM+eutcpg5lRnl3CCn50p6Af5W1otXdsWaOQ0hfAoyLoJui2Rpdy8neNfaUj6K1w+JHjvq6xm4HNwB9aomwCLXxuMPSrO/bRc4QJHS3vc+Qu/vVi67f/V/eEjtOn8YEzCLREoVo79Dj5QP8QO6LY9vcuK6jlQGKbux08HRpiail47KOhy7tdHVB6RTItG7P/o0OrC6GW32JpdaY+Dzet7mcduXoNNL7fja1u5SstWju90kr/vtG0Vur6siPasDUPxVZsrV6kBtjHGLJHDzdf77RL7/Z6Ni7l26Vy/qQ2prTqai8nJllBEGOJyr5LSWTTnB1r6XH2vVBK1RdbqW7veT6gHGqgiKa61J3H8fzi9fX1YjIedFJd7sZjjF3H/CPAbdq0adOmTZs2bbD5H8lJpKRvNiuNAAAAAElFTkSuQmCC';
19 | this.buildObjectMeshes = new Array();
20 | this.labels = new Array();
21 | this.labelSVGS = new Array();
22 | this.baseMaterial;
23 | this.highlightMaterial;
24 | this.cancelledMaterial;
25 | this.cancelledHighlightMaterial;
26 | this.showCancelObjects = false;
27 | this.objectCallback;
28 | this.renderFailedCallback;
29 | this.labelCallback;
30 | this.registerClipIgnore;
31 | this.getMaxHeight;
32 | this.alphaLevel = 0.5;
33 |
34 | this.observableControls = null;
35 |
36 | this.showLabel = localStorage.getItem('showObjectLabels');
37 | if (this.showLabel === null) {
38 | this.showLabel = true;
39 | } else {
40 | this.showLabel = JSON.parse(this.showLabel);
41 | }
42 |
43 | this.rebuildMaterials();
44 | }
45 |
46 | setBuildMaterial(name, color, alpha) {
47 | if (!alpha) {
48 | alpha = this.alphaLevel;
49 | }
50 |
51 | let material = new StandardMaterial(name, this.scene);
52 | material.diffuseColor = color;
53 | material.specularColor = new Color3(0.0, 0.0, 0.0);
54 | material.alpha = alpha;
55 | material.needAlphaTesting = () => true;
56 | material.separateCullingPass = true;
57 | material.backFaceCulling = true;
58 | return material;
59 | }
60 | rebuildMaterials() {
61 | this.baseMaterial = this.setBuildMaterial('BuildObjectBaseMaterial', new Color4(0.1, 0.5, 0.1), 0.25);
62 | this.highlightMaterial = this.setBuildMaterial('BuildObjectHighlightMateria', new Color3(0.8, 0.8, 0.8));
63 | this.cancelledMaterial = this.setBuildMaterial('BuildObjectHighlightMateria', new Color3(1, 0, 0), 0.4);
64 | this.cancelledHighlightMaterial = this.setBuildMaterial('BuildObjectHighlightMateria', new Color3(1, 1, 0), 0.6);
65 | let material = new Texture.CreateFromBase64String(this.xmark, 'checkerboard', this.scene);
66 | this.cancelledMaterial.diffuseTexture = material;
67 | this.cancelledHighlightMaterial.diffuseTexture = material;
68 | }
69 | loadObjectBoundaries(boundaryObjects) {
70 | this.rebuildMaterials();
71 | if (this.buildObjectMeshes.length > 0) {
72 | for (let i = 0; i < this.buildObjectMeshes.length; i++) {
73 | this.buildObjectMeshes[i].dispose();
74 | }
75 | this.labelSVGS.forEach((label) => window.URL.revokeObjectURL(label));
76 | this.buildObjectMeshes = new Array();
77 | this.labels = new Array();
78 | }
79 |
80 | if (!boundaryObjects) {
81 | return;
82 | }
83 |
84 | for (let cancelObjectIdx = 0; cancelObjectIdx < boundaryObjects.length; cancelObjectIdx++) {
85 | let cancelObject = boundaryObjects[cancelObjectIdx];
86 |
87 | let buildObject = MeshBuilder.CreateTiledBox(
88 | 'OBJECTMESH:' + cancelObject.name,
89 | {
90 | pattern: Mesh.CAP_ALL,
91 | alignVertical: Mesh.TOP,
92 | alignHorizontal: Mesh.LEFT,
93 | tileHeight: 4,
94 | tileWidth: 4,
95 | width: Math.abs(cancelObject.x[1] - cancelObject.x[0]),
96 | height: this.getMaxHeight() + 10,
97 | depth: Math.abs(cancelObject.y[1] - cancelObject.y[0]),
98 | sideOrientation: Mesh.FRONTSIDE,
99 | },
100 | this.scene
101 | );
102 |
103 | buildObject.position.x = (cancelObject.x[1] + cancelObject.x[0]) / 2;
104 | buildObject.position.y = this.getMaxHeight() / 2 - 4;
105 | buildObject.position.z = (cancelObject.y[1] + cancelObject.y[0]) / 2;
106 | buildObject.alphaIndex = 5000000;
107 | cancelObject.index = cancelObjectIdx;
108 | buildObject.metadata = cancelObject;
109 | buildObject.enablePointerMoveEvents = true;
110 | this.setObjectTexture(buildObject);
111 | buildObject.setEnabled(this.showCancelObjects);
112 | this.registerClipIgnore(buildObject);
113 | this.buildObjectMeshes.push(buildObject);
114 |
115 | //generate a label
116 |
117 | var textPlane = this.makeTextPlane(cancelObject.name, cancelObject.cancelled ? 'yellow' : 'white', 20);
118 | textPlane.position = new Vector3(0, this.getMaxHeight() / 2 + 10, 0);
119 | textPlane.isPickable = false;
120 | textPlane.metadata = cancelObject;
121 | textPlane.parent = buildObject;
122 | textPlane.setEnabled(this.showLabel);
123 | this.labels.push(textPlane);
124 | }
125 | }
126 | makeTextPlane(text, color, size) {
127 | /*
128 | var dynamicTexture = new DynamicTexture('DynamicTexture', { width: text.length * 20, height: 200 }, this.scene, true);
129 | dynamicTexture.hasAlpha = true;
130 | dynamicTexture.drawText(text, null, null, 'bold 24px Roboto', color, 'transparent', true);*/
131 | var svg = d3
132 | .create('svg')
133 | .attr('width', 800)
134 | .attr('height', 200)
135 | .attr('fill', 'none');
136 |
137 | svg
138 | .append('text')
139 | .attr('x', 400)
140 | .attr('y', 100)
141 | .attr('font-family', 'Verdana')
142 | .attr('font-size', '50px')
143 | .attr('text-anchor', 'middle')
144 | .attr('alignment-baseline', 'middle')
145 | .attr('fill', 'black')
146 | .attr('stroke', color)
147 | .attr('stroke-width', 2)
148 | .attr('text-rendering', 'optimizeLegibility')
149 | .text(text);
150 |
151 | var html = svg
152 | .attr('title', 'test2')
153 | .attr('version', 1.1)
154 | .attr('xmlns', 'http://www.w3.org/2000/svg')
155 | .node(); //.parentNode.innerHTML;
156 |
157 | var doctype = '' + '';
158 |
159 | var source = new XMLSerializer().serializeToString(html);
160 | var blob = new Blob([doctype + source], { type: 'image/svg+xml' });
161 | var url = window.URL.createObjectURL(blob);
162 | this.labelSVGS.push(url);
163 |
164 | let plane = MeshBuilder.CreatePlane('TextPlane', { width: size, height: 8 }, this.scene);
165 | plane.material = new StandardMaterial('TextPlaneMaterial', this.scene);
166 | plane.material.backFaceCulling = false;
167 | plane.material.specularColor = new Color3(0, 0, 0);
168 | plane.material.diffuseTexture = new Texture(url, this.scene); //dynamicTexture;
169 | plane.material.diffuseTexture.hasAlpha = true;
170 | plane.billboardMode = 7;
171 | this.registerClipIgnore(plane);
172 | return plane;
173 | }
174 |
175 | buildObservables() {
176 | if (this.observableControls) {
177 | return;
178 | }
179 |
180 | this.observableControls = this.scene.onPointerObservable.add((pointerInfo) => {
181 | let pickInfo = pointerInfo.pickInfo;
182 | switch (pointerInfo.type) {
183 | case PointerEventTypes.POINTERDOWN:
184 | {
185 | this.cancelHitTimer = Date.now();
186 | }
187 | break;
188 | case PointerEventTypes.POINTERUP:
189 | {
190 | if (Date.now() - this.cancelHitTimer > 200) {
191 | return;
192 | }
193 | this.handleClick(pickInfo);
194 | }
195 | break;
196 | case PointerEventTypes.POINTERMOVE: {
197 | this.handlePointerMove(pickInfo);
198 | }
199 | }
200 | });
201 | }
202 |
203 | clearObservables() {
204 | if (this.observableControls) {
205 | this.scene.onPointerObservable.remove(this.observableControls);
206 | this.observableControls = null;
207 | }
208 | }
209 |
210 | showObjectSelection(visible) {
211 | this.showCancelObjects = visible;
212 | this.buildObjectMeshes.forEach((mesh) => mesh.setEnabled(visible));
213 |
214 | if (visible) {
215 | this.buildObservables();
216 | } else {
217 | this.clearObservables();
218 | }
219 | }
220 | setObjectTexture(mesh) {
221 | if (mesh.metadata.cancelled) {
222 | mesh.material = this.cancelledMaterial;
223 | mesh.enableEdgesRendering();
224 | mesh.edgesWidth = 15.0;
225 | mesh.edgesColor = new Color4(1, 0, 0, 1);
226 | } else {
227 | mesh.material = this.baseMaterial;
228 | mesh.enableEdgesRendering();
229 | mesh.edgesWidth = 15.0;
230 | mesh.edgesColor = new Color4(0, 1, 0, 1);
231 | }
232 | }
233 | handleClick(pickInfo) {
234 | if (!this.showCancelObjects) return;
235 | if (pickInfo.hit && pickInfo.pickedMesh && pickInfo.pickedMesh.name.includes('OBJECTMESH') && this.objectCallback) {
236 | this.objectCallback(pickInfo.pickedMesh.metadata);
237 | }
238 | }
239 | handlePointerMove(pickInfo) {
240 | if (!this.showCancelObjects) return;
241 | this.buildObjectMeshes.forEach((mesh) => this.setObjectTexture(mesh));
242 | if (pickInfo.hit && pickInfo.pickedMesh && pickInfo.pickedMesh.name.includes('OBJECTMESH')) {
243 | pickInfo.pickedMesh.material = pickInfo.pickedMesh.metadata.cancelled ? this.cancelledHighlightMaterial : this.highlightMaterial;
244 | if (this.labelCallback) {
245 | this.labelCallback(pickInfo.pickedMesh.metadata.name);
246 | }
247 | } else {
248 | if (this.labelCallback) {
249 | this.labelCallback('');
250 | }
251 | }
252 | }
253 | showLabels(visible) {
254 | localStorage.setItem('showObjectLabels', visible);
255 | this.showLabel = visible;
256 | this.labels.forEach((label) => label.setEnabled(visible));
257 | }
258 | }
259 |
--------------------------------------------------------------------------------
/GCodeViewer/viewer/checkerboard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sindarius/DWC_GCodeViewer_Plugin/df5a25cf0e7ea563466c12c59a2059b4a03eca44/GCodeViewer/viewer/checkerboard.png
--------------------------------------------------------------------------------
/GCodeViewer/viewer/gcodeline.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-unused-vars */
2 | 'use strict';
3 | import { Color4 } from '@babylonjs/core/Maths/math.color'
4 | import { Mesh } from '@babylonjs/core/Meshes/mesh'
5 | import { MeshBuilder} from '@babylonjs/core/Meshes/meshBuilder'
6 |
7 | export default class {
8 | constructor() {
9 | this.start;
10 | this.end;
11 | this.extruding = false;
12 | this.gcodeLineNumber = 0;
13 | this.color;
14 | this.feedRate = 0;
15 | }
16 |
17 | length() {
18 | return this.distanceVector(this.start, this.end);
19 | }
20 |
21 | renderLine(scene) {
22 | var points = [this.start, this.end];
23 | let lineMesh = Mesh.CreateLines('lines', points, scene);
24 | lineMesh.enableEdgesRendering();
25 | lineMesh.edgesWidth = 10;
26 | lineMesh.edgesColor = new Color4(1, 1, 0, 1);
27 | }
28 |
29 | renderLineV2() {
30 | var tube = MeshBuilder.CreateTube('tube', {
31 | path: [this.start, this.end],
32 | radius: 0.2,
33 | tesselation: 4,
34 | sideOrientation: Mesh.FRONTSIDE,
35 | updatable: false,
36 | });
37 | tube.doNotSyncBoundingInfo = true;
38 | return tube;
39 | }
40 |
41 | distanceVector(v1, v2) {
42 | let dx = v1.x - v2.x;
43 | let dy = v1.y - v2.y;
44 | let dz = v1.z - v2.z;
45 |
46 | return Math.sqrt(dx * dx + dy * dy + dz * dz);
47 | }
48 |
49 | renderLineV3(p, invisible) {
50 | let length = this.distanceVector(this.start, this.end);
51 | let rot2 = Math.atan2(this.end.z - this.start.z, this.end.x - this.start.x);
52 | p.scaling.x = length;
53 | p.rotation.y = -rot2;
54 |
55 | p.position.x = this.start.x + (length / 2) * Math.cos(rot2);
56 | p.position.y = this.start.y;
57 | p.position.z = this.start.z + (length / 2) * Math.sin(rot2);
58 | p.color = this.color;
59 | if (invisible) {
60 | p.materialIndex = 1;
61 | } else {
62 | p.materialIndex = 0;
63 | }
64 |
65 | p.props = {
66 | gcodeLineNumber: this.gcodeLineNumber,
67 | originalColor: this.color,
68 | };
69 | }
70 |
71 | renderParticle(p) {
72 | p.position.x = this.start.x;
73 | p.position.y = this.start.y;
74 | p.position.z = this.start.z;
75 | p.color = this.color;
76 | }
77 |
78 | getPoints() {
79 | return {
80 | points: [this.start, this.end],
81 | colors: [this.color, this.color],
82 | };
83 | }
84 |
85 | getColor() {
86 | if (this.extruding) {
87 | return new Color4(1, 1, 1, 1);
88 | }
89 | return new Color4(1, 0, 0, 1);
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/GCodeViewer/viewer/gcodeprocessor.js:
--------------------------------------------------------------------------------
1 | /*eslint no-useless-escape: 0*/
2 | 'use strict';
3 |
4 | import { Engine } from '@babylonjs/core/Engines/engine'
5 | import { Vector3 } from '@babylonjs/core/Maths/math.vector'
6 | import { Color4 } from '@babylonjs/core/Maths/math.color'
7 | import { VertexBuffer } from '@babylonjs/core/Meshes/buffer'
8 | import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial'
9 | import { SolidParticleSystem } from '@babylonjs/core/Particles/solidParticleSystem'
10 | import { PointsCloudSystem } from '@babylonjs/core/Particles/pointsCloudSystem'
11 | import { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder'
12 |
13 | import gcodeLine from './gcodeline';
14 | import { doArc } from './utils.js'
15 |
16 | export const RenderMode = {
17 | Block: 1,
18 | Line: 2,
19 | Point: 3,
20 | Max: 4,
21 | };
22 |
23 | export const ColorMode = {
24 | Color: 0,
25 | Feed: 1,
26 | };
27 |
28 | export default class {
29 | constructor() {
30 | this.currentPosition = new Vector3(0, 0, 0);
31 | this.currentColor = new Color4(0.25, 0.25, 0.25, 1);
32 | this.renderVersion = RenderMode.Line;
33 | this.absolute = true; //Track if we are in relative or absolute mode.
34 | this.lines = [];
35 | this.travels = [];
36 | this.sps;
37 | this.maxHeight = 0;
38 | this.lineCount = 0;
39 | this.renderMode = '';
40 | this.extruderCount = 5;
41 | this.layerDictionary = {};
42 |
43 | //We'll look at the last 2 layer heights for now to determine layer height.
44 | this.previousLayerHeight = 0;
45 | this.currentLayerHeight = 0;
46 |
47 | //Live Rendering
48 | this.liveTracking = false; //Tracks if we loaded the current job to enable live rendering
49 | this.liveTrackingShowSolid = false; //Flag if we want to continue showing the whole model while rendering
50 |
51 | this.materialTransparency = 0.5;
52 | this.gcodeLineIndex = [];
53 | this.gcodeFilePosition = 0;
54 |
55 | this.refreshTime = 200;
56 | this.timeStamp;
57 |
58 | this.lineLengthTolerance = 0.05;
59 |
60 | this.extruderColors = [
61 | new Color4(0, 1, 1, 1), //c
62 | new Color4(1, 0, 1, 1), //m
63 | new Color4(1, 1, 0, 1), //y
64 | new Color4(0, 0, 0, 1), //k
65 | new Color4(1, 1, 1, 1), //w
66 | ];
67 |
68 | this.progressColor = new Color4(0, 1, 0, 1);
69 |
70 | //scene data
71 | this.lineMeshIndex = 0;
72 | this.scene;
73 | this.renderFuncs = [];
74 |
75 | //Mesh Breaking
76 | this.meshBreakPoint = 20000;
77 |
78 | //average feed rate trimming
79 | this.feedRateTrimming = false;
80 | this.currentFeedRate = 0;
81 | this.feedValues = 0;
82 | this.numChanges = 0;
83 | this.avgFeed = 0;
84 | this.maxFeedRate = 0;
85 | this.minFeedRate = Number.MAX_VALUE;
86 | this.underspeedPercent = 1;
87 |
88 | this.colorMode = Number.parseInt(localStorage.getItem('processorColorMode'));
89 | if (!this.colorMode) {
90 | this.setColorMode(ColorMode.Color);
91 | }
92 |
93 | this.minColorRate = Number.parseInt(localStorage.getItem('minColorRate'));
94 | if (!this.minColorRate) {
95 | this.minColorRate = 1200;
96 | localStorage.setItem('minColorRate', this.minColorRate);
97 | }
98 |
99 | this.maxColorRate = Number.parseInt(localStorage.getItem('maxColorRate'));
100 | if (!this.maxColorRate) {
101 | this.maxColorRate = 3600;
102 | localStorage.setItem('maxColorRate', this.maxColorRate);
103 | }
104 |
105 | this.minFeedColorString = localStorage.getItem('minFeedColor');
106 | if (!this.minFeedColorString) {
107 | this.minFeedColorString = '#0000FF';
108 | }
109 | this.minFeedColor = Color4.FromHexString(this.minFeedColorString.padEnd(9, 'F'));
110 |
111 | this.maxFeedColorString = localStorage.getItem('maxFeedColor');
112 | if (!this.maxFeedColorString) {
113 | this.maxFeedColorString = '#FF0000';
114 | }
115 | this.maxFeedColor = Color4.FromHexString(this.maxFeedColorString.padEnd(9, 'F'));
116 |
117 | //render every nth row
118 | this.everyNthRow = 0;
119 | this.currentRowIdx = -1;
120 | this.currentZ = 0;
121 | this.renderTravels = true;
122 | this.lineVertexAlpha = false;
123 |
124 | this.forceWireMode = localStorage.getItem('forceWireMode');
125 | if (!this.forceWireMode) {
126 | this.forceWireMode = false;
127 | } else {
128 | JSON.parse(this.forceWireMode);
129 | }
130 |
131 | this.spreadLines = false;
132 | this.spreadLineAmount = 10;
133 | this.debug = false;
134 | this.specularColor = new Color4(0.1, 0.1, 0.1, 0.1);
135 |
136 | this.lookAheadLength = 500;
137 | this.cancelLoad = false;
138 |
139 | this.loadingProgressCallback;
140 |
141 | this.hasSpindle = false;
142 | }
143 |
144 | setExtruderColors(colors) {
145 | if (colors === null || colors.length === 0) return;
146 | this.extruderColors = [];
147 | for (var idx = 0; idx < colors.length; idx++) {
148 | var color = colors[idx];
149 |
150 | var extruderColor = Color4.FromHexString(color.padEnd(9, 'F'));
151 | this.extruderColors.push(extruderColor);
152 | }
153 | }
154 |
155 | setProgressColor(color) {
156 | this.progressColor = Color4.FromHexString(color.padEnd(9, 'F'));
157 | }
158 |
159 | getMaxHeight() {
160 | return this.maxHeight;
161 | }
162 |
163 | setRenderQualitySettings(numberOfLines, renderQuality) {
164 | if (renderQuality === undefined) {
165 | renderQuality = 1;
166 | }
167 |
168 | let maxLines = 0;
169 | let renderStartIndex = this.forceWireMode ? 2 : 1;
170 | let maxNRow = 2;
171 |
172 | this.refreshTime = 5000;
173 | this.everyNthRow = 1;
174 | this.renderTravels = true;
175 |
176 | //Render Mode Multipliers
177 | // 12x - 3d
178 | // 2x - line
179 | // 1x - point
180 |
181 | switch (renderQuality) {
182 | //SBC Quality - Pi 3B+
183 | case 1:
184 | {
185 | renderStartIndex = 2;
186 | this.refreshTime = 30000;
187 | maxLines = 25000;
188 | maxNRow = 50;
189 | this.renderTravels = false;
190 | }
191 | break;
192 | //Low Quality
193 | case 2:
194 | {
195 | renderStartIndex = 2;
196 | this.refreshTime = 30000;
197 | maxLines = 500000;
198 | maxNRow = 10;
199 | this.renderTravels = false;
200 | }
201 | break;
202 | //Medium Quality
203 | case 3:
204 | {
205 | maxLines = 1000000;
206 | maxNRow = 3;
207 | }
208 | break;
209 | //High Quality
210 | case 4:
211 | {
212 | maxLines = 15000000;
213 | maxNRow = 2;
214 | }
215 | break;
216 | //Ultra
217 | case 5:
218 | {
219 | maxLines = 25000000;
220 | }
221 | break;
222 | //Max
223 | default: {
224 | this.renderVersion = RenderMode.Block;
225 | this.everyNthRow = 1;
226 | return;
227 | }
228 | }
229 |
230 | for (let renderModeIdx = renderStartIndex; renderModeIdx < 4; renderModeIdx++) {
231 | let vertextMultiplier;
232 | switch (renderModeIdx) {
233 | case 1:
234 | vertextMultiplier = 24;
235 | break;
236 | case 2:
237 | vertextMultiplier = 2;
238 | break;
239 | case 3:
240 | vertextMultiplier = 1;
241 | break;
242 | }
243 |
244 | for (let idx = this.everyNthRow; idx <= maxNRow; idx++) {
245 | if (this.debug) {
246 | console.log('Mode: ' + renderModeIdx + ' NRow: ' + idx + ' vertexcount: ' + (numberOfLines * vertextMultiplier) / idx);
247 | }
248 | if ((numberOfLines * vertextMultiplier) / idx < maxLines) {
249 | this.renderVersion = renderModeIdx;
250 | this.everyNthRow = idx;
251 | return;
252 | }
253 | }
254 | }
255 |
256 | //we couldn't find a working case so we'll set a triage value
257 | console.log('Worst Case');
258 | this.renderVersion = 2;
259 | this.everyNthRow = 20;
260 | }
261 |
262 | initVariables() {
263 | this.currentPosition = new Vector3(0, 0, 0);
264 | this.cancelLoad = false;
265 | this.absolute = true;
266 | this.currentZ = 0;
267 | this.currentRowIdx = -1;
268 | this.gcodeLineIndex = [];
269 | this.lineMeshIndex = 0;
270 | this.lastExtrudedZHeight = 0;
271 | this.previousLayerHeight = 0;
272 | this.currentLayerHeight = 0;
273 | this.minFeedRate = Number.MAX_VALUE;
274 | this.maxFeedRate = 0;
275 | this.hasSpindle = false;
276 | this.currentColor = this.extruderColors[0].clone();
277 | }
278 |
279 | async processGcodeFile(file, renderQuality, clearCache) {
280 | this.initVariables();
281 |
282 | if (renderQuality === undefined || renderQuality === null) {
283 | renderQuality = 4;
284 | }
285 |
286 | if (file === undefined || file === null || file.length === 0) {
287 | return;
288 | }
289 |
290 | var lines = file.split('\n'); //file.split(/\r\n|\n/);
291 | //Get an opportunity to free memory before we strt generating 3d model
292 | if (typeof clearCache === 'function') {
293 | clearCache();
294 | }
295 |
296 | this.lineCount = lines.length;
297 |
298 | if (this.debug) {
299 | console.info(`Line Count : ${this.lineCount}`);
300 | }
301 |
302 | this.setRenderQualitySettings(this.lineCount, renderQuality);
303 |
304 | //set initial color to extruder 0
305 | this.currentColor = this.extruderColors[0].clone();
306 |
307 | lines.reverse();
308 | let filePosition = 0; //going to make this file position
309 | this.timeStamp = Date.now();
310 | while (lines.length) {
311 | if (this.cancelLoad) {
312 | this.cancelLoad = false;
313 | return;
314 | }
315 | var line = lines.pop();
316 | filePosition += line.length + 1;
317 | line.trim();
318 | if (!line.startsWith(';')) {
319 |
320 | this.processLine(line, filePosition);
321 | // this.processLineV2(line, filePosition);
322 |
323 | if (this.loadingProgressCallback) {
324 | this.loadingProgressCallback(filePosition / line.length);
325 | }
326 | }
327 | if (Date.now() - this.timeStamp > 10) {
328 | await this.pauseProcessing();
329 | }
330 | }
331 |
332 | //build the travel mesh
333 | if (this.renderTravels) {
334 | this.createTravelLines(this.scene)
335 | }
336 |
337 | file = {}; //Clear out the file.
338 | }
339 |
340 | pauseProcessing() {
341 | return new Promise((resolve) => setTimeout(resolve)).then(() => {
342 | this.timeStamp = Date.now();
343 | });
344 | }
345 |
346 | async processLine(tokenString, lineNumber) {
347 | //Remove the comments in the line
348 | let commentIndex = tokenString.indexOf(';');
349 | if (commentIndex > -1) {
350 | tokenString = tokenString.substring(0, commentIndex - 1).trim();
351 | }
352 | let tokens;
353 |
354 | tokenString = tokenString.toUpperCase();
355 |
356 | let command = tokenString.match(/[GM]+[0-9.]+/); //|S+
357 |
358 | if (command != null) {
359 | command = command.filter(c => c.startsWith('G') || c.startsWith('M'));
360 | switch (command[0]) {
361 | case 'G0':
362 | case 'G1':
363 | {
364 | tokens = tokenString.split(/(?=[GXYZEF])/);
365 | var line = new gcodeLine();
366 | line.gcodeLineNumber = lineNumber;
367 | line.start = this.currentPosition.clone();
368 | for (let tokenIdx = 1; tokenIdx < tokens.length; tokenIdx++) {
369 | let token = tokens[tokenIdx];
370 | switch (token[0]) {
371 | case 'X':
372 | this.currentPosition.x = this.absolute ? Number(token.substring(1)) : this.currentPosition.x + Number(token.substring(1));
373 | break;
374 | case 'Y':
375 | this.currentPosition.z = this.absolute ? Number(token.substring(1)) : this.currentPosition.z + Number(token.substring(1));
376 | break;
377 | case 'Z':
378 | this.currentPosition.y = this.absolute ? Number(token.substring(1)) : this.currentPosition.y + Number(token.substring(1));
379 | if (this.spreadLines) {
380 | this.currentPosition.y *= this.spreadLineAmount;
381 | }
382 | // this.maxHeight = this.currentPosition.y;
383 | break;
384 | case 'E':
385 | line.extruding = true;
386 | this.maxHeight = this.currentPosition.y; //trying to get the max height of the model.
387 | break;
388 | case 'F':
389 | this.currentFeedRate = Number(token.substring(1));
390 | if (this.currentFeedRate > this.maxFeedRate) {
391 | this.maxFeedRate = this.currentFeedRate;
392 | }
393 | if (this.currentFeedRate < this.minFeedRate) {
394 | this.minFeedRate = this.currentFeedRate;
395 | }
396 |
397 | if (this.colorMode === ColorMode.Feed) {
398 | let ratio = (this.currentFeedRate - this.minColorRate) / (this.maxColorRate - this.minColorRate);
399 | if (ratio >= 1) {
400 | this.currentColor = this.maxFeedColor;
401 | } else if (ratio <= 0) {
402 | this.currentColor = this.minFeedColor;
403 | } else {
404 | this.currentColor = Color4.Lerp(this.minFeedColor, this.maxFeedColor, ratio);
405 | }
406 | }
407 |
408 | break;
409 | }
410 | }
411 |
412 | line.end = this.currentPosition.clone();
413 | if (this.debug) {
414 | console.log(`${tokenString} absolute:${this.absolute}`);
415 | console.log(lineNumber, line);
416 | }
417 |
418 | if (this.feedRateTrimming) {
419 | this.feedValues += this.currentFeedRate;
420 | this.numChanges++;
421 | this.avgFeed = (this.feedValues / this.numChanges) * this.underspeedPercent;
422 | }
423 |
424 | //Nth row exclusion
425 | if (this.everyNthRow > 1 && line.extruding) {
426 | if (this.currentPosition.y > this.currentZ) {
427 | this.currentRowIdx++;
428 | this.currentZ = this.currentPosition.y;
429 | }
430 |
431 | if ((this.currentRowIdx % this.everyNthRow !== 0) ^ (this.currentRowIdx < 2)) {
432 | return;
433 | }
434 | }
435 |
436 | let spindleCutting = this.hasSpindle && command[0] === "G1";
437 | let lineTolerance = line.length() >= this.lineLengthTolerance;
438 | //feed rate trimming was disabled (probably will remove)
439 | // let feedRateTrimming= this.feedRateTrimming && this.currentFeedRate < this.avgFeed;
440 |
441 | if (spindleCutting || (lineTolerance && line.extruding)) {
442 | line.color = this.currentColor.clone();
443 | this.lines.push(line);
444 |
445 | if (this.currentPosition.y > this.currentLayerHeight && this.currentPosition.y < 20) {
446 | this.previousLayerHeight = this.currentLayerHeight;
447 | this.currentLayerHeight = this.currentPosition.y;
448 | }
449 |
450 | } else if (this.renderTravels && !line.extruding) {
451 | line.color = new Color4(1, 0, 0, 1);
452 | this.travels.push(line);
453 | }
454 |
455 | } break;
456 | case 'G2':
457 | case 'G3': {
458 | tokens = tokenString.split(/(?=[GXYZIJFR])/);
459 | let cw = tokens.filter( t => t === "G2");
460 | let arcResult = doArc(tokens, this.currentPosition, !this.absolute, 1);
461 | let curPt = this.currentPosition.clone();
462 | arcResult.points.forEach((point, idx) => {
463 | let line = new gcodeLine();
464 | line.gcodeLineNumber = this.gcodeLineNumber;
465 | line.start = curPt.clone();
466 | line.end = new Vector3(point.x, point.y,point.z);
467 | line.color = this.currentColor.clone();
468 | if(this.debug){
469 | line.color = cw ? new Color4(0,1,1,1) : new Color4(1,1,0,1)
470 | if(idx == 0){
471 | line.color = new Color4(0,1,0,1);
472 | }
473 | }
474 | curPt = line.end.clone();
475 | this.lines.push(line);
476 | });
477 | //Last point to currentposition
478 |
479 |
480 |
481 | this.currentPosition = new Vector3( arcResult.position.x, arcResult.position.y, arcResult.position.z);
482 | } break;
483 | case 'G28':
484 | //Home
485 | this.currentPosition = new Vector3(0, 0, 0);
486 | break;
487 | case 'G90':
488 | this.absolute = true;
489 | break;
490 | case 'G91':
491 | this.absolute = false;
492 | break;
493 | case 'G92':
494 | //this resets positioning, typically for extruder, probably won't need
495 | break;
496 | case 'S':
497 | this.hasSpindle = true;
498 | break;
499 | case 'M3':
500 | case 'M4': {
501 | let tokens = tokenString.split(/(?=[SM])/);
502 | let spindleSpeed = tokens.filter(speed => speed.startsWith('S'))
503 | spindleSpeed = spindleSpeed[0] ? Number(spindleSpeed[0].substring(1)) : 0;
504 | if (spindleSpeed > 0) {
505 | this.hasSpindle = true;
506 | }
507 |
508 | }
509 | break;
510 | case 'M567': {
511 | let tokens = tokenString.split(/(?=[PE])/);
512 | if (this.colorMode === ColorMode.Feed) break;
513 | for (let tokenIdx = 1; tokenIdx < tokens.length; tokenIdx++) {
514 | let token = tokens[tokenIdx];
515 | var finalColors = [1, 1, 1];
516 | switch (token[0]) {
517 | case 'E':
518 | this.extruderPercentage = token.substring(1).split(':');
519 | break;
520 | }
521 | }
522 | for (let extruderIdx = 0; extruderIdx < 4; extruderIdx++) {
523 | finalColors[0] -= (1 - this.extruderColors[extruderIdx].r) * this.extruderPercentage[extruderIdx];
524 | finalColors[1] -= (1 - this.extruderColors[extruderIdx].g) * this.extruderPercentage[extruderIdx];
525 | finalColors[2] -= (1 - this.extruderColors[extruderIdx].b) * this.extruderPercentage[extruderIdx];
526 | }
527 | this.currentColor = new Color4(finalColors[0], finalColors[1], finalColors[2], 0.1);
528 | break;
529 | }
530 | }
531 | }
532 | else {
533 | //command is null so we need to check a couple other items.
534 | if (tokenString.startsWith('T') && this.colorMode !== ColorMode.Feed) {
535 | var extruder = Number(tokenString.substring(1)) % this.extruderCount; //For now map to extruders 0 - 4
536 | if (extruder < 0) extruder = 0; // Cover the case where someone sets a tool to a -1 value
537 | this.currentColor = this.extruderColors[extruder].clone();
538 | }
539 | if (this.debug) {
540 | console.log(tokenString);
541 | }
542 |
543 | }
544 | //break lines into manageable meshes at cost of extra draw calls
545 | if (this.lines.length >= this.meshBreakPoint) {
546 | //lets build the mesh
547 | this.createScene(this.scene);
548 | await this.pauseProcessing();
549 | this.lineMeshIndex++;
550 | }
551 | }
552 |
553 |
554 |
555 |
556 |
557 | /*
558 | processGCodeLine(line) {
559 | var code = line.split(/(?=[XYZ])/);
560 | switch (code[0]) {
561 | case "G0":
562 | case "G1":
563 | for (let tokenIdx = 1; tokenIdx < code.length; tokenIdx++) {
564 | var token = code[tokenIdx];
565 | switch (token[0]) {
566 | case "X": this.absolute ? this.currentPosition.x = Number(token.substring(1)) : this.currentPosition.x += Number(token.substring(1)); break;
567 | case "Y": this.absolute ? this.currentPosition.y = Number(token.substring(1)) : this.currentPosition.y += Number(token.substring(1)); break;
568 | case "Z": this.absolute ? this.currentPosition.z = Number(token.substring(1)) : this.currentPosition.z += Number(token.substring(1)); break;
569 | }
570 | console.log(this.currentPosition);
571 | }
572 | break;
573 | default: break;
574 | }
575 | }
576 |
577 | processMCodeLine(line, lineNumber) {
578 | console.log(`${line} ${lineNumber}`)
579 | }
580 |
581 | async processLineV2(tokenString, lineNumber) {
582 |
583 | //Remove the comments in the line
584 | let commentIndex = tokenString.indexOf(';');
585 | if (commentIndex > -1) {
586 | tokenString = tokenString.substring(0, commentIndex - 1).trim();
587 | }
588 | tokenString = tokenString.toUpperCase()
589 |
590 | switch (tokenString[0]) {
591 | case "G":
592 | this.processGCodeLine(tokenString, lineNumber);
593 | break;
594 | case "M":
595 | break;
596 | default:
597 | break;
598 | }
599 |
600 |
601 |
602 | }
603 | */
604 |
605 |
606 |
607 |
608 | renderLineMode(scene) {
609 | let that = this;
610 | let lastUpdate = Date.now();
611 | let runComplete = false;
612 | let meshIndex = this.lineMeshIndex;
613 | this.gcodeLineIndex.push(new Array());
614 |
615 | this.renderMode = 'Line Rendering';
616 | //Extrusion
617 | let lineArray = [];
618 | let colorArray = [];
619 | if (this.debug) {
620 | console.log(this.lines[0]);
621 | }
622 | for (var lineIdx = 0; lineIdx < this.lines.length; lineIdx++) {
623 | let line = this.lines[lineIdx];
624 | this.gcodeLineIndex[meshIndex].push(line.gcodeLineNumber);
625 | let data = line.getPoints(scene);
626 |
627 | if (this.liveTrackingShowSolid) {
628 | data.colors[0].a = this.lineVertexAlpha ? this.materialTransparency : 1;
629 | data.colors[1].a = this.lineVertexAlpha ? this.materialTransparency : 1;
630 | } else if (this.liveTracking) {
631 | data.colors[0].a = 0;
632 | data.colors[1].a = 0;
633 | } else if (this.lineVertexAlpha) {
634 | data.colors[0].a = this.materialTransparency;
635 | data.colors[1].a = this.materialTransparency;
636 | } else {
637 | data.colors[0].a = 1;
638 | data.colors[1].a = 1;
639 | }
640 | lineArray.push(data.points);
641 | colorArray.push(data.colors);
642 | }
643 |
644 | let lineMesh = MeshBuilder.CreateLineSystem(
645 | 'm ' + this.lineMeshIndex,
646 | {
647 | lines: lineArray,
648 | colors: colorArray,
649 | updatable: true,
650 | useVertexAlpha: this.lineVertexAlpha || this.liveTracking,
651 | },
652 | scene
653 | );
654 |
655 | lineArray = null;
656 | colorArray = null;
657 |
658 | lineMesh.isVisible = true;
659 | lineMesh.isPickable = false;
660 | lineMesh.alphaIndex = 0; // this.lineMeshIndex; //Testing
661 | lineMesh.doNotSyncBoundingInfo = true;
662 | lineMesh.freezeWorldMatrix(); // prevents from re-computing the World Matrix each frame
663 | lineMesh.freezeNormals();
664 | lineMesh.markVerticesDataAsUpdatable(VertexBuffer.ColorKind);
665 |
666 | const lineSolidMat = new StandardMaterial('solidMaterial', scene);
667 | lineSolidMat.specularColor = this.specularColor;
668 | lineSolidMat.diffuseColor = new Color4(1, 1, 1, 0.5);
669 | lineSolidMat.alphaMode = Engine.ALPHA_ONEONE;
670 | lineSolidMat.needAlphaTesting = () => true;
671 | lineMesh.material = lineSolidMat;
672 |
673 | let lastRendered = 0;
674 |
675 | let beforeRenderFunc = function () {
676 |
677 | if (!that.liveTracking && !runComplete && !(that.gcodeFilePosition && lastRendered >= that.gcodeLineIndex[meshIndex].length - 1)) {
678 | return;
679 | } else if (Date.now() - lastUpdate < that.refreshTime) {
680 | return;
681 | } else {
682 | lastUpdate = Date.now();
683 |
684 | var colorData = lineMesh.getVerticesData(VertexBuffer.ColorKind);
685 |
686 | if (colorData === null || colorData === undefined) {
687 | console.log('Failed to Load Color VBO');
688 | return;
689 | }
690 |
691 |
692 |
693 | let renderTo = -1;
694 | let renderAhead = -1;
695 | for (var renderToIdx = lastRendered; renderToIdx < that.gcodeLineIndex[meshIndex].length; renderToIdx++) {
696 | if (that.gcodeLineIndex[meshIndex][renderToIdx] <= that.gcodeFilePosition) {
697 | renderTo = renderToIdx;
698 | }
699 | if (that.gcodeLineIndex[meshIndex][renderToIdx] <= that.gcodeFilePosition + that.lookAheadLength) {
700 | renderAhead = renderToIdx;
701 | }
702 | }
703 |
704 | for (let colorIdx = lastRendered; colorIdx < renderTo; colorIdx++) {
705 | let index = colorIdx * 8;
706 | colorData[index] = that.progressColor.r;
707 | colorData[index + 1] = that.progressColor.g;
708 | colorData[index + 2] = that.progressColor.b;
709 | colorData[index + 3] = that.progressColor.a;
710 | colorData[index + 4] = that.progressColor.r;
711 | colorData[index + 5] = that.progressColor.g;
712 | colorData[index + 6] = that.progressColor.b;
713 | colorData[index + 7] = that.progressColor.a;
714 | }
715 |
716 | //render ahead
717 | for (let renderAheadIdx = renderTo; renderAheadIdx < renderAhead; renderAheadIdx++) {
718 | let index = renderAheadIdx * 8;
719 | colorData[index + 3] = 1;
720 | colorData[index + 7] = 1;
721 | }
722 |
723 | lastRendered = renderTo;
724 | lineMesh.updateVerticesData(VertexBuffer.ColorKind, colorData, true);
725 | if (that.gcodeFilePosition === Number.MAX_VALUE) {
726 | runComplete = true;
727 | }
728 | }
729 | };
730 |
731 | this.renderFuncs.push(beforeRenderFunc);
732 | scene.registerBeforeRender(beforeRenderFunc);
733 | }
734 |
735 | renderBlockMode(scene) {
736 | let that = this;
737 | let lastUpdate = Date.now();
738 | let runComplete = false;
739 | let meshIndex = this.lineMeshIndex;
740 | this.gcodeLineIndex.push(new Array());
741 |
742 | var layerHeight = Math.floor((this.currentLayerHeight - this.previousLayerHeight) * 100) / 100;
743 |
744 | if (this.spreadLines) {
745 | layerHeight /= this.spreadLineAmount;
746 | }
747 |
748 | this.renderMode = 'Mesh Rendering';
749 | var box = MeshBuilder.CreateBox('box', { width: 1, height: layerHeight, depth: layerHeight * 1.2 }, scene);
750 |
751 | let l = this.lines;
752 |
753 | this.gcodeLineIndex.push(new Array());
754 |
755 | let particleBuilder = function (particle, i, s) {
756 | l[s].renderLineV3(particle, that.lineVertexAlpha || (that.liveTracking && !that.liveTrackingShowSolid));
757 | that.gcodeLineIndex[meshIndex].push(particle.props.gcodeLineNumber);
758 | };
759 |
760 | let sps = new SolidParticleSystem('gcodemodel' + meshIndex, scene, {
761 | updatable: true,
762 | enableMultiMaterial: true,
763 | useVertexAlpha: this.lineVertexAlpha || this.liveTracking,
764 | });
765 |
766 | sps.addShape(box, this.lines.length, {
767 | positionFunction: particleBuilder,
768 | });
769 |
770 | sps.buildMesh();
771 |
772 | //Build out solid and transparent material.
773 | let solidMat = new StandardMaterial('solidMaterial', scene);
774 | solidMat.specularColor = this.specularColor;
775 | let transparentMat = new StandardMaterial('transparentMaterial', scene);
776 | transparentMat.specularColor = this.specularColor;
777 | if (this.lineVertexAlpha || this.liveTracking) {
778 | transparentMat.alpha = this.liveTracking && !this.liveTrackingShowSolid ? 0 : this.materialTransparency;
779 | transparentMat.needAlphaTesting = () => true;
780 | transparentMat.separateCullingPass = true;
781 | transparentMat.backFaceCulling = true;
782 | }
783 |
784 | sps.setMultiMaterial([solidMat, transparentMat]);
785 | sps.setParticles();
786 | sps.computeSubMeshes();
787 | sps.mesh.alphaIndex = 0; // this.lineMeshIndex; //meshIndex;
788 | sps.mesh.freezeWorldMatrix(); // prevents from re-computing the World Matrix each frame
789 | sps.mesh.freezeNormals();
790 | sps.mesh.isPickable = false;
791 | sps.mesh.doNotSyncBoundingInfo = true;
792 |
793 | sps.updateParticle = function (particle) {
794 | if (that.gcodeLineIndex[meshIndex][particle.idx] < that.gcodeFilePosition) {
795 | particle.color = that.progressColor;
796 | particle.materialIndex = 0;
797 | } else if (that.gcodeLineIndex[meshIndex][particle.idx] < that.gcodeFilePosition + that.lookAheadLength) {
798 | particle.color = new Color4(particle.color.r, particle.color.g, particle.color.b, 1);
799 | particle.materialIndex = 0;
800 | } else {
801 | particle.color = new Color4(particle.color.r, particle.color.g, particle.color.b, 0);
802 | }
803 | };
804 |
805 | let beforeRenderFunc = function () {
806 | if (that.liveTracking && !runComplete) {
807 | if (Date.now() - lastUpdate < that.refreshTime) {
808 | return;
809 | } else {
810 | lastUpdate = Date.now();
811 | sps.setParticles();
812 | sps.computeSubMeshes();
813 | }
814 | if (that.gcodeFilePosition === Number.MAX_VALUE) {
815 | runComplete = true;
816 | }
817 | }
818 | };
819 |
820 | this.renderFuncs.push(beforeRenderFunc);
821 | scene.registerBeforeRender(beforeRenderFunc);
822 | this.scene.clearCachedVertexData();
823 | }
824 |
825 | renderPointMode(scene) {
826 | let meshIndex = this.lineMeshIndex;
827 | this.gcodeLineIndex.push(new Array());
828 | //point cloud
829 | this.sps = new PointsCloudSystem('pcs' + meshIndex, 1, scene);
830 |
831 | let l = this.lines;
832 |
833 | let particleBuilder = function (particle, i, s) {
834 | l[s].renderParticle(particle);
835 | };
836 |
837 | this.sps.addPoints(this.lines.length, particleBuilder);
838 |
839 | this.sps.buildMeshAsync().then((mesh) => {
840 | mesh.material.pointSize = 2;
841 | });
842 | }
843 |
844 | createScene(scene) {
845 | if (this.renderVersion === RenderMode.Line) {
846 | this.renderLineMode(scene);
847 | } else if (this.renderVersion === RenderMode.Block) {
848 | this.renderBlockMode(scene);
849 | } else if (this.renderVersion === RenderMode.Point) {
850 | this.renderPointMode(scene);
851 | }
852 |
853 | this.lines = [];
854 |
855 | this.scene.render();
856 | }
857 |
858 | createTravelLines(scene) {
859 | //Travels
860 | var travelArray = [];
861 | var travelColorArray = [];
862 | for (var travelIdx = 0; travelIdx < this.travels.length; travelIdx++) {
863 | let line = this.travels[travelIdx];
864 | let data = line.getPoints(scene);
865 | travelArray.push(data.points);
866 | travelColorArray.push(data.colors);
867 | }
868 | var travelMesh = MeshBuilder.CreateLineSystem(
869 | 'travels',
870 | {
871 | lines: travelArray,
872 | colors: travelColorArray,
873 | updatable: false,
874 | useVertexAlpha: false,
875 | },
876 | scene
877 | );
878 | travelMesh.isVisible = false;
879 | this.travels = []; //clear out the travel array after creating the mesh
880 | }
881 | updateFilePosition(filePosition) {
882 | if (this.liveTracking) {
883 | this.gcodeFilePosition = filePosition - 1;
884 | } else {
885 | this.gcodeFilePosition = 0;
886 | }
887 | }
888 | doFinalPass() {
889 | this.liveTracking = true;
890 | this.gcodeFilePosition = Number.MAX_VALUE;
891 | setTimeout(() => {
892 | this.liveTracking = false;
893 | }, this.refreshTime + 200);
894 | }
895 |
896 | updateMesh() {
897 | if (this.renderVersion === 1) {
898 | console.log('Version 1');
899 | } else if (this.renderVersion === 2) {
900 | console.log('Version 2');
901 | }
902 | }
903 | unregisterEvents() {
904 | for (let idx = 0; idx < this.renderFuncs.length; idx++) {
905 | this.scene.unregisterBeforeRender(this.renderFuncs[idx]);
906 | }
907 | this.renderFuncs = [];
908 | }
909 | setLiveTracking(enabled) {
910 | this.liveTracking = enabled;
911 | }
912 |
913 | setColorMode(mode) {
914 | if (!mode) {
915 | this.colorMode = ColorMode.Color;
916 | }
917 | localStorage.setItem('processorColorMode', mode);
918 | this.colorMode = mode;
919 | }
920 | updateMinFeedColor(value) {
921 | localStorage.setItem('minFeedColor', value);
922 | this.minFeedColorString = value;
923 | this.minFeedColor = Color4.FromHexString(value.padEnd(9, 'F'));
924 | }
925 | updateMaxFeedColor(value) {
926 | localStorage.setItem('maxFeedColor', value);
927 | this.maxFeedColorString = value;
928 |
929 | this.maxFeedColor = Color4.FromHexString(value.padEnd(9, 'F'));
930 | }
931 |
932 | updateColorRate(min, max) {
933 | localStorage.setItem('minColorRate', min);
934 | localStorage.setItem('maxColorRate', max);
935 | this.minColorRate = min;
936 | this.maxColorRate = max;
937 | }
938 |
939 | updateForceWireMode(enabled) {
940 | this.forceWireMode = enabled;
941 | localStorage.setItem('forceWireMode', enabled);
942 | }
943 | }
944 |
945 | window.mobilecheck = function () {
946 | var check = false;
947 | (function (a) {
948 | if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true;
949 | })(navigator.userAgent || navigator.vendor || window.opera);
950 | return check;
951 | };
952 |
--------------------------------------------------------------------------------
/GCodeViewer/viewer/gcodeviewer.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | import { Engine } from '@babylonjs/core/Engines/engine'
4 | import { Scene } from "@babylonjs/core/scene"
5 | import { Plane } from '@babylonjs/core/Maths/math.plane'
6 | import { Color3 } from '@babylonjs/core/Maths/math.color'
7 | import { Vector3 } from '@babylonjs/core/Maths/math.vector'
8 | import { Space } from '@babylonjs/core/Maths/math.axis'
9 | import {MeshBuilder} from '@babylonjs/core/Meshes/meshBuilder'
10 | import '@babylonjs/core/Rendering/edgesRenderer'
11 | import { TransformNode} from '@babylonjs/core/Meshes/transformNode'
12 | import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera'
13 | import { PointLight } from '@babylonjs/core/Lights/pointLight'
14 | import { Axis } from '@babylonjs/core/Maths/math.axis'
15 |
16 | import gcodeProcessor from './gcodeprocessor.js';
17 | import Bed from './bed.js';
18 | import BuildObjects from './buildobjects.js';
19 | import Axes from './axes.js';
20 |
21 | export default class {
22 | constructor(canvas) {
23 | this.lastLoadKey = 'lastLoadFailed';
24 | this.fileData;
25 | this.gcodeProcessor = new gcodeProcessor();
26 | this.maxHeight = 0;
27 | this.sceneBackgroundColor = '#000000';
28 | this.canvas = canvas;
29 | this.scene = {};
30 | this.loading = false;
31 | this.toolVisible = false;
32 | this.toolCursor;
33 | this.toolCursorMesh;
34 | this.toolCursorVisible = true;
35 | this.travelVisible = false;
36 | this.debug = false;
37 | this.zTopClipValue;
38 | this.zBottomClipValue;
39 | this.cancelHitTimer = 0;
40 | this.pause = false;
41 |
42 |
43 | this.cameraInertia = localStorage.getItem('cameraInertia') === 'true';
44 |
45 | //objects
46 | this.bed;
47 | this.buildObjects;
48 | this.axes;
49 |
50 | this.renderQuality = Number(localStorage.getItem('renderQuality'));
51 | if (this.renderQuality === undefined || this.renderQuality === null) {
52 | this.renderQuality = 1;
53 | }
54 |
55 | this.hasCacheSupport =false; // 'caches' in window;
56 | /*
57 | if (this.hasCacheSupport) {
58 | window.caches
59 | .open('gcode-viewer')
60 | .then(() => {
61 | console.info('Cache support enabled');
62 | })
63 | .catch(() => {
64 | //Chrome and safari hide caches when not available. Firefox exposes it regardless so we have to force a fail to see if it is supported
65 | this.hasCacheSupport = false;
66 | });
67 | }
68 | */
69 | }
70 |
71 | getMaxHeight() {
72 | return this.maxHeight;
73 | }
74 | setCameraType(arcRotate) {
75 | if (arcRotate) {
76 | this.scene.activeCamera = this.orbitCamera;
77 | } else {
78 | this.scene.activeCamera = this.flyCamera;
79 | }
80 | }
81 | setZClipPlane(top, bottom) {
82 | this.zTopClipValue = -top;
83 | this.zBottomClipValue = bottom;
84 | if (bottom > top) {
85 | this.zTopClipValue = bottom + 1;
86 | }
87 | this.scene.clipPlane = new Plane(0, 1, 0, this.zTopClipValue);
88 | this.scene.clipPlane2 = new Plane(0, -1, 0, this.zBottomClipValue);
89 | }
90 | init() {
91 | this.engine = new Engine(this.canvas, true, { doNotHandleContextLost: true });
92 | this.engine.enableOfflineSupport = false;
93 | this.scene = new Scene(this.engine);
94 | if (this.debug) {
95 | this.scene.debugLayer.show();
96 | }
97 | this.scene.clearColor = Color3.FromHexString(this.getBackgroundColor());
98 |
99 | this.bed = new Bed(this.scene);
100 | this.bed.registerClipIgnore = (mesh) => {
101 | this.registerClipIgnore(mesh);
102 | };
103 | var bedCenter = this.bed.getCenter();
104 |
105 | // Add a camera to the scene and attach it to the canvas
106 | this.orbitCamera = new ArcRotateCamera('Camera', Math.PI / 2, 2.356194, 250, new Vector3(bedCenter.x, -2, bedCenter.y), this.scene);
107 | this.orbitCamera.invertRotation = false;
108 | this.orbitCamera.attachControl(this.canvas, false);
109 | this.updateCameraInertiaProperties()
110 | // this.orbitCamera.wheelDeltaPercentage = 0.02;
111 | // this.orbitCamera.pinchDeltaPercentage = 0.02;
112 | //Disabled at the moment
113 | //this.flyCamera = new UniversalCamera('UniversalCamera', new Vector3(0, 0, -10), this.scene);
114 |
115 | // Add lights to the scene
116 |
117 | //var light1 = new HemisphericLight("light1", new Vector3(1, 1, 0), this.scene);
118 | var light2 = new PointLight('light2', new Vector3(0, 1, -1), this.scene);
119 | light2.diffuse = new Color3(1, 1, 1);
120 | light2.specular = new Color3(1, 1, 1);
121 | var that = this;
122 | this.engine.runRenderLoop(function () {
123 |
124 | if(that.pause){
125 | return;
126 | }
127 | that.scene.render();
128 | //Update light 2 position
129 | light2.position = that.scene.cameras[0].position;
130 |
131 | });
132 |
133 | this.buildObjects = new BuildObjects(this.scene);
134 | this.buildObjects.getMaxHeight = () => {
135 | return this.gcodeProcessor.getMaxHeight();
136 | };
137 | this.buildObjects.registerClipIgnore = (mesh) => {
138 | this.registerClipIgnore(mesh);
139 | };
140 | this.bed.buildBed();
141 |
142 | this.axes = new Axes(this.scene);
143 | this.axes.registerClipIgnore = (mesh) => {
144 | this.registerClipIgnore(mesh);
145 | };
146 | this.axes.render(50);
147 |
148 | this.resetCamera();
149 | }
150 |
151 | resize() {
152 | this.engine.resize();
153 | }
154 |
155 | refreshUI() {
156 | setTimeout(function () { }, 0);
157 | }
158 |
159 | setFileName(path) {
160 | if (this.hasCacheSupport) {
161 | window.caches.open('gcode-viewer').then(function (cache) {
162 | var pathData = new Blob([path], { type: 'text/plain' });
163 | cache.put('gcodeFileName', new Response(pathData));
164 | });
165 | }
166 | }
167 |
168 | getFileName() {
169 | if (this.hasCacheSupport) {
170 | window.caches.open('gcode-viewer').then(function (cache) {
171 | cache.match('gcodeData').then(function (response) {
172 | response.text().then(function (text) {
173 | return text;
174 | });
175 | });
176 | });
177 | } else {
178 | return '';
179 | }
180 | }
181 |
182 | resetCamera() {
183 | var bedCenter = this.bed.getCenter();
184 | var bedSize = this.bed.getSize();
185 | (this.scene.activeCamera.alpha = Math.PI / 2), (this.scene.activeCamera.beta = 2.356194);
186 | if (this.bed.isDelta) {
187 | this.scene.activeCamera.radius = bedCenter.x;
188 | this.scene.activeCamera.target = new Vector3(bedCenter.x, -2, bedCenter.y);
189 | this.scene.activeCamera.position = new Vector3(-bedSize.x, bedSize.z, -bedSize.x);
190 | } else {
191 | this.scene.activeCamera.radius = 250;
192 | this.scene.activeCamera.target = new Vector3(bedCenter.x, -2, bedCenter.y);
193 | this.scene.activeCamera.position = new Vector3(-bedSize.x / 2, bedSize.z, -bedSize.y / 2);
194 | }
195 | }
196 |
197 | lastLoadFailed() {
198 | if (!localStorage) return false;
199 | return localStorage.getItem(this.lastLoadKey) === 'true';
200 | }
201 | setLoadFlag() {
202 | if (localStorage) {
203 | localStorage.setItem(this.lastLoadKey, 'true');
204 | }
205 | }
206 |
207 | clearLoadFlag() {
208 | if (localStorage) {
209 | localStorage.setItem(this.lastLoadKey, '');
210 | localStorage.removeItem(this.lastLoadKey);
211 | }
212 | }
213 |
214 | async processFile(fileContents) {
215 | this.clearScene();
216 | this.refreshUI();
217 |
218 | let that = this;
219 | if (this.hasCacheSupport) {
220 | window.caches.open('gcode-viewer').then(function (cache) {
221 | var gcodeData = new Blob([fileContents], { type: 'text/plain' });
222 | cache.put('gcodeData', new Response(gcodeData));
223 | });
224 | }
225 |
226 | this.fileData = fileContents;
227 | this.gcodeProcessor.setExtruderColors(this.getExtruderColors());
228 | this.gcodeProcessor.setProgressColor(this.getProgressColor());
229 | this.gcodeProcessor.scene = this.scene;
230 |
231 | if (this.lastLoadFailed()) {
232 | console.error('Last rendering failed dropping to SBC quality');
233 | this.updateRenderQuality(1);
234 | this.clearLoadFlag();
235 | }
236 | this.setLoadFlag();
237 | await this.gcodeProcessor.processGcodeFile(fileContents, this.renderQuality, function () {
238 | if (that.hasCacheSupport) {
239 | that.fileData = ''; //free resourcs sooner
240 | }
241 | });
242 | this.clearLoadFlag();
243 |
244 | this.gcodeProcessor.createScene(this.scene);
245 | this.maxHeight = this.gcodeProcessor.getMaxHeight();
246 | this.toggleTravels(this.travelVisible);
247 | this.setCursorVisiblity(this.toolCursorVisible);
248 | }
249 |
250 | toggleTravels(visible) {
251 | var mesh = this.scene.getMeshByName('travels');
252 | if (mesh !== undefined) {
253 | try {
254 | mesh.isVisible = visible;
255 | this.travelVisible = visible;
256 | } catch {
257 | //console.log('Travel Mesh Error');
258 | }
259 | }
260 | }
261 |
262 | getExtruderColors() {
263 | let colors = localStorage.getItem('extruderColors');
264 | if (colors === null) {
265 | colors = ['#00FFFF', '#FF00FF', '#FFFF00', '#000000', '#FFFFFF'];
266 | this.saveExtruderColors(colors);
267 | } else {
268 | colors = colors.split(',');
269 | }
270 | return colors;
271 | }
272 | saveExtruderColors(colors) {
273 | localStorage.setItem('extruderColors', colors);
274 | }
275 | resetExtruderColors() {
276 | localStorage.removeItem('extruderColors');
277 | this.getExtruderColors();
278 | }
279 | getProgressColor() {
280 | let progressColor = localStorage.getItem('progressColor');
281 | if (progressColor === null) {
282 | progressColor = '#FFFFFF';
283 | }
284 | return progressColor;
285 | }
286 | setProgressColor(value) {
287 | localStorage.setItem('progressColor', value);
288 | this.gcodeProcessor.setProgressColor(value);
289 | }
290 |
291 | getBackgroundColor() {
292 | let color = localStorage.getItem('sceneBackgroundColor');
293 | if (color === null) {
294 | color = '#000000';
295 | }
296 | return color;
297 | }
298 | setBackgroundColor(color) {
299 | if (this.scene !== null && this.scene !== undefined) {
300 | if (color.length > 7) {
301 | color = color.substring(0, 7);
302 | }
303 | this.scene.clearColor = Color3.FromHexString(color);
304 | }
305 | localStorage.setItem('sceneBackgroundColor', color);
306 | }
307 | clearScene(clearFileData) {
308 | if (this.fileData && clearFileData) {
309 | this.fileData = '';
310 | }
311 | this.gcodeProcessor.unregisterEvents();
312 |
313 | for (let idx = this.scene.meshes.length - 1; idx >= 0; idx--) {
314 | let sceneEntity = this.scene.meshes[idx];
315 | if (sceneEntity && this.debug) {
316 | console.log(`Disposing ${sceneEntity.name}`);
317 | }
318 | this.scene.removeMesh(sceneEntity);
319 | if (sceneEntity && typeof sceneEntity.dispose === 'function') {
320 | sceneEntity.dispose(false, true);
321 | }
322 | }
323 |
324 | for (let idx = this.scene.materials.length - 1; idx >= 0; idx--) {
325 | let sceneEntity = this.scene.materials[idx];
326 | if (sceneEntity.name !== 'solidMaterial') continue;
327 | if (sceneEntity && this.debug) {
328 | console.log(`Disposing ${sceneEntity.name}`);
329 | }
330 | this.scene.removeMaterial(sceneEntity);
331 | if (sceneEntity && typeof sceneEntity.dispose === 'function') {
332 | sceneEntity.dispose(false, true);
333 | }
334 | }
335 |
336 | if (this.toolCursor) {
337 | this.toolCursor.dispose(false, true);
338 | this.toolCursor = undefined;
339 | }
340 |
341 | this.buildtoolCursor();
342 | this.bed.buildBed();
343 | this.axes.render();
344 | }
345 | reload() {
346 | return new Promise((resolve) => {
347 | this.clearScene();
348 |
349 | if (this.hasCacheSupport) {
350 | let that = this;
351 | window.caches.open('gcode-viewer').then(function (cache) {
352 | cache.match('gcodeData').then(function (response) {
353 | response.text().then(function (text) {
354 | that.processFile(text).then(() => {
355 | resolve();
356 | });
357 | });
358 | });
359 | });
360 | } else {
361 | this.processFile(this.fileData).then(() => {
362 | resolve();
363 | });
364 | }
365 | });
366 | }
367 | getRenderMode() {
368 | return this.gcodeProcessor.renderMode;
369 | }
370 | setCursorVisiblity(visible) {
371 | if (this.scene === undefined) return;
372 | if (this.toolCursor === undefined) {
373 | this.buildtoolCursor();
374 | }
375 | this.toolCursorMesh.isVisible = visible;
376 | this.toolCursorVisible = visible;
377 | }
378 | updateToolPosition(position) {
379 | let x = 0;
380 | let y = 0;
381 | let z = 0;
382 | this.buildtoolCursor();
383 | for (var index = 0; index < position.length; index++) {
384 | switch (position[index].axes) {
385 | case 'X':
386 | {
387 | x = position[index].position;
388 | }
389 | break;
390 | case 'Y':
391 | {
392 | y = position[index].position;
393 | }
394 | break;
395 | case 'Z':
396 | {
397 | z = position[index].position * (this.gcodeProcessor.spreadLines ? this.gcodeProcessor.spreadLineAmount : 1);
398 | }
399 | break;
400 | }
401 |
402 | this.toolCursor.setAbsolutePosition(new Vector3(x, z, y));
403 | }
404 | }
405 | buildtoolCursor() {
406 | if (this.toolCursor !== undefined) return;
407 | this.toolCursor = new TransformNode('toolCursorContainer');
408 | this.toolCursorMesh = MeshBuilder.CreateCylinder('toolCursorMesh', { diameterTop: 0, diameterBottom: 1 }, this.scene);
409 | this.toolCursorMesh.parent = this.toolCursor;
410 | this.toolCursorMesh.position = new Vector3(0, 3, 0);
411 | this.toolCursorMesh.rotate(Axis.X, Math.PI, Space.LOCAL);
412 | this.toolCursorMesh.scaling = new Vector3(3, 3, 3);
413 | this.toolCursorMesh.isVisible = this.toolCursorVisible;
414 | this.registerClipIgnore(this.toolCursorMesh);
415 | }
416 | updateRenderQuality(renderQuality) {
417 | this.renderQuality = renderQuality;
418 | if (localStorage) {
419 | localStorage.setItem('renderQuality', renderQuality);
420 | }
421 | }
422 | registerClipIgnore(mesh) {
423 | if (mesh === undefined || mesh === null) return;
424 | mesh.onBeforeRenderObservable.add(() => {
425 | this.scene.clipPlane = null;
426 | this.scene.clipPlane2 = null;
427 | });
428 | mesh.onAfterRenderObservable.add(() => {
429 | this.scene.clipPlane = new Plane(0, 1, 0, this.zTopClipValue);
430 | this.scene.clipPlane2 = new Plane(0, -1, 0, this.zBottomClipValue);
431 | });
432 | }
433 | updateCameraInertiaProperties() {
434 |
435 | console.log()
436 | if (this.cameraInertia) {
437 | this.orbitCamera.speed = 2;
438 | this.orbitCamera.inertia = 0.9;
439 | this.orbitCamera.panningInertia = 0.9;
440 | this.orbitCamera.inputs.attached.keyboard.angularSpeed = 0.005;
441 | this.orbitCamera.inputs.attached.keyboard.zoomingSensibility = 2;
442 | this.orbitCamera.inputs.attached.keyboard.panningSensibility = 2;
443 | this.orbitCamera.angularSensibilityX = 1000;
444 | this.orbitCamera.angularSensibilityY = 1000;
445 | this.orbitCamera.panningSensibility = 10;
446 | this.orbitCamera.wheelPrecision = 1;
447 |
448 | }
449 | else {
450 | this.orbitCamera.speed = 500;
451 | this.orbitCamera.inertia = 0;
452 | this.orbitCamera.panningInertia = 0;
453 | this.orbitCamera.inputs.attached.keyboard.angularSpeed = 0.05;
454 | this.orbitCamera.inputs.attached.keyboard.zoomingSensibility =0.5;
455 | this.orbitCamera.inputs.attached.keyboard.panningSensibility = 0.5;
456 | this.orbitCamera.angularSensibilityX = 200;
457 | this.orbitCamera.angularSensibilityY = 200;
458 | this.orbitCamera.panningSensibility = 2;
459 | this.orbitCamera.wheelPrecision = 0.25;
460 | }
461 |
462 | }
463 | setCameraInertia(enabled) {
464 | this.cameraInertia = enabled;
465 | localStorage.setItem('cameraInertia', enabled);
466 | this.updateCameraInertiaProperties()
467 | }
468 |
469 | dispose(){
470 | console.info("Shutting down 3D Viewer");
471 | this.engine.dispose();
472 | this.engine = null;
473 | }
474 | }
475 |
--------------------------------------------------------------------------------
/GCodeViewer/viewer/utils.js:
--------------------------------------------------------------------------------
1 |
2 | function getNumber(tokenNumber, value, relativeMove) {
3 | let number = Number(tokenNumber.substring(1));
4 | let newNum = !number ? 0 : number;
5 | return relativeMove ? newNum + value : newNum;
6 | }
7 |
8 | export function doArc(tokens, currentPosition, relativeMove, arcSegLength) {
9 |
10 | let currX = currentPosition.x,
11 | currY = currentPosition.z, //BabylonJS Z represents depth so Y and Z are switched
12 | currZ = currentPosition.y;
13 |
14 | let x = currX,
15 | y = currY,
16 | z = currZ,
17 | i = 0,
18 | j = 0,
19 | r = 0;
20 | var cw = tokens.filter(t => t.startsWith('G2')) ? 1 : -1; //use the sign to drive direction
21 | //read params
22 | for (let tokenIdx = 0; tokenIdx < tokens.length; tokenIdx++) {
23 | let token = tokens[tokenIdx];
24 | switch (token[0]) {
25 | case 'X': {
26 | x = getNumber(token, x, relativeMove);
27 | } break;
28 | case 'Y': {
29 | y = getNumber(token, y, relativeMove);
30 | } break;
31 | case 'Z': {
32 | z = getNumber(token, z, relativeMove);
33 | } break;
34 | case 'I': {
35 | i = getNumber(token, i, false);
36 | } break; // x offset from current position
37 | case 'J': {
38 | j = getNumber(token, j, false);
39 | } break; //y offset from current position
40 | case 'R': {
41 | r = getNumber(token, r, false);
42 | } break;
43 | }
44 | }
45 |
46 | //If we have an R param we need to find th radial point (we'll use 1mm segments for now)
47 | //Given R it is possible to have 2 values . Positive we use the shorter of the two.
48 | if (r) {
49 | let deltaX = x - currX;
50 | let deltaY = y - currY;
51 | let dSquared = Math.pow(deltaX, 2) + Math.pow(deltaY, 2);
52 | let hSquared = Math.pow(r) - dSquared / 4;
53 | if (dSquared == 0 || hSquared < 0) {
54 | return { position: { x: x, y: z, z: y }, points: [] }; //we'll abort the render and move te position to the new position.
55 | }
56 | let hDivD = Math.sqrt(hSquared / dSquared);
57 |
58 | // Ref RRF DoArcMove for details
59 | if ((cw && r < 0.0) || (!cw && r > 0.0)) {
60 | hDivD = -hDivD;
61 | }
62 | i = deltaX / 2 + deltaY * hDivD;
63 | j = deltaY / 2 - deltaX * hDivD;
64 | } else {
65 | //the radial point is an offset from the current position
66 | ///Need at least on point
67 | if (i == 0 && j == 0) {
68 | return { position: { x: x, y: y, z: z }, points: [] }; //we'll abort the render and move te position to the new position.
69 | }
70 | }
71 |
72 | let wholeCircle = currX == i && currY == y;
73 | let centerX = currX + i;
74 | let centerY = currY + j;
75 |
76 | let arcRadius = Math.sqrt(i * i + j * j);
77 | let arcCurrentAngle = Math.atan2(-j, -i);
78 | let finalTheta = Math.atan2(y - centerY, x - centerX);
79 |
80 |
81 | let totalArc;
82 | if (wholeCircle) {
83 | totalArc = 2 * Math.PI;
84 | }
85 | else {
86 | totalArc = cw ? arcCurrentAngle - finalTheta : finalTheta - arcCurrentAngle;
87 | if (totalArc < 0.0) {
88 | totalArc += 2 * Math.PI;
89 | }
90 | }
91 |
92 | //let arcSegmentLength = this.; //hard coding this to 1mm segment for now
93 |
94 | let totalSegments = (arcRadius * totalArc) / arcSegLength + 0.8;
95 | if (totalSegments < 1) {
96 | totalSegments = 1;
97 | }
98 |
99 | let arcAngleIncrement = totalArc / totalSegments;
100 | arcAngleIncrement *= cw ? -1 :1;
101 |
102 | let points = new Array();
103 |
104 | let zDist = currZ - z;
105 | let zStep = zDist / totalSegments;
106 |
107 | //get points for the arc
108 | let px = currX;
109 | let py = currY;
110 | let pz = currZ;
111 | //calculate segments
112 | let currentAngle = arcCurrentAngle;
113 | for (let moveIdx = 0; moveIdx < totalSegments - 1; moveIdx++) {
114 | currentAngle += arcAngleIncrement;
115 | px = centerX + arcRadius * Math.cos(currentAngle) ;
116 | py = centerY + arcRadius * Math.sin(currentAngle) ;
117 | pz += zStep;
118 | points.push({ x: px, y: pz, z: py });
119 | }
120 |
121 | points.push({ x: x, y: z, z: y });
122 |
123 | //position is the final position
124 | return { position: { x: x, y: z, z: y }, points: points }; //we'll abort the render and move te position to the new position.
125 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DWC GCodeViewer Plugin
2 |
3 | This is the initial version of my gcode viewer moved to a DWC Plugin.
4 |
5 | This project is based off my original work on a viewer I used to maintain as a seperate branch of the DWC https://github.com/Sindarius/DuetWebControl/tree/3DViewer
6 | Duet has implemented a new plugin framework in the DWC 3.2 code base so I have moved my viewer over to the plugin system.
7 |
8 | ## New Features
9 | 1) Render Quality Option Levels
10 | 2) Progress tracking
11 | 3) Live Z tracking
12 | 4) Tool position display
13 | 5) Object Cancel/Resume
14 |
15 | On top of these new features I have kept the extruder color mixing which was one of the original goals of this plugin.
16 |
17 | High Detail Rendering Mode
18 | 
19 |
20 | Clipping
21 | 
22 |
23 | Wire Rendeirng
24 | 
25 |
26 | Cancel Object Functionality
27 | 
28 |
--------------------------------------------------------------------------------