------------------------------------------------------------------------------
| 594 | |
| 595 | //------------------------------------------------------------------------------ |
| 596 | bool vtkGLTFDocumentLoader::ExtractPrimitiveAccessorData(Primitive& primitive) |
| 597 | { |
| 598 | // Load connectivity |
| 599 | if (primitive.IndicesId >= 0) |
| 600 | { |
| 601 | // Load indices |
| 602 | if (primitive.IndicesId >= static_cast<int>(this->InternalModel->Accessors.size())) |
| 603 | { |
| 604 | vtkErrorMacro("Invalid indices id for primitive"); |
| 605 | return false; |
| 606 | } |
| 607 | auto accessor = this->InternalModel->Accessors[primitive.IndicesId]; |
| 608 | auto bufferView = this->InternalModel->BufferViews[accessor.BufferView]; |
| 609 | |
| 610 | if (accessor.Type != AccessorType::SCALAR) |
| 611 | { |
| 612 | vtkErrorMacro( |
| 613 | "Invalid accessor.type value for primitive connectivity loading. Expected 'SCALAR'"); |
| 614 | return false; |
| 615 | } |
| 616 | auto& buffer = this->InternalModel->Buffers[bufferView.Buffer]; |
| 617 | |
| 618 | primitive.Indices = vtkSmartPointer<vtkCellArray>::New(); |
| 619 | unsigned int byteOffset = accessor.ByteOffset + bufferView.ByteOffset; |
| 620 | |
| 621 | switch (accessor.ComponentTypeValue) |
| 622 | { |
| 623 | case ComponentType::UNSIGNED_BYTE: |
| 624 | ExtractAndCastCellBufferData<uint8_t>(buffer, primitive.Indices, byteOffset, |
| 625 | bufferView.ByteStride, accessor.Count, primitive.CellSize, primitive.Mode); |
| 626 | break; |
| 627 | case ComponentType::UNSIGNED_SHORT: |
| 628 | ExtractAndCastCellBufferData<uint16_t>(buffer, primitive.Indices, byteOffset, |
| 629 | bufferView.ByteStride, accessor.Count, primitive.CellSize, primitive.Mode); |
| 630 | break; |
| 631 | case ComponentType::UNSIGNED_INT: |
| 632 | ExtractAndCastCellBufferData<uint32_t>(buffer, primitive.Indices, byteOffset, |
| 633 | bufferView.ByteStride, accessor.Count, primitive.CellSize, primitive.Mode); |
| 634 | break; |
| 635 | default: |
| 636 | vtkErrorMacro("Invalid accessor.componentType for primitive connectivity. Expected either " |
| 637 | "GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT or GL_UNSIGNED_INT."); |
| 638 | return false; |
| 639 | } |
| 640 | } |
| 641 | else |
| 642 | { |
| 643 | primitive.Indices = nullptr; |
| 644 | } |
| 645 | |
| 646 | if (!this->ExtractPrimitiveAttributes(primitive)) |
| 647 | { |
| 648 | vtkErrorMacro("Error loading mesh.primitive.attributes"); |
| 649 | return false; |
| 650 | } |
| 651 | if ((primitive.Indices != nullptr) && (!primitive.AttributeValues.empty())) |
| 652 | { |
| 653 | /* Get the elements count of the first associated accessor */ |
no test coverage detected