void BakeNewLOD( IndexData indexData )
{
Debug.Assert( currNumIndexes > 0, "No triangles to bake!" );
// Zip through the tri list of any working data copy and bake
indexData.indexCount = (int)currNumIndexes;
indexData.indexStart = 0;
// Base size of indexes on original
bool use32bitindexes =
( this.indexData.indexBuffer.Type == IndexType.Size32 );
// Create index buffer, we don't need to read it back or modify it a lot
indexData.indexBuffer =
HardwareBufferManager.Instance.CreateIndexBuffer( this.indexData.indexBuffer.Type,
indexData.indexCount,
BufferUsage.StaticWriteOnly,
false );
IntPtr bufPtr = indexData.indexBuffer.Lock( BufferLocking.Discard );
unsafe
{
ushort* pShort = null;
uint* pInt = null;
if ( use32bitindexes )
pInt = (uint*)bufPtr.ToPointer();
else
pShort = (ushort*)bufPtr.ToPointer();
// Use the first working data buffer, they are all the same index-wise
PMWorkingData work = this.workingDataList[ 0 ];
foreach ( PMTriangle tri in work.triList )
{
if ( !tri.removed )
{
if ( use32bitindexes )
{
*pInt++ = tri.vertex[ 0 ].realIndex;
*pInt++ = tri.vertex[ 1 ].realIndex;
*pInt++ = tri.vertex[ 2 ].realIndex;
}
else
{
*pShort++ = (ushort)tri.vertex[ 0 ].realIndex;
*pShort++ = (ushort)tri.vertex[ 1 ].realIndex;
*pShort++ = (ushort)tri.vertex[ 2 ].realIndex;
}
}
}
}
indexData.indexBuffer.Unlock();
}