From 87ac6fbfd94199c049037a5d76ab117944c26b3c Mon Sep 17 00:00:00 2001 From: "Andrea Baldacci, Ph.D" Date: Tue, 31 Oct 2017 02:05:01 +0100 Subject: [PATCH 1/9] Update CMakeLists.txt --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c30278b7f..270aad38a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,6 +211,11 @@ ELSEIF( CMAKE_COMPILER_IS_MINGW ) ADD_DEFINITIONS( -U__STRICT_ANSI__ ) ENDIF() +if(IOS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fembed-bitcode -O3") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fembed-bitcode -O3") +endif(IOS) + if (ASSIMP_COVERALLS) MESSAGE(STATUS "Coveralls enabled") INCLUDE(Coveralls) From 978c156c2ad84d3b8afcabbc55ff966aafe3ecec Mon Sep 17 00:00:00 2001 From: Marco Di Benedetto Date: Wed, 10 Jan 2018 20:02:41 +0100 Subject: [PATCH 2/9] added import of material properties (double sided and transparency) in glTF 1.0 importer. --- code/glTFImporter.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/code/glTFImporter.cpp b/code/glTFImporter.cpp index 381e459fd..9e341c632 100644 --- a/code/glTFImporter.cpp +++ b/code/glTFImporter.cpp @@ -193,9 +193,16 @@ void glTFImporter::ImportMaterials(glTF::Asset& r) 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.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) { aimat->AddProperty(&mat.shininess, 1, AI_MATKEY_SHININESS); From c749594e9de7b98ae63000aef19013dcc020d441 Mon Sep 17 00:00:00 2001 From: Marco Di Benedetto Date: Thu, 18 Jan 2018 19:12:51 +0100 Subject: [PATCH 3/9] gltf instant ok on valid extension. --- code/glTF2Importer.cpp | 4 ++-- code/glTFImporter.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/code/glTF2Importer.cpp b/code/glTF2Importer.cpp index 92328ec2d..8136af2dc 100644 --- a/code/glTF2Importer.cpp +++ b/code/glTF2Importer.cpp @@ -103,8 +103,8 @@ bool glTF2Importer::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool { const std::string &extension = GetExtension(pFile); - if (extension != "gltf" && extension != "glb") - return false; + if (extension == "gltf" || extension == "glb") + return true; if (pIOHandler) { glTF2::Asset asset(pIOHandler); diff --git a/code/glTFImporter.cpp b/code/glTFImporter.cpp index b4d69e32f..4df9e1763 100644 --- a/code/glTFImporter.cpp +++ b/code/glTFImporter.cpp @@ -102,8 +102,8 @@ bool glTFImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool { const std::string &extension = GetExtension(pFile); - if (extension != "gltf" && extension != "glb") - return false; + if (extension == "gltf" || extension == "glb") + return true; if (pIOHandler) { glTF::Asset asset(pIOHandler); From 5f38bd01ece06876250fd3bab4f72456170cf3e4 Mon Sep 17 00:00:00 2001 From: Marco Di Benedetto Date: Thu, 18 Jan 2018 22:28:44 +0100 Subject: [PATCH 4/9] restored gltf checks. --- code/glTF2Importer.cpp | 4 ++-- code/glTFImporter.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/code/glTF2Importer.cpp b/code/glTF2Importer.cpp index 8136af2dc..92328ec2d 100644 --- a/code/glTF2Importer.cpp +++ b/code/glTF2Importer.cpp @@ -103,8 +103,8 @@ bool glTF2Importer::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool { const std::string &extension = GetExtension(pFile); - if (extension == "gltf" || extension == "glb") - return true; + if (extension != "gltf" && extension != "glb") + return false; if (pIOHandler) { glTF2::Asset asset(pIOHandler); diff --git a/code/glTFImporter.cpp b/code/glTFImporter.cpp index 4df9e1763..b4d69e32f 100644 --- a/code/glTFImporter.cpp +++ b/code/glTFImporter.cpp @@ -102,8 +102,8 @@ bool glTFImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool { const std::string &extension = GetExtension(pFile); - if (extension == "gltf" || extension == "glb") - return true; + if (extension != "gltf" && extension != "glb") + return false; if (pIOHandler) { glTF::Asset asset(pIOHandler); From 59ea3b6c8577c4e46e8ca0ca68afcf9efa92cf0a Mon Sep 17 00:00:00 2001 From: Marco Di Benedetto Date: Fri, 9 Feb 2018 16:02:27 +0100 Subject: [PATCH 5/9] fixed android zlib compile error. --- CMakeLists.txt | 8 ++++---- contrib/zlib/zlib.h | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d3616ab7..15374a3fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -230,10 +230,10 @@ ELSEIF( CMAKE_COMPILER_IS_MINGW ) ADD_DEFINITIONS( -U__STRICT_ANSI__ ) ENDIF() -if(IOS) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fembed-bitcode -O3") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fembed-bitcode -O3") -endif(IOS) +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) MESSAGE(STATUS "Coveralls enabled") diff --git a/contrib/zlib/zlib.h b/contrib/zlib/zlib.h index 2d6bb2976..dcb7b5063 100644 --- a/contrib/zlib/zlib.h +++ b/contrib/zlib/zlib.h @@ -77,8 +77,9 @@ extern "C" { the consistency of the compressed data, so the library should never crash even in the case of corrupted input. */ -#ifdef __ANDROID__ -using zcrc_t = unsigned_long; + +#ifdef __ANDROID__ +typedef unsigned long zcrc_t; #endif typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); From c874fd8ae2626334f7920715d4e6977529297dff Mon Sep 17 00:00:00 2001 From: Marco Di Benedetto Date: Fri, 9 Feb 2018 16:18:49 +0100 Subject: [PATCH 6/9] changed std::to_string to to_string. --- code/3DSLoader.cpp | 2 +- code/glTFAsset.inl | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/code/3DSLoader.cpp b/code/3DSLoader.cpp index 9d61e125c..92a64e3d8 100644 --- a/code/3DSLoader.cpp +++ b/code/3DSLoader.cpp @@ -349,7 +349,7 @@ void Discreet3DSImporter::ParseObjectChunk() case Discreet3DS::CHUNK_MAT_MATERIAL: // 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(); break; diff --git a/code/glTFAsset.inl b/code/glTFAsset.inl index b31846abd..bd43b19f2 100644 --- a/code/glTFAsset.inl +++ b/code/glTFAsset.inl @@ -948,24 +948,24 @@ Ref buf = pAsset_Root.buffers.Get(pCompression_Open3DGC.Buffer); size_t size_coordindex = ifs.GetNCoordIndex() * 3;// See float attributes note. if(primitives[0].indices->count != size_coordindex) - throw DeadlyImportError("GLTF: Open3DGC. Compressed indices count (" + std::to_string(size_coordindex) + - ") not equal to uncompressed (" + std::to_string(primitives[0].indices->count) + ")."); + throw DeadlyImportError("GLTF: Open3DGC. Compressed indices count (" + to_string(size_coordindex) + + ") not equal to uncompressed (" + to_string(primitives[0].indices->count) + ")."); size_coordindex *= sizeof(IndicesType); // Coordinates size_t size_coord = ifs.GetNCoord();// See float attributes note. if(primitives[0].attributes.position[0]->count != size_coord) - throw DeadlyImportError("GLTF: Open3DGC. Compressed positions count (" + std::to_string(size_coord) + - ") not equal to uncompressed (" + std::to_string(primitives[0].attributes.position[0]->count) + ")."); + throw DeadlyImportError("GLTF: Open3DGC. Compressed positions count (" + to_string(size_coord) + + ") not equal to uncompressed (" + to_string(primitives[0].attributes.position[0]->count) + ")."); size_coord *= 3 * sizeof(float); // Normals size_t size_normal = ifs.GetNNormal();// See float attributes note. if(primitives[0].attributes.normal[0]->count != size_normal) - throw DeadlyImportError("GLTF: Open3DGC. Compressed normals count (" + std::to_string(size_normal) + - ") not equal to uncompressed (" + std::to_string(primitives[0].attributes.normal[0]->count) + ")."); + throw DeadlyImportError("GLTF: Open3DGC. Compressed normals count (" + to_string(size_normal) + + ") not equal to uncompressed (" + to_string(primitives[0].attributes.normal[0]->count) + ")."); size_normal *= 3 * sizeof(float); // Additional attributes. @@ -989,8 +989,8 @@ Ref buf = pAsset_Root.buffers.Get(pCompression_Open3DGC.Buffer); if(idx_texcoord < primitives[0].attributes.texcoord.size()) { if(primitives[0].attributes.texcoord[idx]->count != tval) - throw DeadlyImportError("GLTF: Open3DGC. Compressed texture coordinates count (" + std::to_string(tval) + - ") not equal to uncompressed (" + std::to_string(primitives[0].attributes.texcoord[idx]->count) + ")."); + throw DeadlyImportError("GLTF: Open3DGC. Compressed texture coordinates count (" + to_string(tval) + + ") not equal to uncompressed (" + to_string(primitives[0].attributes.texcoord[idx]->count) + ")."); idx_texcoord++; } From 4b7cd97fea9dc37f4b741840090c42c6a6a027ae Mon Sep 17 00:00:00 2001 From: Marco Di Benedetto Date: Sat, 24 Feb 2018 17:44:40 +0100 Subject: [PATCH 7/9] added support for embedded textures defined with buffer views. --- code/glTF2Asset.inl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/code/glTF2Asset.inl b/code/glTF2Asset.inl index 520785081..cf43d67f1 100644 --- a/code/glTF2Asset.inl +++ b/code/glTF2Asset.inl @@ -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 (Value* uri = FindString(obj, "uri")) { @@ -686,6 +686,18 @@ inline void Image::Read(Value& obj, Asset& /*r*/) this->uri = uristr; } } + else if (Value* bufferViewVal = FindUInt(obj, "bufferView")) { + this->bufferView = r.bufferViews.Retrieve(bufferViewVal->GetUint()); + Ref buffer = this->bufferView->buffer; + + this->mDataLength = this->bufferView->byteLength; + this->mData = new uint8_t [this->mDataLength]; + memcpy(this->mData, buffer->GetPointer(), this->mDataLength); + + if (Value* mtype = FindString(obj, "mimeType")) { + this->mimeType = mtype->GetString(); + } + } } } From 138b990d0a9e7833bec242517f448df8ee69e861 Mon Sep 17 00:00:00 2001 From: Marco Di Benedetto Date: Sat, 24 Feb 2018 17:57:42 +0100 Subject: [PATCH 8/9] added missing install of pbrmaterial.h --- code/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 6430187b0..6e2db91db 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -72,6 +72,7 @@ SET( PUBLIC_HEADERS ${HEADER_PATH}/matrix4x4.h ${HEADER_PATH}/matrix4x4.inl ${HEADER_PATH}/mesh.h + ${HEADER_PATH}/pbrmaterial.h ${HEADER_PATH}/postprocess.h ${HEADER_PATH}/quaternion.h ${HEADER_PATH}/quaternion.inl From 72e9f3ecb9bd12056d6992d87d3511546486df72 Mon Sep 17 00:00:00 2001 From: Marco Di Benedetto Date: Sat, 24 Feb 2018 18:47:43 +0100 Subject: [PATCH 9/9] fixed embedded texture reading. --- code/glTF2Asset.inl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/glTF2Asset.inl b/code/glTF2Asset.inl index cf43d67f1..8f2b14e1a 100644 --- a/code/glTF2Asset.inl +++ b/code/glTF2Asset.inl @@ -691,8 +691,9 @@ inline void Image::Read(Value& obj, Asset& r) Ref 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->mDataLength); + memcpy(this->mData, buffer->GetPointer() + this->bufferView->byteOffset, this->mDataLength); if (Value* mtype = FindString(obj, "mimeType")) { this->mimeType = mtype->GetString();