my conversion is going horribly wrong, the whole pointer/value/size thing confuses daylights out of me, but here is first out of 4 steps, with sample Edges (original + compressed), if anyone more clued up on c++, would be greatful for some insight
Code: Select all
unsigned char original_EdgeIndex[315] =
{
0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00,
0x04, 0x00, 0x03, 0x00, 0x05, 0x00, 0x06, 0x00, 0x04, 0x00, 0x07, 0x00, 0x08, 0x00, 0x08, 0x00,
0x07, 0x00, 0x09, 0x00, 0x09, 0x00, 0x07, 0x00, 0x0A, 0x00, 0x09, 0x00, 0x0A, 0x00, 0x0B, 0x00,
0x09, 0x00, 0x0B, 0x00, 0x0C, 0x00, 0x09, 0x00, 0x0C, 0x00, 0x0D, 0x00, 0x08, 0x00, 0x0E, 0x00,
0x0F, 0x00, 0x0E, 0x00, 0x08, 0x00, 0x10, 0x00, 0x08, 0x00, 0x11, 0x00, 0x12, 0x00, 0x12, 0x00,
0x11, 0x00, 0x13, 0x00, 0x13, 0x00, 0x14, 0x00, 0x10, 0x00, 0x15, 0x00, 0x0E, 0x00, 0x16, 0x00,
0x15, 0x00, 0x17, 0x00, 0x18, 0x00, 0x18, 0x00, 0x17, 0x00, 0x19, 0x00, 0x19, 0x00, 0x1A, 0x00,
0x1B, 0x00, 0x1B, 0x00, 0x1A, 0x00, 0x1C, 0x00, 0x1B, 0x00, 0x1C, 0x00, 0x1D, 0x00, 0x1D, 0x00,
0x1C, 0x00, 0x1E, 0x00, 0x1D, 0x00, 0x1E, 0x00, 0x1F, 0x00, 0x1F, 0x00, 0x1E, 0x00, 0x20, 0x00,
0x1F, 0x00, 0x20, 0x00, 0x21, 0x00, 0x1F, 0x00, 0x21, 0x00, 0x22, 0x00, 0x22, 0x00, 0x21, 0x00,
0x23, 0x00, 0x22, 0x00, 0x23, 0x00, 0x24, 0x00, 0x24, 0x00, 0x23, 0x00, 0x25, 0x00, 0x25, 0x00,
0x23, 0x00, 0x26, 0x00, 0x25, 0x00, 0x26, 0x00, 0x27, 0x00, 0x27, 0x00, 0x26, 0x00, 0x28, 0x00,
0x27, 0x00, 0x28, 0x00, 0x29, 0x00, 0x29, 0x00, 0x28, 0x00, 0x2A, 0x00, 0x29, 0x00, 0x2A, 0x00,
0x2B, 0x00, 0x29, 0x00, 0x2B, 0x00, 0x2C, 0x00, 0x2A, 0x00, 0x2D, 0x00, 0x2B, 0x00, 0x2B, 0x00,
0x2D, 0x00, 0x2E, 0x00, 0x2B, 0x00, 0x2E, 0x00, 0x2F, 0x00, 0x2B, 0x00, 0x2F, 0x00, 0x30, 0x00,
0x2B, 0x00, 0x30, 0x00, 0x2C, 0x00, 0x2C, 0x00, 0x30, 0x00, 0x31, 0x00, 0x2C, 0x00, 0x31, 0x00,
0x32, 0x00, 0x32, 0x00, 0x31, 0x00, 0x33, 0x00, 0x32, 0x00, 0x33, 0x00, 0x34, 0x00, 0x34, 0x00,
0x33, 0x00, 0x35, 0x00, 0x36, 0x00, 0x2F, 0x00, 0x2E, 0x00, 0x2F, 0x00, 0x36, 0x00, 0x37, 0x00,
0x2F, 0x00, 0x37, 0x00, 0x38, 0x00, 0x2F, 0x00, 0x38, 0x00, 0x39, 0x00, 0x2F, 0x00, 0x39, 0x00,
0x3A, 0x00, 0x2F, 0x00, 0x3A, 0x00, 0x30, 0x00, 0x3B, 0x00, 0x3C,
} ;
//Vertex-Count = 118
//
unsigned char edgeCompressed[96] =
{
0x00, 0x27, 0x00, 0x00, 0x00, 0x14, 0x06, 0x00, 0x04, 0x80, 0x88, 0xAA, 0x20, 0x00, 0x02, 0x88,
0x18, 0x44, 0x88, 0x32, 0x0C, 0x09, 0x00, 0x00, 0x6D, 0xB7, 0x07, 0x00, 0xE7, 0xD4, 0x0E, 0xDF,
0xDD, 0x11, 0x04, 0x51, 0x10, 0xD0, 0x11, 0x1E, 0x00, 0xFD, 0xD1, 0xDD, 0x1D, 0x57, 0x78, 0x44,
0x44, 0x44, 0x3F, 0xDD, 0x55, 0xD1, 0x00, 0x0C, 0x42, 0x08, 0x4D, 0x03, 0x95, 0x5A, 0x68, 0xE4,
0x71, 0xE8, 0xA6, 0x89, 0x86, 0x97, 0x69, 0x13, 0x8C, 0x6E, 0x48, 0x24, 0x76, 0x7A, 0xA2, 0x40,
0x41, 0x04, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
} ;
[b] result = DecompressIndexes_C_Standalone(315,edgeCompressed);[/b]
int DecompressIndexes_NBitStream( uint8_t *pIn, uint16_t *pOut, uint32_t n, uint32_t numToExpand)
{
//32 indexes at a time
//runs in reverse
//writes out 4 quads
const uint32_t rounded = (numToExpand + 31) & -32;
pOut = pOut + (rounded - 1);
uint32_t offset = (rounded - 1) * n;
for (uint32_t i = rounded; i > 0; i--)
{
uint8_t *b = pIn + (offset >> 3);
uint32_t b0 = b[0];
uint32_t b1 = b[1];
uint32_t b2 = b[2];
uint32_t buf = (b0 << 24) | (b1 << 16) | (b2 << 8);
buf = buf << (offset & 0x7);
*pOut-- = buf >> (32 - n);
offset -= n;
}
}
int DecompressIndexes_C_Standalone(const unsigned int numIndexes, const void *indexes)
{
const uint32_t numTriangles = numIndexes / 3;
const uint32_t num1Bits = (uint32_t)(((uint16_t *)indexes)[2]) << 3;
const uint32_t bytesBefore2BitStream = 8 + ((num1Bits + 7) >> 3);
const uint32_t num2BitStreamBytes = (((numTriangles + numTriangles) + 7) >> 3);
const uint32_t bytesBeforeNBitStream = bytesBefore2BitStream + num2BitStreamBytes;
const uint32_t numIndexesInNBitStream = (uint32_t)(((uint16_t *)indexes)[0]);
uint16_t *decompressedNBitStream = (uint16_t *)((uint32_t)indexes + (bytesBeforeNBitStream + 0xf) & ~0xf);
const uint32_t n = ((uint8_t *)indexes)[6];
DecompressIndexes_NBitStream( (uint8_t *)((uint32_t)indexes + bytesBeforeNBitStream),
decompressedNBitStream,
n,
numIndexesInNBitStream);
}