webgl_loader_kmz.html 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - KMZ</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> -
  12. <a href="https://developers.google.com/kml/documentation/kmzarchives" target="_blank" rel="noopener">KMZ</a> loader
  13. </div>
  14. <script src="js/libs/jszip.min.js"></script>
  15. <script type="module">
  16. import * as THREE from '../build/three.module.js';
  17. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  18. import { KMZLoader } from './jsm/loaders/KMZLoader.js';
  19. var camera, scene, renderer;
  20. init();
  21. function init() {
  22. scene = new THREE.Scene();
  23. scene.background = new THREE.Color( 0x999999 );
  24. var light = new THREE.DirectionalLight( 0xffffff );
  25. light.position.set( 0.5, 1.0, 0.5 ).normalize();
  26. scene.add( light );
  27. camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 1, 500 );
  28. camera.position.y = 5;
  29. camera.position.z = 10;
  30. scene.add( camera );
  31. var grid = new THREE.GridHelper( 50, 50, 0xffffff, 0x555555 );
  32. scene.add( grid );
  33. renderer = new THREE.WebGLRenderer( { antialias: true } );
  34. renderer.setPixelRatio( window.devicePixelRatio );
  35. renderer.setSize( window.innerWidth, window.innerHeight );
  36. document.body.appendChild( renderer.domElement );
  37. var loader = new KMZLoader();
  38. loader.load( './models/kmz/Box.kmz', function ( kmz ) {
  39. kmz.scene.position.y = 0.5;
  40. scene.add( kmz.scene );
  41. render();
  42. } );
  43. var controls = new OrbitControls( camera, renderer.domElement );
  44. controls.addEventListener( 'change', render );
  45. controls.update();
  46. window.addEventListener( 'resize', onWindowResize, false );
  47. }
  48. function onWindowResize() {
  49. camera.aspect = window.innerWidth / window.innerHeight;
  50. camera.updateProjectionMatrix();
  51. renderer.setSize( window.innerWidth, window.innerHeight );
  52. render();
  53. }
  54. function render() {
  55. renderer.render( scene, camera );
  56. }
  57. </script>
  58. </body>
  59. </html>