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)
----------------------------------------------------------------------
@ -1066,6 +1066,7 @@ public:
} extensionsRequired;
AssetMetadata asset;
Value* extras = nullptr;
// Dictionaries for each type of object

View File

@ -1,4 +1,4 @@
/*
/*
Open Asset Import Library (assimp)
----------------------------------------------------------------------
@ -616,6 +616,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)

View File

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

View File

@ -580,10 +580,23 @@ ExportProperties::ExportProperties(const ExportProperties &other)
: mIntProperties(other.mIntProperties)
, mFloatProperties(other.mFloatProperties)
, mStringProperties(other.mStringProperties)
, mMatrixProperties(other.mMatrixProperties) {
, mMatrixProperties(other.mMatrixProperties)
, mCallbackProperties(other.mCallbackProperties){
// 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
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 <map>
#include <functional>
namespace Assimp {
@ -107,7 +108,8 @@ public:
}
ExportFormatEntry() :
mExportFunction(), mEnforcePP() {
mExportFunction(),
mEnforcePP() {
mDescription.id = nullptr;
mDescription.description = nullptr;
mDescription.fileExtension = nullptr;
@ -147,7 +149,7 @@ public:
* interface is the default IO handler provided by ASSIMP. The default
* handler is active as long the application doesn't supply its own
* custom IO handler via #SetIOHandler().
* @return A valid IOSystem interface, never nullptr. */
* @return A valid IOSystem interface, never NULL. */
IOSystem *GetIOHandler() const;
// -------------------------------------------------------------------
@ -286,7 +288,7 @@ public:
* @param pIndex Index of the export format to retrieve information
* for. Valid range is 0 to #Exporter::GetExportFormatCount
* @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;
// -------------------------------------------------------------------
@ -329,6 +331,7 @@ public:
typedef std::map<KeyType, ai_real> FloatPropertyMap;
typedef std::map<KeyType, std::string> StringPropertyMap;
typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap;
typedef std::map<KeyType, std::function<void *(void *)>> CallbackPropertyMap;
public:
/** Standard constructor
@ -387,6 +390,8 @@ public:
* @see SetPropertyInteger()
*/
bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue);
bool SetPropertyCallback(const char *szName, const std::function<void *(void *)> &f);
// -------------------------------------------------------------------
/** Get a configuration property.
@ -440,6 +445,8 @@ public:
const aiMatrix4x4 GetPropertyMatrix(const char *szName,
const aiMatrix4x4 &sErrorReturn = aiMatrix4x4()) const;
std::function<void *(void *)> GetPropertyCallback(const char* szName) const;
// -------------------------------------------------------------------
/** Determine a integer configuration property has been set.
* @see HasPropertyInteger()
@ -466,7 +473,8 @@ public:
*/
bool HasPropertyMatrix(const char *szName) const;
protected:
bool HasPropertyCallback(const char *szName) const;
/** List of integer properties */
IntPropertyMap mIntProperties;
@ -478,6 +486,8 @@ protected:
/** List of Matrix properties */
MatrixPropertyMap mMatrixProperties;
CallbackPropertyMap mCallbackProperties;
};
// ----------------------------------------------------------------------------------