提交 50bc249f 编写于 作者: T Tentone

GCode loader example

上级 c79d27fb
"use strict";
/**
* GCodeLoader is used to load gcode files usually used for 3D printing or CNC applications.
* THREE.GCodeLoader is used to load gcode files usually used for 3D printing or CNC applications.
*
* Gcode files are composed by commands used by machines to create objects.
*
* @class GCodeLoader
* @class THREE.GCodeLoader
* @param {Manager} manager Loading manager.
* @author tentone
*/
function GCodeLoader(manager)
THREE.GCodeLoader = function(manager)
{
this.manager = (manager !== undefined) ? manager : THREE.DefaultLoadingManager;
}
GCodeLoader.prototype.load = function(url, onLoad, onProgress, onError)
THREE.GCodeLoader.prototype.load = function(url, onLoad, onProgress, onError)
{
var self = this;
......@@ -28,7 +28,7 @@ GCodeLoader.prototype.load = function(url, onLoad, onProgress, onError)
}, onProgress, onError);
};
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;
......@@ -149,7 +149,7 @@ GCodeLoader.prototype.parse = function(data)
//G2/G3 - Arc Movement (G2 clock wise and G3 counter clock wise)
else if(cmd === "G2" || cmd === "G3")
{
console.warn("GCodeLoader: Arc command not supported");
console.warn("THREE.GCodeLoader: Arc command not supported");
}
//G90: Set to Absolute Positioning
else if(cmd === "G90")
......@@ -173,7 +173,7 @@ GCodeLoader.prototype.parse = function(data)
}
else
{
console.warn("GCodeLoader: Command not supported:" + cmd);
console.warn("THREE.GCodeLoader: Command not supported:" + cmd);
}
}
......
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - loaders - GCode loader</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
font-family: Monospace;
background-color: #000;
color: #fff;
margin: 0px;
overflow: hidden;
}
#info {
color: #fff;
position: absolute;
top: 10px;
width: 100%;
text-align: center;
z-index: 100;
display:block;
}
#info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
</style>
</head>
<body>
<div id="info">
<a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - GCode loader
</div>
<script src="../build/three.js"></script>
<script src="js/controls/OrbitControls.js"></script>
<script src="js/loaders/GCodeLoader.js"></script>
<script>
var container, controls;
var camera, scene, renderer;
init();
animate();
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 10000);
camera.position.set( 0, 0, 50 );
controls = new THREE.OrbitControls( camera );
scene = new THREE.Scene();
var loader = new THREE.GCodeLoader( );
loader.load( 'models/gcode/benchy.gcode', function ( object ) {
object.position.set( -100, -20, 100 );
object.rotation.set( -Math.PI/2, 0, 0 );
scene.add( object );
});
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
window.addEventListener( 'resize', resize, false );
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
controls.update();
renderer.render( scene, camera );
requestAnimationFrame( animate );
}
</script>
</body>
</html>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册