@gltf-transform/functions
Version:
Functions for common glTF modifications, written using the core API
50 lines (49 loc) • 1.8 kB
TypeScript
import { Primitive, type Transform } from '@gltf-transform/core';
/** Options for the {@link weld} function. */
export interface WeldOptions {
/** Whether to overwrite existing indices. */
overwrite?: boolean;
}
export declare const WELD_DEFAULTS: Required<WeldOptions>;
/**
* Welds {@link Primitive Primitives}, merging bitwise identical vertices. When
* merged and indexed, data is shared more efficiently between vertices. File size
* can be reduced, and the GPU uses the vertex cache more efficiently.
*
* Example:
*
* ```javascript
* import { weld, getSceneVertexCount, VertexCountMethod } from '@gltf-transform/functions';
*
* const scene = document.getDefaultScene();
* const srcVertexCount = getSceneVertexCount(scene, VertexCountMethod.UPLOAD);
* await document.transform(weld());
* const dstVertexCount = getSceneVertexCount(scene, VertexCountMethod.UPLOAD);
* ```
*
* @category Transforms
*/
export declare function weld(_options?: WeldOptions): Transform;
/**
* Welds a {@link Primitive}, merging bitwise identical vertices. When merged
* and indexed, data is shared more efficiently between vertices. File size can
* be reduced, and the GPU uses the vertex cache more efficiently.
*
* Example:
*
* ```javascript
* import { weldPrimitive, getMeshVertexCount, VertexCountMethod } from '@gltf-transform/functions';
*
* const mesh = document.getRoot().listMeshes()
* .find((mesh) => mesh.getName() === 'Gizmo');
*
* const srcVertexCount = getMeshVertexCount(mesh, VertexCountMethod.UPLOAD);
*
* for (const prim of mesh.listPrimitives()) {
* weldPrimitive(prim);
* }
*
* const dstVertexCount = getMeshVertexCount(mesh, VertexCountMethod.UPLOAD);
* ```
*/
export declare function weldPrimitive(prim: Primitive, _options?: WeldOptions): void;