AnimationState return null , not found. problem in exporting animation from blender

151 views
Skip to first unread message

Meir Yanovich

unread,
Jan 13, 2014, 4:29:28 PM1/13/14
to urh...@googlegroups.com
Hey 
i added animation to model i made in blender the animation is rotation of mesh in endless loop .
when i export it from blender to Collada it created me *.ani file when i load it in the code based on the SkeletalAnimation example , with out the mover class 
the AnimationState is returned as not set after im loading it from file . 
is there any thing im doing wrong here ?
by the way the model it self loads just fine , but without the animation . 

Node* spitfireNode = scene_->CreateChild("Spitfire");
spitfireNode
->SetPosition(Vector3(0.0f, 5.0f, 0.0f));
AnimatedModel* spitfireObject = spitfireNode->CreateComponent<AnimatedModel>();
spitfireObject
->SetModel(cache->GetResource<Model>("Models/spidfire4_animation_2.mdl"));
spitfireObject
->SetMaterial(cache->GetResource<Material>("Materials/Body_Material_001-material.xml"));
spitfireObject
->SetMaterial(cache->GetResource<Material>("Materials/plopellor_head_Material-material.xml"));
spitfireObject
->SetMaterial(cache->GetResource<Material>("Materials/plopellor_Material-material.xml"));
     
Animation* plopellorAnimation = cache->GetResource<Animation>("Models/Anim1.ani");
AnimationState* state = spitfireObject->AddAnimationState(plopellorAnimation);   //HERE THE STATE IS NOT SET
   
// The state would fail to create (return null) if the animation was not found
if (state) //NEVER ENTERS HERE
{
       
// Enable full blending weight and looping
        state
->SetWeight(1.0f);
        state
->SetLooped(true);
}

Lasse Öörni

unread,
Jan 13, 2014, 6:26:15 PM1/13/14
to urh...@googlegroups.com
Adding an animation state can fail for the following reasons:

- Model has no bones
- The animation resource pointer you passed is null

Message has been deleted

Meir Yanovich

unread,
Jan 14, 2014, 2:40:25 AM1/14/14
to urh...@googlegroups.com
Hey Lasse
i dont have bones in my scene , its simple mesh that rotate along the Y axis in endless loop 
The Animation resource is not null 
im attaching  can send the Colloda file and the source for testing . in few min's 
Thanks 

Meir Yanovich

unread,
Jan 14, 2014, 2:53:00 AM1/14/14
to urh...@googlegroups.com
Here is the files model and source 
anim.zip

Lasse Öörni

unread,
Jan 14, 2014, 3:28:29 AM1/14/14
to urh...@googlegroups.com
I assume you have a child scene node for the rotating propellor, but without skinning (armature)

Normally only bones that have skinned geometry attached to them will be exported. AnimatedModel is mainly concerned with playing skinned skeletal animations and to make it do anything else requires some hackery, which is explained below.

You can try the -s switch in AssetImporter, which will also import non-skinned child nodes into the skeleton, but it's not going to work automatically, because there is nothing attached to the child node. All geometry is attached to the single AnimatedModel component located in the spitfireNode. In that case you have two options:

1) export the propellor as a separate object and use the -s switch in AssetImporter when importing the main airplane model. Then manually find the child node that rotates in the animation, and attach the propellor object. It can be a StaticModel.
2) set up an armature and simple skinning for the airplane, so that the animation works automatically.

Meir Yanovich

unread,
Jan 14, 2014, 3:37:31 AM1/14/14
to urh...@googlegroups.com
Thanks for the fast replay 
i interested in the quick solution that is number 2 you suggested.
what you saying if i understand you right is , do add bone to the model ?
and animate it to do rotation ?
can yo please explain more about the process i need to do ? 

Lasse Öörni

unread,
Jan 14, 2014, 4:21:47 AM1/14/14
to
I have no actual indepth experience with Blender (beyond making simple objects and pressing export), so for *how* it's done you have to look up some online tutorials, or perhaps someone else can answer. But the end result should be that there's a bone for the propellor, which rotates in the animation, and applies full skinning weight for the propellor vertices.

