// Dumps a decoded Draco file: points, faces and every attribute's per-point bytes (hex), for the fixture generator. #include "draco/compression/decode.h" #include #include #include #include static void hex(const uint8_t* p, size_t n) { for (size_t i = 0; i < n; ++i) printf("%02x", p[i]); } int main(int argc, char** argv) { std::ifstream f(argv[1], std::ios::binary); std::vector data((std::istreambuf_iterator(f)), std::istreambuf_iterator()); draco::DecoderBuffer buf; buf.Init(data.data(), data.size()); auto type = draco::Decoder::GetEncodedGeometryType(&buf); if (!type.ok()) { printf("ERROR %s\n", type.status().error_msg()); return 0; } draco::Decoder dec; std::unique_ptr pc; std::unique_ptr mesh; if (type.value() == draco::TRIANGULAR_MESH) { auto r = dec.DecodeMeshFromBuffer(&buf); if (!r.ok()) { printf("ERROR %s\n", r.status().error_msg()); return 0; } mesh = std::move(r).value(); } else { auto r = dec.DecodePointCloudFromBuffer(&buf); if (!r.ok()) { printf("ERROR %s\n", r.status().error_msg()); return 0; } pc = std::move(r).value(); } const draco::PointCloud* g = mesh ? mesh.get() : pc.get(); printf("POINTS %u\n", g->num_points()); if (mesh) { printf("FACES %u ", mesh->num_faces()); for (draco::FaceIndex fi(0); fi < mesh->num_faces(); ++fi) { const auto& face = mesh->face(fi); for (int c = 0; c < 3; ++c) { uint32_t v = face[c].value(); hex((const uint8_t*)&v, 4); } } printf("\n"); } for (int i = 0; i < g->num_attributes(); ++i) { const draco::PointAttribute* a = g->attribute(i); printf("ATTR %d %d %d %d %u ", (int)a->attribute_type(), (int)a->data_type(), (int)a->num_components(), a->normalized() ? 1 : 0, a->unique_id()); for (draco::PointIndex p(0); p < g->num_points(); ++p) hex(a->GetAddress(a->mapped_index(p)), a->byte_stride()); printf("\n"); } return 0; }