webgl_loader_3mf.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - 3MF</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. <style>
  9. body {
  10. background-color: #333;
  11. }
  12. </style>
  13. </head>
  14. <body>
  15. <div id="info">
  16. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a>
  17. <a href="http://3mf.io" target="_blank" rel="noopener">3MF File format</a>
  18. <div>3MF loader test by <a href="https://github.com/technohippy" target="_blank" rel="noopener">technohippy</a></div>
  19. <div>Cube gears file from <a href="https://github.com/3MFConsortium/3mf-samples" target="_blank" rel="noopener">3mf-samples</a></div>
  20. </div>
  21. <script src="js/libs/jszip.min.js"></script>
  22. <script type="module">
  23. import * as THREE from '../build/three.module.js';
  24. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  25. import { ThreeMFLoader } from './jsm/loaders/3MFLoader.js';
  26. var camera, scene, renderer;
  27. init();
  28. function init() {
  29. renderer = new THREE.WebGLRenderer( { antialias: true } );
  30. renderer.setPixelRatio( window.devicePixelRatio );
  31. renderer.setSize( window.innerWidth, window.innerHeight );
  32. document.body.appendChild( renderer.domElement );
  33. scene = new THREE.Scene();
  34. scene.background = new THREE.Color( 0x333333 );
  35. scene.add( new THREE.AmbientLight( 0xffffff, 0.2 ) );
  36. camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 1, 500 );
  37. // Z is up for objects intended to be 3D printed.
  38. camera.up.set( 0, 0, 1 );
  39. camera.position.set( - 80, - 90, 150 );
  40. scene.add( camera );
  41. var controls = new OrbitControls( camera, renderer.domElement );
  42. controls.addEventListener( 'change', render );
  43. controls.minDistance = 50;
  44. controls.maxDistance = 300;
  45. controls.enablePan = false;
  46. controls.target.set( 80, 65, 20 );
  47. controls.update();
  48. var pointLight = new THREE.PointLight( 0xffffff, 0.8 );
  49. camera.add( pointLight );
  50. var loader = new ThreeMFLoader();
  51. loader.load( './models/3mf/cube_gears.3mf', function ( object ) {
  52. scene.add( object );
  53. render();
  54. } );
  55. window.addEventListener( 'resize', onWindowResize, false );
  56. }
  57. function onWindowResize() {
  58. camera.aspect = window.innerWidth / window.innerHeight;
  59. camera.updateProjectionMatrix();
  60. renderer.setSize( window.innerWidth, window.innerHeight );
  61. render();
  62. }
  63. function render() {
  64. renderer.render( scene, camera );
  65. }
  66. </script>
  67. </body>
  68. </html>