------------------------------------------------------------------------------
| 955 | |
| 956 | //------------------------------------------------------------------------------ |
| 957 | bool vtkGLTFDocumentLoader::LoadSkinMatrixData() |
| 958 | { |
| 959 | if (!this->LoadSkinMatrix) |
| 960 | { |
| 961 | // Skip loading the skin bind matrices |
| 962 | return true; |
| 963 | } |
| 964 | AccessorLoadingWorker worker; |
| 965 | worker.Accessors = &(this->InternalModel->Accessors); |
| 966 | worker.BufferViews = &(this->InternalModel->BufferViews); |
| 967 | worker.Buffers = &(this->InternalModel->Buffers); |
| 968 | |
| 969 | using AttributeArrayTypes = vtkTypeList::Create<vtkFloatArray, vtkIntArray>; |
| 970 | |
| 971 | for (Skin& skin : this->InternalModel->Skins) |
| 972 | { |
| 973 | if (skin.InverseBindMatricesAccessorId < 0) |
| 974 | { |
| 975 | // Default is an identity matrix |
| 976 | vtkNew<vtkMatrix4x4> id; |
| 977 | id->Identity(); |
| 978 | skin.InverseBindMatrices.emplace_back(id); |
| 979 | continue; |
| 980 | } |
| 981 | vtkNew<vtkFloatArray> matrixValues; |
| 982 | worker.Setup(skin.InverseBindMatricesAccessorId, AccessorType::MAT4); |
| 983 | vtkArrayDispatch::DispatchByArray<AttributeArrayTypes>::Execute(matrixValues, worker); |
| 984 | |
| 985 | size_t totalNumberOfComponents = |
| 986 | skin.Joints.size() * vtkGLTFDocumentLoader::GetNumberOfComponentsForType(AccessorType::MAT4); |
| 987 | if (!worker.Result || |
| 988 | static_cast<size_t>(matrixValues->GetNumberOfValues()) != totalNumberOfComponents) |
| 989 | { |
| 990 | vtkErrorMacro("Error loading skin.invertBindMatrices data"); |
| 991 | return false; |
| 992 | } |
| 993 | |
| 994 | for (unsigned int matrixId = 0; matrixId < skin.Joints.size(); matrixId++) |
| 995 | { |
| 996 | vtkNew<vtkMatrix4x4> matrix; |
| 997 | matrix->DeepCopy(matrixValues->GetTuple(matrixId)); |
| 998 | matrix->Transpose(); |
| 999 | skin.InverseBindMatrices.emplace_back(matrix); |
| 1000 | } |
| 1001 | } |
| 1002 | return true; |
| 1003 | } |
| 1004 | |
| 1005 | //------------------------------------------------------------------------------ |
| 1006 | bool vtkGLTFDocumentLoader::LoadModelData(const std::vector<char>& glbBuffer) |
no test coverage detected