Merge pull request #3280 from thomasbiang/extras_property_callback

Customize Extras in Gltf2 Exporter with ExporterProperty Callback
pull/3227/head^2
Kim Kulling 2020-07-11 22:56:38 +02:00 committed by GitHub
commit ec156e4da3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 9 deletions

View File

@ -1,4 +1,4 @@
/* /*
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
@ -1066,6 +1066,7 @@ public:
} extensionsRequired; } extensionsRequired;
AssetMetadata asset; AssetMetadata asset;
Value* extras = nullptr;
// Dictionaries for each type of object // Dictionaries for each type of object

View File

@ -1,4 +1,4 @@
/* /*
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
@ -616,6 +616,10 @@ namespace glTF2 {
if (mAsset.scene) { if (mAsset.scene) {
mDoc.AddMember("scene", mAsset.scene->index, mAl); mDoc.AddMember("scene", mAsset.scene->index, mAl);
} }
if(mAsset.extras) {
mDoc.AddMember("extras", *mAsset.extras, mAl);
}
} }
inline void AssetWriter::WriteFile(const char* path) inline void AssetWriter::WriteFile(const char* path)

View File

@ -1,4 +1,4 @@
/* /*
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
@ -116,6 +116,13 @@ glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const ai
ExportAnimations(); ExportAnimations();
// export extras
if(mProperties->HasPropertyCallback("extras"))
{
std::function<void*(void*)> ExportExtras = mProperties->GetPropertyCallback("extras");
mAsset->extras = (rapidjson::Value*)ExportExtras(0);
}
AssetWriter writer(*mAsset); AssetWriter writer(*mAsset);
if (isBinary) { if (isBinary) {

View File

@ -580,10 +580,23 @@ ExportProperties::ExportProperties(const ExportProperties &other)
: mIntProperties(other.mIntProperties) : mIntProperties(other.mIntProperties)
, mFloatProperties(other.mFloatProperties) , mFloatProperties(other.mFloatProperties)
, mStringProperties(other.mStringProperties) , mStringProperties(other.mStringProperties)
, mMatrixProperties(other.mMatrixProperties) { , mMatrixProperties(other.mMatrixProperties)
, mCallbackProperties(other.mCallbackProperties){
// empty // empty
} }
bool ExportProperties::SetPropertyCallback(const char *szName, const std::function<void *(void *)> &f) {
return SetGenericProperty<std::function<void *(void *)>>(mCallbackProperties, szName, f);
}
std::function<void *(void *)> ExportProperties::GetPropertyCallback(const char *szName) const {
return GetGenericProperty<std::function<void *(void *)>>(mCallbackProperties, szName, 0);
}
bool ExportProperties::HasPropertyCallback(const char *szName) const {
return HasGenericProperty<std::function<void *(void *)>>(mCallbackProperties, szName);
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Set a configuration property // Set a configuration property
bool ExportProperties::SetPropertyInteger(const char* szName, int iValue) { bool ExportProperties::SetPropertyInteger(const char* szName, int iValue) {

View File

@ -54,6 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "cexport.h" #include "cexport.h"
#include <map> #include <map>
#include <functional>
namespace Assimp { namespace Assimp {
@ -107,7 +108,8 @@ public:
} }
ExportFormatEntry() : ExportFormatEntry() :
mExportFunction(), mEnforcePP() { mExportFunction(),
mEnforcePP() {
mDescription.id = nullptr; mDescription.id = nullptr;
mDescription.description = nullptr; mDescription.description = nullptr;
mDescription.fileExtension = nullptr; mDescription.fileExtension = nullptr;
@ -147,7 +149,7 @@ public:
* interface is the default IO handler provided by ASSIMP. The default * interface is the default IO handler provided by ASSIMP. The default
* handler is active as long the application doesn't supply its own * handler is active as long the application doesn't supply its own
* custom IO handler via #SetIOHandler(). * custom IO handler via #SetIOHandler().
* @return A valid IOSystem interface, never nullptr. */ * @return A valid IOSystem interface, never NULL. */
IOSystem *GetIOHandler() const; IOSystem *GetIOHandler() const;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@ -286,7 +288,7 @@ public:
* @param pIndex Index of the export format to retrieve information * @param pIndex Index of the export format to retrieve information
* for. Valid range is 0 to #Exporter::GetExportFormatCount * for. Valid range is 0 to #Exporter::GetExportFormatCount
* @return A description of that specific export format. * @return A description of that specific export format.
* nullptr if pIndex is out of range. */ * NULL if pIndex is out of range. */
const aiExportFormatDesc *GetExportFormatDescription(size_t pIndex) const; const aiExportFormatDesc *GetExportFormatDescription(size_t pIndex) const;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@ -329,6 +331,7 @@ public:
typedef std::map<KeyType, ai_real> FloatPropertyMap; typedef std::map<KeyType, ai_real> FloatPropertyMap;
typedef std::map<KeyType, std::string> StringPropertyMap; typedef std::map<KeyType, std::string> StringPropertyMap;
typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap; typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap;
typedef std::map<KeyType, std::function<void *(void *)>> CallbackPropertyMap;
public: public:
/** Standard constructor /** Standard constructor
@ -388,6 +391,8 @@ public:
*/ */
bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue); bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue);
bool SetPropertyCallback(const char *szName, const std::function<void *(void *)> &f);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Get a configuration property. /** Get a configuration property.
* @param szName Name of the property. All supported properties * @param szName Name of the property. All supported properties
@ -440,6 +445,8 @@ public:
const aiMatrix4x4 GetPropertyMatrix(const char *szName, const aiMatrix4x4 GetPropertyMatrix(const char *szName,
const aiMatrix4x4 &sErrorReturn = aiMatrix4x4()) const; const aiMatrix4x4 &sErrorReturn = aiMatrix4x4()) const;
std::function<void *(void *)> GetPropertyCallback(const char* szName) const;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Determine a integer configuration property has been set. /** Determine a integer configuration property has been set.
* @see HasPropertyInteger() * @see HasPropertyInteger()
@ -466,7 +473,8 @@ public:
*/ */
bool HasPropertyMatrix(const char *szName) const; bool HasPropertyMatrix(const char *szName) const;
protected: bool HasPropertyCallback(const char *szName) const;
/** List of integer properties */ /** List of integer properties */
IntPropertyMap mIntProperties; IntPropertyMap mIntProperties;
@ -478,6 +486,8 @@ protected:
/** List of Matrix properties */ /** List of Matrix properties */
MatrixPropertyMap mMatrixProperties; MatrixPropertyMap mMatrixProperties;
CallbackPropertyMap mCallbackProperties;
}; };
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------