------------------------------------------------------------------------------
| 106 | |
| 107 | //------------------------------------------------------------------------------ |
| 108 | void AddMaterialToFieldData(int materialId, vtkSmartPointer<vtkFieldData> fieldData, |
| 109 | const vtkGLTFDocumentLoader::Model& model) |
| 110 | { |
| 111 | int nbTextures = static_cast<int>(model.Textures.size()); |
| 112 | |
| 113 | // Append material information (multiplier, texture indices, and texture coordinate array name) |
| 114 | if (materialId >= 0 && materialId < static_cast<int>(model.Materials.size())) |
| 115 | { |
| 116 | auto material = model.Materials[materialId]; |
| 117 | auto pbr = material.PbrMetallicRoughness; |
| 118 | if (pbr.BaseColorTexture.Index >= 0 && pbr.BaseColorTexture.Index < nbTextures) |
| 119 | { |
| 120 | AddTextureInfoToFieldData( |
| 121 | "BaseColor", pbr.BaseColorTexture.Index, pbr.BaseColorTexture.TexCoord, fieldData); |
| 122 | } |
| 123 | std::vector<float> multiplier(4, 1.0); |
| 124 | if (pbr.BaseColorFactor.size() == 3 || pbr.BaseColorFactor.size() == 4) |
| 125 | { |
| 126 | multiplier = std::vector<float>{ pbr.BaseColorFactor.begin(), pbr.BaseColorFactor.end() }; |
| 127 | } |
| 128 | AddVecNfToFieldData("BaseColorMultiplier", multiplier, fieldData); |
| 129 | if (pbr.MetallicRoughnessTexture.Index >= 0 && pbr.MetallicRoughnessTexture.Index < nbTextures) |
| 130 | { |
| 131 | AddTextureInfoToFieldData("MetallicRoughness", pbr.MetallicRoughnessTexture.Index, |
| 132 | pbr.MetallicRoughnessTexture.TexCoord, fieldData); |
| 133 | } |
| 134 | multiplier = std::vector<float>{ 0, pbr.MetallicFactor, pbr.RoughnessFactor }; |
| 135 | AddVecNfToFieldData("MetallicRoughness", multiplier, fieldData); |
| 136 | if (material.NormalTexture.Index >= 0 && material.NormalTexture.Index < nbTextures) |
| 137 | { |
| 138 | AddTextureInfoToFieldData("Normal", material.NormalTexture.Index, |
| 139 | material.NormalTexture.TexCoord, fieldData, |
| 140 | std::vector<float>(3, material.NormalTextureScale)); |
| 141 | } |
| 142 | if (material.OcclusionTexture.Index >= 0 && material.OcclusionTexture.Index < nbTextures) |
| 143 | { |
| 144 | AddTextureInfoToFieldData("Occlusion", material.OcclusionTexture.Index, |
| 145 | material.OcclusionTexture.TexCoord, fieldData, |
| 146 | std::vector<float>(3, material.OcclusionTextureStrength)); |
| 147 | } |
| 148 | if (material.EmissiveTexture.Index >= 0 && material.EmissiveTexture.Index < nbTextures) |
| 149 | { |
| 150 | AddTextureInfoToFieldData("Emissive", material.EmissiveTexture.Index, |
| 151 | material.EmissiveTexture.TexCoord, fieldData, |
| 152 | std::vector<float>{ material.EmissiveFactor.begin(), material.EmissiveFactor.end() }); |
| 153 | } |
| 154 | // Add alpha cutoff value, alpha mode |
| 155 | if (material.AlphaMode == vtkGLTFDocumentLoader::Material::AlphaModeType::MASK) |
| 156 | { |
| 157 | AddFloatToFieldData("AlphaCutoff", material.AlphaCutoff, fieldData); |
| 158 | } |
| 159 | else if (material.AlphaMode == vtkGLTFDocumentLoader::Material::AlphaModeType::OPAQUE) |
| 160 | { |
| 161 | AddIntegerToFieldData("ForceOpaque", 1, fieldData); |
| 162 | } |
| 163 | } |
| 164 | else |
| 165 | { |
no test coverage detected