Meir Yanovich

unread,
Jan 14, 2014, 4:23:45 AM1/14/14
to urh...@googlegroups.com
Hu sorry i didn't meant to you explaining me how to animate in blender , only 
from the engine side of things , is its support in its best only bones animation ?. 
so if i like for example build crane with different animated parts i need to use bones on it ? 
other then that i need to do as you explained in section 1 ?

On Tuesday, January 14, 2014 11:17:31 AM UTC+2, Lasse Öörni wrote:
I have no actual indepth experience with Blender (beyond making simple objects and pressing export), so you have to look up some online tutorials, or perhaps someone else can answer.

Lasse Öörni

unread,
Jan 14, 2014, 4:37:01 AM1/14/14
to urh...@googlegroups.com
The easiest way to setup an object with moving parts is indeed to have it use skinning & bones, as then it can be a single AnimatedModel object. In most cases I recommend that.

If your model has no deformation (for example compare human limbs to an articulated truck; in the latter there's no deformation) the skinning is kind of "wasted" and it might be more optimal performance-wise to just have a node hierarchy and several static models.

If you want to try 1) and have a complex setup of multiple objects, you can also use the "scene" mode in AssetImporter: it will save objects from different scene nodes as separate models, and a scene file which you can load to show them all. It should also save any animations from the scene. But now you can't use AnimatedModel's animation functions any more, instead you can just "new" an AnimationState yourself and give it a root scene node to animate. Look up "node animations" in the documentation.

Meir Yanovich

unread,
Jan 14, 2014, 4:56:41 AM1/14/14
to urh...@googlegroups.com
sorry but where is the "node animation" info in the http://urho3d.github.io/documentation/index.html 
you referring to ?

Lasse Öörni

unread,
Jan 14, 2014, 6:08:05 AM1/14/14
to urh...@googlegroups.com
Skeletal animation subpage (link found from Rendering page)

http://urho3d.github.io/documentation/a00025.html

Meir Yanovich

unread,
Jan 14, 2014, 7:47:08 AM1/14/14
to urh...@googlegroups.com
Hey , its really hard to understand without proper example , i converted the model like this :
AssetImporter.exe scene models\spitfire\anim\Collada\spidfire4_animation_2.dae models\spitfire\anim\output\spidfire4_animation_2.mdl
it created me main mdl file with 3 sub mdl files for each mesh 
when in code i try to load the scene to show me the model i changed the code back to load StaticModel that load the main mdl file .
but now its dosn't show me the model at all 
this is the code now , what im doing wrong here ?
StaticModel* ModelObject = CarNode->CreateComponent<StaticModel>();
   
ModelObject->SetModel(cache->GetResource<Model>("Models/spidfire4_animation_2.mdl"));
   
ModelObject->SetMaterial(cache->GetResource<Material>("Materials/Body_Material_001-material.xml"));
   
ModelObject->SetMaterial(cache->GetResource<Material>("Materials/plopellor_head_Material-material.xml"));
   
ModelObject->SetMaterial(cache->GetResource<Material>("Materials/plopellor_Material-material.xml"));
   
   
ModelObject->SetCastShadows(true);  
   
Animation* plopelorAnimation = cache->GetResource<Animation>("Models/Anim1.ani");

this is the files i have :
Anim1.ani  
spidfire4_animation_2.mdl
Materials  
Models  
Textures  


./Materials:
Body_Material_001-material.xml  plopellor_Material-material.xml  plopellor_head_Material-material.xml

./Models:
BezierCircle_plopelor.mdl  Body.mdl  Cone_plopelor_head.mdl

./Textures:
UVPlopelor.png  body_texture.png  plopellor_head.png

Lasse Öörni

unread,
Jan 14, 2014, 7:57:21 AM1/14/14
to urh...@googlegroups.com
In scene mode the output file name is not the model name, but the scene .xml name. The AssetImporter decides the filenames for the models itself.

Always check the log. You should be given a clear error if you try to load a scene xml as a model.

