webgl_loader_vrml.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - loaders - vrml loader</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. color: #444;
  11. }
  12. a {
  13. color: #08f;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <div id="info">
  19. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> -
  20. vrml format loader test
  21. <!--model from <a href="http://cs.iupui.edu/~aharris/webDesign/vrml/" target="_blank" rel="noopener">VRML 2.0 Tutorial</a>,-->
  22. </div>
  23. <script type="module">
  24. import * as THREE from '../build/three.module.js';
  25. import Stats from './jsm/libs/stats.module.js';
  26. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  27. import { VRMLLoader } from './jsm/loaders/VRMLLoader.js';
  28. var camera, scene, renderer, stats, controls;
  29. init();
  30. animate();
  31. function init() {
  32. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 1e10 );
  33. camera.position.set( - 10, 5, 10 );
  34. scene = new THREE.Scene();
  35. scene.add( camera );
  36. // light
  37. var hemiLight = new THREE.HemisphereLight( 0xffffff, 0x000000, 1 );
  38. scene.add( hemiLight );
  39. var dirLight = new THREE.DirectionalLight( 0xffffff, 0.5 );
  40. dirLight.position.set( 200, 200, 200 );
  41. scene.add( dirLight );
  42. var loader = new VRMLLoader();
  43. loader.load( 'models/vrml/house.wrl', function ( object ) {
  44. scene.add( object );
  45. } );
  46. // renderer
  47. renderer = new THREE.WebGLRenderer();
  48. renderer.setPixelRatio( window.devicePixelRatio );
  49. renderer.setSize( window.innerWidth, window.innerHeight );
  50. document.body.appendChild( renderer.domElement );
  51. // controls
  52. controls = new OrbitControls( camera, renderer.domElement );
  53. controls.minDistance = 1;
  54. controls.maxDistance = 100;
  55. controls.enableDamping = true;
  56. //
  57. stats = new Stats();
  58. document.body.appendChild( stats.dom );
  59. //
  60. window.addEventListener( 'resize', onWindowResize, false );
  61. }
  62. function onWindowResize() {
  63. camera.aspect = window.innerWidth / window.innerHeight;
  64. camera.updateProjectionMatrix();
  65. renderer.setSize( window.innerWidth, window.innerHeight );
  66. }
  67. function animate() {
  68. requestAnimationFrame( animate );
  69. controls.update(); // to support damping
  70. renderer.render( scene, camera );
  71. stats.update();
  72. }
  73. </script>
  74. </body>
  75. </html>