[F] Conditional compilation for Open3DGC-extension.
authorAlexandr Arutjunov <smal.root@gmail.com>
Sun, 14 Aug 2016 13:27:16 +0000 (16:27 +0300)
committerAlexandr Arutjunov <smal.root@gmail.com>
Sun, 14 Aug 2016 13:27:16 +0000 (16:27 +0300)
[F] Flag comp_allow did not reset when mesh can not be encoded.

code/CMakeLists.txt
code/glTFAsset.h
code/glTFAsset.inl
code/glTFAssetWriter.inl
code/glTFExporter.cpp
code/glTFImporter.cpp

index 44336b0..1b964a3 100644 (file)
@@ -707,9 +707,25 @@ SET ( open3dgc_SRCS
   ../contrib/Open3DGC/o3dgcDynamicVectorEncoder.cpp
   ../contrib/Open3DGC/o3dgcTools.cpp
   ../contrib/Open3DGC/o3dgcTriangleFans.cpp
+  ../contrib/Open3DGC/o3dgcTimer.h
 )
 SOURCE_GROUP( open3dgc FILES ${open3dgc_SRCS})
 
+# Check dependencies for glTF importer with Open3DGC-compression.
+# RT-extensions is used in "contrib/Open3DGC/o3dgcTimer.h" for collecting statistics. Pointed file
+# has implementation for different platforms: WIN32, __MACH__ and other ("else" block).
+FIND_PACKAGE(RT QUIET)
+IF (RT_FOUND OR MSVC)
+  ADD_DEFINITIONS( -DASSIMP_IMPORTER_GLTF_USE_OPEN3DGC )
+  IF (NOT RT_FOUND)
+       SET (RT_LIBRARY "")
+  ENDIF (NOT RT_FOUND)
+ELSE ()
+  SET (open3dgc_SRCS "")
+  SET (RT_LIBRARY "")
+  MESSAGE (INFO " RT-extension not found. glTF import/export will be built without Open3DGC-compression.")
+  #!TODO: off course is better to remove statistics timers from o3dgc codec. Or propose to choose what to use.
+ENDIF ()
 
 INCLUDE_DIRECTORIES( "../contrib/rapidjson/include" )
 INCLUDE_DIRECTORIES( "../contrib" )
@@ -767,10 +783,6 @@ SET( assimp_src
 )
 ADD_DEFINITIONS( -DOPENDDLPARSER_BUILD )
 
-if (open3dgc_SRCS)
-       SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -lrt")
-endif (open3dgc_SRCS)
-
 INCLUDE_DIRECTORIES(
   ../contrib/openddlparser/include
 )
@@ -837,6 +849,11 @@ else (UNZIP_FOUND)
   INCLUDE_DIRECTORIES("../")
 endif (UNZIP_FOUND)
 
