I'm trying to get a really basic Collada model to animate in three.js but I'm having some issues. The two examples (the monster and pump) both work on my machine, but whenever I substitute my model then it will load but it won't animate.
I stripped out a lot of the extra code from the examples and tried to make a really basic script. Here's my code:
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - collada</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
</head>
<body>
<script src="../build/three.min.js"></script>
<script src="js/loaders/ColladaLoader.js"></script>
<script src="js/Detector.js"></script>
<script>
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
var container;
var camera, scene, renderer, objects;
var dae, skin, animation, kfAnimation;
var clock = new THREE.Clock();
var loader = new THREE.ColladaLoader();
loader.load( './obj/Test1/TestSKINNED_Animation01.dae', function ( collada ) {
dae = collada.scene;
skin = collada.skins[ 0 ];
animation = collada.animations[0];
dae.scale.x = dae.scale.y = dae.scale.z = 1;
init();
animate();
} );
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
scene = new THREE.Scene();
// Add the camera
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
camera.position.set( 10, 2, 0 );
camera.lookAt( scene.position );
// Add the Collada
scene.add( dae );
var animHandler = THREE.AnimationHandler;
animHandler.add( animation );
kfAnimation = new THREE.KeyFrameAnimation( animation.node, animation.name );
kfAnimation.timeScale = 1;
kfAnimation.play( true, 0 );
// Add the light
var directionalLight = new THREE.DirectionalLight( 0xeeeeee );
directionalLight.position.set(0.5, 0.5, 0.5);
scene.add( directionalLight );
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
}
function animate() {
var delta = clock.getDelta();
kfAnimation.update(delta);
render();
requestAnimationFrame( animate );
}
function render() {
renderer.render( scene, camera );
}
</script>
</body>
</html>
It loads the model but it doesn't animate. Is this likely a problem with the code or the model? Thanks.