I've been struggling to animate the exported mesh from my blender. Even the included buffalo mesh that I see animated in the example is not working for me. I've been attempting to replicate it without success. Here's the code, and I think there might be a simple issue that I'm missing, but I can't figure it out. I don't think it's a problem with blender since I can't animate any of the included meshes.
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - blender</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: #000000;
margin: 0px;
overflow: hidden;
}
#info {
color: #fff;
position: absolute;
top: 10px;
width: 100%;
text-align: center;
z-index: 100;
display:block;
}
a { color: red }
#stats { position: absolute; top:0; left: 0 }
#stats #fps { background: transparent !important }
#stats #fps #fpsText { color: #aaa !important }
#stats #fps #fpsGraph { display: none }
</style>
</head>
<body>
<div id="info">
<a href="http://crenet-games.com">025 Valgany</a>
</div>
<script src="/js/three.min.js"></script>
<script src="/js/Detector.js"></script>
<script src="/js/libs/stats.min.js"></script>
<script>
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
var modelBB={"min":new THREE.Vector3(),"max":new THREE.Vector3() };
var crewon, animation;
var container, stats;
var camera, scene, renderer, objects;
var particleLight, pointLight;
var skin;
var clock = new THREE.Clock();
init();
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.1, 10000 );
camera.position.set( 2, 4, 5 );
scene = new THREE.Scene();
scene.fog = new THREE.FogExp2( 0x00FF00, 0.035 );
var loader = new THREE.JSONLoader(true);
loader.load("buffalo.js", function(geometry, materials) {
geometry.computeBoundingBox();
var faceMaterial = new THREE.MeshFaceMaterial( materials );
faceMaterial.skinning = true;
THREE.AnimationHandler.add( geometry.animation );
crewon = new THREE.SkinnedMesh(geometry,faceMaterial, false);
modelBB=geometry.boundingBox;
crewon.position.set(0,0,0);
scene.add(crewon);
renderer.render(scene, camera);
animation = new THREE.Animation( crewon, geometry.animation.name );
animation.play( true, 0.5 );
});
// Lights
scene.add( new THREE.AmbientLight( 0xcccccc ) );
pointLight = new THREE.PointLight( 0xffffff, 1, 30 );
pointLight.position.set( 5, 0, 0 );
scene.add( pointLight );
// Renderer
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
// Stats
stats = new Stats();
container.appendChild( stats.domElement );
// Events
window.addEventListener( 'resize', onWindowResize, false );
animate();
}
function onWindowResize( event ) {
renderer.setSize( window.innerWidth, window.innerHeight );
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
}
function animate() {
requestAnimationFrame( animate, renderer.domElement );
var delta = clock.getDelta();
THREE.AnimationHandler.update( delta );
render();
stats.update();
}
function render() {
if ( crewon ){
crewon.rotation.y+=0.01;
}
if( typeof animation != 'undefined' && animation!=null){
animation.update(0.1);
}
if( typeof modelBB != 'undefined' && modelBB!=null){
camera.position.x = 0;
camera.position.y = (modelBB.max.y-modelBB.min.y)/2;
camera.position.z = (modelBB.max.z-modelBB.min.z)*2;
camera.lookAt( new THREE.Vector3(
0,
(modelBB.max.y-modelBB.min.y)/2,
0) );
}
renderer.render( scene, camera );
}
</script>
</body>
</html>