fix the whitespaces

pull/3042/head
iamAdrianIusca 2020-04-23 22:27:55 +03:00
parent 74931fe6d9
commit efa6ead1a5
1 changed files with 80 additions and 95 deletions

View File

@ -55,138 +55,123 @@ using namespace Assimp;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer // Constructor to be privately used by Importer
LimitBoneWeightsProcess::LimitBoneWeightsProcess() LimitBoneWeightsProcess::LimitBoneWeightsProcess() {
{ mMaxWeights = AI_LMW_MAX_WEIGHTS;
mMaxWeights = AI_LMW_MAX_WEIGHTS;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Destructor, private as well // Destructor, private as well
LimitBoneWeightsProcess::~LimitBoneWeightsProcess() LimitBoneWeightsProcess::~LimitBoneWeightsProcess() {
{ // nothing to do here
// nothing to do here
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Returns whether the processing step is present in the given flag field. // Returns whether the processing step is present in the given flag field.
bool LimitBoneWeightsProcess::IsActive( unsigned int pFlags) const bool LimitBoneWeightsProcess::IsActive(unsigned int pFlags) const {
{ return (pFlags & aiProcess_LimitBoneWeights) != 0;
return (pFlags & aiProcess_LimitBoneWeights) != 0;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Executes the post processing step on the given imported data. // Executes the post processing step on the given imported data.
void LimitBoneWeightsProcess::Execute( aiScene* pScene) void LimitBoneWeightsProcess::Execute(aiScene *pScene) {
{
ASSIMP_LOG_DEBUG("LimitBoneWeightsProcess begin"); ASSIMP_LOG_DEBUG("LimitBoneWeightsProcess begin");
for (unsigned int m = 0; m < pScene->mNumMeshes; ++m) { for (unsigned int m = 0; m < pScene->mNumMeshes; ++m) {
ProcessMesh(pScene->mMeshes[m]); ProcessMesh(pScene->mMeshes[m]);
} }
ASSIMP_LOG_DEBUG("LimitBoneWeightsProcess end"); ASSIMP_LOG_DEBUG("LimitBoneWeightsProcess end");
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Executes the post processing step on the given imported data. // Executes the post processing step on the given imported data.
void LimitBoneWeightsProcess::SetupProperties(const Importer* pImp) void LimitBoneWeightsProcess::SetupProperties(const Importer *pImp) {
{ // get the current value of the property
// get the current value of the property this->mMaxWeights = pImp->GetPropertyInteger(AI_CONFIG_PP_LBW_MAX_WEIGHTS, AI_LMW_MAX_WEIGHTS);
this->mMaxWeights = pImp->GetPropertyInteger(AI_CONFIG_PP_LBW_MAX_WEIGHTS,AI_LMW_MAX_WEIGHTS);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Unites identical vertices in the given mesh // Unites identical vertices in the given mesh
void LimitBoneWeightsProcess::ProcessMesh(aiMesh* pMesh) void LimitBoneWeightsProcess::ProcessMesh(aiMesh *pMesh) {
{ if (!pMesh->HasBones())
if (!pMesh->HasBones()) return;
return;
// collect all bone weights per vertex // collect all bone weights per vertex
typedef SmallVector<Weight,8> VertexWeightArray; typedef SmallVector<Weight, 8> VertexWeightArray;
typedef std::vector<VertexWeightArray> WeightsPerVertex; typedef std::vector <VertexWeightArray> WeightsPerVertex;
WeightsPerVertex vertexWeights(pMesh->mNumVertices); WeightsPerVertex vertexWeights(pMesh->mNumVertices);
size_t maxVertexWeights = 0; size_t maxVertexWeights = 0;
for (unsigned int b = 0; b < pMesh->mNumBones; ++b) for (unsigned int b = 0; b < pMesh->mNumBones; ++b) {
{ const aiBone *bone = pMesh->mBones[b];
const aiBone* bone = pMesh->mBones[b]; for (unsigned int w = 0; w < bone->mNumWeights; ++w) {
for (unsigned int w = 0; w < bone->mNumWeights; ++w) const aiVertexWeight &vw = bone->mWeights[w];
{ vertexWeights[vw.mVertexId].push_back(Weight(b, vw.mWeight));
const aiVertexWeight& vw = bone->mWeights[w]; maxVertexWeights = std::max(maxVertexWeights, vertexWeights[vw.mVertexId].size());
vertexWeights[vw.mVertexId].push_back(Weight(b, vw.mWeight)); }
maxVertexWeights = std::max(maxVertexWeights, vertexWeights[vw.mVertexId].size()); }
}
}
if (maxVertexWeights <= mMaxWeights) if (maxVertexWeights <= mMaxWeights)
return; return;
unsigned int removed = 0, old_bones = pMesh->mNumBones; unsigned int removed = 0, old_bones = pMesh->mNumBones;
// now cut the weight count if it exceeds the maximum // now cut the weight count if it exceeds the maximum
for (WeightsPerVertex::iterator vit = vertexWeights.begin(); vit != vertexWeights.end(); ++vit) for (WeightsPerVertex::iterator vit = vertexWeights.begin(); vit != vertexWeights.end(); ++vit) {
{ if (vit->size() <= mMaxWeights)
if (vit->size() <= mMaxWeights) continue;
continue;
// more than the defined maximum -> first sort by weight in descending order. That's // more than the defined maximum -> first sort by weight in descending order. That's
// why we defined the < operator in such a weird way. // why we defined the < operator in such a weird way.
std::sort(vit->begin(), vit->end()); std::sort(vit->begin(), vit->end());
// now kill everything beyond the maximum count // now kill everything beyond the maximum count
unsigned int m = static_cast<unsigned int>(vit->size()); unsigned int m = static_cast<unsigned int>(vit->size());
vit->resize(mMaxWeights); vit->resize(mMaxWeights);
removed += static_cast<unsigned int>(m - vit->size()); removed += static_cast<unsigned int>(m - vit->size());
// and renormalize the weights // and renormalize the weights
float sum = 0.0f; float sum = 0.0f;
for(const Weight* it = vit->begin(); it != vit->end(); ++it) { for (const Weight *it = vit->begin(); it != vit->end(); ++it) {
sum += it->mWeight; sum += it->mWeight;
} }
if (0.0f != sum) { if (0.0f != sum) {
const float invSum = 1.0f / sum; const float invSum = 1.0f / sum;
for(Weight* it = vit->begin(); it != vit->end(); ++it) { for (Weight *it = vit->begin(); it != vit->end(); ++it) {
it->mWeight *= invSum; it->mWeight *= invSum;
} }
} }
} }
// clear weight count for all bone // clear weight count for all bone
for (unsigned int a = 0; a < pMesh->mNumBones; ++a) for (unsigned int a = 0; a < pMesh->mNumBones; ++a) {
{ pMesh->mBones[a]->mNumWeights = 0;
pMesh->mBones[a]->mNumWeights = 0; }
}
// rebuild the vertex weight array for all bones // rebuild the vertex weight array for all bones
for (unsigned int a = 0; a < vertexWeights.size(); ++a) for (unsigned int a = 0; a < vertexWeights.size(); ++a) {
{ const VertexWeightArray &vw = vertexWeights[a];
const VertexWeightArray& vw = vertexWeights[a]; for (const Weight *it = vw.begin(); it != vw.end(); ++it) {
for (const Weight* it = vw.begin(); it != vw.end(); ++it) aiBone *bone = pMesh->mBones[it->mBone];
{ bone->mWeights[bone->mNumWeights++] = aiVertexWeight(a, it->mWeight);
aiBone* bone = pMesh->mBones[it->mBone]; }
bone->mWeights[bone->mNumWeights++] = aiVertexWeight(a, it->mWeight); }
}
}
// remove empty bones // remove empty bones
unsigned int writeBone = 0; unsigned int writeBone = 0;
for (unsigned int readBone = 0; readBone< pMesh->mNumBones; ++readBone) for (unsigned int readBone = 0; readBone < pMesh->mNumBones; ++readBone) {
{ aiBone *bone = pMesh->mBones[readBone];
aiBone* bone = pMesh->mBones[readBone]; if (bone->mNumWeights > 0) {
if (bone->mNumWeights > 0) pMesh->mBones[writeBone++] = bone;
{ } else {
pMesh->mBones[writeBone++] = bone; delete bone;
} }
else }
{ pMesh->mNumBones = writeBone;
delete bone;
}
}
pMesh->mNumBones = writeBone;
if (!DefaultLogger::isNullLogger()) { if (!DefaultLogger::isNullLogger()) {
ASSIMP_LOG_INFO_F("Removed ", removed, " weights. Input bones: ", old_bones, ". Output bones: ", pMesh->mNumBones); ASSIMP_LOG_INFO_F("Removed ", removed, " weights. Input bones: ", old_bones, ". Output bones: ",
} pMesh->mNumBones);
}
} }