Преглед изворни кода

Material: INtroduce double array readout function

Kim Kulling пре 10 месеци
родитељ
комит
0a3b5dfc40
3 измењених фајлова са 75 додато и 7 уклоњено
  1. 1 1
      code/Material/MaterialSystem.cpp
  2. 62 2
      include/assimp/material.h
  3. 12 4
      include/assimp/material.inl

+ 1 - 1
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*/

+ 62 - 2
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);

+ 12 - 4
include/assimp/material.inl

@@ -155,16 +155,24 @@ AI_FORCE_INLINE aiReturn aiMaterial::Get(const char *pKey, unsigned int type,
             ::memcpy(&pOut, prop->mData, sizeof(bool));
         } break;
 
-        case aiPTI_Float:
-        case aiPTI_Double: {
+        case aiPTI_Float: {
             // Read as float and cast to bool
-            ai_real value = 0.0f;
+            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
+            double value = 0.0f;
+            if (AI_SUCCESS == ::aiGetMaterialDouble(this, pKey, type, idx, &value)) {
+                pOut = static_cast<bool>(value);
+                return AI_SUCCESS;
+            }
+            return AI_FAILURE;
+        }
         case aiPTI_Integer: {
             // Cast to bool
             const int value = static_cast<int>(*prop->mData);
@@ -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);
 }