diff --git a/code/Material/MaterialSystem.cpp b/code/Material/MaterialSystem.cpp index 917f69105..cc140e39a 100644 --- a/code/Material/MaterialSystem.cpp +++ b/code/Material/MaterialSystem.cpp @@ -428,7 +428,7 @@ aiReturn aiGetMaterialTexture(const C_STRUCT aiMaterial *mat, C_STRUCT aiString *path, aiTextureMapping *_mapping /*= nullptr*/, unsigned int *uvindex /*= nullptr*/, - ai_real *blend /*= nullptr*/, + float *blend /*= nullptr*/, aiTextureOp *op /*= nullptr*/, aiTextureMapMode *mapmode /*= nullptr*/, unsigned int *flags /*= nullptr*/ diff --git a/include/assimp/material.h b/include/assimp/material.h index c7f808e40..49328e0cd 100644 --- a/include/assimp/material.h +++ b/include/assimp/material.h @@ -829,7 +829,7 @@ public: C_STRUCT aiString *path, aiTextureMapping *mapping = NULL, unsigned int *uvindex = NULL, - ai_real *blend = NULL, + float *blend = NULL, aiTextureOp *op = NULL, aiTextureMapMode *mapmode = NULL) const; @@ -1538,6 +1538,39 @@ ASSIMP_API C_ENUM aiReturn aiGetMaterialFloatArray( float *pOut, unsigned int *pMax); +// --------------------------------------------------------------------------- +/** @brief Retrieve an array of double values with a specific key + * from the material + * + * Pass one of the AI_MATKEY_XXX constants for the last three parameters (the + * example reads the #AI_MATKEY_UVTRANSFORM property of the first diffuse texture) + * @code + * aiUVTransform trafo; + * unsigned int max = sizeof(aiUVTransform); + * if (AI_SUCCESS != aiGetMaterialFloatArray(mat, AI_MATKEY_UVTRANSFORM(aiTextureType_DIFFUSE,0), + * (float*)&trafo, &max) || sizeof(aiUVTransform) != max) + * { + * // error handling + * } + * @endcode + * + * @param pMat Pointer to the input material. May not be NULL + * @param pKey Key to search for. One of the AI_MATKEY_XXX constants. + * @param pOut Pointer to a buffer to receive the result. + * @param pMax Specifies the size of the given buffer, in float's. + * Receives the number of values (not bytes!) read. + * @param type (see the code sample above) + * @param index (see the code sample above) + * @return Specifies whether the key has been found. If not, the output + * arrays remains unmodified and pMax is set to 0.*/ +// --------------------------------------------------------------------------- +ASSIMP_API C_ENUM aiReturn aiGetMaterialDoubleArray(const C_STRUCT aiMaterial *pMat, + const char *pKey, + unsigned int type, + unsigned int index, + double *pOut, + unsigned int *pMax); + // --------------------------------------------------------------------------- /** @brief Retrieve a single float property with a specific key from the material. * @@ -1565,6 +1598,33 @@ inline aiReturn aiGetMaterialFloat(const C_STRUCT aiMaterial *pMat, return aiGetMaterialFloatArray(pMat, pKey, type, index, pOut, (unsigned int *)0x0); } +// --------------------------------------------------------------------------- +/** @brief Retrieve a single double property with a specific key from the material. +* +* Pass one of the AI_MATKEY_XXX constants for the last three parameters (the +* example reads the #AI_MATKEY_SHININESS_STRENGTH property of the first diffuse texture) +* @code +* float specStrength = 1.f; // default value, remains unmodified if we fail. +* aiGetMaterialFloat(mat, AI_MATKEY_SHININESS_STRENGTH, +* (float*)&specStrength); +* @endcode +* +* @param pMat Pointer to the input material. May not be NULL +* @param pKey Key to search for. One of the AI_MATKEY_XXX constants. +* @param pOut Receives the output float. +* @param type (see the code sample above) +* @param index (see the code sample above) +* @return Specifies whether the key has been found. If not, the output +* float remains unmodified.*/ +// --------------------------------------------------------------------------- +inline aiReturn aiGetMaterialDouble(const C_STRUCT aiMaterial *pMat, + const char *pKey, + unsigned int type, + unsigned int index, + double *pOut) { + return aiGetMaterialDoubleArray(pMat, pKey, type, index, pOut, (unsigned int *)0x0); +} + // --------------------------------------------------------------------------- /** @brief Retrieve an array of integer values with a specific key * from a material @@ -1677,7 +1737,7 @@ ASSIMP_API aiReturn aiGetMaterialTexture(const C_STRUCT aiMaterial *mat, aiString *path, aiTextureMapping *mapping = NULL, unsigned int *uvindex = NULL, - ai_real *blend = NULL, + float *blend = NULL, aiTextureOp *op = NULL, aiTextureMapMode *mapmode = NULL, unsigned int *flags = NULL); diff --git a/include/assimp/material.inl b/include/assimp/material.inl index 31dd438fe..3ee0180a5 100644 --- a/include/assimp/material.inl +++ b/include/assimp/material.inl @@ -155,11 +155,19 @@ AI_FORCE_INLINE aiReturn aiMaterial::Get(const char *pKey, unsigned int type, ::memcpy(&pOut, prop->mData, sizeof(bool)); } break; - case aiPTI_Float: + case aiPTI_Float: { + // Read as float and cast to bool + float value = 0.0f; + if (AI_SUCCESS == ::aiGetMaterialFloat(this, pKey, type, idx, &value)) { + pOut = static_cast(value); + return AI_SUCCESS; + } + return AI_FAILURE; + } case aiPTI_Double: { // Read as float and cast to bool - ai_real value = 0.0f; - if (AI_SUCCESS == ::aiGetMaterialFloat(this, pKey, type, idx, &value)) { + double value = 0.0f; + if (AI_SUCCESS == ::aiGetMaterialDouble(this, pKey, type, idx, &value)) { pOut = static_cast(value); return AI_SUCCESS; } @@ -179,7 +187,7 @@ AI_FORCE_INLINE aiReturn aiMaterial::Get(const char *pKey, unsigned int type, // --------------------------------------------------------------------------- AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type, - unsigned int idx,ai_real* pOut, + unsigned int idx, ai_real* pOut, unsigned int* pMax) const { return ::aiGetMaterialFloatArray(this,pKey,type,idx,pOut,pMax); }