How to use animated models?
I just put an armature in the arena model from CSSample and make a animation on Blender then exported and converted to csmodel and csanim but I can't figure out how this is setup.
I have tried it but doesn't work:
auto renderFactory = Application::Get()->GetSystem<RenderComponentFactory>();
auto resourcePool = Application::Get()->GetResourcePool();
auto materialFactory = Application::Get()->GetSystem<MaterialFactory>();
MeshCSPtr mesh = resourcePool->LoadResource<Mesh>(StorageLocation::k_package, "Models/ArenaTest.csmodel");
TextureCSPtr texture = resourcePool->LoadResource<Texture>(StorageLocation::k_package, "Textures/Models.csimage");
SkinnedAnimationCSPtr animation = resourcePool->LoadResource<SkinnedAnimation>(StorageLocation::k_package, "Models/ArenaTest.csanim");
auto material = materialFactory->CreateAnimated("Unlit", texture);
AnimatedMeshComponentSPtr meshComponent = renderFactory->CreateAnimatedMeshComponent(mesh, material);
It looks like what you are doing is correct. What is the actual error you are encountering? Are there any related errors in the console output?
Can you confirm that you are using the
--animated option when exporting the animated model? The following will be needed to export a csmodel from a Collada file made in Blender:
java -jar ChilliSource/Tools/ColladaToCSModel.jar --input Model.DAE --output Model.csmodel --animated --swapyandz
and this for the csanim:
java -jar ChilliSource/Tools/ColladaToCSAnim.jar --input Model.DAE --output Model.csanim --swapyandz
It is also worth running each with the
--logginglevel verbose option and checking the skeleton and animation data make sense. It might help to send me the output of the tools.
If the animation isn't loading, can you confirm you have added the CSAnimProvider in App::CreateSystems():
If the model is rendering correctly, but isn't animating, can you try looping the animation:
If the model is animating, but deforming strangely, something maybe have gone wrong with the animation data. This could be that the skeleton for the model and the animation are different, or different transformations were applied when converted (i.e the --swapyandz and --swaphandedness options)
If none of this is helping, it may be that something in the Collada file is not be supported. Only a sub-set of the Collada format is supported by the conversion tools, which means working with animations can initially be a bit fiddly.
The rules for Collada files which contain animation are:
- Only skinned animation is supported
- Meshes need to be exported triangulated
- Animation data must be in matrix form
- The file can only contain 1 skeleton. The skeleton must include the scene root node. All meshes in the model must be skinned to all nodes in that skeleton
- Each vertex can have, at most, 4 weights
- All nodes in the hierarchy that have children must be joints (i.e part of the skeleton). "Leaf" nodes don't have to be though, allowing attachment points.
- If exporting from 3DS Max or Maya, the OpenCollada exporter should be used for animated models instead of the built-in exporter.
(Note: This is off the top of my head, so I may not have that 100% correct. A couple of the restrictions may have been relaxed.)
I've never used blender armatures before - I take it they just export to a standard joint hierarchy in the collada file?
If none of the above has worked, it may help to send the .DAE. Hopefully I'll be able to see what's going wrong.
I'm using the same options as described and created CSModelProvider and CSAnimProvider on App::CreateSystems.
This is the model: https://dl.dropboxusercontent.com/u/60691076/misc/ArenaTest.dae
Is the arena with 3 bones and a simple animation.
- I get an acess violation at RenderSystem::RenderBuffer when it try to read the vertex and index data.
- Converting without --animated and loading as static mesh works fine.
- Maybe is supposed to work like this but converting with --animated and try to use as static mesh throw the same error.
I've tried rendering the animation and it seems to work. I copy and pasted your code above and used the conversion tools as described in my last post. I did notice that the model tool returns a lot of warnings when running the tool however it was nothing that should cause crashes (just that the vertex weights don't add up to 1.0).
Is there any more detail you could give about how you are using it?
I find the problem.
Models converted with CSModelExporter.exe was causing the error.
The warning has because it had a root bone without weight.
Now is drawing and playing but the animation is wrong.
Only one corner are moving. The two top corner should be moving.
Bone.001 are all the vertex in the top left corner, Bone.002 all the vertex in the top right and Bone all the vertex of the bottom.
The model in many formats: https://dl.dropboxusercontent.com/u/60691076/misc/Model.zip
I've looked into this a bit more and I can't see what's going wrong. It definitely looks like it's an engine issue - most likely something to do with the conversion from Collada files created in Blender. I'll need to look into it in more depth, so I've added it as a high priority issue in our bug tracker.
The latest version of the engine, v1.4.2, contains a fix which should solve the issues you were encountering here
Let me know if you're still having issues!
Now all the vertex groups are moving as it should.
There is a bit of easing in the start and end of each keyframe but on CS the movement isn't interpolated.
Edit: Oh right, it just that the Collada exporter only export linear interpolation which is a big problem.
I wonder why there is never full support for collada in the default exporter of popular 3D editors...
Yeah, Collada support is a bit of a pain. We're currently looking into using something else - possibly FBX, depending on how investigation into the FBX SDK does. I've got a feeling it'll be a while before we change though, so we're stuck with Collada for now.