import { type ItemModel, type ModelGroup } from './model'; /** * Geometry reduction for item-lod/1. Follows the src/cs2/lods.ts pattern: one meshopt pass per material group so a * material identity is never merged across, collapsing the position-welded geometry so seams are not borders. Added here: * a global triangle budget shared by the groups, fallbacks for meshes meshopt cannot reduce far enough (open shells, * many disconnected parts) and an honest report of what was achieved. */ export interface LevelSpec { id: 'lod1' | 'lod2'; /** Cap as a fraction of the source triangles. */ maxRatio: number | null; /** Absolute cap. */ maxTriangles: number | null; /** How the budget is shared between materials. */ allocation: 'triangles' | 'area'; /** Keep open borders in place on the first attempt (protects thin shells; relaxed when the cap cannot be reached). */ lockBorder: boolean; /** * Let UVs and normals steer the collapses (LOD1: the textures stay valid, a triangle never spans two UV islands). Off * (LOD2): collapse the position-welded geometry, which keeps the silhouette at a few hundred triangles but may smear UVs. */ attributes: boolean; /** Aim this fraction below the cap so a rounding wobble cannot cross it. */ margin: number; /** Each material keeps at least this many triangles (or all of them when it has fewer). */ floorTriangles: number; } export declare const ITEM_LOD1: LevelSpec; export declare const ITEM_LOD2: LevelSpec; export interface SimplifiedLevel { spec: LevelSpec; groups: ModelGroup[]; triangles: number; sourceTriangles: number; cap: number; capMet: boolean; /** Why the cap does not apply (a source too small to reduce), else null. */ waived: string | null; /** Measured two-sided surface deviation in metres over the materials this level kept. */ maxErrorM: number; /** `maxErrorM` without the sub-visible detail exemption (see `measureLevelErrors`). */ strictErrorM: number; droppedMaterials: number[]; notes: string[]; /** Set when a vehicle LOD1 was given more triangles than its starting budget to hold the error bound. */ budgetNote?: string; /** Set on a clustered vehicle shell: its triangles span UV islands, so the level is written in flat per-material colours (see `flattenColours`). */ flatColor?: boolean; } type Simplifier = Awaited>; declare function loadSimplifier(): Promise<{ supported: boolean; ready: Promise; useExperimentalFeatures: boolean; compactMesh: (indices: Uint32Array) => [Uint32Array, number]; simplify: (indices: Uint32Array, vertex_positions: Float32Array, vertex_positions_stride: number, target_index_count: number, target_error: number, flags?: import("meshoptimizer").Flags[]) => [Uint32Array, number]; simplifyWithAttributes: (indices: Uint32Array, vertex_positions: Float32Array, vertex_positions_stride: number, vertex_attributes: Float32Array, vertex_attributes_stride: number, attribute_weights: number[], vertex_lock: Uint8Array | null, target_index_count: number, target_error: number, flags?: import("meshoptimizer").Flags[]) => [Uint32Array, number]; getScale: (vertex_positions: Float32Array, vertex_positions_stride: number) => number; simplifyPoints: (vertex_positions: Float32Array, vertex_positions_stride: number, target_vertex_count: number, vertex_colors?: Float32Array, vertex_colors_stride?: number, color_weight?: number) => Uint32Array; }>; /** * The mesh as geometry only: vertices that share a position are one vertex (UV and normal splits are seams, not edges). * Simplifying the split mesh treats every seam as an open border, and at LOD2 ratios meshopt then eats the surface * along them (a UV sphere reduced to 285 triangles kept half its area). `wedges[w]` lists the original vertices at * welded vertex `w`. */ interface PositionTopology { positions: Float32Array; indices: Uint32Array; wedges: number[][]; } export declare function weldPositions(group: ModelGroup): PositionTopology; /** * Vertex clustering on a uniform grid. Blunt, but it reaches any triangle count, which meshopt's edge collapse cannot * guarantee on open or disconnected geometry. The cell size is bisected until the result fits. With `uvAware`, vertices only * merge when they belong to the same UV island and their UVs fall in the same eighth of the texture, so a cell never averages * two UV islands into a smear and no triangle reads the gap between islands. When even the coarsest such grid is over the target * (a faceted shape whose every face is its own island), the keys are relaxed to the island alone and then dropped: reaching the * cap beats keeping the textures tidy, and a level over its cap would fail the item. */ export declare function clusterGroup(group: ModelGroup, targetTriangles: number, uvAware?: boolean): ModelGroup; /** * Keeps the triangles that can be seen from outside the model: the surface is rasterised into a voxel grid, empty space is * flooded from the grid's edge, and a triangle survives when it touches a cell next to reachable space. Seats, dashboards, * engine bays and other interiors of a closed-up body drop out; windows (glass is a surface) keep the cabin sealed. */ export declare function exteriorGroups(groups: readonly ModelGroup[], bounds: { min: readonly number[]; max: readonly number[]; }, resolution?: number): ModelGroup[]; /** Clusters every group on one shared grid, as fine as the triangle budget allows (the densest grid whose total fits). */ export declare function clusterGroups(groups: readonly ModelGroup[], bounds: { min: readonly number[]; max: readonly number[]; }, targetTriangles: number, uvAware?: boolean, shift?: readonly number[], medoidUv?: boolean): ModelGroup[]; export interface GroupResult { group: ModelGroup; method: 'kept' | 'meshopt' | 'meshopt-relaxed' | 'cluster'; } /** * Merge vertices that share position, UVs and colour and whose normals agree within `maxAngleDeg`; the merged normal is * the normalised mean. Exporters split vertices on every normal discontinuity, and meshopt cannot collapse across those * splits (a smooth ball with panel grooves stalled at 53 percent). Hard edges beyond the angle stay split. */ export declare function weldForSimplify(group: ModelGroup, maxAngleDeg?: number): ModelGroup; /** * Splits the welded topology into connected parts (shared welded vertices), largest area first. */ export declare function connectedParts(topology: PositionTopology): Array<{ indices: Uint32Array; area: number; }>; export declare function simplifyGroup(simplifier: Simplifier, input: ModelGroup, targetTriangles: number, lockBorder: boolean, attributes?: boolean): GroupResult; /** Source parts (connected pieces of one material) whose bounding box is smaller than this fraction of the item's longest extent are sub-visible detail (buttons, bolts, stitching) the levels drop by design. */ export declare const ITEM_LOD_DETAIL_PART_RATIO = 0.02; export interface LevelErrors { /** Two-sided distance ignoring source parts smaller than `minPartM`: the shape error of what a viewer can see. */ maxErrorM: number; /** The same distance over every source vertex, tiny parts included. */ strictErrorM: number; } /** * Largest distance, in metres, between the two surfaces over each material the level kept: source vertices to the level's * triangles and the level's vertices back to the source triangles. Measured on the geometry, not taken from the * simplifier's attribute-weighted estimate. A source part smaller than `minPartM` that the level dropped does not count * towards `maxErrorM` (a 1 cm button 1.2 m from the next lamp is not a 1.2 m error), but does towards `strictErrorM`. */ export declare function measureLevelErrors(source: readonly ModelGroup[], level: readonly ModelGroup[], minPartM?: number): LevelErrors; export declare const measureLevelError: (source: readonly ModelGroup[], level: readonly ModelGroup[]) => number; /** Below this many triangles the source already is the cheapest useful mesh: LOD2 equals it and LOD1 is waived. */ export declare const ITEM_LOD_SMALL_SOURCE = 300; export interface SimplifyOptions { /** Tightens the spec's own absolute cap (LOD2 uses it to stay below LOD1). */ maxTriangles?: number; /** Skips the pass that spends spare budget on the parts that came out furthest from the source (see `refineLevel`). */ noRefine?: boolean; } /** * A level whose measured error is over this fraction of the longest extent is one the runtime skips (the backend sample showed * skips between 9 and 14 percent): the levels try to hold it, spending triangles where the error is. */ export declare const ITEM_LOD_MAX_ERROR_RATIO = 0.1; export declare function simplifyModel(model: ItemModel, spec: LevelSpec, options?: SimplifyOptions): Promise; /** A level must cut at least this fraction of the triangles of the level above it, or it is not worth a file. */ export declare const ITEM_LOD_MIN_REDUCTION = 0.5; /** `prop`: LOD1 keeps at most 25 percent of the source. `vehicle`: LOD1 targets max(5000, 10 percent of the source). */ export type ItemLodProfile = 'prop' | 'vehicle'; export declare const VEHICLE_LOD1_MIN_TRIANGLES = 5000; export declare const VEHICLE_LOD1_RATIO = 0.1; export declare function lod1SpecFor(profile: ItemLodProfile, sourceTriangles: number): LevelSpec; /** The widest a vehicle LOD1 may grow while chasing the error bound: the prop budget. Widening stops early when it stops helping. */ export declare const VEHICLE_LOD1_WIDEST_RATIO: number; export declare function simplifyLod1(model: ItemModel, profile: ItemLodProfile, maxErrorRatio?: number): Promise; /** * LOD2 is aimed at half of the level above it (LOD1 when emitted, else the source) so that it passes the 50 percent * reduction rule when the geometry allows, and at the absolute 300 triangle cap. * * A vehicle has dozens of materials, so the per-material budget leaves the body a handful of triangles and an open shell. For * vehicles the visible shell (see `exteriorGroups`) clustered on one grid shared by every material is measured as well, and the * level with the smaller measured error wins. */ export declare function simplifyLod2(model: ItemModel, aboveTriangles: number, profile?: ItemLodProfile): Promise; /** A vehicle LOD2 whose measured error is over this fraction of the longest extent is a broken shape; the tier is left out. */ export declare const VEHICLE_LOD2_MAX_ERROR_RATIO = 0.25; /** * A vehicle clustered on one grid shared by all materials, within `cap` triangles: the whole model, or with `exterior` only * the triangles visible from outside (which stops interiors spending budget but can starve small outer parts such as tyres). */ export declare function simplifyVehicleShell(model: ItemModel, cap: number, exterior?: boolean): SimplifiedLevel; /** Grid placements the vehicle shell tries: a quarter-cell steps along the first axis, half-cell steps along the others. */ export declare const VEHICLE_SHELL_SHIFTS: ReadonlyArray; export {};