[F] Conditional compilation for Open3DGC-extension.

[F] Flag comp_allow did not reset when mesh can not be encoded.
pull/972/head
Alexandr Arutjunov 2016-08-14 16:27:16 +03:00
parent de70f5c028
commit 48f8c117e2
6 changed files with 85 additions and 39 deletions

View File

@ -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}

View File

@ -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,6 +735,7 @@ namespace glTF
{} {}
}; };
#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
/// \struct SCompression_Open3DGC /// \struct SCompression_Open3DGC
/// Compression of mesh data using Open3DGC algorythm. /// Compression of mesh data using Open3DGC algorythm.
struct SCompression_Open3DGC : public SExtension struct SCompression_Open3DGC : public SExtension
@ -749,9 +754,10 @@ namespace glTF
/// \fn SCompression_Open3DGC /// \fn SCompression_Open3DGC
/// Constructor. /// Constructor.
SCompression_Open3DGC() SCompression_Open3DGC()
: SExtension(EType::Compression_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);
#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
/// \fn void Decode_O3DGC(const SCompression_Open3DGC& pCompression_Open3DGC, Asset& pAsset_Root) /// \fn void Decode_O3DGC(const SCompression_Open3DGC& pCompression_Open3DGC, Asset& pAsset_Root)
/// Decode part of "buffer" which encoded with Open3DGC algorithm. /// Decode part of "buffer" which encoded with Open3DGC algorithm.
/// \param [in] pCompression_Open3DGC - reference to structure which describe encoded region. /// \param [in] pCompression_Open3DGC - reference to structure which describe encoded region.
/// \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 Decode_O3DGC(const SCompression_Open3DGC& pCompression_Open3DGC, Asset& pAsset_Root); void Decode_O3DGC(const SCompression_Open3DGC& pCompression_Open3DGC, Asset& pAsset_Root);
#endif
}; };
struct Node : public Object struct Node : public Object

View File

@ -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. #ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
#include <Open3DGC/o3dgcSC3DMCDecoder.h> // Header files, Open3DGC.
# include <Open3DGC/o3dgcSC3DMCDecoder.h>
#endif
namespace glTF { namespace glTF {
@ -820,6 +822,7 @@ 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++)
{ {
#ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
if(it_memb->name.GetString() == std::string("Open3DGC-compression")) if(it_memb->name.GetString() == std::string("Open3DGC-compression"))
{ {
// Search for compressed data. // Search for compressed data.
@ -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)
{ {

View File

@ -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)

View File

@ -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. #ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
#include <Open3DGC/o3dgcSC3DMCEncoder.h> // 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) {
} }

View File

@ -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)