Refactor material system (#6563)
* Refactor material system * Fix sonarqube finding
This commit is contained in:
@@ -80,11 +80,11 @@ aiReturn aiGetMaterialProperty(const aiMaterial *pMat,
|
||||
}
|
||||
}
|
||||
*pPropOut = nullptr;
|
||||
|
||||
return AI_FAILURE;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Implementation of functions "aiGetMaterialFloatArray" and "aiGetMaterialFloatFloatArray".
|
||||
@@ -98,8 +98,8 @@ aiReturn GetMaterialFloatArray(const aiMaterial *pMat,
|
||||
ai_assert(pOut != nullptr);
|
||||
ai_assert(pMat != nullptr);
|
||||
|
||||
const aiMaterialProperty *prop;
|
||||
aiGetMaterialProperty(pMat, pKey, type, index, (const aiMaterialProperty **)&prop);
|
||||
const aiMaterialProperty *prop{nullptr};
|
||||
aiGetMaterialProperty(pMat, pKey, type, index, &prop);
|
||||
if (nullptr == prop) {
|
||||
return AI_FAILURE;
|
||||
}
|
||||
@@ -110,7 +110,6 @@ aiReturn GetMaterialFloatArray(const aiMaterial *pMat,
|
||||
iWrite = prop->mDataLength / sizeof(float);
|
||||
if (pMax) {
|
||||
iWrite = std::min(*pMax, iWrite);
|
||||
;
|
||||
}
|
||||
|
||||
for (unsigned int a = 0; a < iWrite; ++a) {
|
||||
@@ -120,9 +119,7 @@ aiReturn GetMaterialFloatArray(const aiMaterial *pMat,
|
||||
if (pMax) {
|
||||
*pMax = iWrite;
|
||||
}
|
||||
}
|
||||
// data is given in doubles, convert to TReal
|
||||
else if (aiPTI_Double == prop->mType) {
|
||||
} else if (aiPTI_Double == prop->mType) { // data is given in doubles, convert to TReal
|
||||
iWrite = prop->mDataLength / sizeof(double);
|
||||
if (pMax) {
|
||||
iWrite = std::min(*pMax, iWrite);
|
||||
@@ -134,9 +131,7 @@ aiReturn GetMaterialFloatArray(const aiMaterial *pMat,
|
||||
if (pMax) {
|
||||
*pMax = iWrite;
|
||||
}
|
||||
}
|
||||
// data is given in ints, convert to TReal
|
||||
else if (aiPTI_Integer == prop->mType) {
|
||||
} else if (aiPTI_Integer == prop->mType) { // data is given in ints, convert to TReal
|
||||
iWrite = prop->mDataLength / sizeof(int32_t);
|
||||
if (pMax) {
|
||||
iWrite = std::min(*pMax, iWrite);
|
||||
@@ -148,9 +143,7 @@ aiReturn GetMaterialFloatArray(const aiMaterial *pMat,
|
||||
if (pMax) {
|
||||
*pMax = iWrite;
|
||||
}
|
||||
}
|
||||
// a string ... read floats separated by spaces
|
||||
else {
|
||||
} else { // a string ... read floats separated by spaces
|
||||
if (pMax) {
|
||||
iWrite = *pMax;
|
||||
}
|
||||
@@ -174,6 +167,7 @@ aiReturn GetMaterialFloatArray(const aiMaterial *pMat,
|
||||
*pMax = iWrite;
|
||||
}
|
||||
}
|
||||
|
||||
return AI_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -185,7 +179,7 @@ aiReturn aiGetMaterialFloatFloatArray(const aiMaterial *pMat,
|
||||
unsigned int index,
|
||||
float *pOut,
|
||||
unsigned int *pMax) {
|
||||
return ::GetMaterialFloatArray(pMat, pKey, type, index, pOut, pMax);
|
||||
return GetMaterialFloatArray(pMat, pKey, type, index, pOut, pMax);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -198,7 +192,7 @@ aiReturn aiGetMaterialFloatArray(const aiMaterial *pMat,
|
||||
unsigned int index,
|
||||
ai_real *pOut,
|
||||
unsigned int *pMax) {
|
||||
return ::GetMaterialFloatArray(pMat, pKey, type, index, pOut, pMax);
|
||||
return GetMaterialFloatArray(pMat, pKey, type, index, pOut, pMax);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -213,7 +207,7 @@ aiReturn aiGetMaterialIntegerArray(const aiMaterial *pMat,
|
||||
ai_assert(pMat != nullptr);
|
||||
|
||||
const aiMaterialProperty *prop;
|
||||
aiGetMaterialProperty(pMat, pKey, type, index, (const aiMaterialProperty **)&prop);
|
||||
aiGetMaterialProperty(pMat, pKey, type, index, &prop);
|
||||
if (!prop) {
|
||||
return AI_FAILURE;
|
||||
}
|
||||
@@ -305,7 +299,7 @@ aiReturn aiGetMaterialUVTransform(const aiMaterial *pMat,
|
||||
unsigned int index,
|
||||
aiUVTransform *pOut) {
|
||||
unsigned int iMax = 5;
|
||||
return aiGetMaterialFloatArray(pMat, pKey, type, index, (ai_real *)pOut, &iMax);
|
||||
return aiGetMaterialFloatArray(pMat, pKey, type, index, reinterpret_cast<ai_real *>(pOut), &iMax);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -317,8 +311,8 @@ aiReturn aiGetMaterialString(const aiMaterial *pMat,
|
||||
aiString *pOut) {
|
||||
ai_assert(pOut != nullptr);
|
||||
|
||||
const aiMaterialProperty *prop;
|
||||
aiGetMaterialProperty(pMat, pKey, type, index, (const aiMaterialProperty **)&prop);
|
||||
const aiMaterialProperty *prop{nullptr};
|
||||
aiGetMaterialProperty(pMat, pKey, type, index, &prop);
|
||||
if (!prop) {
|
||||
return AI_FAILURE;
|
||||
}
|
||||
@@ -386,7 +380,7 @@ aiReturn aiGetMaterialTexture(const C_STRUCT aiMaterial *mat,
|
||||
}
|
||||
|
||||
// Determine mapping type
|
||||
int mapping_ = static_cast<int>(aiTextureMapping_UV);
|
||||
int mapping_ = aiTextureMapping_UV;
|
||||
aiGetMaterialInteger(mat, AI_MATKEY_MAPPING(type, index), &mapping_);
|
||||
aiTextureMapping mapping = static_cast<aiTextureMapping>(mapping_);
|
||||
if (_mapping)
|
||||
@@ -417,12 +411,11 @@ aiReturn aiGetMaterialTexture(const C_STRUCT aiMaterial *mat,
|
||||
return AI_SUCCESS;
|
||||
}
|
||||
|
||||
static const unsigned int DefaultNumAllocated = 5;
|
||||
static constexpr unsigned int DefaultNumAllocated = 5;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Construction. Actually the one and only way to get an aiMaterial instance
|
||||
aiMaterial::aiMaterial() :
|
||||
mProperties(nullptr), mNumProperties(0), mNumAllocated(DefaultNumAllocated) {
|
||||
aiMaterial::aiMaterial() : mProperties(nullptr), mNumProperties(0), mNumAllocated(DefaultNumAllocated) {
|
||||
// Allocate 5 entries by default
|
||||
mProperties = new aiMaterialProperty *[DefaultNumAllocated];
|
||||
}
|
||||
@@ -436,7 +429,7 @@ aiMaterial::~aiMaterial() {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
aiString aiMaterial::GetName() const {
|
||||
aiString name;
|
||||
aiString name{};
|
||||
Get(AI_MATKEY_NAME, name);
|
||||
|
||||
return name;
|
||||
@@ -507,7 +500,7 @@ aiReturn aiMaterial::AddBinaryProperty(const void *pInput,
|
||||
}
|
||||
|
||||
// Allocate a new material property
|
||||
std::unique_ptr<aiMaterialProperty> pcNew(new aiMaterialProperty());
|
||||
auto pcNew = std::make_unique<aiMaterialProperty>();
|
||||
|
||||
// .. and fill it
|
||||
pcNew->mType = pType;
|
||||
@@ -569,11 +562,9 @@ aiReturn aiMaterial::AddProperty(const aiString *pInput,
|
||||
uint32_t Assimp::ComputeMaterialHash(const aiMaterial *mat, bool includeMatName /*= false*/) {
|
||||
uint32_t hash = 1503; // magic start value, chosen to be my birthday :-)
|
||||
for (unsigned int i = 0; i < mat->mNumProperties; ++i) {
|
||||
aiMaterialProperty *prop;
|
||||
|
||||
// Exclude all properties whose first character is '?' from the hash
|
||||
// See doc for aiMaterialProperty.
|
||||
prop = mat->mProperties[i];
|
||||
const aiMaterialProperty *prop = mat->mProperties[i];
|
||||
if (nullptr != prop && (includeMatName || prop->mKey.data[0] != '?')) {
|
||||
|
||||
hash = SuperFastHash(prop->mKey.data, (unsigned int)prop->mKey.length, hash);
|
||||
@@ -617,7 +608,7 @@ void aiMaterial::CopyPropertyList(aiMaterial *const pcDest,
|
||||
}
|
||||
|
||||
for (unsigned int i = iOldNum; i < pcDest->mNumProperties; ++i) {
|
||||
aiMaterialProperty *propSrc = pcSrc->mProperties[i];
|
||||
const aiMaterialProperty *propSrc = pcSrc->mProperties[i];
|
||||
|
||||
// search whether we have already a property with this name -> if yes, overwrite it
|
||||
aiMaterialProperty *prop;
|
||||
|
||||
Reference in New Issue
Block a user