123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - loaders - BVHLoader</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
- <link type="text/css" rel="stylesheet" href="main.css">
- <style>
- body {
- background-color: #eee;
- color: #444;
- }
- a {
- color: #08f;
- }
- </style>
- </head>
- <body>
- <div id="info">
- <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - BVH Loader<br/>
- animation from <a href="http://mocap.cs.cmu.edu/">http://mocap.cs.cmu.edu/</a>
- </div>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import { OrbitControls } from './jsm/controls/OrbitControls.js';
- import { BVHLoader } from './jsm/loaders/BVHLoader.js';
- var clock = new THREE.Clock();
- var camera, controls, scene, renderer;
- var mixer, skeletonHelper;
- init();
- animate();
- var loader = new BVHLoader();
- loader.load( "models/bvh/pirouette.bvh", function ( result ) {
- skeletonHelper = new THREE.SkeletonHelper( result.skeleton.bones[ 0 ] );
- skeletonHelper.skeleton = result.skeleton; // allow animation mixer to bind to THREE.SkeletonHelper directly
- var boneContainer = new THREE.Group();
- boneContainer.add( result.skeleton.bones[ 0 ] );
- scene.add( skeletonHelper );
- scene.add( boneContainer );
- // play animation
- mixer = new THREE.AnimationMixer( skeletonHelper );
- mixer.clipAction( result.clip ).setEffectiveWeight( 1.0 ).play();
- } );
- function init() {
- camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
- camera.position.set( 0, 200, 400 );
- scene = new THREE.Scene();
- scene.background = new THREE.Color( 0xeeeeee );
- scene.add( new THREE.GridHelper( 400, 10 ) );
- // renderer
- renderer = new THREE.WebGLRenderer( { antialias: true } );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- document.body.appendChild( renderer.domElement );
- controls = new OrbitControls( camera, renderer.domElement );
- controls.minDistance = 300;
- controls.maxDistance = 700;
- window.addEventListener( 'resize', onWindowResize, false );
- }
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- }
- function animate() {
- requestAnimationFrame( animate );
- var delta = clock.getDelta();
- if ( mixer ) mixer.update( delta );
- renderer.render( scene, camera );
- }
- </script>
- </body>
- </html>
|