Clone skinned mesh with SkeletonUtils undefined error

I am loading fbx model like this:

function loadModel(url) {
return new Promise(res => { fbxLoader.load(url, res); })
}

    //Function that is called after model is loaded where basic setup for model is done ( material, size etc.) and it's stored in the array
    function storeLoadedModel(object, size, position, _mat) {            
    
        object.children[0].material = mat; 

        object.scale.set(1, 1, 1);
        object.position.set(0,0,0);

        models.push(object);
    }

After this I want to instantiate bunch of same models with animation

for(let i = 0; i < amount; i++) {

            console.log(models[0]);
            const animatedModel = SkeletonUtils.clone(models[0]);

but the skeleton utils throw this error:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘clone’)
at Object.subclip (chunk-JKTWCPHD.js?v=e962c5f6:22666:27)

I cant figure out why it’s undefined, when I don’t use the clone(), it’s working fine and model loads fine. When i log the model I am getting the model, it’s a group with animations, material, children etc. All looks fine, but for whatever it’s undefined. It probably has something to do with the subclip?

well, where did you define it? (normally that would be an import statement)

edit: just to make sure, the error says SkeletonUtils is undefined, not models[0]

1 Like

This is how I define it:

import * as SkeletonUtils from ‘three/examples/jsm/utils/SkeletonUtils.js’;

Are you sure that SkeletonUtils is not defined? Reading the error, it complains about subclip, which I am using. It also specifies the error line to be on the subclip line

const animatedModel = SkeletonUtils.clone(models[0]);

const mixer = new THREE.AnimationMixer(animatedModel);
const idleAnim = animatedModel.animations[0];
const idleAnimTrim = THREE.AnimationUtils.subclip(idleAnim, ‘idle’, 10, 100);

Ani idea if SkeletonUtils copy has issue with subclips?

ah then Ig animatedModel.animations[0] is undefined, since it does

function subclip( sourceClip, name, startFrame, endFrame, fps = 30 ) {

	const clip = sourceClip.clone();

^^ this. try using models[0].animations[0] instead?

I am using fbx with defined subclips in 3ds max. The only way I was able to get it working in threejs from 3ds max was using fbx, so I have to use subclips.
So the SkeletonUtils probably is not able to clone it along with subclips it seems.

The only solution I was able to figure out so far was to load the same model multiple times instead of cloning it. That is of course bad, but is only solution for me right now.