2016-05-17 19:17:51 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2022-01-10 20:13:43 +00:00
|
|
|
Copyright (c) 2006-2022, assimp team
|
2018-01-28 18:42:05 +00:00
|
|
|
|
2016-05-17 19:17:51 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
|
|
|
conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "UnitTestPCH.h"
|
|
|
|
|
|
|
|
#include <assimp/cexport.h>
|
2017-11-21 16:04:22 +00:00
|
|
|
#include <assimp/postprocess.h>
|
2020-03-22 11:13:09 +00:00
|
|
|
#include <assimp/scene.h>
|
|
|
|
#include <assimp/Importer.hpp>
|
2016-05-17 19:17:51 +00:00
|
|
|
|
|
|
|
class BlendImportMaterials : public ::testing::Test {
|
|
|
|
public:
|
2020-03-22 11:13:09 +00:00
|
|
|
void SetUp() override {
|
2016-05-17 19:17:51 +00:00
|
|
|
im = new Assimp::Importer();
|
|
|
|
}
|
|
|
|
|
2020-03-22 11:13:09 +00:00
|
|
|
void TearDown() override {
|
2016-05-17 19:17:51 +00:00
|
|
|
delete im;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2020-03-22 11:13:09 +00:00
|
|
|
Assimp::Importer *im;
|
2016-05-17 19:17:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-22 11:13:09 +00:00
|
|
|
TEST_F(BlendImportMaterials, testImportMaterial) {
|
|
|
|
const aiScene *pTest = im->ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/BlenderMaterial_269.blend", aiProcess_ValidateDataStructure);
|
2022-11-08 16:03:55 +00:00
|
|
|
ASSERT_TRUE(pTest != nullptr);
|
2016-05-17 19:17:51 +00:00
|
|
|
ASSERT_TRUE(pTest->HasMaterials());
|
|
|
|
|
2017-05-26 07:18:23 +00:00
|
|
|
ASSERT_EQ(1U, pTest->mNumMaterials);
|
2016-05-17 19:17:51 +00:00
|
|
|
|
|
|
|
auto alpha = pTest->mMaterials[0];
|
|
|
|
|
2020-03-22 11:13:09 +00:00
|
|
|
#define ASSERT_PROPERTY_EQ(expected, key, var) \
|
|
|
|
auto var = expected; \
|
|
|
|
ASSERT_EQ(aiReturn_SUCCESS, alpha->Get("$mat.blend." key, 0, 0, var)); \
|
|
|
|
ASSERT_EQ(expected, var);
|
2016-05-17 19:17:51 +00:00
|
|
|
|
2020-03-22 11:13:09 +00:00
|
|
|
#define ASSERT_PROPERTY_FLOAT_EQ(expected, key, var) \
|
|
|
|
auto var = expected; \
|
|
|
|
ASSERT_EQ(aiReturn_SUCCESS, alpha->Get("$mat.blend." key, 0, 0, var)); \
|
|
|
|
ASSERT_FLOAT_EQ(expected, var);
|
2016-05-17 19:17:51 +00:00
|
|
|
|
|
|
|
ASSERT_PROPERTY_EQ(aiColor3D(0.1f, 0.2f, 0.3f), "diffuse.color", diffuseColor);
|
|
|
|
ASSERT_PROPERTY_EQ(0.4f, "diffuse.intensity", diffuseIntensity);
|
2017-05-26 18:29:21 +00:00
|
|
|
ASSERT_PROPERTY_EQ(1, "diffuse.shader", diffuseShader);
|
|
|
|
ASSERT_PROPERTY_EQ(0, "diffuse.ramp", diffuseRamp);
|
2016-05-17 19:17:51 +00:00
|
|
|
|
|
|
|
ASSERT_PROPERTY_EQ(aiColor3D(0.5f, 0.6f, 0.7f), "specular.color", specularColor);
|
|
|
|
ASSERT_PROPERTY_EQ(0.8f, "specular.intensity", specularIntensity);
|
|
|
|
ASSERT_PROPERTY_EQ(1, "specular.shader", specularShader);
|
|
|
|
ASSERT_PROPERTY_EQ(0, "specular.ramp", specularRamp);
|
|
|
|
ASSERT_PROPERTY_EQ(9, "specular.hardness", specularHardness);
|
|
|
|
|
|
|
|
ASSERT_PROPERTY_EQ(1, "transparency.use", transparencyUse);
|
|
|
|
ASSERT_PROPERTY_EQ(2, "transparency.method", transparencyMethod);
|
|
|
|
ASSERT_PROPERTY_EQ(0.01f, "transparency.alpha", transparencyAlpha);
|
|
|
|
ASSERT_PROPERTY_EQ(0.02f, "transparency.specular", transparencySpecular);
|
|
|
|
ASSERT_PROPERTY_EQ(0.03f, "transparency.fresnel", transparencyFresnel);
|
|
|
|
ASSERT_PROPERTY_EQ(3.14f, "transparency.blend", transparencyBlend);
|
|
|
|
ASSERT_PROPERTY_EQ(0.85f, "transparency.ior", transparencyIor);
|
|
|
|
ASSERT_PROPERTY_FLOAT_EQ(0.128f, "transparency.filter", transparencyFilter);
|
|
|
|
ASSERT_PROPERTY_FLOAT_EQ(1.298f, "transparency.falloff", transparencyFalloff);
|
|
|
|
ASSERT_PROPERTY_FLOAT_EQ(0.2376f, "transparency.limit", transparencyLimit);
|
|
|
|
ASSERT_PROPERTY_EQ(7, "transparency.depth", transparencyDepth);
|
|
|
|
ASSERT_PROPERTY_FLOAT_EQ(0.678f, "transparency.glossAmount", transparencyGlossAmount);
|
|
|
|
ASSERT_PROPERTY_FLOAT_EQ(0.208f, "transparency.glossThreshold", transparencyGlossThreshold);
|
|
|
|
ASSERT_PROPERTY_EQ(17, "transparency.glossSamples", transparencyGlossSamples);
|
|
|
|
|
|
|
|
ASSERT_PROPERTY_EQ(1, "mirror.use", mirrorUse);
|
|
|
|
ASSERT_PROPERTY_FLOAT_EQ(0.28f, "mirror.reflectivity", mirrorReflectivity);
|
|
|
|
ASSERT_PROPERTY_EQ(aiColor3D(0.25f, 0.5f, 0.128f), "mirror.color", mirrorColor);
|
|
|
|
ASSERT_PROPERTY_FLOAT_EQ(0.256f, "mirror.fresnel", mirrorFresnel);
|
|
|
|
ASSERT_PROPERTY_FLOAT_EQ(1.61f, "mirror.blend", mirrorBlend);
|
|
|
|
ASSERT_PROPERTY_EQ(12, "mirror.depth", mirrorDepth);
|
|
|
|
ASSERT_PROPERTY_FLOAT_EQ(0.4f, "mirror.maxDist", mirrorMaxDist);
|
|
|
|
ASSERT_PROPERTY_EQ(1, "mirror.fadeTo", mirrorFadeTo);
|
|
|
|
ASSERT_PROPERTY_FLOAT_EQ(0.512f, "mirror.glossAmount", mirrorGlossAmount);
|
|
|
|
ASSERT_PROPERTY_FLOAT_EQ(0.18f, "mirror.glossThreshold", mirrorGlossThreshold);
|
|
|
|
ASSERT_PROPERTY_EQ(61, "mirror.glossSamples", mirrorGlossSamples);
|
|
|
|
ASSERT_PROPERTY_FLOAT_EQ(0.87f, "mirror.glossAnisotropic", mirrorGlossAnisotropic);
|
|
|
|
}
|
2018-06-09 13:45:09 +00:00
|
|
|
|
2020-03-22 11:13:09 +00:00
|
|
|
TEST_F(BlendImportMaterials, testImportMaterialwith2texturesAnd2TexCoordMappings) {
|
|
|
|
const aiScene *pTest = im->ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/plane_2_textures_2_texcoords_279.blend", aiProcess_ValidateDataStructure);
|
2022-11-08 16:03:55 +00:00
|
|
|
ASSERT_TRUE(pTest != nullptr);
|
2018-06-09 13:45:09 +00:00
|
|
|
|
|
|
|
// material has 2 diffuse textures
|
|
|
|
ASSERT_TRUE(pTest->HasMaterials());
|
2019-06-15 17:17:15 +00:00
|
|
|
EXPECT_EQ(1u, pTest->mNumMaterials);
|
2018-06-09 13:45:09 +00:00
|
|
|
const aiMaterial *pMat = pTest->mMaterials[0];
|
|
|
|
ASSERT_TRUE(nullptr != pMat);
|
2019-06-15 17:17:15 +00:00
|
|
|
ASSERT_EQ(2u, pMat->GetTextureCount(aiTextureType_DIFFUSE));
|
2018-06-09 13:45:09 +00:00
|
|
|
aiString aPath;
|
|
|
|
aiTextureMapping tm = aiTextureMapping::aiTextureMapping_OTHER;
|
|
|
|
aiReturn result = pMat->GetTexture(aiTextureType_DIFFUSE, 0, &aPath, &tm);
|
|
|
|
ASSERT_EQ(aiReturn_SUCCESS, result);
|
|
|
|
result = pMat->GetTexture(aiTextureType_DIFFUSE, 1, &aPath, &tm);
|
|
|
|
ASSERT_EQ(aiReturn_SUCCESS, result);
|
|
|
|
|
|
|
|
// mesh has 2 texturecoord sets
|
|
|
|
ASSERT_TRUE(pTest->HasMeshes());
|
2019-06-15 17:17:15 +00:00
|
|
|
EXPECT_EQ(1u, pTest->mNumMeshes);
|
2018-06-09 13:45:09 +00:00
|
|
|
const aiMesh *pMesh = pTest->mMeshes[0];
|
|
|
|
ASSERT_TRUE(nullptr != pMesh);
|
|
|
|
ASSERT_TRUE(pMesh->HasTextureCoords(0));
|
|
|
|
ASSERT_TRUE(pMesh->HasTextureCoords(1));
|
|
|
|
}
|