webgl_loader_vrml.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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="http://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 {
  25. DirectionalLight,
  26. PerspectiveCamera,
  27. Scene,
  28. WebGLRenderer,
  29. } from "../build/three.module.js";
  30. import Stats from './jsm/libs/stats.module.js';
  31. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  32. import { VRMLLoader } from './jsm/loaders/VRMLLoader.js';
  33. var camera, scene, renderer, stats;
  34. init();
  35. animate();
  36. function init() {
  37. camera = new PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.01, 1e10 );
  38. camera.position.z = 6;
  39. scene = new Scene();
  40. scene.add( camera );
  41. // light
  42. var dirLight = new DirectionalLight( 0xffffff );
  43. dirLight.position.set( 200, 200, 1000 ).normalize();
  44. camera.add( dirLight );
  45. camera.add( dirLight.target );
  46. var loader = new VRMLLoader();
  47. loader.load( 'models/vrml/house.wrl', function ( object ) {
  48. scene.add( object );
  49. } );
  50. // renderer
  51. renderer = new WebGLRenderer();
  52. renderer.setPixelRatio( window.devicePixelRatio );
  53. renderer.setSize( window.innerWidth, window.innerHeight );
  54. document.body.appendChild( renderer.domElement );
  55. // controls
  56. var controls = new OrbitControls( camera, renderer.domElement );
  57. //
  58. stats = new Stats();
  59. document.body.appendChild( stats.dom );
  60. //
  61. window.addEventListener( 'resize', onWindowResize, false );
  62. }
  63. function onWindowResize() {
  64. camera.aspect = window.innerWidth / window.innerHeight;
  65. camera.updateProjectionMatrix();
  66. renderer.setSize( window.innerWidth, window.innerHeight );
  67. }
  68. function animate() {
  69. requestAnimationFrame( animate );
  70. renderer.render( scene, camera );
  71. stats.update();
  72. }
  73. </script>
  74. </body>
  75. </html>