From f57e7221c07f385cebcc457d294e90c446995d41 Mon Sep 17 00:00:00 2001 From: ywang Date: Wed, 10 Jun 2020 13:23:29 -0700 Subject: [PATCH 1/2] temp --- code/AssetLib/glTF2/glTF2Exporter.cpp | 17 +++++++++++++++-- code/Common/Exporter.cpp | 2 +- include/assimp/Exporter.hpp | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 566f95e80..98eb79e57 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -1,4 +1,4 @@ -/* +/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- @@ -115,7 +115,20 @@ glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const ai ExportScene(); ExportAnimations(); - + + //wangyi 0608 + if(mProperties->HasPropertyCallback("extras")) + { + std::function ExportExtras = mProperties->GetPropertyCallback("extras"); + char* ret = (char*)ExportExtras((void*)mAsset.get()); + + Document extrasD; + extrasD.Parse(ret); + std::string strHello = extrasD["hello"].GetString(); + + printf("wangyi 0608 ret: %s\r\n", ret); + } + AssetWriter writer(*mAsset); if (isBinary) { diff --git a/code/Common/Exporter.cpp b/code/Common/Exporter.cpp index e8ee188e6..5fef455bb 100644 --- a/code/Common/Exporter.cpp +++ b/code/Common/Exporter.cpp @@ -587,7 +587,7 @@ ExportProperties::ExportProperties(const ExportProperties &other) } //wangyi 0608 -bool ExportProperties::SetPropertyCallback(const char *szName, std::function &f) { +bool ExportProperties::SetPropertyCallback(const char *szName, const std::function &f) { return SetGenericProperty>(mCallbackProperties, szName, f); } std::function ExportProperties::GetPropertyCallback(const char *szName) const { diff --git a/include/assimp/Exporter.hpp b/include/assimp/Exporter.hpp index 4abea6ad0..87c12f374 100644 --- a/include/assimp/Exporter.hpp +++ b/include/assimp/Exporter.hpp @@ -394,7 +394,7 @@ public: bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue); //wangyi 0608 - bool SetPropertyCallback(const char *szName, std::function &f); + bool SetPropertyCallback(const char *szName, const std::function &f); // ------------------------------------------------------------------- /** Get a configuration property. From e65434bf8241a5408ff213dc315d5b8d3ed2f60e Mon Sep 17 00:00:00 2001 From: ywang Date: Thu, 11 Jun 2020 17:37:06 -0700 Subject: [PATCH 2/2] extra callback --- code/AssetLib/glTF2/glTF2Asset.h | 3 ++- code/AssetLib/glTF2/glTF2AssetWriter.inl | 6 +++++- code/AssetLib/glTF2/glTF2Exporter.cpp | 10 ++-------- code/Common/Exporter.cpp | 5 ++--- include/assimp/Exporter.hpp | 12 +++--------- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Asset.h b/code/AssetLib/glTF2/glTF2Asset.h index fc0fe1544..de252b329 100644 --- a/code/AssetLib/glTF2/glTF2Asset.h +++ b/code/AssetLib/glTF2/glTF2Asset.h @@ -1,4 +1,4 @@ -/* +/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- @@ -1006,6 +1006,7 @@ public: } extensionsRequired; AssetMetadata asset; + Value* extras = nullptr; // Dictionaries for each type of object diff --git a/code/AssetLib/glTF2/glTF2AssetWriter.inl b/code/AssetLib/glTF2/glTF2AssetWriter.inl index 361af40cd..0a4d0b2f4 100644 --- a/code/AssetLib/glTF2/glTF2AssetWriter.inl +++ b/code/AssetLib/glTF2/glTF2AssetWriter.inl @@ -1,4 +1,4 @@ -/* +/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- @@ -600,6 +600,10 @@ namespace glTF2 { if (mAsset.scene) { mDoc.AddMember("scene", mAsset.scene->index, mAl); } + + if(mAsset.extras) { + mDoc.AddMember("extras", *mAsset.extras, mAl); + } } inline void AssetWriter::WriteFile(const char* path) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 98eb79e57..537787eb7 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -116,17 +116,11 @@ glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const ai ExportAnimations(); - //wangyi 0608 + // export extras if(mProperties->HasPropertyCallback("extras")) { std::function ExportExtras = mProperties->GetPropertyCallback("extras"); - char* ret = (char*)ExportExtras((void*)mAsset.get()); - - Document extrasD; - extrasD.Parse(ret); - std::string strHello = extrasD["hello"].GetString(); - - printf("wangyi 0608 ret: %s\r\n", ret); + mAsset->extras = (rapidjson::Value*)ExportExtras(0); } AssetWriter writer(*mAsset); diff --git a/code/Common/Exporter.cpp b/code/Common/Exporter.cpp index 5fef455bb..30ab3a813 100644 --- a/code/Common/Exporter.cpp +++ b/code/Common/Exporter.cpp @@ -581,19 +581,18 @@ ExportProperties::ExportProperties(const ExportProperties &other) , mFloatProperties(other.mFloatProperties) , mStringProperties(other.mStringProperties) , mMatrixProperties(other.mMatrixProperties) -//wangyi 0608 , mCallbackProperties(other.mCallbackProperties){ // empty } -//wangyi 0608 bool ExportProperties::SetPropertyCallback(const char *szName, const std::function &f) { return SetGenericProperty>(mCallbackProperties, szName, f); } + std::function ExportProperties::GetPropertyCallback(const char *szName) const { return GetGenericProperty>(mCallbackProperties, szName, 0); } -//wangyi 0608 + bool ExportProperties::HasPropertyCallback(const char *szName) const { return HasGenericProperty>(mCallbackProperties, szName); } diff --git a/include/assimp/Exporter.hpp b/include/assimp/Exporter.hpp index 87c12f374..8e47e24db 100644 --- a/include/assimp/Exporter.hpp +++ b/include/assimp/Exporter.hpp @@ -54,7 +54,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "cexport.h" #include -//wangyi 0608 #include namespace Assimp { @@ -332,7 +331,6 @@ public: typedef std::map FloatPropertyMap; typedef std::map StringPropertyMap; typedef std::map MatrixPropertyMap; - //wangyi 0608 typedef std::map> CallbackPropertyMap; public: @@ -392,8 +390,7 @@ public: * @see SetPropertyInteger() */ bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue); - - //wangyi 0608 + bool SetPropertyCallback(const char *szName, const std::function &f); // ------------------------------------------------------------------- @@ -448,7 +445,6 @@ public: const aiMatrix4x4 GetPropertyMatrix(const char *szName, const aiMatrix4x4 &sErrorReturn = aiMatrix4x4()) const; - //wangyi 0608 std::function GetPropertyCallback(const char* szName) const; // ------------------------------------------------------------------- @@ -476,8 +472,7 @@ public: * @see HasPropertyMatrix() */ bool HasPropertyMatrix(const char *szName) const; - - //wangyi 0608 + bool HasPropertyCallback(const char *szName) const; protected: @@ -492,8 +487,7 @@ protected: /** List of Matrix properties */ MatrixPropertyMap mMatrixProperties; - - //wangyi 0608 + CallbackPropertyMap mCallbackProperties; };