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

Method importerMatTest

test/unit/utglTF2ImportExport.cpp:64–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62class utglTF2ImportExport : public AbstractImportExportBase {
63public:
64 virtual bool importerMatTest(const char *file, bool spec, bool gloss, std::array<aiTextureMapMode, 2> exp_modes = { aiTextureMapMode_Wrap, aiTextureMapMode_Wrap }) {
65 Assimp::Importer importer;
66 const aiScene *scene = importer.ReadFile(file, aiProcess_ValidateDataStructure);
67 EXPECT_NE(scene, nullptr);
68 if (!scene) {
69 return false;
70 }
71
72 EXPECT_TRUE(scene->HasMaterials());
73 if (!scene->HasMaterials()) {
74 return false;
75 }
76 const aiMaterial *material = scene->mMaterials[0];
77
78 // This Material should be a PBR
79 aiShadingMode shadingMode;
80 EXPECT_EQ(aiReturn_SUCCESS, material->Get(AI_MATKEY_SHADING_MODEL, shadingMode));
81 EXPECT_EQ(aiShadingMode_PBR_BRDF, shadingMode);
82
83 // Should import the texture as diffuse and as base color
84 aiString path;
85 std::array<aiTextureMapMode,2> modes;
86 EXPECT_EQ(aiReturn_SUCCESS, material->GetTexture(aiTextureType_DIFFUSE, 0, &path, nullptr, nullptr,
87 nullptr, nullptr, modes.data()));
88 EXPECT_STREQ(path.C_Str(), "CesiumLogoFlat.png");
89 EXPECT_EQ(exp_modes, modes);
90
91 // Also as Base Color
92 EXPECT_EQ(aiReturn_SUCCESS, material->GetTexture(aiTextureType_BASE_COLOR, 0, &path, nullptr, nullptr,
93 nullptr, nullptr, modes.data()));
94 EXPECT_STREQ(path.C_Str(), "CesiumLogoFlat.png");
95 EXPECT_EQ(exp_modes, modes);
96
97 // Should have a MetallicFactor (default is 1.0)
98 ai_real metal_factor = ai_real(0.5);
99 EXPECT_EQ(aiReturn_SUCCESS, material->Get(AI_MATKEY_METALLIC_FACTOR, metal_factor));
100 EXPECT_EQ(ai_real(0.0), metal_factor);
101
102 // And a roughness factor (default is 1.0)
103 ai_real roughness_factor = ai_real(0.5);
104 EXPECT_EQ(aiReturn_SUCCESS, material->Get(AI_MATKEY_ROUGHNESS_FACTOR, roughness_factor));
105 EXPECT_EQ(ai_real(1.0), roughness_factor);
106
107 aiColor3D spec_color = { 0, 0, 0 };
108 ai_real glossiness = ai_real(0.5);
109 if (spec) {
110 EXPECT_EQ(aiReturn_SUCCESS, material->Get(AI_MATKEY_COLOR_SPECULAR, spec_color));
111 constexpr ai_real spec_val(0.20000000298023225); // From the file
112 EXPECT_EQ(spec_val, spec_color.r);
113 EXPECT_EQ(spec_val, spec_color.g);
114 EXPECT_EQ(spec_val, spec_color.b);
115 } else {
116 EXPECT_EQ(aiReturn_FAILURE, material->Get(AI_MATKEY_COLOR_SPECULAR, spec_color));
117 }
118 if (gloss) {
119 EXPECT_EQ(aiReturn_SUCCESS, material->Get(AI_MATKEY_GLOSSINESS_FACTOR, glossiness));
120 EXPECT_EQ(ai_real(1.0), glossiness);
121 } else {

Callers

nothing calls this directly

Calls 5

C_StrMethod · 0.80
ReadFileMethod · 0.45
GetMethod · 0.45
GetTextureMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected