Flag reader placeholder maps instead of guessing them by size - #49
Merged
Conversation
writeGLB skipped any material map that was 1x1 or smaller, on the theory that such images are the 1x1 fills the reader substitutes for empty texture slots. That guess is wrong for a genuinely 1x1 texture the caller supplied, which was silently dropped instead of written -- breaking the external and KTX2 image-mode tests, and CI on master since e33ca75. The reader is the only thing that creates those fills, so let it say so: each Material texture slot gains a `*Placeholder` flag, set where the fill is made, and the writer consults the flag rather than the dimensions. The flag defaults to false, so hand-built materials keep writing their textures no matter how small they are. Adds a test that a material read with no textures round-trips through writeGLB without gaining any, which e33ca75 changed behavior for but never covered. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
CI has been red on
mastersince e33ca75 (Aug 11), on both Linux and Windows:tests.nim(358):fileExists(externalImagePath)test_ktx2.nim(221):fileExists(externalKtx2ImagePath)e33ca75 taught
writeGLBto skip the 1x1 fill images the reader substitutes for empty texture slots, so exported files don't gain meaningless textures. It detected them by size:A 1x1 image is indistinguishable from a real texture that small, and both failing tests supply exactly that — a genuine 1x1 base color the caller built. Their textures were silently dropped, so no sidecar image was ever written. The tests predate e33ca75; the commit changed writer behavior without running them.
Fix
The reader is the only thing that creates these fills, so it records the fact rather than leaving the writer to infer it. Each
Materialtexture slot gains a*Placeholderflag, set at the five sites indefaultRuntimeMaterial()and the five per-primitiveelsebranches where the fill is made. The writer consults the flag:The flag defaults to
false, so hand-built materials keep writing their textures no matter how small — which is what makes the two failing tests pass — while reader placeholders stay out of the output.hasNormalTextureis left as an additional gate on the normal slot; it is a pre-existing, separately-consumed field (all four renderer backends read it) and out of scope here.Tests
Adds "placeholder maps are not written back" to
tests/tests.nim: reads a glTF whose material declares no textures, asserts all five slots come back flagged, writes it out withiwmExternal, and asserts no sidecar image appears next to the.glb. This covers the behavior e33ca75 introduced but never tested. Verified it fails without the fix:Verification
Every step of
.github/workflows/build.ymlrun locally on macOS, all green:nim check src/gltf.nimnim check tests/draco/tests.nimnim r -d:release tests/backend_shaders.nimnim r -d:release tests/draco/tests.nimnim r -d:release tests/tests.nim— including both previously-failing suitesnim r -d:release tests/test_ktx2.nimnim c --compileOnly -d:release -d:shadyBinaryShaders -d:useOpenGLfortests/sample_assets.nimandtools/gltf_viewer.nimOne caveat on local runs: the
EXT_texture_webptest needs apixienew enough to have the pure-Nim WebP decoder (treeform/pixie#581). Against an olderpixieit fails withUnsupported image file formaton a VP8L payload, unrelated to this change; CI installs a currentpixieand decodes it fine.🤖 Generated with Claude Code