------------------------------------------------------------------------------------------------ Get an array if integers from the material
| 198 | // ------------------------------------------------------------------------------------------------ |
| 199 | // Get an array if integers from the material |
| 200 | aiReturn aiGetMaterialIntegerArray(const aiMaterial *pMat, |
| 201 | const char *pKey, |
| 202 | unsigned int type, |
| 203 | unsigned int index, |
| 204 | int *pOut, |
| 205 | unsigned int *pMax) { |
| 206 | ai_assert(pOut != nullptr); |
| 207 | ai_assert(pMat != nullptr); |
| 208 | |
| 209 | const aiMaterialProperty *prop; |
| 210 | aiGetMaterialProperty(pMat, pKey, type, index, &prop); |
| 211 | if (!prop) { |
| 212 | return AI_FAILURE; |
| 213 | } |
| 214 | |
| 215 | // data is given in ints, simply copy it |
| 216 | unsigned int iWrite = 0; |
| 217 | if (aiPTI_Integer == prop->mType || aiPTI_Buffer == prop->mType) { |
| 218 | iWrite = std::max(static_cast<unsigned int>(prop->mDataLength / sizeof(int32_t)), 1u); |
| 219 | if (pMax) { |
| 220 | iWrite = std::min(*pMax, iWrite); |
| 221 | } |
| 222 | if (1 == prop->mDataLength) { |
| 223 | // bool type, 1 byte |
| 224 | *pOut = static_cast<int>(*prop->mData); |
| 225 | } else { |
| 226 | for (unsigned int a = 0; a < iWrite; ++a) { |
| 227 | pOut[a] = static_cast<int>(reinterpret_cast<int32_t *>(prop->mData)[a]); |
| 228 | } |
| 229 | } |
| 230 | if (pMax) { |
| 231 | *pMax = iWrite; |
| 232 | } |
| 233 | } |
| 234 | // data is given in floats convert to int |
| 235 | else if (aiPTI_Float == prop->mType) { |
| 236 | iWrite = prop->mDataLength / sizeof(float); |
| 237 | if (pMax) { |
| 238 | iWrite = std::min(*pMax, iWrite); |
| 239 | ; |
| 240 | } |
| 241 | for (unsigned int a = 0; a < iWrite; ++a) { |
| 242 | pOut[a] = static_cast<int>(reinterpret_cast<float *>(prop->mData)[a]); |
| 243 | } |
| 244 | if (pMax) { |
| 245 | *pMax = iWrite; |
| 246 | } |
| 247 | } |
| 248 | // it is a string ... no way to read something out of this |
| 249 | else { |
| 250 | if (pMax) { |
| 251 | iWrite = *pMax; |
| 252 | } |
| 253 | // strings are zero-terminated with a 32 bit length prefix, so this is safe |
| 254 | const char *cur = prop->mData + 4; |
| 255 | ai_assert(prop->mDataLength >= 5); |
| 256 | ai_assert(!prop->mData[prop->mDataLength - 1]); |
| 257 | for (unsigned int a = 0;; ++a) { |
no test coverage detected