| 90 | // Implementation of functions "aiGetMaterialFloatArray" and "aiGetMaterialFloatFloatArray". |
| 91 | template <class TReal> |
| 92 | aiReturn GetMaterialFloatArray(const aiMaterial *pMat, |
| 93 | const char *pKey, |
| 94 | unsigned int type, |
| 95 | unsigned int index, |
| 96 | TReal *pOut, |
| 97 | unsigned int *pMax) { |
| 98 | ai_assert(pOut != nullptr); |
| 99 | ai_assert(pMat != nullptr); |
| 100 | |
| 101 | const aiMaterialProperty *prop{nullptr}; |
| 102 | aiGetMaterialProperty(pMat, pKey, type, index, &prop); |
| 103 | if (nullptr == prop) { |
| 104 | return AI_FAILURE; |
| 105 | } |
| 106 | |
| 107 | // data is given in floats, convert to TReal |
| 108 | unsigned int iWrite = 0; |
| 109 | if (aiPTI_Float == prop->mType || aiPTI_Buffer == prop->mType) { |
| 110 | iWrite = prop->mDataLength / sizeof(float); |
| 111 | if (pMax) { |
| 112 | iWrite = std::min(*pMax, iWrite); |
| 113 | } |
| 114 | |
| 115 | for (unsigned int a = 0; a < iWrite; ++a) { |
| 116 | pOut[a] = static_cast<TReal>(reinterpret_cast<float *>(prop->mData)[a]); |
| 117 | } |
| 118 | |
| 119 | if (pMax) { |
| 120 | *pMax = iWrite; |
| 121 | } |
| 122 | } else if (aiPTI_Double == prop->mType) { // data is given in doubles, convert to TReal |
| 123 | iWrite = prop->mDataLength / sizeof(double); |
| 124 | if (pMax) { |
| 125 | iWrite = std::min(*pMax, iWrite); |
| 126 | ; |
| 127 | } |
| 128 | for (unsigned int a = 0; a < iWrite; ++a) { |
| 129 | pOut[a] = static_cast<TReal>(reinterpret_cast<double *>(prop->mData)[a]); |
| 130 | } |
| 131 | if (pMax) { |
| 132 | *pMax = iWrite; |
| 133 | } |
| 134 | } else if (aiPTI_Integer == prop->mType) { // data is given in ints, convert to TReal |
| 135 | iWrite = prop->mDataLength / sizeof(int32_t); |
| 136 | if (pMax) { |
| 137 | iWrite = std::min(*pMax, iWrite); |
| 138 | ; |
| 139 | } |
| 140 | for (unsigned int a = 0; a < iWrite; ++a) { |
| 141 | pOut[a] = static_cast<TReal>(reinterpret_cast<int32_t *>(prop->mData)[a]); |
| 142 | } |
| 143 | if (pMax) { |
| 144 | *pMax = iWrite; |
| 145 | } |
| 146 | } else { // a string ... read floats separated by spaces |
| 147 | if (pMax) { |
| 148 | iWrite = *pMax; |
| 149 | } |
no test coverage detected