xatlas-wasi
Version: 
xatlas build with wasi-sdk
702 lines (701 loc) • 20.4 kB
TypeScript
export type ptr<T> = number;
export type bool = boolean;
/**
 * Enum for chart types.
 *
 * @enum {number}
 */
export declare const enum xatlasChartType {
    /**
     * Planar chart type.
     */
    XATLAS_CHART_TYPE_PLANAR = 0,
    /**
     * Orthogonal chart type.
     */
    XATLAS_CHART_TYPE_ORTHO = 1,
    /**
     * Least squares conformal map chart type.
     */
    XATLAS_CHART_TYPE_LSCM = 2,
    /**
     * Piecewise chart type.
     */
    XATLAS_CHART_TYPE_PIECEWISE = 3,
    /**
     * Invalid chart type.
     */
    XATLAS_CHART_TYPE_INVALID = 4
}
/**
 * Enum for index formats.
 *
 * @enum {number}
 */
export declare const enum xatlasIndexFormat {
    /**
     * 16-bit unsigned integer format.
     */
    XATLAS_INDEX_FORMAT_UINT16 = 0,
    /**
     * 32-bit unsigned integer format.
     */
    XATLAS_INDEX_FORMAT_UINT32 = 1
}
/**
 * Enum for add mesh errors.
 *
 * @enum {number}
 */
export declare const enum xatlasAddMeshError {
    /**
     * No error, operation successful.
     */
    XATLAS_ADD_MESH_ERROR_SUCCESS = 0,
    /**
     * Generic error.
     */
    XATLAS_ADD_MESH_ERROR_ERROR = 1,
    /**
     * Index out of range error.
     */
    XATLAS_ADD_MESH_ERROR_INDEXOUTOFRANGE = 2,
    /**
     * Invalid face vertex count error.
     */
    XATLAS_ADD_MESH_ERROR_INVALIDFACEVERTEXCOUNT = 3,
    /**
     * Invalid index count error.
     */
    XATLAS_ADD_MESH_ERROR_INVALIDINDEXCOUNT = 4
}
/**
 * Enum for progress categories.
 *
 * @enum {number}
 */
export declare const enum xatlasProgressCategory {
    /**
     * Adding mesh progress.
     */
    XATLAS_PROGRESS_CATEGORY_ADDMESH = 0,
    /**
     * Computing charts progress.
     */
    XATLAS_PROGRESS_CATEGORY_COMPUTECHARTS = 1,
    /**
     * Packing charts progress.
     */
    XATLAS_PROGRESS_CATEGORY_PACKCHARTS = 2,
    /**
     * Building output meshes progress.
     */
    XATLAS_PROGRESS_CATEGORY_BUILDOUTPUTMESHES = 3
}
/**
 * Interface for WebAssembly exports of xatlas.
 */
