سؤال

I'm currently trying to display a simple animated 3D model with Three.js. The file exports fine from 3DS Max, but when I try to animate it I get the error:

Uncaught TypeError: Cannot read property 'morphTargetInfluences' of undefined

I'm using the animation code found in http://threejs.org/examples/webgl_loader_collada.html

function animate() {

    requestAnimationFrame( animate );
    controls.update();

    for ( var i = 0; i < skin.morphTargetInfluences.length; i++ ) {

        skin.morphTargetInfluences[ i ] = 0;

    }

    skin.morphTargetInfluences[ Math.floor( explode * 30 ) ] = 1;

    render();
}

I have tracked the error down to the fact that my model has no skins. Is it possible for me to animate it anyway? The imported Three.js object does have a single entry in the Animations array.

هل كانت مفيدة؟

المحلول

I know it's an old post, but I also had the same problem when trying to load .dae file using ColladaLoader, so posting the comment in case someone is banging their head with the same problem.

You can probably load the animation if you have more than 30 bones.

If you look at the ColladaLoader.js, there is a line:

if(sortedbones.length < maxbones)

and maxbones is set to 30. So, if there aren't more than 30 bones, geometry.morphTargets is left undefined.

If you don't want to have so many bones, you can hack the ColladaLoader file and set maxbones to 1.


Adding to my comment.

I figure, newer version of the ColladaLoader don't have this problem. I'm not sure where I got the old files from...

You can get the newest files from GitHub. https://github.com/mrdoob/three.js

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top