webgl_loader_gcode.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - loaders - GCode loader</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <link type="text/css" rel="stylesheet" href="main.css">
  8. </head>
  9. <body>
  10. <div id="info">
  11. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - GCode loader
  12. </div>
  13. <script type="module">
  14. import * as THREE from '../build/three.module.js';
  15. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  16. import { GCodeLoader } from './jsm/loaders/GCodeLoader.js';
  17. var container;
  18. var camera, scene, renderer;
  19. init();
  20. animate();
  21. function init() {
  22. container = document.createElement( 'div' );
  23. document.body.appendChild( container );
  24. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 10000 );
  25. camera.position.set( 0, 0, 70 );
  26. scene = new THREE.Scene();
  27. var loader = new GCodeLoader();
  28. loader.load( 'models/gcode/benchy.gcode', function ( object ) {
  29. object.position.set( - 100, - 20, 100 );
  30. scene.add( object );
  31. } );
  32. renderer = new THREE.WebGLRenderer();
  33. renderer.setPixelRatio( window.devicePixelRatio );
  34. renderer.setSize( window.innerWidth, window.innerHeight );
  35. container.appendChild( renderer.domElement );
  36. var controls = new OrbitControls( camera, renderer.domElement );
  37. window.addEventListener( 'resize', resize, false );
  38. }
  39. function resize() {
  40. camera.aspect = window.innerWidth / window.innerHeight;
  41. camera.updateProjectionMatrix();
  42. renderer.setSize( window.innerWidth, window.innerHeight );
  43. }
  44. function animate() {
  45. renderer.render( scene, camera );
  46. requestAnimationFrame( animate );
  47. }
  48. </script>
  49. </body>
  50. </html>