Page 1 of 2

Skeletal animation for ZGE

Posted: Fri May 02, 2014 8:45 pm
by Rado1
Hi all,

after one afternoon of learning, implementation and testing I finally added skeletal animation to ZGE. The provided external library ZgeSkelet is build as a wrapper to skeletal-based 3D character animation library Cal3D, which is very easy to understand, build and integrate. (That's the reason why all of this has taken such a short time.) In addition, ZgeSkelet provides also a helper for rendering animated meshes directly by VBOs. For now, I have the 1st experimental version of the library for Windows, but I hope it can easily be compiled also for Android.

The demo project can be downloaded from this link. To change cyclic animations, press keys 1 - 5; to activate action animations press 6 or 7. Action animations have higher priority than cyclic animations, but they both run at the same time (animations can overlap). The demo contains the ZGE project, ZgeSkelet.dll, and animation resource files. The resource files are taken from Cal3D examples, but you can create your own with Blender + Cal3D exporting plugin; or with 3D Max if you have it.

You can learn more about Cal3D from this page. It will give you hints how to use ZgeSkelet external library.

The library is still not complete. As next, I plan to improve management of materials and their usage for sub-meshes, because now all meshes of the animated model can have only one material. Also, loading of animation resources from memory will further be explored. Later it will appear on Google Code, so you can check also its implementation and compile it by yourself.

Any comments are welcome. Thanks.

Rado1.

Posted: Sun May 04, 2014 10:30 pm
by Rado1
Today, I added support for multi-textured meshes. The demos and the latest version of the ZgeSkelet DLL can be downloaded here.

Posted: Mon May 05, 2014 7:28 am
by VilleK
That's very nice! Finally there is an alternative for those who want support for mesh skeletal animations until if/when it gets added as a ZGE built-in feature. Rado1 does it again :)

Posted: Mon May 05, 2014 3:33 pm
by Rado1
A small update: loaded materials can be identified by user IDs and these material IDs can be retrieved by zsk_GetSubmeshUserMaterialId() function. This mechanism can be used during rendering to switch among different materials used for rendering sub-meshes. This is more effective than switching materials by texture file names as used up to now.

The ZgeSkeletDemo2 has been updated accordingly. Demos can be downloaded from this link.

Posted: Tue May 06, 2014 10:34 pm
by Rado1
Added support for loading resources from memory, i.e., the functions:

Code: Select all

int zsk_LoadSkeletonBuffer(int coreModel, xptr buffer) {}
int zsk_LoadAnimationBuffer(int coreModel, xptr buffer) {}
int zsk_LoadMeshBuffer(int coreModel, xptr buffer) {}
int zsk_LoadMaterialBuffer(int coreModel, int userId, xptr buffer) {}
All these functions require an byte[] array with the content of animation resource file. Thanks to "power" of ZGE scripting language, it was possible to write quite a nice code which can load files by ZGE and then to pass them to ZgeSkelet library. I mean the following:

Code: Select all

const string RESDIR = ANDROID ? "/assets/skeleton/" : "skeleton\\";
byte[] fileBuffer;

/ load file and store it in a buffer which is then returned
byte[] load(string filename){
  @FileAction(File:
    @File(FileName: RESDIR + filename, Encoding: 1, TargetArray: fileBuffer),
    Action : 0);

  return fileBuffer;
}

// load skeleton
zsk_LoadSkeletonBuffer(SkeletonCoreModel, load("skeleton.csf"));
...
Nice, isn't it? (Ville, Kjell is it correct?) Thanks to this feature, I was also able to port the ZgeSkelet library to Android, because it was not possible to use the functions which load animation resources directly from files (zsk_Load*()) - they are working only on Windows. Since ZGE is able to load files from Windows and also from Android seamlessly, the current solution is portable and very elegant. Originally I started to implement loading files for Android by NDK, by it required some dirty and non-flexible JNI programming.

The previously mentioned download link contains now updated DLL, the Android shared library compiled for armeabi-v7a, and updated demo projects. The demo project #1 can be compiled also for Android - just copy the libZgeSkelet.so to the libs/armeabi folder and copy the skeleton folder with animation resources to the assets folder; then recompile Android apk again and install on device. If you do not want to compile by yourself, use the included Skelet Demo 1-debug.apk.

Posted: Wed May 07, 2014 7:30 am
by VilleK
Fantastic :). Code looks correct to me. Hope someone will put this to good use! Let me know if you want to upload a video clip of this to ZGE YouTube channel.

Posted: Fri May 23, 2014 10:39 am
by Rado1
ZgeSkelet project has been added to Google code: http://code.google.com/p/zgeskelet/

Among source code, compilation instructions and version history, the project contains also the description how to use skeletal animation in ZGE projects, including Android apps: http://code.google.com/p/zgeskelet/wiki/HowTo

Posted: Sun Mar 15, 2015 9:29 am
by Rado1
Source code repository for ZgeSkelet has been moved to GitHub.

Re: Skeletal animation for ZGE

Posted: Sun Jan 03, 2016 1:12 pm
by Barefists
I've been at this for a whole day but I can't find a solution for this.
I'm exporting Cal3d assets from 3ds max 2016 using both the Cal3d Exporters found at Vizard and IMVU, but all the exported models give an access violation error in ZGE. :(

Image

Please help.

Re: Skeletal animation for ZGE

Posted: Sun Jan 03, 2016 6:58 pm
by Rado1
Hi Barefists,

just send me your assets and the ZGE project file, I can have a look at it and possibly also debug.

Rado1.

Re: Skeletal animation for ZGE

Posted: Mon Jan 04, 2016 12:09 am
by Barefists
Hi Rado,

Thanks for your help! :)
The files can be found here.

Regards,
XM

Re: Skeletal animation for ZGE

Posted: Mon Jan 04, 2016 10:21 pm
by Rado1
Hi, I observed that the crash happens at calling zsk_GetSubmeshUserMaterialId() function in initialization of model. The problem is that submeshes do not define their materials. In blondie_mesh.xmf MATERIAL="-1" which is not probably correct value.

I fixed the project and set camera and light to render mesh properly, download it from here. However, check your material, shader and texture coordinates for submeshes, because textures are not rendered correctly. BTW the textures are unnecessarily large ...

BTW updated version of ZgeSkelet DLL (also for 64bit) can be found here.

Re: Skeletal animation for ZGE

Posted: Tue Jan 05, 2016 1:46 am
by Barefists
Hi Rado! Thank you so much for your help! I adjusted the material settings and have it working now! :)
Image

Re: Skeletal animation for ZGE

Posted: Tue Jan 05, 2016 7:32 am
by Rado1
It looks nice.

Re: Skeletal animation for ZGE

Posted: Wed Jan 06, 2016 12:02 am
by Barefists
Thanks! I can't take credit for the model though - it's generated using Mixamo Fuse and animated in their autorigger (all free with an Adobe ID at http://www.mixamo.com).

I've been trying to get StevenM's extra lights dll to work with this, but it seems the Cal3D model only accepts lighting from one source. Not sure where the problem lies, here's a screenshot of it - the sphere beside the model (on the same z-plane) catches the red light, but not the model.
Image

Project files here.