webgl_loader_lwo.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - LWO 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. </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. <script type="module">
  16. import * as THREE from '../build/three.module.js';
  17. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  18. import { LWOLoader } from './jsm/loaders/LWOLoader.js';
  19. var container, controls;
  20. var camera, scene, renderer;
  21. function init() {
  22. container = document.createElement( 'div' );
  23. document.body.appendChild( container );
  24. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 200 );
  25. camera.position.set( - 0.7, 14.6, 43.2 );
  26. scene = new THREE.Scene();
  27. scene.background = new THREE.Color( 0xa0a0a0 );
  28. var ambientLight = new THREE.AmbientLight( 0xaaaaaa, 1.75 );
  29. scene.add( ambientLight );
  30. var light = new THREE.DirectionalLight( 0xffffff, 1 );
  31. light.position.set( 0, 200, 100 );
  32. light.castShadow = true;
  33. light.shadow.camera.top = 180;
  34. light.shadow.camera.bottom = - 100;
  35. light.shadow.camera.left = - 120;
  36. light.shadow.camera.right = 120;
  37. scene.add( light );
  38. light = new THREE.DirectionalLight( 0xffffff, 0.7 );
  39. light.position.set( - 100, 200, - 100 );
  40. scene.add( light );
  41. light = new THREE.DirectionalLight( 0xffffff, 0.4 );
  42. light.position.set( 100, - 200, 100 );
  43. scene.add( light );
  44. light = new THREE.DirectionalLight( 0xffffff, 1 );
  45. light.position.set( - 100, - 100, 100 );
  46. scene.add( light );
  47. var grid = new THREE.GridHelper( 200, 20, 0x000000, 0x000000 );
  48. grid.material.opacity = 0.3;
  49. grid.material.transparent = true;
  50. scene.add( grid );
  51. var loader = new LWOLoader();
  52. loader.load( 'models/lwo/Objects/LWO3/Demo.lwo', function ( object ) {
  53. var phong = object.meshes[ 0 ];
  54. phong.position.set( - 2, 12, 0 );
  55. var standard = object.meshes[ 1 ];
  56. standard.position.set( 2, 12, 0 );
  57. var rocket = object.meshes[ 2 ];
  58. rocket.position.set( 0, 10.5, - 1 );
  59. scene.add( phong, standard, rocket );
  60. } );
  61. renderer = new THREE.WebGLRenderer( { antialias: true, alpha: true } );
  62. renderer.setPixelRatio( window.devicePixelRatio );
  63. renderer.setSize( window.innerWidth, window.innerHeight );
  64. renderer.shadowMap.enabled = true;
  65. renderer.physicallyCorrectLights = true;
  66. renderer.gammaFactor = 1.18;
  67. renderer.outputEncoding = THREE.sRGBEncoding;
  68. container.appendChild( renderer.domElement );
  69. controls = new OrbitControls( camera, renderer.domElement );
  70. controls.target.set( 1.33, 10, - 6.7 );
  71. controls.update();
  72. renderer.setAnimationLoop( function () {
  73. renderer.render( scene, camera );
  74. } );
  75. window.addEventListener( 'resize', onWindowResize, false );
  76. }
  77. function onWindowResize() {
  78. camera.aspect = window.innerWidth / window.innerHeight;
  79. camera.updateProjectionMatrix();
  80. renderer.setSize( window.innerWidth, window.innerHeight );
  81. }
  82. init();
  83. </script>
  84. </body>
  85. </html>