webgl_loader_collada.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. <style>
  8. body {
  9. background:#777;
  10. padding:0;
  11. margin:0;
  12. overflow:hidden;
  13. }
  14. #info {
  15. position: absolute;
  16. top: 0px;
  17. width: 100%;
  18. color: #ffffff;
  19. padding: 5px;
  20. font-family:Monospace;
  21. font-size:13px;
  22. text-align:center;
  23. }
  24. a {
  25. color: #ffffff;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <div id="container"></div>
  31. <div id="info">
  32. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> collada loader
  33. | Elf Girl by <a href="https://sketchfab.com/yellow09" target="_blank" rel="noopener">halloween</a> is licensed under <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank" rel="noopener">CC Attribution</a>
  34. </div>
  35. <script src="../build/three.js"></script>
  36. <script src="js/loaders/ColladaLoader.js"></script>
  37. <script src="js/WebGL.js"></script>
  38. <script src="js/libs/stats.min.js"></script>
  39. <script>
  40. if ( WEBGL.isWebGLAvailable() === false ) {
  41. document.body.appendChild( WEBGL.getWebGLErrorMessage() );
  42. }
  43. var container, stats, clock;
  44. var camera, scene, renderer, elf;
  45. init();
  46. animate();
  47. function init() {
  48. container = document.getElementById( 'container' );
  49. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 2000 );
  50. camera.position.set( 8, 10, 8 );
  51. camera.lookAt( 0, 3, 0 );
  52. scene = new THREE.Scene();
  53. clock = new THREE.Clock();
  54. // loading manager
  55. var loadingManager = new THREE.LoadingManager( function() {
  56. scene.add( elf );
  57. } );
  58. // collada
  59. var loader = new THREE.ColladaLoader( loadingManager );
  60. loader.load( './models/collada/elf/elf.dae', function ( collada ) {
  61. elf = collada.scene;
  62. } );
  63. //
  64. var ambientLight = new THREE.AmbientLight( 0xcccccc, 0.4 );
  65. scene.add( ambientLight );
  66. var directionalLight = new THREE.DirectionalLight( 0xffffff, 0.8 );
  67. directionalLight.position.set( 1, 1, 0 ).normalize();
  68. scene.add( directionalLight );
  69. //
  70. renderer = new THREE.WebGLRenderer();
  71. renderer.setPixelRatio( window.devicePixelRatio );
  72. renderer.setSize( window.innerWidth, window.innerHeight );
  73. container.appendChild( renderer.domElement );
  74. //
  75. stats = new Stats();
  76. container.appendChild( stats.dom );
  77. //
  78. window.addEventListener( 'resize', onWindowResize, false );
  79. }
  80. function onWindowResize() {
  81. camera.aspect = window.innerWidth / window.innerHeight;
  82. camera.updateProjectionMatrix();
  83. renderer.setSize( window.innerWidth, window.innerHeight );
  84. }
  85. function animate() {
  86. requestAnimationFrame( animate );
  87. render();
  88. stats.update();
  89. }
  90. function render() {
  91. var delta = clock.getDelta();
  92. if ( elf !== undefined ) {
  93. elf.rotation.z += delta * 0.5;
  94. }
  95. renderer.render( scene, camera );
  96. }
  97. </script>
  98. </body>
  99. </html>