Skip to content

armgit / kiln

Public Imported from GitHub
0

Build and revise procedural 3D assets with your coding agent. Local MCP server, CLI and TypeScript engine with rendered review, editable source and GLB export.

Keep a uv-y foliage gradient through atlas remapping, and state what the structural checks cover (#293, #289) (#298)

Matthew Kissinger4a3347f345b4
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 40ce5239..8f450c58 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -30,6 +30,23 @@ does not publish a package.
material factors. `materialRecipe` and the portable material specs already named
their output and are unchanged
([#288](https://github.com/instruktlabs/kiln/issues/288)).
+- `remapUVToAtlas` takes an optional `axes`. The default `uv` is unchanged and replaces
+ both components, which silently destroys a per-vertex gradient carried in V — a foliage
+ wind sway weight read as `uv-y` is the known case, and the asset still validates and
+ renders. `axes: 'u-only'` rescales U into the named region and passes V through
+ bit-for-bit, requiring `inputOrigin: 'top-left'` over a region spanning the full atlas
+ height, so a column sheet keeps the gradient while U can still be inset to texel
+ centers. A packed or vertically inset region is rejected rather than remapped. The
+ binding records `axes` only for `u-only`, so existing stamps and exported extras are
+ byte-identical. The helper contract, Discovery notes and authoring guidance now state
+ what replacing V costs ([#293](https://github.com/instruktlabs/kiln/issues/293)).
+- The floating-parts warning and the part-connectivity observation state their coverage:
+ both read the bounding boxes of drawn meshes at a 2 cm tolerance, so a smaller gap reads
+ as contact and primitives welded into one mesh are never compared with each other. The
+ QA integration reference says to measure millimetre contacts in the destination before
+ saving. Reproduced from a reported clean pass on a 2 mm detached part; the checks behaved
+ as specified and the tolerance, not welding, is what admitted it. No check changes
+ behaviour ([#289](https://github.com/instruktlabs/kiln/issues/289)).
## 1.5.0 (2026-10-25)
diff --git a/dist/agent-run.mjs b/dist/agent-run.mjs
index 8facb08b..d00d4b36 100644
--- a/dist/agent-run.mjs
+++ b/dist/agent-run.mjs
@@ -8653,12 +8653,13 @@ const mesh = new THREE.Mesh(unwrapped, bakedPbr);`
},
{
name: "remapUVToAtlas",
- signature: "remapUVToAtlas(geometry, atlasTextureOrManifest, regionName, { inputOrigin: 'top-left' | 'bottom-left', mode: 'content-boundary' | 'texel-center' })",
+ signature: "remapUVToAtlas(geometry, atlasTextureOrManifest, regionName, { inputOrigin: 'top-left' | 'bottom-left', mode: 'content-boundary' | 'texel-center', axes?: 'uv' | 'u-only' })",
returns: "THREE.BufferGeometry",
category: "uv",
description: "Maps existing unit UV0 into a named atlas content rectangle on an owned geometry clone, preserving topology and rich attributes.",
- example: "const card = remapUVToAtlas(planeGeo(1, 1), atlas, 'patch', { inputOrigin: 'bottom-left', mode: 'texel-center' });",
- promptNotes: "UV0 must be finite in [0,1], with two components per vertex. Content-boundary maps endpoints to content edges; texel-center maps endpoints to the first/last content texel centers. Explicitly identify the input UV origin; atlas image coordinates use top left and flipY=false. Geometry, normals, colors, skin weights, morph buffers, groups and source metadata are preserved independently. UV scale changes invalidate tangents; regenerate when needed. This helper does not project, unwrap, tile within a region or change material sampling."
+ example: `const card = remapUVToAtlas(planeGeo(1, 1), atlas, 'patch', { inputOrigin: 'bottom-left', mode: 'texel-center' });
+const blade = remapUVToAtlas(leafGeo, fernColumnAtlas, 'fern', { inputOrigin: 'top-left', mode: 'texel-center', axes: 'u-only' });`,
+ promptNotes: "UV0 must be finite in [0,1], with two components per vertex. Content-boundary maps endpoints to content edges; texel-center maps endpoints to the first/last content texel centers. Explicitly identify the input UV origin; atlas image coordinates use top left and flipY=false. Geometry, normals, colors, skin weights, morph buffers, groups and source metadata are preserved independently. UV scale changes invalidate tangents; regenerate when needed. The default axes 'uv' replaces both components, so it destroys a per-vertex gradient carried in V — a foliage wind sway weight read as uv-y is the known case, and the result still validates and renders. Pass axes 'u-only' for that: it rescales U into the named column and leaves V bit-for-bit, requiring inputOrigin 'top-left' and a region that spans the full atlas height (lay the sheet out as full-height species columns with gutter 0). This helper does not project, unwrap, tile within a region or change material sampling."
},
{
name: "normalMapFromHeight",
@@ -14907,13 +14908,18 @@ function lookup(table, id) {
fail3("unknown atlas reference.");
return found;
}
-function derivedBinding(p, regionName, origin, mode) {
+function derivedBinding(p, regionName, origin, mode, axes) {
if (!["top-left", "bottom-left"].includes(origin) || !["content-boundary", "texel-center"].includes(mode))
fail3("explicit binding origin/mode required.");
+ if (axes !== undefined && axes !== "u-only")
+ fail3("unsupported binding axes.");
+ const uOnly = axes === "u-only";
const r = p.manifest.regions.find((r) => r.name === regionName);
if (!r)
fail3("unknown named region.");
const { x, y, width: w, height: h } = r.content, center = mode === "texel-center", bottom = origin === "bottom-left";
+ if (uOnly && (origin !== "top-left" || y !== 0 || h !== p.manifest.height))
+ fail3("u-only binding requires a top-left origin over a full-height region.");
return {
manifestHash: p.manifest.manifestHash,
specHash: p.manifest.specHash,
@@ -14923,29 +14929,30 @@ function derivedBinding(p, regionName, origin, mode) {
allocation: structuredClone(r.allocation),
inputOrigin: origin,
mode,
+ ...uOnly ? { axes: "u-only" } : {},
scale: [
(w - (center ? 1 : 0)) / p.manifest.width,
- (bottom ? -1 : 1) * (h - (center ? 1 : 0)) / p.manifest.height
+ uOnly ? 1 : (bottom ? -1 : 1) * (h - (center ? 1 : 0)) / p.manifest.height
],
offset: [
(x + (center ? 0.5 : 0)) / p.manifest.width,
- (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / p.manifest.height
+ uOnly ? 0 : (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / p.manifest.height
]
};
}
function expandAtlasBinding(input, table) {
canonicalAtlasMetadataJsonV1(input);
- const r = closed(input, ["version", "atlasId", "region", "inputOrigin", "mode"]);
+ const r = closed(input, ["version", "atlasId", "region", "inputOrigin", "mode", "axes"]);
if (r["version"] !== ATLAS_PROVENANCE_VERSION)
fail3("unsupported binding version.");
- return derivedBinding(lookup(table, r["atlasId"]), r["region"], r["inputOrigin"], r["mode"]);
+ return derivedBinding(lookup(table, r["atlasId"]), r["region"], r["inputOrigin"], r["mode"], r["axes"]);
}
function readAtlasGeometryBinding(geometry, provenance) {
const stamp = field(geometry.userData, "kilnAtlasBinding");
if (stamp === undefined)
return;
canonicalAtlasMetadataJsonV1(stamp);
- const r = stamp, derived = derivedBinding(provenance, r["region"], r["inputOrigin"], r["mode"]);
+ const r = stamp, derived = derivedBinding(provenance, r["region"], r["inputOrigin"], r["mode"], r["axes"]);
if (canonicalAtlasMetadataJsonV1(stamp) !== canonicalAtlasMetadataJsonV1(derived))
fail3("named binding identity or remap formula mismatch.");
return {
@@ -14953,7 +14960,8 @@ function readAtlasGeometryBinding(geometry, provenance) {
atlasId: provenance.manifest.manifestHash,
region: r["region"],
inputOrigin: r["inputOrigin"],
- mode: r["mode"]
+ mode: r["mode"],
+ ...r["axes"] === undefined ? {} : { axes: r["axes"] }
};
}
function collectAtlasProvenance(root) {
@@ -15530,8 +15538,9 @@ function inspectAtlasScene(root) {
continue;
}
const center = binding.mode === "texel-center" ? 0.5 : 0;
+ const centerY = binding.axes === "u-only" ? 0 : center;
const minX = (region.content.x + center) / entry.p.manifest.width, maxX = (region.content.x + region.content.width - center) / entry.p.manifest.width;
- const minY = (region.content.y + center) / entry.p.manifest.height, maxY = (region.content.y + region.content.height - center) / entry.p.manifest.height;
+ const minY = (region.content.y + centerY) / entry.p.manifest.height, maxY = (region.content.y + region.content.height - centerY) / entry.p.manifest.height;
const tolerance = 4 * 2 ** -23;
let invalid = false;
const point = new THREE11.Vector2;
@@ -16978,7 +16987,7 @@ function inspectPartConnectivity(scene, supports) {
disposition: "observe",
dimension: "visualQuality",
profile: "geometry.partConnectivity",
- message: `${subject} separate from the largest component in the rest-pose bounding boxes of visible parts; the nearest box gap is ${group.gap.toFixed(3)} m. This may be intentional. Box adjacency is not physical attachment evidence.${lodNote}`,
+ message: `${subject} separate from the largest component in the rest-pose bounding boxes of visible parts; the nearest box gap is ${group.gap.toFixed(3)} m. This may be intentional. Box adjacency is not physical attachment evidence: a gap under ${CONNECTIVITY_TOLERANCE} m reads as contact, and primitives welded into one mesh form one box.${lodNote}`,
affected: { node: group.parts[0] },
measurement: {
name: "gapToMainComponent",
@@ -30854,14 +30863,21 @@ ${canonicalAtlasMetadataJsonV1(payload)}`)}` !== manifestHash)
function remapUVToAtlas(geometry, atlas, name, options) {
const manifest = manifestOf(atlas);
canonicalAtlasMetadataJsonV1(options);
- if (!options || typeof options !== "object" || Array.isArray(options) || Object.keys(options).some((k) => !["inputOrigin", "mode"].includes(k)) || !["top-left", "bottom-left"].includes(options.inputOrigin) || !["content-boundary", "texel-center"].includes(options.mode))
+ if (!options || typeof options !== "object" || Array.isArray(options) || Object.keys(options).some((k) => !["inputOrigin", "mode", "axes"].includes(k)) || !["top-left", "bottom-left"].includes(options.inputOrigin) || !["content-boundary", "texel-center"].includes(options.mode))
atlasFailure("explicit inputOrigin and content-boundary/texel-center mode are required.");
+ if (options.axes !== undefined && !["uv", "u-only"].includes(options.axes))
+ atlasFailure("axes must be uv (default, both components) or u-only.");
+ const uOnly = options.axes === "u-only";
+ if (uOnly && options.inputOrigin !== "top-left")
+ atlasFailure("u-only requires inputOrigin top-left: V passes through unmapped, so a bottom-left flip would invert the gradient it carries.");
const region = manifest.regions.find((r) => r.name === name);
if (!region)
atlasFailure(`unknown named region ${String(name)}.`);
const { x, y, width: w, height: h } = region.content;
if (![x, y, w, h].every(Number.isSafeInteger) || x < 0 || y < 0 || w < 1 || h < 1 || x + w > manifest.width || y + h > manifest.height)
atlasFailure("invalid region content rectangle.");
+ if (uOnly && (y !== 0 || h !== manifest.height))
+ atlasFailure(`u-only requires a region spanning the full atlas height; ${name} covers rows ${y}..${y + h} of ${manifest.height}. Lay the atlas out as full-height columns with gutter 0.`);
const uv = geometry?.getAttribute?.("uv"), position = geometry?.getAttribute?.("position");
if (!position || !uv || uv.itemSize !== 2 || uv.count !== position.count || uv.count < 1 || uv.count > TEXTURE_ATLAS_LIMITS.uvVertices || uv.isInstancedBufferAttribute || uv.data?.isInstancedInterleavedBuffer)
atlasFailure("matching per-vertex UV0 and positions are required; per-instance UVs are unsupported.");
@@ -30894,9 +30910,9 @@ function remapUVToAtlas(geometry, atlas, name, options) {
const bottom = options.inputOrigin === "bottom-left";
const offset = [
(x + (center ? 0.5 : 0)) / manifest.width,
- (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / manifest.height
+ uOnly ? 0 : (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / manifest.height
];
- const scale = [su, bottom ? -sv : sv];
+ const scale = [su, uOnly ? 1 : bottom ? -sv : sv];
const output = remapUV(geometry, { scale, offset });
output.userData.kilnAtlasBinding = {
manifestHash: manifest.manifestHash,
@@ -30907,6 +30923,7 @@ function remapUVToAtlas(geometry, atlas, name, options) {
allocation: structuredClone(region.allocation),
inputOrigin: options.inputOrigin,
mode: options.mode,
+ ...uOnly ? { axes: "u-only" } : {},
scale,
offset
};
@@ -39500,7 +39517,7 @@ function inspectSceneStructure(root, opts = {}) {
names.push(`+${rest.length - names.length} more`);
entries.push(`+${rest.length} more floating: ${names.join(", ")} — the same fix applies: shift each onto its nearest sibling, or call snapTo(part, hostPart).`);
}
- warnings.push(`Floating parts (no mesh overlap with any sibling, 2cm tol): ${entries.join(" | ")}`);
+ warnings.push(`Floating parts (no mesh overlap with any sibling, 2cm tol): ${entries.join(" | ")} — Coverage: drawn meshes only, at 2cm. A smaller gap reads as contact and a primitive welded into another mesh is never seen, so a silent pass is not a fit audit; measure contacts in the destination.`);
}
if (supported.length > 0) {
const shown = supported.slice(0, FLOATER_NAMES_SHOWN);
@@ -44990,11 +45007,13 @@ define2("remapUVToAtlas", {
axes: "Explicit top-left or bottom-left input origin; target follows top-left image coordinates.",
parameters: [
"Requires a compiled atlas texture or manifest and exact region name.",
- "inputOrigin and content-boundary/texel-center mode are both required; finite per-vertex UV0 only."
+ "inputOrigin and content-boundary/texel-center mode are both required; finite per-vertex UV0 only.",
+ "Optional axes selects which components the region owns: 'uv' (default) both, 'u-only' U alone. u-only requires inputOrigin top-left over a region spanning the full atlas height, and is rejected otherwise."
],
topology: ["Preserves vertices, indices, groups, draw range and morph correspondence."],
preservation: [
- "Owns output attributes and metadata; UV0 is replaced. Nonidentity scale drops stale tangents with a warning."
+ "Owns output attributes and metadata; UV0 is replaced. Nonidentity scale drops stale tangents with a warning.",
+ "Replacing V destroys any per-vertex gradient UV0 carries, such as a foliage wind sway weight read as uv-y: the asset still validates and renders. axes u-only passes V through bit-for-bit and rescales U into a full-height column instead."
],
semantics: [
"Records the named region and affine mapping without changing asset category, project membership or materials."
@@ -45004,8 +45023,14 @@ define2("remapUVToAtlas", {
references: ["src/texture-atlas.ts", "src/uv-shapes.ts"],
tags: ["uv", "atlas", "ownership"],
aliases: ["named region UV mapping"],
- intents: ["bind existing UVs to a named atlas region"],
- limitations: ["Does not unwrap, project, resample or tile within a region."],
+ intents: [
+ "bind existing UVs to a named atlas region",
+ "put species in atlas columns while keeping a V gradient"
+ ],
+ limitations: [
+ "Does not unwrap, project, resample or tile within a region.",
+ "u-only needs a column layout authored for it: a packed sheet or a nonzero gutter insets the region vertically and is rejected rather than remapped."
+ ],
related: [
{ name: "textureAtlas", relation: "prerequisite" },
{ name: "projectUV", relation: "companion" }
diff --git a/dist/build.json b/dist/build.json
index 5f11d176..2b72d28c 100644
--- a/dist/build.json
+++ b/dist/build.json
@@ -2,10 +2,10 @@
"schemaVersion": 1,
"entries": {
"worker": {
- "identity": "sha256:edf7989be0c54163d7b260a8bd9ada32d207a140d153fb079e78a1f5ac288185",
+ "identity": "sha256:b817cd61ecee540bb6f68f5ac4c9f8f2c1860d4f307acdd5efd6c2da1cc11171",
"engineVersion": "1.5.0",
"toolchain": "[email protected]",
- "sourceHash": "639ce14184fda78b29f721efed22124d667751f1fef1a2b5e322c25154ec1959",
+ "sourceHash": "f53a7b8fe566fbcc1756dd50decf7329d38fc853cc88ed2bf05c34f3e44aca03",
"rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a",
"dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10",
"dependencies": {
@@ -37,13 +37,13 @@
},
"target": "node",
"file": "evaluator-worker.mjs",
- "bundleHash": "sha256:b729bef5fda52674cabf362880ed986bbe9cbabb67bc0341c0a7cdb0c5619f66"
+ "bundleHash": "sha256:4c5521b27238d6848a39c552d2844507d7bd2f92df3ce5e4e2b91d15ca521706"
},
"agent-run": {
- "identity": "sha256:edf7989be0c54163d7b260a8bd9ada32d207a140d153fb079e78a1f5ac288185",
+ "identity": "sha256:b817cd61ecee540bb6f68f5ac4c9f8f2c1860d4f307acdd5efd6c2da1cc11171",
"engineVersion": "1.5.0",
"toolchain": "[email protected]",
- "sourceHash": "639ce14184fda78b29f721efed22124d667751f1fef1a2b5e322c25154ec1959",
+ "sourceHash": "f53a7b8fe566fbcc1756dd50decf7329d38fc853cc88ed2bf05c34f3e44aca03",
"rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a",
"dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10",
"dependencies": {
@@ -75,13 +75,13 @@
},
"target": "node",
"file": "agent-run.mjs",
- "bundleHash": "sha256:2b36abd5b141e03287ce5b8f628df3d1347598a5079ed6edfaf50e6ae011cec1"
+ "bundleHash": "sha256:632042c1d9d6a4d6ea6209718d54b0cbd99863782ab51e6e0f3f6a65bd5cf0a5"
},
"agent-providers": {
- "identity": "sha256:edf7989be0c54163d7b260a8bd9ada32d207a140d153fb079e78a1f5ac288185",
+ "identity": "sha256:b817cd61ecee540bb6f68f5ac4c9f8f2c1860d4f307acdd5efd6c2da1cc11171",
"engineVersion": "1.5.0",
"toolchain": "[email protected]",
- "sourceHash": "639ce14184fda78b29f721efed22124d667751f1fef1a2b5e322c25154ec1959",
+ "sourceHash": "f53a7b8fe566fbcc1756dd50decf7329d38fc853cc88ed2bf05c34f3e44aca03",
"rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a",
"dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10",
"dependencies": {
@@ -116,10 +116,10 @@
"bundleHash": "sha256:9d6faf03d307321bc2e3bd5ce5bdee0bbbf61e0ebed8bfebfa1fb072287b83fa"
},
"mcp": {
- "identity": "sha256:edf7989be0c54163d7b260a8bd9ada32d207a140d153fb079e78a1f5ac288185",
+ "identity": "sha256:b817cd61ecee540bb6f68f5ac4c9f8f2c1860d4f307acdd5efd6c2da1cc11171",
"engineVersion": "1.5.0",
"toolchain": "[email protected]",
- "sourceHash": "639ce14184fda78b29f721efed22124d667751f1fef1a2b5e322c25154ec1959",
+ "sourceHash": "f53a7b8fe566fbcc1756dd50decf7329d38fc853cc88ed2bf05c34f3e44aca03",
"rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a",
"dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10",
"dependencies": {
@@ -154,10 +154,10 @@
"bundleHash": "sha256:deeb947091b693e92337a2081678ed06cd0a2d23f813a375001c31dbf529a815"
},
"cli": {
- "identity": "sha256:edf7989be0c54163d7b260a8bd9ada32d207a140d153fb079e78a1f5ac288185",
+ "identity": "sha256:b817cd61ecee540bb6f68f5ac4c9f8f2c1860d4f307acdd5efd6c2da1cc11171",
"engineVersion": "1.5.0",
"toolchain": "[email protected]",
- "sourceHash": "639ce14184fda78b29f721efed22124d667751f1fef1a2b5e322c25154ec1959",
+ "sourceHash": "f53a7b8fe566fbcc1756dd50decf7329d38fc853cc88ed2bf05c34f3e44aca03",
"rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a",
"dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10",
"dependencies": {
@@ -189,13 +189,13 @@
},
"target": "node",
"file": "cli.mjs",
- "bundleHash": "sha256:20b3c895e2bb7523e32216e0508c4079ab53fcd572446a3b66bd5053c8e9b1d0"
+ "bundleHash": "sha256:47ae66667a40f15555369996d039e58dd90a11fd661ebb9a3965819b1ce44568"
},
"engine": {
- "identity": "sha256:edf7989be0c54163d7b260a8bd9ada32d207a140d153fb079e78a1f5ac288185",
+ "identity": "sha256:b817cd61ecee540bb6f68f5ac4c9f8f2c1860d4f307acdd5efd6c2da1cc11171",
"engineVersion": "1.5.0",
"toolchain": "[email protected]",
- "sourceHash": "639ce14184fda78b29f721efed22124d667751f1fef1a2b5e322c25154ec1959",
+ "sourceHash": "f53a7b8fe566fbcc1756dd50decf7329d38fc853cc88ed2bf05c34f3e44aca03",
"rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a",
"dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10",
"dependencies": {
@@ -227,7 +227,7 @@
},
"target": "node",
"file": "mcp-engine.mjs",
- "bundleHash": "sha256:635ac9bbc43d2ca046d284afb5698c20380aa4e9ecc53fe5dc307f1e55b861f2"
+ "bundleHash": "sha256:c3b19ac35fba13051365f1346876c695d965372ed75a52f9d416fd6ceafd77bf"
}
}
}
diff --git a/dist/cli.mjs b/dist/cli.mjs
index 2c89efc7..1b5256e0 100644
--- a/dist/cli.mjs
+++ b/dist/cli.mjs
@@ -2151,13 +2151,18 @@ function lookup(table, id) {
fail2("unknown atlas reference.");
return found;
}
-function derivedBinding(p, regionName, origin, mode) {
+function derivedBinding(p, regionName, origin, mode, axes) {
if (!["top-left", "bottom-left"].includes(origin) || !["content-boundary", "texel-center"].includes(mode))
fail2("explicit binding origin/mode required.");
+ if (axes !== undefined && axes !== "u-only")
+ fail2("unsupported binding axes.");
+ const uOnly = axes === "u-only";
const r = p.manifest.regions.find((r) => r.name === regionName);
if (!r)
fail2("unknown named region.");
const { x, y, width: w, height: h } = r.content, center = mode === "texel-center", bottom = origin === "bottom-left";
+ if (uOnly && (origin !== "top-left" || y !== 0 || h !== p.manifest.height))
+ fail2("u-only binding requires a top-left origin over a full-height region.");
return {
manifestHash: p.manifest.manifestHash,
specHash: p.manifest.specHash,
@@ -2167,29 +2172,30 @@ function derivedBinding(p, regionName, origin, mode) {
allocation: structuredClone(r.allocation),
inputOrigin: origin,
mode,
+ ...uOnly ? { axes: "u-only" } : {},
scale: [
(w - (center ? 1 : 0)) / p.manifest.width,
- (bottom ? -1 : 1) * (h - (center ? 1 : 0)) / p.manifest.height
+ uOnly ? 1 : (bottom ? -1 : 1) * (h - (center ? 1 : 0)) / p.manifest.height
],
offset: [
(x + (center ? 0.5 : 0)) / p.manifest.width,
- (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / p.manifest.height
+ uOnly ? 0 : (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / p.manifest.height
]
};
}
function expandAtlasBinding(input, table) {
canonicalAtlasMetadataJsonV1(input);
- const r = closed(input, ["version", "atlasId", "region", "inputOrigin", "mode"]);
+ const r = closed(input, ["version", "atlasId", "region", "inputOrigin", "mode", "axes"]);
if (r["version"] !== ATLAS_PROVENANCE_VERSION)
fail2("unsupported binding version.");
- return derivedBinding(lookup(table, r["atlasId"]), r["region"], r["inputOrigin"], r["mode"]);
+ return derivedBinding(lookup(table, r["atlasId"]), r["region"], r["inputOrigin"], r["mode"], r["axes"]);
}
function readAtlasGeometryBinding(geometry, provenance) {
const stamp = field(geometry.userData, "kilnAtlasBinding");
if (stamp === undefined)
return;
canonicalAtlasMetadataJsonV1(stamp);
- const r = stamp, derived = derivedBinding(provenance, r["region"], r["inputOrigin"], r["mode"]);
+ const r = stamp, derived = derivedBinding(provenance, r["region"], r["inputOrigin"], r["mode"], r["axes"]);
if (canonicalAtlasMetadataJsonV1(stamp) !== canonicalAtlasMetadataJsonV1(derived))
fail2("named binding identity or remap formula mismatch.");
return {
@@ -2197,7 +2203,8 @@ function readAtlasGeometryBinding(geometry, provenance) {
atlasId: provenance.manifest.manifestHash,
region: r["region"],
inputOrigin: r["inputOrigin"],
- mode: r["mode"]
+ mode: r["mode"],
+ ...r["axes"] === undefined ? {} : { axes: r["axes"] }
};
}
function collectAtlasProvenance(root) {
@@ -2814,8 +2821,9 @@ function inspectAtlasScene(root) {
continue;
}
const center = binding.mode === "texel-center" ? 0.5 : 0;
+ const centerY = binding.axes === "u-only" ? 0 : center;
const minX = (region.content.x + center) / entry.p.manifest.width, maxX = (region.content.x + region.content.width - center) / entry.p.manifest.width;
- const minY = (region.content.y + center) / entry.p.manifest.height, maxY = (region.content.y + region.content.height - center) / entry.p.manifest.height;
+ const minY = (region.content.y + centerY) / entry.p.manifest.height, maxY = (region.content.y + region.content.height - centerY) / entry.p.manifest.height;
const tolerance = 4 * 2 ** -23;
let invalid = false;
const point = new THREE3.Vector2;
@@ -11607,7 +11615,7 @@ function inspectPartConnectivity(scene, supports) {
disposition: "observe",
dimension: "visualQuality",
profile: "geometry.partConnectivity",
- message: `${subject} separate from the largest component in the rest-pose bounding boxes of visible parts; the nearest box gap is ${group.gap.toFixed(3)} m. This may be intentional. Box adjacency is not physical attachment evidence.${lodNote}`,
+ message: `${subject} separate from the largest component in the rest-pose bounding boxes of visible parts; the nearest box gap is ${group.gap.toFixed(3)} m. This may be intentional. Box adjacency is not physical attachment evidence: a gap under ${CONNECTIVITY_TOLERANCE} m reads as contact, and primitives welded into one mesh form one box.${lodNote}`,
affected: { node: group.parts[0] },
measurement: {
name: "gapToMainComponent",
@@ -27547,14 +27555,21 @@ ${canonicalAtlasMetadataJsonV1(payload)}`)}` !== manifestHash)
function remapUVToAtlas(geometry, atlas, name, options) {
const manifest = manifestOf(atlas);
canonicalAtlasMetadataJsonV1(options);
- if (!options || typeof options !== "object" || Array.isArray(options) || Object.keys(options).some((k) => !["inputOrigin", "mode"].includes(k)) || !["top-left", "bottom-left"].includes(options.inputOrigin) || !["content-boundary", "texel-center"].includes(options.mode))
+ if (!options || typeof options !== "object" || Array.isArray(options) || Object.keys(options).some((k) => !["inputOrigin", "mode", "axes"].includes(k)) || !["top-left", "bottom-left"].includes(options.inputOrigin) || !["content-boundary", "texel-center"].includes(options.mode))
atlasFailure("explicit inputOrigin and content-boundary/texel-center mode are required.");
+ if (options.axes !== undefined && !["uv", "u-only"].includes(options.axes))
+ atlasFailure("axes must be uv (default, both components) or u-only.");
+ const uOnly = options.axes === "u-only";
+ if (uOnly && options.inputOrigin !== "top-left")
+ atlasFailure("u-only requires inputOrigin top-left: V passes through unmapped, so a bottom-left flip would invert the gradient it carries.");
const region = manifest.regions.find((r) => r.name === name);
if (!region)
atlasFailure(`unknown named region ${String(name)}.`);
const { x, y, width: w, height: h } = region.content;
if (![x, y, w, h].every(Number.isSafeInteger) || x < 0 || y < 0 || w < 1 || h < 1 || x + w > manifest.width || y + h > manifest.height)
atlasFailure("invalid region content rectangle.");
+ if (uOnly && (y !== 0 || h !== manifest.height))
+ atlasFailure(`u-only requires a region spanning the full atlas height; ${name} covers rows ${y}..${y + h} of ${manifest.height}. Lay the atlas out as full-height columns with gutter 0.`);
const uv = geometry?.getAttribute?.("uv"), position = geometry?.getAttribute?.("position");
if (!position || !uv || uv.itemSize !== 2 || uv.count !== position.count || uv.count < 1 || uv.count > TEXTURE_ATLAS_LIMITS.uvVertices || uv.isInstancedBufferAttribute || uv.data?.isInstancedInterleavedBuffer)
atlasFailure("matching per-vertex UV0 and positions are required; per-instance UVs are unsupported.");
@@ -27587,9 +27602,9 @@ function remapUVToAtlas(geometry, atlas, name, options) {
const bottom = options.inputOrigin === "bottom-left";
const offset = [
(x + (center ? 0.5 : 0)) / manifest.width,
- (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / manifest.height
+ uOnly ? 0 : (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / manifest.height
];
- const scale = [su, bottom ? -sv : sv];
+ const scale = [su, uOnly ? 1 : bottom ? -sv : sv];
const output = remapUV(geometry, { scale, offset });
output.userData.kilnAtlasBinding = {
manifestHash: manifest.manifestHash,
@@ -27600,6 +27615,7 @@ function remapUVToAtlas(geometry, atlas, name, options) {
allocation: structuredClone(region.allocation),
inputOrigin: options.inputOrigin,
mode: options.mode,
+ ...uOnly ? { axes: "u-only" } : {},
scale,
offset
};
@@ -31167,12 +31183,13 @@ const mesh = new THREE.Mesh(unwrapped, bakedPbr);`
},
{
name: "remapUVToAtlas",
- signature: "remapUVToAtlas(geometry, atlasTextureOrManifest, regionName, { inputOrigin: 'top-left' | 'bottom-left', mode: 'content-boundary' | 'texel-center' })",
+ signature: "remapUVToAtlas(geometry, atlasTextureOrManifest, regionName, { inputOrigin: 'top-left' | 'bottom-left', mode: 'content-boundary' | 'texel-center', axes?: 'uv' | 'u-only' })",
returns: "THREE.BufferGeometry",
category: "uv",
description: "Maps existing unit UV0 into a named atlas content rectangle on an owned geometry clone, preserving topology and rich attributes.",
- example: "const card = remapUVToAtlas(planeGeo(1, 1), atlas, 'patch', { inputOrigin: 'bottom-left', mode: 'texel-center' });",
- promptNotes: "UV0 must be finite in [0,1], with two components per vertex. Content-boundary maps endpoints to content edges; texel-center maps endpoints to the first/last content texel centers. Explicitly identify the input UV origin; atlas image coordinates use top left and flipY=false. Geometry, normals, colors, skin weights, morph buffers, groups and source metadata are preserved independently. UV scale changes invalidate tangents; regenerate when needed. This helper does not project, unwrap, tile within a region or change material sampling."
+ example: `const card = remapUVToAtlas(planeGeo(1, 1), atlas, 'patch', { inputOrigin: 'bottom-left', mode: 'texel-center' });
+const blade = remapUVToAtlas(leafGeo, fernColumnAtlas, 'fern', { inputOrigin: 'top-left', mode: 'texel-center', axes: 'u-only' });`,
+ promptNotes: "UV0 must be finite in [0,1], with two components per vertex. Content-boundary maps endpoints to content edges; texel-center maps endpoints to the first/last content texel centers. Explicitly identify the input UV origin; atlas image coordinates use top left and flipY=false. Geometry, normals, colors, skin weights, morph buffers, groups and source metadata are preserved independently. UV scale changes invalidate tangents; regenerate when needed. The default axes 'uv' replaces both components, so it destroys a per-vertex gradient carried in V — a foliage wind sway weight read as uv-y is the known case, and the result still validates and renders. Pass axes 'u-only' for that: it rescales U into the named column and leaves V bit-for-bit, requiring inputOrigin 'top-left' and a region that spans the full atlas height (lay the sheet out as full-height species columns with gutter 0). This helper does not project, unwrap, tile within a region or change material sampling."
},
{
name: "normalMapFromHeight",
@@ -39932,7 +39949,7 @@ function inspectSceneStructure(root, opts = {}) {
names.push(`+${rest.length - names.length} more`);
entries.push(`+${rest.length} more floating: ${names.join(", ")} — the same fix applies: shift each onto its nearest sibling, or call snapTo(part, hostPart).`);
}
- warnings.push(`Floating parts (no mesh overlap with any sibling, 2cm tol): ${entries.join(" | ")}`);
+ warnings.push(`Floating parts (no mesh overlap with any sibling, 2cm tol): ${entries.join(" | ")} — Coverage: drawn meshes only, at 2cm. A smaller gap reads as contact and a primitive welded into another mesh is never seen, so a silent pass is not a fit audit; measure contacts in the destination.`);
}
if (supported.length > 0) {
const shown = supported.slice(0, FLOATER_NAMES_SHOWN);
@@ -48922,11 +48939,13 @@ var init_helper_contracts = __esm(() => {
axes: "Explicit top-left or bottom-left input origin; target follows top-left image coordinates.",
parameters: [
"Requires a compiled atlas texture or manifest and exact region name.",
- "inputOrigin and content-boundary/texel-center mode are both required; finite per-vertex UV0 only."
+ "inputOrigin and content-boundary/texel-center mode are both required; finite per-vertex UV0 only.",
+ "Optional axes selects which components the region owns: 'uv' (default) both, 'u-only' U alone. u-only requires inputOrigin top-left over a region spanning the full atlas height, and is rejected otherwise."
],
topology: ["Preserves vertices, indices, groups, draw range and morph correspondence."],
preservation: [
- "Owns output attributes and metadata; UV0 is replaced. Nonidentity scale drops stale tangents with a warning."
+ "Owns output attributes and metadata; UV0 is replaced. Nonidentity scale drops stale tangents with a warning.",
+ "Replacing V destroys any per-vertex gradient UV0 carries, such as a foliage wind sway weight read as uv-y: the asset still validates and renders. axes u-only passes V through bit-for-bit and rescales U into a full-height column instead."
],
semantics: [
"Records the named region and affine mapping without changing asset category, project membership or materials."
@@ -48936,8 +48955,14 @@ var init_helper_contracts = __esm(() => {
references: ["src/texture-atlas.ts", "src/uv-shapes.ts"],
tags: ["uv", "atlas", "ownership"],
aliases: ["named region UV mapping"],
- intents: ["bind existing UVs to a named atlas region"],
- limitations: ["Does not unwrap, project, resample or tile within a region."],
+ intents: [
+ "bind existing UVs to a named atlas region",
+ "put species in atlas columns while keeping a V gradient"
+ ],
+ limitations: [
+ "Does not unwrap, project, resample or tile within a region.",
+ "u-only needs a column layout authored for it: a packed sheet or a nonzero gutter insets the region vertically and is rejected rather than remapped."
+ ],
related: [
{ name: "textureAtlas", relation: "prerequisite" },
{ name: "projectUV", relation: "companion" }
diff --git a/dist/evaluator-worker.mjs b/dist/evaluator-worker.mjs
index eca09aee..60ef3a42 100644
--- a/dist/evaluator-worker.mjs
+++ b/dist/evaluator-worker.mjs
@@ -5070,13 +5070,18 @@ function lookup(table, id) {
fail2("unknown atlas reference.");
return found;
}
-function derivedBinding(p, regionName, origin, mode) {
+function derivedBinding(p, regionName, origin, mode, axes) {
if (!["top-left", "bottom-left"].includes(origin) || !["content-boundary", "texel-center"].includes(mode))
fail2("explicit binding origin/mode required.");
+ if (axes !== undefined && axes !== "u-only")
+ fail2("unsupported binding axes.");
+ const uOnly = axes === "u-only";
const r = p.manifest.regions.find((r) => r.name === regionName);
if (!r)
fail2("unknown named region.");
const { x, y, width: w, height: h } = r.content, center = mode === "texel-center", bottom = origin === "bottom-left";
+ if (uOnly && (origin !== "top-left" || y !== 0 || h !== p.manifest.height))
+ fail2("u-only binding requires a top-left origin over a full-height region.");
return {
manifestHash: p.manifest.manifestHash,
specHash: p.manifest.specHash,
@@ -5086,29 +5091,30 @@ function derivedBinding(p, regionName, origin, mode) {
allocation: structuredClone(r.allocation),
inputOrigin: origin,
mode,
+ ...uOnly ? { axes: "u-only" } : {},
scale: [
(w - (center ? 1 : 0)) / p.manifest.width,
- (bottom ? -1 : 1) * (h - (center ? 1 : 0)) / p.manifest.height
+ uOnly ? 1 : (bottom ? -1 : 1) * (h - (center ? 1 : 0)) / p.manifest.height
],
offset: [
(x + (center ? 0.5 : 0)) / p.manifest.width,
- (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / p.manifest.height
+ uOnly ? 0 : (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / p.manifest.height
]
};
}
function expandAtlasBinding(input, table) {
canonicalAtlasMetadataJsonV1(input);
- const r = closed(input, ["version", "atlasId", "region", "inputOrigin", "mode"]);
+ const r = closed(input, ["version", "atlasId", "region", "inputOrigin", "mode", "axes"]);
if (r["version"] !== ATLAS_PROVENANCE_VERSION)
fail2("unsupported binding version.");
- return derivedBinding(lookup(table, r["atlasId"]), r["region"], r["inputOrigin"], r["mode"]);
+ return derivedBinding(lookup(table, r["atlasId"]), r["region"], r["inputOrigin"], r["mode"], r["axes"]);
}
function readAtlasGeometryBinding(geometry, provenance) {
const stamp = field(geometry.userData, "kilnAtlasBinding");
if (stamp === undefined)
return;
canonicalAtlasMetadataJsonV1(stamp);
- const r = stamp, derived = derivedBinding(provenance, r["region"], r["inputOrigin"], r["mode"]);
+ const r = stamp, derived = derivedBinding(provenance, r["region"], r["inputOrigin"], r["mode"], r["axes"]);
if (canonicalAtlasMetadataJsonV1(stamp) !== canonicalAtlasMetadataJsonV1(derived))
fail2("named binding identity or remap formula mismatch.");
return {
@@ -5116,7 +5122,8 @@ function readAtlasGeometryBinding(geometry, provenance) {
atlasId: provenance.manifest.manifestHash,
region: r["region"],
inputOrigin: r["inputOrigin"],
- mode: r["mode"]
+ mode: r["mode"],
+ ...r["axes"] === undefined ? {} : { axes: r["axes"] }
};
}
function collectAtlasProvenance(root) {
@@ -5727,8 +5734,9 @@ function inspectAtlasScene(root) {
continue;
}
const center = binding.mode === "texel-center" ? 0.5 : 0;
+ const centerY = binding.axes === "u-only" ? 0 : center;
const minX = (region.content.x + center) / entry.p.manifest.width, maxX = (region.content.x + region.content.width - center) / entry.p.manifest.width;
- const minY = (region.content.y + center) / entry.p.manifest.height, maxY = (region.content.y + region.content.height - center) / entry.p.manifest.height;
+ const minY = (region.content.y + centerY) / entry.p.manifest.height, maxY = (region.content.y + region.content.height - centerY) / entry.p.manifest.height;
const tolerance = 4 * 2 ** -23;
let invalid = false;
const point = new THREE5.Vector2;
@@ -7223,7 +7231,7 @@ function inspectPartConnectivity(scene, supports) {
disposition: "observe",
dimension: "visualQuality",
profile: "geometry.partConnectivity",
- message: `${subject} separate from the largest component in the rest-pose bounding boxes of visible parts; the nearest box gap is ${group.gap.toFixed(3)} m. This may be intentional. Box adjacency is not physical attachment evidence.${lodNote}`,
+ message: `${subject} separate from the largest component in the rest-pose bounding boxes of visible parts; the nearest box gap is ${group.gap.toFixed(3)} m. This may be intentional. Box adjacency is not physical attachment evidence: a gap under ${CONNECTIVITY_TOLERANCE} m reads as contact, and primitives welded into one mesh form one box.${lodNote}`,
affected: { node: group.parts[0] },
measurement: {
name: "gapToMainComponent",
@@ -22797,14 +22805,21 @@ ${canonicalAtlasMetadataJsonV1(payload)}`)}` !== manifestHash)
function remapUVToAtlas(geometry, atlas, name, options) {
const manifest = manifestOf(atlas);
canonicalAtlasMetadataJsonV1(options);
- if (!options || typeof options !== "object" || Array.isArray(options) || Object.keys(options).some((k) => !["inputOrigin", "mode"].includes(k)) || !["top-left", "bottom-left"].includes(options.inputOrigin) || !["content-boundary", "texel-center"].includes(options.mode))
+ if (!options || typeof options !== "object" || Array.isArray(options) || Object.keys(options).some((k) => !["inputOrigin", "mode", "axes"].includes(k)) || !["top-left", "bottom-left"].includes(options.inputOrigin) || !["content-boundary", "texel-center"].includes(options.mode))
atlasFailure("explicit inputOrigin and content-boundary/texel-center mode are required.");
+ if (options.axes !== undefined && !["uv", "u-only"].includes(options.axes))
+ atlasFailure("axes must be uv (default, both components) or u-only.");
+ const uOnly = options.axes === "u-only";
+ if (uOnly && options.inputOrigin !== "top-left")
+ atlasFailure("u-only requires inputOrigin top-left: V passes through unmapped, so a bottom-left flip would invert the gradient it carries.");
const region = manifest.regions.find((r) => r.name === name);
if (!region)
atlasFailure(`unknown named region ${String(name)}.`);
const { x, y, width: w, height: h } = region.content;
if (![x, y, w, h].every(Number.isSafeInteger) || x < 0 || y < 0 || w < 1 || h < 1 || x + w > manifest.width || y + h > manifest.height)
atlasFailure("invalid region content rectangle.");
+ if (uOnly && (y !== 0 || h !== manifest.height))
+ atlasFailure(`u-only requires a region spanning the full atlas height; ${name} covers rows ${y}..${y + h} of ${manifest.height}. Lay the atlas out as full-height columns with gutter 0.`);
const uv = geometry?.getAttribute?.("uv"), position = geometry?.getAttribute?.("position");
if (!position || !uv || uv.itemSize !== 2 || uv.count !== position.count || uv.count < 1 || uv.count > TEXTURE_ATLAS_LIMITS.uvVertices || uv.isInstancedBufferAttribute || uv.data?.isInstancedInterleavedBuffer)
atlasFailure("matching per-vertex UV0 and positions are required; per-instance UVs are unsupported.");
@@ -22837,9 +22852,9 @@ function remapUVToAtlas(geometry, atlas, name, options) {
const bottom = options.inputOrigin === "bottom-left";
const offset = [
(x + (center ? 0.5 : 0)) / manifest.width,
- (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / manifest.height
+ uOnly ? 0 : (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / manifest.height
];
- const scale = [su, bottom ? -sv : sv];
+ const scale = [su, uOnly ? 1 : bottom ? -sv : sv];
const output = remapUV(geometry, { scale, offset });
output.userData.kilnAtlasBinding = {
manifestHash: manifest.manifestHash,
@@ -22850,6 +22865,7 @@ function remapUVToAtlas(geometry, atlas, name, options) {
allocation: structuredClone(region.allocation),
inputOrigin: options.inputOrigin,
mode: options.mode,
+ ...uOnly ? { axes: "u-only" } : {},
scale,
offset
};
@@ -28810,12 +28826,13 @@ const mesh = new THREE.Mesh(unwrapped, bakedPbr);`
},
{
name: "remapUVToAtlas",
- signature: "remapUVToAtlas(geometry, atlasTextureOrManifest, regionName, { inputOrigin: 'top-left' | 'bottom-left', mode: 'content-boundary' | 'texel-center' })",
+ signature: "remapUVToAtlas(geometry, atlasTextureOrManifest, regionName, { inputOrigin: 'top-left' | 'bottom-left', mode: 'content-boundary' | 'texel-center', axes?: 'uv' | 'u-only' })",
returns: "THREE.BufferGeometry",
category: "uv",
description: "Maps existing unit UV0 into a named atlas content rectangle on an owned geometry clone, preserving topology and rich attributes.",
- example: "const card = remapUVToAtlas(planeGeo(1, 1), atlas, 'patch', { inputOrigin: 'bottom-left', mode: 'texel-center' });",
- promptNotes: "UV0 must be finite in [0,1], with two components per vertex. Content-boundary maps endpoints to content edges; texel-center maps endpoints to the first/last content texel centers. Explicitly identify the input UV origin; atlas image coordinates use top left and flipY=false. Geometry, normals, colors, skin weights, morph buffers, groups and source metadata are preserved independently. UV scale changes invalidate tangents; regenerate when needed. This helper does not project, unwrap, tile within a region or change material sampling."
+ example: `const card = remapUVToAtlas(planeGeo(1, 1), atlas, 'patch', { inputOrigin: 'bottom-left', mode: 'texel-center' });
+const blade = remapUVToAtlas(leafGeo, fernColumnAtlas, 'fern', { inputOrigin: 'top-left', mode: 'texel-center', axes: 'u-only' });`,
+ promptNotes: "UV0 must be finite in [0,1], with two components per vertex. Content-boundary maps endpoints to content edges; texel-center maps endpoints to the first/last content texel centers. Explicitly identify the input UV origin; atlas image coordinates use top left and flipY=false. Geometry, normals, colors, skin weights, morph buffers, groups and source metadata are preserved independently. UV scale changes invalidate tangents; regenerate when needed. The default axes 'uv' replaces both components, so it destroys a per-vertex gradient carried in V — a foliage wind sway weight read as uv-y is the known case, and the result still validates and renders. Pass axes 'u-only' for that: it rescales U into the named column and leaves V bit-for-bit, requiring inputOrigin 'top-left' and a region that spans the full atlas height (lay the sheet out as full-height species columns with gutter 0). This helper does not project, unwrap, tile within a region or change material sampling."
},
{
name: "normalMapFromHeight",
@@ -35402,7 +35419,7 @@ function inspectSceneStructure(root, opts = {}) {
names.push(`+${rest.length - names.length} more`);
entries.push(`+${rest.length} more floating: ${names.join(", ")} — the same fix applies: shift each onto its nearest sibling, or call snapTo(part, hostPart).`);
}
- warnings.push(`Floating parts (no mesh overlap with any sibling, 2cm tol): ${entries.join(" | ")}`);
+ warnings.push(`Floating parts (no mesh overlap with any sibling, 2cm tol): ${entries.join(" | ")} — Coverage: drawn meshes only, at 2cm. A smaller gap reads as contact and a primitive welded into another mesh is never seen, so a silent pass is not a fit audit; measure contacts in the destination.`);
}
if (supported.length > 0) {
const shown = supported.slice(0, FLOATER_NAMES_SHOWN);
diff --git a/dist/mcp-engine.mjs b/dist/mcp-engine.mjs
index 8fa17ff1..df432498 100644
--- a/dist/mcp-engine.mjs
+++ b/dist/mcp-engine.mjs
@@ -9827,13 +9827,18 @@ function lookup(table, id) {
fail5("unknown atlas reference.");
return found;
}
-function derivedBinding(p, regionName, origin, mode) {
+function derivedBinding(p, regionName, origin, mode, axes) {
if (!["top-left", "bottom-left"].includes(origin) || !["content-boundary", "texel-center"].includes(mode))
fail5("explicit binding origin/mode required.");
+ if (axes !== undefined && axes !== "u-only")
+ fail5("unsupported binding axes.");
+ const uOnly = axes === "u-only";
const r = p.manifest.regions.find((r) => r.name === regionName);
if (!r)
fail5("unknown named region.");
const { x, y, width: w, height: h } = r.content, center = mode === "texel-center", bottom = origin === "bottom-left";
+ if (uOnly && (origin !== "top-left" || y !== 0 || h !== p.manifest.height))
+ fail5("u-only binding requires a top-left origin over a full-height region.");
return {
manifestHash: p.manifest.manifestHash,
specHash: p.manifest.specHash,
@@ -9843,29 +9848,30 @@ function derivedBinding(p, regionName, origin, mode) {
allocation: structuredClone(r.allocation),
inputOrigin: origin,
mode,
+ ...uOnly ? { axes: "u-only" } : {},
scale: [
(w - (center ? 1 : 0)) / p.manifest.width,
- (bottom ? -1 : 1) * (h - (center ? 1 : 0)) / p.manifest.height
+ uOnly ? 1 : (bottom ? -1 : 1) * (h - (center ? 1 : 0)) / p.manifest.height
],
offset: [
(x + (center ? 0.5 : 0)) / p.manifest.width,
- (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / p.manifest.height
+ uOnly ? 0 : (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / p.manifest.height
]
};
}
function expandAtlasBinding(input, table) {
canonicalAtlasMetadataJsonV1(input);
- const r = closed(input, ["version", "atlasId", "region", "inputOrigin", "mode"]);
+ const r = closed(input, ["version", "atlasId", "region", "inputOrigin", "mode", "axes"]);
if (r["version"] !== ATLAS_PROVENANCE_VERSION)
fail5("unsupported binding version.");
- return derivedBinding(lookup(table, r["atlasId"]), r["region"], r["inputOrigin"], r["mode"]);
+ return derivedBinding(lookup(table, r["atlasId"]), r["region"], r["inputOrigin"], r["mode"], r["axes"]);
}
function readAtlasGeometryBinding(geometry, provenance) {
const stamp = field(geometry.userData, "kilnAtlasBinding");
if (stamp === undefined)
return;
canonicalAtlasMetadataJsonV1(stamp);
- const r = stamp, derived = derivedBinding(provenance, r["region"], r["inputOrigin"], r["mode"]);
+ const r = stamp, derived = derivedBinding(provenance, r["region"], r["inputOrigin"], r["mode"], r["axes"]);
if (canonicalAtlasMetadataJsonV1(stamp) !== canonicalAtlasMetadataJsonV1(derived))
fail5("named binding identity or remap formula mismatch.");
return {
@@ -9873,7 +9879,8 @@ function readAtlasGeometryBinding(geometry, provenance) {
atlasId: provenance.manifest.manifestHash,
region: r["region"],
inputOrigin: r["inputOrigin"],
- mode: r["mode"]
+ mode: r["mode"],
+ ...r["axes"] === undefined ? {} : { axes: r["axes"] }
};
}
function collectAtlasProvenance(root) {
@@ -11674,8 +11681,9 @@ function inspectAtlasScene(root) {
continue;
}
const center = binding.mode === "texel-center" ? 0.5 : 0;
+ const centerY = binding.axes === "u-only" ? 0 : center;
const minX = (region.content.x + center) / entry.p.manifest.width, maxX = (region.content.x + region.content.width - center) / entry.p.manifest.width;
- const minY = (region.content.y + center) / entry.p.manifest.height, maxY = (region.content.y + region.content.height - center) / entry.p.manifest.height;
+ const minY = (region.content.y + centerY) / entry.p.manifest.height, maxY = (region.content.y + region.content.height - centerY) / entry.p.manifest.height;
const tolerance = 4 * 2 ** -23;
let invalid = false;
const point = new THREE11.Vector2;
@@ -18321,7 +18329,7 @@ function inspectPartConnectivity(scene, supports) {
disposition: "observe",
dimension: "visualQuality",
profile: "geometry.partConnectivity",
- message: `${subject} separate from the largest component in the rest-pose bounding boxes of visible parts; the nearest box gap is ${group.gap.toFixed(3)} m. This may be intentional. Box adjacency is not physical attachment evidence.${lodNote}`,
+ message: `${subject} separate from the largest component in the rest-pose bounding boxes of visible parts; the nearest box gap is ${group.gap.toFixed(3)} m. This may be intentional. Box adjacency is not physical attachment evidence: a gap under ${CONNECTIVITY_TOLERANCE} m reads as contact, and primitives welded into one mesh form one box.${lodNote}`,
affected: { node: group.parts[0] },
measurement: {
name: "gapToMainComponent",
@@ -28644,14 +28652,21 @@ ${canonicalAtlasMetadataJsonV1(payload)}`)}` !== manifestHash)
function remapUVToAtlas(geometry, atlas, name, options) {
const manifest = manifestOf(atlas);
canonicalAtlasMetadataJsonV1(options);
- if (!options || typeof options !== "object" || Array.isArray(options) || Object.keys(options).some((k) => !["inputOrigin", "mode"].includes(k)) || !["top-left", "bottom-left"].includes(options.inputOrigin) || !["content-boundary", "texel-center"].includes(options.mode))
+ if (!options || typeof options !== "object" || Array.isArray(options) || Object.keys(options).some((k) => !["inputOrigin", "mode", "axes"].includes(k)) || !["top-left", "bottom-left"].includes(options.inputOrigin) || !["content-boundary", "texel-center"].includes(options.mode))
atlasFailure("explicit inputOrigin and content-boundary/texel-center mode are required.");
+ if (options.axes !== undefined && !["uv", "u-only"].includes(options.axes))
+ atlasFailure("axes must be uv (default, both components) or u-only.");
+ const uOnly = options.axes === "u-only";
+ if (uOnly && options.inputOrigin !== "top-left")
+ atlasFailure("u-only requires inputOrigin top-left: V passes through unmapped, so a bottom-left flip would invert the gradient it carries.");
const region = manifest.regions.find((r) => r.name === name);
if (!region)
atlasFailure(`unknown named region ${String(name)}.`);
const { x, y, width: w, height: h } = region.content;
if (![x, y, w, h].every(Number.isSafeInteger) || x < 0 || y < 0 || w < 1 || h < 1 || x + w > manifest.width || y + h > manifest.height)
atlasFailure("invalid region content rectangle.");
+ if (uOnly && (y !== 0 || h !== manifest.height))
+ atlasFailure(`u-only requires a region spanning the full atlas height; ${name} covers rows ${y}..${y + h} of ${manifest.height}. Lay the atlas out as full-height columns with gutter 0.`);
const uv = geometry?.getAttribute?.("uv"), position = geometry?.getAttribute?.("position");
if (!position || !uv || uv.itemSize !== 2 || uv.count !== position.count || uv.count < 1 || uv.count > TEXTURE_ATLAS_LIMITS.uvVertices || uv.isInstancedBufferAttribute || uv.data?.isInstancedInterleavedBuffer)
atlasFailure("matching per-vertex UV0 and positions are required; per-instance UVs are unsupported.");
@@ -28684,9 +28699,9 @@ function remapUVToAtlas(geometry, atlas, name, options) {
const bottom = options.inputOrigin === "bottom-left";
const offset = [
(x + (center ? 0.5 : 0)) / manifest.width,
- (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / manifest.height
+ uOnly ? 0 : (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / manifest.height
];
- const scale = [su, bottom ? -sv : sv];
+ const scale = [su, uOnly ? 1 : bottom ? -sv : sv];
const output = remapUV(geometry, { scale, offset });
output.userData.kilnAtlasBinding = {
manifestHash: manifest.manifestHash,
@@ -28697,6 +28712,7 @@ function remapUVToAtlas(geometry, atlas, name, options) {
allocation: structuredClone(region.allocation),
inputOrigin: options.inputOrigin,
mode: options.mode,
+ ...uOnly ? { axes: "u-only" } : {},
scale,
offset
};
@@ -32250,12 +32266,13 @@ const mesh = new THREE.Mesh(unwrapped, bakedPbr);`
},
{
name: "remapUVToAtlas",
- signature: "remapUVToAtlas(geometry, atlasTextureOrManifest, regionName, { inputOrigin: 'top-left' | 'bottom-left', mode: 'content-boundary' | 'texel-center' })",
+ signature: "remapUVToAtlas(geometry, atlasTextureOrManifest, regionName, { inputOrigin: 'top-left' | 'bottom-left', mode: 'content-boundary' | 'texel-center', axes?: 'uv' | 'u-only' })",
returns: "THREE.BufferGeometry",
category: "uv",
description: "Maps existing unit UV0 into a named atlas content rectangle on an owned geometry clone, preserving topology and rich attributes.",
- example: "const card = remapUVToAtlas(planeGeo(1, 1), atlas, 'patch', { inputOrigin: 'bottom-left', mode: 'texel-center' });",
- promptNotes: "UV0 must be finite in [0,1], with two components per vertex. Content-boundary maps endpoints to content edges; texel-center maps endpoints to the first/last content texel centers. Explicitly identify the input UV origin; atlas image coordinates use top left and flipY=false. Geometry, normals, colors, skin weights, morph buffers, groups and source metadata are preserved independently. UV scale changes invalidate tangents; regenerate when needed. This helper does not project, unwrap, tile within a region or change material sampling."
+ example: `const card = remapUVToAtlas(planeGeo(1, 1), atlas, 'patch', { inputOrigin: 'bottom-left', mode: 'texel-center' });
+const blade = remapUVToAtlas(leafGeo, fernColumnAtlas, 'fern', { inputOrigin: 'top-left', mode: 'texel-center', axes: 'u-only' });`,
+ promptNotes: "UV0 must be finite in [0,1], with two components per vertex. Content-boundary maps endpoints to content edges; texel-center maps endpoints to the first/last content texel centers. Explicitly identify the input UV origin; atlas image coordinates use top left and flipY=false. Geometry, normals, colors, skin weights, morph buffers, groups and source metadata are preserved independently. UV scale changes invalidate tangents; regenerate when needed. The default axes 'uv' replaces both components, so it destroys a per-vertex gradient carried in V — a foliage wind sway weight read as uv-y is the known case, and the result still validates and renders. Pass axes 'u-only' for that: it rescales U into the named column and leaves V bit-for-bit, requiring inputOrigin 'top-left' and a region that spans the full atlas height (lay the sheet out as full-height species columns with gutter 0). This helper does not project, unwrap, tile within a region or change material sampling."
},
{
name: "normalMapFromHeight",
@@ -40091,7 +40108,7 @@ function inspectSceneStructure(root, opts = {}) {
names.push(`+${rest.length - names.length} more`);
entries.push(`+${rest.length} more floating: ${names.join(", ")} — the same fix applies: shift each onto its nearest sibling, or call snapTo(part, hostPart).`);
}
- warnings.push(`Floating parts (no mesh overlap with any sibling, 2cm tol): ${entries.join(" | ")}`);
+ warnings.push(`Floating parts (no mesh overlap with any sibling, 2cm tol): ${entries.join(" | ")} — Coverage: drawn meshes only, at 2cm. A smaller gap reads as contact and a primitive welded into another mesh is never seen, so a silent pass is not a fit audit; measure contacts in the destination.`);
}
if (supported.length > 0) {
const shown = supported.slice(0, FLOATER_NAMES_SHOWN);
@@ -49276,11 +49293,13 @@ define2("remapUVToAtlas", {
axes: "Explicit top-left or bottom-left input origin; target follows top-left image coordinates.",
parameters: [
"Requires a compiled atlas texture or manifest and exact region name.",
- "inputOrigin and content-boundary/texel-center mode are both required; finite per-vertex UV0 only."
+ "inputOrigin and content-boundary/texel-center mode are both required; finite per-vertex UV0 only.",
+ "Optional axes selects which components the region owns: 'uv' (default) both, 'u-only' U alone. u-only requires inputOrigin top-left over a region spanning the full atlas height, and is rejected otherwise."
],
topology: ["Preserves vertices, indices, groups, draw range and morph correspondence."],
preservation: [
- "Owns output attributes and metadata; UV0 is replaced. Nonidentity scale drops stale tangents with a warning."
+ "Owns output attributes and metadata; UV0 is replaced. Nonidentity scale drops stale tangents with a warning.",
+ "Replacing V destroys any per-vertex gradient UV0 carries, such as a foliage wind sway weight read as uv-y: the asset still validates and renders. axes u-only passes V through bit-for-bit and rescales U into a full-height column instead."
],
semantics: [
"Records the named region and affine mapping without changing asset category, project membership or materials."
@@ -49290,8 +49309,14 @@ define2("remapUVToAtlas", {
references: ["src/texture-atlas.ts", "src/uv-shapes.ts"],
tags: ["uv", "atlas", "ownership"],
aliases: ["named region UV mapping"],
- intents: ["bind existing UVs to a named atlas region"],
- limitations: ["Does not unwrap, project, resample or tile within a region."],
+ intents: [
+ "bind existing UVs to a named atlas region",
+ "put species in atlas columns while keeping a V gradient"
+ ],
+ limitations: [
+ "Does not unwrap, project, resample or tile within a region.",
+ "u-only needs a column layout authored for it: a packed sheet or a nonzero gutter insets the region vertically and is rejected rather than remapped."
+ ],
related: [
{ name: "textureAtlas", relation: "prerequisite" },
{ name: "projectUV", relation: "companion" }
diff --git a/docs/procedural-surfaces-v3.md b/docs/procedural-surfaces-v3.md
index 61af9c60..018d595c 100644
--- a/docs/procedural-surfaces-v3.md
+++ b/docs/procedural-surfaces-v3.md
@@ -291,6 +291,17 @@ morphs and skin data are retained according to the UV helper's contract. A
region binding describes that geometry's region; it does not infer independent
region assignments for material groups.
+The optional `axes` selects which components the region owns. The default `uv`
+replaces both, which destroys any per-vertex gradient UV0 carries in V — a
+foliage wind sway weight read as `uv-y` is the known case, and the asset still
+validates and renders. `u-only` rescales U into the named region and passes V
+through bit-for-bit; it requires `inputOrigin: 'top-left'` over a region
+spanning the full atlas height, so lay such a sheet out as full-height columns
+with explicit `content` rectangles and `gutter: 0`, and author each column so
+V=0 is its top row. A packed or vertically inset region is rejected rather than
+remapped. The binding records `axes` only for `u-only`, so existing bindings and
+exported extras are unchanged.
+
Saved atlas maps retain the canonical recipe, named-region/source manifest,
compiler identity, encoded-image hash, decoded pixel hash and exact source
revision pins. `kiln material export` includes the complete verified material
diff --git a/skills/kiln-author-asset/references/geometry-recipes.md b/skills/kiln-author-asset/references/geometry-recipes.md
index 3221b9a8..4cc8e7d8 100644
--- a/skills/kiln-author-asset/references/geometry-recipes.md
+++ b/skills/kiln-author-asset/references/geometry-recipes.md
@@ -292,6 +292,20 @@ material groups. For repeating grass or directional wood, preserve or project
UVs and tile a standalone texture instead of forcing every surface into an atlas.
Neither atlas remapping nor `autoUnwrap` creates painted detail.
+When UV0 carries a per-vertex gradient as well as a texture coordinate, the
+default remap replaces it and the asset still validates and renders. The known
+case is foliage wind: a runtime may read V as the sway weight, 0 at the anchored
+base to 1 at the free tip, so a packed region collapses the whole sway range into
+the region's share of the sheet height, and a `bottom-left` origin swaps base for
+tip. Confirm what the destination reads from UV0 before remapping. To keep such a
+gradient, lay the atlas out as full-height species columns with `gutter: 0` and
+explicit `content` rectangles, then pass
+`{inputOrigin:'top-left', mode:'texel-center', axes:'u-only'}`: U is rescaled
+into the column and inset to texel centers so one species cannot bleed into its
+neighbour, while V passes through unchanged. Author the column artwork so V=0 is
+its top row, since atlas and glTF image coordinates both start top left. A region
+that does not span the full atlas height is rejected rather than remapped.
+
For repeated boards or other directional surfaces, align UV length with the
physical grain direction and retain the chosen texel density. Repeating the same
narrow UV band can miss a texture's authored detail even when the map is bound.
diff --git a/skills/kiln-qa-asset/references/integration-checks.md b/skills/kiln-qa-asset/references/integration-checks.md
index 38ee2313..a2f6f812 100644
--- a/skills/kiln-qa-asset/references/integration-checks.md
+++ b/skills/kiln-qa-asset/references/integration-checks.md
@@ -75,6 +75,17 @@ Do not invent a universal performance cap. State the destination, tested conditi
## Functional fit
+Kiln's own structural checks — the floating-parts warning and the part-connectivity
+observation — read the bounding boxes of drawn meshes with a 2 cm adjacency
+tolerance. They report a part or subassembly detached from the body; they are not a
+fit audit. Two consequences bound what a clean pass means. A separation under the
+tolerance reads as contact, so a part standing a millimetre or two off its host is
+not reported. And one mesh is one box, so primitives merged into a single mesh —
+what per-material welding for draw-call reduction produces — are not compared with
+each other at any separation. Where millimetre contact is a requirement, measure it
+in the destination against the exported file, and run that audit before saving the
+revision rather than after.
+
For an enterable building or gate, test the intended actor through the exported
opening with collision enabled. Include thresholds, plinths, lintels, trim and
hinge travel. The open leaf and nominal wall dimensions do not prove passage.
diff --git a/src/__tests__/__snapshots__/prompt-api.test.ts.snap b/src/__tests__/__snapshots__/prompt-api.test.ts.snap
index ea2f9596..758be360 100644
--- a/src/__tests__/__snapshots__/prompt-api.test.ts.snap
+++ b/src/__tests__/__snapshots__/prompt-api.test.ts.snap
@@ -735,7 +735,7 @@ await autoUnwrap(geometry: BufferGeometry, opts?: { resolution?: 1024, padding?:
// geometry.
// e.g. const unwrapped = await autoUnwrap(someCsgResult, { resolution: 1024 }); const mesh =
// new THREE.Mesh(unwrapped, bakedPbr);
-remapUVToAtlas(geometry, atlasTextureOrManifest, regionName, { inputOrigin: 'top-left' | 'bottom-left', mode: 'content-boundary' | 'texel-center' })
+remapUVToAtlas(geometry, atlasTextureOrManifest, regionName, { inputOrigin: 'top-left' | 'bottom-left', mode: 'content-boundary' | 'texel-center', axes?: 'uv' | 'u-only' })
// Maps existing unit UV0 into a named atlas content rectangle on an owned geometry clone,
// preserving topology and rich attributes.
// NOTE: UV0 must be finite in [0,1], with two components per vertex. Content-boundary maps
@@ -743,10 +743,16 @@ remapUVToAtlas(geometry, atlasTextureOrManifest, regionName, { inputOrigin: 'top
// centers. Explicitly identify the input UV origin; atlas image coordinates use top left and
// flipY=false. Geometry, normals, colors, skin weights, morph buffers, groups and source
// metadata are preserved independently. UV scale changes invalidate tangents; regenerate when
- // needed. This helper does not project, unwrap, tile within a region or change material
- // sampling.
+ // needed. The default axes 'uv' replaces both components, so it destroys a per-vertex
+ // gradient carried in V — a foliage wind sway weight read as uv-y is the known case, and the
+ // result still validates and renders. Pass axes 'u-only' for that: it rescales U into the
+ // named column and leaves V bit-for-bit, requiring inputOrigin 'top-left' and a region that
+ // spans the full atlas height (lay the sheet out as full-height species columns with gutter
+ // 0). This helper does not project, unwrap, tile within a region or change material sampling.
// e.g. const card = remapUVToAtlas(planeGeo(1, 1), atlas, 'patch', { inputOrigin:
- // 'bottom-left', mode: 'texel-center' });
+ // 'bottom-left', mode: 'texel-center' }); const blade = remapUVToAtlas(leafGeo,
+ // fernColumnAtlas, 'fern', { inputOrigin: 'top-left', mode: 'texel-center', axes: 'u-only'
+ // });
// Textures (approved resource loading is async)
await loadApprovedTexture(resourceId)
diff --git a/src/__tests__/examples.test.ts b/src/__tests__/examples.test.ts
index 585325be..94bb7a03 100644
--- a/src/__tests__/examples.test.ts
+++ b/src/__tests__/examples.test.ts
@@ -58,7 +58,7 @@ const outcomes = new Map<string, Outcome>(
// Exact remaining advisory groups are still asserted, without a blanket filter.
const documentedAdvisories: Record<string, string[]> = {
'demo-floating-observatory': [
- 'Floating parts (no mesh overlap with any sibling, 2cm tol): Mesh_WaterfallSprayDroplet_3 — Fix: shift "Mesh_WaterfallSprayDroplet_3" by [0.000, 0.000, -0.024] toward "Mesh_ContinuousWaterCurtain", or call snapTo(part, hostPart) to do it automatically. | Mesh_WaterfallSprayDroplet_5 — Fix: shift "Mesh_WaterfallSprayDroplet_5" by [0.000, 0.000, -0.026] toward "Mesh_ContinuousWaterCurtain", or call snapTo(part, hostPart) to do it automatically. | Mesh_WaterfallSprayDroplet_9 — Fix: shift "Mesh_WaterfallSprayDroplet_9" by [0.000, 0.000, -0.046] toward "Mesh_ContinuousWaterCurtain", or call snapTo(part, hostPart) to do it automatically. | Mesh_WaterfallSprayDroplet_11 — Fix: shift "Mesh_WaterfallSprayDroplet_11" by [0.000, 0.000, -0.059] toward "Mesh_ContinuousWaterCurtain", or call snapTo(part, hostPart) to do it automatically.',
+ 'Floating parts (no mesh overlap with any sibling, 2cm tol): Mesh_WaterfallSprayDroplet_3 — Fix: shift "Mesh_WaterfallSprayDroplet_3" by [0.000, 0.000, -0.024] toward "Mesh_ContinuousWaterCurtain", or call snapTo(part, hostPart) to do it automatically. | Mesh_WaterfallSprayDroplet_5 — Fix: shift "Mesh_WaterfallSprayDroplet_5" by [0.000, 0.000, -0.026] toward "Mesh_ContinuousWaterCurtain", or call snapTo(part, hostPart) to do it automatically. | Mesh_WaterfallSprayDroplet_9 — Fix: shift "Mesh_WaterfallSprayDroplet_9" by [0.000, 0.000, -0.046] toward "Mesh_ContinuousWaterCurtain", or call snapTo(part, hostPart) to do it automatically. | Mesh_WaterfallSprayDroplet_11 — Fix: shift "Mesh_WaterfallSprayDroplet_11" by [0.000, 0.000, -0.059] toward "Mesh_ContinuousWaterCurtain", or call snapTo(part, hostPart) to do it automatically. — Coverage: drawn meshes only, at 2cm. A smaller gap reads as contact and a primitive welded into another mesh is never seen, so a silent pass is not a fit audit; measure contacts in the destination.',
],
};
diff --git a/src/__tests__/texture-atlas-uv-column.test.ts b/src/__tests__/texture-atlas-uv-column.test.ts
new file mode 100644
index 00000000..516e7f2c
--- /dev/null
+++ b/src/__tests__/texture-atlas-uv-column.test.ts
@@ -0,0 +1,326 @@
+/**
+ * Column-atlas UV remapping (#293).
+ *
+ * A foliage runtime carries the wind sway weight in UV0's V coordinate — the
+ * `uv-y` convention — so V is a per-vertex gradient from anchored base to free
+ * tip, not an atlas coordinate. The default `axes: 'uv'` remap replaces both
+ * components, which is correct for ordinary assets and destroys that gradient.
+ * `axes: 'u-only'` rescales U into a full-height species column and passes V
+ * through untouched.
+ */
+import { afterEach, expect, test } from 'bun:test';
+import * as THREE from 'three';
+import { remapUVToAtlas, textureAtlas } from '../texture-atlas';
+import { collectAtlasProvenance, expandAtlasBinding } from '../atlas-provenance';
+import { renderSceneToGLB } from '../render';
+import { loadGlbReviewScene } from '../views/glb';
+import { inspectAtlasScene } from '../qa/atlas';
+
+const previousQaMode = process.env['KILN_QA_MODE'];
+afterEach(() => {
+ if (previousQaMode === undefined) delete process.env['KILN_QA_MODE'];
+ else process.env['KILN_QA_MODE'] = previousQaMode;
+});
+
+const sampler = {
+ minFilter: 'linear',
+ magFilter: 'linear',
+ wrapS: 'clamp-to-edge',
+ wrapT: 'clamp-to-edge',
+};
+
+function leafSource(tint: number) {
+ return {
+ kind: 'procedural',
+ spec: {
+ schemaVersion: 3,
+ width: 32,
+ height: 32,
+ operations: [
+ {
+ op: 'paint',
+ shape: { kind: 'rectangle', x: 0, y: 0, width: 32, height: 32 },
+ rgba: [tint, 255, 0, 255],
+ },
+ ],
+ },
+ };
+}
+
+/** Three full-height species columns in a 96x32 sheet, no gutter. */
+const columnSpec = {
+ schemaVersion: 1,
+ width: 96,
+ height: 32,
+ usage: 'albedo',
+ sampler,
+ regions: [0, 1, 2].map((i) => ({
+ name: `species_${i}`,
+ content: { x: i * 32, y: 0, width: 32, height: 32 },
+ gutter: 0,
+ source: leafSource(10 * i),
+ })),
+};
+
+/** A packed sheet: MaxRects places each region with the default gutter of 2. */
+const packedSpec = {
+ schemaVersion: 1,
+ usage: 'albedo',
+ sampler,
+ pack: { edge: 1024 as const },
+ regions: [0, 1, 2].map((i) => ({ name: `species_${i}`, source: leafSource(10 * i) })),
+};
+
+/** One blade: V runs 0 at the anchored base to 1 at the free tip. */
+function blade(): THREE.BufferGeometry {
+ const geometry = new THREE.BufferGeometry();
+ geometry.setAttribute(
+ 'position',
+ new THREE.Float32BufferAttribute([-0.01, 0, 0, 0.01, 0, 0, -0.01, 1, 0, 0.01, 1, 0], 3),
+ );
+ geometry.setAttribute('uv', new THREE.Float32BufferAttribute([0, 0, 1, 0, 0, 1, 1, 1], 2));
+ geometry.setIndex([0, 1, 2, 2, 1, 3]);
+ return geometry;
+}
+
+const vs = (geometry: THREE.BufferGeometry) => {
+ const uv = geometry.getAttribute('uv');
+ return [uv.getY(0), uv.getY(1), uv.getY(2), uv.getY(3)];
+};
+const us = (geometry: THREE.BufferGeometry) => {
+ const uv = geometry.getAttribute('uv');
+ return [uv.getX(0), uv.getX(1), uv.getX(2), uv.getX(3)];
+};
+
+test('u-only rescales U into the column band and leaves the uv-y gradient exact', async () => {
+ const atlas = await textureAtlas(columnSpec);
+ const output = remapUVToAtlas(blade(), atlas, 'species_1', {
+ inputOrigin: 'top-left',
+ mode: 'content-boundary',
+ axes: 'u-only',
+ });
+ expect(us(output)).toEqual([1 / 3, 2 / 3, 1 / 3, 2 / 3].map(Math.fround));
+ expect(vs(output)).toEqual([0, 0, 1, 1]);
+});
+
+test('u-only insets U at texel centers while V stays exact', async () => {
+ const atlas = await textureAtlas(columnSpec);
+ const output = remapUVToAtlas(blade(), atlas, 'species_1', {
+ inputOrigin: 'top-left',
+ mode: 'texel-center',
+ axes: 'u-only',
+ });
+ // 32-texel column at x=32 in a 96-wide sheet: first/last texel centers.
+ expect(us(output)).toEqual([32.5 / 96, 63.5 / 96, 32.5 / 96, 63.5 / 96].map(Math.fround));
+ expect(vs(output)).toEqual([0, 0, 1, 1]);
+ // The same inset applied to V is what squeezes a sway gradient.
+ const both = remapUVToAtlas(blade(), atlas, 'species_1', {
+ inputOrigin: 'top-left',
+ mode: 'texel-center',
+ });
+ expect(vs(both)).not.toEqual([0, 0, 1, 1]);
+});
+
+test('u-only preserves every V value in a dense gradient bit-for-bit', async () => {
+ const atlas = await textureAtlas(columnSpec);
+ const geometry = new THREE.BufferGeometry();
+ const positions: number[] = [];
+ const uvs: number[] = [];
+ for (let i = 0; i < 64; i++) {
+ const v = i / 63;
+ positions.push(0, v, 0);
+ uvs.push(i % 2, v);
+ }
+ geometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
+ geometry.setAttribute('uv', new THREE.Float32BufferAttribute(uvs, 2));
+ const before = Float32Array.from(geometry.getAttribute('uv').array);
+ const output = remapUVToAtlas(geometry, atlas, 'species_2', {
+ inputOrigin: 'top-left',
+ mode: 'texel-center',
+ axes: 'u-only',
+ });
+ const after = output.getAttribute('uv');
+ for (let i = 0; i < 64; i++) expect(after.getY(i)).toBe(before[i * 2 + 1]!);
+});
+
+test('u-only rejects a region that does not span the full atlas height', async () => {
+ const atlas = await textureAtlas(packedSpec);
+ expect(() =>
+ remapUVToAtlas(blade(), atlas, 'species_1', {
+ inputOrigin: 'top-left',
+ mode: 'content-boundary',
+ axes: 'u-only',
+ }),
+ ).toThrow(/full atlas height/i);
+});
+
+test('u-only rejects a bottom-left input origin, which would invert base and tip', async () => {
+ const atlas = await textureAtlas(columnSpec);
+ expect(() =>
+ remapUVToAtlas(blade(), atlas, 'species_1', {
+ inputOrigin: 'bottom-left',
+ mode: 'content-boundary',
+ axes: 'u-only',
+ }),
+ ).toThrow(/top-left/i);
+});
+
+test('u-only rejects an unknown axes value', async () => {
+ const atlas = await textureAtlas(columnSpec);
+ expect(() =>
+ remapUVToAtlas(blade(), atlas, 'species_1', {
+ inputOrigin: 'top-left',
+ mode: 'content-boundary',
+ axes: 'v-only',
+ } as never),
+ ).toThrow();
+});
+
+test('u-only records axes in the binding and round-trips through provenance', async () => {
+ const atlas = await textureAtlas(columnSpec);
+ const output = remapUVToAtlas(blade(), atlas, 'species_1', {
+ inputOrigin: 'top-left',
+ mode: 'texel-center',
+ axes: 'u-only',
+ });
+ const binding = output.userData.kilnAtlasBinding;
+ expect(binding.axes).toBe('u-only');
+ expect(binding.scale).toEqual([31 / 96, 1]);
+ expect(binding.offset).toEqual([32.5 / 96, 0]);
+
+ const material = new THREE.MeshStandardMaterial({ map: atlas });
+ const mesh = new THREE.Mesh(output, material);
+ const root = new THREE.Group();
+ root.add(mesh);
+ const provenance = collectAtlasProvenance(root);
+ const compact = provenance.binding(output);
+ expect(compact?.axes).toBe('u-only');
+ expect(expandAtlasBinding(compact, provenance.table!)).toEqual(binding);
+});
+
+test('atlas QA accepts a u-only binding whose V spans the full column', async () => {
+ // texel-center insets U only, so the V domain this binding must satisfy is the
+ // content boundary, not the inset one.
+ const atlas = await textureAtlas(columnSpec);
+ for (const mode of ['content-boundary', 'texel-center'] as const) {
+ const geometry = remapUVToAtlas(blade(), atlas, 'species_1', {
+ inputOrigin: 'top-left',
+ mode,
+ axes: 'u-only',
+ });
+ const root = new THREE.Group();
+ root.add(new THREE.Mesh(geometry, new THREE.MeshStandardMaterial({ map: atlas })));
+ const inspection = inspectAtlasScene(root);
+ expect(inspection.findings.map((f) => f.code)).toEqual([]);
+ }
+});
+
+test('atlas QA still rejects a V gradient that escapes an inset region', async () => {
+ // The same pass-through V over a region that does not reach the sheet edges is
+ // out of domain; u-only rejects that layout, so only a hand-built UV gets here.
+ const inset = {
+ ...columnSpec,
+ regions: columnSpec.regions.map((r, i) => ({
+ ...r,
+ content: { ...r.content, y: 2, height: 28 },
+ source: {
+ kind: 'procedural',
+ spec: {
+ schemaVersion: 3,
+ width: 32,
+ height: 28,
+ operations: [
+ {
+ op: 'paint',
+ shape: { kind: 'rectangle', x: 0, y: 0, width: 32, height: 28 },
+ rgba: [10 * i, 255, 0, 255],
+ },
+ ],
+ },
+ },
+ })),
+ };
+ const atlas = await textureAtlas(inset);
+ const geometry = remapUVToAtlas(blade(), atlas, 'species_1', {
+ inputOrigin: 'top-left',
+ mode: 'content-boundary',
+ });
+ geometry.setAttribute('uv', new THREE.Float32BufferAttribute([0, 0, 1, 0, 0, 1, 1, 1], 2));
+ const root = new THREE.Group();
+ root.add(new THREE.Mesh(geometry, new THREE.MeshStandardMaterial({ map: atlas })));
+ expect(inspectAtlasScene(root).findings.map((f) => f.code)).toContain('ATLAS_UV_DOMAIN');
+});
+
+test('a u-only binding survives a GLB round trip with the gradient intact', async () => {
+ // This fixture is one blade, not a qualifiable asset; the binding is the subject.
+ process.env['KILN_QA_MODE'] = 'off';
+ const atlas = await textureAtlas(columnSpec);
+ const geometry = remapUVToAtlas(blade(), atlas, 'species_1', {
+ inputOrigin: 'top-left',
+ mode: 'texel-center',
+ axes: 'u-only',
+ });
+ const root = new THREE.Group();
+ root.add(new THREE.Mesh(geometry, new THREE.MeshStandardMaterial({ map: atlas })));
+ const exported = await renderSceneToGLB(root, { optimize: 'off' });
+ const restored = await loadGlbReviewScene(exported.bytes);
+ const meshes: THREE.Mesh[] = [];
+ restored.root.traverse((node) => {
+ if ((node as THREE.Mesh).isMesh) meshes.push(node as THREE.Mesh);
+ });
+ const reloaded = meshes[0]!.geometry;
+ expect(reloaded.userData.kilnAtlasBinding).toEqual(geometry.userData.kilnAtlasBinding);
+ expect(vs(reloaded)).toEqual([0, 0, 1, 1]);
+});
+
+test('the default axes value stays absent from the binding, so existing stamps are unchanged', async () => {
+ const atlas = await textureAtlas(columnSpec);
+ const output = remapUVToAtlas(blade(), atlas, 'species_1', {
+ inputOrigin: 'bottom-left',
+ mode: 'texel-center',
+ });
+ const binding = output.userData.kilnAtlasBinding;
+ expect('axes' in binding).toBe(false);
+
+ const explicit = remapUVToAtlas(blade(), atlas, 'species_1', {
+ inputOrigin: 'bottom-left',
+ mode: 'texel-center',
+ axes: 'uv',
+ });
+ expect(explicit.userData.kilnAtlasBinding).toEqual(binding);
+ expect(us(explicit)).toEqual(us(output));
+ expect(vs(explicit)).toEqual(vs(output));
+});
+
+/**
+ * Evidence for #293: what the default replacement does to a `uv-y` gradient.
+ * The full-height column case happens to survive, which is exactly why the
+ * blanket "UV0 is replaced" contract line misled an author into hand-rolling
+ * atlas UVs — the working configuration is indistinguishable from the broken
+ * ones without doing the arithmetic.
+ */
+test('default uv remapping destroys a uv-y gradient on a packed region', async () => {
+ const atlas = await textureAtlas(packedSpec);
+ const output = remapUVToAtlas(blade(), atlas, 'species_1', {
+ inputOrigin: 'top-left',
+ mode: 'content-boundary',
+ });
+ const gradient = vs(output);
+ expect(gradient[0]).toBeGreaterThan(0);
+ // 32 content texels in a 1024 sheet: the sway range collapses to ~3%.
+ expect(gradient[2]! - gradient[0]!).toBeCloseTo(32 / 1024, 6);
+});
+
+test('default uv remapping on a full-height column survives only by arithmetic', async () => {
+ const atlas = await textureAtlas(columnSpec);
+ const boundary = remapUVToAtlas(blade(), atlas, 'species_1', {
+ inputOrigin: 'top-left',
+ mode: 'content-boundary',
+ });
+ expect(vs(boundary)).toEqual([0, 0, 1, 1]);
+ const flipped = remapUVToAtlas(blade(), atlas, 'species_1', {
+ inputOrigin: 'bottom-left',
+ mode: 'content-boundary',
+ });
+ expect(vs(flipped)).toEqual([1, 1, 0, 0]);
+});
diff --git a/src/atlas-provenance.ts b/src/atlas-provenance.ts
index 6fee2680..d1e30d6c 100644
--- a/src/atlas-provenance.ts
+++ b/src/atlas-provenance.ts
@@ -49,6 +49,8 @@ export interface AtlasBindingV1 {
region: string;
inputOrigin: 'top-left' | 'bottom-left';
mode: 'content-boundary' | 'texel-center';
+ /** Present only for a u-only column binding; absent means both components. */
+ axes?: 'u-only';
}
function fail(message: string): never {
throw new TypeError(`atlas provenance: ${message}`);
@@ -139,17 +141,29 @@ function lookup(table: AtlasProvenanceTableV1, id: unknown): AtlasProvenanceV1 {
if (!found) fail('unknown atlas reference.');
return found;
}
-function derivedBinding(p: AtlasProvenanceV1, regionName: unknown, origin: unknown, mode: unknown) {
+function derivedBinding(
+ p: AtlasProvenanceV1,
+ regionName: unknown,
+ origin: unknown,
+ mode: unknown,
+ axes: unknown,
+) {
if (
!['top-left', 'bottom-left'].includes(origin as string) ||
!['content-boundary', 'texel-center'].includes(mode as string)
)
fail('explicit binding origin/mode required.');
+ if (axes !== undefined && axes !== 'u-only') fail('unsupported binding axes.');
+ const uOnly = axes === 'u-only';
const r = p.manifest.regions.find((r) => r.name === regionName);
if (!r) fail('unknown named region.');
const { x, y, width: w, height: h } = r.content,
center = mode === 'texel-center',
bottom = origin === 'bottom-left';
+ // Mirrors remapUVToAtlas: u-only passes V through, so it admits only a
+ // top-left origin over a region that spans the whole atlas height.
+ if (uOnly && (origin !== 'top-left' || y !== 0 || h !== p.manifest.height))
+ fail('u-only binding requires a top-left origin over a full-height region.');
return {
manifestHash: p.manifest.manifestHash,
specHash: p.manifest.specHash,
@@ -159,21 +173,28 @@ function derivedBinding(p: AtlasProvenanceV1, regionName: unknown, origin: unkno
allocation: structuredClone(r.allocation),
inputOrigin: origin,
mode,
+ ...(uOnly ? { axes: 'u-only' as const } : {}),
scale: [
(w - (center ? 1 : 0)) / p.manifest.width,
- ((bottom ? -1 : 1) * (h - (center ? 1 : 0))) / p.manifest.height,
+ uOnly ? 1 : ((bottom ? -1 : 1) * (h - (center ? 1 : 0))) / p.manifest.height,
],
offset: [
(x + (center ? 0.5 : 0)) / p.manifest.width,
- (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / p.manifest.height,
+ uOnly ? 0 : (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / p.manifest.height,
],
};
}
export function expandAtlasBinding(input: unknown, table: AtlasProvenanceTableV1) {
canonicalAtlasMetadataJsonV1(input);
- const r = closed(input, ['version', 'atlasId', 'region', 'inputOrigin', 'mode']);
+ const r = closed(input, ['version', 'atlasId', 'region', 'inputOrigin', 'mode', 'axes']);
if (r['version'] !== ATLAS_PROVENANCE_VERSION) fail('unsupported binding version.');
- return derivedBinding(lookup(table, r['atlasId']), r['region'], r['inputOrigin'], r['mode']);
+ return derivedBinding(
+ lookup(table, r['atlasId']),
+ r['region'],
+ r['inputOrigin'],
+ r['mode'],
+ r['axes'],
+ );
}
/** A geometry-wide stamp can be associated only with the exact primary atlas supplied here. */
export function readAtlasGeometryBinding(
@@ -184,7 +205,7 @@ export function readAtlasGeometryBinding(
if (stamp === undefined) return undefined;
canonicalAtlasMetadataJsonV1(stamp);
const r = stamp as Record<string, unknown>,
- derived = derivedBinding(provenance, r['region'], r['inputOrigin'], r['mode']);
+ derived = derivedBinding(provenance, r['region'], r['inputOrigin'], r['mode'], r['axes']);
if (canonicalAtlasMetadataJsonV1(stamp) !== canonicalAtlasMetadataJsonV1(derived))
fail('named binding identity or remap formula mismatch.');
return {
@@ -193,6 +214,7 @@ export function readAtlasGeometryBinding(
region: r['region'] as string,
inputOrigin: r['inputOrigin'] as AtlasBindingV1['inputOrigin'],
mode: r['mode'] as AtlasBindingV1['mode'],
+ ...(r['axes'] === undefined ? {} : { axes: r['axes'] as AtlasBindingV1['axes'] }),
};
}
export interface AtlasProvenanceCollection {
diff --git a/src/discovery/helper-contracts.ts b/src/discovery/helper-contracts.ts
index 85abe37a..65e21d64 100644
--- a/src/discovery/helper-contracts.ts
+++ b/src/discovery/helper-contracts.ts
@@ -2970,10 +2970,12 @@ define(
parameters: [
'Requires a compiled atlas texture or manifest and exact region name.',
'inputOrigin and content-boundary/texel-center mode are both required; finite per-vertex UV0 only.',
+ "Optional axes selects which components the region owns: 'uv' (default) both, 'u-only' U alone. u-only requires inputOrigin top-left over a region spanning the full atlas height, and is rejected otherwise.",
],
topology: ['Preserves vertices, indices, groups, draw range and morph correspondence.'],
preservation: [
'Owns output attributes and metadata; UV0 is replaced. Nonidentity scale drops stale tangents with a warning.',
+ 'Replacing V destroys any per-vertex gradient UV0 carries, such as a foliage wind sway weight read as uv-y: the asset still validates and renders. axes u-only passes V through bit-for-bit and rescales U into a full-height column instead.',
],
semantics: [
'Records the named region and affine mapping without changing asset category, project membership or materials.',
@@ -2984,8 +2986,14 @@ define(
references: ['src/texture-atlas.ts', 'src/uv-shapes.ts'],
tags: ['uv', 'atlas', 'ownership'],
aliases: ['named region UV mapping'],
- intents: ['bind existing UVs to a named atlas region'],
- limitations: ['Does not unwrap, project, resample or tile within a region.'],
+ intents: [
+ 'bind existing UVs to a named atlas region',
+ 'put species in atlas columns while keeping a V gradient',
+ ],
+ limitations: [
+ 'Does not unwrap, project, resample or tile within a region.',
+ 'u-only needs a column layout authored for it: a packed sheet or a nonzero gutter insets the region vertically and is rejected rather than remapped.',
+ ],
related: [
{ name: 'textureAtlas', relation: 'prerequisite' },
{ name: 'projectUV', relation: 'companion' },
diff --git a/src/discovery/helper-specs.ts b/src/discovery/helper-specs.ts
index 1ccc699d..807be2b5 100644
--- a/src/discovery/helper-specs.ts
+++ b/src/discovery/helper-specs.ts
@@ -1183,15 +1183,15 @@ const PRIMITIVES: HelperSpec[] = [
{
name: 'remapUVToAtlas',
signature:
- "remapUVToAtlas(geometry, atlasTextureOrManifest, regionName, { inputOrigin: 'top-left' | 'bottom-left', mode: 'content-boundary' | 'texel-center' })",
+ "remapUVToAtlas(geometry, atlasTextureOrManifest, regionName, { inputOrigin: 'top-left' | 'bottom-left', mode: 'content-boundary' | 'texel-center', axes?: 'uv' | 'u-only' })",
returns: 'THREE.BufferGeometry',
category: 'uv',
description:
'Maps existing unit UV0 into a named atlas content rectangle on an owned geometry clone, preserving topology and rich attributes.',
example:
- "const card = remapUVToAtlas(planeGeo(1, 1), atlas, 'patch', { inputOrigin: 'bottom-left', mode: 'texel-center' });",
+ "const card = remapUVToAtlas(planeGeo(1, 1), atlas, 'patch', { inputOrigin: 'bottom-left', mode: 'texel-center' });\nconst blade = remapUVToAtlas(leafGeo, fernColumnAtlas, 'fern', { inputOrigin: 'top-left', mode: 'texel-center', axes: 'u-only' });",
promptNotes:
- 'UV0 must be finite in [0,1], with two components per vertex. Content-boundary maps endpoints to content edges; texel-center maps endpoints to the first/last content texel centers. Explicitly identify the input UV origin; atlas image coordinates use top left and flipY=false. Geometry, normals, colors, skin weights, morph buffers, groups and source metadata are preserved independently. UV scale changes invalidate tangents; regenerate when needed. This helper does not project, unwrap, tile within a region or change material sampling.',
+ "UV0 must be finite in [0,1], with two components per vertex. Content-boundary maps endpoints to content edges; texel-center maps endpoints to the first/last content texel centers. Explicitly identify the input UV origin; atlas image coordinates use top left and flipY=false. Geometry, normals, colors, skin weights, morph buffers, groups and source metadata are preserved independently. UV scale changes invalidate tangents; regenerate when needed. The default axes 'uv' replaces both components, so it destroys a per-vertex gradient carried in V — a foliage wind sway weight read as uv-y is the known case, and the result still validates and renders. Pass axes 'u-only' for that: it rescales U into the named column and leaves V bit-for-bit, requiring inputOrigin 'top-left' and a region that spans the full atlas height (lay the sheet out as full-height species columns with gutter 0). This helper does not project, unwrap, tile within a region or change material sampling.",
},
{
name: 'normalMapFromHeight',
diff --git a/src/qa/atlas.ts b/src/qa/atlas.ts
index 7444c742..38df197b 100644
--- a/src/qa/atlas.ts
+++ b/src/qa/atlas.ts
@@ -490,10 +490,13 @@ export function inspectAtlasScene(root: unknown): AtlasStructuralInspectionV1 {
continue;
}
const center = binding.mode === 'texel-center' ? 0.5 : 0;
+ // u-only maps U alone, so only U carries the texel-center inset; V passes
+ // through over the whole content extent of a full-height region.
+ const centerY = binding.axes === 'u-only' ? 0 : center;
const minX = (region.content.x + center) / entry.p.manifest.width,
maxX = (region.content.x + region.content.width - center) / entry.p.manifest.width;
- const minY = (region.content.y + center) / entry.p.manifest.height,
- maxY = (region.content.y + region.content.height - center) / entry.p.manifest.height;
+ const minY = (region.content.y + centerY) / entry.p.manifest.height,
+ maxY = (region.content.y + region.content.height - centerY) / entry.p.manifest.height;
// Four Float32 ulps at the unit domain cover representable boundary roundoff.
const tolerance = 4 * 2 ** -23;
let invalid = false;
diff --git a/src/qa/part-connectivity.ts b/src/qa/part-connectivity.ts
index 666a1c86..932f590e 100644
--- a/src/qa/part-connectivity.ts
+++ b/src/qa/part-connectivity.ts
@@ -268,7 +268,7 @@ export function inspectPartConnectivity(
disposition: 'observe' as const,
dimension: 'visualQuality' as const,
profile: 'geometry.partConnectivity',
- message: `${subject} separate from the largest component in the rest-pose bounding boxes of visible parts; the nearest box gap is ${group.gap.toFixed(3)} m. This may be intentional. Box adjacency is not physical attachment evidence.${lodNote}`,
+ message: `${subject} separate from the largest component in the rest-pose bounding boxes of visible parts; the nearest box gap is ${group.gap.toFixed(3)} m. This may be intentional. Box adjacency is not physical attachment evidence: a gap under ${CONNECTIVITY_TOLERANCE} m reads as contact, and primitives welded into one mesh form one box.${lodNote}`,
affected: { node: group.parts[0]! },
measurement: {
name: 'gapToMainComponent',
diff --git a/src/qa/structural-coverage.test.ts b/src/qa/structural-coverage.test.ts
new file mode 100644
index 00000000..f0e4465e
--- /dev/null
+++ b/src/qa/structural-coverage.test.ts
@@ -0,0 +1,115 @@
+/**
+ * What the structural checks cover (#289).
+ *
+ * An M16A1 passed QA clean with a front sight post 2 mm off its A-frame and a
+ * magazine catch 0.85 mm off the receiver; the consuming game's own contact
+ * audit caught both. The reported suspicion was that per-material welding hid
+ * the detached primitive inside a mesh the checks treat as one part.
+ *
+ * Welding does hide a primitive, but it is not what hid these two. Both checks
+ * read bounding boxes with a 2 cm adjacency tolerance, so a sub-centimetre gap
+ * reads as contact whether or not the parts are welded. These tests pin both
+ * limits with the reported measurements, so neither can drift silently and
+ * neither gets mistaken for the other again.
+ */
+
+import { expect, test } from 'bun:test';
+import * as THREE from 'three';
+import { inspectSceneStructure } from '../render';
+import { analyzePartConnectivity, CONNECTIVITY_TOLERANCE } from './part-connectivity';
+
+function boxAt(name: string, size: [number, number, number], at: [number, number, number]) {
+ const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size));
+ mesh.name = name;
+ mesh.position.set(...at);
+ return mesh;
+}
+
+function sceneOf(...meshes: THREE.Object3D[]): THREE.Object3D {
+ const root = new THREE.Object3D();
+ root.name = 'Asset';
+ for (const mesh of meshes) root.add(mesh);
+ return root;
+}
+
+/** An A-frame with a sight post standing `gap` metres clear of its crown. */
+function sightPost(gap: number): THREE.Object3D {
+ return sceneOf(
+ boxAt('Mesh_a_frame', [0.1, 0.05, 0.05], [0, 0, 0]),
+ boxAt('Mesh_front_sight_post', [0.004, 0.02, 0.004], [0, 0.035 + gap, 0]),
+ );
+}
+
+/** The same two primitives merged into one BufferGeometry: what a per-material weld produces. */
+function weldedSightPost(gap: number): THREE.Object3D {
+ const frame = new THREE.BoxGeometry(0.1, 0.05, 0.05).toNonIndexed();
+ const post = new THREE.BoxGeometry(0.004, 0.02, 0.004).toNonIndexed();
+ post.translate(0, 0.035 + gap, 0);
+ const merged = new THREE.BufferGeometry();
+ for (const key of ['position', 'normal', 'uv'] as const) {
+ const a = frame.getAttribute(key) as THREE.BufferAttribute;
+ const b = post.getAttribute(key) as THREE.BufferAttribute;
+ const values = new Float32Array(a.array.length + b.array.length);
+ values.set(a.array as Float32Array, 0);
+ values.set(b.array as Float32Array, a.array.length);
+ merged.setAttribute(key, new THREE.BufferAttribute(values, a.itemSize));
+ }
+ const mesh = new THREE.Mesh(merged);
+ mesh.name = 'Mesh_receiver';
+ // A second mesh, so the pairwise check runs at all: it skips single-mesh scenes.
+ return sceneOf(mesh, boxAt('Mesh_barrel', [0.3, 0.02, 0.02], [0.2, 0, 0]));
+}
+
+const floatingWarnings = (root: THREE.Object3D) =>
+ inspectSceneStructure(root, { category: 'weapon' }).filter((w) => w.startsWith('Floating parts'));
+
+// -----------------------------------------------------------------------------
+// Limit 1 — the adjacency tolerance, which is what hid the reported defects
+// -----------------------------------------------------------------------------
+
+test('a gap below the 2 cm tolerance reads as contact even between separate meshes', () => {
+ // The two gaps reported in #289, as separate parts: no weld involved.
+ for (const gap of [0.002, 0.00085]) {
+ expect(floatingWarnings(sightPost(gap))).toEqual([]);
+ expect(analyzePartConnectivity(sightPost(gap)).groups).toEqual([]);
+ }
+});
+
+test('the warning fires once the gap clears the tolerance it states', () => {
+ expect(floatingWarnings(sightPost(CONNECTIVITY_TOLERANCE))).toEqual([]);
+ expect(analyzePartConnectivity(sightPost(CONNECTIVITY_TOLERANCE)).groups).toEqual([]);
+ const warnings = floatingWarnings(sightPost(0.025));
+ expect(warnings).toHaveLength(1);
+ expect(warnings[0]).toContain('Mesh_a_frame');
+ expect(analyzePartConnectivity(sightPost(0.025)).groups).toHaveLength(1);
+});
+
+// -----------------------------------------------------------------------------
+// Limit 2 — mesh granularity, real but not the cause here
+// -----------------------------------------------------------------------------
+
+test('a primitive welded into another mesh is invisible at any separation', () => {
+ // 20 cm is ten times the tolerance and still silent: one mesh is one box.
+ for (const gap of [0.002, 0.05, 0.2]) {
+ expect(floatingWarnings(weldedSightPost(gap))).toEqual([]);
+ expect(analyzePartConnectivity(weldedSightPost(gap)).groups).toEqual([]);
+ }
+ // Unwelded, the same 20 cm separation is reported.
+ expect(floatingWarnings(sightPost(0.2))).toHaveLength(1);
+});
+
+test('the connectivity report counts welded primitives as one analyzed part', () => {
+ const report = analyzePartConnectivity(weldedSightPost(0.2));
+ expect(report.partsAnalyzed).toBe(2);
+ expect(report.mainComponentSize).toBe(2);
+});
+
+// -----------------------------------------------------------------------------
+// What the author is told when the warning does fire
+// -----------------------------------------------------------------------------
+
+test('the floating-parts warning states what it does not cover', () => {
+ const warning = floatingWarnings(sightPost(0.05))[0]!;
+ expect(warning).toContain('2cm');
+ expect(warning).toMatch(/welded|within a mesh|one mesh/i);
+});
diff --git a/src/render.ts b/src/render.ts
index 27a3d1d3..f6695bf0 100644
--- a/src/render.ts
+++ b/src/render.ts
@@ -2999,7 +2999,7 @@ export function inspectSceneStructure(
);
}
warnings.push(
- `Floating parts (no mesh overlap with any sibling, 2cm tol): ${entries.join(' | ')}`,
+ `Floating parts (no mesh overlap with any sibling, 2cm tol): ${entries.join(' | ')} — Coverage: drawn meshes only, at 2cm. A smaller gap reads as contact and a primitive welded into another mesh is never seen, so a silent pass is not a fit audit; measure contacts in the destination.`,
);
}
if (supported.length > 0) {
diff --git a/src/texture-atlas.ts b/src/texture-atlas.ts
index 144f3e97..a45c1bfd 100644
--- a/src/texture-atlas.ts
+++ b/src/texture-atlas.ts
@@ -50,6 +50,13 @@ export async function textureAtlas(
export interface AtlasUVOptionsV1 {
inputOrigin: 'top-left' | 'bottom-left';
mode: 'content-boundary' | 'texel-center';
+ /**
+ * Which UV components the region mapping owns. Default `uv` replaces both.
+ * `u-only` rescales U into a full-height column and passes V through
+ * untouched, for a runtime that reads V as a per-vertex gradient rather than
+ * an atlas coordinate — the `uv-y` foliage wind weight is the known case.
+ */
+ axes?: 'uv' | 'u-only';
}
function manifestOf(atlas: THREE.Texture | TextureAtlasManifestV1): TextureAtlasManifestV1 {
const value = (atlas as THREE.Texture)?.isTexture
@@ -98,11 +105,18 @@ export function remapUVToAtlas(
!options ||
typeof options !== 'object' ||
Array.isArray(options) ||
- Object.keys(options).some((k) => !['inputOrigin', 'mode'].includes(k)) ||
+ Object.keys(options).some((k) => !['inputOrigin', 'mode', 'axes'].includes(k)) ||
!['top-left', 'bottom-left'].includes(options.inputOrigin) ||
!['content-boundary', 'texel-center'].includes(options.mode)
)
atlasFailure('explicit inputOrigin and content-boundary/texel-center mode are required.');
+ if (options.axes !== undefined && !['uv', 'u-only'].includes(options.axes))
+ atlasFailure('axes must be uv (default, both components) or u-only.');
+ const uOnly = options.axes === 'u-only';
+ if (uOnly && options.inputOrigin !== 'top-left')
+ atlasFailure(
+ 'u-only requires inputOrigin top-left: V passes through unmapped, so a bottom-left flip would invert the gradient it carries.',
+ );
const region = manifest.regions.find((r) => r.name === name);
if (!region) atlasFailure(`unknown named region ${String(name)}.`);
const { x, y, width: w, height: h } = region.content;
@@ -116,6 +130,12 @@ export function remapUVToAtlas(
y + h > manifest.height
)
atlasFailure('invalid region content rectangle.');
+ // Passing V through only addresses the region when the region is the whole
+ // column: a guttered or packed rectangle would sample outside it instead.
+ if (uOnly && (y !== 0 || h !== manifest.height))
+ atlasFailure(
+ `u-only requires a region spanning the full atlas height; ${name} covers rows ${y}..${y + h} of ${manifest.height}. Lay the atlas out as full-height columns with gutter 0.`,
+ );
const uv = geometry?.getAttribute?.('uv'),
position = geometry?.getAttribute?.('position');
if (
@@ -171,9 +191,9 @@ export function remapUVToAtlas(
const bottom = options.inputOrigin === 'bottom-left';
const offset: [number, number] = [
(x + (center ? 0.5 : 0)) / manifest.width,
- (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / manifest.height,
+ uOnly ? 0 : (y + (bottom ? h - (center ? 0.5 : 0) : center ? 0.5 : 0)) / manifest.height,
];
- const scale: [number, number] = [su, bottom ? -sv : sv];
+ const scale: [number, number] = [su, uOnly ? 1 : bottom ? -sv : sv];
const output = remapUV(geometry, { scale, offset });
output.userData.kilnAtlasBinding = {
manifestHash: manifest.manifestHash,
@@ -184,6 +204,9 @@ export function remapUVToAtlas(
allocation: structuredClone(region.allocation),
inputOrigin: options.inputOrigin,
mode: options.mode,
+ // Omitted for the default, so stamps and exported extras predating u-only
+ // stay byte-identical.
+ ...(uOnly ? { axes: 'u-only' as const } : {}),
scale,
offset,
};