webgl_loader_collada.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - collada</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="container"></div>
  11. <div id="info">
  12. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> collada loader<br/>
  13. Elf Girl by <a href="https://sketchfab.com/yellow09" target="_blank" rel="noopener">halloween</a>, <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank" rel="noopener">CC Attribution</a>
  14. </div>
  15. <script type="module">
  16. import * as THREE from '../build/three.module.js';
  17. import Stats from './jsm/libs/stats.module.js';
  18. import { ColladaLoader } from './jsm/loaders/ColladaLoader.js';
  19. var container, stats, clock;
  20. var camera, scene, renderer, elf;
  21. init();
  22. animate();
  23. function init() {
  24. container = document.getElementById( 'container' );
  25. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 2000 );
  26. camera.position.set( 8, 10, 8 );
  27. camera.lookAt( 0, 3, 0 );
  28. scene = new THREE.Scene();
  29. clock = new THREE.Clock();
  30. // loading manager
  31. var loadingManager = new THREE.LoadingManager( function () {
  32. scene.add( elf );
  33. } );
  34. // collada
  35. var loader = new ColladaLoader( loadingManager );
  36. loader.load( './models/collada/elf/elf.dae', function ( collada ) {
  37. elf = collada.scene;
  38. } );
  39. //
  40. var ambientLight = new THREE.AmbientLight( 0xcccccc, 0.4 );
  41. scene.add( ambientLight );
  42. var directionalLight = new THREE.DirectionalLight( 0xffffff, 0.8 );
  43. directionalLight.position.set( 1, 1, 0 ).normalize();
  44. scene.add( directionalLight );
  45. //
  46. renderer = new THREE.WebGLRenderer();
  47. renderer.setPixelRatio( window.devicePixelRatio );
  48. renderer.setSize( window.innerWidth, window.innerHeight );
  49. container.appendChild( renderer.domElement );
  50. //
  51. stats = new Stats();
  52. container.appendChild( stats.dom );
  53. //
  54. window.addEventListener( 'resize', onWindowResize, false );
  55. }
  56. function onWindowResize() {
  57. camera.aspect = window.innerWidth / window.innerHeight;
  58. camera.updateProjectionMatrix();
  59. renderer.setSize( window.innerWidth, window.innerHeight );
  60. }
  61. function animate() {
  62. requestAnimationFrame( animate );
  63. render();
  64. stats.update();
  65. }
  66. function render() {
  67. var delta = clock.getDelta();
  68. if ( elf !== undefined ) {
  69. elf.rotation.z += delta * 0.5;
  70. }
  71. renderer.render( scene, camera );
  72. }
  73. </script>
  74. </body>
  75. </html>