export interface WasmExports {
    memory: WebAssembly.Memory;
    /**
     * Creates an atlas.
     * @returns Pointer to the created xatlasAtlas.
     */
    xatlasCreate(): ptr<xatlasAtlas>;
    /**
     * Destroys the given atlas.
     * @param atlas - Pointer to the xatlasAtlas to destroy.
     */
    xatlasDestroy(atlas: ptr<xatlasAtlas>): void;
    /**
     * Adds a mesh to the atlas.
     * @param atlas - Pointer to the xatlasAtlas.
     * @param meshDecl - Pointer to the xatlasMeshDecl.
     * @param meshCountHint - Hint for the number of meshes.
     * @returns Error code of type xatlasAddMeshError.
     */
    xatlasAddMesh(atlas: ptr<xatlasAtlas>, meshDecl: ptr<xatlasMeshDecl>, meshCountHint: number): xatlasAddMeshError;
    xatlasAddMeshJoin?(atlas: ptr<xatlasAtlas>): void;
    /**
     * Adds a UV mesh to the atlas.
     * @param atlas - Pointer to the xatlasAtlas.
     * @param decl - Pointer to the xatlasUvMeshDecl.
     * @returns Error code of type xatlasAddMeshError.
     */
    xatlasAddUvMesh(atlas: ptr<xatlasAtlas>, decl: ptr<xatlasUvMeshDecl>): xatlasAddMeshError;
    /**
     * Computes the charts for the given atlas.
     * @param atlas - Pointer to the xatlasAtlas.
     * @param chartOptions - Pointer to the xatlasChartOptions.
     */
    xatlasComputeCharts(atlas: ptr<xatlasAtlas>, chartOptions: ptr<xatlasChartOptions>): void;
    /**
     * Packs the charts in the given atlas.
     * @param atlas - Pointer to the xatlasAtlas.
     * @param packOptions - Pointer to the xatlasPackOptions.
     */
    xatlasPackCharts(atlas: ptr<xatlasAtlas>, packOptions: ptr<xatlasPackOptions>): void;
    /**
     * Generates the atlas.
     * @param atlas - Pointer to the xatlasAtlas.
     * @param chartOptions - Pointer to the xatlasChartOptions.
     * @param packOptions - Pointer to the xatlasPackOptions.
     */
    xatlasGenerate(atlas: ptr<xatlasAtlas>, chartOptions: ptr<xatlasChartOptions>, packOptions: ptr<xatlasPackOptions>): void;
    xatlasAddMeshErrorString?(error: xatlasAddMeshError): ptr<string>;
    xatlasProgressCategoryString?(category: xatlasProgressCategory): ptr<string>;
    /**
     * Initializes the mesh declaration.
     * @param meshDecl - Pointer to the xatlasMeshDecl to initialize.
     */
    xatlasMeshDeclInit(meshDecl: ptr<xatlasMeshDecl>): void;
    /**
     * Initializes the UV mesh declaration.
     * @param uvMeshDecl - Pointer to the xatlasUvMeshDecl to initialize.
     */
    xatlasUvMeshDeclInit(uvMeshDecl: ptr<xatlasUvMeshDecl>): void;
    /**
     * Initializes the chart options.
     * @param chartOptions - Pointer to the xatlasChartOptions to initialize.
     */
    xatlasChartOptionsInit(chartOptions: ptr<xatlasChartOptions>): void;
    /**
     * Initializes the pack options.
     * @param packOptions - Pointer to the xatlasPackOptions to initialize.
     */
    xatlasPackOptionsInit(packOptions: ptr<xatlasPackOptions>): void;
    /**
     * Allocates memory of the given size.
     * @param size - Size of memory to allocate.
     * @returns Pointer to the allocated memory.
     */
    malloc(size: number): ptr<void>;
    /**
     * Reallocates memory at the given pointer to the new size.
     * @param ptr - Pointer to the existing memory.
     * @param size - New size of memory.
     * @returns Pointer to the reallocated memory.
     */
    realloc(ptr: ptr<void>, size: number): ptr<void>;
    /**
     * Frees the memory at the given pointer.
     * @param ptr - Pointer to the memory to free.
     */
    free(ptr: ptr<void>): void;
    /**
     * Copies original indices and normalizes UV.
     * @param atlas - Pointer to the xatlasAtlas.
     * @param mesh - Pointer to the xatlasMesh.
     * @param output - Pointer to the output buffer.
     */
    copy_uv(atlas: ptr<xatlasAtlas>, mesh: ptr<xatlasMesh>, output: ptr<void>): void;
}
/**
 * Class for managing WebAssembly context and memory operations.
 */
