永远也不完美的程序

不断学习,不断实践,不断的重构……

常用链接

统计

积分与排名

好友链接

最新评论

Skeletal Animation Blending(转)

转自:http://www.circlesoft.org/DirectMesh2/DM2Spec/pages/Features.htm

2 Features


This section describes the major features of DM2, in basic form.  While the functionality of these features will be discussed, more detailed information about their implementation will be given later.

     
      


2.1 Skeletal Animation

DirectMesh v2.0 will use skeletal animation as it's primary form of frame-based movement.  Skeletal animation is based on bones, which are in turn connected to individual vertices.  These vertices act as a "skin" on top of the bones. 

Unlike keyframe animation, where each and every vertex is animated, skeletal animation consists of transforming only the bones.  The bones then act on the assigned vertices, providing the expected deformation.  Since this is how the human body actually works, it is an ideal scheme for character animation.

These vertex deformations will be processed in a vertex shader, on GPU hardware.  If the required hardware is not available, the animation interfaces will fall back to a software implementation.  Leveraging the GPU to perform these transforms will minimize the performance hit that is normally associated with skeletal animation.

The software implementation will also be available for use even if hardware support is present.  This could be useful in situations where the same pose must be rendered multiple times.  In this case, it is a waste to skin the mesh for each time, considering that it can be done in software once and applied to all subsequent renders.

Each vertex will have a maximum of 4 attached bones.  This is to accommodate for the limitations of current graphics hardware, file size, and memory usage.  A case of 5 or more bones acting on a single vertex is usually uncommon, anyways.

This maximum of 4 attached bones will be able to be changed at runtime.  This can be useful in situations where dynamic level-of-detail (LOD) is critical.  For example, if a model is far away from the viewpoint, the number of active bones can be lowered to prevent wasted transforms.  If the models moves closer to the viewpoint, the number of active bones can be raised again.


2.2 Morph Targets

