Skip to content

Commit

Permalink
simplify mesh indices retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Mar 1, 2021
1 parent 733926d commit d9e48ec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 30 deletions.
14 changes: 3 additions & 11 deletions include/c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,13 @@ EXPORT_API void dracoMeshRelease(draco_mesh *mesh);

EXPORT_API uint32_t dracoMeshNumFaces(const draco_mesh *mesh);

// Queries an array of 3*face_count elements containing the triangle indices.
// out_values must be allocated to contain at least 3*face_count uint16_t elements.
// out_size must be exactly 3*face_count*sizeof(uint16_t), else out_values
// won't be filled and returns false.
EXPORT_API bool dracoMeshGetTrianglesUint16(const draco_mesh *mesh,
const size_t out_size,
uint16_t *out_values);

// Queries an array of 3*face_count elements containing the triangle indices.
// out_values must be allocated to contain at least 3*face_count uint32_t elements.
// out_size must be exactly 3*face_count*sizeof(uint32_t), else out_values
// won't be filled and returns false.
EXPORT_API bool dracoMeshGetTrianglesUint32(const draco_mesh *mesh,
const size_t out_size,
uint32_t *out_values);
EXPORT_API bool dracoMeshGetIndices(const draco_mesh *mesh,
const size_t out_size,
uint32_t *out_values);

// draco::Decoder

Expand Down
2 changes: 1 addition & 1 deletion src/c_api_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ TEST(DracoCAPITest, TestDecode) {

auto indices_size = 3 * num_faces * sizeof(uint32_t);
uint32_t *indices = (uint32_t *)malloc(indices_size);
ASSERT_TRUE(dracoMeshGetTrianglesUint32(mesh, indices_size, indices));
ASSERT_TRUE(dracoMeshGetIndices(mesh, indices_size, indices));
free(indices);

auto pa1 = dracoPointCloudGetAttribute(mesh, 0);
Expand Down
25 changes: 7 additions & 18 deletions src/mesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,24 @@ uint32_t dracoMeshNumFaces(const draco_mesh *mesh) {
return reinterpret_cast<const draco::Mesh*>(mesh)->num_faces();
}

template <typename T>
bool GetTrianglesArray(const draco::Mesh *m, const size_t out_size,
T *out_values) {
uint32_t *out_values) {
const uint32_t num_faces = m->num_faces();
if (num_faces * 3 * sizeof(T) != out_size) {
if (num_faces * 3 * sizeof(uint32_t) != out_size) {
return false;
}

for (uint32_t face_id = 0; face_id < num_faces; ++face_id) {
const draco::Mesh::Face &face = m->face(draco::FaceIndex(face_id));
out_values[face_id * 3 + 0] = static_cast<T>(face[0].value());
out_values[face_id * 3 + 1] = static_cast<T>(face[1].value());
out_values[face_id * 3 + 2] = static_cast<T>(face[2].value());
out_values[face_id * 3 + 0] = face[0].value();
out_values[face_id * 3 + 1] = face[1].value();
out_values[face_id * 3 + 2] = face[2].value();
}
return true;
}

bool dracoMeshGetTrianglesUint16(const draco_mesh *mesh, const size_t out_size,
uint16_t *out_values) {
auto m = reinterpret_cast<const draco::Mesh*>(mesh);
if (m->num_points() > std::numeric_limits<uint16_t>::max()) {
return false;
}

return GetTrianglesArray(m, out_size, out_values);
}

bool dracoMeshGetTrianglesUint32(const draco_mesh *mesh, const size_t out_size,
uint32_t *out_values) {
bool dracoMeshGetIndices(const draco_mesh *mesh, const size_t out_size,
uint32_t *out_values) {
auto m = reinterpret_cast<const draco::Mesh*>(mesh);
if (m->num_points() > std::numeric_limits<uint32_t>::max()) {
return false;
Expand Down

0 comments on commit d9e48ec

Please sign in to comment.