-
Notifications
You must be signed in to change notification settings - Fork 0
How to Use
Rado1 edited this page Mar 15, 2015
·
1 revision
- Open an ZGE project.
- Include
ZExternalLibrary
component for ZgeSkelet library to theOnLoaded
section ofZApplication
. It can be found in the context menu Add from library... > External libraries > Skeletal animation library of the Project tree. - Create core model(s) by the
zsk_CreateCoreModel()
function. This initialization phase is usually placed either to theOnLoaded
section ofZApplication
orOnStart
section ofAppState
component. - Load core skeleton, animations, meshes and materials by
zsk_Load*()
functions. They can either be loaded from files directly, or from memory buffer (see thezsk_Load*Buffer()
variants). Memory buffers are byte arrays which can either be preloaded and persistent (so they are included in the ZGE project "statically") or can be loaded dynamically byFile
+FileAction
components. Memory buffers must be used if you build your application for Android; becausezsk_Load*()
functions are working only on Windows. - After loading materials, prepare the material threads and sets by
zsk_CreateCoreMaterialThread()
andzsk_SetCoreMaterialId()
functions. They are used later to set or dynamically change "skins" of animated models. To understand material threads and sets, see the Cal3D User's Guide for details. - The natural way (but not the only one) of using instances of animated models is to wrap them to ZGE's
Model
components because they have similar life cycles. To create a model instance, use thezsk_CreateModelInstance()
function. Then attach already loaded meshes to it byzsk_AttachMesh()
and set the material set used for initial rendering of model byzsk_AttachMesh()
function. All this procedure is usually placed to theOnSpawn
section of theModel
component. - To start cyclic animation use the
zsk_BlendAnimCycle()
function and to start action animation, use thezsk_ExecuteAction()
function. If animations represent initial state of the model instance, they are placed to itsOnSpawn
section, and if animations should be changed on runtime, they are placed to theOnUpdate
section of the correspondingModel
component. - To change the mesh of the animated model in time, use the
zsk_Update()
function in the model'sOnUpdate
section. To achieve real-time animation, useZApplication.DeltaTime
property as value of thedeltaTime
argument. The simulated animation time can also be slower than real, e.g.ZApplication.DeltaTime / 2
, or faster, e.g.,ZApplication.DeltaTime * 2
. - To render meshes of the animated model use the predefined functions which allow effective OpenGL rendering by means of Vertex Buffer Objects (VBOs).
- For models rendered with no or one texture, use the
zsk_RenderModelInstance()
function placed in theOnRender
section. Do not forget to set the used material byUseMaterial
component. If materials of the animated model define different colors, you can set thebSetColor
argument to 1 to make different colors visible on the rendered meshes. If the model uses texture, put it to the used material's (byMaterialTexture}} component) and set the {{{bRenderTexture
argument to 1. See the sources of ZgeSkeletDemo1.zgeproj project as an example of usage thezsk_RenderModelInstance()
function. - For multi-textured models use the
zsk_RenderSubmesh()
function which allows to render a single sub-mesh (a part of the model's mesh drawn with a single material). To draw all of the model's sub-meshes, you must obtain their numbers for each of the model's mesh by means of thezsk_GetSubmeshCount()
function. To query a material attached to a sub-mesh, use either thezsk_GetSubmeshTexture()
function which returns a file name of the 1st of the material's textures, or use more effectivezsk_GetSubmeshUserMaterialId()
function which returns the material's user ID previously specified in corresponding call of thezsk_LoadMaterial*()
function. See the sources of ZgeSkeletDemo2.zgeproj project as an example of multi-textured skinned animated models. - When a model finishes its life, place the
zsk_DestroyModelInstance
to itsOnRemove
section. - When there will be no other instance of a given core model used (in a given game stage), call the
zsk_DestroyCoreModel()
function. This is usually done in theOnClose
section of theZAppliaction
component, orOnLeave
section ofAppState
component.
For examples of usage ZgeSkelet in ZGE projects, download the demo applications from here.
- Compile your Android application, e.g., use Project / Android: Build APK (debug) menu item.
- Place libZgeSkelet.so file to the libs/armeabi folder. If the destination device supports the armv7a instruction set, it is recommended to use the library from ZgeSkelet-armv7a.zip file. If not and you want to support wider range of devices, use the library from ZgeSkelet-arm.zip file. They both work fine, but the version for armv7a achieves better performance.
- Compile the APK again as in step 1.
- Deploy the APK file to your Android device and install it in a standard way.
Note 1: The 1st and 2nd steps are required only when the application is built the first time. After that, a single compilation produces correct APK.
Note 2: Use the step 2 also in the case when updating to a newer version of the ZgeSkelet library.