webgl_loader_collada_skinning.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. scene.fog = new THREE.FogExp2( 0xfff4e5, 0.0003 );
  49. var light = new THREE.DirectionalLight( 0xffffff, 1.5 );
  50. light.position.set( 0, -4, -4 ).normalize();
  51. scene.add( light );
  52. renderer = new THREE.WebGLRenderer( { antialias: true } );
  53. renderer.setClearColor( scene.fog.color, 1 );
  54. renderer.setSize( window.innerWidth, window.innerHeight );
  55. renderer.sortObjects = false;
  56. container.appendChild( renderer.domElement );
  57. stats = new Stats();
  58. stats.domElement.style.position = 'absolute';
  59. stats.domElement.style.top = '0px';
  60. container.appendChild( stats.domElement );
  61. var loader = new THREE.ColladaLoader();
  62. loader.load( "./models/collada/avatar.dae", function ( geometry, materials ) {
  63. scene.add( geometry.scene );
  64. camera.lookAt(geometry.scene.children[0].children[1].position);
  65. var skin = geometry.scene.children[0].children[1];
  66. if ( skin.geometry.animation ) {
  67. THREE.AnimationHandler.add( skin.geometry.animation );
  68. var animation = new THREE.Animation(
  69. skin,
  70. skin.geometry.animation.name
  71. );
  72. // animation.loop = false;
  73. animation.play();
  74. }
  75. } );
  76. window.addEventListener( 'resize', onWindowResize, false );
  77. animate();
  78. }
  79. function onWindowResize() {
  80. camera.aspect = window.innerWidth / window.innerHeight;
  81. camera.updateProjectionMatrix();
  82. renderer.setSize( window.innerWidth, window.innerHeight );
  83. }
  84. function animate() {
  85. requestAnimationFrame( animate, renderer.domElement );
  86. var delta = clock.getDelta();
  87. THREE.AnimationHandler.update( delta );
  88. renderer.render( scene, camera );
  89. stats.update();
  90. }
  91. </script>
  92. </body>
  93. </html>