Updated meshoptimizer.

This commit is contained in:
Бранимир Караџић
2020-02-12 08:03:01 -08:00
parent bf7762dd10
commit 830aa1f2b3

View File

@@ -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);