------------------------------------------------------------------------------
| 649 | |
| 650 | //------------------------------------------------------------------------------ |
| 651 | bool vtkGLTFDocumentLoaderInternals::LoadMaterial( |
| 652 | const nlohmann::json& root, vtkGLTFDocumentLoader::Material& material) |
| 653 | { |
| 654 | double metallicFactor = 1; |
| 655 | double roughnessFactor = 1; |
| 656 | |
| 657 | const auto& pbrRoot = root.value("pbrMetallicRoughness", nlohmann::json::object()); |
| 658 | if (!pbrRoot.empty()) |
| 659 | { |
| 660 | if (vtkGLTFUtils::GetDoubleValue(pbrRoot, "metallicFactor", metallicFactor)) |
| 661 | { |
| 662 | if (metallicFactor < 0 || metallicFactor > 1) |
| 663 | { |
| 664 | vtkWarningWithObjectMacro(this->Self, |
| 665 | "Invalid material.pbrMetallicRoughness.metallicFactor value. Using default " |
| 666 | "value instead."); |
| 667 | metallicFactor = 1; |
| 668 | } |
| 669 | } |
| 670 | if (vtkGLTFUtils::GetDoubleValue(pbrRoot, "roughnessFactor", roughnessFactor)) |
| 671 | { |
| 672 | if (roughnessFactor < 0 || roughnessFactor > 1) |
| 673 | { |
| 674 | vtkWarningWithObjectMacro(this->Self, |
| 675 | "Invalid material.pbrMetallicRoughness.roughnessFactor value. Using default" |
| 676 | " value instead."); |
| 677 | roughnessFactor = 1; |
| 678 | } |
| 679 | } |
| 680 | auto pbrRootBaseColorTextureIt = pbrRoot.find("baseColorTexture"); |
| 681 | if (pbrRootBaseColorTextureIt != pbrRoot.end()) |
| 682 | { |
| 683 | this->LoadTextureInfo( |
| 684 | pbrRootBaseColorTextureIt.value(), material.PbrMetallicRoughness.BaseColorTexture); |
| 685 | } |
| 686 | auto pbrRootMetallicRoughnessTextureIt = pbrRoot.find("metallicRoughnessTexture"); |
| 687 | if (pbrRootMetallicRoughnessTextureIt != pbrRoot.end()) |
| 688 | { |
| 689 | this->LoadTextureInfo(pbrRootMetallicRoughnessTextureIt.value(), |
| 690 | material.PbrMetallicRoughness.MetallicRoughnessTexture); |
| 691 | } |
| 692 | vtkGLTFUtils::GetDoubleArray( |
| 693 | pbrRoot, "baseColorFactor", material.PbrMetallicRoughness.BaseColorFactor); |
| 694 | } |
| 695 | if (material.PbrMetallicRoughness.BaseColorFactor.size() != |
| 696 | vtkGLTFDocumentLoader::GetNumberOfComponentsForType(vtkGLTFDocumentLoader::AccessorType::VEC4)) |
| 697 | { |
| 698 | material.PbrMetallicRoughness.BaseColorFactor.clear(); |
| 699 | } |
| 700 | if (material.PbrMetallicRoughness.BaseColorFactor.empty()) |
| 701 | { |
| 702 | material.PbrMetallicRoughness.BaseColorFactor.insert( |
| 703 | material.PbrMetallicRoughness.BaseColorFactor.end(), { 1, 1, 1, 1 }); |
| 704 | } |
| 705 | material.PbrMetallicRoughness.MetallicFactor = metallicFactor; |
| 706 | material.PbrMetallicRoughness.RoughnessFactor = roughnessFactor; |
| 707 | auto rootNormalTextureIt = root.find("normalTexture"); |
| 708 | if (rootNormalTextureIt != root.end()) |
no test coverage detected