webgl_loader_amf.html 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - AMF</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: #999;
  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://amf.wikispaces.com" target="_blank" rel="noopener">AMF File format</a>
  18. <div>AMF loader test by <a href="https://github.com/tamarintech" target="_blank" rel="noopener">tamarintech</a></div>
  19. <div>Rook manufacturing file from <a href="http://amf.wikispaces.com/AMF+test+files" target="_blank" rel="noopener">AMF test files</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 { AMFLoader } from './jsm/loaders/AMFLoader.js';
  26. var camera, scene, renderer;
  27. init();
  28. function init() {
  29. scene = new THREE.Scene();
  30. scene.background = new THREE.Color( 0x999999 );
  31. scene.add( new THREE.AmbientLight( 0x999999 ) );
  32. camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 1, 500 );
  33. // Z is up for objects intended to be 3D printed.
  34. camera.up.set( 0, 0, 1 );
  35. camera.position.set( 0, - 9, 6 );
  36. camera.add( new THREE.PointLight( 0xffffff, 0.8 ) );
  37. scene.add( camera );
  38. var grid = new THREE.GridHelper( 50, 50, 0xffffff, 0x555555 );
  39. grid.rotateOnAxis( new THREE.Vector3( 1, 0, 0 ), 90 * ( Math.PI / 180 ) );
  40. scene.add( grid );
  41. renderer = new THREE.WebGLRenderer( { antialias: true } );
  42. renderer.setPixelRatio( window.devicePixelRatio );
  43. renderer.setSize( window.innerWidth, window.innerHeight );
  44. document.body.appendChild( renderer.domElement );
  45. var loader = new AMFLoader();
  46. loader.load( './models/amf/rook.amf', function ( amfobject ) {
  47. scene.add( amfobject );
  48. render();
  49. } );
  50. var controls = new OrbitControls( camera, renderer.domElement );
  51. controls.addEventListener( 'change', render );
  52. controls.target.set( 0, 1.2, 2 );
  53. controls.update();
  54. window.addEventListener( 'resize', onWindowResize, false );
  55. }
  56. function onWindowResize() {
  57. camera.aspect = window.innerWidth / window.innerHeight;
  58. camera.updateProjectionMatrix();
  59. renderer.setSize( window.innerWidth, window.innerHeight );
  60. render();
  61. }
  62. function render() {
  63. renderer.render( scene, camera );
  64. }
  65. </script>
  66. </body>
  67. </html>