webgl_loader_lwo.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - LWOLoader</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> - LWOLoader
  12. <P>Lightwave Object loader by <a href="https://discoverthreejs.com/" target="_blank" rel="noopener">Discover three.js</a></P>
  13. Models by <a href="https://onthez.com/" target="_blank" rel="noopener">on the z</a> - Environment images by <a href="https://hdrihaven.com/" target="_blank" rel="noopener">HDRI Haven</a>
  14. </div>
  15. <!-- Import maps polyfill -->
  16. <!-- Remove this when import maps will be widely supported -->
  17. <script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
  18. <script type="importmap">
  19. {
  20. "imports": {
  21. "three": "../build/three.module.js",
  22. "three/addons/": "./jsm/"
  23. }
  24. }
  25. </script>
  26. <script type="module">
  27. import * as THREE from 'three';
  28. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  29. import { LWOLoader } from 'three/addons/loaders/LWOLoader.js';
  30. let camera, scene, renderer;
  31. init();
  32. function init() {
  33. const container = document.createElement( 'div' );
  34. document.body.appendChild( container );
  35. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 200 );
  36. camera.position.set( - 0.7, 14.6, 43.2 );
  37. scene = new THREE.Scene();
  38. scene.background = new THREE.Color( 0xa0a0a0 );
  39. const ambientLight = new THREE.AmbientLight( 0x222222 );
  40. scene.add( ambientLight );
  41. const light1 = new THREE.DirectionalLight( 0x888888 );
  42. light1.position.set( 0, 200, 100 );
  43. scene.add( light1 );
  44. const grid = new THREE.GridHelper( 200, 20, 0x000000, 0x000000 );
  45. grid.material.opacity = 0.3;
  46. grid.material.transparent = true;
  47. scene.add( grid );
  48. const loader = new LWOLoader();
  49. loader.load( 'models/lwo/Objects/LWO3/Demo.lwo', function ( object ) {
  50. const phong = object.meshes[ 0 ];
  51. phong.position.set( - 2, 12, 0 );
  52. const standard = object.meshes[ 1 ];
  53. standard.position.set( 2, 12, 0 );
  54. const rocket = object.meshes[ 2 ];
  55. rocket.position.set( 0, 10.5, - 1 );
  56. scene.add( phong, standard, rocket );
  57. } );
  58. renderer = new THREE.WebGLRenderer( { antialias: true } );
  59. renderer.setPixelRatio( window.devicePixelRatio );
  60. renderer.setSize( window.innerWidth, window.innerHeight );
  61. renderer.setAnimationLoop( animation );
  62. renderer.outputEncoding = THREE.sRGBEncoding;
  63. renderer.toneMapping = THREE.ACESFilmicToneMapping;
  64. container.appendChild( renderer.domElement );
  65. const controls = new OrbitControls( camera, renderer.domElement );
  66. controls.target.set( 1.33, 10, - 6.7 );
  67. controls.update();
  68. window.addEventListener( 'resize', onWindowResize );
  69. }
  70. function onWindowResize() {
  71. camera.aspect = window.innerWidth / window.innerHeight;
  72. camera.updateProjectionMatrix();
  73. renderer.setSize( window.innerWidth, window.innerHeight );
  74. }
  75. function animation() {
  76. renderer.render( scene, camera );
  77. }
  78. </script>
  79. </body>
  80. </html>