DRTVWR-542 Rename simplification methods in UI and add a fallback

master
Andrey Kleshchev 2021-07-28 21:25:18 +03:00
parent d64b1bded9
commit 1531a31cd9
3 changed files with 46 additions and 40 deletions

View File

@ -46,6 +46,7 @@ public:
// returns amount of indices in destiantion
// result_error returns how far from original the model is in % if not NULL
// Works with U32 indices (LLFace uses U16 indices)
static U64 simplifyU32(
U32 *destination,
const U32 *indices,
@ -57,8 +58,9 @@ public:
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
// Returns amount of indices in destiantion
// Result_error returns how far from original the model is in % if not NULL
// Meant for U16 indices (LLFace uses U16 indices)
static U64 simplify(
U16 *destination,
const U16 *indices,

View File

@ -1840,7 +1840,9 @@ void LLModelPreview::genMeshOptimizerLODs(S32 which_lod, S32 meshopt_mode, U32 d
LLModel* target_model = mModel[lod][mdl_idx];
if (meshopt_mode == MESH_OPTIMIZER_COMBINE)
S32 model_meshopt_mode = meshopt_mode;
if (model_meshopt_mode == MESH_OPTIMIZER_COMBINE)
{
// Figure out buffer size
S32 size_indices = 0;
@ -1961,22 +1963,23 @@ void LLModelPreview::genMeshOptimizerLODs(S32 which_lod, S32 meshopt_mode, U32 d
if (copy_triangle)
{
if (idx >= U16_MAX)
{
// Shouldn't happen due to simplification?
// Todo: add a fallback?
LL_ERRS() << "Over triangle limit" << LL_ENDL;
break;
}
if (old_to_new_positions_map[idx] == -1)
{
// New position, need to copy it
// Validate size
if (buf_positions_copied >= U16_MAX)
{
// Shouldn't happen due to simplification?
LL_ERRS() << "Over triangle limit" << LL_ENDL;
// Normally this shouldn't happen since the whole point is to reduce amount of vertices
// but it might happen if user tries to run optimization with too large triangle or error value
// so fallback to 'per face' mode or verify requested limits and copy base model as is.
LL_WARNS() << "Over triangle limit. Failed to optimize in 'per object' mode, falling back to per face variant for"
<< " model " << target_model->mLabel
<< " target Indices: " << target_indices
<< " new Indices: " << new_indices
<< " original count: " << size_indices
<< " error treshold: " << lod_error_threshold
<< LL_ENDL;
model_meshopt_mode = MESH_OPTIMIZER;
break;
}
@ -1999,6 +2002,11 @@ void LLModelPreview::genMeshOptimizerLODs(S32 which_lod, S32 meshopt_mode, U32 d
}
}
if (buf_positions_copied >= U16_MAX)
{
break;
}
LLVolumeFace &new_face = target_model->getVolumeFace(face_idx);
//new_face = face; //temp
@ -2037,7 +2045,9 @@ void LLModelPreview::genMeshOptimizerLODs(S32 which_lod, S32 meshopt_mode, U32 d
ll_aligned_free_32(buffer_indices);
ll_aligned_free_32(combined_indices);
}
else
if (model_meshopt_mode == MESH_OPTIMIZER
|| model_meshopt_mode == MESH_OPTIMIZER_SLOPPY)
{
// Run meshoptimizer for each face
for (U32 face_idx = 0; face_idx < base->getNumVolumeFaces(); ++face_idx)
@ -2049,21 +2059,11 @@ void LLModelPreview::genMeshOptimizerLODs(S32 which_lod, S32 meshopt_mode, U32 d
S32 size = (num_indices * sizeof(U16) + 0xF) & ~0xF;
U16* output = (U16*)ll_aligned_malloc_16(size);
/*
generateShadowIndexBuffer appears to deform model
LLMeshOptimizer::generateShadowIndexBuffer(
&shadow[0],
face.mIndices,
num_indices,
&face.mPositions[0],
face.mNumVertices);
*/
S32 target_indices = 0;
F32 result_code = 0; // how far from original the model is, 1 == 100%
S32 new_indices = 0;
if (meshopt_mode == MESH_OPTIMIZER_SLOPPY)
if (model_meshopt_mode == MESH_OPTIMIZER_SLOPPY)
{
target_indices = llfloor(num_indices * indices_ratio);
new_indices = LLMeshOptimizer::simplifySloppy(
@ -2078,7 +2078,7 @@ void LLModelPreview::genMeshOptimizerLODs(S32 which_lod, S32 meshopt_mode, U32 d
&result_code);
}
if (meshopt_mode == MESH_OPTIMIZER)
if (model_meshopt_mode == MESH_OPTIMIZER)
{
target_indices = llmax(3, llfloor(num_indices * indices_ratio)); // leave at least one triangle
new_indices = LLMeshOptimizer::simplify(
@ -2100,7 +2100,9 @@ void LLModelPreview::genMeshOptimizerLODs(S32 which_lod, S32 meshopt_mode, U32 d
<< " of model " << target_model->mLabel
<< " target Indices: " << target_indices
<< " new Indices: " << new_indices
<< " original count: " << num_indices << LL_ENDL;
<< " original count: " << num_indices
<< " error treshold: " << lod_error_threshold
<< LL_ENDL;
}
LLVolumeFace &new_face = target_model->getVolumeFace(face_idx);
@ -2118,7 +2120,9 @@ void LLModelPreview::genMeshOptimizerLODs(S32 which_lod, S32 meshopt_mode, U32 d
LL_INFOS() << "No indices generated by meshoptimizer for face " << face_idx
<< " of model " << target_model->mLabel
<< " target Indices: " << target_indices
<< " original count: " << num_indices << LL_ENDL;
<< " original count: " << num_indices
<< " error treshold: " << lod_error_threshold
<< LL_ENDL;
}
// Face got optimized away

View File

@ -178,15 +178,15 @@
value="Generate" />
<item
name="MeshOpt"
label="MeshOpt"
label="Simplify per face"
value="MeshOpt" />
<item
name="MeshOptSloppy"
label="MeshOptSloppy"
label="Simplify sloppy"
value="MeshOptSloppy" />
<item
name="MeshOptCombine"
label="MeshOptCombine"
label="Simplify per object"
value="MeshOptCombine" />
</combo_box>
<line_editor
@ -319,15 +319,15 @@
value="Generate" />
<item
name="MeshOpt"
label="MeshOpt"
label="Simplify per face"
value="MeshOpt" />
<item
name="MeshOptSloppy"
label="MeshOptSloppy"
label="Simplify sloppy"
value="MeshOptSloppy" />
<item
name="MeshOptCombine"
label="MeshOptCombine"
label="Simplify per object"
value="MeshOptCombine" />
<item
name="Use LoD above"
@ -464,15 +464,15 @@
value="Generate" />
<item
name="MeshOpt"
label="MeshOpt"
label="Simplify per face"
value="MeshOpt" />
<item
name="MeshOptSloppy"
label="MeshOptSloppy"
label="Simplify sloppy"
value="MeshOptSloppy" />
<item
name="MeshOptCombine"
label="MeshOptCombine"
label="Simplify per object"
value="MeshOptCombine" />
<item
name="Use LoD above"
@ -609,15 +609,15 @@
value="Generate" />
<item
name="MeshOpt"
label="MeshOpt"
label="Simplify per face"
value="MeshOpt" />
<item
name="MeshOptSloppy"
label="MeshOptSloppy"
label="Simplify sloppy"
value="MeshOptSloppy" />
<item
name="MeshOptCombine"
label="MeshOptCombine"
label="Simplify per object"
value="MeshOptCombine" />
<item
name="Use LoD above"