FBX Blendshape/morph Animation parsing

Source: Internet
Author: User

Three variants are currently supported in FBX 2015.1: Skindeformer,blendshapedeformer,vertexcachedeformer. Defined in Fbxdeformer.h:

Enum Edeformertype {

Eunknown,//!< Unknown deformer type

ESkin,//!< Type Fbxskin

Eblendshape,//!< Type fbxblendshape

Evertexcache//!< Type Fbxvertexcachedeformer


The first two variants correspond to: bone skin animation and deformation animation, (the third is not studied).

The corresponding playback code can be found in the Viewscene example.

The skeleton skin animation game used the most, so the study earlier. These days have seen a bit of deformation animation (Blendshape/morph animation), scattered record a number of considerations.

One, Blendshape basic principle.

In principle, interpolation is between mesh with the same topology. Details are mentioned later in this article.

The typical application is to make an emoticon animation.

Second, make a model with deformable animation in 3dmax.

I use 3dmax 2012 (Chinese version).

1, first build a Model X, and then copy out an X1.

2, the X1 is deformed under the condition that the topological structure remains unchanged.

3, add the Deformer modifier to x, add X1 to one channel of the Deformer modifier, then X1 becomes a morph target of X.

4, adjust the channel value, you can see X affected by X1 deformation.

5, turn on auto key, record warp animation.

You can repeat the above method to add multiple morph targets to X.

One channel of the Deformer modifier can add multiple morph targets, and the channel name will display the name of the first morph target added to this channel, and any morph targets added by this channel can be seen in the target list in the Progressive deform column.

When multiple morph targets are added to a channel, the progressive morph,x is transformed sequentially in the order of the targets in the target list.

Also note that it is not possible for any of the X1 to maintain topological modifications to affect the X, only the modification of the local space (for example, modifications made with the local space modifier, changes made directly to the vertex position), and changes to the X1 as a whole (such as rotation, panning, and Scaling, etc.) will not work.

Third, fbx deformation animation principle.

The Computeshapedeformation () function in the Viewscene example of the FBX SDK implements data extraction and playback of the Morph animation, which can be understood by reading this part of the code to understand the logical structure of the distorted animation data in FBX:

A mesh contains multiple blendshape,

A blendshape contains multiple blendshapechannel,

A blendshapechannel contains multiple targetshape and a weight animation curve weightcurve.

The Targetshape contains controlpoints and a fullweight value.

The correspondence between these structures and 3dmax is as follows:

Mesh corresponds to the model in 3dmax,

The blendshape corresponds to the Deformer modifier, and a model can add multiple Deformer modifiers,

The blendshapechannel corresponds to the channel of the Deformer modifier, and blendshapechannel->getname () gets the channel name.

Targetshape corresponds to a morph target, one channel can add multiple morph targets. Targetshape->getname () Gets the morph target name.

The Weightcurve of the channel gives the progress weight of this channel deformation at each point in time.

The fullweight value of the Targetshape represents the full deformation of this channel when the weight value of the deformation progress of the tunnel is exactly the same as this targetshape. For a channel with only one targetshape, the fullweight of Targetshape must be 100, and for channels with multiple targetshape, the targetshape values of each fullweight increase sequentially, And the last Targetshape fullweight must be 100.

Visible, very intuitive, so that the deformation interpolation algorithm almost no longer see Computeshapedeformation () code can be directly imagined.

The following is a note in Computeshapedeformation () that illustrates the interpolation algorithm in progressive morph and progressive morph with specific examples, exactly as our intuitive vision:

If there is a targetshape on this channel, the influence are easy to calculate:

Influence = (targetshape-basegeometry) * weight * 0.01

Dstgeometry = Basegeometry + influence

But if there was more than one targetshapes on the This channel, the is a in-between

Blendshape, also called progressive morph. The calculation of influence is different.

For example, given-in-between targets, the full weight percentage of first target

IS-weight percentage of the second target is 100.

When the weight percentage reach, the base geometry are already be fully morphed

To the first target shape. When the weight go through, it begin to morph from the

First target shape to the second target shape.

To calculate influence when the weight percentage is 25:

1. Falls in the scope of 0 and, the morphing are from base geometry to the first target.

2. And since already half between 0 and, so the real weight percentage

The first target is 50.

Influence = (firsttargetshape-basegeometry) * (25-0)/(50-0) * 100

Dstgeometry = Basegeometry + influence

To calculate influence when the weight percentage is 75:

1. Falls in the scope of the and, the morphing are from the first target to the second.

2. And since-is already half-between, so the real weight percentage

To the second target is 50.

Influence = (secondtargetshape-firsttargetshape) * (75-50)/(100-50) * 100

Dstgeometry = Firsttargetshape + influence

Four, multi-channel simultaneous impact when the superposition mode.

Assuming that the deformed object x is affected by Channel1 and Channel2 two channels, there is only one morph target shape1 in Channel1, and the channel deformation progress is only one morph target W1;channel2 in Shape2, and the channel deformation progress is W2. Set V is a point on X, the original coordinate is p;v1 is the shape1, the coordinates of P1;V2 is shape2, the coordinates of the first place is P2.

The coordinate p_deformed of V under the influence of two channels shall be calculated as follows:

p_deformedbychannel1=p+ (p1-p) *w1

p_deformedbychannel1andchannel2=p_deformedbychannel1+ (P2-P_DEFORMEDBYCHANNEL1) *w2


Five, normal problem.

Deformation of the deformed object, if only the vertex position changes, and the normal is not changed, then in the case of light to display the effect is not correct, so the normal also need to be in the deformation of the object and deformation of the target interpolation.

The previous analysis of the FBX morph animation data logical structure mentions that "Targetshape contains controlpoints and a fullweight value" because in the viewscene example, The vertex position of deformed object is deformed only using Targetshape's controlpoints, but the normal deformation is not dealt with at all. I didn't find a way to get effective normals from Targetshape. And when I export the animation as an ASCII fbx, I see that the Targetshape normals data is all 0.

My current solution is to get targetshapename by Targetshape and then search the scene by name for the model (mesh) that corresponds to the targetshape, and then get the normal data from the mesh. This requires that the deformable target model cannot be deleted and is exported to the FBX file along with the deformed object. Another problem to note is that since my engine only supports triangulation, the object will be built into a triangular mesh when the 3dmax is modeled, or the "triangulation" option is checked when exporting to FBX files, or the APIs provided by the FBX SDK are converted to triangular mesh after the engine loads the FBX file. However, neither of the two can guarantee that the mesh and deformation target mesh of deformed objects will still have identical topological structure after triangulation. If the topological structure of deformed object mesh and deformed target mesh is different, normal interpolation cannot be done.

Note: Vertex position interpolation is not required to deform the mesh and deformation of the target mesh topology is the same, as long as the vertex can correspond, vertex position interpolation can be done, so if the viewscene example as the same as only processing vertex deformation, regardless of normal deformation, It is not necessary to require the model to be built into a triangular network in 3dmax. (There is no need to consider the normal deformation of the situation is really there, for example, like "Subway parkour" kind of light-free Q version 3d game, do not need normal, so do not consider normal deformation when deformation).

Normal interpolation is the interpolation between vectors, which is different from vertex position interpolation (interpolation between points). The interpolation between the points is directly linear, and the interpolation between vectors should strictly use spherical interpolation (SLERP). However, after testing, it was found that the visual difference between the two methods is not very large, and the linear interpolation speed is much faster, so I still chose the linear interpolation.

Six, the Viewscene example has an error in the Morph animation code.

The code that plays the Morph animation in the Viewscene example is faulty, exporting the animation from 3dmax to FBX and then playing with the Viewscene example, you'll find that the viewscene example plays differently in 3dmax, and there are obvious errors such as jumps in the animation.

I can't remember exactly what caused it, but I solved the problem in my own playback program.

Effect Video:

FBX Blendshape/morph Animation parsing

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.