webgl_loader_bvh.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - loaders - BVHLoader</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. <style>
  9. body {
  10. background-color: #eee;
  11. color: #444;
  12. }
  13. a {
  14. color: #08f;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <div id="info">
  20. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - BVH Loader<br/>
  21. animation from <a href="http://mocap.cs.cmu.edu/">http://mocap.cs.cmu.edu/</a>
  22. </div>
  23. <script type="module">
  24. import * as THREE from '../build/three.module.js';
  25. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  26. import { BVHLoader } from './jsm/loaders/BVHLoader.js';
  27. var clock = new THREE.Clock();
  28. var camera, controls, scene, renderer;
  29. var mixer, skeletonHelper;
  30. init();
  31. animate();
  32. var loader = new BVHLoader();
  33. loader.load( "models/bvh/pirouette.bvh", function ( result ) {
  34. skeletonHelper = new THREE.SkeletonHelper( result.skeleton.bones[ 0 ] );
  35. skeletonHelper.skeleton = result.skeleton; // allow animation mixer to bind to THREE.SkeletonHelper directly
  36. var boneContainer = new THREE.Group();
  37. boneContainer.add( result.skeleton.bones[ 0 ] );
  38. scene.add( skeletonHelper );
  39. scene.add( boneContainer );
  40. // play animation
  41. mixer = new THREE.AnimationMixer( skeletonHelper );
  42. mixer.clipAction( result.clip ).setEffectiveWeight( 1.0 ).play();
  43. } );
  44. function init() {
  45. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
  46. camera.position.set( 0, 200, 400 );
  47. scene = new THREE.Scene();
  48. scene.background = new THREE.Color( 0xeeeeee );
  49. scene.add( new THREE.GridHelper( 400, 10 ) );
  50. // renderer
  51. renderer = new THREE.WebGLRenderer( { antialias: true } );
  52. renderer.setPixelRatio( window.devicePixelRatio );
  53. renderer.setSize( window.innerWidth, window.innerHeight );
  54. document.body.appendChild( renderer.domElement );
  55. controls = new OrbitControls( camera, renderer.domElement );
  56. controls.minDistance = 300;
  57. controls.maxDistance = 700;
  58. window.addEventListener( 'resize', onWindowResize, false );
  59. }
  60. function onWindowResize() {
  61. camera.aspect = window.innerWidth / window.innerHeight;
  62. camera.updateProjectionMatrix();
  63. renderer.setSize( window.innerWidth, window.innerHeight );
  64. }
  65. function animate() {
  66. requestAnimationFrame( animate );
  67. var delta = clock.getDelta();
  68. if ( mixer ) mixer.update( delta );
  69. renderer.render( scene, camera );
  70. }
  71. </script>
  72. </body>
  73. </html>