gcodeViewer.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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" style="display:none;"></p>
  35. <p id="displayfilepath"></p>
  36. <p id="filesize"></p>
  37. </div>
  38. <script>
  39. //Get file information from the hash info
  40. var files = ao_module_loadInputFiles();
  41. var file = "";
  42. if (files.length > 0){
  43. file = files[0];
  44. $("#filename").text(file.filename);
  45. $("#filepath").text("../../media?file=" + file.filepath);
  46. $("#displayfilepath").text(file.filepath);
  47. //Get filesize info
  48. $.ajax({
  49. url: "../../system/file_system/getProperties",
  50. data: {path: file.filepath},
  51. success: function(data){
  52. var filesize = ao_module_utils.formatBytes(data.Filesize, 2);
  53. $("#filesize").text(filesize);
  54. }
  55. });
  56. }
  57. //ao module initiation
  58. ao_module_setWindowTitle("GCODEviewer - " + $("#filename").text().trim());
  59. var container;
  60. var camera, scene, renderer;
  61. init();
  62. animate();
  63. function init() {
  64. container = document.createElement( 'div' );
  65. document.body.appendChild( container );
  66. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 10000 );
  67. camera.position.set(0,50,100);
  68. var controls = new THREE.OrbitControls( camera );
  69. controls.target = new THREE.Vector3(0, 20, 0);
  70. controls.update();
  71. scene = new THREE.Scene();
  72. //Setup the background color and the platform
  73. var backgroundcolor = new THREE.Color("#212121");
  74. scene.background = backgroundcolor;
  75. var loader = new THREE.GCodeLoader();
  76. loader.load( $("#filepath").text(), function ( object ) {
  77. var box = new THREE.Box3().setFromObject( object );
  78. const center = new THREE.Vector3();
  79. box.getSize(center)
  80. console.log(center)
  81. object.position.set(0,0,0);
  82. camera.position.set(center.x,50,center.z);
  83. controls.update();
  84. scene.add( object );
  85. } );
  86. renderer = new THREE.WebGLRenderer();
  87. renderer.setPixelRatio( window.devicePixelRatio );
  88. renderer.setSize( window.innerWidth, window.innerHeight );
  89. container.appendChild( renderer.domElement );
  90. window.addEventListener( 'resize', resize, false );
  91. }
  92. function resize() {
  93. camera.aspect = window.innerWidth / window.innerHeight;
  94. camera.updateProjectionMatrix();
  95. renderer.setSize( window.innerWidth, window.innerHeight );
  96. }
  97. function animate() {
  98. renderer.render( scene, camera );
  99. requestAnimationFrame( animate );
  100. }
  101. </script>
  102. </body>
  103. </html>