Fbx model parsing and loading based on fbx SDK-(4)

Source: Internet
Author: User
8. Skeleton skin Animation

Currently, skeleton skin animation is the most commonly used animation method in game engines. There are many materials about its basic principles on the network and other complex operations involved, for example, interpolation and fusion will not be discussed here, and the implementation method is also related to the Action Management System of a specific engine; here we will briefly introduce how to load the skeleton and skin information from fbx and complete the most basic skin animation effects. The implementation of the skeleton animation mainly includes the drive of the skeleton and the operation of the skin. The drive of the skeleton has been completed during the loading of the animation data in the previous article, the next step is the skinning operation between the mesh and skeleton.

We know that bone animation updates the mesh associated with these bones by updating a small number of skeleton, the smooth and smooth action can be achieved by performing such updates between each frame and performing appropriate interpolation and fusion. The preceding basic ry and the loading of animation data (skeleton and mesh) have the necessary information. Next we need to associate the two to implement correct sking during skinning. This part of data is actually read in mesh units. Its hierarchical structure is shown below:

The mesh can be obtained from the node with the current attribute of emesh (the same as reading the geometric mesh data ), it may be a small part of the mesh that forms the entire model (sub-mesh ). If the current mesh contains the corresponding skin animation data, you can read all vertex-to-skeleton ing information from it. The skin data in the mesh is managed by one or more kfbxdeformer. kfbxdeformer is an object of the kfbxtakenodecontainer type. Each deformer manages the mappings between some vertices in the current mesh and skeleton. The mappings are organized in two different ways, therefore, kfbxskin and kfbxvertexcachedeformer derived from deformer (generally, you only need to consider the kfbxskin method ). Each skin (deformer) may correspond to multiple vertices, which may be mapped to multiple skeleton, and each skeleton in skin (deformer) corresponds to a cluster. In this way, find the affected vertex in each cluster (-> skeleton, obtain the corresponding connection information, such as ing matrix and bone weight, and store the corresponding information to complete the ing skin between skeleton and mesh. Note: The relationship between vertex and skeleton is many to many, that is, a vertex may be affected by multiple skeleton, and one skeleton may affect multiple vertex; pay attention to these relationships when designing data structures. The code for this part is described as follows:

Void associateskeletonwithctrlpoint (kfbxmesh * pmesh, cskeletonmgr * pskeletonmgr, list <vertexskeletonlist> & ctrlpointskeletonlist) {If (! Pmesh |! Pskeletonmgr) {return;} int ctrlpointcount = pmesh-> getcontrolpointscount (); int deformercount = pmesh-> getdeformercount (); // initialize the corresponding list ctrlpointskeletonlist. setcapacity (ctrlpointcount); ctrlpointskeletonlist. setlistsize (ctrlpointcount); kfbxdeformer * pfbxdeformer; kfbxskin * pfbxskin; For (INT I = 0; I <deformercount; ++ I) {Limit = pmesh-> getdeformer (I ); if (pfbxdeformer = NULL) {continue;} // only eskin is considered If (pfbxdeformer-> getdeformertype ()! = Pipeline: eskin) {continue;} pfbxskin = (kfbxskin *) (pfbxdeformer); If (pfbxskin = NULL) {continue;} pipeline (pfbxskin, pskeletonmgr, ctrlpointskeletonlist );}}
Void associateskeletonwithctrlpoint (kfbxskin * pskin, cskeletonmgr * pskeletonmgr, list <vertexskeletonlist> & ctrlpointskeletonlist) {If (! Pskin |! Response) {return;} kfbxcluster: elinkmode linkmode = kfbxcluster: enormalize; kfbxcluster * pcluster; kfbxnode * plinknode; int knode; vertex * vertex; kfbxxmatrix transformmatrix, transformlinkmatrix; int clustercount = pskin-> getclustercount (); // process each cluster in the current skin (corresponding to skeleton) for (INT I = 0; I <clustercount; ++ I) {pcluster = pskin-> getcluster (I); If (! Pcluster) {continue;} plinknode = pcluster-> getlink (); If (! Plinknode) {continue;} // The skeleton corresponding to the current cluster is searched through the skeleton manager and associated with the cluster skeletonindex = pskeletonmgr-> findskeleton (plinknode-> getname ()); //... // associate skeleton with clusterif (skeletonindex <0) {continue;} pskeleton = pskeletonmgr-> getskeleton (skeletonindex); // obtain each cluster (skeleton) the corresponding transform and transformlink matrices are described in the following sections: pcluster-> gettransformmatrix (transformmatrix); pcluster-> gettransformlinkmatrix (transformlinkmatrix); // other suitable operations, convert transform and transformlink into ing matrices and store them in the corresponding skeleton // ...int associatedctrlpointcount = pcluster-> getcontrolpointindicescount (); int * Records = pcluster-> getcontrolpointindices (); double * pctrlpointweights = pcluster-> getcontrolpointweights (); int ctrlpointindex; // traverses each vertex affected by the current cluster, the corresponding information is recorded so that the for (Int J = 0; j <associatedctrlpointcount; ++ J) {ctrlpointindex = pctrlpointindices [J]; ctrlpointskeletonlist [ctrlpointindex] is used for skinning. addskeleton (skeletonindex, pctrlpointweights [J]) ;}}

The above code is only part of the complete code, because most of the operations involved are related to the specific implementation system. Here, only part of the code is listed for reference. There are two operations
Pcluster-> gettransformmatrix (transformmatrix );
Pcluster-> gettransformlinkmatrix (transformlinkmatrix );
Note that the two operations obtain two matrices, the former transformmatrix (MtUsed to describe the transformation matrix of the mesh (vertex transformation matrix) at the current ing moment (under the initial ing state ),
The latter transformlinkmatrix (recordedMTLIs used to describe the transformation matrix of bone at the current ing time (refer to the description in kfbxcluster. h ). Suppose that the vertex can be associated through the current clusterVAnd skeletonBAnd its corresponding space transformation matrix isMV,MBTherefore
MV = MT; MB = MTL
In the skin of the mesh to skeleton, the skeleton spatial position must be transformed to obtain the spatial position of the mesh (vertex). Therefore, such a transformation matrix is required.MMake


You can get it through simple transformation.

TheMWhen the animation is updated, it can be used for the ing between skeleton and mesh.
Then, you can update the mesh through skeleton to obtain the animation of the entire model. For example, a set of actions shown in the following figure:

 

 

9. Other problems

Although the fbx SDK provides a friendly operation interface for the fbx model, the current version has some problems:

  • The fbximporter provided by the fbx SDK currently does not support Chinese paths. Therefore, the provided fbx source file address should not contain Chinese characters.
  • The fbx export plug-in 3D Max or Maya may cause some problems, especially in the parts with Symmetric Property UV.
  • The exported normal with the smooth feature will also be non-smooth at some mesh interfaces.

The last two problems may have serious impacts in some cases, but since the original geometric data has been loaded into its own engine, therefore, tangent and normal can be re-computed in the engine.

The preceding section describes common operations involved in fbx loading using the fbx SDK, such as loading grids, materials, and animations. It also provides some implementation code, however, different systems have different management methods for various resources (such as animation, skeleton, and material), and the Code cannot be used directly. It is essential to modify the code appropriately. In addition, the errors are inevitable, so the above content is only for reference, the specific implementation also needs to study and reference the relevant Autodesk Doc.

Finally, welcome to the discussion and discussion ~~

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.