Merge branch 'master' into fbx_export_footer_tweak

pull/1823/head
Kim Kulling 2018-03-07 19:44:38 +01:00 committed by GitHub
commit af8839a8b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 239 additions and 47 deletions

View File

@ -230,6 +230,11 @@ ELSEIF( CMAKE_COMPILER_IS_MINGW )
ADD_DEFINITIONS( -U__STRICT_ANSI__ ) ADD_DEFINITIONS( -U__STRICT_ANSI__ )
ENDIF() ENDIF()
if (IOS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fembed-bitcode -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fembed-bitcode -O3")
endif()
if (ASSIMP_COVERALLS) if (ASSIMP_COVERALLS)
MESSAGE(STATUS "Coveralls enabled") MESSAGE(STATUS "Coveralls enabled")
INCLUDE(Coveralls) INCLUDE(Coveralls)

View File

@ -349,7 +349,7 @@ void Discreet3DSImporter::ParseObjectChunk()
case Discreet3DS::CHUNK_MAT_MATERIAL: case Discreet3DS::CHUNK_MAT_MATERIAL:
// Add a new material to the list // Add a new material to the list
mScene->mMaterials.push_back(D3DS::Material(std::string("UNNAMED_" + std::to_string(mScene->mMaterials.size())))); mScene->mMaterials.push_back(D3DS::Material(std::string("UNNAMED_" + to_string(mScene->mMaterials.size()))));
ParseMaterialChunk(); ParseMaterialChunk();
break; break;

View File

@ -72,6 +72,7 @@ SET( PUBLIC_HEADERS
${HEADER_PATH}/matrix4x4.h ${HEADER_PATH}/matrix4x4.h
${HEADER_PATH}/matrix4x4.inl ${HEADER_PATH}/matrix4x4.inl
${HEADER_PATH}/mesh.h ${HEADER_PATH}/mesh.h
${HEADER_PATH}/pbrmaterial.h
${HEADER_PATH}/postprocess.h ${HEADER_PATH}/postprocess.h
${HEADER_PATH}/quaternion.h ${HEADER_PATH}/quaternion.h
${HEADER_PATH}/quaternion.inl ${HEADER_PATH}/quaternion.inl

View File

@ -131,6 +131,7 @@ void ColladaLoader::SetupProperties(const Importer* pImp)
{ {
noSkeletonMesh = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_NO_SKELETON_MESHES,0) != 0; noSkeletonMesh = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_NO_SKELETON_MESHES,0) != 0;
ignoreUpDirection = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION,0) != 0; ignoreUpDirection = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION,0) != 0;
useColladaName = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_USE_COLLADA_NAMES,0) != 0;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -1913,6 +1914,11 @@ const Collada::Node* ColladaLoader::FindNodeBySID( const Collada::Node* pNode, c
// The name must be unique for proper node-bone association. // The name must be unique for proper node-bone association.
std::string ColladaLoader::FindNameForNode( const Collada::Node* pNode) std::string ColladaLoader::FindNameForNode( const Collada::Node* pNode)
{ {
// If explicitly requested, just use the collada name.
if (useColladaName) {
return pNode->mName;
}
// Now setup the name of the assimp node. The collada name might not be // Now setup the name of the assimp node. The collada name might not be
// unique, so we use the collada ID. // unique, so we use the collada ID.
if (!pNode->mID.empty()) if (!pNode->mID.empty())

View File

@ -248,6 +248,7 @@ protected:
bool noSkeletonMesh; bool noSkeletonMesh;
bool ignoreUpDirection; bool ignoreUpDirection;
bool useColladaName;
/** Used by FindNameForNode() to generate unique node names */ /** Used by FindNameForNode() to generate unique node names */
unsigned int mNodeNameCounter; unsigned int mNodeNameCounter;

View File

@ -303,11 +303,12 @@ void ObjFileMtlImporter::createMaterial()
// New Material created // New Material created
m_pModel->m_pCurrentMaterial = new ObjFile::Material(); m_pModel->m_pCurrentMaterial = new ObjFile::Material();
m_pModel->m_pCurrentMaterial->MaterialName.Set( name ); m_pModel->m_pCurrentMaterial->MaterialName.Set( name );
m_pModel->m_MaterialLib.push_back( name );
m_pModel->m_MaterialMap[ name ] = m_pModel->m_pCurrentMaterial;
if (m_pModel->m_pCurrentMesh) { if (m_pModel->m_pCurrentMesh) {
m_pModel->m_pCurrentMesh->m_uiMaterialIndex = static_cast<unsigned int>(m_pModel->m_MaterialLib.size() - 1); m_pModel->m_pCurrentMesh->m_uiMaterialIndex = static_cast<unsigned int>(m_pModel->m_MaterialLib.size() - 1);
} }
m_pModel->m_MaterialLib.push_back( name );
m_pModel->m_MaterialMap[ name ] = m_pModel->m_pCurrentMaterial;
} else { } else {
// Use older material // Use older material
m_pModel->m_pCurrentMaterial = (*it).second; m_pModel->m_pCurrentMaterial = (*it).second;

View File

@ -1043,71 +1043,91 @@ bool PLY::PropertyInstance::ParseValueBinary(IOStreamBuffer<char> &streamBuffer,
switch (eType) switch (eType)
{ {
case EDT_UInt: case EDT_UInt:
out->iUInt = (uint32_t)*((uint32_t*)pCur); {
pCur += 4; uint32_t t;
memcpy(&t, pCur, sizeof(uint32_t));
pCur += sizeof(uint32_t);
// Swap endianness // Swap endianness
if (p_bBE)ByteSwap::Swap((int32_t*)&out->iUInt); if (p_bBE)ByteSwap::Swap(&t);
out->iUInt = t;
break; break;
}
case EDT_UShort: case EDT_UShort:
{ {
uint16_t i = *((uint16_t*)pCur); uint16_t t;
memcpy(&t, pCur, sizeof(uint16_t));
pCur += sizeof(uint16_t);
// Swap endianness // Swap endianness
if (p_bBE)ByteSwap::Swap(&i); if (p_bBE)ByteSwap::Swap(&t);
out->iUInt = (uint32_t)i; out->iUInt = t;
pCur += 2;
break; break;
} }
case EDT_UChar: case EDT_UChar:
{ {
out->iUInt = (uint32_t)(*((uint8_t*)pCur)); uint8_t t;
pCur++; memcpy(&t, pCur, sizeof(uint8_t));
pCur += sizeof(uint8_t);
out->iUInt = t;
break; break;
} }
case EDT_Int: case EDT_Int:
out->iInt = *((int32_t*)pCur); {
pCur += 4; int32_t t;
memcpy(&t, pCur, sizeof(int32_t));
pCur += sizeof(int32_t);
// Swap endianness // Swap endianness
if (p_bBE)ByteSwap::Swap(&out->iInt); if (p_bBE)ByteSwap::Swap(&t);
out->iInt = t;
break; break;
}
case EDT_Short: case EDT_Short:
{ {
int16_t i = *((int16_t*)pCur); int16_t t;
memcpy(&t, pCur, sizeof(int16_t));
pCur += sizeof(int16_t);
// Swap endianness // Swap endianness
if (p_bBE)ByteSwap::Swap(&i); if (p_bBE)ByteSwap::Swap(&t);
out->iInt = (int32_t)i; out->iInt = t;
pCur += 2;
break; break;
} }
case EDT_Char: case EDT_Char:
out->iInt = (int32_t)*((int8_t*)pCur); {
pCur++; int8_t t;
memcpy(&t, pCur, sizeof(int8_t));
pCur += sizeof(int8_t);
out->iInt = t;
break; break;
}
case EDT_Float: case EDT_Float:
{ {
out->fFloat = *((float*)pCur); float t;
memcpy(&t, pCur, sizeof(float));
pCur += sizeof(float);
// Swap endianness // Swap endianness
if (p_bBE)ByteSwap::Swap((int32_t*)&out->fFloat); if (p_bBE)ByteSwap::Swap(&t);
pCur += 4; out->fFloat = t;
break; break;
} }
case EDT_Double: case EDT_Double:
{ {
out->fDouble = *((double*)pCur); double t;
memcpy(&t, pCur, sizeof(double));
pCur += sizeof(double);
// Swap endianness // Swap endianness
if (p_bBE)ByteSwap::Swap((int64_t*)&out->fDouble); if (p_bBE)ByteSwap::Swap(&t);
pCur += 8; out->fDouble = t;
break; break;
} }
default: default:

View File

@ -669,7 +669,7 @@ inline Image::Image()
} }
inline void Image::Read(Value& obj, Asset& /*r*/) inline void Image::Read(Value& obj, Asset& r)
{ {
if (!mDataLength) { if (!mDataLength) {
if (Value* uri = FindString(obj, "uri")) { if (Value* uri = FindString(obj, "uri")) {
@ -686,6 +686,19 @@ inline void Image::Read(Value& obj, Asset& /*r*/)
this->uri = uristr; this->uri = uristr;
} }
} }
else if (Value* bufferViewVal = FindUInt(obj, "bufferView")) {
this->bufferView = r.bufferViews.Retrieve(bufferViewVal->GetUint());
Ref<Buffer> buffer = this->bufferView->buffer;
this->mDataLength = this->bufferView->byteLength;
// maybe this memcpy could be avoided if aiTexture does not delete[] pcData at destruction.
this->mData = new uint8_t [this->mDataLength];
memcpy(this->mData, buffer->GetPointer() + this->bufferView->byteOffset, this->mDataLength);
if (Value* mtype = FindString(obj, "mimeType")) {
this->mimeType = mtype->GetString();
}
}
} }
} }

View File

@ -948,24 +948,24 @@ Ref<Buffer> buf = pAsset_Root.buffers.Get(pCompression_Open3DGC.Buffer);
size_t size_coordindex = ifs.GetNCoordIndex() * 3;// See float attributes note. size_t size_coordindex = ifs.GetNCoordIndex() * 3;// See float attributes note.
if(primitives[0].indices->count != size_coordindex) if(primitives[0].indices->count != size_coordindex)
throw DeadlyImportError("GLTF: Open3DGC. Compressed indices count (" + std::to_string(size_coordindex) + throw DeadlyImportError("GLTF: Open3DGC. Compressed indices count (" + to_string(size_coordindex) +
") not equal to uncompressed (" + std::to_string(primitives[0].indices->count) + ")."); ") not equal to uncompressed (" + to_string(primitives[0].indices->count) + ").");
size_coordindex *= sizeof(IndicesType); size_coordindex *= sizeof(IndicesType);
// Coordinates // Coordinates
size_t size_coord = ifs.GetNCoord();// See float attributes note. size_t size_coord = ifs.GetNCoord();// See float attributes note.
if(primitives[0].attributes.position[0]->count != size_coord) if(primitives[0].attributes.position[0]->count != size_coord)
throw DeadlyImportError("GLTF: Open3DGC. Compressed positions count (" + std::to_string(size_coord) + throw DeadlyImportError("GLTF: Open3DGC. Compressed positions count (" + to_string(size_coord) +
") not equal to uncompressed (" + std::to_string(primitives[0].attributes.position[0]->count) + ")."); ") not equal to uncompressed (" + to_string(primitives[0].attributes.position[0]->count) + ").");
size_coord *= 3 * sizeof(float); size_coord *= 3 * sizeof(float);
// Normals // Normals
size_t size_normal = ifs.GetNNormal();// See float attributes note. size_t size_normal = ifs.GetNNormal();// See float attributes note.
if(primitives[0].attributes.normal[0]->count != size_normal) if(primitives[0].attributes.normal[0]->count != size_normal)
throw DeadlyImportError("GLTF: Open3DGC. Compressed normals count (" + std::to_string(size_normal) + throw DeadlyImportError("GLTF: Open3DGC. Compressed normals count (" + to_string(size_normal) +
") not equal to uncompressed (" + std::to_string(primitives[0].attributes.normal[0]->count) + ")."); ") not equal to uncompressed (" + to_string(primitives[0].attributes.normal[0]->count) + ").");
size_normal *= 3 * sizeof(float); size_normal *= 3 * sizeof(float);
// Additional attributes. // Additional attributes.
@ -989,8 +989,8 @@ Ref<Buffer> buf = pAsset_Root.buffers.Get(pCompression_Open3DGC.Buffer);
if(idx_texcoord < primitives[0].attributes.texcoord.size()) if(idx_texcoord < primitives[0].attributes.texcoord.size())
{ {
if(primitives[0].attributes.texcoord[idx]->count != tval) if(primitives[0].attributes.texcoord[idx]->count != tval)
throw DeadlyImportError("GLTF: Open3DGC. Compressed texture coordinates count (" + std::to_string(tval) + throw DeadlyImportError("GLTF: Open3DGC. Compressed texture coordinates count (" + to_string(tval) +
") not equal to uncompressed (" + std::to_string(primitives[0].attributes.texcoord[idx]->count) + ")."); ") not equal to uncompressed (" + to_string(primitives[0].attributes.texcoord[idx]->count) + ").");
idx_texcoord++; idx_texcoord++;
} }

View File

@ -194,9 +194,16 @@ void glTFImporter::ImportMaterials(glTF::Asset& r)
aimat->AddProperty(&str, AI_MATKEY_NAME); aimat->AddProperty(&str, AI_MATKEY_NAME);
} }
SetMaterialColorProperty(embeddedTexIdxs, r, mat.diffuse, aimat, aiTextureType_DIFFUSE, AI_MATKEY_COLOR_DIFFUSE); SetMaterialColorProperty(embeddedTexIdxs, r, mat.ambient, aimat, aiTextureType_AMBIENT, AI_MATKEY_COLOR_AMBIENT );
SetMaterialColorProperty(embeddedTexIdxs, r, mat.diffuse, aimat, aiTextureType_DIFFUSE, AI_MATKEY_COLOR_DIFFUSE );
SetMaterialColorProperty(embeddedTexIdxs, r, mat.specular, aimat, aiTextureType_SPECULAR, AI_MATKEY_COLOR_SPECULAR); SetMaterialColorProperty(embeddedTexIdxs, r, mat.specular, aimat, aiTextureType_SPECULAR, AI_MATKEY_COLOR_SPECULAR);
SetMaterialColorProperty(embeddedTexIdxs, r, mat.ambient, aimat, aiTextureType_AMBIENT, AI_MATKEY_COLOR_AMBIENT); SetMaterialColorProperty(embeddedTexIdxs, r, mat.emission, aimat, aiTextureType_EMISSIVE, AI_MATKEY_COLOR_EMISSIVE);
aimat->AddProperty(&mat.doubleSided, 1, AI_MATKEY_TWOSIDED);
if (mat.transparent && (mat.transparency != 1.0f)) {
aimat->AddProperty(&mat.transparency, 1, AI_MATKEY_OPACITY);
}
if (mat.shininess > 0.f) { if (mat.shininess > 0.f) {
aimat->AddProperty(&mat.shininess, 1, AI_MATKEY_SHININESS); aimat->AddProperty(&mat.shininess, 1, AI_MATKEY_SHININESS);

View File

@ -77,8 +77,9 @@ extern "C" {
the consistency of the compressed data, so the library should never crash the consistency of the compressed data, so the library should never crash
even in the case of corrupted input. even in the case of corrupted input.
*/ */
#ifdef __ANDROID__ #ifdef __ANDROID__
using zcrc_t = unsigned_long; typedef unsigned long zcrc_t;
#endif #endif
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));

View File

@ -934,6 +934,16 @@ enum aiComponent
*/ */
#define AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION "IMPORT_COLLADA_IGNORE_UP_DIRECTION" #define AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION "IMPORT_COLLADA_IGNORE_UP_DIRECTION"
// ---------------------------------------------------------------------------
/** @brief Specifies whether the Collada loader should use Collada names as node names.
*
* If this property is set to true, the Collada names will be used as the
* node name. The default is to use the id tag (resp. sid tag, if no id tag is present)
* instead.
* Property type: Bool. Default value: false.
*/
#define AI_CONFIG_IMPORT_COLLADA_USE_COLLADA_NAMES "IMPORT_COLLADA_USE_COLLADA_NAMES"
// ---------- All the Export defines ------------ // ---------- All the Export defines ------------
/** @brief Specifies the xfile use double for real values of float /** @brief Specifies the xfile use double for real values of float

View File

@ -0,0 +1,5 @@
newmtl MyMaterial
Ka 1.000 1.000 1.000
Kd 1.000 1.000 1.000
Ns 200.000
Ks 0.050 0.050 0.050

View File

@ -0,0 +1,32 @@
g Object
mtllib cube_mtllib_after_g.mat
usemtl MyMaterial
v 0.0 0.0 0.0
v 0.0 0.0 1.0
v 0.0 1.0 0.0
v 0.0 1.0 1.0
v 1.0 0.0 0.0
v 1.0 0.0 1.0
v 1.0 1.0 0.0
v 1.0 1.0 1.0
vn 0.0 0.0 1.0
vn 0.0 0.0 -1.0
vn 0.0 1.0 0.0
vn 0.0 -1.0 0.0
vn 1.0 0.0 0.0
vn -1.0 0.0 0.0
f 1//2 7//2 5//2
f 1//2 3//2 7//2
f 1//6 4//6 3//6
f 1//6 2//6 4//6
f 3//3 8//3 7//3
f 3//3 4//3 8//3
f 5//5 7//5 8//5
f 5//5 8//5 6//5
f 1//4 5//4 6//4
f 1//4 6//4 2//4
f 2//1 6//1 8//1
f 2//1 8//1 4//1

Binary file not shown.

View File

@ -0,0 +1,45 @@
ply
format ascii 1.0
comment Created by Blender 2.77 (sub 0) - www.blender.org, source file: ''
element vertex 24
property float x
property float y
property float z
property float nx
property float ny
property float nz
property float s
property float t
element face 6
property list uchar uint vertex_indices
end_header
1.000000 1.000000 -1.000000 0.000000 0.000000 -1.000000 0.000000 0.000000
1.000000 -1.000000 -1.000000 0.000000 0.000000 -1.000000 1.000000 0.000000
-1.000000 -1.000000 -1.000000 0.000000 0.000000 -1.000000 1.000000 1.000000
-1.000000 1.000000 -1.000000 0.000000 0.000000 -1.000000 0.000000 1.000000
1.000000 0.999999 1.000000 0.000000 -0.000000 1.000000 0.000000 0.000000
-1.000000 1.000000 1.000000 0.000000 -0.000000 1.000000 1.000000 0.000000
-1.000000 -1.000000 1.000000 0.000000 -0.000000 1.000000 1.000000 1.000000
0.999999 -1.000001 1.000000 0.000000 -0.000000 1.000000 0.000000 1.000000
1.000000 1.000000 -1.000000 1.000000 -0.000000 0.000000 0.000000 0.000000
1.000000 0.999999 1.000000 1.000000 -0.000000 0.000000 1.000000 0.000000
0.999999 -1.000001 1.000000 1.000000 -0.000000 0.000000 1.000000 1.000000
1.000000 -1.000000 -1.000000 1.000000 -0.000000 0.000000 0.000000 1.000000
1.000000 -1.000000 -1.000000 -0.000000 -1.000000 -0.000000 0.000000 0.000000
0.999999 -1.000001 1.000000 -0.000000 -1.000000 -0.000000 1.000000 0.000000
-1.000000 -1.000000 1.000000 -0.000000 -1.000000 -0.000000 1.000000 1.000000
-1.000000 -1.000000 -1.000000 -0.000000 -1.000000 -0.000000 0.000000 1.000000
-1.000000 -1.000000 -1.000000 -1.000000 0.000000 -0.000000 0.000000 0.000000
-1.000000 -1.000000 1.000000 -1.000000 0.000000 -0.000000 1.000000 0.000000
-1.000000 1.000000 1.000000 -1.000000 0.000000 -0.000000 1.000000 1.000000
-1.000000 1.000000 -1.000000 -1.000000 0.000000 -0.000000 0.000000 1.000000
1.000000 0.999999 1.000000 0.000000 1.000000 0.000000 0.000000 0.000000
1.000000 1.000000 -1.000000 0.000000 1.000000 0.000000 1.000000 0.000000
-1.000000 1.000000 -1.000000 0.000000 1.000000 0.000000 1.000000 1.000000
-1.000000 1.000000 1.000000 0.000000 1.000000 0.000000 0.000000 1.000000
4 0 1 2 3
4 4 5 6 7
4 8 9 10 11
4 12 13 14 15
4 16 17 18 19
4 20 21 22 23

View File

@ -354,3 +354,16 @@ TEST_F(utObjImportExport, 0based_array_Test) {
const aiScene *scene = myimporter.ReadFileFromMemory(ObjModel.c_str(), ObjModel.size(), 0); const aiScene *scene = myimporter.ReadFileFromMemory(ObjModel.c_str(), ObjModel.size(), 0);
EXPECT_EQ(nullptr, scene); EXPECT_EQ(nullptr, scene);
} }
TEST_F( utObjImportExport, mtllib_after_g ) {
::Assimp::Importer importer;
const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/OBJ/cube_mtllib_after_g.obj", aiProcess_ValidateDataStructure );
ASSERT_NE( nullptr, scene );
EXPECT_EQ(scene->mNumMeshes, 1U);
const aiMesh *mesh = scene->mMeshes[0];
const aiMaterial* mat = scene->mMaterials[mesh->mMaterialIndex];
aiString name;
ASSERT_EQ(aiReturn_SUCCESS, mat->Get(AI_MATKEY_NAME, name));
EXPECT_STREQ("MyMaterial", name.C_Str());
}

View File

@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/Exporter.hpp> #include <assimp/Exporter.hpp>
#include <assimp/scene.h> #include <assimp/scene.h>
#include "AbstractImportExportBase.h" #include "AbstractImportExportBase.h"
#include <assimp/postprocess.h>
using namespace ::Assimp; using namespace ::Assimp;
@ -52,7 +53,7 @@ class utPLYImportExport : public AbstractImportExportBase {
public: public:
virtual bool importerTest() { virtual bool importerTest() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", 0 ); const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", aiProcess_ValidateDataStructure);
EXPECT_EQ( 1u, scene->mNumMeshes ); EXPECT_EQ( 1u, scene->mNumMeshes );
EXPECT_NE( nullptr, scene->mMeshes[0] ); EXPECT_NE( nullptr, scene->mMeshes[0] );
EXPECT_EQ( 8u, scene->mMeshes[0]->mNumVertices ); EXPECT_EQ( 8u, scene->mMeshes[0]->mNumVertices );
@ -65,7 +66,7 @@ public:
virtual bool exporterTest() { virtual bool exporterTest() {
Importer importer; Importer importer;
Exporter exporter; Exporter exporter;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", 0); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
EXPECT_EQ(aiReturn_SUCCESS, exporter.Export(scene, "ply", ASSIMP_TEST_MODELS_DIR "/PLY/cube_test.ply")); EXPECT_EQ(aiReturn_SUCCESS, exporter.Export(scene, "ply", ASSIMP_TEST_MODELS_DIR "/PLY/cube_test.ply"));
@ -89,19 +90,50 @@ TEST_F(utPLYImportExport, exportTest_Success ) {
//Test issue 1623, crash when loading two PLY files in a row //Test issue 1623, crash when loading two PLY files in a row
TEST_F(utPLYImportExport, importerMultipleTest) { TEST_F(utPLYImportExport, importerMultipleTest) {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", 0); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", 0); scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
} }
TEST_F(utPLYImportExport, importPLYwithUV) {
Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube_uv.ply", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene);
EXPECT_NE(nullptr, scene->mMeshes[0]);
//This test model is using n-gons, so 6 faces instead of 12 tris
EXPECT_EQ(6u, scene->mMeshes[0]->mNumFaces);
EXPECT_EQ(aiPrimitiveType_POLYGON, scene->mMeshes[0]->mPrimitiveTypes);
EXPECT_EQ(true, scene->mMeshes[0]->HasTextureCoords(0));
}
TEST_F(utPLYImportExport, importBinaryPLY) {
Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube_binary.ply", 0);
EXPECT_NE(nullptr, scene);
EXPECT_NE(nullptr, scene->mMeshes[0]);
//This test model is double sided, so 12 faces instead of 6
EXPECT_EQ(12u, scene->mMeshes[0]->mNumFaces);
}
TEST_F( utPLYImportExport, vertexColorTest ) { TEST_F( utPLYImportExport, vertexColorTest ) {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/PLY/float-color.ply", 0 ); const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/PLY/float-color.ply", aiProcess_ValidateDataStructure);
EXPECT_NE( nullptr, scene ); EXPECT_NE( nullptr, scene );
EXPECT_EQ(1u, scene->mMeshes[0]->mNumFaces);
EXPECT_EQ(aiPrimitiveType_TRIANGLE, scene->mMeshes[0]->mPrimitiveTypes);
EXPECT_EQ(true, scene->mMeshes[0]->HasVertexColors(0));
auto first_face = scene->mMeshes[0]->mFaces[0];
EXPECT_EQ(3, first_face.mNumIndices);
EXPECT_EQ(0, first_face.mIndices[0]);
EXPECT_EQ(1, first_face.mIndices[1]);
EXPECT_EQ(2, first_face.mIndices[2]);
} }
static const char *test_file = static const char *test_file =
@ -125,6 +157,6 @@ static const char *test_file =
TEST_F( utPLYImportExport, parseErrorTest ) { TEST_F( utPLYImportExport, parseErrorTest ) {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFileFromMemory( test_file, strlen( test_file ), 0 ); const aiScene *scene = importer.ReadFileFromMemory( test_file, strlen( test_file ), aiProcess_ValidateDataStructure);
EXPECT_NE( nullptr, scene ); EXPECT_NE( nullptr, scene );
} }