diff --git a/tools/codectest.cpp b/tools/codectest.cpp index 1f1116ba..cebc2b05 100644 --- a/tools/codectest.cpp +++ b/tools/codectest.cpp @@ -17,9 +17,9 @@ int main(int argc, char** argv) _setmode(_fileno(stdout), _O_BINARY); #endif - if (argc != 2 || atoi(argv[1]) <= 0) + if (argc < 2 || argc > 3 || atoi(argv[1]) <= 0) { - fprintf(stderr, "Usage: %s \n", argv[0]); + fprintf(stderr, "Usage: %s []\n", argv[0]); return 1; } @@ -32,10 +32,29 @@ int main(int argc, char** argv) while ((bytes_read = fread(buffer, 1, sizeof(buffer), stdin)) > 0) input.insert(input.end(), buffer, buffer + bytes_read); - size_t vertex_count = input.size() / stride; - std::vector output(meshopt_encodeVertexBufferBound(vertex_count, stride)); - size_t output_size = meshopt_encodeVertexBuffer(output.data(), output.size(), input.data(), vertex_count, stride); + if (argc == 3) + { + // if count is specified, we assume input is meshopt-encoded and decode it first + size_t count = atoi(argv[2]); - fwrite(output.data(), 1, output_size, stdout); - return 0; + std::vector decoded(count * stride); + int res = meshopt_decodeVertexBuffer(&decoded[0], count, stride, &input[0], input.size()); + if (res != 0) + { + fprintf(stderr, "Error decoding input: %d\n", res); + return 2; + } + + fwrite(decoded.data(), 1, decoded.size(), stdout); + return 0; + } + else + { + size_t vertex_count = input.size() / stride; + std::vector output(meshopt_encodeVertexBufferBound(vertex_count, stride)); + size_t output_size = meshopt_encodeVertexBuffer(output.data(), output.size(), input.data(), vertex_count, stride); + + fwrite(output.data(), 1, output_size, stdout); + return 0; + } }