weldPrimitive

  • Index a Primitive and (optionally) weld similar vertices. When merged and indexed, data is shared more efficiently between vertices. File size can be reduced, and the GPU can sometimes use the vertex cache more efficiently.

    When welding, the 'tolerance' threshold determines which vertices qualify for welding based on distance between the vertices as a fraction of the primitive's bounding box (AABB). For example, tolerance=0.01 welds vertices within +/-1% of the AABB's longest dimension. Other vertex attributes are also compared during welding, with attribute-specific thresholds. For --tolerance=0, geometry is indexed in place, without merging.

    Example:

    import { weldPrimitive } from '@gltf-transform/functions';
    
    const mesh = document.getRoot().listMeshes()
        .find((mesh) => mesh.getName() === 'Gizmo');
    
    for (const prim of mesh.listPrimitives()) {
      weldPrimitive(document, prim, {tolerance: 0.0001});
    }
    
Function symbol, where the argument and output are a box labeled 'glTF'.

Made by Don McCurdy Documented with greendoc © 2023 MIT License