mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-21 06:13:07 +01:00
Updated meshoptimizer.
This commit is contained in:
2
3rdparty/meshoptimizer/Makefile
vendored
2
3rdparty/meshoptimizer/Makefile
vendored
@@ -72,7 +72,7 @@ gltfpack: $(GLTFPACK_OBJECTS) $(LIBRARY)
|
||||
|
||||
js/meshopt_decoder.js: src/vertexcodec.cpp src/indexcodec.cpp
|
||||
@mkdir -p build
|
||||
emcc $(filter %.cpp,$^) -O3 -DNDEBUG -s EXPORTED_FUNCTIONS='["_meshopt_decodeVertexBuffer", "_meshopt_decodeIndexBuffer"]' -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_STACK=32768 -s TOTAL_MEMORY=65536 -o build/meshopt_decoder.wasm
|
||||
emcc $(filter %.cpp,$^) -O3 -DNDEBUG -s EXPORTED_FUNCTIONS='["_meshopt_decodeVertexBuffer", "_meshopt_decodeIndexBuffer"]' -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_STACK=24576 -s TOTAL_MEMORY=65536 -o build/meshopt_decoder.wasm
|
||||
sed -i "s#\(var wasm = \)\".*\";#\\1\"$$(cat build/meshopt_decoder.wasm | base64 -w 0)\";#" $@
|
||||
|
||||
$(EXECUTABLE): $(DEMO_OBJECTS) $(LIBRARY)
|
||||
|
||||
10
3rdparty/meshoptimizer/js/meshopt_decoder.js
vendored
10
3rdparty/meshoptimizer/js/meshopt_decoder.js
vendored
File diff suppressed because one or more lines are too long
10
3rdparty/meshoptimizer/src/clusterizer.cpp
vendored
10
3rdparty/meshoptimizer/src/clusterizer.cpp
vendored
@@ -190,9 +190,9 @@ meshopt_Bounds meshopt_computeClusterBounds(const unsigned int* indices, size_t
|
||||
// compute triangle normals and gather triangle corners
|
||||
float normals[256][3];
|
||||
float corners[256][3][3];
|
||||
unsigned int triangles = 0;
|
||||
size_t triangles = 0;
|
||||
|
||||
for (unsigned int i = 0; i < index_count; i += 3)
|
||||
for (size_t i = 0; i < index_count; i += 3)
|
||||
{
|
||||
unsigned int a = indices[i + 0], b = indices[i + 1], c = indices[i + 2];
|
||||
assert(a < vertex_count && b < vertex_count && c < vertex_count);
|
||||
@@ -251,7 +251,7 @@ meshopt_Bounds meshopt_computeClusterBounds(const unsigned int* indices, size_t
|
||||
// compute a tight cone around all normals, mindp = cos(angle/2)
|
||||
float mindp = 1.f;
|
||||
|
||||
for (unsigned int i = 0; i < triangles; ++i)
|
||||
for (size_t i = 0; i < triangles; ++i)
|
||||
{
|
||||
float dp = normals[i][0] * axis[0] + normals[i][1] * axis[1] + normals[i][2] * axis[2];
|
||||
|
||||
@@ -277,7 +277,7 @@ meshopt_Bounds meshopt_computeClusterBounds(const unsigned int* indices, size_t
|
||||
float maxt = 0;
|
||||
|
||||
// we need to find the point on center-t*axis ray that lies in negative half-space of all triangles
|
||||
for (unsigned int i = 0; i < triangles; ++i)
|
||||
for (size_t i = 0; i < triangles; ++i)
|
||||
{
|
||||
// dot(center-t*axis-corner, trinormal) = 0
|
||||
// dot(center-corner, trinormal) - t * dot(axis, trinormal) = 0
|
||||
@@ -334,7 +334,7 @@ meshopt_Bounds meshopt_computeMeshletBounds(const meshopt_Meshlet* meshlet, cons
|
||||
|
||||
unsigned int indices[sizeof(meshlet->indices) / sizeof(meshlet->indices[0][0])];
|
||||
|
||||
for (unsigned int i = 0; i < meshlet->triangle_count; ++i)
|
||||
for (size_t i = 0; i < meshlet->triangle_count; ++i)
|
||||
{
|
||||
unsigned int a = meshlet->vertices[meshlet->indices[i][0]];
|
||||
unsigned int b = meshlet->vertices[meshlet->indices[i][1]];
|
||||
|
||||
6
3rdparty/meshoptimizer/tools/cgltf.h
vendored
6
3rdparty/meshoptimizer/tools/cgltf.h
vendored
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* cgltf - a single-file glTF 2.0 parser written in C99.
|
||||
*
|
||||
* Version: 1.2
|
||||
* Version: 1.3
|
||||
*
|
||||
* Website: https://github.com/jkuhlmann/cgltf
|
||||
*
|
||||
@@ -423,7 +423,7 @@ typedef struct cgltf_light {
|
||||
cgltf_float spot_outer_cone_angle;
|
||||
} cgltf_light;
|
||||
|
||||
typedef struct cgltf_node {
|
||||
struct cgltf_node {
|
||||
char* name;
|
||||
cgltf_node* parent;
|
||||
cgltf_node** children;
|
||||
@@ -443,7 +443,7 @@ typedef struct cgltf_node {
|
||||
cgltf_float scale[3];
|
||||
cgltf_float matrix[16];
|
||||
cgltf_extras extras;
|
||||
} cgltf_node;
|
||||
};
|
||||
|
||||
typedef struct cgltf_scene {
|
||||
char* name;
|
||||
|
||||
35
3rdparty/meshoptimizer/tools/gltfpack.cpp
vendored
35
3rdparty/meshoptimizer/tools/gltfpack.cpp
vendored
@@ -801,6 +801,15 @@ void reindexMesh(Mesh& mesh)
|
||||
}
|
||||
}
|
||||
|
||||
const Stream* getPositionStream(const Mesh& mesh)
|
||||
{
|
||||
for (size_t i = 0; i < mesh.streams.size(); ++i)
|
||||
if (mesh.streams[i].type == cgltf_attribute_type_position)
|
||||
return &mesh.streams[i];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void optimizeMesh(Mesh& mesh)
|
||||
{
|
||||
size_t vertex_count = mesh.streams[0].data.size();
|
||||
@@ -816,33 +825,31 @@ void optimizeMesh(Mesh& mesh)
|
||||
meshopt_remapIndexBuffer(&mesh.indices[0], &mesh.indices[0], mesh.indices.size(), &remap[0]);
|
||||
|
||||
for (size_t i = 0; i < mesh.streams.size(); ++i)
|
||||
{
|
||||
assert(mesh.streams[i].data.size() == vertex_count);
|
||||
|
||||
meshopt_remapVertexBuffer(&mesh.streams[i].data[0], &mesh.streams[i].data[0], vertex_count, sizeof(Attr), &remap[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void sortPointMesh(Mesh& mesh)
|
||||
{
|
||||
size_t positions = 0;
|
||||
const Stream* positions = getPositionStream(mesh);
|
||||
if (!positions)
|
||||
return;
|
||||
|
||||
for (size_t i = 0; i < mesh.streams.size(); ++i)
|
||||
if (mesh.streams[i].type == cgltf_attribute_type_position)
|
||||
{
|
||||
positions = i;
|
||||
break;
|
||||
}
|
||||
|
||||
assert(mesh.streams[positions].type == cgltf_attribute_type_position);
|
||||
assert(mesh.indices.empty());
|
||||
|
||||
size_t total_vertices = mesh.streams[positions].data.size();
|
||||
size_t vertex_count = mesh.streams[0].data.size();
|
||||
|
||||
std::vector<unsigned int> remap(total_vertices);
|
||||
meshopt_spatialSortRemap(&remap[0], mesh.streams[positions].data[0].f, total_vertices, sizeof(Attr));
|
||||
std::vector<unsigned int> remap(vertex_count);
|
||||
meshopt_spatialSortRemap(&remap[0], positions->data[0].f, vertex_count, sizeof(Attr));
|
||||
|
||||
for (size_t i = 0; i < mesh.streams.size(); ++i)
|
||||
{
|
||||
assert(mesh.streams[i].data.size() == total_vertices);
|
||||
assert(mesh.streams[i].data.size() == vertex_count);
|
||||
|
||||
meshopt_remapVertexBuffer(&mesh.streams[i].data[0], &mesh.streams[i].data[0], total_vertices, sizeof(Attr), &remap[0]);
|
||||
meshopt_remapVertexBuffer(&mesh.streams[i].data[0], &mesh.streams[i].data[0], vertex_count, sizeof(Attr), &remap[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user