提交 60875297 编写于 作者: T Tentone

Clean up code

上级 33712aa5
......@@ -10,19 +10,19 @@
* @author tentone
* @author joewalnes
*/
THREE.GCodeLoader = function( manager ) {
THREE.GCodeLoader = function ( manager ) {
this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
}
THREE.GCodeLoader.prototype.load = function( url, onLoad, onProgress, onError ) {
THREE.GCodeLoader.prototype.load = function ( url, onLoad, onProgress, onError ) {
var self = this;
var loader = new THREE.FileLoader( self.manager );
loader.setPath( this.path );
loader.load( url, function( text ) {
loader.load( url, function ( text ) {
onLoad( self.parse( text ) );
......@@ -30,7 +30,7 @@ THREE.GCodeLoader.prototype.load = function( url, onLoad, onProgress, onError )
};
THREE.GCodeLoader.prototype.parse = function( data ) {
THREE.GCodeLoader.prototype.parse = function ( data ) {
var currentState = { x:0, y:0, z:0, e:0, f:0, extruding:false };
var currentLayer = undefined;
......@@ -54,15 +54,15 @@ THREE.GCodeLoader.prototype.parse = function( data ) {
function getLineGroup( line ) {
if( currentLayer === undefined ) {
if ( currentLayer === undefined ) {
newLayer( line );
}
var grouptype = line.extruding ? 1 : 0;
if( currentLayer.lines[grouptype] === undefined ) {
if ( currentLayer.lines[ grouptype ] === undefined ) {
currentLayer.lines[grouptype] = {
currentLayer.lines[ grouptype ] = {
type: grouptype,
feed: line.e,
......@@ -75,7 +75,7 @@ THREE.GCodeLoader.prototype.parse = function( data ) {
}
return currentLayer.lines[grouptype];
return currentLayer.lines[ grouptype ];
}
//Create lie segment between p1 and p2
......@@ -84,11 +84,11 @@ THREE.GCodeLoader.prototype.parse = function( data ) {
var group = getLineGroup( p2 );
var geometry = group.geometry;
group.segmentCount++;
group.segmentCount ++;
geometry.vertices.push( new THREE.Vector3( p1.x, p1.y, p1.z ) );
geometry.vertices.push( new THREE.Vector3( p2.x, p2.y, p2.z ) );
if( p2.extruding ) {
if ( p2.extruding ) {
box.min.set( Math.min( box.min.x, p2.x ), Math.min( box.min.y, p2.y ), Math.min( box.min.z, p2.z ) );
box.max.set( Math.max( box.max.x, p2.x ), Math.max( box.max.y, p2.y ), Math.max( box.max.z, p2.z ) );
......@@ -111,19 +111,19 @@ THREE.GCodeLoader.prototype.parse = function( data ) {
var lines = data.replace( /;.+/g,'' ).split( '\n' );
for( var i = 0; i < lines.length; i++ ) {
var tokens = lines[i].split( ' ' );
for ( var i = 0; i < lines.length; i ++ ) {
var tokens = lines[ i ].split( ' ' );
var cmd = tokens[0].toUpperCase();
//Argumments
var args = {};
tokens.splice( 1 ).forEach( function( token ) {
tokens.splice( 1 ).forEach( function ( token ) {
if( token[0] !== undefined ) {
if ( token[0] !== undefined ) {
var key = token[0].toLowerCase();
var value = parseFloat( token.substring( 1 ) );
args[key] = value;
args[ key ] = value;
}
......@@ -131,7 +131,7 @@ THREE.GCodeLoader.prototype.parse = function( data ) {
//Process commands
//G0/G1 – Linear Movement
if( cmd === 'G0' || cmd === 'G1' ) {
if ( cmd === 'G0' || cmd === 'G1' ) {
var line = {
x: args.x !== undefined ? absolute( currentState.x, args.x ) : currentState.x,
......@@ -142,11 +142,11 @@ THREE.GCodeLoader.prototype.parse = function( data ) {
};
//Layer change detection is or made by watching Z, it's made by watching when we extrude at a new Z position
if( delta( currentState.e, line.e ) > 0 ) {
if ( delta( currentState.e, line.e ) > 0 ) {
line.extruding = delta( currentState.e, line.e ) > 0;
if( currentLayer == undefined || line.z != currentLayer.z ) {
if ( currentLayer == undefined || line.z != currentLayer.z ) {
newLayer( line );
}
......@@ -156,24 +156,24 @@ THREE.GCodeLoader.prototype.parse = function( data ) {
currentState = line;
}
//G2/G3 - Arc Movement ( G2 clock wise and G3 counter clock wise )
else if( cmd === 'G2' || cmd === 'G3' ) {
else if ( cmd === 'G2' || cmd === 'G3' ) {
console.warn( 'THREE.GCodeLoader: Arc command not supported' );
}
//G90: Set to Absolute Positioning
else if( cmd === 'G90' ) {
else if ( cmd === 'G90' ) {
relative = false;
}
//G91: Set to Relative Positioning
else if( cmd === 'G91' ) {
else if ( cmd === 'G91' ) {
relative = true;
}
//G92: Set Position
else if( cmd === 'G92' ) {
else if ( cmd === 'G92' ) {
var line = currentState;
line.x = args.x !== undefined ? args.x : line.x;
......@@ -193,20 +193,20 @@ THREE.GCodeLoader.prototype.parse = function( data ) {
var object = new THREE.Object3D();
object.name = 'gcode';
for( var i = 0; i < layers.length; i++ ) {
var layer = layers[i];
for ( var i = 0; i < layers.length; i ++ ) {
var layer = layers[ i ];
for( var j = 0; j < layer.lines.length; j++ ) {
for ( var j = 0; j < layer.lines.length; j ++ ) {
var line = layer.lines[j];
var line = layer.lines[ j ];
if( line !== undefined ) {
if ( line !== undefined ) {
var segments = new THREE.LineSegments( line.geometry, line.material );
segments.name = 'layer' + i;
object.add( segments );
}
}
}
return object;
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册