Skip to content

Commit

Permalink
simplify: Fix C++ interface wrapper
Browse files Browse the repository at this point in the history
Destination buffer should have target_index_count elements (unlike the
baseline simplifier which needs index_count elements in the worst case).
  • Loading branch information
zeux committed Feb 10, 2019
1 parent 54e352a commit 70a80d0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions demo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void simplify(const Mesh& mesh, float threshold = 0.2f)
size_t target_index_count = size_t(mesh.indices.size() * threshold);
float target_error = 1e-3f;

lod.indices.resize(mesh.indices.size());
lod.indices.resize(mesh.indices.size()); // note: simplify needs space for index_count elements in the destination array, not target_index_count
lod.indices.resize(meshopt_simplify(&lod.indices[0], &mesh.indices[0], mesh.indices.size(), &mesh.vertices[0].px, mesh.vertices.size(), sizeof(Vertex), target_index_count, target_error));

lod.vertices.resize(mesh.vertices.size());
Expand All @@ -387,7 +387,7 @@ void simplifySloppy(const Mesh& mesh, float threshold = 0.2f)

size_t target_index_count = size_t(mesh.indices.size() * threshold);

lod.indices.resize(mesh.indices.size());
lod.indices.resize(target_index_count);
lod.indices.resize(meshopt_simplifySloppy(&lod.indices[0], &mesh.indices[0], mesh.indices.size(), &mesh.vertices[0].px, mesh.vertices.size(), sizeof(Vertex), target_index_count));

lod.vertices.resize(mesh.vertices.size());
Expand Down
2 changes: 1 addition & 1 deletion src/meshoptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ template <typename T>
inline size_t meshopt_simplifySloppy(T* destination, const T* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t target_index_count)
{
meshopt_IndexAdapter<T> in(0, indices, index_count);
meshopt_IndexAdapter<T> out(destination, 0, index_count);
meshopt_IndexAdapter<T> out(destination, 0, target_index_count);

return meshopt_simplifySloppy(out.data, in.data, index_count, vertex_positions, vertex_count, vertex_positions_stride, target_index_count);
}
Expand Down
4 changes: 3 additions & 1 deletion src/simplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,9 @@ struct CellHasher

size_t hash(unsigned int i) const
{
// MurmurHash2 finalizer
unsigned int h = vertex_ids[i];

// MurmurHash2 finalizer
h ^= h >> 13;
h *= 0x5bd1e995;
h ^= h >> 15;
Expand All @@ -881,6 +882,7 @@ struct TriangleHasher
{
const unsigned int* tri = indices + i * 3;

// Optimized Spatial Hashing for Collision Detection of Deformable Objects
return (tri[0] * 73856093) ^ (tri[1] * 19349663) ^ (tri[2] * 83492791);
}

Expand Down

0 comments on commit 70a80d0

Please sign in to comment.