I published a video, which is explaining the way to convert MMD files ( PMX and VMD ) to a JSON file for three.js.
Here is it.
The convert was operated on Blender.
some bones of the MMD model are controled by IK or physics. However, three.js does not support IK and physics. Therefore, you need to bake all bones as FK bones.
import bpy
for obj in bpy.data.objects:
obj.name = 'obj'
for mesh in bpy.data.meshes:
mesh.name = 'mesh'
for armature in bpy.data.armatures:
armature.name = 'arm'
for bone in armature.bones:
bone.name = 'b'
for material in bpy.data.materials:
material.name = 'm'
Fix the rest pose. To do so, press control + A, and then check all transforms.
Make sure that you checked “Skeltal animation”, and “Copy textures”. if you have already published textures, dont check “Copy textures”. Then, press “Export Three.js”. Publishing may take a few min.
WIP
As the result, you will see like this example (about 4MB).
var width = window.innerWidth,
height = window.innerHeight,
clock = new THREE.Clock(),
scene,
camera,
renderer,
loader,
miku,
action;
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 40, width / height, 1, 1000 );
camera.position.set( 0, 2, 6 );
renderer = new THREE.WebGLRenderer();
renderer.setSize( width, height );
document.body.appendChild( renderer.domElement );
var ambientLight = new THREE.AmbientLight( 0xffffff )
scene.add( ambientLight );
var directionalLight = new THREE.DirectionalLight( 0xffffff );
directionalLight.position.set( .5, 1, .5 ).normalize();
scene.add( directionalLight );
scene.add( new THREE.GridHelper( 10, 1 ) );
loader = new THREE.JSONLoader();
loader.load( 'miku.js', function( geometry, materials ) {
materials.forEach(function ( mat ) {
mat.skinning = true;
// mat.wireframe = true;
} );
miku = new THREE.SkinnedMesh(
geometry,
new THREE.MeshFaceMaterial( materials )
);
THREE.AnimationHandler.add( miku.geometry.animations[ 0 ] );
action = new THREE.Animation(
miku,
miku.geometry.animations[ 0 ].name,
THREE.AnimationHandler.CATMULLROM
);
scene.add( miku );
action.play();
} );
( function renderLoop (){
requestAnimationFrame( renderLoop );
var delta = clock.getDelta();
THREE.AnimationHandler.update( delta );
renderer.render( scene, camera );
} )();