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

Function GetMaterialFloatArray

code/Material/MaterialSystem.cpp:92–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90// Implementation of functions "aiGetMaterialFloatArray" and "aiGetMaterialFloatFloatArray".
91template <class TReal>
92aiReturn 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 }

Callers 2

aiGetMaterialFloatArrayFunction · 0.85

Calls 4

aiGetMaterialPropertyFunction · 0.85
fast_atoreal_moveFunction · 0.85
minFunction · 0.50
IsSpaceFunction · 0.50

Tested by

no test coverage detected