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,29 +55,25 @@ using namespace Assimp;
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
LimitBoneWeightsProcess::LimitBoneWeightsProcess()
{
LimitBoneWeightsProcess::LimitBoneWeightsProcess() {
mMaxWeights = AI_LMW_MAX_WEIGHTS;
}
// ------------------------------------------------------------------------------------------------
// Destructor, private as well
LimitBoneWeightsProcess::~LimitBoneWeightsProcess()
{
LimitBoneWeightsProcess::~LimitBoneWeightsProcess() {
// nothing to do here
}
// ------------------------------------------------------------------------------------------------
// 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;
}
// ------------------------------------------------------------------------------------------------
// 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");
for (unsigned int m = 0; m < pScene->mNumMeshes; ++m) {
@ -89,31 +85,27 @@ void LimitBoneWeightsProcess::Execute( aiScene* pScene)
// ------------------------------------------------------------------------------------------------
// 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
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
void LimitBoneWeightsProcess::ProcessMesh(aiMesh* pMesh)
{
void LimitBoneWeightsProcess::ProcessMesh(aiMesh *pMesh) {
if (!pMesh->HasBones())
return;
// collect all bone weights per vertex
typedef SmallVector<Weight,8> VertexWeightArray;
typedef std::vector<VertexWeightArray> WeightsPerVertex;
typedef SmallVector<Weight, 8> VertexWeightArray;
typedef std::vector <VertexWeightArray> WeightsPerVertex;
WeightsPerVertex vertexWeights(pMesh->mNumVertices);
size_t maxVertexWeights = 0;
for (unsigned int b = 0; b < pMesh->mNumBones; ++b)
{
const aiBone* bone = pMesh->mBones[b];
for (unsigned int w = 0; w < bone->mNumWeights; ++w)
{
const aiVertexWeight& vw = bone->mWeights[w];
for (unsigned int b = 0; b < pMesh->mNumBones; ++b) {
const aiBone *bone = pMesh->mBones[b];
for (unsigned int w = 0; w < bone->mNumWeights; ++w) {
const aiVertexWeight &vw = bone->mWeights[w];
vertexWeights[vw.mVertexId].push_back(Weight(b, vw.mWeight));
maxVertexWeights = std::max(maxVertexWeights, vertexWeights[vw.mVertexId].size());
}
@ -125,8 +117,7 @@ void LimitBoneWeightsProcess::ProcessMesh(aiMesh* pMesh)
unsigned int removed = 0, old_bones = pMesh->mNumBones;
// 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)
continue;
@ -141,30 +132,27 @@ void LimitBoneWeightsProcess::ProcessMesh(aiMesh* pMesh)
// and renormalize the weights
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;
}
if (0.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;
}
}
}
// 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;
}
// rebuild the vertex weight array for all bones
for (unsigned int a = 0; a < vertexWeights.size(); ++a)
{
const VertexWeightArray& vw = vertexWeights[a];
for (const Weight* it = vw.begin(); it != vw.end(); ++it)
{
aiBone* bone = pMesh->mBones[it->mBone];
for (unsigned int a = 0; a < vertexWeights.size(); ++a) {
const VertexWeightArray &vw = vertexWeights[a];
for (const Weight *it = vw.begin(); it != vw.end(); ++it) {
aiBone *bone = pMesh->mBones[it->mBone];
bone->mWeights[bone->mNumWeights++] = aiVertexWeight(a, it->mWeight);
}
}
@ -172,21 +160,18 @@ void LimitBoneWeightsProcess::ProcessMesh(aiMesh* pMesh)
// remove empty bones
unsigned int writeBone = 0;
for (unsigned int readBone = 0; readBone< pMesh->mNumBones; ++readBone)
{
aiBone* bone = pMesh->mBones[readBone];
if (bone->mNumWeights > 0)
{
for (unsigned int readBone = 0; readBone < pMesh->mNumBones; ++readBone) {
aiBone *bone = pMesh->mBones[readBone];
if (bone->mNumWeights > 0) {
pMesh->mBones[writeBone++] = bone;
}
else
{
} else {
delete bone;
}
}
pMesh->mNumBones = writeBone;
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);
}
}