summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indra/cmake/CMakeLists.txt1
-rw-r--r--indra/cmake/MESHOPTIMIZER.cmake8
-rw-r--r--indra/llmeshoptimizer/CMakeLists.txt5
-rw-r--r--indra/llmeshoptimizer/llmeshoptimizer.cpp24
-rw-r--r--indra/llmeshoptimizer/llmeshoptimizer.h12
-rw-r--r--indra/newview/llmodelpreview.cpp27
6 files changed, 62 insertions, 15 deletions
diff --git a/indra/cmake/CMakeLists.txt b/indra/cmake/CMakeLists.txt
index 7795aa7db1..527a9cba43 100644
--- a/indra/cmake/CMakeLists.txt
+++ b/indra/cmake/CMakeLists.txt
@@ -75,6 +75,7 @@ set(cmake_SOURCE_FILES
LLXML.cmake
Linking.cmake
MediaPluginBase.cmake
+ MESHOPTIMIZER.cmake
NDOF.cmake
OPENAL.cmake
OpenGL.cmake
diff --git a/indra/cmake/MESHOPTIMIZER.cmake b/indra/cmake/MESHOPTIMIZER.cmake
index 7600a56999..6a31dc5569 100644
--- a/indra/cmake/MESHOPTIMIZER.cmake
+++ b/indra/cmake/MESHOPTIMIZER.cmake
@@ -1,16 +1,16 @@
# -*- cmake -*-
+include(Linking)
include(Prebuilt)
use_prebuilt_binary(meshoptimizer)
if (WINDOWS)
- set(MESHOPTIMIZER_LIBRARIES
- debug meshoptimizer
- optimized meshoptimizer)
+ set(MESHOPTIMIZER_LIBRARIES meshoptimizer.lib)
elseif (LINUX)
- set(MESHOPTIMIZER_LIBRARIES meshoptimizer)
+ set(MESHOPTIMIZER_LIBRARIES meshoptimizer.o)
elseif (DARWIN)
set(MESHOPTIMIZER_LIBRARIES libmeshoptimizer.o)
endif (WINDOWS)
+
set(MESHOPTIMIZER_INCLUDE_DIRS ${LIBS_PREBUILT_DIR}/include/meshoptimizer)
diff --git a/indra/llmeshoptimizer/CMakeLists.txt b/indra/llmeshoptimizer/CMakeLists.txt
index 1eea19de66..016794cfad 100644
--- a/indra/llmeshoptimizer/CMakeLists.txt
+++ b/indra/llmeshoptimizer/CMakeLists.txt
@@ -6,9 +6,11 @@ include(MESHOPTIMIZER)
include(00-Common)
include(LLCommon)
+include(LLMath)
include_directories(
${LLCOMMON_INCLUDE_DIRS}
+ ${LLMATH_INCLUDE_DIRS}
${LLMESHOPTIMIZER_INCLUDE_DIR}
${MESHOPTIMIZER_INCLUDE_DIRS}
${LIBS_PREBUILT_DIR}/include #access to boost headers, needed for LLError
@@ -34,7 +36,8 @@ list(APPEND llmeshoptimizer_SOURCE_FILES ${llmeshoptimizer_HEADER_FILES})
target_link_libraries(llmeshoptimizer
${LLCOMMON_LIBRARIES}
- ${MESHOPTIMIZER_LIBRARY})
+ ${LLMATH_LIBRARIES}
+ ${MESHOPTIMIZER_LIBRARIES})
# Add tests
diff --git a/indra/llmeshoptimizer/llmeshoptimizer.cpp b/indra/llmeshoptimizer/llmeshoptimizer.cpp
index c46fa8dcf3..02e97ef984 100644
--- a/indra/llmeshoptimizer/llmeshoptimizer.cpp
+++ b/indra/llmeshoptimizer/llmeshoptimizer.cpp
@@ -28,7 +28,6 @@
#include "meshoptimizer.h"
-
LLMeshOptimizer::LLMeshOptimizer()
{
// Todo: Looks like for memory management, we can add allocator and deallocator callbacks
@@ -38,12 +37,27 @@ LLMeshOptimizer::LLMeshOptimizer()
LLMeshOptimizer::~LLMeshOptimizer()
{
-
}
//static
-U32 LLMeshOptimizer::simplifyModel()
+U64 LLMeshOptimizer::simplify(U16 *destination,
+ const U16 *indices,
+ U64 index_count,
+ const LLVector4a *vertex_positions,
+ U64 vertex_count,
+ U64 target_index_count,
+ F32 target_error,
+ F32* result_error
+ )
{
- LL_WARNS() << "NOT IMPLEMENTED" << LL_ENDL;
- return 0;
+ return meshopt_simplify<unsigned short>(destination,
+ indices,
+ index_count,
+ (const float*)vertex_positions, // verify that it is correct to convert to float
+ vertex_count,
+ sizeof(LLVector4a), // should be either 0 or 4
+ target_index_count,
+ target_error,
+ result_error
+ );
}
diff --git a/indra/llmeshoptimizer/llmeshoptimizer.h b/indra/llmeshoptimizer/llmeshoptimizer.h
index d53ec2e24c..a0c53ed9e1 100644
--- a/indra/llmeshoptimizer/llmeshoptimizer.h
+++ b/indra/llmeshoptimizer/llmeshoptimizer.h
@@ -28,6 +28,8 @@
#include "linden_common.h"
+#include "llmath.h"
+
class LLMeshOptimizer
{
public:
@@ -35,7 +37,15 @@ public:
~LLMeshOptimizer();
// returns state
- static U32 simplifyModel();
+ static U64 simplify(
+ U16 *destination,
+ const U16 *indices,
+ U64 index_count,
+ const LLVector4a *vertex_positions,
+ U64 vertex_count,
+ U64 target_index_count,
+ F32 target_error,
+ F32* result_error);
private:
};
diff --git a/indra/newview/llmodelpreview.cpp b/indra/newview/llmodelpreview.cpp
index a6eef74cdc..f23143e3fa 100644
--- a/indra/newview/llmodelpreview.cpp
+++ b/indra/newview/llmodelpreview.cpp
@@ -3705,13 +3705,33 @@ void LLModelPreview::onLODMeshOptimizerParamCommit(S32 lod, bool enforce_tri_lim
mModel[lod][mdl_idx]->mLabel = name;
mModel[lod][mdl_idx]->mSubmodelID = base->mSubmodelID;
- //mModel[lod][mdl_idx]->setNumVolumeFaces( );
+ mModel[lod][mdl_idx]->setNumVolumeFaces(base->getNumVolumeFaces());
LLModel* target_model = mModel[lod][mdl_idx];
+ // Run meshoptimizer for each face
+ for (U32 face_idx = 0; face_idx < base->getNumVolumeFaces(); ++face_idx)
+ {
+ const LLVolumeFace &face = base->getVolumeFace(face_idx);
+ S32 num_indices = face.mNumIndices;
+ std::vector<U16> output(num_indices); //todo: do not allocate per each face, add one large buffer somewhere
+
+ // todo: run generateShadowIndexBuffer, at some stage, potentially inside simplify
+
+ F32 error_code = 0;
+ LLMeshOptimizer::simplify(&output[0],
+ &face.mIndices[0],
+ num_indices,
+ &face.mPositions[0],
+ face.mNumVertices,
+ triangle_count * 3, //todo: indices limit, not triangles limit*3
+ lod_error_threshold,
+ &error_code);
+
+ // todo: copy result into face
+ }
- //
- LLMeshOptimizer::simplifyModel(/*Some params*/);
+ LL_WARNS() << "WORK IN PROGRESS" << LL_ENDL;
//blind copy skin weights and just take closest skin weight to point on
//decimated mesh for now (auto-generating LODs with skin weights is still a bit
@@ -3755,7 +3775,6 @@ void LLModelPreview::onLODMeshOptimizerParamCommit(S32 lod, bool enforce_tri_lim
mResourceCost = calcResourceCost();
- LLMeshOptimizer::simplifyModel();
refresh();
}