• Rewrites a Primitive such that all unused vertices in its vertex attributes are removed. When multiple Primitives share vertex attributes, each indexing only a few, compaction can be used to produce Primitives each having smaller, independent vertex streams instead.

    Regardless of whether the Primitive is indexed or contains unused vertices, compaction will clone every Accessor. The resulting Primitive will share no Accessors with other Primitives, allowing later changes to the vertex stream to be applied in isolation.


    import { compactPrimitive, transformMesh } from '@gltf-transform/functions';
    import { fromTranslation } from 'gl-matrix/mat4';
    const mesh = document.getRoot().listMeshes().find((mesh) => mesh.getName() === 'MyMesh');
    const prim = mesh.listPrimitives().find((prim) => { ... });
    // Compact primitive, removing unused vertices and detaching shared vertex
    // attributes. Without compaction, `transformPrimitive` might affect other
    // primitives sharing the same vertex attributes.
    // Transform primitive vertices, y += 10.
    transformPrimitive(prim, fromTranslation([], [0, 10, 0]));

    Parameters 'remap' and 'dstVertexCount' are optional. When either is provided, the other must be provided as well. If one or both are missing, both will be computed from the mesh indices.

Function symbol, where the argument and output are a box labeled 'glTF'.

Made by Don McCurdy. Documentation built with greendoc and published under Creative Commons Attribution 3.0.