Model loading · function
weldMesh
Weld one mesh. Returns the same mesh when nothing can be merged.
Explained in Importing models.
function weldMesh(mesh: MeshData): MeshDataimport { weldMesh } from '@driftengine/assets';Parameters
| Parameter | Type | Description |
|---|---|---|
mesh | MeshData |
In depth
Every attribute decides identity, and that is a cost as well as a correctness rule. Two corners alike in position, normal and UV but weighted to different bones are two vertices, and merging them moves geometry with the wrong limb; two alike in everything including their UV but opposite in the bitangent's sign are a mirrored UV shell, and merging them lights one side of the model inside out. Neither is visible in any count a bake prints.
What it costs is a file whose tangent frame was derived per corner instead of authored: a
corner soup gets one triangle's frame per corner, so no two corners agree and the weld that
would have merged them cannot. The way out is not a looser key — it is to derive the frame
from the welded mesh, which is what the baker does as of 3.30.0: it passes
deriveTangents: false to the reader and calls deriveTangentsFor here, afterwards.
How much it costs depends on the unwrap, and two figures in this repository disagreed about
it. The frame is normalised, so two triangles produce different frames only where the
direction u increases in differs between them. On a separable unwrap — u from x, v from y —
every triangle on a flat surface agrees and a derived frame costs almost nothing; a 253-mesh CAD
export measured 728,168 vertices against 728,161 with no frame, seven vertices, and that file is
not on this machine. On a rotational unwrap the direction turns with position and almost nothing
merges: 9,600 corners to 9,482 vertices against 1,681, six different frames at one point at
worst, measured in tangentOrder.test.ts and reproducible. The order is fixed for the second
case; the first is why it went unnoticed.