Refactor: Expand tabs to 4 spaces

This commit is contained in:
Richard
2015-05-18 21:57:13 -06:00
parent a96a595a7a
commit 83de707587
324 changed files with 78951 additions and 78956 deletions

View File

@@ -53,7 +53,7 @@ using namespace Assimp;
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
FindInstancesProcess::FindInstancesProcess()
: configSpeedFlag (false)
: configSpeedFlag (false)
{}
// ------------------------------------------------------------------------------------------------
@@ -65,213 +65,213 @@ FindInstancesProcess::~FindInstancesProcess()
// Returns whether the processing step is present in the given flag field.
bool FindInstancesProcess::IsActive( unsigned int pFlags) const
{
// FindInstances makes absolutely no sense together with PreTransformVertices
// fixme: spawn error message somewhere else?
return 0 != (pFlags & aiProcess_FindInstances) && 0 == (pFlags & aiProcess_PreTransformVertices);
// FindInstances makes absolutely no sense together with PreTransformVertices
// fixme: spawn error message somewhere else?
return 0 != (pFlags & aiProcess_FindInstances) && 0 == (pFlags & aiProcess_PreTransformVertices);
}
// ------------------------------------------------------------------------------------------------
// Setup properties for the step
void FindInstancesProcess::SetupProperties(const Importer* pImp)
{
// AI_CONFIG_FAVOUR_SPEED
configSpeedFlag = (0 != pImp->GetPropertyInteger(AI_CONFIG_FAVOUR_SPEED,0));
// AI_CONFIG_FAVOUR_SPEED
configSpeedFlag = (0 != pImp->GetPropertyInteger(AI_CONFIG_FAVOUR_SPEED,0));
}
// ------------------------------------------------------------------------------------------------
// Compare the bones of two meshes
bool CompareBones(const aiMesh* orig, const aiMesh* inst)
{
for (unsigned int i = 0; i < orig->mNumBones;++i) {
aiBone* aha = orig->mBones[i];
aiBone* oha = inst->mBones[i];
for (unsigned int i = 0; i < orig->mNumBones;++i) {
aiBone* aha = orig->mBones[i];
aiBone* oha = inst->mBones[i];
if (aha->mNumWeights != oha->mNumWeights ||
aha->mOffsetMatrix != oha->mOffsetMatrix) {
return false;
}
if (aha->mNumWeights != oha->mNumWeights ||
aha->mOffsetMatrix != oha->mOffsetMatrix) {
return false;
}
// compare weight per weight ---
for (unsigned int n = 0; n < aha->mNumWeights;++n) {
if (aha->mWeights[n].mVertexId != oha->mWeights[n].mVertexId ||
(aha->mWeights[n].mWeight - oha->mWeights[n].mWeight) < 10e-3f) {
return false;
}
}
}
return true;
// compare weight per weight ---
for (unsigned int n = 0; n < aha->mNumWeights;++n) {
if (aha->mWeights[n].mVertexId != oha->mWeights[n].mVertexId ||
(aha->mWeights[n].mWeight - oha->mWeights[n].mWeight) < 10e-3f) {
return false;
}
}
}
return true;
}
// ------------------------------------------------------------------------------------------------
// Update mesh indices in the node graph
void UpdateMeshIndices(aiNode* node, unsigned int* lookup)
{
for (unsigned int n = 0; n < node->mNumMeshes;++n)
node->mMeshes[n] = lookup[node->mMeshes[n]];
for (unsigned int n = 0; n < node->mNumMeshes;++n)
node->mMeshes[n] = lookup[node->mMeshes[n]];
for (unsigned int n = 0; n < node->mNumChildren;++n)
UpdateMeshIndices(node->mChildren[n],lookup);
for (unsigned int n = 0; n < node->mNumChildren;++n)
UpdateMeshIndices(node->mChildren[n],lookup);
}
// ------------------------------------------------------------------------------------------------
// Executes the post processing step on the given imported data.
void FindInstancesProcess::Execute( aiScene* pScene)
{
DefaultLogger::get()->debug("FindInstancesProcess begin");
if (pScene->mNumMeshes) {
DefaultLogger::get()->debug("FindInstancesProcess begin");
if (pScene->mNumMeshes) {
// use a pseudo hash for all meshes in the scene to quickly find
// the ones which are possibly equal. This step is executed early
// in the pipeline, so we could, depending on the file format,
// have several thousand small meshes. That's too much for a brute
// everyone-against-everyone check involving up to 10 comparisons
// each.
boost::scoped_array<uint64_t> hashes (new uint64_t[pScene->mNumMeshes]);
boost::scoped_array<unsigned int> remapping (new unsigned int[pScene->mNumMeshes]);
// use a pseudo hash for all meshes in the scene to quickly find
// the ones which are possibly equal. This step is executed early
// in the pipeline, so we could, depending on the file format,
// have several thousand small meshes. That's too much for a brute
// everyone-against-everyone check involving up to 10 comparisons
// each.
boost::scoped_array<uint64_t> hashes (new uint64_t[pScene->mNumMeshes]);
boost::scoped_array<unsigned int> remapping (new unsigned int[pScene->mNumMeshes]);
unsigned int numMeshesOut = 0;
for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
unsigned int numMeshesOut = 0;
for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
aiMesh* inst = pScene->mMeshes[i];
hashes[i] = GetMeshHash(inst);
aiMesh* inst = pScene->mMeshes[i];
hashes[i] = GetMeshHash(inst);
for (int a = i-1; a >= 0; --a) {
if (hashes[i] == hashes[a])
{
aiMesh* orig = pScene->mMeshes[a];
if (!orig)
continue;
for (int a = i-1; a >= 0; --a) {
if (hashes[i] == hashes[a])
{
aiMesh* orig = pScene->mMeshes[a];
if (!orig)
continue;
// check for hash collision .. we needn't check
// the vertex format, it *must* match due to the
// (brilliant) construction of the hash
if (orig->mNumBones != inst->mNumBones ||
orig->mNumFaces != inst->mNumFaces ||
orig->mNumVertices != inst->mNumVertices ||
orig->mMaterialIndex != inst->mMaterialIndex ||
orig->mPrimitiveTypes != inst->mPrimitiveTypes)
continue;
// check for hash collision .. we needn't check
// the vertex format, it *must* match due to the
// (brilliant) construction of the hash
if (orig->mNumBones != inst->mNumBones ||
orig->mNumFaces != inst->mNumFaces ||
orig->mNumVertices != inst->mNumVertices ||
orig->mMaterialIndex != inst->mMaterialIndex ||
orig->mPrimitiveTypes != inst->mPrimitiveTypes)
continue;
// up to now the meshes are equal. find an appropriate
// epsilon to compare position differences against
float epsilon = ComputePositionEpsilon(inst);
epsilon *= epsilon;
// up to now the meshes are equal. find an appropriate
// epsilon to compare position differences against
float epsilon = ComputePositionEpsilon(inst);
epsilon *= epsilon;
// now compare vertex positions, normals,
// tangents and bitangents using this epsilon.
if (orig->HasPositions()) {
if(!CompareArrays(orig->mVertices,inst->mVertices,orig->mNumVertices,epsilon))
continue;
}
if (orig->HasNormals()) {
if(!CompareArrays(orig->mNormals,inst->mNormals,orig->mNumVertices,epsilon))
continue;
}
if (orig->HasTangentsAndBitangents()) {
if (!CompareArrays(orig->mTangents,inst->mTangents,orig->mNumVertices,epsilon) ||
!CompareArrays(orig->mBitangents,inst->mBitangents,orig->mNumVertices,epsilon))
continue;
}
// now compare vertex positions, normals,
// tangents and bitangents using this epsilon.
if (orig->HasPositions()) {
if(!CompareArrays(orig->mVertices,inst->mVertices,orig->mNumVertices,epsilon))
continue;
}
if (orig->HasNormals()) {
if(!CompareArrays(orig->mNormals,inst->mNormals,orig->mNumVertices,epsilon))
continue;
}
if (orig->HasTangentsAndBitangents()) {
if (!CompareArrays(orig->mTangents,inst->mTangents,orig->mNumVertices,epsilon) ||
!CompareArrays(orig->mBitangents,inst->mBitangents,orig->mNumVertices,epsilon))
continue;
}
// use a constant epsilon for colors and UV coordinates
static const float uvEpsilon = 10e-4f;
{
unsigned int i, end = orig->GetNumUVChannels();
for(i = 0; i < end; ++i) {
if (!orig->mTextureCoords[i]) {
continue;
}
if(!CompareArrays(orig->mTextureCoords[i],inst->mTextureCoords[i],orig->mNumVertices,uvEpsilon)) {
break;
}
}
if (i != end) {
continue;
}
}
{
unsigned int i, end = orig->GetNumColorChannels();
for(i = 0; i < end; ++i) {
if (!orig->mColors[i]) {
continue;
}
if(!CompareArrays(orig->mColors[i],inst->mColors[i],orig->mNumVertices,uvEpsilon)) {
break;
}
}
if (i != end) {
continue;
}
}
// use a constant epsilon for colors and UV coordinates
static const float uvEpsilon = 10e-4f;
{
unsigned int i, end = orig->GetNumUVChannels();
for(i = 0; i < end; ++i) {
if (!orig->mTextureCoords[i]) {
continue;
}
if(!CompareArrays(orig->mTextureCoords[i],inst->mTextureCoords[i],orig->mNumVertices,uvEpsilon)) {
break;
}
}
if (i != end) {
continue;
}
}
{
unsigned int i, end = orig->GetNumColorChannels();
for(i = 0; i < end; ++i) {
if (!orig->mColors[i]) {
continue;
}
if(!CompareArrays(orig->mColors[i],inst->mColors[i],orig->mNumVertices,uvEpsilon)) {
break;
}
}
if (i != end) {
continue;
}
}
// These two checks are actually quite expensive and almost *never* required.
// Almost. That's why they're still here. But there's no reason to do them
// in speed-targeted imports.
if (!configSpeedFlag) {
// These two checks are actually quite expensive and almost *never* required.
// Almost. That's why they're still here. But there's no reason to do them
// in speed-targeted imports.
if (!configSpeedFlag) {
// It seems to be strange, but we really need to check whether the
// bones are identical too. Although it's extremely unprobable
// that they're not if control reaches here, we need to deal
// with unprobable cases, too. It could still be that there are
// equal shapes which are deformed differently.
if (!CompareBones(orig,inst))
continue;
// It seems to be strange, but we really need to check whether the
// bones are identical too. Although it's extremely unprobable
// that they're not if control reaches here, we need to deal
// with unprobable cases, too. It could still be that there are
// equal shapes which are deformed differently.
if (!CompareBones(orig,inst))
continue;
// For completeness ... compare even the index buffers for equality
// face order & winding order doesn't care. Input data is in verbose format.
boost::scoped_array<unsigned int> ftbl_orig(new unsigned int[orig->mNumVertices]);
boost::scoped_array<unsigned int> ftbl_inst(new unsigned int[orig->mNumVertices]);
// For completeness ... compare even the index buffers for equality
// face order & winding order doesn't care. Input data is in verbose format.
boost::scoped_array<unsigned int> ftbl_orig(new unsigned int[orig->mNumVertices]);
boost::scoped_array<unsigned int> ftbl_inst(new unsigned int[orig->mNumVertices]);
for (unsigned int tt = 0; tt < orig->mNumFaces;++tt) {
aiFace& f = orig->mFaces[tt];
for (unsigned int nn = 0; nn < f.mNumIndices;++nn)
ftbl_orig[f.mIndices[nn]] = tt;
for (unsigned int tt = 0; tt < orig->mNumFaces;++tt) {
aiFace& f = orig->mFaces[tt];
for (unsigned int nn = 0; nn < f.mNumIndices;++nn)
ftbl_orig[f.mIndices[nn]] = tt;
aiFace& f2 = inst->mFaces[tt];
for (unsigned int nn = 0; nn < f2.mNumIndices;++nn)
ftbl_inst[f2.mIndices[nn]] = tt;
}
if (0 != ::memcmp(ftbl_inst.get(),ftbl_orig.get(),orig->mNumVertices*sizeof(unsigned int)))
continue;
}
aiFace& f2 = inst->mFaces[tt];
for (unsigned int nn = 0; nn < f2.mNumIndices;++nn)
ftbl_inst[f2.mIndices[nn]] = tt;
}
if (0 != ::memcmp(ftbl_inst.get(),ftbl_orig.get(),orig->mNumVertices*sizeof(unsigned int)))
continue;
}
// We're still here. Or in other words: 'inst' is an instance of 'orig'.
// Place a marker in our list that we can easily update mesh indices.
remapping[i] = remapping[a];
// We're still here. Or in other words: 'inst' is an instance of 'orig'.
// Place a marker in our list that we can easily update mesh indices.
remapping[i] = remapping[a];
// Delete the instanced mesh, we don't need it anymore
delete inst;
pScene->mMeshes[i] = NULL;
break;
}
}
// Delete the instanced mesh, we don't need it anymore
delete inst;
pScene->mMeshes[i] = NULL;
break;
}
}
// If we didn't find a match for the current mesh: keep it
if (pScene->mMeshes[i]) {
remapping[i] = numMeshesOut++;
}
}
ai_assert(0 != numMeshesOut);
if (numMeshesOut != pScene->mNumMeshes) {
// If we didn't find a match for the current mesh: keep it
if (pScene->mMeshes[i]) {
remapping[i] = numMeshesOut++;
}
}
ai_assert(0 != numMeshesOut);
if (numMeshesOut != pScene->mNumMeshes) {
// Collapse the meshes array by removing all NULL entries
for (unsigned int real = 0, i = 0; real < numMeshesOut; ++i) {
if (pScene->mMeshes[i])
pScene->mMeshes[real++] = pScene->mMeshes[i];
}
// Collapse the meshes array by removing all NULL entries
for (unsigned int real = 0, i = 0; real < numMeshesOut; ++i) {
if (pScene->mMeshes[i])
pScene->mMeshes[real++] = pScene->mMeshes[i];
}
// And update the node graph with our nice lookup table
UpdateMeshIndices(pScene->mRootNode,remapping.get());
// And update the node graph with our nice lookup table
UpdateMeshIndices(pScene->mRootNode,remapping.get());
// write to log
if (!DefaultLogger::isNullLogger()) {
// write to log
if (!DefaultLogger::isNullLogger()) {
char buffer[512];
::sprintf(buffer,"FindInstancesProcess finished. Found %i instances",pScene->mNumMeshes-numMeshesOut);
DefaultLogger::get()->info(buffer);
}
pScene->mNumMeshes = numMeshesOut;
}
else DefaultLogger::get()->debug("FindInstancesProcess finished. No instanced meshes found");
}
char buffer[512];
::sprintf(buffer,"FindInstancesProcess finished. Found %i instances",pScene->mNumMeshes-numMeshesOut);
DefaultLogger::get()->info(buffer);
}
pScene->mNumMeshes = numMeshesOut;
}
else DefaultLogger::get()->debug("FindInstancesProcess finished. No instanced meshes found");
}
}