Merge branch 'master' into fix-build-with-m3d-import-only
commit
e9f95e5ab6
|
@ -105,7 +105,11 @@ void JoinVerticesProcess::Execute( aiScene* pScene) {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
bool areVerticesEqual(const Vertex &lhs, const Vertex &rhs, bool complex) {
|
bool areVerticesEqual(
|
||||||
|
const Vertex &lhs,
|
||||||
|
const Vertex &rhs,
|
||||||
|
unsigned numUVChannels,
|
||||||
|
unsigned numColorChannels) {
|
||||||
// A little helper to find locally close vertices faster.
|
// A little helper to find locally close vertices faster.
|
||||||
// Try to reuse the lookup table from the last step.
|
// Try to reuse the lookup table from the last step.
|
||||||
const static float epsilon = 1e-5f;
|
const static float epsilon = 1e-5f;
|
||||||
|
@ -124,10 +128,6 @@ bool areVerticesEqual(const Vertex &lhs, const Vertex &rhs, bool complex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((lhs.texcoords[0] - rhs.texcoords[0]).SquareLength() > squareEpsilon) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((lhs.tangent - rhs.tangent).SquareLength() > squareEpsilon) {
|
if ((lhs.tangent - rhs.tangent).SquareLength() > squareEpsilon) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -136,19 +136,18 @@ bool areVerticesEqual(const Vertex &lhs, const Vertex &rhs, bool complex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Usually we won't have vertex colors or multiple UVs, so we can skip from here
|
for (unsigned i = 0; i < numUVChannels; i++) {
|
||||||
// Actually this increases runtime performance slightly, at least if branch
|
if ((lhs.texcoords[i] - rhs.texcoords[i]).SquareLength() > squareEpsilon) {
|
||||||
// prediction is on our side.
|
return false;
|
||||||
if (complex) {
|
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
if (i > 0 && (lhs.texcoords[i] - rhs.texcoords[i]).SquareLength() > squareEpsilon) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (GetColorDifference(lhs.colors[i], rhs.colors[i]) > squareEpsilon) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < numColorChannels; i++) {
|
||||||
|
if (GetColorDifference(lhs.colors[i], rhs.colors[i]) > squareEpsilon) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,9 +240,16 @@ struct std::hash<Vertex> {
|
||||||
//template specialization for std::equal_to for Vertex
|
//template specialization for std::equal_to for Vertex
|
||||||
template<>
|
template<>
|
||||||
struct std::equal_to<Vertex> {
|
struct std::equal_to<Vertex> {
|
||||||
|
equal_to(unsigned numUVChannels, unsigned numColorChannels) :
|
||||||
|
mNumUVChannels(numUVChannels),
|
||||||
|
mNumColorChannels(numColorChannels) {}
|
||||||
bool operator()(const Vertex &lhs, const Vertex &rhs) const {
|
bool operator()(const Vertex &lhs, const Vertex &rhs) const {
|
||||||
return areVerticesEqual(lhs, rhs, false);
|
return areVerticesEqual(lhs, rhs, mNumUVChannels, mNumColorChannels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned mNumUVChannels;
|
||||||
|
unsigned mNumColorChannels;
|
||||||
};
|
};
|
||||||
// now start the JoinVerticesProcess
|
// now start the JoinVerticesProcess
|
||||||
int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex) {
|
int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex) {
|
||||||
|
@ -316,8 +322,13 @@ int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex) {
|
||||||
uniqueAnimatedVertices[animMeshIndex].reserve(pMesh->mNumVertices);
|
uniqueAnimatedVertices[animMeshIndex].reserve(pMesh->mNumVertices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// a map that maps a vertix to its new index
|
// a map that maps a vertex to its new index
|
||||||
std::unordered_map<Vertex,int> vertex2Index;
|
const auto numBuckets = pMesh->mNumVertices;
|
||||||
|
const auto hasher = std::hash<Vertex>();
|
||||||
|
const auto comparator = std::equal_to<Vertex>(
|
||||||
|
pMesh->GetNumUVChannels(),
|
||||||
|
pMesh->GetNumColorChannels());
|
||||||
|
std::unordered_map<Vertex, int> vertex2Index(numBuckets, hasher, comparator);
|
||||||
// we can not end up with more vertices than we started with
|
// we can not end up with more vertices than we started with
|
||||||
vertex2Index.reserve(pMesh->mNumVertices);
|
vertex2Index.reserve(pMesh->mNumVertices);
|
||||||
// Now check each vertex if it brings something new to the table
|
// Now check each vertex if it brings something new to the table
|
||||||
|
|
Loading…
Reference in New Issue