×
Menu

NiSkinInstance help (en)

 

 Выдержка из оригинальной справки. (NDL Gamebryo 1.1)
 
NiSkinInstance contains the skinning data that is instance-dependent, as well as a pointer to an NiSkinData object, which contains the instance-independent data. Skinning is usually achieved by attaching an NiSkinInstance object to an NiGeometry object, but the NiSkinInstance class does contain functions to allow applications to implement manual skinning (i.e. skinning without attaching an NiSkinInstance object to an NiGeometry object).
 
Notes
The following description defines the calculations that are used to deform vertices and normals in a skinned object. Given the index, b, of a particular bone in an NiSkinInstance; a transformation, Mb, for that bone is calculated as follows:
 
Mb = Mroot parent to skin * Mbone b to root parent * Mskin to bone b
 
Where
Mskin to bone b transforms bind-pose vertices and normals from the coordinate system of the skinned object to the coordinate system of bone b. This transformation is stored in an NiSkinData::BoneData object, an array of which is passed as the pkBoneData argument to the NiSkinData constructor and which can be accessed by the function NiSkinData::GetBoneData.
 
Mbone b to root parent deforms bind-pose vertices by transforming them from the coordinate system of bone b to the coordinate system of the root bone parent, using the current object transformations. This matrix is calculated by factoring the world transformation of the root bone parent out of the world transformation of the bone (i.e. the inverse of the world transformation of the root bone parent is multiplied by the world transformation of bone b).
 
Mroot parent to skin transforms deformed vertices from the coordinate system of the parent of the root bone back to coordinate system of the skinned object. This transformation is passed as the kRootParentToSkin argument to the NiSkinData constructor and accessed by the function NiSkinData::GetRootParentToSkin.
 
At first glance, it may seem that these transformations combine to form an identity matrix, since they transform from the skin's coordinate system to bone b's coordinate system, and then back again to the skin's coordinate system. They do not combine to form an identity matrix, however, because the vertices are transformed from the coordinate system of the skin to the coordinate system of bone b using bind pose transformations, and then transformed from bone b's coordinate system to the coordinate system of the root bone's parent using the current transformations of all the bones in the hierarchy from bone b to the root bone parent, and then finally from the root bone parent's coordinate system back to the skin's coordinate system using bind pose transformations.
 
Having defined how a transformation matrix for each bone is calculated, we can define how these transformations are combined to calculate final vertex positions and normal vectors for a skinned object. Suppose a particular vertex is influenced by two bones, whose indices are b0 and b1, and that the weight of bone b0 is w0, and the weight of bone b1 is w1 (the sum of w0 and w1 must be 1.0. Weights for vertex-bone interactions are stored in the NiSkinData::BoneVertData class.) If the bind-pose position of the vertex is v, then the deformed vertex position is:
 
w0 * Mb0 * v + w1 * Mb1 * v
This formula extends naturally to vertices that are influenced by any number of bones.
 
Bind pose normals are deformed in the same way, except the scales are factored out of the transformation matrices, and, since the above equation does not produce normals that are of unit length even if the bind pose normals are of unit-length, the normals produced by the deformation code are re-unitized.
 
Hardware Skinning in DX8
The NiDX8Renderer supports hardware-based skinning on hardware T&L devices that can support at least 4 bones (matrices) per object. Gamebryo will enable hardware skinning if the hardware is capable and if the skinned object has been prepared for hardware skinning by being partitioned. Skinned objects are partitioned by the artist tools when they are exported with support for hardware skinning enabled. On hardware that cannot support the required minimum number of bones, or if the skinned object does not contain partitions, optimized Gamebryo software skinning code will be used. Hardware skinning not only avoids the need to deform the skin on the host processor, but also the need to repack video-memory vertex buffers each frame, further enhancing performance. It is also possible to use vertex shaders on cards that support them to deform skinned objects using as many as 20 or more bones per object.