7 CompactVB
Chuck Walbourn редактировал(а) эту страницу 2022-01-20 17:34:24 -08:00
DirectXMesh

Finishes mesh optimization by reordering vertices and trimming any trailing unused vertices.

HRESULT CompactVB(
   const void* vbin, size_t stride, size_t nVerts,
   size_t trailingUnused,
   const uint32_t* vertexRemap, void* vbout );

Parameters

The vbin buffer must be nVerts*stride bytes.

The vbout buffer must be (nVerts-trailingUnused)*stride bytes.

A vertexRemap is an array with nVerts elements that describes how to reorder the vertices of the original mesh: oldLoc = vertexRemap[newLoc]. See OptimizeVertices.

trailingUnused is the number of "unused" vertex positions at the end of the remap array. This is typically computed by OptimizeVertices.

Remarks

This function is typically used in conjunction with WeldVertices.

This is the pseudo-code for applying a vertex remap to a vertex buffer:

for each j in nVerts
    srcIndex = vertexRemap[ j ]
    if ( srcIndex != -1 )
       memcpy( newVB + j * stride,
               oldVB + srcIndex * stride,
               stride )

After applying the vertex remap, any point reps are invalid as the vertices have been moved.

Example

// newIndices is created by some operation that leaves vertices unused.

auto vertRemap = std::make_unique<uint32_t[]>(nVerts);
size_t trailingUnused = 0;
if ( FAILED( OptimizeVertices( newIndices, nFaces, nVerts,
    vertRemap.get(), &trailingUnused ) ) )
   // Error

auto vb = std::make_unique<WaveFrontReader<uint16_t>::Vertex>(nVerts - trailingUnused);
if ( FAILED( CompactVB( mesh->vertices.data(),
   sizeof(WaveFrontReader<uint16_t>::Vertex),
   nVerts, trailingUnused, vertRemap.get(), vb.get() ) ) )
   // Error