30
30
31
31
#include " importer_mesh.h"
32
32
33
+ #include " core/io/marshalls.h"
33
34
#include " core/math/random_pcg.h"
34
35
#include " core/math/static_raycaster.h"
35
36
#include " scene/resources/surface_tool.h"
@@ -424,9 +425,8 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli
424
425
normal_weights[j] = 2.0 ; // Give some weight to normal preservation, may be worth exposing as an import setting
425
426
}
426
427
427
- const float max_mesh_error = FLT_MAX; // We don't want to limit by error, just by index target
428
- float scale = SurfaceTool::simplify_scale_func ((const float *)merged_vertices_ptr, merged_vertex_count, sizeof (Vector3));
429
- float mesh_error = 0 .0f ;
428
+ Vector<float > merged_vertices_f32 = vector3_to_float32_array (merged_vertices_ptr, merged_vertex_count);
429
+ float scale = SurfaceTool::simplify_scale_func (merged_vertices_f32.ptr (), merged_vertex_count, sizeof (float ) * 3 );
430
430
431
431
unsigned int index_target = 12 ; // Start with the smallest target, 4 triangles
432
432
unsigned int last_index_count = 0 ;
@@ -446,11 +446,25 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli
446
446
raycaster->commit ();
447
447
}
448
448
449
+ const float max_mesh_error = FLT_MAX; // We don't want to limit by error, just by index target
450
+ float mesh_error = 0 .0f ;
451
+
449
452
while (index_target < index_count) {
450
453
PackedInt32Array new_indices;
451
454
new_indices.resize (index_count);
452
455
453
- size_t new_index_count = SurfaceTool::simplify_with_attrib_func ((unsigned int *)new_indices.ptrw (), (const uint32_t *)merged_indices_ptr, index_count, (const float *)merged_vertices_ptr, merged_vertex_count, sizeof (Vector3), index_target, max_mesh_error, &mesh_error, (float *)merged_normals.ptr (), normal_weights.ptr (), 3 );
456
+ Vector<float > merged_normals_f32 = vector3_to_float32_array (merged_normals.ptr (), merged_normals.size ());
457
+
458
+ size_t new_index_count = SurfaceTool::simplify_with_attrib_func (
459
+ (unsigned int *)new_indices.ptrw (),
460
+ (const uint32_t *)merged_indices_ptr, index_count,
461
+ merged_vertices_f32.ptr (), merged_vertex_count,
462
+ sizeof (float ) * 3 , // Vertex stride
463
+ index_target,
464
+ max_mesh_error,
465
+ &mesh_error,
466
+ merged_normals_f32.ptr (),
467
+ normal_weights.ptr (), 3 );
454
468
455
469
if (new_index_count < last_index_count * 1 .5f ) {
456
470
index_target = index_target * 1 .5f ;
0 commit comments