From b08340f1831005ae227577899a64408cc939a12d Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 10 Jun 2022 19:43:14 +0300 Subject: SL-17475 Remap models before simplification --- indra/llmath/CMakeLists.txt | 3 +++ indra/llmath/llvolume.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ indra/llmath/llvolume.h | 4 ++++ 3 files changed, 49 insertions(+) (limited to 'indra/llmath') diff --git a/indra/llmath/CMakeLists.txt b/indra/llmath/CMakeLists.txt index 552e820127..4617309606 100644 --- a/indra/llmath/CMakeLists.txt +++ b/indra/llmath/CMakeLists.txt @@ -4,12 +4,14 @@ project(llmath) include(00-Common) include(LLCommon) +include(LLMeshOptimizer) include(bugsplat) include(Boost) include_directories( ${LLCOMMON_INCLUDE_DIRS} ${LLCOMMON_SYSTEM_INCLUDE_DIRS} + ${LLMESHOPTIMIZER_INCLUDE_DIRS} ) set(llmath_SOURCE_FILES @@ -109,6 +111,7 @@ add_library (llmath ${llmath_SOURCE_FILES}) target_link_libraries(llmath ${LLCOMMON_LIBRARIES} + ${LLMESHOPTIMIZER_LIBRARIES} ) # Add tests diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 5099920f32..23f372f6e3 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -49,6 +49,7 @@ #include "llsdserialize.h" #include "llvector4a.h" #include "llmatrix4a.h" +#include "llmeshoptimizer.h" #include "lltimer.h" #define DEBUG_SILHOUETTE_BINORMALS 0 @@ -4952,6 +4953,47 @@ bool LLVolumeFace::VertexMapData::ComparePosition::operator()(const LLVector3& a return a.mV[2] < b.mV[2]; } +void LLVolumeFace::remap() +{ + // generate a remap buffer + std::vector remap(mNumIndices); + S32 remap_vertices_count = LLMeshOptimizer::generateRemapMulti(&remap[0], + NULL, + mNumIndices, + mPositions, + mNormals, + mTexCoords, + mNumVertices); + + // Allocate new buffers + U16* remap_indices = (U16*)ll_aligned_malloc_16(mNumIndices * sizeof(U16)); + + S32 tc_bytes_size = ((remap_vertices_count * sizeof(LLVector2)) + 0xF) & ~0xF; + LLVector4a* remap_positions = (LLVector4a*)ll_aligned_malloc<64>(sizeof(LLVector4a) * 2 * remap_vertices_count + tc_bytes_size); + LLVector4a* remap_normals = remap_positions + remap_vertices_count; + LLVector2* remap_tex_coords = (LLVector2*)(remap_normals + remap_vertices_count); + + // fill the buffers + LLMeshOptimizer::remapIndexBufferU16(remap_indices, mIndices, mNumIndices, &remap[0]); + LLMeshOptimizer::remapPositionsBuffer(remap_positions, mPositions, mNumVertices, &remap[0]); + LLMeshOptimizer::remapNormalsBuffer(remap_normals, mNormals, mNumVertices, &remap[0]); + LLMeshOptimizer::remapUVBuffer(remap_tex_coords, mTexCoords, mNumVertices, &remap[0]); + + // free unused buffers + ll_aligned_free_16(mIndices); + ll_aligned_free<64>(mPositions); + ll_aligned_free_16(mTangents); + + mTangents = NULL; + + mIndices = remap_indices; + mPositions = remap_positions; + mNormals = remap_normals; + mTexCoords = remap_tex_coords; + mNumVertices = remap_vertices_count; + mNumAllocatedVertices = remap_vertices_count; +} + void LLVolumeFace::optimize(F32 angle_cutoff) { LLVolumeFace new_face; diff --git a/indra/llmath/llvolume.h b/indra/llmath/llvolume.h index c0b224b1ff..9697952f5b 100644 --- a/indra/llmath/llvolume.h +++ b/indra/llmath/llvolume.h @@ -902,6 +902,10 @@ public: typedef std::map, VertexMapData::ComparePosition > PointMap; }; + // Eliminates non unique triangles, takes positions, + // normals and texture coordinates into account. + void remap(); + void optimize(F32 angle_cutoff = 2.f); bool cacheOptimize(); -- cgit v1.2.3 From 45bcefd981e268b158d11d59f2ba9063293986a6 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Tue, 14 Jun 2022 16:39:46 +0300 Subject: SL-17475 fix remap causing an assert --- indra/llmath/llvolume.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 23f372f6e3..9efdcd4e8c 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -4957,8 +4957,8 @@ void LLVolumeFace::remap() { // generate a remap buffer std::vector remap(mNumIndices); - S32 remap_vertices_count = LLMeshOptimizer::generateRemapMulti(&remap[0], - NULL, + S32 remap_vertices_count = LLMeshOptimizer::generateRemapMultiU16(&remap[0], + mIndices, mNumIndices, mPositions, mNormals, -- cgit v1.2.3 From b1cbf369cf63f270cb810f640a14420be53035ed Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Tue, 14 Jun 2022 18:33:50 +0300 Subject: SL-17475 Use a shadow indices buffer before simplification --- indra/llmath/llvolume.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 9efdcd4e8c..04d3e9fc08 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -4955,7 +4955,7 @@ bool LLVolumeFace::VertexMapData::ComparePosition::operator()(const LLVector3& a void LLVolumeFace::remap() { - // generate a remap buffer + // Generate a remap buffer std::vector remap(mNumIndices); S32 remap_vertices_count = LLMeshOptimizer::generateRemapMultiU16(&remap[0], mIndices, @@ -4966,26 +4966,29 @@ void LLVolumeFace::remap() mNumVertices); // Allocate new buffers - U16* remap_indices = (U16*)ll_aligned_malloc_16(mNumIndices * sizeof(U16)); + S32 size = ((mNumIndices * sizeof(U16)) + 0xF) & ~0xF; + U16* remap_indices = (U16*)ll_aligned_malloc_16(size); S32 tc_bytes_size = ((remap_vertices_count * sizeof(LLVector2)) + 0xF) & ~0xF; LLVector4a* remap_positions = (LLVector4a*)ll_aligned_malloc<64>(sizeof(LLVector4a) * 2 * remap_vertices_count + tc_bytes_size); LLVector4a* remap_normals = remap_positions + remap_vertices_count; LLVector2* remap_tex_coords = (LLVector2*)(remap_normals + remap_vertices_count); - // fill the buffers + // Fill the buffers LLMeshOptimizer::remapIndexBufferU16(remap_indices, mIndices, mNumIndices, &remap[0]); LLMeshOptimizer::remapPositionsBuffer(remap_positions, mPositions, mNumVertices, &remap[0]); LLMeshOptimizer::remapNormalsBuffer(remap_normals, mNormals, mNumVertices, &remap[0]); LLMeshOptimizer::remapUVBuffer(remap_tex_coords, mTexCoords, mNumVertices, &remap[0]); - // free unused buffers + // Free unused buffers ll_aligned_free_16(mIndices); ll_aligned_free<64>(mPositions); - ll_aligned_free_16(mTangents); + // Tangets are now invalid + ll_aligned_free_16(mTangents); mTangents = NULL; + // Assign new values mIndices = remap_indices; mPositions = remap_positions; mNormals = remap_normals; -- cgit v1.2.3 From f451672b0c549092796a018997152cbeb57418b2 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 16 Jun 2022 16:46:04 +0300 Subject: SL-17475 Fix wrong remap buffer size --- indra/llmath/llvolume.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 04d3e9fc08..4a069b0f63 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -4956,7 +4956,7 @@ bool LLVolumeFace::VertexMapData::ComparePosition::operator()(const LLVector3& a void LLVolumeFace::remap() { // Generate a remap buffer - std::vector remap(mNumIndices); + std::vector remap(mNumVertices); S32 remap_vertices_count = LLMeshOptimizer::generateRemapMultiU16(&remap[0], mIndices, mNumIndices, -- cgit v1.2.3