From c769f8d4ad3b671f2e824fa3d9142e4f7e9a2ae4 Mon Sep 17 00:00:00 2001 From: Joshua Hyatt Date: Sat, 29 Aug 2020 22:21:34 -0600 Subject: [PATCH 1/8] Replace unique_ptr with raw pointer to avoid destructing stream --- code/AssetLib/Obj/ObjFileImporter.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/code/AssetLib/Obj/ObjFileImporter.cpp b/code/AssetLib/Obj/ObjFileImporter.cpp index b6e1f9061..794cb8ec0 100644 --- a/code/AssetLib/Obj/ObjFileImporter.cpp +++ b/code/AssetLib/Obj/ObjFileImporter.cpp @@ -107,8 +107,8 @@ const aiImporterDesc *ObjFileImporter::GetInfo() const { void ObjFileImporter::InternReadFile(const std::string &file, aiScene *pScene, IOSystem *pIOHandler) { // Read file into memory static const std::string mode = "rb"; - std::unique_ptr fileStream(pIOHandler->Open(file, mode)); - if (!fileStream.get()) { + IOStream *fileStream = pIOHandler->Open(file, mode); + if (!fileStream) { throw DeadlyImportError("Failed to open file " + file + "."); } @@ -119,10 +119,10 @@ void ObjFileImporter::InternReadFile(const std::string &file, aiScene *pScene, I } IOStreamBuffer streamedBuffer; - streamedBuffer.open(fileStream.get()); + streamedBuffer.open(fileStream); // Allocate buffer and read file into it - //TextFileToBuffer( fileStream.get(),m_Buffer); + //TextFileToBuffer( fileStream,m_Buffer); // Get the model name std::string modelName, folderName; @@ -145,6 +145,8 @@ void ObjFileImporter::InternReadFile(const std::string &file, aiScene *pScene, I streamedBuffer.close(); + pIOHandler->Close(fileStream); + // Clean up allocated storage for the next import m_Buffer.clear(); From cc2613f2644fd7ccb8730be871aba1de25128d49 Mon Sep 17 00:00:00 2001 From: Joshua Hyatt Date: Sat, 29 Aug 2020 23:06:33 -0600 Subject: [PATCH 2/8] Replace unique_ptr with raw pointer --- code/AssetLib/FBX/FBXImporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/FBX/FBXImporter.cpp b/code/AssetLib/FBX/FBXImporter.cpp index 8c908be40..61f67b382 100644 --- a/code/AssetLib/FBX/FBXImporter.cpp +++ b/code/AssetLib/FBX/FBXImporter.cpp @@ -141,7 +141,7 @@ void FBXImporter::SetupProperties(const Importer *pImp) { // ------------------------------------------------------------------------------------------------ // Imports the given file into the given scene structure. void FBXImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { - std::unique_ptr stream(pIOHandler->Open(pFile, "rb")); + IOStream* stream = pIOHandler->Open(pFile, "rb"); if (!stream) { ThrowException("Could not open file for reading"); } From 953e976de6f7c771cef880c7537407a76fb64d64 Mon Sep 17 00:00:00 2001 From: Joshua Hyatt Date: Sat, 29 Aug 2020 23:56:50 -0600 Subject: [PATCH 3/8] Close stream when finished --- code/AssetLib/FBX/FBXImporter.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/AssetLib/FBX/FBXImporter.cpp b/code/AssetLib/FBX/FBXImporter.cpp index 61f67b382..564317afe 100644 --- a/code/AssetLib/FBX/FBXImporter.cpp +++ b/code/AssetLib/FBX/FBXImporter.cpp @@ -159,6 +159,8 @@ void FBXImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy contents[contents.size() - 1] = 0; const char *const begin = &*contents.begin(); + pIOHandler->Close(stream); + // broadphase tokenizing pass in which we identify the core // syntax elements of FBX (brackets, commas, key:value mappings) TokenList tokens; From dcf9a7b2d8b2955f3594c43be9bd9a85c3f0db3d Mon Sep 17 00:00:00 2001 From: Joshua Hyatt Date: Sat, 29 Aug 2020 23:58:31 -0600 Subject: [PATCH 4/8] Conform variable names to code standards --- code/AssetLib/FBX/FBXImporter.cpp | 10 +++++----- code/AssetLib/Obj/ObjFileImporter.cpp | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/code/AssetLib/FBX/FBXImporter.cpp b/code/AssetLib/FBX/FBXImporter.cpp index 564317afe..0ecb10daa 100644 --- a/code/AssetLib/FBX/FBXImporter.cpp +++ b/code/AssetLib/FBX/FBXImporter.cpp @@ -141,8 +141,8 @@ void FBXImporter::SetupProperties(const Importer *pImp) { // ------------------------------------------------------------------------------------------------ // Imports the given file into the given scene structure. void FBXImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { - IOStream* stream = pIOHandler->Open(pFile, "rb"); - if (!stream) { + IOStream* pStream = pIOHandler->Open(pFile, "rb"); + if (!pStream) { ThrowException("Could not open file for reading"); } @@ -154,12 +154,12 @@ void FBXImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy // streaming for its output data structures so the net win with // streaming input data would be very low. std::vector contents; - contents.resize(stream->FileSize() + 1); - stream->Read(&*contents.begin(), 1, contents.size() - 1); + contents.resize(pStream->FileSize() + 1); + pStream->Read(&*contents.begin(), 1, contents.size() - 1); contents[contents.size() - 1] = 0; const char *const begin = &*contents.begin(); - pIOHandler->Close(stream); + pIOHandler->Close(pStream); // broadphase tokenizing pass in which we identify the core // syntax elements of FBX (brackets, commas, key:value mappings) diff --git a/code/AssetLib/Obj/ObjFileImporter.cpp b/code/AssetLib/Obj/ObjFileImporter.cpp index 794cb8ec0..2f330b729 100644 --- a/code/AssetLib/Obj/ObjFileImporter.cpp +++ b/code/AssetLib/Obj/ObjFileImporter.cpp @@ -107,22 +107,22 @@ const aiImporterDesc *ObjFileImporter::GetInfo() const { void ObjFileImporter::InternReadFile(const std::string &file, aiScene *pScene, IOSystem *pIOHandler) { // Read file into memory static const std::string mode = "rb"; - IOStream *fileStream = pIOHandler->Open(file, mode); - if (!fileStream) { + IOStream *pFileStream = pIOHandler->Open(file, mode); + if (!pFileStream) { throw DeadlyImportError("Failed to open file " + file + "."); } // Get the file-size and validate it, throwing an exception when fails - size_t fileSize = fileStream->FileSize(); + size_t fileSize = pFileStream->FileSize(); if (fileSize < ObjMinSize) { throw DeadlyImportError("OBJ-file is too small."); } IOStreamBuffer streamedBuffer; - streamedBuffer.open(fileStream); + streamedBuffer.open(pFileStream); // Allocate buffer and read file into it - //TextFileToBuffer( fileStream,m_Buffer); + //TextFileToBuffer( pFileStream,m_Buffer); // Get the model name std::string modelName, folderName; @@ -145,7 +145,7 @@ void ObjFileImporter::InternReadFile(const std::string &file, aiScene *pScene, I streamedBuffer.close(); - pIOHandler->Close(fileStream); + pIOHandler->Close(pFileStream); // Clean up allocated storage for the next import m_Buffer.clear(); From 638499a2783aa5a2fd494aebbb404147dcc964e4 Mon Sep 17 00:00:00 2001 From: Joshua Hyatt Date: Tue, 1 Sep 2020 10:30:31 -0600 Subject: [PATCH 5/8] Replace unique_ptr and add custom deleter --- code/AssetLib/FBX/FBXImporter.cpp | 13 +++++++------ code/AssetLib/Obj/ObjFileImporter.cpp | 15 ++++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/code/AssetLib/FBX/FBXImporter.cpp b/code/AssetLib/FBX/FBXImporter.cpp index 0ecb10daa..f80b65cd4 100644 --- a/code/AssetLib/FBX/FBXImporter.cpp +++ b/code/AssetLib/FBX/FBXImporter.cpp @@ -141,8 +141,11 @@ void FBXImporter::SetupProperties(const Importer *pImp) { // ------------------------------------------------------------------------------------------------ // Imports the given file into the given scene structure. void FBXImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { - IOStream* pStream = pIOHandler->Open(pFile, "rb"); - if (!pStream) { + auto streamCloser = [&](IOStream *pStream) { + pIOHandler->Close(pStream); + }; + std::unique_ptr stream(pIOHandler->Open(pFile, "rb"), streamCloser); + if (!stream) { ThrowException("Could not open file for reading"); } @@ -154,13 +157,11 @@ void FBXImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy // streaming for its output data structures so the net win with // streaming input data would be very low. std::vector contents; - contents.resize(pStream->FileSize() + 1); - pStream->Read(&*contents.begin(), 1, contents.size() - 1); + contents.resize(stream->FileSize() + 1); + stream->Read(&*contents.begin(), 1, contents.size() - 1); contents[contents.size() - 1] = 0; const char *const begin = &*contents.begin(); - pIOHandler->Close(pStream); - // broadphase tokenizing pass in which we identify the core // syntax elements of FBX (brackets, commas, key:value mappings) TokenList tokens; diff --git a/code/AssetLib/Obj/ObjFileImporter.cpp b/code/AssetLib/Obj/ObjFileImporter.cpp index 2f330b729..4fa122c45 100644 --- a/code/AssetLib/Obj/ObjFileImporter.cpp +++ b/code/AssetLib/Obj/ObjFileImporter.cpp @@ -107,22 +107,25 @@ const aiImporterDesc *ObjFileImporter::GetInfo() const { void ObjFileImporter::InternReadFile(const std::string &file, aiScene *pScene, IOSystem *pIOHandler) { // Read file into memory static const std::string mode = "rb"; - IOStream *pFileStream = pIOHandler->Open(file, mode); - if (!pFileStream) { + auto streamCloser = [&](IOStream *pStream) { + pIOHandler->Close(pStream); + }; + std::unique_ptr fileStream(pIOHandler->Open(file, mode), streamCloser); + if (!fileStream.get()) { throw DeadlyImportError("Failed to open file " + file + "."); } // Get the file-size and validate it, throwing an exception when fails - size_t fileSize = pFileStream->FileSize(); + size_t fileSize = fileStream->FileSize(); if (fileSize < ObjMinSize) { throw DeadlyImportError("OBJ-file is too small."); } IOStreamBuffer streamedBuffer; - streamedBuffer.open(pFileStream); + streamedBuffer.open(fileStream.get()); // Allocate buffer and read file into it - //TextFileToBuffer( pFileStream,m_Buffer); + //TextFileToBuffer( fileStream.get(),m_Buffer); // Get the model name std::string modelName, folderName; @@ -145,8 +148,6 @@ void ObjFileImporter::InternReadFile(const std::string &file, aiScene *pScene, I streamedBuffer.close(); - pIOHandler->Close(pFileStream); - // Clean up allocated storage for the next import m_Buffer.clear(); From 542d784457e591014a3fe244b552c7885f958a33 Mon Sep 17 00:00:00 2001 From: Chananya Freiman Date: Wed, 2 Sep 2020 02:52:56 +0300 Subject: [PATCH 6/8] Update Jassimp's AiTextureType.java The newer PBR enums are missing, making it impossible to import many models. --- .../jassimp/src/jassimp/AiTextureType.java | 190 +++++++++--------- 1 file changed, 98 insertions(+), 92 deletions(-) diff --git a/port/jassimp/jassimp/src/jassimp/AiTextureType.java b/port/jassimp/jassimp/src/jassimp/AiTextureType.java index 6b3e642e0..9b236ee94 100644 --- a/port/jassimp/jassimp/src/jassimp/AiTextureType.java +++ b/port/jassimp/jassimp/src/jassimp/AiTextureType.java @@ -56,109 +56,115 @@ package jassimp; * regardless which 3D tool they're using. */ public enum AiTextureType { - /** - * The texture is combined with the result of the diffuse - * lighting equation. + /** Dummy value. + * + * No texture, but the value to be used as 'texture semantic' + * (#aiMaterialProperty::mSemantic) for all material properties + * *not* related to textures. + */ + NONE(0), + + /** LEGACY API MATERIALS + * Legacy refers to materials which + * Were originally implemented in the specifications around 2000. + * These must never be removed, as most engines support them. + */ + + /** The texture is combined with the result of the diffuse + * lighting equation. + */ + DIFFUSE(1), + + /** The texture is combined with the result of the specular + * lighting equation. + */ + SPECULAR(2), + + /** The texture is combined with the result of the ambient + * lighting equation. + */ + AMBIENT(3), + + /** The texture is added to the result of the lighting + * calculation. It isn't influenced by incoming light. + */ + EMISSIVE(4), + + /** The texture is a height map. + * + * By convention, higher gray-scale values stand for + * higher elevations from the base height. + */ + HEIGHT(5), + + /** The texture is a (tangent space) normal-map. + * + * Again, there are several conventions for tangent-space + * normal maps. Assimp does (intentionally) not + * distinguish here. + */ + NORMALS(6), + + /** The texture defines the glossiness of the material. + * + * The glossiness is in fact the exponent of the specular + * (phong) lighting equation. Usually there is a conversion + * function defined to map the linear color values in the + * texture to a suitable exponent. Have fun. */ - DIFFUSE(0x1), + SHININESS(7), - - /** - * The texture is combined with the result of the specular - * lighting equation. + /** The texture defines per-pixel opacity. + * + * Usually 'white' means opaque and 'black' means + * 'transparency'. Or quite the opposite. Have fun. */ - SPECULAR(0x2), + OPACITY(8), - - /** - * The texture is combined with the result of the ambient - * lighting equation. + /** Displacement texture + * + * The exact purpose and format is application-dependent. + * Higher color values stand for higher vertex displacements. */ - AMBIENT(0x3), + DISPLACEMENT(9), - - /** - * The texture is added to the result of the lighting - * calculation. It isn't influenced by incoming light. + /** Lightmap texture (aka Ambient Occlusion) + * + * Both 'Lightmaps' and dedicated 'ambient occlusion maps' are + * covered by this material property. The texture contains a + * scaling value for the final color value of a pixel. Its + * intensity is not affected by incoming light. */ - EMISSIVE(0x4), + LIGHTMAP(10), - - /** - * The texture is a height map.

- * - * By convention, higher gray-scale values stand for - * higher elevations from the base height. + /** Reflection texture + * + * Contains the color of a perfect mirror reflection. + * Rarely used, almost never for real-time applications. */ - HEIGHT(0x5), + REFLECTION(11), - - /** - * The texture is a (tangent space) normal-map.

- * - * Again, there are several conventions for tangent-space - * normal maps. Assimp does (intentionally) not distinguish here. + /** PBR Materials + * PBR definitions from maya and other modelling packages now use this standard. + * This was originally introduced around 2012. + * Support for this is in game engines like Godot, Unreal or Unity3D. + * Modelling packages which use this are very common now. + */ + + BASE_COLOR(12), + NORMAL_CAMERA(13), + EMISSION_COLOR(14), + METALNESS(15), + DIFFUSE_ROUGHNESS(16), + AMBIENT_OCCLUSION(17), + + /** Unknown texture + * + * A texture reference that does not match any of the definitions + * above is considered to be 'unknown'. It is still imported, + * but is excluded from any further post-processing. */ - NORMALS(0x6), - - - /** - * The texture defines the glossiness of the material.

- * - * The glossiness is in fact the exponent of the specular - * (phong) lighting equation. Usually there is a conversion - * function defined to map the linear color values in the - * texture to a suitable exponent. Have fun. - */ - SHININESS(0x7), - - - /** - * The texture defines per-pixel opacity.

- * - * Usually 'white' means opaque and 'black' means - * 'transparency'. Or quite the opposite. Have fun. - */ - OPACITY(0x8), - - - /** - * Displacement texture.

- * - * The exact purpose and format is application-dependent. - * Higher color values stand for higher vertex displacements. - */ - DISPLACEMENT(0x9), - - - /** - * Lightmap texture (aka Ambient Occlusion).

- * - * Both 'Lightmaps' and dedicated 'ambient occlusion maps' are - * covered by this material property. The texture contains a - * scaling value for the final color value of a pixel. Its - * intensity is not affected by incoming light. - */ - LIGHTMAP(0xA), - - - /** - * Reflection texture.

- * - * Contains the color of a perfect mirror reflection. - * Rarely used, almost never for real-time applications. - */ - REFLECTION(0xB), - - - /** - * Unknown texture.

- * - * A texture reference that does not match any of the definitions - * above is considered to be 'unknown'. It is still imported, - * but is excluded from any further postprocessing. - */ - UNKNOWN(0xC); + UNKNOWN(18); /** From 9053dfea05d149a54ae291327ebb12f2372ffc38 Mon Sep 17 00:00:00 2001 From: Gargaj Date: Wed, 2 Sep 2020 16:28:12 +0200 Subject: [PATCH 7/8] add missing define to glTF importer --- code/AssetLib/glTF/glTFCommon.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code/AssetLib/glTF/glTFCommon.cpp b/code/AssetLib/glTF/glTFCommon.cpp index 2c46a46e3..6bea18a0a 100644 --- a/code/AssetLib/glTF/glTFCommon.cpp +++ b/code/AssetLib/glTF/glTFCommon.cpp @@ -38,6 +38,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ +#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER + #include "AssetLib/glTF/glTFCommon.h" namespace glTFCommon { @@ -187,3 +189,5 @@ bool ParseDataURI(const char *const_uri, size_t uriLen, DataURI &out) { } // namespace Util } // namespace glTFCommon + +#endif From f3b25b999be1589e47d914258f3bd76306abbe6c Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Sat, 5 Sep 2020 23:17:11 +0200 Subject: [PATCH 8/8] Fix an unreferenced formal parameter warning on MSVC when no exporter is built --- code/Common/Exporter.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/Common/Exporter.cpp b/code/Common/Exporter.cpp index 6b3a50346..207b93fc7 100644 --- a/code/Common/Exporter.cpp +++ b/code/Common/Exporter.cpp @@ -140,6 +140,8 @@ void ExportAssimp2Json(const char* , IOSystem*, const aiScene* , const Assimp::E #endif static void setupExporterArray(std::vector &exporters) { + (void)exporters; + #ifndef ASSIMP_BUILD_NO_COLLADA_EXPORTER exporters.push_back(Exporter::ExportFormatEntry("collada", "COLLADA - Digital Asset Exchange Schema", "dae", &ExportSceneCollada)); #endif