Skip to content

feat(uv): add box_uv(tile=) world-scale box projection for tiling materials - #134

Open
farisbasha wants to merge 1 commit into
wrong-nebula:mainfrom
farisbasha:feat-box-uv
Open

farisbasha wants to merge 1 commit into
wrong-nebula:mainfrom
farisbasha:feat-box-uv

Conversation

@farisbasha

Copy link
Copy Markdown
Contributor

Adds an explicit world-scale box projection op for tiling materials, as asked in #67.

Problem

unwrap() packs LSCM islands into [0,1]^2, which is right for unique baked textures but breaks repeating materials (brick, concrete, planks): texel density changes from face to face. On main, a .glb only gets TEXCOORD_0 when faces carry UVs, so without unwrap() there are no UVs to tile with at all.

What it adds

wall = box(4, 0.2, 3) | box_uv(tile=1)   # 1 texture repeat per metre on every face
units("mm")
slab = box(2000, 2000, 100) | box_uv(2)  # 1 repeat per 2 m; the scene unit is converted
  • box_uv(tile=1): each face is projected onto the plane of its dominant normal axis (triplanar box mapping), and one UV unit spans tile metres. Model units are converted with the scene unit, so mm/inch scenes get the same repeat size as metre scenes.
  • Opposite faces are not mirrored (UV winding stays counter-clockwise on every outward face).
  • The UVs are written to faces[].uvs, so .glb export carries them like unwrap() UVs.
  • tile must be a positive finite number; the op is listed in the uv spec topic and in the GBNF pipe-op rule.

Core function: forma_core::uv::unwrap_box(mesh, meters_per_unit, tile).

Tests

  • crates/forma-lang/tests/box_uv.rs (4 tests): per-face UV extent equals the face size in metres, tile and mm scenes give the same repeat, no mirrored faces, bad tile values rejected.
  • crates/forma-core/tests/box_uv_export.rs (2 tests): the GLB TEXCOORD_0 data spans [-1,1]^2 for a 2 m box with tile=1; bad inputs to unwrap_box are rejected.
  • CI command cargo test --locked --release -p forma-core -p forma-lang -p forma-cli -p forma-mcp -p forma-server -- --skip test_10000_fuzzed_modeling_operations_zero_crashes_zero_nans: 163 passed, 0 failed (Linux). I did not run the npm/WASM smoke tests.

Closes #67

This PR was prepared with AI assistance (Claude).

Projects each face onto its dominant axis plane so one UV unit spans
`tile` metres on every face (scene unit converted), without mirroring
opposite faces. UVs go to faces[].uvs, so .glb export carries them.

Closes wrong-nebula#67
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: world-scale box/triplanar UV projection for tiling PBR materials

1 participant