Merge branch 'Muzz-fix/import-weld-epsilon'
This commit is contained in:
@@ -193,6 +193,7 @@ int32 FindVertex(const MeshData& mesh, int32 vertexIndex, int32 startIndex, int3
|
||||
#if USE_SPATIAL_SORT
|
||||
, const Assimp::SpatialSort& spatialSort
|
||||
, std::vector<unsigned int>& spatialSortCache
|
||||
, float posEpsilon
|
||||
#endif
|
||||
)
|
||||
{
|
||||
@@ -204,7 +205,7 @@ int32 FindVertex(const MeshData& mesh, int32 vertexIndex, int32 startIndex, int3
|
||||
|
||||
#if USE_SPATIAL_SORT
|
||||
const Float3 vPosition = mesh.Positions[vertexIndex];
|
||||
spatialSort.FindPositions(*(aiVector3D*)&vPosition, 1e-5f, spatialSortCache);
|
||||
spatialSort.FindPositions(*(aiVector3D*)&vPosition, posEpsilon, spatialSortCache);
|
||||
if (spatialSortCache.empty())
|
||||
return INVALID_INDEX;
|
||||
|
||||
@@ -298,6 +299,14 @@ void MeshData::BuildIndexBuffer()
|
||||
Assimp::SpatialSort vertexFinder;
|
||||
vertexFinder.Fill((const aiVector3D*)Positions.Get(), vertexCount, sizeof(Float3));
|
||||
std::vector<unsigned int> spatialSortCache;
|
||||
|
||||
// Ensure that the weld radius stays above float precision based on the mesh's largest coordinate
|
||||
float maxAbs = 0.0f;
|
||||
for (int32 i = 0; i < vertexCount; i++)
|
||||
{
|
||||
maxAbs = Math::Max(maxAbs, Positions[i].GetAbsolute().MaxValue());
|
||||
}
|
||||
const float posEpsilon = Math::Max(1e-5f, maxAbs * 1e-6f);
|
||||
#endif
|
||||
|
||||
// Build index buffer
|
||||
@@ -306,7 +315,7 @@ void MeshData::BuildIndexBuffer()
|
||||
// Find duplicated vertex before the current one
|
||||
const int32 reuseVertexIndex = FindVertex(*this, vertexIndex, 0, vertexIndex, mapping
|
||||
#if USE_SPATIAL_SORT
|
||||
, vertexFinder, spatialSortCache
|
||||
, vertexFinder, spatialSortCache, posEpsilon
|
||||
#endif
|
||||
);
|
||||
if (reuseVertexIndex == INVALID_INDEX)
|
||||
|
||||
@@ -164,7 +164,7 @@ void SpatialSort::FindPositions(const aiVector3D& pPosition,
|
||||
// Add all positions inside the distance range within the given radius to the result aray
|
||||
std::vector<Entry>::const_iterator it = mPositions.begin() + index;
|
||||
const ai_real pSquared = pRadius * pRadius;
|
||||
while (it->mDistance < maxDist)
|
||||
while (it->mDistance <= maxDist)
|
||||
{
|
||||
if ((it->mPosition - pPosition).SquareLength() < pSquared)
|
||||
poResults.push_back(it->mIndex);
|
||||
|
||||
Reference in New Issue
Block a user