MCPcopy Create free account
hub / github.com/assimp/assimp / aiGetMaterialIntegerArray

Function aiGetMaterialIntegerArray

code/Material/MaterialSystem.cpp:200–274  ·  view source on GitHub ↗

------------------------------------------------------------------------------------------------ Get an array if integers from the material

Source from the content-addressed store, hash-verified

198// ------------------------------------------------------------------------------------------------
199// Get an array if integers from the material
200aiReturn 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) {

Callers 3

apply_materialFunction · 0.85
apply_materialFunction · 0.85
aiGetMaterialIntegerFunction · 0.85

Calls 5

aiGetMaterialPropertyFunction · 0.85
strtol10Function · 0.85
maxFunction · 0.50
minFunction · 0.50
IsSpaceFunction · 0.50

Tested by

no test coverage detected