You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/StudyCenter/wwwroot/lib/three.js/examples/webgl_loader_mmd.html

277 lines
6.2 KiB

<!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">
<style>
body {
font-family: Monospace;
background-color: #fff;
color: #000;
margin: 0px;
overflow: hidden;
}
#info {
color: #000;
position: absolute;
top: 10px;
width: 100%;
text-align: center;
display:block;
}
#info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
</style>
</head>
<body>
<div id="info">
<a href="http://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>
</div>
<script src="../build/three.js"></script>
<script src="js/libs/mmdparser.min.js"></script>
<script src="js/libs/ammo.js"></script>
<script src="js/loaders/TGALoader.js"></script>
<script src="js/loaders/MMDLoader.js"></script>
<script src="js/effects/OutlineEffect.js"></script>
<script src="js/animation/CCDIKSolver.js"></script>
<script src="js/animation/MMDPhysics.js"></script>
<script src="js/animation/MMDAnimationHelper.js"></script>
<script src="js/controls/OrbitControls.js"></script>
<script src="js/libs/stats.min.js"></script>
<script src="js/libs/dat.gui.min.js"></script>
<script>
var container, stats;
var mesh, camera, scene, renderer, effect;
var helper, ikHelper, physicsHelper;
var clock = new THREE.Clock();
init();
animate();
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
camera.position.z = 30;
// scene
scene = new THREE.Scene();
scene.background = new THREE.Color( 0xffffff );
var gridHelper = new THREE.PolarGridHelper( 30, 10 );
gridHelper.position.y = - 10;
scene.add( gridHelper );
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 THREE.OutlineEffect( renderer );
// STATS
stats = new Stats();
container.appendChild( stats.dom );
// 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' ];
helper = new THREE.MMDAnimationHelper( {
afterglow: 2.0
} );
var loader = new THREE.MMDLoader();
loader.loadWithAnimation( modelFile, vmdFiles, function ( mmd ) {
mesh = mmd.mesh;
mesh.position.y = - 10;
scene.add( mesh );
helper.add( mesh, {
animation: mmd.animation,
physics: true
} );
ikHelper = helper.objects.get( mesh ).ikSolver.createHelper();
ikHelper.visible = false;
scene.add( ikHelper );
physicsHelper = helper.objects.get( mesh ).physics.createHelper();
physicsHelper.visible = false;
scene.add( physicsHelper );
initGui();
}, onProgress, null );
var controls = new THREE.OrbitControls( camera, renderer.domElement );
window.addEventListener( 'resize', onWindowResize, false );
var phongMaterials;
var originalMaterials;
function makePhongMaterials( materials ) {
var array = [];
for ( var i = 0, il = materials.length; i < il; i ++ ) {
var m = new THREE.MeshPhongMaterial();
m.copy( materials[ i ] );
m.needsUpdate = true;
array.push( m );
}
phongMaterials = array;
}
function initGui() {
var api = {
'animation': true,
'gradient mapping': true,
'ik': true,
'outline': true,
'physics': true,
'show IK bones': false,
'show rigid bodies': false
};
var gui = new dat.GUI();
gui.add( api, 'animation' ).onChange( function () {
helper.enable( 'animation', api[ 'animation' ] );
} );
gui.add( api, 'gradient mapping' ).onChange( function () {
if ( originalMaterials === undefined ) originalMaterials = mesh.material;
if ( phongMaterials === undefined ) makePhongMaterials( mesh.material );
if ( api[ 'gradient mapping' ] ) {
mesh.material = originalMaterials;
} else {
mesh.material = phongMaterials;
}
} );
gui.add( api, 'ik' ).onChange( function () {
helper.enable( 'ik', api[ 'ik' ] );
} );
gui.add( api, 'outline' ).onChange( function () {
effect.enabled = api[ 'outline' ];
} );
gui.add( api, 'physics' ).onChange( function () {
helper.enable( 'physics', api[ 'physics' ] );
} );
gui.add( api, 'show IK bones' ).onChange( function () {
ikHelper.visible = api[ 'show IK bones' ];
} );
gui.add( api, 'show rigid bodies' ).onChange( function () {
if ( physicsHelper !== undefined ) physicsHelper.visible = api[ 'show rigid bodies' ];
} );
}
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
effect.setSize( window.innerWidth, window.innerHeight );
}
//
function animate() {
requestAnimationFrame( animate );
stats.begin();
render();
stats.end();
}
function render() {
helper.update( clock.getDelta() );
effect.render( scene, camera );
}
</script>
</body>
</html>