Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
progress in 3d view
Browse files Browse the repository at this point in the history
  • Loading branch information
cho45 committed Sep 19, 2015
1 parent d632b83 commit c9d59c6
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 569 deletions.
2 changes: 1 addition & 1 deletion browser/rev.txt
@@ -1 +1 @@
2ec8968
d632b83
7 changes: 7 additions & 0 deletions browser/src/app.js
Expand Up @@ -443,6 +443,11 @@ Polymer({
console.log('loaded gcode', 'total', total, 'durations', durations);

viewer.constructPathObject();

for (var i = 0, len = res.gcode.sent.length; i < len; i++) {
viewer.overridePathColor(i+1, "#000000");
}

viewer.render();
} else {
viewer.loadGCode("");
Expand All @@ -454,6 +459,8 @@ Polymer({
} else
if (res.type === 'gcode.progress') {
self.push('gcode.sent', self.shift('gcode.remain'));
viewer.overridePathColor(self.gcode.sent.length, "#000000");
viewer.render();
self.async(function () {
var container = document.getElementById('gcode-list').parentNode;
var target = container.querySelector('.remain');
Expand Down
38 changes: 34 additions & 4 deletions browser/src/cnc-gcode.js
Expand Up @@ -102,6 +102,8 @@ Polymer({
initContext : function () {
var self = this;
self.context = new gcode.Context();
self.lineNumber = 1;
self.lineNumberMotionMap = {};
},

/**
Expand All @@ -111,7 +113,13 @@ Polymer({
*/
executeBlock : function (line) {
var self = this;
return self.context.executeBlock(gcode.Block.parse(line));
var motions = self.context.executeBlock(gcode.Block.parse(line));
self.lineNumberMotionMap[ self.lineNumber++ ] = motions;
var ret = 0;
for (var i = 0, it; (it = motions[i]); i++) {
ret += it.duration;
}
return ret;
},

/**
Expand All @@ -127,17 +135,18 @@ Polymer({
self.initContext();
self.context.rapidFeedRate = self.rapidFeedRate;

var duration = 0;
var lines = raw.split(/\n/);
for (var i = 0, len = lines.length; i < len; i++) {
duration += self.context.executeBlock(gcode.Block.parse(lines[i]));
self.context.executeBlock(gcode.Block.parse(lines[i]));
}
console.log('duration', duration);

self.constructPathObject();
self.render();
},

/**
* Construct 3D path object for this context
*/
constructPathObject : function () {
var self = this;
if (self.path) {
Expand Down Expand Up @@ -170,6 +179,7 @@ Polymer({

for (var i = 1, len = self.context.motions.length; i < len; i++) {
var motion = self.context.motions[i];
motion._pathIndex = i;
positions[i * 6 + 0] = motion.prevMotion.x;
positions[i * 6 + 1] = motion.prevMotion.y;
positions[i * 6 + 2] = motion.prevMotion.z;
Expand Down Expand Up @@ -204,6 +214,26 @@ Polymer({
self.resetCamera();
},

/**
* Override path color for current path object created from current context.
*
* This method is only valid after calling constructPathObject()
*/
overridePathColor : function (lineNumber, color) {
var self = this;
color = new THREE.Color(color);
var attr = self.path.geometry.getAttribute('color');
var colors = attr.array;
var motions = self.lineNumberMotionMap[lineNumber];
for (var j = 0, it; (it = motions[j]); j++) {
var i = it._pathIndex;
colors[i * 6 + 0] = colors[i * 6 + 3] = color.r;
colors[i * 6 + 1] = colors[i * 6 + 4] = color.g;
colors[i * 6 + 2] = colors[i * 6 + 5] = color.b;
}
attr.needsUpdate = true;
},

resetCamera : function () {
var self = this;
if (!self.controls) return;
Expand Down

0 comments on commit c9d59c6

Please sign in to comment.