Improved Q3BSPZipArchive + added material merging

This commit is contained in:
Léo Terziman
2013-11-12 11:09:31 +01:00
parent 51bf836db4
commit bb9288fa26
3 changed files with 64 additions and 17 deletions

View File

@@ -880,6 +880,56 @@ void SceneCombiner::MergeMeshes(aiMesh** _out,unsigned int /*flags*/,
delete *it;
}
// ------------------------------------------------------------------------------------------------
void SceneCombiner::MergeMaterials(aiMaterial** dest,
std::vector<aiMaterial*>::const_iterator begin,
std::vector<aiMaterial*>::const_iterator end)
{
ai_assert(NULL != dest);
if (begin == end) {
*dest = NULL; // no materials ...
return;
}
// Allocate the output material
aiMaterial* out = *dest = new aiMaterial();
// Get the maximal number of properties
unsigned int size = 0;
for (std::vector<aiMaterial*>::const_iterator it = begin; it != end; ++it) {
size += (*it)->mNumProperties;
}
out->mNumAllocated = size;
out->mNumProperties = 0;
out->mProperties = new aiMaterialProperty*[out->mNumAllocated];
for (std::vector<aiMaterial*>::const_iterator it = begin; it != end; ++it) {
for(unsigned int i = 0; i < (*it)->mNumProperties; ++i) {
aiMaterialProperty* sprop = (*it)->mProperties[i];
// Test if we already have a matching property
const aiMaterialProperty* prop_exist;
if(aiGetMaterialProperty(out, sprop->mKey.C_Str(), sprop->mType, sprop->mIndex, &prop_exist) != AI_SUCCESS) {
// If not, we add it to the new material
aiMaterialProperty* prop = out->mProperties[i] = new aiMaterialProperty();
prop->mDataLength = sprop->mDataLength;
prop->mData = new char[prop->mDataLength];
::memcpy(prop->mData, sprop->mData, prop->mDataLength);
prop->mIndex = sprop->mIndex;
prop->mSemantic = sprop->mSemantic;
prop->mKey = sprop->mKey;
prop->mType = sprop->mType;
out->mNumProperties++;
}
}
}
}
// ------------------------------------------------------------------------------------------------
template <typename Type>
inline void CopyPtrArray (Type**& dest, const Type* const * src, unsigned int num)