webgl_loader_collada_skinning.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - collada - skinning</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. color: #000;
  10. font-family:Monospace;
  11. font-size:13px;
  12. text-align:center;
  13. background-color: #000;
  14. margin: 0px;
  15. overflow: hidden;
  16. }
  17. #info {
  18. position: absolute;
  19. top: 0px; width: 100%;
  20. padding: 5px;
  21. }
  22. a {
  23. color: #f00;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <div id="container"></div>
  29. <div id="info">
  30. <a href="http://threejs.org" target="_blank">three.js</a> webgl - collada - skinning
  31. </div>
  32. <script src="../build/three.min.js"></script>
  33. <script src="js/loaders/ColladaLoader.js"></script>
  34. <script src="js/Detector.js"></script>
  35. <script src="js/libs/stats.min.js"></script>
  36. <script>
  37. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  38. var container, stats;
  39. var camera, scene, renderer;
  40. var clock = new THREE.Clock();
  41. init();
  42. function init() {
  43. container = document.getElementById( 'container' );
  44. camera = new THREE.PerspectiveCamera( 25, window.innerWidth / window.innerHeight, 1, 10000 );
  45. camera.position.set( -5, -5, 5 );
  46. camera.up.set( 0, 0, 1 );
  47. scene = new THREE.Scene();
  48. var light = new THREE.DirectionalLight( 0xffffff, 1.5 );
  49. light.position.set( 0, -4, -4 ).normalize();
  50. scene.add( light );
  51. renderer = new THREE.WebGLRenderer( { antialias: true } );
  52. renderer.setClearColor( 0xfff4e5 );
  53. renderer.setSize( window.innerWidth, window.innerHeight );
  54. renderer.sortObjects = false;
  55. container.appendChild( renderer.domElement );
  56. stats = new Stats();
  57. stats.domElement.style.position = 'absolute';
  58. stats.domElement.style.top = '0px';
  59. container.appendChild( stats.domElement );
  60. var loader = new THREE.ColladaLoader();
  61. loader.load( "./models/collada/avatar.dae", function ( collada ) {
  62. collada.scene.traverse( function ( child ) {
  63. if ( child instanceof THREE.SkinnedMesh ) {
  64. var animation = new THREE.Animation( child );
  65. animation.play();
  66. camera.lookAt( child.position );
  67. }
  68. } );
  69. scene.add( collada.scene );
  70. } );
  71. window.addEventListener( 'resize', onWindowResize, false );
  72. animate();
  73. }
  74. function onWindowResize() {
  75. camera.aspect = window.innerWidth / window.innerHeight;
  76. camera.updateProjectionMatrix();
  77. renderer.setSize( window.innerWidth, window.innerHeight );
  78. }
  79. function animate() {
  80. requestAnimationFrame( animate, renderer.domElement );
  81. THREE.AnimationHandler.update( clock.getDelta() );
  82. renderer.render( scene, camera );
  83. stats.update();
  84. }
  85. </script>
  86. </body>
  87. </html>