Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: Colored nozzle temperature layers to 3D view. #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,18 @@ <h3>Running analysis....</h3>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#options3DAccordionTab">
3D Render options
</a>
</div>
<div id="options3DAccordionTab" class="accordion-body collapse">
<div class="accordion-inner">
<label for="show3DNozzleTempCheckbox"><input type="checkbox" id="show3DNozzleTempCheckbox" onclick="GCODE.ui.processOptions()" > Color Nozzle Temp</label>
</div>
</div>
</div>

<div class="accordion-group">
<div class="accordion-heading">
Expand Down
25 changes: 22 additions & 3 deletions js/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
var min = {x: undefined, y: undefined, z: undefined, speed: undefined, volSpeed: undefined, extrSpeed: undefined};
var modelSize = {x: undefined, y: undefined, z: undefined};
var filamentByLayer = {};
var tempNozzleByLayer = [];
var tempBedByLayer = [];
var temperatureUnit = "C (default)";
var filamentByExtruder = {};
var totalFilament=0;
var printTime=0;
Expand Down Expand Up @@ -87,6 +90,9 @@
modelSize: modelSize,
totalFilament:totalFilament,
filamentByLayer: filamentByLayer,
tempNozzleByLayer: tempNozzleByLayer,
tempBedByLayer: tempBedByLayer,
temperatureUnit: temperatureUnit,
filamentByExtruder: filamentByExtruder,
printTime: printTime,
layerHeight: layerHeight,
Expand Down Expand Up @@ -289,6 +295,8 @@
var j, layer= 0, extrude=false, prevRetract= {e: 0, a: 0, b: 0, c: 0}, retract=0, x, y, z=0, f, prevZ=0, prevX, prevY,lastF=4000, prev_extrude = {a: undefined, b: undefined, c: undefined, e: undefined, abs: undefined}, extrudeRelative=false, volPerMM, extruder;
var dcExtrude=false;
var assumeNonDC = false;
var nozzle_temp=0;
var bed_temp=0;

