MCPcopy Create free account
hub / github.com/Kitware/VTK / ExtractPrimitiveAttributes

Method ExtractPrimitiveAttributes

IO/Geometry/vtkGLTFDocumentLoader.cxx:680–748  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

678
679//------------------------------------------------------------------------------
680bool vtkGLTFDocumentLoader::ExtractPrimitiveAttributes(Primitive& primitive)
681{
682 AccessorLoadingWorker worker;
683 worker.Accessors = &(this->InternalModel->Accessors);
684 worker.BufferViews = &(this->InternalModel->BufferViews);
685 worker.Buffers = &(this->InternalModel->Buffers);
686 using AttributeArrayTypes =
687 vtkTypeList::Create<vtkFloatArray, vtkIntArray, vtkUnsignedShortArray>;
688
689 // Load all attributes
690 for (auto& attributePair : primitive.AttributeIndices)
691 {
692 Accessor accessor = this->InternalModel->Accessors[attributePair.second];
693 // Create array
694 if (attributePair.first == "JOINTS_0")
695 {
696 primitive.AttributeValues[attributePair.first] =
697 vtkSmartPointer<vtkUnsignedShortArray>::New();
698 }
699 else
700 {
701 primitive.AttributeValues[attributePair.first] = vtkSmartPointer<vtkFloatArray>::New();
702 }
703
704 worker.NormalizeTuples = attributePair.first == "WEIGHTS_0";
705 worker.LoadTangents = attributePair.first == "TANGENT";
706
707 // Read data
708 worker.Setup(attributePair.second, accessor.Type);
709 vtkArrayDispatch::DispatchByArray<AttributeArrayTypes>::Execute(
710 primitive.AttributeValues[attributePair.first], worker);
711
712 if (!worker.Result)
713 {
714 vtkErrorMacro("Error loading mesh.primitive attribute '" << attributePair.first << "'");
715 return false;
716 }
717 }
718
719 worker.NormalizeTuples = false;
720 worker.LoadTangents = false;
721
722 // Load morph targets
723 for (auto& target : primitive.Targets)
724 {
725 for (auto& attributePair : target.AttributeIndices)
726 {
727 if (attributePair.first != "POSITION" && attributePair.first != "NORMAL" &&
728 attributePair.first != "TANGENT")
729 {
730 vtkWarningMacro(
731 "Invalid attribute name for morph target: " << attributePair.first << " ignoring.");
732 continue;
733 }
734 Accessor accessor = this->InternalModel->Accessors[attributePair.second];
735 target.AttributeValues[attributePair.first] = vtkSmartPointer<vtkFloatArray>::New();
736 worker.Setup(attributePair.second, accessor.Type);
737 vtkArrayDispatch::DispatchByArray<AttributeArrayTypes>::Execute(

Callers 1

Calls 3

SetupMethod · 0.80
NewFunction · 0.50
ExecuteFunction · 0.50

Tested by

no test coverage detected