webgl_loader_3ds.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - loaders - 3DS 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> - 3DS loader
  12. </div>
  13. <script type="module">
  14. import * as THREE from '../build/three.module.js';
  15. import { TrackballControls } from './jsm/controls/TrackballControls.js';
  16. import { TDSLoader } from './jsm/loaders/TDSLoader.js';
  17. var container, controls;
  18. var camera, scene, renderer;
  19. init();
  20. animate();
  21. function init() {
  22. container = document.createElement( 'div' );
  23. document.body.appendChild( container );
  24. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 10 );
  25. camera.position.z = 2;
  26. scene = new THREE.Scene();
  27. scene.add( new THREE.HemisphereLight() );
  28. var directionalLight = new THREE.DirectionalLight( 0xffeedd );
  29. directionalLight.position.set( 0, 0, 2 );
  30. scene.add( directionalLight );
  31. //3ds files dont store normal maps
  32. var loader = new THREE.TextureLoader();
  33. var normal = loader.load( 'models/3ds/portalgun/textures/normal.jpg' );
  34. var loader = new TDSLoader( );
  35. loader.setResourcePath( 'models/3ds/portalgun/textures/' );
  36. loader.load( 'models/3ds/portalgun/portalgun.3ds', function ( object ) {
  37. object.traverse( function ( child ) {
  38. if ( child.isMesh ) {
  39. child.material.normalMap = normal;
  40. }
  41. } );
  42. scene.add( object );
  43. } );
  44. renderer = new THREE.WebGLRenderer();
  45. renderer.setPixelRatio( window.devicePixelRatio );
  46. renderer.setSize( window.innerWidth, window.innerHeight );
  47. container.appendChild( renderer.domElement );
  48. controls = new TrackballControls( camera, renderer.domElement );
  49. window.addEventListener( 'resize', resize, false );
  50. }
  51. function resize() {
  52. camera.aspect = window.innerWidth / window.innerHeight;
  53. camera.updateProjectionMatrix();
  54. renderer.setSize( window.innerWidth, window.innerHeight );
  55. }
  56. function animate() {
  57. controls.update();
  58. renderer.render( scene, camera );
  59. requestAnimationFrame( animate );
  60. }
  61. </script>
  62. </body>
  63. </html>