| 164 | } |
| 165 | |
| 166 | bool Tr2MeshBase::BindToRig( const std::string* boneList, const int numBones, TriGeometryResSkeletonData* renderRig, bool forceRebind ) |
| 167 | { |
| 168 | CCP_STATS_ZONE( "Tr2Mesh::BindToRig" ); |
| 169 | |
| 170 | CCP_STATS_INC( tr2MeshBindToRig ); |
| 171 | |
| 172 | forceRebind |= m_forcedRebind; |
| 173 | m_forcedRebind = false; |
| 174 | |
| 175 | if( !GetGeometryResource() || !GetGeometryResource()->IsPrepared() ) |
| 176 | { |
| 177 | return false; |
| 178 | } |
| 179 | |
| 180 | if( ( m_pBoneList == boneList ) && ( m_renderRig == renderRig ) && ( m_numBones == numBones ) && !forceRebind ) |
| 181 | { |
| 182 | return true; |
| 183 | } |
| 184 | |
| 185 | TriGeometryResMeshData* meshData = GetGeometryResource()->GetMeshData( m_meshIndex ); |
| 186 | if( !meshData ) |
| 187 | { |
| 188 | // resource is prepard but mesh doesn't exist, this can happen for ragdoll dummy boxshapes. |
| 189 | // don't trigger continuous rebindings, return true. |
| 190 | return true; |
| 191 | } |
| 192 | |
| 193 | // keep this array here as member |
| 194 | unsigned int n = (unsigned int)meshData->m_jointBindings.size(); |
| 195 | m_jointMappingAnimRig.resize( n ); |
| 196 | |
| 197 | for( unsigned int j = 0; j < m_jointMappingAnimRig.size(); ++j ) |
| 198 | { |
| 199 | const char* name = meshData->m_jointBindings[j].m_name.c_str(); |
| 200 | |
| 201 | m_jointMappingAnimRig[j] = FindJoint( boneList, numBones, name ); |
| 202 | |
| 203 | while( m_jointMappingAnimRig[j] == 0xffffffff ) |
| 204 | { |
| 205 | unsigned int renderIndex = renderRig->FindJoint( name ); |
| 206 | if( renderIndex != 0xffffffff ) |
| 207 | { |
| 208 | unsigned int parentIndex = renderRig->m_joints[renderIndex].m_parentJoint; |
| 209 | if( parentIndex != 0xffffffff ) |
| 210 | { |
| 211 | const char* parentName = renderRig->m_joints[parentIndex].m_name.c_str(); |
| 212 | m_jointMappingAnimRig[j] = FindJoint( boneList, numBones, parentName ); |
| 213 | name = parentName; |
| 214 | } |
| 215 | else |
| 216 | { |
| 217 | CCP_LOGWARN( "Resource %s - attempted to bind a joint that was not found on the render rig: %s", meshData->m_name.c_str(), name ); |
| 218 | break; |
| 219 | } |
| 220 | } |
| 221 | else |
| 222 | { |
| 223 | CCP_LOGWARN( "Resource %s - attempted to bind a joint that was not found on the render rig: %s", meshData->m_name.c_str(), name ); |
no test coverage detected