From cd7ec515ba54e7267926c482ee28093305a7a48d Mon Sep 17 00:00:00 2001 From: kaetemi Date: Mon, 21 Sep 2015 15:53:12 +0200 Subject: [PATCH] Adjust material import --- .../tools/3d/mesh_utils/assimp_material.cpp | 40 ++++++++----------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/code/nel/tools/3d/mesh_utils/assimp_material.cpp b/code/nel/tools/3d/mesh_utils/assimp_material.cpp index b542ada14..b2fd78868 100644 --- a/code/nel/tools/3d/mesh_utils/assimp_material.cpp +++ b/code/nel/tools/3d/mesh_utils/assimp_material.cpp @@ -38,7 +38,7 @@ using namespace NL3D; // http://assimp.sourceforge.net/lib_html/materials.html -inline CRGBA convColor(const aiColor3D &ac) +inline CRGBA convColor(const aiColor3D &ac, uint8 a = 255) { return CRGBA(ac.r * 255.99f, ac.g * 255.99f, ac.b * 255.99f); } @@ -73,35 +73,29 @@ void assimpMaterial(NL3D::CMaterial &mat, CMeshUtilsContext &context, const aiMa break; } + // Colors follow GL convention + // "While the ambient, diffuse, specular and emission + // "material parameters all have alpha components, only the diffuse" + // "alpha component is used in the lighting computation." + if (am->Get(AI_MATKEY_COLOR_DIFFUSE, c3) == aiReturn_SUCCESS) + mat.setDiffuse(convColor(c3)); + if (am->Get(AI_MATKEY_OPACITY, f) == aiReturn_SUCCESS) mat.setOpacity(f * 255.99f); - if (am->Get(AI_MATKEY_SHININESS, f) == aiReturn_SUCCESS) - mat.setShininess(f); // OR (float)pow(2.0, shininess * 10.0) * 4.f ?? - - if (am->Get(AI_MATKEY_COLOR_DIFFUSE, c3) == aiReturn_SUCCESS) - { - CRGBA diffuse = convColor(c3); - diffuse.A = mat.getOpacity(); - mat.setDiffuse(diffuse); - } - if (am->Get(AI_MATKEY_COLOR_AMBIENT, c3) == aiReturn_SUCCESS) mat.setAmbient(convColor(c3)); + if (am->Get(AI_MATKEY_SHININESS, f) == aiReturn_SUCCESS) + mat.setShininess(f); // (float)pow(2.0, f * 10.0) * 4.f; + if (am->Get(AI_MATKEY_COLOR_SPECULAR, c3) == aiReturn_SUCCESS) - { - CRGBA specular = convColor(c3); - if (am->Get(AI_MATKEY_SHININESS_STRENGTH, f) == aiReturn_SUCCESS) - { - CRGBAF fColor = specular; - fColor *= f; - uint8 a = specular.A; - specular = fColor; - specular.A = a; - } - mat.setSpecular(specular); - } + mat.setSpecular(convColor(c3)); + + if (am->Get(AI_MATKEY_SHININESS_STRENGTH, f) == aiReturn_SUCCESS) + mat.setSpecular(CRGBAF(mat.getSpecular()) * f); + else + mat.setSpecular(NLMISC::CRGBA::Black); if (am->Get(AI_MATKEY_COLOR_EMISSIVE, c3) == aiReturn_SUCCESS) mat.setEmissive(convColor(c3));