A morph target is a keyframe of a mesh (or a portion of a mesh) in a specific pose.  Each morph target is blended with the base mesh by a certain percentage, where 0% has no effect on the mesh and 100% has full effect on the mesh.  This percentage can be animated, providing smooth transitions between targets.  When a morph target exhibits an effect on the base mesh (that is, it's blend percentage is greater than 0), it is said to be "active". 

This morphing technique is very useful for situations where a high amount of detail is required.  Since using bones is not practical in such situations,  morph targets are used instead.  A prime example is facial animation, since individual vertices must be tweaked to get the exact pose required.

Multiple morph targets can be active during the same frame.  For example, the face of a character may have a "winking" morph target and a "smiling" morph target.  These two targets can be blended together with the base mesh to generate a model that is both "winking" and "smiling".

Due to the complexity of morph targets, they must be processed in software.  For this reason, there is no limit to the number of morph targets per mesh.  However, more morph targets will result in increased memory usage and file size.  Also, there is no limit to the number of active morph targets, although more active morph targets will result in a performance hit.

Skeletal animation and morphing can both be used simultaneously.  After all of the active morph targets are composted into a dynamic buffer, the processed mesh will be deformed by the skinning shader.  This provides a very flexible solution, in which both quick, efficient animation and detailed animation can be combined.

For a practical example of morphing, consider our friend Johnny:

Johnny has the following morph targets defined:

We can now combine these morph targets in any way that we like.  For example:


2.3 Subsets

A subset is a group of faces that share the same material.  A DirectMesh model can be divided up into multiple subsets, allowing for different materials to be used throughout the mesh.  This can be very useful when modeling, since most real-world objects and characters are actually composites of different parts.

Depending on the number of active bones, there may be more transformation matrices than constant registers in the skinning shader.  If this occurs, the mesh must be split up into multiple subsets, based on each face's active bones.  This is done so that the shader will always have registers available for the matrices.

Below is a table of the default maximum number of bones per subset, based on each vertex shader model.  Note that 12 or 16 constant registers will always be left over, in case the shader needs to store custom data.  Since each bone transformation matrix is 3x4 (3 rows by 4 columns; the perspective vector does not need to be store), every bone takes up 3 constants (each constant register holds a float4, and a matrix is 3 float4's).

Vertex Shader Model Minimum Constants Available Constants Left Over Bone Matrices Available
vs_1_1 96 12 28
vs_2_0 256 16 80
vs_2_x 256 16 80
vs_3_0 256 16 80

It is important to note that these values are only the recommended defaults.  A new value may be specified at runtime (the maximum number of active bones per subset is 255), and the subsets will be reconfigured automatically.  This is to accommodate for both shaders that need additional constant space and for substantially different hardware.

Since each subset has different device-related properties, each subset must be rendered independently.  For this reason, it is best to keep the number of subsets as low as possible.
 


2.4 Material Manager

DM2 files can contain information defining a mesh's material.  A material includes the selected shader, constant values, and textures.  This will allow the artist to easily export the material properties along with the base mesh and its animations.

At runtime, the DirectMesh interfaces can automatically load all vertex shader, pixel shader, and effect files.  Textures can also be dynamically loaded.  Before rendering, DirectMesh will setup the shader, its constants, and the textures.  No outside intervention is necessary.  However, since this tightly integrates the material system and DirectMesh, complete material management will be optional.  Some developers may prefer to handle material-related events themselves.


2.5 Animation Blending

An Animation Stage represents an individual, active animation that can be blended with other stages to form the final pose of the mesh.  In order to combine the Animation Stages, two types of animation blending are implemented within the pipeline:  additive blending and transitional blending.

2.5.1 Additive Blending

Additive blending is used to combine multiple Animation Stages.  Essentially, it overlays multiple Animation Stages on top of one another, enabling multiple animations to be playing at the same time.   There is no limit to the number of additive blends, but each additional stage will produce a small performance hit.

To ensure that the bones are correctly blended together, the artist can flag each bone as "active" or "inactive" for each Animation Stage.  The "active" bones from the different Animation Stages will then be combined to form the final pose.  This effectively masks bones that are not essential to each animation from the bones that are.  For example, a "Walking" animation may displace the leg and arm bones.  However, only the leg bones are flagged as active, since they are essential to the "Walking" animation.  The arm bones are not essential (since you can walk and do different things with your arms at the same time), so they can be used in a different blending stage.

All of the active animations are organized into a hierarchy.  If a conflict between animations occur (they both have the same bone(s) active at the same time), then the animation higher in the hierarchy will override the lower animation.  If the complete bone set is not flagged as active between the blended animations, then the highest animation will use the position of it's bones.  Also, if more than one blended animation has at least one active morph target, then the morphs in the higher animation will override the morphs in the lower animation(s).

Take the following as an example:

 
 

The "Walk" pose.  This is the first animation in the blending sequence.  On the right, the active bones are highlighted in red.

 

 

The "Fire" pose.  This is the second animation in the blending sequence.  On the right, the active bones are highlighted in red.

 

 

The Final pose.  Note that the active bones from the "Walk" pose are combined with the active bones from the "Fire" pose.  The bones that aren't flagged as active between "Walk" and "Fire" are taken from "Fire".

2.5.2 Transitional Blending

Transitional blending is used to blend the end of one animation with the beginning of another.  For example, a "Walking" animation can seamlessly transition to a "Running" animation.  This is achieved by blending a decrementing percentage of the current animation with an incrementing percentage of the future animation.

Whereas additive blending blends separate Animation Stages together, transitional blending is used to compose an individual Animation Stage.  It never blends two stages together - just individual animations, creating it's own dynamic Animation Stage.  In effect, stages created with the Transitional Blender are fed back into the Additive Blender, allowing them to be combined with other stages. 

This is useful if only one of the active stages needs to transition.  Referring the examples from above, assume that the "Walking" animation is being blended with the "Firing" animation.  The "Walking" animation can then be transitioned into the "Running" animation, while still being blended with the "Firing" animation.

Also, additive blending combines Animation Stages, based on each stage's set of active bones.  Transitional blending, on the other hand, simply combines all bones.  The set of active bones in the new Animation Stage are determined by combining both sets of active bones from the animations being transitioned between. 


2.6 File Compression

To maintain an acceptable disk footprint, DM2 files can be compressed.  zLib will be used to deflate and inflate the files.  File compression is optional, allowing for custom file processing (ie custom compression and/or encryption) or a shorter loading time.


2.7 Common Exporter Framework

The Common Exporter Framework, otherwise abbreviated as CEF, serves as an exporting library, independent of 3d modeling suites.  This allows for new exporters to be created quickly, since the majority of the functionality is completely reusable.

To create a new plugin, the programmer must provide the implementation of an abstracted Studio interface, which acts as a bridge between CEF and the modeling suite.  It allows the framework to communicate back and forth with any arbitrary program.  Dialogs (as well as other GUI-related events), file writing, and mesh processing will be handled by CEF.

A 3D modeling program doesn't have to support all of the features of DM2 to use CEF.  When queried, the interface to the modeler can fill in data that it has, and can leave empty the data that it doesn't support.  For example, if "Studio X" doesn't support morph targets, it should just leave the morphing data blank.  However, it can still fill in all of the other information that it does support.


2.8 Software Development Kit

The DirectMesh Software Development Kit comes complete with source code, documentation, utilities, exporters, samples, and tutorials.  The licensing of the DMSDK is very simple:  it is completely free to use in any private, public, or commercial endeavor.  The source code can be modified without any restrictions whatsoever.

posted on 2010-01-16 10:37 狂烂球 阅读(1347) 评论(0)  编辑 收藏 引用 所属分类: 图形编程


只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理