Meir Yanovich

unread,
Jan 14, 2014, 8:12:14 AM1/14/14
to urh...@googlegroups.com
Any reason it doesn't write output logs ? 
where can i enable it ? 
im using StaticScene project as  base for my testing .
i do see logs from running other examples 

Lasse Öörni

unread,
Jan 14, 2014, 9:14:21 AM1/14/14
to urh...@googlegroups.com
The samples should write the output log next to the executable. Eg. the 04_StaticScene.exe produces the log file StaticScene.log. By default logging is enabled; you should check that each project has the preprocessor define ENABLE_LOGGING. If for some reason you have disabled logging from CMake you can rerun CMake with the option -DENABLE_LOGGING=1

Meir Yanovich

unread,
Jan 14, 2014, 9:25:03 AM1/14/14
to urh...@googlegroups.com
Thanks 
i found the log entry that say :
[Tue Jan 14 16:16:54 2014] DEBUG: Loading resource Models/spidfire4_animation_2.mdl
[Tue Jan 14 16:16:54 2014] ERROR: Models/spidfire4_animation_2.mdl is not a valid model file
no more info why its not valid 
1. can i make the log more verbose ? for cases like this ? 
2. what is the current way to use the AssetImporter.exe for exporting scene?  what i do is this:

D:\dev\cpp\3d\Urho3D\Bin>AssetImporter.exe scene models\spitfire\anim\Collada\spidfire4_animation_2.dae models\spitfire\anim\output\spidfire4_animation_2.mdl
Reading file models\spitfire\anim\Collada\spidfire4_animation_2.dae
Added model models/spitfire/anim/output/Models/Body.mdl
Added node Body
Added model models/spitfire/anim/output/Models/Cone_plopelor_head.mdl
Added node Cone_plopelor_head
Added model models/spitfire/anim/output/Models/BezierCircle_plopelor.mdl
Added node BezierCircle_plopelor
Writing model Body
Writing geometry 0 with 1154 vertices 1392 indices
Writing model Cone_plopelor_head
Writing geometry 0 with 121 vertices 204 indices
Writing model BezierCircle_plopelor
Writing geometry 0 with 2280 vertices 2280 indices
Writing animation Anim1 length 0.416667
Writing scene
Writing material Body_Material_001-material
Writing material plopellor_Material-material
Writing material plopellor_head_Material-material
Copying texture body_texture.png
Copying texture UVPlopelor.png
Copying texture plopellor_head.png


Lasse Öörni

unread,
Jan 14, 2014, 9:52:57 AM1/14/14
to urh...@googlegroups.com
No, for errors there's no more verbose output than that. If you open the failing "mdl" file in a text editor I'm 99% sure that it's the xml scene file, and that's why it fails.

The correct form to import a scene with its models saved as separate models:

assetimporter scene yourdaefile.dae yourscenefile.xml

Meir Yanovich

unread,
Jan 14, 2014, 12:06:48 PM1/14/14
to urh...@googlegroups.com
Lasse i aprisiate your help , but im doing here something very wrong and i have no idea what 
in the log i still getting error saying :
[Tue Jan 14 18:59:51 2014] ERROR: Models/spidfire4_animation_2.xml is not a valid model file
what hints should i look for why its error?
attaching the spidfire4_animation_2.xml


can you please tell me how my code should look like if i like to see the model if i exported it with AssetImporter.exe 
its looks like this :
D:\dev\cpp\3d\Urho3d_forwindows\Bin>AssetImporter.exe scene models\spidfire\anim_scene\spidfire4_animation_2.dae models\spidfire\anim_scene\spidfire4_animation_2.xml
Reading file models\spidfire\anim_scene\spidfire4_animation_2.dae
Added model models/spidfire/anim_scene/Models/Body.mdl
Added node Body
Added model models/spidfire/anim_scene/Models/Cone_plopelor_head.mdl
Added node Cone_plopelor_head
Added model models/spidfire/anim_scene/Models/BezierCircle_plopelor.mdl
Added node BezierCircle_plopelor
Writing model Body
Writing geometry 0 with 1154 vertices 1392 indices
Writing model Cone_plopelor_head
Writing geometry 0 with 122 vertices 204 indices
Writing model BezierCircle_plopelor
Writing geometry 0 with 2280 vertices 2280 indices
Writing animation Anim1 length 0.416667
Writing scene
Writing material Body_Material_001-material
Writing material plopellor_Material-material
Writing material plopellor_head_Material-material
Copying texture body_texture.png
Copying texture UVPlopelor.png
Copying texture plopellor_head.png

