From 830aa1f2b36c7cfef0205c55d955002d300c1743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Wed, 12 Feb 2020 08:03:01 -0800 Subject: [PATCH] Updated meshoptimizer. --- 3rdparty/meshoptimizer/src/indexcodec.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/3rdparty/meshoptimizer/src/indexcodec.cpp b/3rdparty/meshoptimizer/src/indexcodec.cpp index f30db42fd..409e5d43e 100644 --- a/3rdparty/meshoptimizer/src/indexcodec.cpp +++ b/3rdparty/meshoptimizer/src/indexcodec.cpp @@ -239,7 +239,7 @@ size_t meshopt_encodeIndexBuffer(unsigned char* buffer, size_t buffer_size, cons unsigned char* data = code + index_count / 3; unsigned char* data_safe_end = buffer + buffer_size - 16; - int fecmax = version >= 1 ? 14 : 15; + int fecmax = version >= 1 ? 13 : 15; // use static encoding table; it's possible to pack the result and then build an optimal table and repack // for now we keep it simple and use the table that has been generated based on symbol frequency on a training mesh set @@ -265,7 +265,16 @@ size_t meshopt_encodeIndexBuffer(unsigned char* buffer, size_t buffer_size, cons int fe = fer >> 2; int fc = getVertexFifo(vertexfifo, c, vertexfifooffset); - int fec = (fc >= 1 && fc < fecmax) ? fc : (c == next) ? (next++, 0) : (c + 1 == last && version >= 1) ? (--last, 14) : 15; + int fec = (fc >= 1 && fc < fecmax) ? fc : (c == next) ? (next++, 0) : 15; + + if (fec == 15 && version >= 1) + { + // encode last-1 and last+1 to optimize strip-like sequences + if (c + 1 == last) + fec = 13, last = c; + if (c == last + 1) + fec = 14, last = c; + } *code++ = (unsigned char)((fe << 4) | fec); @@ -278,7 +287,7 @@ size_t meshopt_encodeIndexBuffer(unsigned char* buffer, size_t buffer_size, cons encodeIndex(data, c, next, last), last = c; // we only need to push third vertex since first two are likely already in the vertex fifo - if (fec == 0 || fec == 15 || (fec == 14 && version >= 1)) + if (fec == 0 || fec >= fecmax) pushVertexFifo(vertexfifo, c, vertexfifooffset); // we only need to push two new edges to edge fifo since the third one is already there @@ -461,7 +470,7 @@ int meshopt_decodeIndexBuffer(void* destination, size_t index_count, size_t inde unsigned int next = 0; unsigned int last = 0; - int fecmax = version >= 1 ? 14 : 15; + int fecmax = version >= 1 ? 13 : 15; // since we store 16-byte codeaux table at the end, triangle data has to begin before data_safe_end const unsigned char* code = buffer + 1; @@ -514,8 +523,9 @@ int meshopt_decodeIndexBuffer(void* destination, size_t index_count, size_t inde { unsigned int c = 0; + // fec - (fec ^ 3) decodes 13, 14 into -1, 1 // note that we need to update the last index since free indices are delta-encoded - last = c = (fec == 14) ? last - 1 : decodeIndex(data, next, last); + last = c = (fec != 15) ? last + (fec - (fec ^ 3)) : decodeIndex(data, next, last); // output triangle writeTriangle(destination, i, index_size, a, b, c);