kopia lustrzana https://github.com/OpenBuilds/OpenBuilds-CONTROL
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
rodzic
df3b4b3d76
commit
41baf894dc
|
@ -12,7 +12,7 @@ body {
|
|||
|
||||
#renderArea {
|
||||
/* 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%;
|
||||
border-top: 1px solid #ccc;
|
||||
/* margin-top: 5px; */
|
||||
|
@ -22,7 +22,7 @@ body {
|
|||
|
||||
#editor {
|
||||
/* 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%;
|
||||
border-top: 1px solid #ccc;
|
||||
/* margin-top: 5px; */
|
||||
|
@ -32,7 +32,7 @@ body {
|
|||
#console {
|
||||
/*font-family: "Courier New", Courier, monospace;*/
|
||||
font-family: "Lucida Console", Monaco, monospace;
|
||||
height: calc(100% - 1px);
|
||||
height: calc(100vh - 480px);
|
||||
width: 100%;
|
||||
overflow-y: auto;
|
||||
overflow-x: none;
|
||||
|
|
|
@ -532,8 +532,8 @@
|
|||
<div id="renderArea"></div>
|
||||
<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 id="runSimBtn" title="Run simulation" class="button dark" onclick="simStart()"><i class="fas fa-fighter-jet"></i> Simulate</button>
|
||||
<button id="stopSimBtn" style="display: none;" title="Stop Sim" class="button dark" onclick="simStop()"><i class="fas fa-stop"></i> Stop Sim</button>
|
||||
<button id="runSimBtn" title="Run simulation" class="button dark" onclick="sim(0)"><i class="fas fa-fighter-jet"></i> Simulate</button>
|
||||
<button id="stopSimBtn" style="display: none;" title="Stop Sim" class="button dark" onclick="simstop()"><i class="fas fa-stop"></i> Stop Sim</button>
|
||||
<button id="resetViewBtn" title="Stop Sim" class="button dark" onclick="resetView(object)"><i class="fas fa-stop"></i> Reset View</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"name": "PWA Splash",
|
||||
"short_name": "PWA Splash",
|
||||
"description": "PWA SPlash Screens",
|
||||
"name": "OpenBuilds Machine Driver Jog",
|
||||
"short_name": "OpenBuilds Machine Driver Jog",
|
||||
"description": "OpenBuilds Machine Driver Jog",
|
||||
"scope": ".",
|
||||
"start_url": "/",
|
||||
"start_url": "/jog",
|
||||
"display": "standalone",
|
||||
"orientation": "portrait",
|
||||
"theme_color": "#ffffff",
|
||||
|
|
|
@ -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.setShowPrintMargin(false);
|
||||
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())
|
||||
});
|
||||
|
||||
|
@ -60,13 +66,16 @@ $(document).ready(function() {
|
|||
|
||||
$.get("/gcode").done(function(data) {
|
||||
console.log(data.length)
|
||||
editor.session.setValue(data);
|
||||
$('#controlTab').click()
|
||||
if (webgl) {
|
||||
$('#gcodeviewertab').click();
|
||||
} else {
|
||||
$('#gcodeeditortab').click()
|
||||
if (data.length > 2) {
|
||||
editor.session.setValue(data);
|
||||
$('#controlTab').click()
|
||||
if (webgl) {
|
||||
$('#gcodeviewertab').click();
|
||||
} else {
|
||||
$('#gcodeeditortab').click()
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
22
app/js/ui.js
22
app/js/ui.js
|
@ -138,10 +138,10 @@ function setJogPanel(val, status) {
|
|||
if (val == 0) { // Not Connected Yet
|
||||
// Show panel and resize editor
|
||||
$("#svgview").css('background-color', '#f5f6f7');
|
||||
$("#jogcontrols").slideUp(20);
|
||||
$("#editor").css('height', 'calc(' + 100 + 'vh - ' + 290 + 'px)');
|
||||
$("#console").css('height', 'calc(' + 100 + 'vh - ' + 290 + 'px)');
|
||||
$("#renderArea").css('height', 'calc(' + 100 + 'vh - ' + 290 + 'px)');
|
||||
// $("#jogcontrols").slideUp(20);
|
||||
$("#editor").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
|
||||
$("#console").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
|
||||
$("#renderArea").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
|
||||
// $('#console').scrollTop($("#console")[0].scrollHeight - $("#console").height());
|
||||
if (editor) {
|
||||
editor.resize()
|
||||
|
@ -162,7 +162,6 @@ function setJogPanel(val, status) {
|
|||
} else if (val == 1 || val == 2) { // Connected, but not Playing yet
|
||||
// Show panel and resize editor
|
||||
$("#svgview").css('background-color', '#ffffff');
|
||||
$("#jogcontrols").slideDown(20);
|
||||
$("#editor").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
|
||||
$("#console").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 (!simRunning) {
|
||||
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)');
|
||||
$("#console").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
|
||||
$("#renderArea").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
|
||||
// $('#console').scrollTop($("#console")[0].scrollHeight - $("#console").height());
|
||||
if (editor) {
|
||||
editor.resize()
|
||||
}
|
||||
$("#jogcontrols").slideDown(20);
|
||||
// $("#jogcontrols").slideDown(20);
|
||||
$('.jogbtn').attr('disabled', true);
|
||||
if (!$('#jograte').attr('disabled')) {
|
||||
$('#jograte').attr('disabled', true);
|
||||
|
@ -205,7 +203,6 @@ function setJogPanel(val, status) {
|
|||
} else if (val == 4) { // Paused
|
||||
// Show panel and resize editor
|
||||
$("#svgview").css('background-color', '#f5f6f7');
|
||||
$("#jogcontrols").slideDown(20);
|
||||
$("#editor").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
|
||||
$("#console").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
|
||||
// Show panel and resize editor
|
||||
$("#svgview").css('background-color', '#f5f6f7');
|
||||
$("#jogcontrols").slideUp(20);
|
||||
$("#editor").css('height', 'calc(' + 100 + 'vh - ' + 290 + 'px)');
|
||||
$("#console").css('height', 'calc(' + 100 + 'vh - ' + 290 + 'px)');
|
||||
$("#renderArea").css('height', 'calc(' + 100 + 'vh - ' + 290 + 'px)');
|
||||
$("#editor").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
|
||||
$("#console").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
|
||||
$("#renderArea").css('height', 'calc(' + 100 + 'vh - ' + 480 + 'px)');
|
||||
// $('#console').scrollTop($("#console")[0].scrollHeight - $("#console").height());
|
||||
if (editor) {
|
||||
editor.resize()
|
||||
|
|
|
@ -16,45 +16,53 @@ function drawRuler(xmin, xmax, ymin, ymax) {
|
|||
ruler.add(line);
|
||||
}
|
||||
|
||||
for (i = xmin; i <= xmax; i += 5) {
|
||||
var geometry = new THREE.Geometry();
|
||||
geometry.vertices.push(new THREE.Vector3(i, -1, 0));
|
||||
geometry.vertices.push(new THREE.Vector3(i, -6, 0));
|
||||
var line = new THREE.Line(geometry, material);
|
||||
// line.translateX(-xmax / 2)
|
||||
// line.translateY(-ymax / 2)
|
||||
ruler.add(line);
|
||||
for (i = xmin; i <= xmax; i++) {
|
||||
if (i % 5 == 0) {
|
||||
var geometry = new THREE.Geometry();
|
||||
geometry.vertices.push(new THREE.Vector3(i, -1, 0));
|
||||
geometry.vertices.push(new THREE.Vector3(i, -6, 0));
|
||||
var line = new THREE.Line(geometry, material);
|
||||
// line.translateX(-xmax / 2)
|
||||
// line.translateY(-ymax / 2)
|
||||
ruler.add(line);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = xmin; i <= xmax; i += 10) {
|
||||
var geometry = new THREE.Geometry();
|
||||
geometry.vertices.push(new THREE.Vector3(i, -1, 0));
|
||||
geometry.vertices.push(new THREE.Vector3(i, -7, 0));
|
||||
var line = new THREE.Line(geometry, material);
|
||||
// line.translateX(-xmax / 2)
|
||||
// line.translateY(-ymax / 2)
|
||||
ruler.add(line);
|
||||
for (i = xmin; i <= xmax; i++) {
|
||||
if (i % 10 == 0) {
|
||||
var geometry = new THREE.Geometry();
|
||||
geometry.vertices.push(new THREE.Vector3(i, -1, 0));
|
||||
geometry.vertices.push(new THREE.Vector3(i, -7, 0));
|
||||
var line = new THREE.Line(geometry, material);
|
||||
// line.translateX(-xmax / 2)
|
||||
// line.translateY(-ymax / 2)
|
||||
ruler.add(line);
|
||||
}
|
||||
}
|
||||
|
||||
// y axis
|
||||
for (i = ymin; i <= ymax; i += 5) {
|
||||
var geometry = new THREE.Geometry();
|
||||
geometry.vertices.push(new THREE.Vector3(-1, i, 0));
|
||||
geometry.vertices.push(new THREE.Vector3(-6, i, 0));
|
||||
var line = new THREE.Line(geometry, material);
|
||||
// line.translateX(-ymax / 2)
|
||||
// line.translateY(-ymax / 2)
|
||||
ruler.add(line);
|
||||
for (i = ymin; i <= ymax; i++) {
|
||||
if (i % 5 == 0) {
|
||||
var geometry = new THREE.Geometry();
|
||||
geometry.vertices.push(new THREE.Vector3(-1, i, 0));
|
||||
geometry.vertices.push(new THREE.Vector3(-6, i, 0));
|
||||
var line = new THREE.Line(geometry, material);
|
||||
// line.translateX(-ymax / 2)
|
||||
// line.translateY(-ymax / 2)
|
||||
ruler.add(line);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = ymin; i <= ymax; i += 10) {
|
||||
var geometry = new THREE.Geometry();
|
||||
geometry.vertices.push(new THREE.Vector3(-1, i, 0));
|
||||
geometry.vertices.push(new THREE.Vector3(-7, i, 0));
|
||||
var line = new THREE.Line(geometry, material);
|
||||
// line.translateX(-ymax / 2)
|
||||
// line.translateY(-ymax / 2)
|
||||
ruler.add(line);
|
||||
for (i = ymin; i <= ymax; i++) {
|
||||
if (i % 10 == 0) {
|
||||
var geometry = new THREE.Geometry();
|
||||
geometry.vertices.push(new THREE.Vector3(-1, i, 0));
|
||||
geometry.vertices.push(new THREE.Vector3(-7, i, 0));
|
||||
var line = new THREE.Line(geometry, material);
|
||||
// line.translateX(-ymax / 2)
|
||||
// line.translateY(-ymax / 2)
|
||||
ruler.add(line);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = ymin; i <= ymax; i++) {
|
||||
|
@ -69,28 +77,32 @@ function drawRuler(xmin, xmax, ymin, ymax) {
|
|||
|
||||
var x = [];
|
||||
var y = [];
|
||||
for (var i = xmin; i <= xmax; i += 10) {
|
||||
x[i] = this.makeSprite(this.scene, "webgl", {
|
||||
x: i,
|
||||
y: -10,
|
||||
z: 0,
|
||||
text: i,
|
||||
color: "#cc0000",
|
||||
size: 4
|
||||
});
|
||||
ruler.add(x[i]);
|
||||
for (var i = xmin; i <= xmax; i++) {
|
||||
if (i % 10 == 0) {
|
||||
x[i] = this.makeSprite(this.scene, "webgl", {
|
||||
x: i,
|
||||
y: -10,
|
||||
z: 0,
|
||||
text: i,
|
||||
color: "#cc0000",
|
||||
size: 4
|
||||
});
|
||||
ruler.add(x[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = ymin; i <= ymax; i += 10) {
|
||||
y[i] = this.makeSprite(this.scene, "webgl", {
|
||||
x: -10,
|
||||
y: i,
|
||||
z: 0,
|
||||
text: i,
|
||||
color: "#006600",
|
||||
size: 4
|
||||
});
|
||||
ruler.add(y[i]);
|
||||
for (var i = ymin; i <= ymax; i++) {
|
||||
if (i % 10 == 0) {
|
||||
y[i] = this.makeSprite(this.scene, "webgl", {
|
||||
x: -10,
|
||||
y: i,
|
||||
z: 0,
|
||||
text: i,
|
||||
color: "#006600",
|
||||
size: 4
|
||||
});
|
||||
ruler.add(y[i]);
|
||||
}
|
||||
}
|
||||
ruler.name = "Rulers"
|
||||
|
||||
|
|
|
@ -354,32 +354,32 @@ function animate() {
|
|||
|
||||
var toolpaths = new THREE.Group();
|
||||
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 (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);
|
||||
}
|
||||
};
|
||||
}
|
||||
// if (fancysim == true) {
|
||||
// scene.add(simgcodeobj)
|
||||
// } else {
|
||||
if (object) {
|
||||
scene.add(object)
|
||||
}
|
||||
scene.add(toolpaths)
|
||||
|
||||
if (fancysim == true) {
|
||||
scene.add(simgcodeobj)
|
||||
} else {
|
||||
if (object) {
|
||||
scene.add(object)
|
||||
}
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
|
||||
clearSceneFlag = false;
|
||||
|
@ -546,8 +546,8 @@ function fixRenderSize() {
|
|||
controls.reset();
|
||||
setTimeout(function() {
|
||||
resetView();
|
||||
}, 100);
|
||||
}, 400)
|
||||
}, 10);
|
||||
}, 10)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
var object
|
||||
var draw, line, t = 0,
|
||||
timefactor = 1,
|
||||
var draw, line, timefactor = 1,
|
||||
object, simRunning = false;
|
||||
|
||||
var loader = new THREE.ObjectLoader();
|
||||
|
||||
var worker = new Worker('lib/3dview/workers/gcodeparser.js');
|
||||
worker.addEventListener('message', function(e) {
|
||||
object = loader.parse(e.data);
|
||||
object = loader.parse(JSON.parse(e.data));
|
||||
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();
|
||||
setTimeout(function() {
|
||||
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() {
|
||||
timefactor = timefactor * 10;
|
||||
if (timefactor > 1024) timefactor = 0.1;
|
||||
$('#simspeedval').text(timefactor);
|
||||
}
|
||||
|
||||
function simStart() {
|
||||
if (object) {
|
||||
simRunning = true;
|
||||
function sim(startindex) {
|
||||
if (typeof(object) == 'undefined' || !scene.getObjectByName('gcodeobject')) {
|
||||
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()
|
||||
$('#stopSimBtn').show()
|
||||
t = 0;
|
||||
cone.position.x = 0;
|
||||
cone.position.y = 0;
|
||||
cone.position.z = 20;
|
||||
cone.visible = true;
|
||||
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);
|
||||
};
|
||||
};
|
||||
playSim();
|
||||
}
|
||||
}
|
||||
clearSceneFlag = true;
|
||||
$("#conetext").show();
|
||||
cone.visible = true
|
||||
var posx = object.userData.lines[0].p2.x; //- (sizexmax/2);
|
||||
var posy = object.userData.lines[0].p2.y; //- (sizeymax/2);
|
||||
var posz = object.userData.lines[0].p2.z + 20;
|
||||
cone.position.x = posx;
|
||||
cone.position.y = posy;
|
||||
cone.position.z = posz;
|
||||
cone.material = new THREE.MeshPhongMaterial({
|
||||
color: 0x28a745,
|
||||
specular: 0x0000ff,
|
||||
shininess: 100,
|
||||
opacity: 0.9,
|
||||
transparent: true
|
||||
})
|
||||
|
||||
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) {
|
||||
object.children[i].material.color.set(0xcc0000);
|
||||
};
|
||||
};
|
||||
cone.visible = false;
|
||||
$('#runSimBtn').show()
|
||||
$('#stopSimBtn').hide()
|
||||
simRunning = false
|
||||
timefactor = 1;
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
runSim(); //kick it off
|
||||
}
|
||||
}
|
||||
|
||||
function playSim() {
|
||||
function simstop() {
|
||||
simRunning = false;
|
||||
$('#runSimBtn').show()
|
||||
$('#stopSimBtn').hide()
|
||||
timefactor = 1;
|
||||
$('#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();
|
||||
};
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
editor.gotoLine(0)
|
||||
cone.visible = false;
|
||||
clearSceneFlag = true;
|
||||
}
|
Plik diff jest za duży
Load Diff
|
@ -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);
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "OpenBuildsMachineDriver",
|
||||
"version": "1.0.83",
|
||||
"version": "1.0.87",
|
||||
"license": "AGPL-3.0",
|
||||
"description": "Machine Interface Driver for OpenBuilds",
|
||||
"author": "github.com/openbuilds <webmaster@openbuilds.com>",
|
||||
|
|
Ładowanie…
Reference in New Issue