Hello guys.
I have FBX model and FBX animation loaded dynamically.
How to apply animation to model?
Animation object is a THREE.Group object with 1 children - THREE.Bone. I guess i have to add that bone to model, but dunno how to do that correcly. And also i tried to convert animation object to AnimationClip and animation started playing, but not for whole model (video).
Thank you
I have an update.
I used skeleton helper for model and added to its bones 1 bone from animation object.
So now skeleton animated correctly, but not the model.
How to apply that skeleton for model?
_LoadModels() {
const loader = new FBXLoader();
loader.setPath('./resources/guard/');
loader.load('guard.fbx', (fbx) => {
this._target = fbx;
this._target.scale.setScalar(0.038);
this._params.scene.add(this._target);
this._target.name = 'player';
this._bones = {};
for (let b of this._target.children[1].skeleton.bones) {
this._bones[b.name] = b;
}
this._target.traverse(c => {
c.castShadow = true;
c.receiveShadow = true;
if (c.material && c.material.map) {
c.material.map.encoding = THREE.sRGBEncoding;
}
});
this.Broadcast({
topic: 'load.character',
model: this._target,
bones: this._bones,
});
this._mixer = new THREE.AnimationMixer(this._target);
const _OnLoad = (animName, anim) => {
const clip = anim.animations[0];
const action = this._mixer.clipAction(clip);
this._animations[animName] = {
clip: clip,
action: action,
};
};
this._manager = new THREE.LoadingManager();
this._manager.onLoad = () => {
this._stateMachine.SetState('idle');
};
const loader = new FBXLoader(this._manager);
loader.setPath('./resources/guard/');
loader.load('Sword And Shield Idle.fbx', (a) => { _OnLoad('idle', a); });
loader.load('Sword And Shield Run.fbx', (a) => { _OnLoad('run', a); });
loader.load('Sword And Shield Walk.fbx', (a) => { _OnLoad('walk', a); });
loader.load('Sword And Shield Slash.fbx', (a) => { _OnLoad('attack', a); });
loader.load('Sword And Shield Death.fbx', (a) => { _OnLoad('death', a); });
});
}