Compare commits

...

2 Commits

Author SHA1 Message Date
Kim Kulling
469fdb1ab2 Indroduce matgetreal 2024-09-26 13:49:27 +02:00
Kim Kulling
0a3b5dfc40 Material: INtroduce double array readout function 2024-09-25 16:38:34 +02:00
3 changed files with 92 additions and 8 deletions

View File

@@ -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*/

View File

@@ -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,45 @@ 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);
}
inline aiReturn aiGetMaterialReal(const C_STRUCT aiMaterial *pMat,
const char *pKey,
unsigned int type,
unsigned int index,
ai_real *pOut) {
#ifndef ASSIMP_DOUBLE_PRECISION
return aiGetMaterialFloatArray(pMat, pKey, type, index, pOut, (unsigned int *)0x0);
#else
return aiGetMaterialDoubleArray(pMat, pKey, type, index, pOut, (unsigned int *)0x0);
#endif
}
// ---------------------------------------------------------------------------
/** @brief Retrieve an array of integer values with a specific key
* from a material
@@ -1677,7 +1749,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);

View File

@@ -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<bool>(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<bool>(value);
return AI_SUCCESS;
}
@@ -179,9 +187,13 @@ 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);
#ifndef ASSIMP_DOUBLE_PRECISION
return ::aiGetMaterialFloatArray(this, pKey, type, idx, pOut, pMax);
#else
return ::aiGetMaterialDoubleArray(this, pKey, type, idx, pOut, pMax);
#endif
}
// ---------------------------------------------------------------------------
AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type,