MCPcopy Create free account
hub / github.com/assimp/assimp / WriteMaterial

Method WriteMaterial

code/Pbrt/PbrtExporter.cpp:605–682  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

603}
604
605void PbrtExporter::WriteMaterial(int m) {
606 aiMaterial* material = mScene->mMaterials[m];
607
608 // get material name
609 auto materialName = material->GetName();
610 mOutput << std::endl << "# - Material " << m+1 << ": " << materialName.C_Str() << "\n";
611
612 // Print out number of properties
613 mOutput << "# - Number of Material Properties: " << material->mNumProperties << "\n";
614
615 // Print out texture type counts
616 mOutput << "# - Non-Zero Texture Type Counts: ";
617 for (int i = 1; i <= aiTextureType_UNKNOWN; i++) {
618 int count = material->GetTextureCount(aiTextureType(i));
619 if (count > 0)
620 mOutput << aiTextureTypeToString(aiTextureType(i)) << ": " << count << " ";
621 }
622 mOutput << "\n";
623
624 auto White = [](const aiColor3D &c) { return c.r == 1 && c.g == 1 && c.b == 1; };
625 auto Black = [](const aiColor3D &c) { return c.r == 0 && c.g == 0 && c.b == 0; };
626
627 aiColor3D diffuse, specular, transparency;
628 bool constantDiffuse = (material->Get(AI_MATKEY_COLOR_DIFFUSE, diffuse) == AI_SUCCESS &&
629 !White(diffuse));
630 bool constantSpecular = (material->Get(AI_MATKEY_COLOR_SPECULAR, specular) == AI_SUCCESS &&
631 !White(specular));
632 bool constantTransparency = (material->Get(AI_MATKEY_COLOR_TRANSPARENT, transparency) == AI_SUCCESS &&
633 !Black(transparency));
634
635 float opacity, shininess, shininessStrength, eta;
636 bool constantOpacity = (material->Get(AI_MATKEY_OPACITY, opacity) == AI_SUCCESS &&
637 opacity != 0);
638 bool constantShininess = material->Get(AI_MATKEY_SHININESS, shininess) == AI_SUCCESS;
639 bool constantShininessStrength = material->Get(AI_MATKEY_SHININESS_STRENGTH, shininessStrength) == AI_SUCCESS;
640 bool constantEta = (material->Get(AI_MATKEY_REFRACTI, eta) == AI_SUCCESS &&
641 eta != 1);
642
643 mOutput << "# - Constants: diffuse " << constantDiffuse << " specular " << constantSpecular <<
644 " transparency " << constantTransparency << " opacity " << constantOpacity <<
645 " shininess " << constantShininess << " shininess strength " << constantShininessStrength <<
646 " eta " << constantEta << "\n";
647
648 aiString roughnessMap;
649 if (material->Get(AI_MATKEY_TEXTURE_SHININESS(0), roughnessMap) == AI_SUCCESS) {
650 std::string roughnessTexture = std::string("float:") +
651 RemoveSuffix(CleanTextureFilename(roughnessMap)) + "_Roughness";
652 mOutput << "MakeNamedMaterial \"" << materialName.C_Str() << "\""
653 << " \"string type\" \"coateddiffuse\"\n"
654 << " \"texture roughness\" \"" << roughnessTexture << "\"\n";
655 } else if (constantShininess) {
656 // Assume plastic for now at least
657 float roughness = std::max(0.f, 1.f - shininess);
658 mOutput << "MakeNamedMaterial \"" << materialName.C_Str() << "\""
659 << " \"string type\" \"coateddiffuse\"\n"
660 << " \"float roughness\" " << roughness << "\n";
661 } else
662 // Diffuse

Callers

nothing calls this directly

Calls 6

aiTextureTypeEnum · 0.85
aiTextureTypeToStringFunction · 0.85
C_StrMethod · 0.80
maxFunction · 0.50
GetNameMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected