Bläddra i källkod

[F] Conditional compilation for Open3DGC-extension.
[F] Flag comp_allow did not reset when mesh can not be encoded.

Alexandr Arutjunov 9 år sedan
förälder
incheckning
48f8c117e2
6 ändrade filer med 87 tillägg och 41 borttagningar
  1. 21 4
      code/CMakeLists.txt
  2. 37 29
      code/glTFAsset.h
  3. 9 3
      code/glTFAsset.inl
  4. 4 2
      code/glTFAssetWriter.inl
  5. 12 2
      code/glTFExporter.cpp
  6. 4 1
      code/glTFImporter.cpp

+ 21 - 4
code/CMakeLists.txt

@@ -707,9 +707,25 @@ SET ( open3dgc_SRCS
   ../contrib/Open3DGC/o3dgcDynamicVectorEncoder.cpp
   ../contrib/Open3DGC/o3dgcDynamicVectorEncoder.cpp
   ../contrib/Open3DGC/o3dgcTools.cpp
   ../contrib/Open3DGC/o3dgcTools.cpp
   ../contrib/Open3DGC/o3dgcTriangleFans.cpp
   ../contrib/Open3DGC/o3dgcTriangleFans.cpp
+  ../contrib/Open3DGC/o3dgcTimer.h
 )
 )
 SOURCE_GROUP( open3dgc FILES ${open3dgc_SRCS})
 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/rapidjson/include" )
 INCLUDE_DIRECTORIES( "../contrib" )
 INCLUDE_DIRECTORIES( "../contrib" )
@@ -767,10 +783,6 @@ SET( assimp_src
 )
 )
 ADD_DEFINITIONS( -DOPENDDLPARSER_BUILD )
 ADD_DEFINITIONS( -DOPENDDLPARSER_BUILD )
 
 
-if (open3dgc_SRCS)
-	SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -lrt")
-endif (open3dgc_SRCS)
-
 INCLUDE_DIRECTORIES(
 INCLUDE_DIRECTORIES(
   ../contrib/openddlparser/include
   ../contrib/openddlparser/include
 )
 )
@@ -837,6 +849,11 @@ else (UNZIP_FOUND)
   INCLUDE_DIRECTORIES("../")
   INCLUDE_DIRECTORIES("../")
 endif (UNZIP_FOUND)
 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
 INSTALL( TARGETS assimp
   LIBRARY DESTINATION ${ASSIMP_LIB_INSTALL_DIR}
   LIBRARY DESTINATION ${ASSIMP_LIB_INSTALL_DIR}
   ARCHIVE DESTINATION ${ASSIMP_LIB_INSTALL_DIR}
   ARCHIVE DESTINATION ${ASSIMP_LIB_INSTALL_DIR}

+ 37 - 29
code/glTFAsset.h

@@ -716,9 +716,13 @@ namespace glTF
 		{
 		{
 			/// \enum EType
 			/// \enum EType
 			/// Type of extension.
 			/// 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.
 			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::vector<Primitive> primitives;
 		std::list<SExtension*> Extension;///< List of extensions used in mesh.
 		std::list<SExtension*> Extension;///< List of extensions used in mesh.
@@ -760,7 +766,7 @@ namespace glTF
 
 
 		/// \fn ~Mesh()
 		/// \fn ~Mesh()
 		/// Destructor.
 		/// 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)
 		/// \fn void Read(Value& pJSON_Object, Asset& pAsset_Root)
 		/// Get mesh data from JSON-object and place them to root asset.
 		/// 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.
 		/// \param [out] pAsset_Root - reference to root assed where data will be stored.
 		void Read(Value& pJSON_Object, Asset& pAsset_Root);
 		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
     struct Node : public Object

+ 9 - 3
code/glTFAsset.inl

@@ -43,8 +43,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 // Header files, Assimp
 // Header files, Assimp
 #include <assimp/DefaultLogger.hpp>
 #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 {
 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++)
 	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.
 			// Search for compressed data.
 			// Compressed data contain description of part of "buffer" which is encoded. This part must be decoded and
 			// 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.
 			Extension.push_back(ext_o3dgc);// store info in mesh extensions list.
 		}// if(it_memb->name.GetString() == "Open3DGC-compression")
 		}// if(it_memb->name.GetString() == "Open3DGC-compression")
 		else
 		else
+#endif
 		{
 		{
 			throw DeadlyImportError(std::string("GLTF: Unknown mesh extension: \"") + it_memb->name.GetString() + "\".");
 			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.
 	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)
 inline void Mesh::Decode_O3DGC(const SCompression_Open3DGC& pCompression_Open3DGC, Asset& pAsset_Root)
 {
 {
 typedef unsigned short IndicesType;///< \sa glTFExporter::ExportMeshes.
 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".
 	// No. Do not delete "output_data". After calling "EncodedRegion_Mark" bufferView is owner of "output_data".
 	// "delete [] output_data;"
 	// "delete [] output_data;"
 }
 }
+#endif
 
 
 inline void Camera::Read(Value& obj, Asset& r)
 inline void Camera::Read(Value& obj, Asset& r)
 {
 {

+ 4 - 2
code/glTFAssetWriter.inl

@@ -60,7 +60,7 @@ namespace glTF {
                 val.PushBack(r[i], al);
                 val.PushBack(r[i], al);
             }
             }
             return val;
             return val;
-        };
+        }
 
 
         template<class T>
         template<class T>
         inline void AddRefsVector(Value& obj, const char* fieldId, std::vector< Ref<T> >& v, MemoryPoolAllocator<>& al) {
         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);
                 lst.PushBack(StringRef(v[i]->id), al);
             }
             }
             obj.AddMember(StringRef(fieldId), lst, al);
             obj.AddMember(StringRef(fieldId), lst, al);
-        };
+        }
 
 
 
 
     }
     }
@@ -212,6 +212,7 @@ namespace glTF {
 			{
 			{
 				switch(ptr_ext->Type)
 				switch(ptr_ext->Type)
 				{
 				{
+#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
 					case Mesh::SExtension::EType::Compression_Open3DGC:
 					case Mesh::SExtension::EType::Compression_Open3DGC:
 						{
 						{
 							Value json_comp_data;
 							Value json_comp_data;
@@ -241,6 +242,7 @@ namespace glTF {
 						}
 						}
 
 
 						break;
 						break;
+#endif
 					default:
 					default:
 						throw DeadlyImportError("GLTF: Can not write mesh: unknown mesh extension, only Open3DGC is supported.");
 						throw DeadlyImportError("GLTF: Can not write mesh: unknown mesh extension, only Open3DGC is supported.");
 				}// switch(ptr_ext->Type)
 				}// switch(ptr_ext->Type)

+ 12 - 2
code/glTFExporter.cpp

@@ -61,8 +61,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 
 #include "glTFAssetWriter.h"
 #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;
 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];
 		const aiMesh* aim = mScene->mMeshes[idx_mesh];
 
 
 		// Check if compressing requested and mesh can be encoded.
 		// Check if compressing requested and mesh can be encoded.
+#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
 		comp_allow = mProperties->GetPropertyBool("extensions.Open3DGC.use", false);
 		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))
 		if(comp_allow && (aim->mPrimitiveTypes == aiPrimitiveType_TRIANGLE) && (aim->mNumVertices > 0) && (aim->mNumFaces > 0))
 		{
 		{
 			idx_srcdata_tc.clear();
 			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.";
 				msg = "mesh must has vertices and faces.";
 
 
 			DefaultLogger::get()->warn("GLTF: can not use Open3DGC-compression: " + msg);
 			DefaultLogger::get()->warn("GLTF: can not use Open3DGC-compression: " + msg);
+            comp_allow = false;
 		}
 		}
 
 
         std::string meshId = mAsset->FindUniqueID(aim->mName.C_Str(), "mesh");
         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.
 		///TODO: animation: weights, joints.
 		if(comp_allow)
 		if(comp_allow)
 		{
 		{
+#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
 			// Only one type of compression supported at now - Open3DGC.
 			// Only one type of compression supported at now - Open3DGC.
 			//
 			//
 			o3dgc::BinaryStream bs;
 			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();
 			ext->VerticesCount = comp_o3dgc_ifs.GetNCoord();
 			// And assign to mesh.
 			// And assign to mesh.
 			m->Extension.push_back(ext);
 			m->Extension.push_back(ext);
+#endif
 		}// if(comp_allow)
 		}// if(comp_allow)
 	}// for (unsigned int i = 0; i < mScene->mNumMeshes; ++i) {
 	}// for (unsigned int i = 0; i < mScene->mNumMeshes; ++i) {
 }
 }

+ 4 - 1
code/glTFImporter.cpp

@@ -264,6 +264,7 @@ void glTFImporter::ImportMeshes(glTF::Asset& r)
 		{
 		{
 			for(Mesh::SExtension* cur_ext : mesh.Extension)
 			for(Mesh::SExtension* cur_ext : mesh.Extension)
 			{
 			{
+#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
 				if(cur_ext->Type == Mesh::SExtension::EType::Compression_Open3DGC)
 				if(cur_ext->Type == Mesh::SExtension::EType::Compression_Open3DGC)
 				{
 				{
 					// Limitations for meshes when using Open3DGC-compression.
 					// Limitations for meshes when using Open3DGC-compression.
@@ -282,8 +283,10 @@ void glTFImporter::ImportMeshes(glTF::Asset& r)
 					buf->EncodedRegion_SetCurrent(mesh.id);
 					buf->EncodedRegion_SetCurrent(mesh.id);
 				}
 				}
 				else
 				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)
 		}// if(mesh.Extension.size() > 0)