mybe the code is wrong ?
here it is :
Node* spitfireNode = scene_->CreateChild("Spitfire");
    spitfireNode
->SetPosition(Vector3(0.0f, 5.0f, 0.0f));

   
   
StaticModel* spitfireObject = spitfireNode->CreateComponent<StaticModel>();
    spitfireObject
->SetModel(cache->GetResource<Model>("Models/spidfire4_animation_2.xml"));
    spitfireObject
->SetMaterial(cache->GetResource<Material>("Materials/Body_Material_001-material.xml"));
 spitfireObject
->SetMaterial(cache->GetResource<Material>("Materials/plopellor_head_Material-material.xml"));
 spitfireObject
->SetMaterial(cache->GetResource<Material>("Materials/plopellor_Material-material.xml"));
     
   
Animation* plopellorAnimation = cache->GetResource<Animation>("Models/Anim1.ani");

spidfire4_animation_2.xml

Chris Friesen

unread,
Jan 14, 2014, 1:00:52 PM1/14/14
to urh...@googlegroups.com
 spitfireObject->SetModel(cache->GetResource<Model>("Models/spidfire4_animation_2.xml"));

models are usually the mdl files

Lasse Öörni

unread,
Jan 14, 2014, 1:21:59 PM1/14/14
to urh...@googlegroups.com
Yes, the idea is that you load the scene which AssetImporter produced (using scene->LoadXML()) which will contain the models.

For just trying out you can load it into the editor instead of using code.

Loading a scene will always empty it from existing content, which is inconvenient if you have other objects already there, or if you want to instantiate several of the objects. So the next more advanced step is to save an object "prefab" in the editor. Select their root node and choose File -> Save Node. This will also produce an XML file, but a different one, where the root element is not "scene" but "node", similar to the object prefabs the NinjaSnowWar example uses (Bin/Data/Objects)

This node XML can be instantiated into the scene by calling scene->InstantiateXML() without erasing existing content.

In fact a prefab mode could be added to AssetImporter, which would produce this kinds of files directly without having to go through the editor.

But as you see, it's much easier to just make the model skeletal :)

Meir Yanovich

unread,
Jan 14, 2014, 2:35:37 PM1/14/14
to urh...@googlegroups.com
Hmm , well this process i would never guessed , 
1. this stuff must be documented .
2. advanced examples like this must be made 
3. this process must be simplified , how does other 3d engines doing it ? are they all base on skeletal setup ? 

Meir Yanovich

unread,
Jan 14, 2014, 2:57:59 PM1/14/14
to urh...@googlegroups.com
ok after trying to do what you suggested i noticed that in the editor 
the nodes of the model are not ordered in Hierarchy as in blender 
the nodes are in same level under the Scene node . do i need to order them in the editor ?
do i need to set something in the AssetImporter ? or blender ?

Lasse Öörni

unread,
Jan 14, 2014, 2:58:02 PM1/14/14
to urh...@googlegroups.com
There is no "must", really. Of course it's in everyone's best interests to improve the engine and documentation, and there are already steps taken toward it, but at the same time this project owes you nothing and you should realize that.

Meir Yanovich

unread,
Jan 14, 2014, 3:08:49 PM1/14/14
to urh...@googlegroups.com
Sorry Lasse, its all understood its just was way of expression .
of course  i know its hard work to maintain and support such project . dont get me wrong 
i trying to learn it in every free second i have and got frustrated when i can't figure stuff . in the little time i have .
please continue the good work! 
(:
Reply all
Reply to author
Forward
0 new messages