I'm working on developing a game that features an animated character with various animations sourced from Mixamo. The goal is to have the character's animation change dynamically based on user interactions within the game, such as Walking
, Running
, or Idle
. Here's how I am currently loading the FBX
model (without animations):
loader.load('Assets/Animations/Main.fbx', function(object){
object.traverse(function (child){
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
child.frustumCulled = false;
}
});
object.rotation.x = Math.PI / 2
object.position.x = 11;
scene.add(object);
});
Additionally, I have separate files for animations that do not include skin:
Idle.fbx
Walking.fbx
Running.fbx
The end goal is to achieve something similar to the examples shown here or here. However, both of these references present challenges; one relies on a model with multiple animations attached (while my model has three animations without skin), and the other is written in TypeScript instead of JavaScript.
Being relatively new to 3D modeling, I'm unsure about how to attach all the skinless animations to the main fbx model. Is there a way to combine these animations into a single model using Blender, or can this be achieved directly in three.js?
I would greatly appreciate any guidance or assistance with this. Thank you!
EDIT:
In response to @GuyNachshon's suggestions, should I approach it like this?
First, load the model without animations (yourMesh
) and establish an AnimationMixer
:
var mixer;
loader.load('Assets/Animations/Main.fbx', function(object){
object.traverse(function (child){
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
child.frustumCulled = false;
}
});
mixer = new THREE.AnimationMixer(object);
object.rotation.x = Math.PI / 2
object.position.x = 11;
scene.add(object);
});
Next, load the three animation files without skin and add them to an animationsArray
. (Not entirely certain if this is the correct method of loading animations...):
loader.load('Assets/Animations/Idle.fbx', function(object){
object.traverse(function (child){
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
child.frustumCulled = false;
}
});
object.rotation.x = Math.PI / 2
object.position.x = 11;
animationsArray.push(object);
scene.add(object);
});
loader.load('Assets/Animations/Walking.fbx', function(object){
object.traverse(function (child){
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
child.frustumCulled = false;
}
});
object.rotation.x = Math.PI / 2
object.position.x = 11;
animationsArray.push(object);
scene.add(object);
});
loader.load('Assets/Animations/Running.fbx', function(object){
object.traverse(function (child){
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
child.frustumCulled = false;
}
});
object.rotation.x = Math.PI / 2
object.position.x = 11;
animationsArray.push(object);
scene.add(object);
});
Once all assets are loaded, initiate the actions
:
let actions = mixer.clipAction(animationsArray).play();
And then follow up with:
actions.play();
Will this line trigger the playback of the first animation within animationsArray
?