webgl_loader_3ds.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. <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, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
  25. </style>
  26. </head>
  27. <body>
  28. <div id="info">
  29. <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - 3DS loader
  30. </div>
  31. <script src="../build/three.js"></script>
  32. <script src="js/controls/TrackballControls.js"></script>
  33. <script src="js/loaders/TDSLoader.js"></script>
  34. <script>
  35. var container, controls;
  36. var camera, scene, renderer;
  37. init();
  38. animate();
  39. function init() {
  40. container = document.createElement( 'div' );
  41. document.body.appendChild( container );
  42. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 10 );
  43. camera.position.z = 2;
  44. controls = new THREE.TrackballControls( camera );
  45. scene = new THREE.Scene();
  46. scene.add( new THREE.HemisphereLight() );
  47. var directionalLight = new THREE.DirectionalLight( 0xffeedd );
  48. directionalLight.position.set( 0, 0, 2 );
  49. scene.add( directionalLight );
  50. //3ds files dont store normal maps
  51. var loader = new THREE.TextureLoader();
  52. var normal = loader.load( 'models/3ds/portalgun/textures/normal.jpg' );
  53. var loader = new THREE.TDSLoader( );
  54. loader.setResourcePath( 'models/3ds/portalgun/textures/' );
  55. loader.load( 'models/3ds/portalgun/portalgun.3ds', function ( object ) {
  56. object.traverse( function ( child ) {
  57. if ( child instanceof THREE.Mesh ) {
  58. child.material.normalMap = normal;
  59. }
  60. } );
  61. scene.add( object );
  62. });
  63. renderer = new THREE.WebGLRenderer();
  64. renderer.setPixelRatio( window.devicePixelRatio );
  65. renderer.setSize( window.innerWidth, window.innerHeight );
  66. container.appendChild( renderer.domElement );
  67. window.addEventListener( 'resize', resize, false );
  68. }
  69. function resize() {
  70. camera.aspect = window.innerWidth / window.innerHeight;
  71. camera.updateProjectionMatrix();
  72. renderer.setSize( window.innerWidth, window.innerHeight );
  73. }
  74. function animate() {
  75. controls.update();
  76. renderer.render( scene, camera );
  77. requestAnimationFrame( animate );
  78. }
  79. </script>
  80. </body>
  81. </html>