feat(mesh): support uvBounds and planar back-face UVs

Add an optional uvBounds to extrudeShape/extrudeShapeParts so UVs can be derived from a framing rectangle instead of the shape's bounding box, letting a traced silhouette align with its full image. The bottom face now uses the same planar xy UVs as the top face (no horizontal mirror), so the texture is consistent across front, back, and walls.
This commit is contained in:
2026-08-08 15:12:07 +08:00
parent dc8127dba1
commit 21fc1b29c1
6 changed files with 146 additions and 43 deletions
+13
View File
@@ -74,6 +74,19 @@ describe('extrudeShapeParts', () => {
expect(caps.positions.length + walls.positions.length).toBe(combined.positions.length);
expect(caps.indices.length + walls.indices.length).toBe(combined.indices.length);
});
it('applies uvBounds to caps and walls', () => {
const uvBounds = { minX: 0, minY: 0, maxX: 4, maxY: 4 };
const { caps, walls } = extrudeShapeParts(rectShape(1, 1), {
height: 1,
uvBounds,
});
// Caps: bottom-left vertex at (-0.5,-0.5) -> u=-0.125.
expect(caps.uvs[0]).toBeCloseTo(-0.125, 5);
// Walls: first outline point (-0.5,-0.5) -> u=-0.125, v=-0.125.
expect(walls.uvs[0]).toBeCloseTo(-0.125, 5);
expect(walls.uvs[1]).toBeCloseTo(-0.125, 5);
});
});
describe('mergeFaces', () => {