closes https://github.com/assimp/assimp/issues/2166: add missing setter for metadata.

pull/3137/head
Kim Kulling 2020-04-06 11:16:16 +02:00
parent 085212e58a
commit 131aed73b0
4 changed files with 487 additions and 511 deletions

View File

@ -44,15 +44,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @brief Implementation of the Plain-C API
*/
#include <assimp/BaseImporter.h>
#include <assimp/Exceptional.h>
#include <assimp/GenericProperty.h>
#include <assimp/cimport.h>
#include <assimp/LogStream.hpp>
#include <assimp/DefaultLogger.hpp>
#include <assimp/Importer.hpp>
#include <assimp/importerdesc.h>
#include <assimp/scene.h>
#include <assimp/GenericProperty.h>
#include <assimp/Exceptional.h>
#include <assimp/BaseImporter.h>
#include <assimp/DefaultLogger.hpp>
#include <assimp/Importer.hpp>
#include <assimp/LogStream.hpp>
#include "CApi/CInterfaceIOWrapper.h"
#include "Importer.h"
@ -62,8 +62,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ------------------------------------------------------------------------------------------------
#ifndef ASSIMP_BUILD_SINGLETHREADED
# include <thread>
#include <mutex>
#include <thread>
#endif
// ------------------------------------------------------------------------------------------------
using namespace Assimp;
@ -100,8 +100,7 @@ namespace Assimp {
/** will delete all registered importers. */
void DeleteImporterInstanceList(std::vector<BaseImporter *> &out);
} // namespace assimp
} // namespace Assimp
#ifndef ASSIMP_BUILD_SINGLETHREADED
/** Global mutex to manage the access to the log-stream map */
@ -112,8 +111,8 @@ static std::mutex gLogStreamMutex;
// Custom LogStream implementation for the C-API
class LogToCallbackRedirector : public LogStream {
public:
explicit LogToCallbackRedirector(const aiLogStream& s)
: stream (s) {
explicit LogToCallbackRedirector(const aiLogStream &s) :
stream(s) {
ai_assert(NULL != s.callback);
}
@ -212,8 +211,7 @@ const aiScene* aiImportFileFromMemory(
const char *pBuffer,
unsigned int pLength,
unsigned int pFlags,
const char* pHint)
{
const char *pHint) {
return aiImportFileFromMemoryWithProperties(pBuffer, pLength, pFlags, pHint, NULL);
}
@ -223,8 +221,7 @@ const aiScene* aiImportFileFromMemoryWithProperties(
unsigned int pLength,
unsigned int pFlags,
const char *pHint,
const aiPropertyStore* props)
{
const aiPropertyStore *props) {
ai_assert(NULL != pBuffer);
ai_assert(0 != pLength);
@ -251,8 +248,7 @@ const aiScene* aiImportFileFromMemoryWithProperties(
if (scene) {
ScenePrivateData *priv = const_cast<ScenePrivateData *>(ScenePriv(scene));
priv->mOrigImporter = imp;
}
else {
} else {
// if failed, extract error code and destroy the import
gLastErrorString = imp->GetErrorString();
delete imp;
@ -264,8 +260,7 @@ const aiScene* aiImportFileFromMemoryWithProperties(
// ------------------------------------------------------------------------------------------------
// Releases all resources associated with the given import process.
void aiReleaseImport( const aiScene* pScene)
{
void aiReleaseImport(const aiScene *pScene) {
if (!pScene) {
return;
}
@ -276,8 +271,7 @@ void aiReleaseImport( const aiScene* pScene)
const ScenePrivateData *priv = ScenePriv(pScene);
if (!priv || !priv->mOrigImporter) {
delete pScene;
}
else {
} else {
// deleting the Importer also deletes the scene
// Note: the reason that this is not written as 'delete priv->mOrigImporter'
// is a suspected bug in gcc 4.4+ (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52339)
@ -290,11 +284,9 @@ void aiReleaseImport( const aiScene* pScene)
// ------------------------------------------------------------------------------------------------
ASSIMP_API const aiScene *aiApplyPostProcessing(const aiScene *pScene,
unsigned int pFlags)
{
unsigned int pFlags) {
const aiScene *sc = NULL;
ASSIMP_BEGIN_EXCEPTION_REGION();
// find the importer associated with this data
@ -343,8 +335,7 @@ ASSIMP_API const aiScene *aiApplyCustomizedPostProcessing( const aiScene *scene,
}
// ------------------------------------------------------------------------------------------------
void CallbackToLogRedirector (const char* msg, char* dt)
{
void CallbackToLogRedirector(const char *msg, char *dt) {
ai_assert(NULL != msg);
ai_assert(NULL != dt);
LogStream *s = (LogStream *)dt;
@ -353,8 +344,7 @@ void CallbackToLogRedirector (const char* msg, char* dt)
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API aiLogStream aiGetPredefinedLogStream(aiDefaultLogStream pStream,const char* file)
{
ASSIMP_API aiLogStream aiGetPredefinedLogStream(aiDefaultLogStream pStream, const char *file) {
aiLogStream sout;
ASSIMP_BEGIN_EXCEPTION_REGION();
@ -362,8 +352,7 @@ ASSIMP_API aiLogStream aiGetPredefinedLogStream(aiDefaultLogStream pStream,const
if (!stream) {
sout.callback = NULL;
sout.user = NULL;
}
else {
} else {
sout.callback = &CallbackToLogRedirector;
sout.user = (char *)stream;
}
@ -373,8 +362,7 @@ ASSIMP_API aiLogStream aiGetPredefinedLogStream(aiDefaultLogStream pStream,const
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiAttachLogStream( const aiLogStream* stream )
{
ASSIMP_API void aiAttachLogStream(const aiLogStream *stream) {
ASSIMP_BEGIN_EXCEPTION_REGION();
#ifndef ASSIMP_BUILD_SINGLETHREADED
@ -392,8 +380,7 @@ ASSIMP_API void aiAttachLogStream( const aiLogStream* stream )
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API aiReturn aiDetachLogStream( const aiLogStream* stream)
{
ASSIMP_API aiReturn aiDetachLogStream(const aiLogStream *stream) {
ASSIMP_BEGIN_EXCEPTION_REGION();
#ifndef ASSIMP_BUILD_SINGLETHREADED
@ -418,8 +405,7 @@ ASSIMP_API aiReturn aiDetachLogStream( const aiLogStream* stream)
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiDetachAllLogStreams(void)
{
ASSIMP_API void aiDetachAllLogStreams(void) {
ASSIMP_BEGIN_EXCEPTION_REGION();
#ifndef ASSIMP_BUILD_SINGLETHREADED
std::lock_guard<std::mutex> lock(gLogStreamMutex);
@ -440,8 +426,7 @@ ASSIMP_API void aiDetachAllLogStreams(void)
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiEnableVerboseLogging(aiBool d)
{
ASSIMP_API void aiEnableVerboseLogging(aiBool d) {
if (!DefaultLogger::isNullLogger()) {
DefaultLogger::get()->setLogSeverity((d == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL));
}
@ -450,29 +435,25 @@ ASSIMP_API void aiEnableVerboseLogging(aiBool d)
// ------------------------------------------------------------------------------------------------
// Returns the error text of the last failed import process.
const char* aiGetErrorString()
{
const char *aiGetErrorString() {
return gLastErrorString.c_str();
}
// -----------------------------------------------------------------------------------------------
// Return the description of a importer given its index
const aiImporterDesc* aiGetImportFormatDescription( size_t pIndex)
{
const aiImporterDesc *aiGetImportFormatDescription(size_t pIndex) {
return Importer().GetImporterInfo(pIndex);
}
// -----------------------------------------------------------------------------------------------
// Return the number of importers
size_t aiGetImportFormatCount(void)
{
size_t aiGetImportFormatCount(void) {
return Importer().GetImporterCount();
}
// ------------------------------------------------------------------------------------------------
// Returns the error text of the last failed import process.
aiBool aiIsExtensionSupported(const char* szExtension)
{
aiBool aiIsExtensionSupported(const char *szExtension) {
ai_assert(NULL != szExtension);
aiBool candoit = AI_FALSE;
ASSIMP_BEGIN_EXCEPTION_REGION();
@ -487,8 +468,7 @@ aiBool aiIsExtensionSupported(const char* szExtension)
// ------------------------------------------------------------------------------------------------
// Get a list of all file extensions supported by ASSIMP
void aiGetExtensionList(aiString* szOut)
{
void aiGetExtensionList(aiString *szOut) {
ai_assert(NULL != szOut);
ASSIMP_BEGIN_EXCEPTION_REGION();
@ -502,8 +482,7 @@ void aiGetExtensionList(aiString* szOut)
// ------------------------------------------------------------------------------------------------
// Get the memory requirements for a particular import.
void aiGetMemoryRequirements(const C_STRUCT aiScene *pIn,
C_STRUCT aiMemoryInfo* in)
{
C_STRUCT aiMemoryInfo *in) {
ASSIMP_BEGIN_EXCEPTION_REGION();
// find the importer associated with this data
@ -518,21 +497,18 @@ void aiGetMemoryRequirements(const C_STRUCT aiScene* pIn,
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API aiPropertyStore* aiCreatePropertyStore(void)
{
ASSIMP_API aiPropertyStore *aiCreatePropertyStore(void) {
return reinterpret_cast<aiPropertyStore *>(new PropertyMap());
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiReleasePropertyStore(aiPropertyStore* p)
{
ASSIMP_API void aiReleasePropertyStore(aiPropertyStore *p) {
delete reinterpret_cast<PropertyMap *>(p);
}
// ------------------------------------------------------------------------------------------------
// Importer::SetPropertyInteger
ASSIMP_API void aiSetImportPropertyInteger(aiPropertyStore* p, const char* szName, int value)
{
ASSIMP_API void aiSetImportPropertyInteger(aiPropertyStore *p, const char *szName, int value) {
ASSIMP_BEGIN_EXCEPTION_REGION();
PropertyMap *pp = reinterpret_cast<PropertyMap *>(p);
SetGenericProperty<int>(pp->ints, szName, value);
@ -541,8 +517,7 @@ ASSIMP_API void aiSetImportPropertyInteger(aiPropertyStore* p, const char* szNam
// ------------------------------------------------------------------------------------------------
// Importer::SetPropertyFloat
ASSIMP_API void aiSetImportPropertyFloat(aiPropertyStore* p, const char* szName, ai_real value)
{
ASSIMP_API void aiSetImportPropertyFloat(aiPropertyStore *p, const char *szName, ai_real value) {
ASSIMP_BEGIN_EXCEPTION_REGION();
PropertyMap *pp = reinterpret_cast<PropertyMap *>(p);
SetGenericProperty<ai_real>(pp->floats, szName, value);
@ -552,8 +527,7 @@ ASSIMP_API void aiSetImportPropertyFloat(aiPropertyStore* p, const char* szName,
// ------------------------------------------------------------------------------------------------
// Importer::SetPropertyString
ASSIMP_API void aiSetImportPropertyString(aiPropertyStore *p, const char *szName,
const C_STRUCT aiString* st)
{
const C_STRUCT aiString *st) {
if (!st) {
return;
}
@ -566,8 +540,7 @@ ASSIMP_API void aiSetImportPropertyString(aiPropertyStore* p, const char* szName
// ------------------------------------------------------------------------------------------------
// Importer::SetPropertyMatrix
ASSIMP_API void aiSetImportPropertyMatrix(aiPropertyStore *p, const char *szName,
const C_STRUCT aiMatrix4x4* mat)
{
const C_STRUCT aiMatrix4x4 *mat) {
if (!mat) {
return;
}
@ -579,8 +552,7 @@ ASSIMP_API void aiSetImportPropertyMatrix(aiPropertyStore* p, const char* szName
// ------------------------------------------------------------------------------------------------
// Rotation matrix to quaternion
ASSIMP_API void aiCreateQuaternionFromMatrix(aiQuaternion* quat,const aiMatrix3x3* mat)
{
ASSIMP_API void aiCreateQuaternionFromMatrix(aiQuaternion *quat, const aiMatrix3x3 *mat) {
ai_assert(NULL != quat);
ai_assert(NULL != mat);
*quat = aiQuaternion(*mat);
@ -590,8 +562,7 @@ ASSIMP_API void aiCreateQuaternionFromMatrix(aiQuaternion* quat,const aiMatrix3x
// Matrix decomposition
ASSIMP_API void aiDecomposeMatrix(const aiMatrix4x4 *mat, aiVector3D *scaling,
aiQuaternion *rotation,
aiVector3D* position)
{
aiVector3D *position) {
ai_assert(NULL != rotation);
ai_assert(NULL != position);
ai_assert(NULL != scaling);
@ -601,15 +572,13 @@ ASSIMP_API void aiDecomposeMatrix(const aiMatrix4x4* mat,aiVector3D* scaling,
// ------------------------------------------------------------------------------------------------
// Matrix transpose
ASSIMP_API void aiTransposeMatrix3(aiMatrix3x3* mat)
{
ASSIMP_API void aiTransposeMatrix3(aiMatrix3x3 *mat) {
ai_assert(NULL != mat);
mat->Transpose();
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiTransposeMatrix4(aiMatrix4x4* mat)
{
ASSIMP_API void aiTransposeMatrix4(aiMatrix4x4 *mat) {
ai_assert(NULL != mat);
mat->Transpose();
}
@ -617,8 +586,7 @@ ASSIMP_API void aiTransposeMatrix4(aiMatrix4x4* mat)
// ------------------------------------------------------------------------------------------------
// Vector transformation
ASSIMP_API void aiTransformVecByMatrix3(aiVector3D *vec,
const aiMatrix3x3* mat)
{
const aiMatrix3x3 *mat) {
ai_assert(NULL != mat);
ai_assert(NULL != vec);
*vec *= (*mat);
@ -626,8 +594,7 @@ ASSIMP_API void aiTransformVecByMatrix3(aiVector3D* vec,
// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiTransformVecByMatrix4(aiVector3D *vec,
const aiMatrix4x4* mat)
{
const aiMatrix4x4 *mat) {
ai_assert(NULL != mat);
ai_assert(NULL != vec);
@ -638,8 +605,7 @@ ASSIMP_API void aiTransformVecByMatrix4(aiVector3D* vec,
// Matrix multiplication
ASSIMP_API void aiMultiplyMatrix4(
aiMatrix4x4 *dst,
const aiMatrix4x4* src)
{
const aiMatrix4x4 *src) {
ai_assert(NULL != dst);
ai_assert(NULL != src);
*dst = (*dst) * (*src);
@ -648,8 +614,7 @@ ASSIMP_API void aiMultiplyMatrix4(
// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMultiplyMatrix3(
aiMatrix3x3 *dst,
const aiMatrix3x3* src)
{
const aiMatrix3x3 *src) {
ai_assert(NULL != dst);
ai_assert(NULL != src);
*dst = (*dst) * (*src);
@ -658,16 +623,14 @@ ASSIMP_API void aiMultiplyMatrix3(
// ------------------------------------------------------------------------------------------------
// Matrix identity
ASSIMP_API void aiIdentityMatrix3(
aiMatrix3x3* mat)
{
aiMatrix3x3 *mat) {
ai_assert(NULL != mat);
*mat = aiMatrix3x3();
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiIdentityMatrix4(
aiMatrix4x4* mat)
{
aiMatrix4x4 *mat) {
ai_assert(NULL != mat);
*mat = aiMatrix4x4();
}

View File

@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
@ -100,13 +98,27 @@ struct aiMetadataEntry {
*/
// -------------------------------------------------------------------------------
inline aiMetadataType GetAiType( bool ) { return AI_BOOL; }
inline aiMetadataType GetAiType( int32_t ) { return AI_INT32; }
inline aiMetadataType GetAiType( uint64_t ) { return AI_UINT64; }
inline aiMetadataType GetAiType( float ) { return AI_FLOAT; }
inline aiMetadataType GetAiType( double ) { return AI_DOUBLE; }
inline aiMetadataType GetAiType( const aiString & ) { return AI_AISTRING; }
inline aiMetadataType GetAiType( const aiVector3D & ) { return AI_AIVECTOR3D; }
inline aiMetadataType GetAiType(bool) {
return AI_BOOL;
}
inline aiMetadataType GetAiType(int32_t) {
return AI_INT32;
}
inline aiMetadataType GetAiType(uint64_t) {
return AI_UINT64;
}
inline aiMetadataType GetAiType(float) {
return AI_FLOAT;
}
inline aiMetadataType GetAiType(double) {
return AI_DOUBLE;
}
inline aiMetadataType GetAiType(const aiString &) {
return AI_AISTRING;
}
inline aiMetadataType GetAiType(const aiVector3D &) {
return AI_AIVECTOR3D;
}
#endif // __cplusplus
@ -134,16 +146,14 @@ struct aiMetadata {
* @brief The default constructor, set all members to zero by default.
*/
aiMetadata() AI_NO_EXCEPT
: mNumProperties(0)
, mKeys(nullptr)
, mValues(nullptr) {
: mNumProperties(0),
mKeys(nullptr),
mValues(nullptr) {
// empty
}
aiMetadata( const aiMetadata &rhs )
: mNumProperties( rhs.mNumProperties )
, mKeys( nullptr )
, mValues( nullptr ) {
aiMetadata(const aiMetadata &rhs) :
mNumProperties(rhs.mNumProperties), mKeys(nullptr), mValues(nullptr) {
mKeys = new aiString[mNumProperties];
for (size_t i = 0; i < static_cast<size_t>(mNumProperties); ++i) {
mKeys[i] = rhs.mKeys[i];
@ -160,45 +170,38 @@ struct aiMetadata {
int32_t v;
::memcpy(&v, rhs.mValues[i].mData, sizeof(int32_t));
mValues[i].mData = new int32_t(v);
}
break;
} break;
case AI_UINT64: {
uint64_t v;
::memcpy(&v, rhs.mValues[i].mData, sizeof(uint64_t));
mValues[i].mData = new uint64_t(v);
}
break;
} break;
case AI_FLOAT: {
float v;
::memcpy(&v, rhs.mValues[i].mData, sizeof(float));
mValues[i].mData = new float(v);
}
break;
} break;
case AI_DOUBLE: {
double v;
::memcpy(&v, rhs.mValues[i].mData, sizeof(double));
mValues[i].mData = new double(v);
}
break;
} break;
case AI_AISTRING: {
aiString v;
rhs.Get<aiString>(mKeys[i], v);
mValues[i].mData = new aiString(v);
}
break;
} break;
case AI_AIVECTOR3D: {
aiVector3D v;
rhs.Get<aiVector3D>(mKeys[i], v);
mValues[i].mData = new aiVector3D(v);
}
break;
} break;
#ifndef SWIG
case FORCE_32BIT:
#endif
default:
break;
}
}
}
@ -252,8 +255,7 @@ struct aiMetadata {
* @brief Allocates property fields + keys.
* @param numProperties Number of requested properties.
*/
static inline
aiMetadata *Alloc( unsigned int numProperties ) {
static inline aiMetadata *Alloc(unsigned int numProperties) {
if (0 == numProperties) {
return nullptr;
}
@ -269,19 +271,16 @@ struct aiMetadata {
/**
* @brief Deallocates property fields + keys.
*/
static inline
void Dealloc( aiMetadata *metadata ) {
static inline void Dealloc(aiMetadata *metadata) {
delete metadata;
}
template <typename T>
inline
void Add(const std::string& key, const T& value) {
inline void Add(const std::string &key, const T &value) {
aiString *new_keys = new aiString[mNumProperties + 1];
aiMetadataEntry *new_values = new aiMetadataEntry[mNumProperties + 1];
for(unsigned int i = 0; i < mNumProperties; ++i)
{
for (unsigned int i = 0; i < mNumProperties; ++i) {
new_keys[i] = mKeys[i];
new_values[i] = mValues[i];
}
@ -298,8 +297,7 @@ struct aiMetadata {
}
template <typename T>
inline
bool Set( unsigned index, const std::string& key, const T& value ) {
inline bool Set(unsigned index, const std::string &key, const T &value) {
// In range assertion
if (index >= mNumProperties) {
return false;
@ -322,8 +320,25 @@ struct aiMetadata {
}
template <typename T>
inline
bool Get( unsigned index, T& value ) const {
inline bool Set( const std::string &key, const T &value ) {
if (key.empty()) {
return false;
}
bool result = false;
for (unsigned int i = 0; i < mNumProperties; ++i) {
if (key == mKeys[i].C_Str()) {
Set(i, key, value);
result = true;
break;
}
}
return result;
}
template <typename T>
inline bool Get(unsigned index, T &value) const {
// In range assertion
if (index >= mNumProperties) {
return false;
@ -343,8 +358,7 @@ struct aiMetadata {
}
template <typename T>
inline
bool Get( const aiString& key, T& value ) const {
inline bool Get(const aiString &key, T &value) const {
// Search for the given key
for (unsigned int i = 0; i < mNumProperties; ++i) {
if (mKeys[i] == key) {
@ -355,8 +369,7 @@ struct aiMetadata {
}
template <typename T>
inline
bool Get( const std::string& key, T& value ) const {
inline bool Get(const std::string &key, T &value) const {
return Get(aiString(key), value);
}
@ -365,8 +378,7 @@ struct aiMetadata {
/// \param [out] pKey - pointer to the key value.
/// \param [out] pEntry - pointer to the entry: type and value.
/// \return false - if pIndex is out of range, else - true.
inline
bool Get(size_t index, const aiString*& key, const aiMetadataEntry*& entry) const {
inline bool Get(size_t index, const aiString *&key, const aiMetadataEntry *&entry) const {
if (index >= mNumProperties) {
return false;
}
@ -379,8 +391,7 @@ struct aiMetadata {
/// Check whether there is a metadata entry for the given key.
/// \param [in] Key - the key value value to check for.
inline
bool HasKey(const char* key) {
inline bool HasKey(const char *key) {
if (nullptr == key) {
return false;
}
@ -395,7 +406,6 @@ struct aiMetadata {
}
#endif // __cplusplus
};
#endif // AI_METADATA_H_INC

View File

@ -213,6 +213,10 @@ TEST_F(utFBXImporterExporter, importUnitScaleFactor) {
double factor(0.0);
scene->mMetaData->Get("UnitScaleFactor", factor);
EXPECT_DOUBLE_EQ(500.0, factor);
scene->mMetaData->Set("UnitScaleFactor", factor * 2);
scene->mMetaData->Get("UnitScaleFactor", factor);
EXPECT_DOUBLE_EQ(1000.0, factor);
}
TEST_F(utFBXImporterExporter, importEmbeddedAsciiTest) {