Over 10 Million Study Resources Now at Your Fingertips

Download as :
Rating : ⭐⭐⭐⭐⭐
Price : $10.99
Pages: 2

Set the local variable maxboneindex equal loop variable

Now we know which subset we are processing and we also know which bone combination structure to use, so we can fetch the bone matrix indices it uses. We set up a loop to loop through each element in the BoneID array. This will be a maximum of four in the non-indexed case, but may be less if the hardware does not support all four matrix slots. This value will be stored in our mesh container’s InfluenceCount member as in the indexed case. In the non-indexed case, this value actually contains the total number of bones that influence a given subset, but is pretty much the same thing as far as determining the size of the palette being used is concerned.

As discussed earlier, in the non-indexed case we do not have matrix indices in the vertices to worry about, so we can set the D3DRS_VERTEXBLEND render state on a per-subset level so that we do not unnecessarily blend using matrices that have zero weights defined in the vertex. However, in order to perform this optimization, we must know how many matrices this subset uses (among all its vertices). In the following loop, we simply test each BoneId element for this subset to see if a valid BoneId is stored there. Each time we find one, we set the local variable MaxBoneIndex equal to loop variable ‘j’. At the end of this loop, MaxBoneIndex will contain a value between 0 and 3 describing the highest matrix index that influences this subset. If this was 2 for example, then we know that we can set the D3DRS_VERTEXBLEND render state to process only 1 weight (the second weight is calculated by the pipeline). This would save us having to incorporate matrices 2 and 3 into the calculation unnecessarily as their contribution would have zero weight anyway. Remember, without doing this step, if one vertex in the mesh was influenced by four bones, but all the rest were influenced by only one, we would multi-matrix transform every vertex in the mesh using four matrices, even if those matrices contribute nothing.

// First calculate the world matrices
for ( j = 0; j <= MaxBoneIndex; ++j )
// Get the index
MatrixIndex = pBoneComb[ iAttribID ].BoneId[j];

// If it's valid, set this index entry
if ( MatrixIndex != UINT_MAX )
// Generate the final matrix
D3DXMatrixMultiply( &mtxEntry,
&pContainer->pBoneOffset[ MatrixIndex ], pContainer->ppBoneMatrices[ MatrixIndex ] );

At this point the device has been assigned all the matrices needed to transform and render this subset. We will now set the vertex blend render state to process MaxBoneIndex weights and finally draw the actual subset using CTriMesh::DrawSubset.

// Set the blending count to however many are required / in use m_pD3DDevice->SetRenderState( D3DRS_VERTEXBLEND, MaxBoneIndex );

// Disable software processing if it was enabled
if ( pContainer->SWRemapBegin < pContainer->AttribGroupCount ) m_pD3DDevice->SetSoftwareVertexProcessing( FALSE );

} // End if Non-Indexed

3)Pass the combined matrices and both vertex buffers into the ID3DXSkinInfo::UpdateSkinnedMesh function. On function return, the destination mesh will contain world space geometry that has been calculated using multi-matrix transformations.

4)Set the device world matrix to an identity matrix (destination mesh already in world space )

How It Works
Login account
Login Your Account
Add to cart
Add to Cart
Make payment
Document download
Download File
PageId: ELIAC64F16
Uploaded by :
Page 1 Preview
set the local variable maxboneindex equal loop var
Sell Your Old Documents & Earn Wallet Balance