void Skeleton::addWeight( unsigned int vertexIdx, const std::string& boneId, float weight ) { // make sure the vertex we're trying to describe is in our array while ( vertexIdx >= m_weights.size() ) { m_weights.push_back( VertexWeight() ); } // find the index assigned to the specified bone int boneIdx = getBoneIndex( boneId ); if ( boneIdx < 0 ) { boneIdx = m_boneNames.size(); m_boneNames.push_back( boneId ); } // find the next index to fill in unsigned int nextIdx = 0; for ( nextIdx = 0; nextIdx < 4; ++nextIdx ) { if ( m_weights[ vertexIdx ].m_indices[ nextIdx ] < 0 ) { break; } } ASSERT_MSG( nextIdx < 4, "Too many skin weights assigned" ); m_weights[ vertexIdx ].m_weights[ nextIdx ] = weight; m_weights[ vertexIdx ].m_indices[ nextIdx ] = (float)boneIdx; }
BoneWeights::BoneWeights( const NifModel * nif, const QModelIndex & index, int b, int vcnt ) { trans = Transform( nif, index ); center = nif->get<Vector3>( index, "Center" ); radius = nif->get<float>( index, "Radius" ); bone = b; QModelIndex idxWeights = nif->getIndex( index, "Vertex Weights" ); if ( idxWeights.isValid() ) { for ( int c = 0; c < nif->rowCount( idxWeights ); c++ ) { QModelIndex idx = idxWeights.child( c, 0 ); weights.append( VertexWeight( nif->get<int>( idx, "Index" ), nif->get<float>( idx, "Weight" ) ) ); } } else // create artificial ones, TODO: should they weight nothing* instead? for ( int c = 0; c < vcnt; c++ ) weights.append( VertexWeight( c, 1.0f ) ); }