+# Add RT-extension library for glTF importer with Open3DGC-compression.
+IF (RT_FOUND AND ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC)
+  TARGET_LINK_LIBRARIES(assimp ${RT_LIBRARY})
+ENDIF (RT_FOUND AND ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC)
+
 INSTALL( TARGETS assimp
   LIBRARY DESTINATION ${ASSIMP_LIB_INSTALL_DIR}
   ARCHIVE DESTINATION ${ASSIMP_LIB_INSTALL_DIR}
index 237158d..f09e979 100644 (file)
@@ -716,9 +716,13 @@ namespace glTF
                {
                        /// \enum EType
                        /// Type of extension.
-                       enum class EType
+                       enum EType
                        {
-                               Compression_Open3DGC ///< Compression of mesh data using Open3DGC algorythm.
+                               #ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
+                                       Compression_Open3DGC,///< Compression of mesh data using Open3DGC algorythm.
+                               #endif
+
+                               Unknown
                        };
 
                        EType Type;///< Type of extension.
@@ -731,27 +735,29 @@ namespace glTF
                        {}
                };
 
-               /// \struct SCompression_Open3DGC
-               /// Compression of mesh data using Open3DGC algorythm.
-               struct SCompression_Open3DGC : public SExtension
-               {
-                       using SExtension::Type;
-
-                       std::string Buffer;///< ID of "buffer" used for storing compressed data.
-                       size_t Offset;///< Offset in "bufferView" where compressed data are stored.
-                       size_t Count;///< Count of elements in compressed data. Is always equivalent to size in bytes: look comments for "Type" and "Component_Type".
-                       bool Binary;///< If true then "binary" mode is used for coding, if false - "ascii" mode.
-                       size_t IndicesCount;///< Count of indices in mesh.
-                       size_t VerticesCount;///< Count of vertices in mesh.
-                       // AttribType::Value Type;///< Is always "SCALAR".
-                       // ComponentType Component_Type;///< Is always "ComponentType_UNSIGNED_BYTE" (5121).
-
-                       /// \fn SCompression_Open3DGC
-                       /// Constructor.
-                       SCompression_Open3DGC()
-                               : SExtension(EType::Compression_Open3DGC)
-                       {}
-               };
+               #ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
+                       /// \struct SCompression_Open3DGC
+                       /// Compression of mesh data using Open3DGC algorythm.
+                       struct SCompression_Open3DGC : public SExtension
+                       {
+                               using SExtension::Type;
+
+                               std::string Buffer;///< ID of "buffer" used for storing compressed data.
+                               size_t Offset;///< Offset in "bufferView" where compressed data are stored.
+                               size_t Count;///< Count of elements in compressed data. Is always equivalent to size in bytes: look comments for "Type" and "Component_Type".
+                               bool Binary;///< If true then "binary" mode is used for coding, if false - "ascii" mode.
+                               size_t IndicesCount;///< Count of indices in mesh.
+                               size_t VerticesCount;///< Count of vertices in mesh.
+                               // AttribType::Value Type;///< Is always "SCALAR".
+                               // ComponentType Component_Type;///< Is always "ComponentType_UNSIGNED_BYTE" (5121).
+
+                               /// \fn SCompression_Open3DGC
+                               /// Constructor.
+                               SCompression_Open3DGC()
+                               : SExtension(Compression_Open3DGC)
+                               {}
+                       };
+               #endif
 
         std::vector<Primitive> primitives;
                std::list<SExtension*> Extension;///< List of extensions used in mesh.
@@ -760,7 +766,7 @@ namespace glTF
 
                /// \fn ~Mesh()
                /// Destructor.
-               ~Mesh() { for(auto e : Extension) { delete e; }; }
+               ~Mesh() { for(std::list<SExtension*>::iterator it = Extension.begin(), it_end = Extension.end(); it != it_end; it++) { delete *it; }; }
 
                /// \fn void Read(Value& pJSON_Object, Asset& pAsset_Root)
                /// Get mesh data from JSON-object and place them to root asset.
@@ -768,11 +774,13 @@ namespace glTF
                /// \param [out] pAsset_Root - reference to root assed where data will be stored.
                void Read(Value& pJSON_Object, Asset& pAsset_Root);
 
-               /// \fn void Decode_O3DGC(const SCompression_Open3DGC& pCompression_Open3DGC, Asset& pAsset_Root)
-               /// Decode part of "buffer" which encoded with Open3DGC algorithm.
-               /// \param [in] pCompression_Open3DGC - reference to structure which describe encoded region.
-               /// \param [out] pAsset_Root - reference to root assed where data will be stored.
-               void Decode_O3DGC(const SCompression_Open3DGC& pCompression_Open3DGC, Asset& pAsset_Root);
+               #ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
+                       /// \fn void Decode_O3DGC(const SCompression_Open3DGC& pCompression_Open3DGC, Asset& pAsset_Root)
+                       /// Decode part of "buffer" which encoded with Open3DGC algorithm.
+                       /// \param [in] pCompression_Open3DGC - reference to structure which describe encoded region.
+                       /// \param [out] pAsset_Root - reference to root assed where data will be stored.
+                       void Decode_O3DGC(const SCompression_Open3DGC& pCompression_Open3DGC, Asset& pAsset_Root);
+               #endif
     };
 
     struct Node : public Object
index 382b37d..89d5611 100644 (file)
@@ -43,8 +43,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 // Header files, Assimp
 #include <assimp/DefaultLogger.hpp>
 
-// Header files, Open3DGC.
-#include <Open3DGC/o3dgcSC3DMCDecoder.h>
+#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
+       // Header files, Open3DGC.
+#      include <Open3DGC/o3dgcSC3DMCDecoder.h>
+#endif
 
 namespace glTF {
 
@@ -820,7 +822,8 @@ inline void Mesh::Read(Value& pJSON_Object, Asset& pAsset_Root)
 
        for(Value::MemberIterator it_memb = json_extensions->MemberBegin(); it_memb != json_extensions->MemberEnd(); it_memb++)
        {
-               if(it_memb->name.GetString() == std::string("Open3DGC-compression"))
+#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
+        if(it_memb->name.GetString() == std::string("Open3DGC-compression"))
                {
                        // Search for compressed data.
                        // Compressed data contain description of part of "buffer" which is encoded. This part must be decoded and
@@ -871,6 +874,7 @@ inline void Mesh::Read(Value& pJSON_Object, Asset& pAsset_Root)
                        Extension.push_back(ext_o3dgc);// store info in mesh extensions list.
                }// if(it_memb->name.GetString() == "Open3DGC-compression")
                else
+#endif
                {
                        throw DeadlyImportError(std::string("GLTF: Unknown mesh extension: \"") + it_memb->name.GetString() + "\".");
                }
@@ -881,6 +885,7 @@ mr_skip_extensions:
        return;// After label some operators must be present.
 }
 
+#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
 inline void Mesh::Decode_O3DGC(const SCompression_Open3DGC& pCompression_Open3DGC, Asset& pAsset_Root)
 {
 typedef unsigned short IndicesType;///< \sa glTFExporter::ExportMeshes.
@@ -1038,6 +1043,7 @@ Ref<Buffer> buf = pAsset_Root.buffers.Get(pCompression_Open3DGC.Buffer);
        // No. Do not delete "output_data". After calling "EncodedRegion_Mark" bufferView is owner of "output_data".
        // "delete [] output_data;"
 }
+#endif
 
 inline void Camera::Read(Value& obj, Asset& r)
 {
index d76bb5d..78bc759 100644 (file)
@@ -60,7 +60,7 @@ namespace glTF {
                 val.PushBack(r[i], al);
             }
             return val;
-        };
+        }
 
         template<class T>
         inline void AddRefsVector(Value& obj, const char* fieldId, std::vector< Ref<T> >& v, MemoryPoolAllocator<>& al) {
@@ -72,7 +72,7 @@ namespace glTF {
                 lst.PushBack(StringRef(v[i]->id), al);
             }
             obj.AddMember(StringRef(fieldId), lst, al);
-        };
+        }
 
 
     }
