ws-3d3: codecs/model/Draco: Draco decoder (port of Google Draco 1.5.7, Apache-2.0)
Meshes (sequential; Edgebreaker standard / predictive / valence, topology splits, attribute seams) and sequential point clouds, bitstreams 1.0 - 2.2; generic / integer / quantization / octahedral normal attribute decoders; difference, parallelogram, multi and constrained multi-parallelogram, tex coords (deprecated and portable, exact int64 arithmetic) and geometric normal predictions; metadata. Byte-exact against libdraco on 196 files (Draco test data 0.9 - 2.2 and draco_encoder outputs at every level / quantization). kd-tree point clouds: UNSUPPORTED for now.
This commit is contained in:
1 parent
de4f14a343
commit
9a6ddd5c16
12 files changed
+4159
No files matched your search
@@ -0,0 +1,44 @@
|
||||
// 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 <cstdio>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
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<char> data((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||
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<draco::PointCloud> pc;
|
||||
std::unique_ptr<draco::Mesh> 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;
|
||||
}
|
||||
Reference in new issue
Block a user