全部代码就不贴上了 太多了 有兴趣可以查看 源码
https://github.com/bemlai/webglMmd
function init() {
var loader = new THREE.MMDLoader();
helper = new THREE.MMDHelper();
var audioParams ={ delayTime:0 };// { delayTime: 160 * 1 / 30 };
loader.load( modelFile, vmdFiles, function ( object ) {
mesh = object;
mesh.castShadow = true;
mesh.receiveShadow = true;
helper.add( mesh );
helper.setAnimation( mesh );
//helper.setPhysics( mesh );
/
/*
* Note: create CCDIKHelper after calling helper.setAnimation()
*/
//骨骼辅助显示
ikHelper = new THREE.CCDIKHelper( mesh );
ikHelper.visible = false;
scene.add( ikHelper );
/*
* Note: You're recommended to call helper.setPhysics()
* after calling helper.setAnimation().
*
*/
//物理刚体辅助显示
helper.setPhysics( mesh );
physicsHelper = new THREE.MMDPhysicsHelper( mesh );
physicsHelper.visible = false;
scene.add( physicsHelper );
//
//描边 已取消
//effect.enabled = false;
loader.loadVmds( cameraFiles, function ( vmd ) {
helper.setCamera( myMmdScen.camera );
loader.pourVmdIntoCamera( myMmdScen.camera, vmd );
helper.setCameraAnimation( myMmdScen.camera );
//默认初始化不开启自动镜头,改到加载后,时间同步、
//更改 开启镜头
//helper.doCameraAnimation = true;
if(helper.doCameraAnimation)SLOG("开启自动镜头");
loader.loadAudio( audioFile, function ( audio, listener ) {
helper.setAudio( audio, listener, audioParams );
//===================
//helper.doCameraAnimation = false;
/*
* Note: call this method after you set all animations
* including camera and audio.
*/
//console.log("统一模型工作时间");
// 该函数作用:查找摄像机 音频 动作数据 模块 中最长的时间 当到达最最长时间 所有都停止 如果未设置 则模块到达自己结束时间停止 不会同步
helper.unifyAnimationDuration();
if(myMmdScen.camera.add( listener ))SLOG("音频已绑定至相机");
if(scene.add( mesh ))SLOG("模型已添加至场景");
if(mesh.add( audio ))SLOG("音频已添加至模型");
readyStarHtml();
renderer.render( scene, myMmdScen.camera );
SLOG("就绪   :)");
//helper.doCameraAnimation = false;
}, onProgress, onError );
}, onProgress, onError );
}, onProgress, onError );
//effect.enabled = false;
//document.getElementById('otherinfo1').innerHTML = "";
}