weld

Function weld 

Source
pub fn weld(mesh: &mut Mesh, uvs: Option<Vec<f32>>) -> Option<Vec<f32>>
Expand description

Weld a mesh’s vertices in place, carrying uvs through the same remap and returning them still 1:1 with the welded positions.

The one body behind every entry point here. It welds in whatever frame the CALLER hands it, which is the decision the caller owns: see the module doc for why the object frame is the right one for shared geometry, and what a world-frame weld does to it.

Computes the normals first when a processor left them absent or short. The key carries the quantized normal so a crease stays split, and weld_indexed REFUSES a mesh whose normals do not match its positions 1:1 while signalling that refusal with the same None it returns for “nothing collided” — so without this, a silently skipped weld is indistinguishable from an already-welded one, on every model. calculate_normals accumulates from the triangle winding, so it needs only positions and indices and is happy in any frame; transform_mesh_world then rotates the result into world space with the positions. build_mesh_data’s call already guarantees 1:1 normals; the two placement appliers do NOT, which is where this earns its keep.

None from weld_indexed leaves the mesh and the UVs untouched, with no reallocation.

§What legitimately calls this AFTER the bake

element::build_mesh_data, for geometry with no cross-occurrence identity to protect (instance_meta absent). Two populations arrive there, and they are not the same:

  • Geometry BORN after the placement bake, which no earlier weld could have reached: CSG void-cut output, layer slices, the #858 palette-split parts. This is the weld that collapses the kernel’s per-face output for them.
  • Geometry already welded in the object frame that merely lost its instance_meta on the way there — a void host (welded in apply_placement, then cut, then nulled at voids::process_element_with_voids), a multi-item element (processing.rs keeps the metadata only for a single instanceable item), a textured face-set sub-mesh. For these it is a SECOND weld: cheap when nothing new collides, but it CAN merge world-frame coincidences the object frame kept apart, so their shipped buffers are placement-dependent in the way the module doc describes. Accepted because none of them is shared.

Shared geometry must not reach that call site. build_mesh_data keeps it out on instance_meta; #4122 is about recording the answer instead of inferring it.