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

Method LoadMaterial

IO/Geometry/vtkGLTFDocumentLoaderInternals.cxx:651–766  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

649
650//------------------------------------------------------------------------------
651bool 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())

Callers 1

LoadModelMetaDataMethod · 0.95

Calls 14

LoadTextureInfoMethod · 0.95
objectClass · 0.85
GetDoubleValueFunction · 0.70
GetDoubleArrayFunction · 0.70
GetStringValueFunction · 0.70
GetBoolValueFunction · 0.70
valueMethod · 0.45
emptyMethod · 0.45
findMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected