123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - loaders - MMD loader</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: #fff;
- color: #444;
- }
- a {
- color: #08f;
- }
- </style>
- </head>
- <body>
- <div id="info">
- <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - MMDLoader test<br />
- <a href="https://github.com/mrdoob/three.js/tree/master/examples/models/mmd#readme" target="_blank" rel="noopener">MMD Assets license</a><br />
- Copyright
- <a href="http://www.geocities.jp/higuchuu4/index_e.htm" target="_blank" rel="noopener">Model Data</a>
- <a href="http://www.nicovideo.jp/watch/sm13147122" target="_blank" rel="noopener">Dance Data</a>
- <a href="http://www.nicovideo.jp/watch/sm11938255" target="_blank" rel="noopener">Audio Data</a><br />
- Camera is customized from <a href="http://www.nicovideo.jp/watch/sm19168559" target="_blank" rel="noopener">this Data</a>
- </div>
- <script src="js/libs/ammo.js"></script>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import { OutlineEffect } from './jsm/effects/OutlineEffect.js';
- import { MMDLoader } from './jsm/loaders/MMDLoader.js';
- import { MMDAnimationHelper } from './jsm/animation/MMDAnimationHelper.js';
- var container;
- var mesh, camera, scene, renderer, effect;
- var helper;
- var ready = false;
- var clock = new THREE.Clock();
- Ammo().then( function ( AmmoLib ) {
- Ammo = AmmoLib;
- init();
- animate();
- } );
- function init() {
- container = document.createElement( 'div' );
- document.body.appendChild( container );
- camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
- // scene
- scene = new THREE.Scene();
- scene.background = new THREE.Color( 0xffffff );
- scene.add( new THREE.PolarGridHelper( 30, 10 ) );
- var ambient = new THREE.AmbientLight( 0x666666 );
- scene.add( ambient );
- var directionalLight = new THREE.DirectionalLight( 0x887766 );
- directionalLight.position.set( - 1, 1, 1 ).normalize();
- scene.add( directionalLight );
- //
- renderer = new THREE.WebGLRenderer( { antialias: true } );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- container.appendChild( renderer.domElement );
- effect = new OutlineEffect( renderer );
- // model
- function onProgress( xhr ) {
- if ( xhr.lengthComputable ) {
- var percentComplete = xhr.loaded / xhr.total * 100;
- console.log( Math.round( percentComplete, 2 ) + '% downloaded' );
- }
- }
- var modelFile = 'models/mmd/miku/miku_v2.pmd';
- var vmdFiles = [ 'models/mmd/vmds/wavefile_v2.vmd' ];
- var cameraFiles = [ 'models/mmd/vmds/wavefile_camera.vmd' ];
- var audioFile = 'models/mmd/audios/wavefile_short.mp3';
- var audioParams = { delayTime: 160 * 1 / 30 };
- helper = new MMDAnimationHelper();
- var loader = new MMDLoader();
- loader.loadWithAnimation( modelFile, vmdFiles, function ( mmd ) {
- mesh = mmd.mesh;
- helper.add( mesh, {
- animation: mmd.animation,
- physics: true
- } );
- loader.loadAnimation( cameraFiles, camera, function ( cameraAnimation ) {
- helper.add( camera, {
- animation: cameraAnimation
- } );
- new THREE.AudioLoader().load( audioFile, function ( buffer ) {
- var listener = new THREE.AudioListener();
- var audio = new THREE.Audio( listener ).setBuffer( buffer );
- listener.position.z = 1;
- helper.add( audio, audioParams );
- scene.add( audio );
- scene.add( listener );
- scene.add( mesh );
- ready = true;
- }, onProgress, null );
- }, onProgress, null );
- }, onProgress, null );
- //
- window.addEventListener( 'resize', onWindowResize, false );
- }
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- effect.setSize( window.innerWidth, window.innerHeight );
- }
- //
- function animate() {
- requestAnimationFrame( animate );
- render();
- }
- function render() {
- if ( ready ) {
- helper.update( clock.getDelta() );
- }
- effect.render( scene, camera );
- }
- </script>
- </body>
- </html>
|