------------------------------------------------------------------------------
| 479 | |
| 480 | //------------------------------------------------------------------------------ |
| 481 | bool BuildMultiBlockDataSetFromNode(vtkGLTFDocumentLoader::Model& m, unsigned int nodeId, |
| 482 | vtkSmartPointer<vtkMultiBlockDataSet> parentDataSet, |
| 483 | vtkSmartPointer<vtkMultiBlockDataSet> nodeDataset, std::string nodeName, bool applyDeformations, |
| 484 | int outputPointsPrecision) |
| 485 | { |
| 486 | if (nodeId >= m.Nodes.size()) |
| 487 | { |
| 488 | vtkErrorWithObjectMacro(nullptr, "Invalid node index " << nodeId); |
| 489 | return false; |
| 490 | } |
| 491 | bool createNewBlocks = false; |
| 492 | // If nodeDataset is not defined, create it and append it to the parent dataset |
| 493 | if (!nodeDataset) |
| 494 | { |
| 495 | createNewBlocks = true; |
| 496 | nodeDataset = vtkSmartPointer<vtkMultiBlockDataSet>::New(); |
| 497 | parentDataSet->SetBlock(parentDataSet->GetNumberOfBlocks(), nodeDataset); |
| 498 | parentDataSet->GetMetaData(parentDataSet->GetNumberOfBlocks() - 1) |
| 499 | ->Set(vtkCompositeDataSet::NAME(), nodeName); |
| 500 | } |
| 501 | |
| 502 | vtkGLTFDocumentLoader::Node node = m.Nodes[nodeId]; |
| 503 | int blockId = 0; |
| 504 | if (node.Mesh >= 0) |
| 505 | { |
| 506 | std::vector<vtkSmartPointer<vtkMatrix4x4>> jointMats; |
| 507 | |
| 508 | if (node.Skin >= 0) |
| 509 | { |
| 510 | // Compute skinning matrices |
| 511 | const vtkGLTFDocumentLoader::Skin& skin = m.Skins[node.Skin]; |
| 512 | vtkGLTFDocumentLoader::ComputeJointMatrices(m, skin, node, jointMats); |
| 513 | } |
| 514 | |
| 515 | std::vector<float>* morphingWeights = nullptr; |
| 516 | if (!node.Weights.empty()) |
| 517 | { |
| 518 | morphingWeights = &(node.Weights); |
| 519 | } |
| 520 | else if (!node.InitialWeights.empty()) |
| 521 | { |
| 522 | morphingWeights = &(node.InitialWeights); |
| 523 | } |
| 524 | |
| 525 | vtkSmartPointer<vtkMultiBlockDataSet> meshDataSet = nullptr; |
| 526 | if (!createNewBlocks) |
| 527 | { |
| 528 | meshDataSet = vtkMultiBlockDataSet::SafeDownCast(nodeDataset->GetBlock(blockId)); |
| 529 | } |
| 530 | std::string meshDatasetName = "Mesh_" + vtk::to_string(node.Mesh); |
| 531 | if (!BuildMultiBlockDatasetFromMesh(m, node.Mesh, nodeDataset, meshDataSet, meshDatasetName, |
| 532 | node.GlobalTransform, jointMats, applyDeformations, morphingWeights, |
| 533 | outputPointsPrecision)) |
| 534 | { |
| 535 | vtkErrorWithObjectMacro( |
| 536 | nullptr, "Could not build vtkMultiBlockDataSet from mesh " << node.Mesh); |
| 537 | return false; |
| 538 | } |
no test coverage detected