Skip to content

feat(core,lang): add glTF COLOR_0 vertex color export and vcolor baking op - #213

Open
morelandjo wants to merge 1 commit into
wrong-nebula:mainfrom
morelandjo:feat/gltf-vertex-colors
Open

morelandjo wants to merge 1 commit into
wrong-nebula:mainfrom
morelandjo:feat/gltf-vertex-colors

Conversation

@morelandjo

Copy link
Copy Markdown

Closes #65

Summary

Adds zero-dependency per-face-corner vertex colors (Face::colors), glTF 2.0 COLOR_0 export & import, and a composable vcolor (alias bake_color) op supporting solid face painting, height/axis gradients, directional shading, stepped toon ramps, and underside/base ambient occlusion darkening.

# Height gradient + 3-step toon ramp + base/underside AO baked into COLOR_0
rock = sphere(1.0)
  | vcolor(low=(0.2, 0.25, 0.3), high=(0.7, 0.75, 0.8), sun=(0.4, -0.5, 0.8), steps=3, ao=0.3)

# Selective face painting + layered multiply pass
prop = box(1, 1, 1)
  | vcolor((0.9, 0.4, 0.2), faces="top")
  | vcolor(sun=(0.3, -0.4, 0.8), ambient=0.4, multiply=true)

What Changed

  • forma-core:
    • mesh.rs: Added #[serde(default)] pub colors: Vec<[f32; 4]> (display sRGB RGBA, empty = 0 bytes when unused) to Face, preserved through triangulated(), flip_winding(), and dedup_face_verts().
    • ops.rs: Added VColorParams and op_vcolor supporting solid color, low/high gradient along axis (x/y/z), directional sun + shadow/ambient, stepped toon steps (>= 2), underside/base ao, FaceSelector filtering, and multiply layering.
    • export.rs: Exported COLOR_0 in both single-part and multi-part scene .glb as compact normalized UNSIGNED_SHORT VEC4 (componentType: 5123, "normalized": true, 8 bytes/vertex, sRGB → linear per glTF 2.0 spec). Omitted completely on uncolored meshes (zero bloat). Included quantized color in the vertex weld key.
    • import.rs: Added COLOR_0 import (FLOAT, UNSIGNED_SHORT, UNSIGNED_BYTE; VEC3 and VEC4) converting linear → sRGB back into Face::colors.
    • instancing.rs: Included Face::colors in compute_mesh_signature so differently vertex-colored meshes do not falsely deduplicate.
    • render.rs: Modulated software PNG preview face colors by Face::colors when present.
  • forma-lang:
    • pipeline.rs, lib.rs: Wired vcolor(...) / bake_color(...) pipe & functional op; advertised in the existing progressive uv topic (uv(unwrap,decimate,vcolor), +1 token in SPEC_PIPE, zero new dependencies).
  • Tests:

Verification

  • cargo clippy --locked --workspace --all-targets --all-features -- -D warnings — clean
  • 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 — all passed
  • npm run build:wasm && npm test — 5/5 passed
  • python3 scripts/check_local_paths.py — clean

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: glTF vertex color (COLOR_0) export / baked directional shading

1 participant