2
0

webgl_loader_collada_skinning.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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.js"></script>
  33. <script src="js/loaders/collada/Animation.js"></script>
  34. <script src="js/loaders/collada/AnimationHandler.js"></script>
  35. <script src="js/loaders/collada/KeyFrameAnimation.js"></script>
  36. <script src="js/loaders/ColladaLoader.js"></script>
  37. <script src="js/Detector.js"></script>
  38. <script src="js/libs/stats.min.js"></script>
  39. <script>
  40. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  41. var container, stats;
  42. var camera, scene, renderer;
  43. var clock = new THREE.Clock();
  44. init();
  45. function init() {
  46. container = document.getElementById( 'container' );
  47. camera = new THREE.PerspectiveCamera( 25, window.innerWidth / window.innerHeight, 1, 10000 );
  48. camera.position.set( -5, -5, 5 );
  49. camera.up.set( 0, 0, 1 );
  50. scene = new THREE.Scene();
  51. var light = new THREE.DirectionalLight( 0xffffff, 1.5 );
  52. light.position.set( 0, -4, -4 ).normalize();
  53. scene.add( light );
  54. renderer = new THREE.WebGLRenderer( { antialias: true } );
  55. renderer.setClearColor( 0xfff4e5 );
  56. renderer.setPixelRatio( window.devicePixelRatio );
  57. renderer.setSize( window.innerWidth, window.innerHeight );
  58. renderer.sortObjects = false;
  59. container.appendChild( renderer.domElement );
  60. stats = new Stats();
  61. container.appendChild( stats.dom );
  62. var loader = new THREE.ColladaLoader();
  63. loader.load( "./models/collada/avatar.dae", function ( collada ) {
  64. collada.scene.traverse( function ( child ) {
  65. if ( child instanceof THREE.SkinnedMesh ) {
  66. var animation = new THREE.Animation( child, child.geometry.animation );
  67. animation.play();
  68. camera.lookAt( child.position );
  69. }
  70. } );
  71. scene.add( collada.scene );
  72. } );
  73. window.addEventListener( 'resize', onWindowResize, false );
  74. animate();
  75. }
  76. function onWindowResize() {
  77. camera.aspect = window.innerWidth / window.innerHeight;
  78. camera.updateProjectionMatrix();
  79. renderer.setSize( window.innerWidth, window.innerHeight );
  80. }
  81. function animate() {
  82. requestAnimationFrame( animate, renderer.domElement );
  83. THREE.AnimationHandler.update( clock.getDelta() );
  84. renderer.render( scene, camera );
  85. stats.update();
  86. }
  87. </script>
  88. </body>
  89. </html>