Skip to content

Commit 3dbb193

Browse files
committed
Merge pull request godotengine#109990 from zeux/meshopt-0.25
Update meshoptimizer to v0.25
2 parents 01c4038 + 90ff46c commit 3dbb193

File tree

8 files changed

+1162
-143
lines changed

8 files changed

+1162
-143
lines changed

scene/resources/surface_tool.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ class SurfaceTool : public RefCounted {
8989
SIMPLIFY_ERROR_ABSOLUTE = 1 << 2, // From meshopt_SimplifyErrorAbsolute
9090
/* Remove disconnected parts of the mesh during simplification incrementally, regardless of the topological restrictions inside components. */
9191
SIMPLIFY_PRUNE = 1 << 3, // From meshopt_SimplifyPrune
92+
/* Produce more regular triangle sizes and shapes during simplification, at some cost to geometric quality. */
93+
SIMPLIFY_REGULARIZE = 1 << 4, // From meshopt_SimplifyRegularize
94+
/* Allow collapses across attribute discontinuities, except for vertices that are tagged with 0x02 in vertex_lock. */
95+
SIMPLIFY_PERMISSIVE = 1 << 5, // From meshopt_SimplifyPermissive
9296
};
9397

9498
typedef void (*OptimizeVertexCacheFunc)(unsigned int *destination, const unsigned int *indices, size_t index_count, size_t vertex_count);

thirdparty/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ Patches:
679679
## meshoptimizer
680680

681681
- Upstream: https://github.com/zeux/meshoptimizer
682-
- Version: 0.24 (7b2d4f4c817aea55d74dcd65d9763ac2ca608026, 2025)
682+
- Version: 0.25 (6daea4695c48338363b08022d2fb15deaef6ac09, 2025)
683683
- License: MIT
684684

685685
Files extracted from upstream repository:
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
// This file is part of meshoptimizer library; see meshoptimizer.h for version/license details
22
#include "meshoptimizer.h"
33

4+
#ifdef MESHOPTIMIZER_ALLOC_EXPORT
5+
meshopt_Allocator::Storage& meshopt_Allocator::storage()
6+
{
7+
static Storage s = {::operator new, ::operator delete };
8+
return s;
9+
}
10+
#endif
11+
412
void meshopt_setAllocator(void* (MESHOPTIMIZER_ALLOC_CALLCONV* allocate)(size_t), void (MESHOPTIMIZER_ALLOC_CALLCONV* deallocate)(void*))
513
{
6-
meshopt_Allocator::Storage::allocate = allocate;
7-
meshopt_Allocator::Storage::deallocate = deallocate;
14+
meshopt_Allocator::Storage& s = meshopt_Allocator::storage();
15+
s.allocate = allocate;
16+
s.deallocate = deallocate;
817
}

thirdparty/meshoptimizer/indexgenerator.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,31 @@ void meshopt_generateShadowIndexBufferMulti(unsigned int* destination, const uns
439439
generateShadowBuffer(destination, indices, index_count, vertex_count, hasher, allocator);
440440
}
441441

442+
void meshopt_generatePositionRemap(unsigned int* destination, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride)
443+
{
444+
using namespace meshopt;
445+
446+
assert(vertex_positions_stride >= 12 && vertex_positions_stride <= 256);
447+
assert(vertex_positions_stride % sizeof(float) == 0);
448+
449+
meshopt_Allocator allocator;
450+
VertexCustomHasher hasher = {vertex_positions, vertex_positions_stride / sizeof(float), NULL, NULL};
451+
452+
size_t table_size = hashBuckets(vertex_count);
453+
unsigned int* table = allocator.allocate<unsigned int>(table_size);
454+
memset(table, -1, table_size * sizeof(unsigned int));
455+
456+
for (size_t i = 0; i < vertex_count; ++i)
457+
{
458+
unsigned int* entry = hashLookup(table, table_size, hasher, unsigned(i), ~0u);
459+
460+
if (*entry == ~0u)
461+
*entry = unsigned(i);
462+
463+
destination[i] = *entry;
464+
}
465+
}
466+
442467
void meshopt_generateAdjacencyIndexBuffer(unsigned int* destination, const unsigned int* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride)
443468
{
444469
using namespace meshopt;

thirdparty/meshoptimizer/meshoptimizer.h

Lines changed: 126 additions & 44 deletions
Large diffs are not rendered by default.

thirdparty/meshoptimizer/overdrawoptimizer.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@
1010
namespace meshopt
1111
{
1212

13-
static void calculateSortData(float* sort_data, const unsigned int* indices, size_t index_count, const float* vertex_positions, size_t vertex_positions_stride, const unsigned int* clusters, size_t cluster_count)
13+
static void calculateSortData(float* sort_data, const unsigned int* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, const unsigned int* clusters, size_t cluster_count)
1414
{
1515
size_t vertex_stride_float = vertex_positions_stride / sizeof(float);
1616

1717
float mesh_centroid[3] = {};
1818

19-
for (size_t i = 0; i < index_count; ++i)
19+
for (size_t i = 0; i < vertex_count; ++i)
2020
{
21-
const float* p = vertex_positions + vertex_stride_float * indices[i];
21+
const float* p = vertex_positions + vertex_stride_float * i;
2222

2323
mesh_centroid[0] += p[0];
2424
mesh_centroid[1] += p[1];
2525
mesh_centroid[2] += p[2];
2626
}
2727

28-
mesh_centroid[0] /= index_count;
29-
mesh_centroid[1] /= index_count;
30-
mesh_centroid[2] /= index_count;
28+
mesh_centroid[0] /= float(vertex_count);
29+
mesh_centroid[1] /= float(vertex_count);
30+
mesh_centroid[2] /= float(vertex_count);
3131

3232
for (size_t cluster = 0; cluster < cluster_count; ++cluster)
3333
{
@@ -306,7 +306,7 @@ void meshopt_optimizeOverdraw(unsigned int* destination, const unsigned int* ind
306306

307307
// fill sort data
308308
float* sort_data = allocator.allocate<float>(cluster_count);
309-
calculateSortData(sort_data, indices, index_count, vertex_positions, vertex_positions_stride, clusters, cluster_count);
309+
calculateSortData(sort_data, indices, index_count, vertex_positions, vertex_count, vertex_positions_stride, clusters, cluster_count);
310310

311311
// sort clusters using sort data
312312
unsigned short* sort_keys = allocator.allocate<unsigned short>(cluster_count);

0 commit comments

Comments
 (0)