Exporting animations with Blender


#1

Hello,

It has been a few days that I’ve been trying to export a model and a simple animation I made with Blender (2.79b) using Reattiva’s Urho3D-Blender exporter (https://github.com/reattiva/Urho3D-Blender).

The model exports properly, but there’s no way I can make the animation work.

Here’s what I’ve done:

  1. Created a Sphere, scaled it, moved it above ground.

  2. Created a “Bounce” action on the Dope Sheet.

  3. Selected “F” to save that data-block even if it had no users.

  4. Moved to frame 1, and inserted a keyframe with Location and Rotation.

  5. Moved to frame 11, moved the sphere up and inserted another keyframe with Location and Rotation.

  6. Moved to frame 21, moved the sphere down and inserted another keyframe with Location and Rotation.

  7. Edited the end frame to be frame 21.

  8. On the Urho3D-Blender exporter, I made these selections:

No errors occured and the files were generated properly:

  1. The Sphere.mdl model: https://github.com/turbo-9/etc/blob/master/Sphere.mdl
  2. The Bounce.ani animation: https://github.com/turbo-9/etc/blob/master/Bounce.ani

Here is the Sphere.blend file: https://github.com/turbo-9/etc/blob/master/Sphere.blend

And I’m testing it with this simple test.cpp file:

#include <Urho3D/Core/Object.h>
#include <Urho3D/Core/Context.h>
#include <Urho3D/Core/CoreEvents.h>
#include <Urho3D/Core/ProcessUtils.h>
#include <Urho3D/Engine/Application.h>
#include <Urho3D/Engine/Engine.h>
#include <Urho3D/Input/Input.h>
#include <Urho3D/Resource/ResourceCache.h>
#include <Urho3D/Input/Controls.h>
#include <Urho3D/Scene/Scene.h>
#include <Urho3D/Graphics/Graphics.h>
#include <Urho3D/Graphics/Camera.h>
#include <Urho3D/Graphics/Light.h>
#include <Urho3D/Graphics/Geometry.h>
#include <Urho3D/Graphics/Renderer.h>
#include <Urho3D/Graphics/DebugRenderer.h>
#include <Urho3D/Graphics/Octree.h>
#include <Urho3D/Graphics/Model.h>
#include <Urho3D/Graphics/StaticModel.h>
#include <Urho3D/Graphics/Material.h>

#include <Urho3D/Graphics/AnimatedModel.h>
#include <Urho3D/Graphics/AnimationController.h>

using namespace Urho3D;

class Game : public Application {

	public:

		Game(Context *context) : Application(context) {

		}

		void Setup() {

			engineParameters_["FullScreen"]=false;
			engineParameters_["WindowWidth"]=640;
			engineParameters_["WindowHeight"]=480;

		}

		void Start() {

			ResourceCache *cache_ = GetSubsystem<ResourceCache>();
			Scene *scene_ = new Scene(context_);
			scene_->CreateComponent<Octree>();

			GetSubsystem<Input>()->SetMouseVisible(true);

			// Create a camera:
			Node *cameraNode_ = scene_->CreateChild("Camera");
			cameraNode_->CreateComponent<Camera>();
			cameraNode_->SetPosition(Vector3(0.0f, 0.0f, 0.0f));
			Renderer* renderer = GetSubsystem<Renderer>();
			SharedPtr<Viewport> viewport(new Viewport(context_, scene_, cameraNode_->GetComponent<Camera>()));
			renderer->SetViewport(0, viewport);

			// Create the animated sphere:
			Node *sphereNode_ = scene_->CreateChild("Sphere");
			sphereNode_->SetPosition(Vector3(0.0f, -0.5f, 5.0f));
			AnimatedModel *sphereAnimatedModel_ = sphereNode_->CreateComponent<AnimatedModel>();
			sphereAnimatedModel_->SetModel(cache_->GetResource<Model>("Models/Sphere.mdl"));
			sphereAnimatedModel_->SetMaterial(cache_->GetResource<Material>("Materials/Stone.xml"));

			AnimationController *sphereAnimationController_ = sphereNode_->CreateComponent<AnimationController>();
			sphereAnimationController_->PlayExclusive("Models/Bounce.ani", 0, true, 0.0f);

			// Replacing the sphereAnimatedModel_ with "Models/Jack.mdl"
			// and the sphereAnimationController_ with "Models/Jack_Walk.ani"
			// works properly.

	}

}; URHO3D_DEFINE_APPLICATION_MAIN(Game);

And, although the model is loaded properly, the animations don’t work at all:

result

Does anyone have any idea what I did wrong? I believe I’m probably missing some important step on the pipeline.

Best regards.


[Solved] Models & Skyboxes
#2

Try replacing the AnimatedModel with a StaticModel.

In the documentation under Node animation it reads:

Create an AnimationController component to the root scene node of the animation. This node should not contain an AnimatedModel component.


#3

@Modanung, thank you for the reply.

I tried replacing the AnimatedModel with a StaticModel like you said, but unfortunately it didn’t work (it also stopped showing the model).

Although the documentation says the AnimationController should not contain an AnimatedModel, isn’t that what the sample 44_RibbonTrailDemo does?

// Load ninja animated model for bone trail demo.
Node* ninjaNode = scene_->CreateChild("Ninja");
ninjaNode->SetPosition(Vector3(5.0f, 0.0f, 0.0f));
ninjaNode->SetRotation(Quaternion(0.0f, 180.0f, 0.0f));
AnimatedModel* ninja = ninjaNode->CreateComponent<AnimatedModel>();
ninja->SetModel(cache->GetResource<Model>("Models/NinjaSnowWar/Ninja.mdl"));
ninja->SetMaterial(cache->GetResource<Material>("Materials/NinjaSnowWar/Ninja.xml"));
ninja->SetCastShadows(true);

// Create animation controller and play attack animation.
ninjaAnimCtrl_ = ninjaNode->CreateComponent<AnimationController>();
ninjaAnimCtrl_->PlayExclusive("Models/NinjaSnowWar/Ninja_Attack3.ani", 0, true, 0.0f);

#4

The animation format is fairly general, an animation can control bones but it can also control nodes, even in addition to bones.

However, all indications are that for the Reattiva exporter node animation doesn’t work yet.

I’ll check your files in a sec. though to see if they even make sense.


#5

Your animation looks legit, it’s targeting a Node|Bone named Sphere.

Note: your animation’s range maxed out at just above 1.5 iirc, depending on your scene setup that could be so small that you can’t see it working, so I’d be double-checking what scaling you have going on.

To tie back to what @Modanung said:

Your scene should (based on your file) look like this: (nodes in bold, components in italic)

  • arbitrary_node
    • AnimationController
      • your Bounce animation attached here
    • Sphere (your target node)
      • StaticModel
        • sphere model attached and appropriated scaled

Because your animation’s range is so small make sure it’s looping so you can at least detect flicker if it’s far too tiny a motion.

Report back if that fixes or doesn’t, this is a fun one.


#6

@Sinoid, thank you very much for the explanation, I really wasn’t understanding that.

The scheme you listed worked perfectly!

bounce

Here’s the test.cpp file:

#include <Urho3D/Core/Object.h>
#include <Urho3D/Core/Context.h>
#include <Urho3D/Core/CoreEvents.h>
#include <Urho3D/Core/ProcessUtils.h>
#include <Urho3D/Engine/Application.h>
#include <Urho3D/Engine/Engine.h>
#include <Urho3D/Input/Input.h>
#include <Urho3D/Resource/ResourceCache.h>
#include <Urho3D/Input/Controls.h>
#include <Urho3D/Scene/Scene.h>
#include <Urho3D/Graphics/Graphics.h>
#include <Urho3D/Graphics/Camera.h>
#include <Urho3D/Graphics/Light.h>
#include <Urho3D/Graphics/Geometry.h>
#include <Urho3D/Graphics/Renderer.h>
#include <Urho3D/Graphics/DebugRenderer.h>
#include <Urho3D/Graphics/Octree.h>
#include <Urho3D/Graphics/Model.h>
#include <Urho3D/Graphics/StaticModel.h>
#include <Urho3D/Graphics/Material.h>

#include <Urho3D/Graphics/AnimatedModel.h>
#include <Urho3D/Graphics/AnimationController.h>

using namespace Urho3D;

class Game : public Application {

	public:

		Game(Context *context) : Application(context) {

		}

		void Setup() {

			engineParameters_["FullScreen"]=false;
			engineParameters_["WindowWidth"]=640;
			engineParameters_["WindowHeight"]=480;

		}

		void Start() {

			ResourceCache *cache_ = GetSubsystem<ResourceCache>();
			Scene *scene_ = new Scene(context_);
			scene_->CreateComponent<Octree>();

			GetSubsystem<Input>()->SetMouseVisible(true);

			// Create a camera:
			Node *cameraNode_ = scene_->CreateChild("Camera");
			cameraNode_->CreateComponent<Camera>();
			cameraNode_->SetPosition(Vector3(0.0f, 0.0f, 0.0f));
			Renderer* renderer = GetSubsystem<Renderer>();
			SharedPtr<Viewport> viewport(new Viewport(context_, scene_, cameraNode_->GetComponent<Camera>()));
			renderer->SetViewport(0, viewport);

			// Create the animated sphere:
			Node *mainNode_ = scene_->CreateChild("mainNode");
				AnimationController *animationControllerComponent_ = mainNode_->CreateComponent<AnimationController>();
					animationControllerComponent_->PlayExclusive("Models/Bounce.ani", 0, true, 0.0f);
				Node *sphereNode_ = mainNode_->CreateChild("sphereNode");
					sphereNode_->SetPosition(Vector3(0.0f, -2.5f, 5.0f));
					StaticModel *staticModelComponent_ = sphereNode_->CreateComponent<StaticModel>();
						staticModelComponent_->SetModel(cache_->GetResource<Model>("Models/Sphere.mdl"));
						staticModelComponent_->SetMaterial(cache_->GetResource<Material>("Materials/Stone.xml"));

	}

}; URHO3D_DEFINE_APPLICATION_MAIN(Game);

@Modanung @Sinoid, you guys are awesome! Thank you so much for the help!

Edit: Also, as @Sinoid said, it’s very important to not forget the scale (which I did before):

scale


#7

Thank you for a fun issue to look at and providing the necessary files for it be figured out.


#8

Sorry to bother again, but I’m having some problems exporting an animation that used bone rigging.

  1. I made 2 spheres (Head and Body) one above the other:
    image1

  2. Then I added one armature bone (BodyBone) and extruded another bone (HeadBone):
    image2

  3. I parented the BodyBone to the Body sphere and the HeadBone to the Head sphere:
    image3

  4. This is the Outliner tree structure:
    image4

  5. After that, I opened the Dope Sheet, selected the Action Editor, created a new action named “Swing” and marked the “F” to save that data-block even if it had no users.

  6. Went to frame 1 and added a keyframe for Location, Rotation and Scale of the bones:
    image5

  7. Went to frame 21, moved the Head and Body using the bones on the Pose Mode, and added a keyframe for Location, Rotation and Scale of the bones:
    image6

  • This is the Dope Sheet structure:
    image7
  1. Edited the end frame to be frame 21, tested the animation, and it was working properly:
    image8

  2. Then tried to export with the Urho3D-blender exporter using these options:

  1. Then I tried to export with these options:
  1. Then I tried to load them, but, unfortunately, didn’t work:
    image13
  1. Here’s the small test.cpp file I’m using:
#include <Urho3D/Core/Object.h>
#include <Urho3D/Core/Context.h>
#include <Urho3D/Core/CoreEvents.h>
#include <Urho3D/Core/ProcessUtils.h>
#include <Urho3D/Engine/Application.h>
#include <Urho3D/Engine/Engine.h>
#include <Urho3D/Input/Input.h>
#include <Urho3D/Resource/ResourceCache.h>
#include <Urho3D/Input/Controls.h>
#include <Urho3D/Scene/Scene.h>
#include <Urho3D/Graphics/Graphics.h>
#include <Urho3D/Graphics/Camera.h>
#include <Urho3D/Graphics/Light.h>
#include <Urho3D/Graphics/Geometry.h>
#include <Urho3D/Graphics/Renderer.h>
#include <Urho3D/Graphics/DebugRenderer.h>
#include <Urho3D/Graphics/Octree.h>
#include <Urho3D/Graphics/Model.h>
#include <Urho3D/Graphics/StaticModel.h>
#include <Urho3D/Graphics/Material.h>

#include <Urho3D/Graphics/AnimatedModel.h>
#include <Urho3D/Graphics/AnimationController.h>

using namespace Urho3D;

class Game : public Application {

	public:

		Game(Context *context) : Application(context) {

		}

		void Setup() {

			engineParameters_["FullScreen"]=false;
			engineParameters_["WindowWidth"]=640;
			engineParameters_["WindowHeight"]=480;

		}

		void Start() {

			ResourceCache *cache_ = GetSubsystem<ResourceCache>();
			Scene *scene_ = new Scene(context_);
			scene_->CreateComponent<Octree>();

			GetSubsystem<Input>()->SetMouseVisible(true);

			// Create a camera:
			Node *cameraNode_ = scene_->CreateChild("Camera");
			cameraNode_->CreateComponent<Camera>();
			cameraNode_->SetPosition(Vector3(0.0f, 0.0f, 0.0f));
			Renderer *renderer = GetSubsystem<Renderer>();
			SharedPtr<Viewport> viewport(new Viewport(context_, scene_, cameraNode_->GetComponent<Camera>()));
			renderer->SetViewport(0, viewport);

			// Create the animated sphere:

			// This didn't work. Only the model was loaded, but not the animation.
			Node *mainNode_ = scene_->CreateChild("mainNode");
				AnimationController *animationControllerComponent_ = mainNode_->CreateComponent<AnimationController>();
					animationControllerComponent_->PlayExclusive("Models/Swing.ani", 0, true, 0.0f);
				Node *sphereNode_ = mainNode_->CreateChild("sphereNode");
					sphereNode_->SetPosition(Vector3(-1.0f, -1.0f, 5.0f));
					StaticModel *staticModelComponent_ = sphereNode_->CreateComponent<StaticModel>();
						staticModelComponent_->SetModel(cache_->GetResource<Model>("Models/Body.mdl"));
						staticModelComponent_->SetMaterial(cache_->GetResource<Material>("Materials/Stone.xml"));

			// This also didn't work. Neither the model, nor the animation was loaded.
			Node *sphere2Node_ = scene_->CreateChild("Sphere2");
			sphere2Node_->SetPosition(Vector3(1.0f, -0.5f, 5.0f));
			AnimatedModel *sphere2AnimatedModel_ = sphere2Node_->CreateComponent<AnimatedModel>();
			sphere2AnimatedModel_->SetModel(cache_->GetResource<Model>("Models/Body.mdl"));
			sphere2AnimatedModel_->SetMaterial(cache_->GetResource<Material>("Materials/Stone.xml"));
			AnimationController *sphere2AnimationController_ = sphere2Node_->CreateComponent<AnimationController>();
			sphere2AnimationController_->PlayExclusive("Models/Swing.ani", 0, true, 0.0f);

	}

}; URHO3D_DEFINE_APPLICATION_MAIN(Game);

Sorry for the amount of images and the very long post, but I thought it was the most clear way to describe precisely what I was doing.

Now I’m kind of lost. I’m not really sure which is the correct method to export that bone rigged animation. Or what I’m missing here.

Does anyone have any idea?


#9

In this case it is the bones that are animated, not the objects themselves. Therefor you’ll want to export using the Skeletons + Animations options instead of of objects as you did before.

You can apply an object’s scale (required for both the head and body) in Blender with Ctrl+A then S in Object mode.


#10

@Modanung, did as you said and the model and animation are exporting without errors now. Thank you very much!

Edit: But I can’t load them properly on the test. I’m probably loading them the wrong way.

Edit2: Are weights required for a bone rigged animation?


#11

I do believe they are, it is what determines the bones’ influence. When parenting (Ctrl+P) an object to an armature Blender can help you with that.


#12

@Modanung, thank you so much! I was parenting it to the Bone. Tried parenting it to Armature Deform > With Automatic Weights as you said and it worked! I was able to import it on the editor and test the animation! Thank you very much for the help!

Edit: Also, to anyone also doing this, don’t forget to select the Weights option under the Geometries section of the Urho3D-Blender exporter.

Edit2: Just to complement the solution, here’s the test.cpp file with the loading code for the bone rigged animation:

#include <Urho3D/Core/Object.h>
#include <Urho3D/Core/Context.h>
#include <Urho3D/Core/CoreEvents.h>
#include <Urho3D/Core/ProcessUtils.h>
#include <Urho3D/Engine/Application.h>
#include <Urho3D/Engine/Engine.h>
#include <Urho3D/Input/Input.h>
#include <Urho3D/Resource/ResourceCache.h>
#include <Urho3D/Input/Controls.h>
#include <Urho3D/Scene/Scene.h>
#include <Urho3D/Graphics/Graphics.h>
#include <Urho3D/Graphics/Camera.h>
#include <Urho3D/Graphics/Light.h>
#include <Urho3D/Graphics/Geometry.h>
#include <Urho3D/Graphics/Renderer.h>
#include <Urho3D/Graphics/DebugRenderer.h>
#include <Urho3D/Graphics/Octree.h>
#include <Urho3D/Graphics/Model.h>
#include <Urho3D/Graphics/StaticModel.h>
#include <Urho3D/Graphics/Material.h>

#include <Urho3D/Graphics/AnimatedModel.h>
#include <Urho3D/Graphics/AnimationController.h>

using namespace Urho3D;

class Game : public Application {

	public:

		Game(Context *context) : Application(context) {

		}

		void Setup() {

			engineParameters_["FullScreen"]=false;
			engineParameters_["WindowWidth"]=640;
			engineParameters_["WindowHeight"]=480;

		}

		void Start() {

			ResourceCache *cache_ = GetSubsystem<ResourceCache>();
			Scene *scene_ = new Scene(context_);
			scene_->CreateComponent<Octree>();

			GetSubsystem<Input>()->SetMouseVisible(true);

			// Create a camera:
			Node *cameraNode_ = scene_->CreateChild("Camera");
			cameraNode_->CreateComponent<Camera>();
			cameraNode_->SetPosition(Vector3(0.0f, 0.0f, 0.0f));
			Renderer *renderer = GetSubsystem<Renderer>();
			SharedPtr<Viewport> viewport(new Viewport(context_, scene_, cameraNode_->GetComponent<Camera>()));
			renderer->SetViewport(0, viewport);

			// Create the bone rigged animated sphere:
			Node *mainNode = scene_->CreateChild("mainNode");
				mainNode->SetPosition(Vector3(0.0f, -1.0f, 5.0f));

				AnimatedModel *animatedModelComponent = mainNode->CreateComponent<AnimatedModel>();
					animatedModelComponent->SetModel(cache_->GetResource<Model>("Models/Model.mdl"));
					animatedModelComponent->SetMaterial(cache_->GetResource<Material>("Materials/Stone.xml"));

				AnimationController *animationControllerComponent = mainNode->CreateComponent<AnimationController>();
					animationControllerComponent->PlayExclusive("Models/Swing.ani", 0, true, 0.0f);

	}

}; URHO3D_DEFINE_APPLICATION_MAIN(Game);

The Model.mdl file: https://github.com/turbo-9/etc/blob/master/test3/Model.mdl
The Swing.ani file: https://github.com/turbo-9/etc/blob/master/test3/Swing.ani

The Model.blend file: https://github.com/turbo-9/etc/blob/master/test3/Model.blend

Thanks again to @Modanung and @Sinoid for all the help and patience! You guys are the best!


#13

@turbo9 You’re welcome. :slight_smile:


#14

I’m also having my first attempt at making a skeletal animation in Blender and exporting it to Urho. After hours of online tutorials and work I managed to do this low-poly Ant-creature walk cycle in Blender:
Ant-walk-Blender

The problem is that when I export it to Blender (using either the Blender add-on or AssetImporter via FBX format), the result is a weird/funny looking animation:
Ant-walk-Urho

In case it’s not very clear (from the video), the legs are swinging sideways instead of back-n-forth and also look broken/twisted at the knees.

Any ideas as to what might be causing this issue? I’m a total beginner at skeletal animation both in Blender and Urho so after trying for hours to figure it out, by fiddling with all sort of setting I’m not making any progress. Any help is greatly appreciated.


#15

If anyone wants to look at the Blender file:
http://www.qbkgames.com/MiscData/Ant.blend

I used Sample 06 - Skeletal Animation, to preview the exported model and animation by replacing the default Kachujin model/anim. The ants look white because they have to custom material assigned, but I’m not worried about that now, I just want to get the animation working.


#16

@QBkGames, try this:
Go to Object Mode > A to select everything > Ctrl+A > L for Location
Then Ctrl+A again > R for Rotation
And then Ctrl+A again > S for Scale


#17

Since the scale is already uniform of both the model and the rig it should be enough to apply the rotation of the armature by selecting it and (in Object Mode) do the Ctrl+A > R thingy.
This seems to leave the animation undamaged.

Interesting hind legs, btw. :wink:


#18

Thanks a lot guys for your assistance.
I knew that scaling had to be applied otherwise it might cause problems, but I would have never thought of rotation. But that makes sense, the reason the legs were moving across was because of the unapplied 90 degree rotation of the armature.


#19

The ant is supposed to be some alien creature (ant like) so it’s evolution does not fit the earth like locomotion biology :slight_smile: