v1.0.87 - fixes for 3d viewer, g2/g3 support, sketchucam modal gcode support, redraw grid to match gcode, keep jog tab open and css fixes

pull/110/head
openbuilds-engineer 2018-09-06 18:10:40 +02:00
rodzic df3b4b3d76
commit 41baf894dc
11 zmienionych plików z 1651 dodań i 319 usunięć

Wyświetl plik

@ -12,7 +12,7 @@ body {
#renderArea { #renderArea {
/* Note only uses height attribs from here, before we connect to websocket. After that, it gets set by websocket.js */ /* Note only uses height attribs from here, before we connect to websocket. After that, it gets set by websocket.js */
height: 300px; height: calc(100vh - 480px);
width: 100%; width: 100%;
border-top: 1px solid #ccc; border-top: 1px solid #ccc;
/* margin-top: 5px; */ /* margin-top: 5px; */
@ -22,7 +22,7 @@ body {
#editor { #editor {
/* Note only uses height attribs from here, before we connect to websocket. After that, it gets set by websocket.js */ /* Note only uses height attribs from here, before we connect to websocket. After that, it gets set by websocket.js */
height: calc(100% - 1px); height: calc(100vh - 480px);
width: 100%; width: 100%;
border-top: 1px solid #ccc; border-top: 1px solid #ccc;
/* margin-top: 5px; */ /* margin-top: 5px; */
@ -32,7 +32,7 @@ body {
#console { #console {
/*font-family: "Courier New", Courier, monospace;*/ /*font-family: "Courier New", Courier, monospace;*/
font-family: "Lucida Console", Monaco, monospace; font-family: "Lucida Console", Monaco, monospace;
height: calc(100% - 1px); height: calc(100vh - 480px);
width: 100%; width: 100%;
overflow-y: auto; overflow-y: auto;
overflow-x: none; overflow-x: none;

Wyświetl plik

@ -532,8 +532,8 @@
<div id="renderArea"></div> <div id="renderArea"></div>
<div class="fixed-bottom m-3 mb-9"> <div class="fixed-bottom m-3 mb-9">
<button class="button dark" onclick="simSpeed();"><span class="icon"><span class="fas fa-tachometer-alt"></span></span><span class="caption"><span id="simspeedval">1</span>x</span></button> <button class="button dark" onclick="simSpeed();"><span class="icon"><span class="fas fa-tachometer-alt"></span></span><span class="caption"><span id="simspeedval">1</span>x</span></button>
<button id="runSimBtn" title="Run simulation" class="button dark" onclick="simStart()"><i class="fas fa-fighter-jet"></i> Simulate</button>&nbsp; <button id="runSimBtn" title="Run simulation" class="button dark" onclick="sim(0)"><i class="fas fa-fighter-jet"></i> Simulate</button>&nbsp;
<button id="stopSimBtn" style="display: none;" title="Stop Sim" class="button dark" onclick="simStop()"><i class="fas fa-stop"></i> Stop Sim</button>&nbsp; <button id="stopSimBtn" style="display: none;" title="Stop Sim" class="button dark" onclick="simstop()"><i class="fas fa-stop"></i> Stop Sim</button>&nbsp;
<button id="resetViewBtn" title="Stop Sim" class="button dark" onclick="resetView(object)"><i class="fas fa-stop"></i> Reset View</button>&nbsp; <button id="resetViewBtn" title="Stop Sim" class="button dark" onclick="resetView(object)"><i class="fas fa-stop"></i> Reset View</button>&nbsp;
</div> </div>
</div> </div>

Wyświetl plik

@ -1,9 +1,9 @@
{ {
"name": "PWA Splash", "name": "OpenBuilds Machine Driver Jog",
"short_name": "PWA Splash", "short_name": "OpenBuilds Machine Driver Jog",
"description": "PWA SPlash Screens", "description": "OpenBuilds Machine Driver Jog",
"scope": ".", "scope": ".",
"start_url": "/", "start_url": "/jog",
"display": "standalone", "display": "standalone",
"orientation": "portrait", "orientation": "portrait",
"theme_color": "#ffffff", "theme_color": "#ffffff",

Wyświetl plik

@ -17,6 +17,12 @@ $(document).ready(function() {
editor.session.setValue('; No GCODE yet - please Load a GCODE file from the Open GCODE button'); // from samplefile.js editor.session.setValue('; No GCODE yet - please Load a GCODE file from the Open GCODE button'); // from samplefile.js
editor.setShowPrintMargin(false); editor.setShowPrintMargin(false);
editor.getSession().on('change', function() { editor.getSession().on('change', function() {
if (scene.getObjectByName('gcodeobject')) {
// console.log("Existing GCODE object: Cleaning up first")
scene.remove(scene.getObjectByName('gcodeobject'))
object = false;
}
resetView();
parseGcodeInWebWorker(editor.getValue()) parseGcodeInWebWorker(editor.getValue())
}); });
@ -60,6 +66,7 @@ $(document).ready(function() {
$.get("/gcode").done(function(data) { $.get("/gcode").done(function(data) {
console.log(data.length) console.log(data.length)
if (data.length > 2) {
editor.session.setValue(data); editor.session.setValue(data);
$('#controlTab').click() $('#controlTab').click()
if (webgl) { if (webgl) {
@ -67,6 +74,8 @@ $(document).ready(function() {
} else { } else {
$('#gcodeeditortab').click() $('#gcodeeditortab').click()
} }
}
}); });

Wyświetl plik

@ -138,10 +138,10 @@ function setJogPanel(val, status) {
if (val == 0) { // Not Connected Yet if (val == 0) { // Not Connected Yet
// Show panel and resize editor // Show panel and resize editor
$("#svgview").css('background-color', '#f5f6f7'); $("#svgview").css('background-color', '#f5f6f7');
$("#jogcontrols").slideUp(20); // $("#jogcontrols").slideUp(20);
$("#editor").css('height', 'calc(' + 100 + 'vh - ' + 290 + 'px)'); $("#editor").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
$("#console").css('height', 'calc(' + 100 + 'vh - ' + 290 + 'px)'); $("#console").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
$("#renderArea").css('height', 'calc(' + 100 + 'vh - ' + 290 + 'px)'); $("#renderArea").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
// $('#console').scrollTop($("#console")[0].scrollHeight - $("#console").height()); // $('#console').scrollTop($("#console")[0].scrollHeight - $("#console").height());
if (editor) { if (editor) {
editor.resize() editor.resize()
@ -162,7 +162,6 @@ function setJogPanel(val, status) {
} else if (val == 1 || val == 2) { // Connected, but not Playing yet } else if (val == 1 || val == 2) { // Connected, but not Playing yet
// Show panel and resize editor // Show panel and resize editor
$("#svgview").css('background-color', '#ffffff'); $("#svgview").css('background-color', '#ffffff');
$("#jogcontrols").slideDown(20);
$("#editor").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)'); $("#editor").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
$("#console").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)'); $("#console").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
$("#renderArea").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)'); $("#renderArea").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
@ -178,7 +177,7 @@ function setJogPanel(val, status) {
if (object) { if (object) {
if (!simRunning) { if (!simRunning) {
cone.visible = false; cone.visible = false;
update3Dprogress(object.children.length) // update3Dprogress(object.children.length)
} }
} }
} }
@ -188,11 +187,10 @@ function setJogPanel(val, status) {
$("#editor").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)'); $("#editor").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
$("#console").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)'); $("#console").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
$("#renderArea").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)'); $("#renderArea").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
// $('#console').scrollTop($("#console")[0].scrollHeight - $("#console").height());
if (editor) { if (editor) {
editor.resize() editor.resize()
} }
$("#jogcontrols").slideDown(20); // $("#jogcontrols").slideDown(20);
$('.jogbtn').attr('disabled', true); $('.jogbtn').attr('disabled', true);
if (!$('#jograte').attr('disabled')) { if (!$('#jograte').attr('disabled')) {
$('#jograte').attr('disabled', true); $('#jograte').attr('disabled', true);
@ -205,7 +203,6 @@ function setJogPanel(val, status) {
} else if (val == 4) { // Paused } else if (val == 4) { // Paused
// Show panel and resize editor // Show panel and resize editor
$("#svgview").css('background-color', '#f5f6f7'); $("#svgview").css('background-color', '#f5f6f7');
$("#jogcontrols").slideDown(20);
$("#editor").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)'); $("#editor").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
$("#console").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)'); $("#console").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
$("#renderArea").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)'); $("#renderArea").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
@ -224,10 +221,9 @@ function setJogPanel(val, status) {
} else if (val == 5) { // Alarm State } else if (val == 5) { // Alarm State
// Show panel and resize editor // Show panel and resize editor
$("#svgview").css('background-color', '#f5f6f7'); $("#svgview").css('background-color', '#f5f6f7');
$("#jogcontrols").slideUp(20); $("#editor").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
$("#editor").css('height', 'calc(' + 100 + 'vh - ' + 290 + 'px)'); $("#console").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
$("#console").css('height', 'calc(' + 100 + 'vh - ' + 290 + 'px)'); $("#renderArea").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
$("#renderArea").css('height', 'calc(' + 100 + 'vh - ' + 290 + 'px)');
// $('#console').scrollTop($("#console")[0].scrollHeight - $("#console").height()); // $('#console').scrollTop($("#console")[0].scrollHeight - $("#console").height());
if (editor) { if (editor) {
editor.resize() editor.resize()

Wyświetl plik

@ -16,7 +16,8 @@ function drawRuler(xmin, xmax, ymin, ymax) {
ruler.add(line); ruler.add(line);
} }
for (i = xmin; i <= xmax; i += 5) { for (i = xmin; i <= xmax; i++) {
if (i % 5 == 0) {
var geometry = new THREE.Geometry(); var geometry = new THREE.Geometry();
geometry.vertices.push(new THREE.Vector3(i, -1, 0)); geometry.vertices.push(new THREE.Vector3(i, -1, 0));
geometry.vertices.push(new THREE.Vector3(i, -6, 0)); geometry.vertices.push(new THREE.Vector3(i, -6, 0));
@ -25,8 +26,10 @@ function drawRuler(xmin, xmax, ymin, ymax) {
// line.translateY(-ymax / 2) // line.translateY(-ymax / 2)
ruler.add(line); ruler.add(line);
} }
}
for (i = xmin; i <= xmax; i += 10) { for (i = xmin; i <= xmax; i++) {
if (i % 10 == 0) {
var geometry = new THREE.Geometry(); var geometry = new THREE.Geometry();
geometry.vertices.push(new THREE.Vector3(i, -1, 0)); geometry.vertices.push(new THREE.Vector3(i, -1, 0));
geometry.vertices.push(new THREE.Vector3(i, -7, 0)); geometry.vertices.push(new THREE.Vector3(i, -7, 0));
@ -35,9 +38,11 @@ function drawRuler(xmin, xmax, ymin, ymax) {
// line.translateY(-ymax / 2) // line.translateY(-ymax / 2)
ruler.add(line); ruler.add(line);
} }
}
// y axis // y axis
for (i = ymin; i <= ymax; i += 5) { for (i = ymin; i <= ymax; i++) {
if (i % 5 == 0) {
var geometry = new THREE.Geometry(); var geometry = new THREE.Geometry();
geometry.vertices.push(new THREE.Vector3(-1, i, 0)); geometry.vertices.push(new THREE.Vector3(-1, i, 0));
geometry.vertices.push(new THREE.Vector3(-6, i, 0)); geometry.vertices.push(new THREE.Vector3(-6, i, 0));
@ -46,8 +51,10 @@ function drawRuler(xmin, xmax, ymin, ymax) {
// line.translateY(-ymax / 2) // line.translateY(-ymax / 2)
ruler.add(line); ruler.add(line);
} }
}
for (i = ymin; i <= ymax; i += 10) { for (i = ymin; i <= ymax; i++) {
if (i % 10 == 0) {
var geometry = new THREE.Geometry(); var geometry = new THREE.Geometry();
geometry.vertices.push(new THREE.Vector3(-1, i, 0)); geometry.vertices.push(new THREE.Vector3(-1, i, 0));
geometry.vertices.push(new THREE.Vector3(-7, i, 0)); geometry.vertices.push(new THREE.Vector3(-7, i, 0));
@ -56,6 +63,7 @@ function drawRuler(xmin, xmax, ymin, ymax) {
// line.translateY(-ymax / 2) // line.translateY(-ymax / 2)
ruler.add(line); ruler.add(line);
} }
}
for (i = ymin; i <= ymax; i++) { for (i = ymin; i <= ymax; i++) {
var geometry = new THREE.Geometry(); var geometry = new THREE.Geometry();
@ -69,7 +77,8 @@ function drawRuler(xmin, xmax, ymin, ymax) {
var x = []; var x = [];
var y = []; var y = [];
for (var i = xmin; i <= xmax; i += 10) { for (var i = xmin; i <= xmax; i++) {
if (i % 10 == 0) {
x[i] = this.makeSprite(this.scene, "webgl", { x[i] = this.makeSprite(this.scene, "webgl", {
x: i, x: i,
y: -10, y: -10,
@ -80,8 +89,10 @@ function drawRuler(xmin, xmax, ymin, ymax) {
}); });
ruler.add(x[i]); ruler.add(x[i]);
} }
}
for (var i = ymin; i <= ymax; i += 10) { for (var i = ymin; i <= ymax; i++) {
if (i % 10 == 0) {
y[i] = this.makeSprite(this.scene, "webgl", { y[i] = this.makeSprite(this.scene, "webgl", {
x: -10, x: -10,
y: i, y: i,
@ -92,6 +103,7 @@ function drawRuler(xmin, xmax, ymin, ymax) {
}); });
ruler.add(y[i]); ruler.add(y[i]);
} }
}
ruler.name = "Rulers" ruler.name = "Rulers"
var material = new THREE.LineBasicMaterial({ var material = new THREE.LineBasicMaterial({

Wyświetl plik

@ -354,32 +354,32 @@ function animate() {
var toolpaths = new THREE.Group(); var toolpaths = new THREE.Group();
toolpaths.name = "Toolpaths"; toolpaths.name = "Toolpaths";
for (i = 0; i < toolpathsInScene.length; i++) { // for (i = 0; i < toolpathsInScene.length; i++) {
//
// if (toolpathsInScene[i].userData.visible) {
// if (toolpathsInScene[i].userData.inflated) {
// if (toolpathsInScene[i].userData.inflated.userData.pretty) {
// if (toolpathsInScene[i].userData.inflated.userData.pretty.children.length > 0) {
// toolpaths.add(toolpathsInScene[i].userData.inflated.userData.pretty);
// } else {
// toolpaths.add(toolpathsInScene[i].userData.inflated);
// }
// } else {
// toolpaths.add(toolpathsInScene[i].userData.inflated);
// }
// };
// }
// }
// scene.add(toolpaths)
if (toolpathsInScene[i].userData.visible) { // if (fancysim == true) {
if (toolpathsInScene[i].userData.inflated) { // scene.add(simgcodeobj)
if (toolpathsInScene[i].userData.inflated.userData.pretty) { // } else {
if (toolpathsInScene[i].userData.inflated.userData.pretty.children.length > 0) {
toolpaths.add(toolpathsInScene[i].userData.inflated.userData.pretty);
} else {
toolpaths.add(toolpathsInScene[i].userData.inflated);
}
} else {
toolpaths.add(toolpathsInScene[i].userData.inflated);
}
};
}
}
scene.add(toolpaths)
if (fancysim == true) {
scene.add(simgcodeobj)
} else {
if (object) { if (object) {
scene.add(object) scene.add(object)
} }
} // }
clearSceneFlag = false; clearSceneFlag = false;
@ -546,8 +546,8 @@ function fixRenderSize() {
controls.reset(); controls.reset();
setTimeout(function() { setTimeout(function() {
resetView(); resetView();
}, 100); }, 10);
}, 400) }, 10)
} }

Wyświetl plik

@ -1,15 +1,14 @@
var object var object
var draw, line, t = 0, var draw, line, timefactor = 1,
timefactor = 1,
object, simRunning = false; object, simRunning = false;
var loader = new THREE.ObjectLoader(); var loader = new THREE.ObjectLoader();
var worker = new Worker('lib/3dview/workers/gcodeparser.js'); var worker = new Worker('lib/3dview/workers/gcodeparser.js');
worker.addEventListener('message', function(e) { worker.addEventListener('message', function(e) {
object = loader.parse(e.data); object = loader.parse(JSON.parse(e.data));
scene.add(object); scene.add(object);
// redrawGrid(object.userData.size.minx, object.userData.size.maxx, object.userData.size.miny, object.userData.size.maxy) redrawGrid(parseInt(object.userData.bbbox2.min.x), parseInt(object.userData.bbbox2.max.x), parseInt(object.userData.bbbox2.min.y), parseInt(object.userData.bbbox2.max.y))
// animate(); // animate();
setTimeout(function() { setTimeout(function() {
console.log("Reset Camera"); console.log("Reset Camera");
@ -26,101 +25,146 @@ function parseGcodeInWebWorker(gcode) {
}); });
}; };
function update3Dprogress(position) {
for (i = 0; i < object.children.length; i++) {
if (object.children[i].userData.cmd.g == 0) {
object.children[i].material.color.set(0xdddddd);
};
if (object.children[i].userData.cmd.g == 1) {
object.children[i].material.color.set(0xdddddd);
};
};
for (i = 0; i < position; i++) {
if (object.children[i].userData.cmd.g == 0) {
object.children[i].material.color.set(0x00cc00);
};
if (object.children[i].userData.cmd.g == 1) {
object.children[i].material.color.set(0xcc0000);
};
}
}
function simSpeed() { function simSpeed() {
timefactor = timefactor * 10; timefactor = timefactor * 10;
if (timefactor > 1024) timefactor = 0.1; if (timefactor > 1024) timefactor = 0.1;
$('#simspeedval').text(timefactor); $('#simspeedval').text(timefactor);
} }
function simStart() { function sim(startindex) {
if (object) { if (typeof(object) == 'undefined' || !scene.getObjectByName('gcodeobject')) {
simRunning = true; console.log('No Gcode in Preview yet')
var message = `No Gcode in Preview yet: Please setup toolpaths, and generate GCODE before running simulation`
Metro.toast.create(message, null, 10000, 'bg-red');
simstop()
} else {
lastLine = {
x: 0,
y: 0,
z: 0,
e: 0,
f: 0,
feedrate: null,
extruding: false
};
$('#runSimBtn').hide() $('#runSimBtn').hide()
$('#stopSimBtn').show() $('#stopSimBtn').show()
t = 0; clearSceneFlag = true;
cone.position.x = 0; $("#conetext").show();
cone.position.y = 0; cone.visible = true
cone.position.z = 20; var posx = object.userData.lines[0].p2.x; //- (sizexmax/2);
cone.visible = true; var posy = object.userData.lines[0].p2.y; //- (sizeymax/2);
for (i = 0; i < object.children.length; i++) { var posz = object.userData.lines[0].p2.z + 20;
if (object.children[i].userData.cmd.g == 0) { cone.position.x = posx;
object.children[i].material.color.set(0xdddddd); cone.position.y = posy;
}; cone.position.z = posz;
if (object.children[i].userData.cmd.g == 1) { cone.material = new THREE.MeshPhongMaterial({
object.children[i].material.color.set(0xdddddd); color: 0x28a745,
}; specular: 0x0000ff,
}; shininess: 100,
playSim(); opacity: 0.9,
transparent: true
})
simRunning = true;
// timefactor = 1;
$('#simspeedval').text(timefactor);
var simIdx = startindex;
$('#simstartbtn').attr('disabled', true);
$('#simstopbtn').attr('disabled', false);
$('#editorContextMenu').hide() // sometimes we launch sim(linenum) from the context menu... close it once running
var runSim = function() {
// editor.gotoLine(simIdx + 1)
$('#gcodesent').html(simIdx + 1);
// $('#simgcode').html(object.userData.lines[simIdx].args.origtext);
var posx = object.userData.lines[simIdx].p2.x; //- (sizexmax/2);
var posy = object.userData.lines[simIdx].p2.y; //- (sizeymax/2);
var posz = object.userData.lines[simIdx].p2.z;
if (object.userData.lines[simIdx].args.isFake) {
if (object.userData.lines[simIdx].args.text.length < 1) {
var text = "empty line"
} else {
var text = object.userData.lines[simIdx].args.text
}
var simTime = 0.01 / timefactor;
} else {
var text = object.userData.lines[simIdx].args.cmd
var simTime = object.userData.lines[simIdx].p2.timeMins / timefactor;
}
if (object.userData.lines[simIdx].p2.feedrate == null) {
var feedrate = 0.00
} else {
var feedrate = object.userData.lines[simIdx].p2.feedrate
}
$("#conetext").html(
` <table style="border: 1px solid #888">
<tr class="stripe" style="border-bottom: 1px solid #888">
<td><b>CMD</b></td><td align="right"><b>` + text + `</b></td>
</tr>
<tr class="stripe" style="border-bottom: 1px solid #888">
<td><b>X:</b></td><td align="right"><b>` + posx.toFixed(2) + `mm</b></td>
</tr>
<tr class="stripe" style="border-bottom: 1px solid #888">
<td><b>Y:</b></td><td align="right"><b>` + posy.toFixed(2) + `mm</b></td>
</tr>
<tr class="stripe" style="border-bottom: 1px solid #888">
<td><b>Z:</b></td><td align="right"><b>` + posz.toFixed(2) + `mm</b></td>
</tr>
<tr class="stripe" style="border-bottom: 1px solid #888">
<td><b>F:</b></td><td align="right"><b>` + feedrate + `mm/min</b></td>
</tr>
</table>
`);
var simTimeInSec = simTime * 60;
// console.log(simTimeInSec)
if (!object.userData.lines[simIdx].args.isFake) {
TweenMax.to(cone.position, simTimeInSec, {
x: posx,
y: posy,
z: posz + 20,
onComplete: function() {
if (simRunning == false) {
//return
simstop();
} else {
simIdx++;
if (simIdx < object.userData.lines.length) {
runSim();
} else {
simstop();
}
}
}
})
} else {
if (simRunning == false) {
//return
simstop();
} else {
simIdx++;
if (simIdx < object.userData.lines.length) {
runSim();
} else {
simstop();
}
} }
} }
function simStop() {
if (object) {
t = object.children.length;
for (i = 0; i < object.children.length; i++) {
if (object.children[i].userData.cmd.g == 0) {
object.children[i].material.color.set(0x00cc00);
}; };
if (object.children[i].userData.cmd.g == 1) { runSim(); //kick it off
object.children[i].material.color.set(0xcc0000); }
}; }
};
cone.visible = false; function simstop() {
simRunning = false;
$('#runSimBtn').show() $('#runSimBtn').show()
$('#stopSimBtn').hide() $('#stopSimBtn').hide()
simRunning = false
timefactor = 1; timefactor = 1;
$('#simspeedval').text(timefactor); $('#simspeedval').text(timefactor);
editor.gotoLine(0)
cone.visible = false;
clearSceneFlag = true;
} }
}
function playSim() {
$('#simspeedval').text(timefactor);
if (object.children[t]) {
object.children[t].visible = true;
if (object.children[t].userData.cmd.g == 0) {
object.children[t].material.color.set(0x00cc00);
};
if (object.children[t].userData.cmd.g == 1) {
object.children[t].material.color.set(0xcc0000);
};
TweenMax.to(cone.position, object.children[t].userData.time / timefactor, {
x: object.children[t].userData.cmd.x,
y: object.children[t].userData.cmd.y,
z: object.children[t].userData.cmd.z + 20,
onComplete: function() {
t++
if (t == object.children.length) {
simStop();
} else {
playSim();
};
}
});
};
};

Wyświetl plik

@ -0,0 +1,145 @@
self.addEventListener('message', function(e) {
importScripts("/lib/threejs/three.min.js");
var data = e.data;
var result = parseGcode(e.data.data);
self.postMessage(result.toJSON());
}, false);
var object;
var lastpos = {
x: 0,
y: 0,
z: 0
};
function parseGcode(input) {
const lines = input
.split('\n')
// .filter(l => l.length > 0); // discard empty lines
const commands = lines.map(parseLine);
lastpos = {
x: 0,
y: 0,
z: 0
};
var object = new THREE.Group();
var cmdindex = 0;
for (let cmd of commands) {
var geometry = new THREE.Geometry();
var oldVector = new THREE.Vector3(lastpos.x, lastpos.y, lastpos.z)
var newVector = new THREE.Vector3(newx(cmd, lastpos), newy(cmd, lastpos), newz(cmd, lastpos))
geometry.vertices.push(oldVector);
geometry.vertices.push(newVector);
var distance = distanceVector(oldVector, newVector);
if (distance > 0) {
var fr;
if (cmd.f > 0) {
fr = cmd.f;
} else {
fr = 5000;
}
var timeMinutes = distance / fr;
// adjust for acceleration
var timeSeconds = (timeMinutes * 1.32) * 60;
}
var line = false;
if (cmd.g == 0) {
var material = new THREE.LineBasicMaterial({
color: 0x00cc00
});
line = new THREE.Line(geometry, material);
line.userData.cmd = cmd
line.userData.distance = distance
line.userData.time = timeSeconds
line.userData.index = cmdindex;
object.add(line);
} else if (cmd.g == 1) {
var material = new THREE.LineBasicMaterial({
color: 0xcc0000
});
line = new THREE.Line(geometry, material);
line.userData.cmd = cmd
line.userData.distance = distance
line.userData.time = timeSeconds
line.userData.index = cmdindex;
object.add(line);
} else {
var dotGeometry = new THREE.Geometry();
dotGeometry.vertices.push(new THREE.Vector3(lastpos.x, lastpos.y, lastpos.z));
var dotMaterial = new THREE.PointsMaterial({
size: 0,
color: 0xdddddd,
sizeAttenuation: false
});
var dot = new THREE.Points(dotGeometry, dotMaterial);
dot.userData.cmd = cmd
dot.userData.index = cmdindex;
object.add(dot);
}
lastpos = {
x: newx(cmd, lastpos),
y: newy(cmd, lastpos),
z: newz(cmd, lastpos),
}
cmdindex++
}
var helper = new THREE.BoxHelper(object);
helper.update();
var box3 = new THREE.Box3();
box3.setFromObject(helper);
// var size = {
// minx: box3.min.x;
// miny: box3.min.y;
// maxx: box3.max.x;
// maxy: box3.max.y;
// minz: box3.min.z;
// maxz: box3.max.z;
// }
object.userData.size = box3;
return (object);
}
function parseLine(line, index) {
const cmd = {};
if (line.startsWith(';'))
cmd.comment = line.slice(1);
else {
const values = line.split(' ');
values.forEach(v => {
cmd[v.slice(0, 1).toLowerCase()] = +v.slice(1);
});
};
return cmd;
};
function newx(cmd, lastpos) {
if (cmd.x) {
return cmd.x
} else {
return lastpos.x
};
}
function newy(cmd, lastpos) {
if (cmd.y) {
return cmd.y
} else {
return lastpos.y
};
}
function newz(cmd, lastpos) {
if (cmd.z) {
return cmd.z
} else {
return lastpos.z
};
}
function distanceVector(v1, v2) {
var dx = v1.x - v2.x;
var dy = v1.y - v2.y;
var dz = v1.z - v2.z;
return Math.sqrt(dx * dx + dy * dy + dz * dz);
}

Wyświetl plik

@ -1,6 +1,6 @@
{ {
"name": "OpenBuildsMachineDriver", "name": "OpenBuildsMachineDriver",
"version": "1.0.83", "version": "1.0.87",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"description": "Machine Interface Driver for OpenBuilds", "description": "Machine Interface Driver for OpenBuilds",
"author": "github.com/openbuilds <webmaster@openbuilds.com>", "author": "github.com/openbuilds <webmaster@openbuilds.com>",