gcodeViewer.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>Gcode Viewer</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. <!-- Modified from THREE.JS Gcode loader example-->
  8. <style>
  9. body {
  10. font-family: Monospace;
  11. background-color: #FFFFFF;
  12. margin: 0px;
  13. overflow: hidden;
  14. }
  15. #infotab{
  16. position:fixed;
  17. z-index:999;
  18. right:10px;
  19. bottom:0px;
  20. max-width:480px;
  21. word-break: break-all;
  22. color:white;
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <script src="script/threejs/build/three.js"></script>
  28. <script src="script/threejs/OrbitControls.js"></script>
  29. <script src="script/threejs/GCodeLoader.js"></script>
  30. <script src="../../script/jquery.min.js"></script>
  31. <script src="../../script/ao_module.js"></script>
  32. <div id="infotab">
  33. <p id="filename"></p>
  34. <p id="filepath"></p>
  35. <p id="filesize"></p>
  36. </div>
  37. <script>
  38. //Get file information from the hash info
  39. var files = ao_module_loadInputFiles();
  40. var file = "";
  41. if (files.length > 0){
  42. file = files[0];
  43. $("#filename").text(file.filename);
  44. $("#filepath").text("../../media?file=" + file.filepath);
  45. //Get filesize info
  46. $.ajax({
  47. url: "../../system/file_system/getProperties",
  48. data: {path: file.filepath},
  49. success: function(data){
  50. var filesize = ao_module_utils.formatBytes(data.Filesize, 2);
  51. $("#filesize").text(filesize);
  52. }
  53. });
  54. }
  55. //ao module initiation
  56. ao_module_setWindowTitle("GCODEviewer - " + $("#filename").text().trim());
  57. var container;
  58. var camera, scene, renderer;
  59. init();
  60. animate();
  61. function init() {
  62. container = document.createElement( 'div' );
  63. document.body.appendChild( container );
  64. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 10000 );
  65. camera.position.set(0,50,100);
  66. var controls = new THREE.OrbitControls( camera );
  67. controls.target = new THREE.Vector3(0, 20, 0);
  68. controls.update();
  69. scene = new THREE.Scene();
  70. //Setup the background color and the platform
  71. var backgroundcolor = new THREE.Color("#212121");
  72. scene.background = backgroundcolor;
  73. var loader = new THREE.GCodeLoader();
  74. loader.load( $("#filepath").text(), function ( object ) {
  75. var box = new THREE.Box3().setFromObject( object );
  76. const center = new THREE.Vector3();
  77. box.getSize(center)
  78. console.log(center)
  79. object.position.set(0,0,0);
  80. camera.position.set(center.x,50,center.z);
  81. controls.update();
  82. scene.add( object );
  83. } );
  84. renderer = new THREE.WebGLRenderer();
  85. renderer.setPixelRatio( window.devicePixelRatio );
  86. renderer.setSize( window.innerWidth, window.innerHeight );
  87. container.appendChild( renderer.domElement );
  88. window.addEventListener( 'resize', resize, false );
  89. }
  90. function resize() {
  91. camera.aspect = window.innerWidth / window.innerHeight;
  92. camera.updateProjectionMatrix();
  93. renderer.setSize( window.innerWidth, window.innerHeight );
  94. }
  95. function animate() {
  96. renderer.render( scene, camera );
  97. requestAnimationFrame( animate );
  98. }
  99. </script>
  100. </body>
  101. </html>