summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Kleshchev <andreykproductengine@lindenlab.com>2021-07-12 19:18:25 +0300
committerAndrey Kleshchev <andreykproductengine@lindenlab.com>2021-07-12 19:18:25 +0300
commit938969c811732a3e2faf0229301de286bd12c1a5 (patch)
tree808583514409914544ce476cf9f6d20dfb397c3d
parenteb13133e3e0020c73399414cea4d9b39ef526cd3 (diff)
DRTVWR-542 WIP #6
Trying out 'sloppy' variant
-rw-r--r--indra/llmeshoptimizer/llmeshoptimizer.cpp24
-rw-r--r--indra/llmeshoptimizer/llmeshoptimizer.h12
-rw-r--r--indra/newview/llfloatermodelpreview.cpp8
-rw-r--r--indra/newview/llmodelpreview.cpp42
-rw-r--r--indra/newview/llmodelpreview.h5
-rw-r--r--indra/newview/skins/default/xui/en/floater_model_preview.xml16
6 files changed, 92 insertions, 15 deletions
diff --git a/indra/llmeshoptimizer/llmeshoptimizer.cpp b/indra/llmeshoptimizer/llmeshoptimizer.cpp
index dbf8e5b631..2f3d2491c2 100644
--- a/indra/llmeshoptimizer/llmeshoptimizer.cpp
+++ b/indra/llmeshoptimizer/llmeshoptimizer.cpp
@@ -66,3 +66,27 @@ U64 LLMeshOptimizer::simplify(U16 *destination,
result_error
);
}
+
+//static
+U64 LLMeshOptimizer::simplifySloppy(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
+ )
+{
+ const size_t vertex_stride = 4; // should be either 0 or 4
+ return meshopt_simplifySloppy<unsigned short>(destination,
+ indices,
+ index_count,
+ (const float*)vertex_positions, // verify that it is correct to convert to float
+ vertex_count,
+ vertex_stride,
+ target_index_count,
+ target_error,
+ result_error
+ );
+}
diff --git a/indra/llmeshoptimizer/llmeshoptimizer.h b/indra/llmeshoptimizer/llmeshoptimizer.h
index 157de0251d..c4250c537d 100644
--- a/indra/llmeshoptimizer/llmeshoptimizer.h
+++ b/indra/llmeshoptimizer/llmeshoptimizer.h
@@ -47,6 +47,18 @@ public:
U64 target_index_count,
F32 target_error,
F32* result_error);
+
+ // returns amount of indices in destiantion
+ // result_error returns how far from original the model is in % if not NULL
+ static U64 simplifySloppy(
+ 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/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp
index 85250abefc..d61311d610 100644
--- a/indra/newview/llfloatermodelpreview.cpp
+++ b/indra/newview/llfloatermodelpreview.cpp
@@ -730,7 +730,10 @@ void LLFloaterModelPreview::onLODParamCommit(S32 lod, bool enforce_tri_limit)
mModelPreview->onLODGenerateParamCommit(lod, enforce_tri_limit);
break;
case LLModelPreview::MESH_OPTIMIZER:
- mModelPreview->onLODMeshOptimizerParamCommit(lod, enforce_tri_limit);
+ mModelPreview->onLODMeshOptimizerParamCommit(lod, enforce_tri_limit, false);
+ break;
+ case LLModelPreview::MESH_OPTIMIZER_SLOPPY:
+ mModelPreview->onLODMeshOptimizerParamCommit(lod, enforce_tri_limit, true);
break;
default:
LL_ERRS() << "Only supposed to be called to generate models" << LL_ENDL;
@@ -1736,7 +1739,8 @@ void LLFloaterModelPreview::onLoDSourceCommit(S32 lod)
LLComboBox* lod_source_combo = getChild<LLComboBox>("lod_source_" + lod_name[lod]);
S32 index = lod_source_combo->getCurrentIndex();
if (index == LLModelPreview::GENERATE
- || index == LLModelPreview::MESH_OPTIMIZER)
+ || index == LLModelPreview::MESH_OPTIMIZER
+ || index == LLModelPreview::MESH_OPTIMIZER_SLOPPY)
{ //rebuild LoD to update triangle counts
onLODParamCommit(lod, true);
}
diff --git a/indra/newview/llmodelpreview.cpp b/indra/newview/llmodelpreview.cpp
index 5eb49ee938..c33b48c16e 100644
--- a/indra/newview/llmodelpreview.cpp
+++ b/indra/newview/llmodelpreview.cpp
@@ -1706,7 +1706,7 @@ void LLModelPreview::genGlodLODs(S32 which_lod, U32 decimation, bool enforce_tri
}
}
-void LLModelPreview::genMeshOptimizerLODs(S32 which_lod, U32 decimation, bool enforce_tri_limit)
+void LLModelPreview::genMeshOptimizerLODs(S32 which_lod, U32 decimation, bool enforce_tri_limit, bool sloppy)
{
LL_INFOS() << "Generating lod " << which_lod << " using meshoptimizer" << LL_ENDL;
// Allow LoD from -1 to LLModel::LOD_PHYSICS
@@ -1851,14 +1851,34 @@ void LLModelPreview::genMeshOptimizerLODs(S32 which_lod, U32 decimation, bool en
S32 target_indices = llmax(3, llfloor(num_indices * indices_ratio)); // leave at least one triangle
F32 result_code = 0; // how far from original the model is
- S32 new_indices = LLMeshOptimizer::simplify(&output[0],
- face.mIndices,
- num_indices,
- &face.mPositions[0],
- face.mNumVertices,
- target_indices,
- lod_error_threshold,
- &result_code);
+ S32 new_indices = 0;
+
+ if (sloppy)
+ {
+ new_indices = LLMeshOptimizer::simplifySloppy(
+ &output[0],
+ face.mIndices,
+ num_indices,
+ &face.mPositions[0],
+ face.mNumVertices,
+ target_indices,
+ lod_error_threshold,
+ &result_code);
+ }
+
+ if (new_indices <= 0)
+ {
+ new_indices = LLMeshOptimizer::simplify(
+ &output[0],
+ face.mIndices,
+ num_indices,
+ &face.mPositions[0],
+ face.mNumVertices,
+ target_indices,
+ lod_error_threshold,
+ &result_code);
+ }
+
if (result_code < 0)
{
@@ -3800,11 +3820,11 @@ void LLModelPreview::onLODGenerateParamCommit(S32 lod, bool enforce_tri_limit)
}
}
-void LLModelPreview::onLODMeshOptimizerParamCommit(S32 requested_lod, bool enforce_tri_limit)
+void LLModelPreview::onLODMeshOptimizerParamCommit(S32 requested_lod, bool enforce_tri_limit, bool sloppy)
{
if (!mLODFrozen)
{
- genMeshOptimizerLODs(requested_lod, 3, enforce_tri_limit);
+ genMeshOptimizerLODs(requested_lod, 3, enforce_tri_limit, sloppy);
refresh();
}
}
diff --git a/indra/newview/llmodelpreview.h b/indra/newview/llmodelpreview.h
index f6f4ce580d..9f38156ca2 100644
--- a/indra/newview/llmodelpreview.h
+++ b/indra/newview/llmodelpreview.h
@@ -126,6 +126,7 @@ public:
LOD_FROM_FILE = 0,
GENERATE,
MESH_OPTIMIZER,
+ MESH_OPTIMIZER_SLOPPY,
USE_LOD_ABOVE,
} eLoDMode;
@@ -163,7 +164,7 @@ public:
bool lodsReady() { return !mGenLOD && mLodsQuery.empty(); }
void queryLODs() { mGenLOD = true; };
void genGlodLODs(S32 which_lod = -1, U32 decimation = 3, bool enforce_tri_limit = false);
- void genMeshOptimizerLODs(S32 which_lod = -1, U32 decimation = 3, bool enforce_tri_limit = false);
+ void genMeshOptimizerLODs(S32 which_lod = -1, U32 decimation = 3, bool enforce_tri_limit = false, bool sloppy = false);
void generateNormals();
void restoreNormals();
U32 calcResourceCost();
@@ -175,7 +176,7 @@ public:
void updateLodControls(S32 lod);
void clearGLODGroup();
void onLODGenerateParamCommit(S32 lod, bool enforce_tri_limit);
- void onLODMeshOptimizerParamCommit(S32 lod, bool enforce_tri_limit);
+ void onLODMeshOptimizerParamCommit(S32 lod, bool enforce_tri_limit, bool sloppy);
void addEmptyFace(LLModel* pTarget);
const bool getModelPivot(void) const { return mHasPivot; }
diff --git a/indra/newview/skins/default/xui/en/floater_model_preview.xml b/indra/newview/skins/default/xui/en/floater_model_preview.xml
index 96bda42316..230284555c 100644
--- a/indra/newview/skins/default/xui/en/floater_model_preview.xml
+++ b/indra/newview/skins/default/xui/en/floater_model_preview.xml
@@ -180,6 +180,10 @@
name="MeshOpt"
label="MeshOpt"
value="MeshOpt" />
+ <item
+ name="MeshOptSloppy"
+ label="MeshOptSloppy"
+ value="MeshOptSloppy" />
</combo_box>
<line_editor
follows="left|top"
@@ -314,6 +318,10 @@
label="MeshOpt"
value="MeshOpt" />
<item
+ name="MeshOptSloppy"
+ label="MeshOptSloppy"
+ value="MeshOptSloppy" />
+ <item
name="Use LoD above"
label="Use LoD above"
value="Use LoD above" />
@@ -451,6 +459,10 @@
label="MeshOpt"
value="MeshOpt" />
<item
+ name="MeshOptSloppy"
+ label="MeshOptSloppy"
+ value="MeshOptSloppy" />
+ <item
name="Use LoD above"
label="Use LoD above"
value="Use LoD above" />
@@ -588,6 +600,10 @@
label="MeshOpt"
value="MeshOpt" />
<item
+ name="MeshOptSloppy"
+ label="MeshOptSloppy"
+ value="MeshOptSloppy" />
+ <item
name="Use LoD above"
label="Use LoD above"
value="Use LoD above" />