webgl_loader_lwo.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. </style>
  29. </head>
  30. <body>
  31. <div id="info">
  32. <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - LWOLoader<br />
  33. <P>Loader for Lightwave LWO V3 file format, by <a href="https://discoverthreejs.com/" target="_blank" rel="noopener">Discover three.js</a></P>
  34. </div>
  35. <script src="../build/three.js"></script>
  36. <script src="js/loaders/LWOLoader.js"></script>
  37. <script src="js/controls/OrbitControls.js"></script>
  38. <script src="js/WebGL.js"></script>
  39. <script src="js/libs/stats.min.js"></script>
  40. <script>
  41. if ( WEBGL.isWebGLAvailable() === false ) {
  42. document.body.appendChild( WEBGL.getWebGLErrorMessage() );
  43. }
  44. var container, stats, controls;
  45. var camera, scene, renderer;
  46. function init() {
  47. container = document.createElement( 'div' );
  48. document.body.appendChild( container );
  49. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 200 );
  50. camera.position.set( 5, 4, 20 );
  51. controls = new THREE.OrbitControls( camera );
  52. controls.target.y = 4;
  53. controls.update();
  54. scene = new THREE.Scene();
  55. scene.background = new THREE.Color( 0xa0a0a0 );
  56. var ambientLight = new THREE.HemisphereLight( 0xddeeff, 0x0f0e0d, 2 );
  57. var mainLight = new THREE.DirectionalLight( 0xffffff, 2 );
  58. mainLight.position.set( 10, 10, - 10 );
  59. scene.add( ambientLight, mainLight );
  60. var grid = new THREE.GridHelper( 200, 20, 0x000000, 0x000000 );
  61. grid.material.opacity = 0.2;
  62. grid.material.transparent = true;
  63. scene.add( grid );
  64. var loader = new THREE.LWOLoader();
  65. loader.load( 'models/lwo/StandardMaterials.lwo', function ( lwo ) {
  66. const mesh = lwo.meshes[ 0 ];
  67. mesh.position.set( 3, 6, 0 );
  68. scene.add( mesh );
  69. } );
  70. renderer = new THREE.WebGLRenderer( { antialias: true } );
  71. renderer.setPixelRatio( window.devicePixelRatio );
  72. renderer.setSize( window.innerWidth, window.innerHeight );
  73. renderer.physicallyCorrectLights = true;
  74. renderer.gammaFactor = 2.2;
  75. renderer.gammaOutput = true;
  76. container.appendChild( renderer.domElement );
  77. renderer.setAnimationLoop( function () {
  78. stats.begin();
  79. renderer.render( scene, camera );
  80. stats.end();
  81. } );
  82. window.addEventListener( 'resize', onWindowResize, false );
  83. // stats
  84. stats = new Stats();
  85. container.appendChild( stats.dom );
  86. }
  87. function onWindowResize() {
  88. camera.aspect = window.innerWidth / window.innerHeight;
  89. camera.updateProjectionMatrix();
  90. renderer.setSize( window.innerWidth, window.innerHeight );
  91. }
  92. init();
  93. </script>
  94. </body>
  95. </html>