webgl_loader_lwo.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. <style>
  8. body {
  9. font-family: Monospace;
  10. background-color: #000;
  11. color: #fff;
  12. margin: 0px;
  13. overflow: hidden;
  14. }
  15. #info {
  16. color: #fff;
  17. position: absolute;
  18. top: 10px;
  19. width: 100%;
  20. text-align: center;
  21. z-index: 100;
  22. display:block;
  23. }
  24. #info a {
  25. color: #046;
  26. font-weight: bold;
  27. }
  28. p {
  29. margin: 8px 0;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <div id="info">
  35. <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - LWOLoader
  36. <P>Lightwave Object loader by <a href="https://discoverthreejs.com/" target="_blank" rel="noopener">Discover three.js</a></P>
  37. 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>
  38. </div>
  39. <script src="../build/three.js"></script>
  40. <script src="js/loaders/LWOLoader.js"></script>
  41. <script src="js/controls/OrbitControls.js"></script>
  42. <script src="js/WebGL.js"></script>
  43. <script src="js/libs/stats.min.js"></script>
  44. <script>
  45. if ( WEBGL.isWebGLAvailable() === false ) {
  46. document.body.appendChild( WEBGL.getWebGLErrorMessage() );
  47. }
  48. var container, stats, controls;
  49. var camera, scene, renderer;
  50. function init() {
  51. container = document.createElement( 'div' );
  52. document.body.appendChild( container );
  53. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 200 );
  54. camera.position.set( -.7, 14.6, 43.2 );
  55. scene = new THREE.Scene();
  56. scene.background = new THREE.Color( 0xa0a0a0 );
  57. var ambientLight = new THREE.AmbientLight( 0xaaaaaa, 1.75 );
  58. scene.add( ambientLight );
  59. var light = new THREE.DirectionalLight( 0xffffff, 1 );
  60. light.position.set( 0, 200, 100 );
  61. light.castShadow = true;
  62. light.shadow.camera.top = 180;
  63. light.shadow.camera.bottom = -100;
  64. light.shadow.camera.left = -120;
  65. light.shadow.camera.right = 120;
  66. scene.add( light );
  67. light = new THREE.DirectionalLight( 0xffffff, 0.7 );
  68. light.position.set( -100, 200, -100 );
  69. scene.add( light );
  70. light = new THREE.DirectionalLight( 0xffffff, 0.4 );
  71. light.position.set( 100, -200, 100 );
  72. scene.add( light );
  73. light = new THREE.DirectionalLight( 0xffffff, 1 );
  74. light.position.set( -100, -100, 100 );
  75. scene.add( light );
  76. var grid = new THREE.GridHelper( 200, 20, 0x000000, 0x000000 );
  77. grid.material.opacity = 0.3;
  78. grid.material.transparent = true;
  79. scene.add( grid );
  80. var loader = new THREE.LWOLoader();
  81. loader.load( 'models/lwo/Objects/LWO3/Demo.lwo', function ( object ) {
  82. var phong = object.meshes[0];
  83. phong.position.set( -2, 12, 0 );
  84. var standard = object.meshes[1];
  85. standard.position.set( 2, 12, 0 );
  86. var rocket = object.meshes[2];
  87. rocket.position.set( 0, 10.5, -1 );
  88. scene.add( phong, standard, rocket );
  89. } );
  90. renderer = new THREE.WebGLRenderer( { antialias: true, alpha: true } );
  91. renderer.setPixelRatio( window.devicePixelRatio );
  92. renderer.setSize( window.innerWidth, window.innerHeight );
  93. renderer.shadowMap.enabled = true;
  94. renderer.physicallyCorrectLights = true;
  95. renderer.gammaFactor = 1.18;
  96. renderer.gammaOutput = true;
  97. container.appendChild( renderer.domElement );
  98. controls = new THREE.OrbitControls( camera, renderer.domElement );
  99. controls.target.set( 1.33, 10, -6.7 );
  100. controls.update();
  101. renderer.setAnimationLoop( function () {
  102. stats.begin();
  103. renderer.render( scene, camera );
  104. stats.end();
  105. } );
  106. window.addEventListener( 'resize', onWindowResize, false );
  107. // stats
  108. stats = new Stats();
  109. container.appendChild( stats.dom );
  110. }
  111. function onWindowResize() {
  112. camera.aspect = window.innerWidth / window.innerHeight;
  113. camera.updateProjectionMatrix();
  114. renderer.setSize( window.innerWidth, window.innerHeight );
  115. }
  116. init();
  117. </script>
  118. </body>
  119. </html>