@@ -212,6 +212,7 @@ namespace glTF {
                        {
                                switch(ptr_ext->Type)
                                {
+#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
                                        case Mesh::SExtension::EType::Compression_Open3DGC:
                                                {
                                                        Value json_comp_data;
@@ -241,6 +242,7 @@ namespace glTF {
                                                }
 
                                                break;
+#endif
                                        default:
                                                throw DeadlyImportError("GLTF: Can not write mesh: unknown mesh extension, only Open3DGC is supported.");
                                }// switch(ptr_ext->Type)
index 7379859..fb60183 100644 (file)
@@ -61,8 +61,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include "glTFAssetWriter.h"
 
-// Header files, Open3DGC.
-#include <Open3DGC/o3dgcSC3DMCEncoder.h>
+#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
+       // Header files, Open3DGC.
+#      include <Open3DGC/o3dgcSC3DMCEncoder.h>
+#endif
 
 using namespace rapidjson;
 
@@ -277,7 +279,12 @@ bool comp_allow;// Point that data of current mesh can be compressed.
                const aiMesh* aim = mScene->mMeshes[idx_mesh];
 
                // Check if compressing requested and mesh can be encoded.
+#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
                comp_allow = mProperties->GetPropertyBool("extensions.Open3DGC.use", false);
+#else
+               comp_allow = false;
+#endif
+
                if(comp_allow && (aim->mPrimitiveTypes == aiPrimitiveType_TRIANGLE) && (aim->mNumVertices > 0) && (aim->mNumFaces > 0))
                {
                        idx_srcdata_tc.clear();
@@ -293,6 +300,7 @@ bool comp_allow;// Point that data of current mesh can be compressed.
                                msg = "mesh must has vertices and faces.";
 
                        DefaultLogger::get()->warn("GLTF: can not use Open3DGC-compression: " + msg);
+            comp_allow = false;
                }
 
         std::string meshId = mAsset->FindUniqueID(aim->mName.C_Str(), "mesh");
@@ -365,6 +373,7 @@ bool comp_allow;// Point that data of current mesh can be compressed.
                ///TODO: animation: weights, joints.
                if(comp_allow)
                {
+#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
                        // Only one type of compression supported at now - Open3DGC.
                        //
                        o3dgc::BinaryStream bs;
@@ -449,6 +458,7 @@ bool comp_allow;// Point that data of current mesh can be compressed.
                        ext->VerticesCount = comp_o3dgc_ifs.GetNCoord();
                        // And assign to mesh.
                        m->Extension.push_back(ext);
+#endif
                }// if(comp_allow)
        }// for (unsigned int i = 0; i < mScene->mNumMeshes; ++i) {
 }
index 5cdd856..0444296 100644 (file)
@@ -264,6 +264,7 @@ void glTFImporter::ImportMeshes(glTF::Asset& r)
                {
                        for(Mesh::SExtension* cur_ext : mesh.Extension)
                        {
+#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
                                if(cur_ext->Type == Mesh::SExtension::EType::Compression_Open3DGC)
                                {
                                        // Limitations for meshes when using Open3DGC-compression.
@@ -282,8 +283,10 @@ void glTFImporter::ImportMeshes(glTF::Asset& r)
                                        buf->EncodedRegion_SetCurrent(mesh.id);
                                }
                                else
+#endif
                                {
-                                       throw DeadlyImportError("GLTF: Can not import mesh: unknown mesh extension, only Open3DGC is supported.");
+                                       throw DeadlyImportError("GLTF: Can not import mesh: unknown mesh extension (code: \"" + std::to_string(cur_ext->Type) +
+                                                                                       "\"), only Open3DGC is supported.");
                                }
                        }
                }// if(mesh.Extension.size() > 0)