webgl_loader_3ds.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - loaders - OBJ 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">three.js</a> - TDSLoader 3DS loader test
  30. <p>Press the mouse right button to rotate the model and use the scroll wheel to zoom.</p>
  31. </div>
  32. <script src="../build/three.js"></script>
  33. <script src="js/loaders/TDSLoader.js"></script>
  34. <script src="js/libs/syncinput.min.js"></script>
  35. <script>
  36. var container;
  37. var camera, scene, renderer;
  38. var mouse;
  39. initialize();
  40. function initialize()
  41. {
  42. container = document.createElement( 'div' );
  43. document.body.appendChild( container );
  44. // Mouse
  45. mouse = new Mouse();
  46. // Camera
  47. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 2000 );
  48. camera.position.z = 2;
  49. // Setup scene
  50. scene = new THREE.Scene();
  51. var ambient = new THREE.AmbientLight( 0x101030 );
  52. scene.add( ambient );
  53. var directionalLight = new THREE.DirectionalLight( 0xffeedd );
  54. directionalLight.position.set( 0, 0, 2 );
  55. scene.add( directionalLight );
  56. // Texture
  57. var texture = new THREE.Texture();
  58. var loader = new THREE.ImageLoader();
  59. loader.load( 'models/3ds/portalgun/textures/color.jpg', function ( image ) {
  60. texture.image = image;
  61. texture.needsUpdate = true;
  62. } );
  63. // Normal texture
  64. var normal = new THREE.Texture();
  65. loader.load( 'models/3ds/portalgun/textures/normal.jpg', function ( image ) {
  66. normal.image = image;
  67. normal.needsUpdate = true;
  68. } );
  69. // 3DS Model
  70. var loader = new THREE.TDSLoader( );
  71. loader.load( 'models/3ds/portalgun/portalgun.3ds', function ( object ) {
  72. object.traverse( function ( child ) {
  73. if ( child instanceof THREE.Mesh ) {
  74. child.material.map = texture;
  75. child.material.normalMap = normal;
  76. }
  77. } );
  78. scene.add( object );
  79. });
  80. // Renderer
  81. renderer = new THREE.WebGLRenderer();
  82. renderer.setPixelRatio( window.devicePixelRatio );
  83. renderer.setSize( window.innerWidth, window.innerHeight );
  84. container.appendChild( renderer.domElement );
  85. window.addEventListener( 'resize', resize, false );
  86. update();
  87. }
  88. function update() {
  89. requestAnimationFrame( update );
  90. mouse.update();
  91. if ( mouse.buttonPressed( Mouse.LEFT ) ) {
  92. scene.rotation.y += mouse.delta.x * 0.01;
  93. }
  94. camera.position.z += mouse.wheel * 0.001;
  95. renderer.render( scene, camera );
  96. }
  97. function resize() {
  98. camera.aspect = window.innerWidth / window.innerHeight;
  99. camera.updateProjectionMatrix();
  100. renderer.setSize( window.innerWidth, window.innerHeight );
  101. }
  102. </script>
  103. </body>
  104. </html>