I was wondering, is it possible to play an animation associated to a mesh, not only to an armature? I have several independent animations on different meshes of the model:
The .ani files are successfully created with AssetImporter.
Train_MiddleWheel.001CDABigWhellIPO.001.ani
Train_MiddleWheel.001CDABigWhellIPO.002.ani
Train_MiddleWheel.001CDABigWhellIPO.ani
Train_MiddleWheel.002CDABigWhellIPO.001.ani
Train_MiddleWheel.002CDABigWhellIPO.002.ani
Train_MiddleWheel.002CDABigWhellIPO.ani
Train_MiddleWheelCDABigWhellIPO.001.ani
Train_MiddleWheelCDABigWhellIPO.002.ani
Train_MiddleWheelCDABigWhellIPO.ani
Train_SmallWheel2.001CDABigWhellIPO.001.ani
Train_SmallWheel2.001CDABigWhellIPO.002.ani
Train_SmallWheel2.001CDABigWhellIPO.ani
Train_SmallWheel2CDABigWhellIPO.001.ani
Train_SmallWheel2CDABigWhellIPO.002.ani
Train_SmallWheel2CDABigWhellIPO.ani
When I try to play them, nothing happens, I must do something wrong. I found the instructions related to this topic in the documentation here:
https://urho3d.github.io/documentation/1.5/_skeletal_animation.html
It says:
"Animations can also be applied outside of an AnimatedModel’s bone hierarchy, to control the transforms of named nodes in the scene. The AssetImporter utility will automatically save node animations in both model or scene modes to the output file directory.
Like with skeletal animations, there are two ways to play back node animations:
Instantiate an AnimationState yourself, using the constructor which takes a root scene node (animated nodes are searched for as children of this node) and an animation pointer. You need to manually advance its time position, and then call Apply() to apply to the scene nodes.
Create an AnimationController component to the root scene node of the animation. This node should not contain an AnimatedModel component. Use the AnimationController to play back the animation just like you would play back a skeletal animation."
However i’m confuse about what is the proper code to do this, here’s what I tried:
AnimatedModel* Object = tileNode->CreateComponent<AnimatedModel>();
RigidBody* Body = tileNode->CreateComponent<RigidBody>();
CollisionShape* Shape = tileNode->CreateComponent<CollisionShape>();
Shape->SetSphere(1.0f);
Body->SetMass(0.1f);
Body->SetGravityOverride(Vector3(0.0, 0.0, 0.0));
Body->SetUseGravity(false);
Body->SetLinearDamping(0.0f);
Body->SetAngularDamping(0.0f);
Body->SetAngularVelocity(Vector3(0.0, 0.0, 0.0));
Body->SetCollisionLayer(1);
Object->SetModel(cache->GetResource<Model>("Models/Train.mdl"));
//wheelObject->SetModel(cache->GetResource<Model>("Models/castleguard.mdl"));
Object->SetCastShadows(true);
Object->SetMaterial(cache->GetResource<Material>("Materials/Stone.xml"));
Animation* trainAnimation = cache->GetResource<Animation>("Models/Train_MiddleWheel.001CDABigWhellIPO.001.ani");
trainAnimation->SetName("Train_MiddleWheel");
AnimationState* state = Object->AddAnimationState(trainAnimation);
if (state)
{
state->SetWeight(1.0f);
state->SetLooped(true);
state->SetTime(Random(trainAnimation->GetLength()));
}
AnimationController* Animated = tileNode->CreateComponent<AnimationController>();
Animated->SetSpeed("Train_MiddleWheel", 1.0);
Animated->Play("Train_MiddleWheel", 0, true, 0.1f);
Here’s the model files created with AssetImporter:
https://ufile.io/62h4o
If you have any idea
thanks