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

Function WriteMaterial

IO/Geometry/vtkGLTFWriter.cxx:805–831  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

803}
804
805void WriteMaterial(
806 vtkPolyData* pd, nlohmann::json& materials, size_t textureIndex, bool haveTexture)
807{
808 nlohmann::json mat;
809 nlohmann::json model;
810
811 if (haveTexture)
812 {
813 nlohmann::json tex;
814 tex["texCoord"] = 0; // TEXCOORD_0
815 tex["index"] = textureIndex;
816 model["baseColorTexture"] = tex;
817 }
818
819 std::vector<float> dcolor = GetFieldAsFloat(pd, "diffuse_color", { 1, 1, 1 });
820 std::vector<float> scolor = GetFieldAsFloat(pd, "specular_color", { 0, 0, 0 });
821 float transparency = GetFieldAsFloat(pd, "transparency", { 0 })[0];
822 float shininess = GetFieldAsFloat(pd, "shininess", { 0 })[0];
823 model["baseColorFactor"].emplace_back(dcolor[0]);
824 model["baseColorFactor"].emplace_back(dcolor[1]);
825 model["baseColorFactor"].emplace_back(dcolor[2]);
826 model["baseColorFactor"].emplace_back(1 - transparency);
827 model["metallicFactor"] = shininess;
828 model["roughnessFactor"] = 1.0;
829 mat["pbrMetallicRoughness"] = model;
830 materials.emplace_back(mat);
831}
832}
833
834std::vector<std::string> vtkGLTFWriter::GetFieldAsStringVector(vtkDataObject* obj, const char* name)

Callers 1

Calls 2

GetFieldAsFloatFunction · 0.85
emplace_backMethod · 0.45

Tested by

no test coverage detected