export declare class WasmContext {
    exports: WasmExports;
    /**
     * Uint8Array view of the WebAssembly memory.
     */
    memU8: Uint8Array;
    /**
     * Uint16Array view of the WebAssembly memory.
     */
    memU16: Uint16Array;
    /**
     * Uint32Array view of the WebAssembly memory.
     */
    memU32: Uint32Array;
    /**
     * Float32Array view of the WebAssembly memory.
     */
    memF32: Float32Array;
    /**
     * Creates an instance of WasmContext.
     * @param exports - The WebAssembly exports object.
     */
    constructor(exports: WasmExports);
    /**
     * Reloads the memory views.
     * Call this method manually in case of memory growth.
     */
    reload(): void;
    /**
     * Reads a portion of the WebAssembly memory as a Uint8Array.
     * @param ptr - Pointer to the start of the memory.
     * @param size - Number of bytes to read.
     * @returns The portion of memory as a Uint8Array.
     */
    readU8(ptr: ptr<any>, size: number): Uint8Array;
    /**
     * Writes an array of Uint8 values to the WebAssembly memory.
     * @param ptr - Pointer to the start of the memory.
     * @param arr - Array of Uint8 values to write.
     */
    writeU8(ptr: ptr<any>, arr: ArrayLike<number>): void;
    /**
     * Reads a portion of the WebAssembly memory as a Uint16Array.
     * @param ptr - Pointer to the start of the memory.
     * @param size - Number of elements to read.
     * @returns The portion of memory as a Uint16Array.
     */
    readU16(ptr: ptr<any>, size: number): Uint16Array;
    /**
     * Writes an array of Uint16 values to the WebAssembly memory.
     * @param ptr - Pointer to the start of the memory.
     * @param arr - Array of Uint16 values to write.
     */
    writeU16(ptr: ptr<any>, arr: ArrayLike<number>): void;
    /**
     * Reads a portion of the WebAssembly memory as a Uint32Array.
     * @param ptr - Pointer to the start of the memory.
     * @param size - Number of elements to read.
     * @returns The portion of memory as a Uint32Array.
     */
    readU32(ptr: ptr<any>, size: number): Uint32Array;
    /**
     * Writes an array of Uint32 values to the WebAssembly memory.
     * @param ptr - Pointer to the start of the memory.
     * @param arr - Array of Uint32 values to write.
     */
    writeU32(ptr: ptr<any>, arr: ArrayLike<number>): void;
    /**
     * Reads a portion of the WebAssembly memory as a Float32Array.
     * @param ptr - Pointer to the start of the memory.
     * @param size - Number of elements to read.
     * @returns The portion of memory as a Float32Array.
     */
    readF32(ptr: ptr<any>, size: number): Float32Array;
    /**
     * Writes an array of Float32 values to the WebAssembly memory.
     * @param ptr - Pointer to the start of the memory.
     * @param arr - Array of Float32 values to write.
     */
    writeF32(ptr: ptr<any>, arr: ArrayLike<number>): void;
}
export declare class xatlasChart {
    /**
     * Size of the `xatlasChart` structure in bytes.
     */
    static readonly SIZE = 20;
    /**
     * Pointer to an array of face indices.
     */
    faceArray: ptr<number>;
    /**
     * Index of the atlas this chart belongs to.
     */
    atlasIndex: number;
    /**
     * Number of faces in this chart.
     */
    faceCount: number;
    /**
     * Type of chart.
     */
    type: xatlasChartType;
    /**
     * Material index for the faces in this chart.
     */
    material: number;
    /**
     * Reads the `xatlasChart` data from the WebAssembly memory.
     * @param ptr - Pointer to the `xatlasChart` structure in the WebAssembly memory.
     * @param ctx - The `WasmContext` instance providing access to the WebAssembly memory.
     */
    read(ptr: ptr<any>, ctx: WasmContext): void;
    /**
     * Writes the `xatlasChart` data to the WebAssembly memory.
     * @param ptr - Pointer to the `xatlasChart` structure in the WebAssembly memory.
     * @param ctx - The `WasmContext` instance providing access to the WebAssembly memory.
     */
    write(ptr: ptr<any>, ctx: WasmContext): void;
}
export declare class xatlasVertex {
    /**
     * Size of the `xatlasVertex` structure in bytes.
     */
    static readonly SIZE = 20;
    /**
     * Index of the atlas this vertex belongs to.
     */
    atlasIndex: number;
    /**
     * Index of the chart this vertex belongs to.
     */
    chartIndex: number;
    /**
     * UV coordinates of the vertex.
     */
    uv: [number, number];
    /**
     * Cross-reference index for the vertex.
     */
    xref: number;
    /**
     * Reads the `xatlasVertex` data from the WebAssembly memory.
     * @param ptr - Pointer to the `xatlasVertex` structure in the WebAssembly memory.
     * @param ctx - The `WasmContext` instance providing access to the WebAssembly memory.
     */
    read(ptr: ptr<any>, ctx: WasmContext): void;
    /**
     * Writes the `xatlasVertex` data to the WebAssembly memory.
     * @param ptr - Pointer to the `xatlasVertex` structure in the WebAssembly memory.
     * @param ctx - The `WasmContext` instance providing access to the WebAssembly memory.
     */
    write(ptr: ptr<any>, ctx: WasmContext): void;
}
export declare class xatlasMesh {
    /**
     * Size of the `xatlasMesh` structure in bytes.
     */
    static readonly SIZE = 24;
    /**
     * Pointer to an array of `xatlasChart` structures.
     */
    chartArray: ptr<xatlasChart>;
    /**
     * Pointer to an array of indices.
     */
    indexArray: ptr<number>;
    /**
     * Pointer to an array of `xatlasVertex` structures.
     */
    vertexArray: ptr<xatlasVertex>;
    /**
     * Number of charts in this mesh.
     */
    chartCount: number;
    /**
     * Number of indices in this mesh.
     */
    indexCount: number;
    /**
     * Number of vertices in this mesh.
     */
    vertexCount: number;
    /**
     * Reads the `xatlasMesh` data from the WebAssembly memory.
     * @param ptr - Pointer to the `xatlasMesh` structure in the WebAssembly memory.
     * @param ctx - The `WasmContext` instance providing access to the WebAssembly memory.
     */
    read(ptr: ptr<any>, ctx: WasmContext): void;
    /**
     * Writes the `xatlasMesh` data to the WebAssembly memory.
     * @param ptr - Pointer to the `xatlasMesh` structure in the WebAssembly memory.
     * @param ctx - The `WasmContext` instance providing access to the WebAssembly memory.
     */
    write(ptr: ptr<any>, ctx: WasmContext): void;
}
export declare class xatlasAtlas {
    /**
     * Warning: do not allocate this directly, real size larger than this.
     */
    static readonly SIZE = 36;
    /**
     * Pointer to an array representing the image.
     */
    image: ptr<number>;
    /**
     * Pointer to an array of `xatlasMesh` structures.
     */
    meshes: ptr<xatlasMesh>;
    /**
     * Pointer to an array representing the utilization.
     */
    utilization: ptr<number>;
    /**
     * Width of the atlas.
     */
    width: number;
    /**
     * Height of the atlas.
     */
    height: number;
    /**
     * Number of atlases.
     */
    atlasCount: number;
    /**
     * Number of charts.
     */
    chartCount: number;
    /**
     * Number of meshes.
     */
    meshCount: number;
    /**
     * Texels per unit.
     */
    texelsPerUnit: number;
    /**
     * Reads the `xatlasAtlas` data from the WebAssembly memory.
     * @param ptr - Pointer to the `xatlasAtlas` structure in the WebAssembly memory.
     * @param ctx - The `WasmContext` instance providing access to the WebAssembly memory.
     */
    read(ptr: ptr<any>, ctx: WasmContext): void;
    /**
     * Writes the `xatlasAtlas` data to the WebAssembly memory.
     * @param ptr - Pointer to the `xatlasAtlas` structure in the WebAssembly memory.
     * @param ctx - The `WasmContext` instance providing access to the WebAssembly memory.
     */
    write(ptr: ptr<any>, ctx: WasmContext): void;
}
export declare class xatlasMeshDecl {
    /**
     * Size of the `xatlasMeshDecl` structure in bytes.
     */
    static readonly SIZE = 64;
    /**
     * Pointer to vertex position data.
     */
    vertexPositionData: ptr<any>;
    /**
     * Pointer to vertex normal data.
     */
    vertexNormalData: ptr<any>;
    /**
     * Pointer to vertex UV data.
     */
    vertexUvData: ptr<any>;
    /**
     * Pointer to index data.
     */
    indexData: ptr<any>;
    /**
     * Pointer to face ignore data.
     */
    faceIgnoreData: ptr<bool>;
    /**
     * Pointer to face material data.
     */
    faceMaterialData: ptr<number>;
    /**
     * Pointer to face vertex count data.
     */
    faceVertexCount: ptr<number>;
    /**
     * Number of vertices.
     */
    vertexCount: number;
    /**
     * Stride of vertex position data.
     */
    vertexPositionStride: number;
    /**
     * Stride of vertex normal data.
     */
    vertexNormalStride: number;
    /**
     * Stride of vertex UV data.
     */
    vertexUvStride: number;
    /**
     * Number of indices.
     */
    indexCount: number;
    /**
     * Offset of indices.
     */
    indexOffset: number;
    /**
     * Number of faces.
     */
    faceCount: number;
    /**
     * Format of the indices.
     */
    indexFormat: xatlasIndexFormat;
    /**
     * Epsilon value for calculations.
     */
    epsilon: number;
    /**
     * Reads the `xatlasMeshDecl` data from the WebAssembly memory.
     * @param ptr - Pointer to the `xatlasMeshDecl` structure in the WebAssembly memory.
     * @param ctx - The `WasmContext` instance providing access to the WebAssembly memory.
     */
    read(ptr: ptr<any>, ctx: WasmContext): void;
    /**
     * Writes the `xatlasMeshDecl` data to the WebAssembly memory.
     * @param ptr - Pointer to the `xatlasMeshDecl` structure in the WebAssembly memory.
     * @param ctx - The `WasmContext` instance providing access to the WebAssembly memory.
     */
    write(ptr: ptr<any>, ctx: WasmContext): void;
}
export declare class xatlasUvMeshDecl {
    /**
     * Size of the `xatlasUvMeshDecl` structure in bytes.
     */
    static readonly SIZE = 32;
    /**
     * Pointer to vertex UV data.
     */
    vertexUvData: ptr<any>;
    /**
     * Pointer to index data.
     */
    indexData: ptr<any>;
    /**
     * Pointer to face material data.
     */
    faceMaterialData: ptr<number>;
    /**
     * Number of vertices.
     */
    vertexCount: number;
    /**
     * Stride of vertex data.
     */
    vertexStride: number;
    /**
     * Number of indices.
     */
    indexCount: number;
    /**
     * Offset of indices.
     */
    indexOffset: number;
    /**
     * Format of the indices.
     */
    indexFormat: xatlasIndexFormat;
    /**
     * Reads the `xatlasUvMeshDecl` data from the WebAssembly memory.
     * @param ptr - Pointer to the `xatlasUvMeshDecl` structure in the WebAssembly memory.
     * @param ctx - The `WasmContext` instance providing access to the WebAssembly memory.
     */
    read(ptr: ptr<any>, ctx: WasmContext): void;
    /**
     * Writes the `xatlasUvMeshDecl` data to the WebAssembly memory.
     * @param ptr - Pointer to the `xatlasUvMeshDecl` structure in the WebAssembly memory.
     * @param ctx - The `WasmContext` instance providing access to the WebAssembly memory.
     */
    write(ptr: ptr<any>, ctx: WasmContext): void;
}
export declare class xatlasChartOptions {
    /**
     * Size of the `xatlasChartOptions` structure in bytes.
     */
    static readonly SIZE = 44;
    /**
     * Pointer to parameter function.
     * You should always use `0` (NULL) for this.
     */
    paramFunc: ptr<any>;
    /**
     * Maximum chart area.
     */
    maxChartArea: number;
    /**
     * Maximum boundary length.
     */
    maxBoundaryLength: number;
    /**
     * Weight for normal deviation.
     */
    normalDeviationWeight: number;
    /**
     * Weight for roundness.
     */
    roundnessWeight: number;
    /**
     * Weight for straightness.
     */
    straightnessWeight: number;
    /**
     * Weight for normal seams.
     */
    normalSeamWeight: number;
    /**
     * Weight for texture seams.
     */
    textureSeamWeight: number;
    /**
     * Maximum cost.
     */
    maxCost: number;
    /**
     * Maximum number of iterations.
     */
    maxIterations: number;
    /**
     * Flag to use input mesh UVs.
     */
    useInputMeshUvs: bool;
    /**
     * Flag to fix winding.
     */
    fixWinding: bool;
    /**
     * Reads the `xatlasChartOptions` data from the WebAssembly memory.
     * @param ptr - Pointer to the `xatlasChartOptions` structure in the WebAssembly memory.
     * @param ctx - The `WasmContext` instance providing access to the WebAssembly memory.
     */
    read(ptr: ptr<any>, ctx: WasmContext): void;
    /**
     * Writes the `xatlasChartOptions` data to the WebAssembly memory.
     * @param ptr - Pointer to the `xatlasChartOptions` structure in the WebAssembly memory.
     * @param ctx - The `WasmContext` instance providing access to the WebAssembly memory.
     */
    write(ptr: ptr<any>, ctx: WasmContext): void;
}
export declare class xatlasPackOptions {
    /**
     * Size of the `xatlasPackOptions` structure in bytes.
     */
    static readonly SIZE = 24;
    /**
     * Maximum chart size.
     */
    maxChartSize: number;
    /**
     * Padding value.
     */
    padding: number;
    /**
     * Texels per unit.
     */
    texelsPerUnit: number;
    /**
     * Resolution value.
     */
    resolution: number;
    /**
     * Flag for bilinear filtering.
     */
    bilinear: bool;
    /**
     * Flag for block alignment.
     */
    blockAlign: bool;
    /**
     * Flag for brute force.
     */
    bruteForce: bool;
    /**
     * Flag to create an image.
     */
    createImage: bool;
    /**
     * Flag to rotate charts to axis.
     */
    rotateChartsToAxis: bool;
    /**
     * Flag to rotate charts.
     */
    rotateCharts: bool;
    /**
     * Reads the `xatlasPackOptions` data from the WebAssembly memory.
     * @param ptr - Pointer to the `xatlasPackOptions` structure in the WebAssembly memory.
     * @param ctx - The `WasmContext` instance providing access to the WebAssembly memory.
     */
    read(ptr: ptr<any>, ctx: WasmContext): void;
    /**
     * Writes the `xatlasPackOptions` data to the WebAssembly memory.
     * @param ptr - Pointer to the `xatlasPackOptions` structure in the WebAssembly memory.
     * @param ctx - The `WasmContext` instance providing access to the WebAssembly memory.
     */
    write(ptr: ptr<any>, ctx: WasmContext): void;
}