for(var i=0;i<gcode.length;i++){
// for(var len = gcode.length- 1, i=0;i!=len;i++){
Expand Down Expand Up @@ -393,7 +401,7 @@
}
if(!model[layer])model[layer]=[];
//if(typeof(x) !== 'undefined' || typeof(y) !== 'undefined' ||typeof(z) !== 'undefined'||retract!=0)
model[layer][model[layer].length] = {x: Number(x), y: Number(y), z: Number(z), extrude: extrude, retract: Number(retract), noMove: false, extrusion: (extrude||retract)?Number(prev_extrude["abs"]):0, extruder: extruder, prevX: Number(prevX), prevY: Number(prevY), prevZ: Number(prevZ), speed: Number(lastF), gcodeLine: Number(i), volPerMM: typeof(volPerMM)==='undefined'?-1:volPerMM};
model[layer][model[layer].length] = {x: Number(x), y: Number(y), z: Number(z), extrude: extrude, retract: Number(retract), noMove: false, extrusion: (extrude||retract)?Number(prev_extrude["abs"]):0, extruder: extruder, prevX: Number(prevX), prevY: Number(prevY), prevZ: Number(prevZ), speed: Number(lastF), gcodeLine: Number(i), volPerMM: typeof(volPerMM)==='undefined'?-1:volPerMM, bedTemp: bed_temp, nozzleTemp: nozzle_temp};
//{x: x, y: y, z: z, extrude: extrude, retract: retract, noMove: false, extrusion: (extrude||retract)?prev_extrude["abs"]:0, prevX: prevX, prevY: prevY, prevZ: prevZ, speed: lastF, gcodeLine: i};
if(typeof(x) !== 'undefined') prevX = x;
if(typeof(y) !== 'undefined') prevY = y;
Expand All @@ -409,6 +417,15 @@
dcExtrude=true;
}else if(gcode[i].match(/^(?:M103)/i)){
dcExtrude=false;
}else if(gcode[i].match(/^(?:M149)/i)){
var args = gcode[i].split(/\s/);
temperatureUnit=args[1];
}else if(gcode[i].match(/^(?:M104|M109)/i)){
var args = gcode[i].split(/\s/);
nozzle_temp=Number(args[1].substr(1));
}else if(gcode[i].match(/^(?:M140|M190)/i)){
var args = gcode[i].split(/\s/);
bed_temp=Number(args[1].substr(1));
}else if(gcode[i].match(/^(?:G92)/i)){
var args = gcode[i].split(/\s/);
for(j=0;j<args.length;j++){
Expand Down Expand Up @@ -442,7 +459,7 @@
}
if(!model[layer])model[layer]=[];
if(typeof(x) !== 'undefined' || typeof(y) !== 'undefined' ||typeof(z) !== 'undefined')
model[layer][model[layer].length] = {x: parseFloat(x), y: parseFloat(y), z: parseFloat(z), extrude: extrude, retract: parseFloat(retract), noMove: true, extrusion: 0, extruder: extruder, prevX: parseFloat(prevX), prevY: parseFloat(prevY), prevZ: parseFloat(prevZ), speed: parseFloat(lastF), gcodeLine: parseFloat(i)};
model[layer][model[layer].length] = {x: parseFloat(x), y: parseFloat(y), z: parseFloat(z), extrude: extrude, retract: parseFloat(retract), noMove: true, extrusion: 0, extruder: extruder, prevX: parseFloat(prevX), prevY: parseFloat(prevY), prevZ: parseFloat(prevZ), speed: parseFloat(lastF), gcodeLine: parseFloat(i), bedTemp: bed_temp, nozzleTemp: nozzle_temp};
}else if(gcode[i].match(/^(?:G28)/i)){
var args = gcode[i].split(/\s/);
for(j=0;j<args.length;j++){
Expand Down Expand Up @@ -492,7 +509,7 @@

if(!model[layer])model[layer]=[];
// if(typeof(x) !== 'undefined' || typeof(y) !== 'undefined' ||typeof(z) !== 'undefined'||retract!=0)
model[layer][model[layer].length] = {x: Number(x), y: Number(y), z: Number(z), extrude: extrude, retract: Number(retract), noMove: false, extrusion: (extrude||retract)?Number(prev_extrude["abs"]):0, extruder: extruder, prevX: Number(prevX), prevY: Number(prevY), prevZ: Number(prevZ), speed: Number(lastF), gcodeLine: Number(i)};
model[layer][model[layer].length] = {x: Number(x), y: Number(y), z: Number(z), extrude: extrude, retract: Number(retract), noMove: false, extrusion: (extrude||retract)?Number(prev_extrude["abs"]):0, extruder: extruder, prevX: Number(prevX), prevY: Number(prevY), prevZ: Number(prevZ), speed: Number(lastF), gcodeLine: Number(i), bedTemp: bed_temp, nozzleTemp: nozzle_temp};
// if(typeof(x) !== 'undefined' || typeof(y) !== 'undefined' ||typeof(z) !== 'undefined') model[layer][model[layer].length] = {x: x, y: y, z: z, extrude: extrude, retract: retract, noMove:false, extrusion: (extrude||retract)?prev_extrude["abs"]:0, prevX: prevX, prevY: prevY, prevZ: prevZ, speed: lastF, gcodeLine: parseFloat(i)};
}
if(typeof(sendLayer) !== "undefined"){
Expand All @@ -509,6 +526,8 @@
sendMultiLayerZ[sendMultiLayerZ.length] = sendLayerZ;
sendLayer = undefined;
sendLayerZ = undefined;
tempNozzleByLayer.splice(layer,0,nozzle_temp);
tempBedByLayer.splice(layer,0,bed_temp);
}
}
// sendMultiLayer[sendMultiLayer.length] = layer;
Expand Down
20 changes: 19 additions & 1 deletion js/gCodeReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ GCODE.gCodeReader = (function(){
gcode = [];
var i;
for(i=0;i<lines.length;i++){
if(lines[i].match(/^(G0|G1|G90|G91|G92|M82|M83|G28)/i))gcode.push(lines[i]);
if(lines[i].match(/^(G0|G1|G90|G91|G92|M82|M83|G28|M104|M109|M140|M190)/i))gcode.push(lines[i]);
}
lines = [];
// console.log("GCode prepared");
Expand Down Expand Up @@ -250,6 +250,9 @@ GCODE.gCodeReader = (function(){
totalFilament = msg.totalFilament;
filamentByLayer = msg.filamentByLayer;
filamentByExtruder = msg.filamentByExtruder;
tempNozzleByLayer=msg.tempNozzleByLayer;
tempBedByLayer=msg.tempBedByLayer;
temperatureUnit=msg.temperatureUnit;
speeds = msg.speeds;
speedsByLayer = msg.speedsByLayer;
printTime = msg.printTime;
Expand Down Expand Up @@ -280,6 +283,21 @@ GCODE.gCodeReader = (function(){
getLayerFilament: function(z){
return filamentByLayer[z];
},
getNozzleTemp: function(z){
if('undefined' !== typeof tempNozzleByLayer[z])
return tempNozzleByLayer[z];
else
return 0;
},
getBedTemp: function(z){
if('undefined' !== typeof tempBedByLayer[z])
return tempBedByLayer[z];
else
return 0;
},
getTemperatureUnit(){
return temperatureUnit;
},
getLayerSpeeds: function(z){
return speedsByLayer[z]?speedsByLayer[z]:{};
},
Expand Down
61 changes: 53 additions & 8 deletions js/renderer3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ GCODE.renderer3d = (function(){
var modelLoaded=false;
var model;
var prevX=0, prevY= 0, prevZ=0;
var bedTemp=0;
var nozzleTemp=0;
var sliderHor, sliderVer;
var object;
var geometry;
Expand All @@ -27,7 +29,8 @@ GCODE.renderer3d = (function(){
var mouseX = 0, mouseY = 0;

var renderOptions = {
showMoves: true,
showMoves: false,
showTemp: true,
colorLine: 0x000000,
colorMove: 0x00ff00,
rendererType: "webgl"
Expand Down Expand Up @@ -58,21 +61,63 @@ GCODE.renderer3d = (function(){
prevX = cmds[j].x;
prevY = cmds[j].y;
prevZ = cmds[j].z;
bedTemp = cmds[j].bedTemp;
nozzleTemp = cmds[j].nozzleTemp;
}
};

var buildModelIteratively = function(){
var i;

var geoMin;
var geoMax;
var lineMaterial = new THREE.LineBasicMaterial({color: renderOptions["colorLine"], lineWidth: 2, opacity: 0.6, fog: false});
var lineColor = new THREE.Color('hsl(0, 100%, 50%)');

var tempMin=Infinity;
var tempMax=-Infinity;
var scaleMin=0.999;
var scaleMax=0.5;

if (renderOptions["showTemp"]){
for(var i=0;i<model.length;i+=1){
var cmds = model[i];
for(var j=0;j<cmds.length;j++){
if(cmds[j].extrude){
if (cmds[j].nozzleTemp<tempMin){tempMin=cmds[j].nozzleTemp;}
if (cmds[j].nozzleTemp>tempMax){tempMax=cmds[j].nozzleTemp;}
}
}
}
}

for(i=0;i<model.length;i+=1){
geometry = new THREE.Geometry();
buildModelIteration(i);
//TODO: need to remove UI stuff from here

geometry.computeBoundingBox();

if (i==0){
geoMin=geometry.boundingBox.min;
geoMax=geometry.boundingBox.max;
}
if (geometry.boundingBox.min.x<geoMin.x){geoMin.x=geometry.boundingBox.min.x;}
if (geometry.boundingBox.min.y<geoMin.y){geoMin.y=geometry.boundingBox.min.y;}
if (geometry.boundingBox.min.z<geoMin.z){geoMin.z=geometry.boundingBox.min.z;}
if (geometry.boundingBox.max.x<geoMax.x){geoMax.x=geometry.boundingBox.max.x;}
if (geometry.boundingBox.max.y<geoMax.y){geoMax.y=geometry.boundingBox.max.y;}
if (geometry.boundingBox.max.z<geoMax.z){geoMax.z=geometry.boundingBox.max.z;}

if (renderOptions["showTemp"]){
if (nozzleTemp<tempMin){nozzleTemp=tempMin;}
if (nozzleTemp>tempMax){nozzleTemp=tempMax;}
var scaledHue = ((nozzleTemp-tempMin)*(scaleMax-scaleMin)/(tempMax-tempMin))+scaleMin;
if (tempMin==tempMax){scaledHue=0.7;}//Fixed blue color if no temp change so user knows show temp checkbox is working
lineColor.setHSV(scaledHue,1,1);
lineMaterial = new THREE.LineBasicMaterial({color: lineColor, lineWidth: 2, opacity: 0.6, fog: false});
}
object.add(new THREE.Line(geometry, lineMaterial, THREE.LinePieces));
}
var lineMaterial = new THREE.LineBasicMaterial({color: renderOptions["colorLine"], lineWidth: 2, opacity: 0.6, fog: false});
geometry.computeBoundingBox();
object.add(new THREE.Line(geometry, lineMaterial, THREE.LinePieces));
var center = new THREE.Vector3().add(geometry.boundingBox.min, geometry.boundingBox.max).divideScalar(2);

var center = new THREE.Vector3().add(geoMin, geoMax).divideScalar(2);
object.position = center.multiplyScalar(-1);

}
Expand Down
11 changes: 10 additions & 1 deletion js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ GCODE.ui = (function(){
var segments = GCODE.renderer.getLayerNumSegments(layerNum);
var renderOptions = GCODE.renderer.getOptions();
var filament = GCODE.gCodeReader.getLayerFilament(z);
var tempNoozle = GCODE.gCodeReader.getNozzleTemp(layerNum);
var tempBed = GCODE.gCodeReader.getBedTemp(layerNum);
var tempUnit = GCODE.gCodeReader.getTemperatureUnit();
var output = [];

var aggFilamentUsed = 0.0;
Expand All @@ -167,6 +170,9 @@ GCODE.ui = (function(){

output.push("Layer number: " + layerNum);
output.push("Layer height (mm): " + z);
output.push("Nozzle temp: " + tempNoozle);
output.push("Bed temp: " + tempBed);
output.push("Temperature unit: " + tempUnit);
output.push("GCODE commands in layer: " + segments);
output.push("Filament used by layer (mm): " + filament.toFixed(2));
output.push("Filament used, summed (mm): " + aggFilamentUsed);
Expand Down Expand Up @@ -461,7 +467,6 @@ GCODE.ui = (function(){
if(window.location.search.match(/new/)){
$('#errAnalyseTab').removeClass('hide');
}

},

processOptions: function(){
Expand All @@ -487,6 +492,10 @@ GCODE.ui = (function(){
alpha: document.getElementById('alphaCheckbox').checked,
showNextLayer: document.getElementById('showNextLayer').checked,
});

GCODE.renderer3d.setOption({
showTemp: document.getElementById('show3DNozzleTempCheckbox').checked,
});

showGCode = document.getElementById('showGCodeCheckbox').checked;

Expand Down