Repository navigation
BUILD-2045: Apply sparse glTF attributes and indices when assembling GLB parts - #6208
Conversation
…ceback read_glb_parts walked the GLB document without checking it, so a material or pbrMetallicRoughness that is not an object (AttributeError), an accessor past the BIN chunk (struct.error), an index out of range or a JSON chunk that does not parse ended the CLI in a Python traceback. _check_glb_document now checks, before the part loop, what the reader dereferences: the tables it indexes, the accessors its primitives name (type, and that their bytes are inside the BIN chunk) and the material fields it converts. Inputs the reader tolerated stay tolerated. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…read as before Review of ItsNotRexed#5999 (kaiffeetasse): - A node name that is not a string (5, 3.5, true, a non-empty list), or the mesh's when the node has none, reached classify_part_role and raised TypeError. _check_glb_document now refuses it where the reader would use it; a falsy name still falls back, and a mesh name the node overrides is left alone. - count, byteOffset and byteStride go through int() in the reader, so 3.0 read as 3 on main. The check took only ints and turned those into errors; it now takes whole floats too. Fractions, strings and bools stay errors. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
A valid zero-initialized The glTF specification initializes an accessor to zero when it has no buffer view. Sparse overrides are optional. Both color encodings should produce three Run this from the repository root with import json, runpy, subprocess, sys, tempfile
from pathlib import Path
t = runpy.run_path("tests/test_ped_assemble_sparse_glb.py")
doc, data = t["triangle"]()
color = doc["accessors"][1]
view = doc["bufferViews"][color["sparse"]["values"]["bufferView"]]
at = view["byteOffset"]
data[at:at+8] = bytes(8)
with tempfile.TemporaryDirectory() as tmp:
src, out = Path(tmp)/"in.glb", Path(tmp)/"out.glb"
for explicit in (True, False):
if not explicit:
del color["sparse"]
src.write_bytes(t["container"](json.dumps(doc).encode(), bytes(data)))
r = subprocess.run([sys.executable, "-I", "tools/ped_assemble.py", "assemble", str(src), "-o", str(out), "--no-standing-offset"], capture_output=True,text=True)
print(explicit, r.returncode, r.stderr.strip())The dependency head AI-assisted. |
Kam471
left a comment
There was a problem hiding this comment.
Reviewed 9e8424ca769067a97ac871eec848790bb3018a68 on Windows 11 (MSVC 19.44, Python 3.13), synthetic GLBs only.
python -I -m pytest tests/test_ped_assemble_sparse_glb.py tests/test_ped_assemble_malformed_glb.py -q-> 14 passed, 90 subtests.python -I -m pytest tests/test_ped_assemble.py tests/test_ped_catalogues.py -q-> 23 passed.git diff --checkclean.- Reproduced the zero-base case: an accessor with no bufferView and no sparse is valid glTF (all zeros), but still exits 2 with
accessors[1] has no bufferView._read_glb_accessoralready zero-fills, so this is a one-line relaxation in_check_glb_documentplus charging the rows toMAX_IMPLICIT_SPARSE_ROWS. Not a regression from main (which raises KeyError), but it belongs with this sparse work. - 6199 touches the same
read_glb_partsregion; both will need a small rebase, no logical conflict seen.
Verdict: mergeable, no blocking finding. First-frame impact: offline asset assembly only, not the runtime loader.
shayderrr
left a comment
There was a problem hiding this comment.
Summary: tools/ped_assemble.py gains _check_glb_document() validation of tables, accessors, bufferView regions, sparse index ordering and material fields, and rewrites _read_glb_accessor() to read strided dense bases or an implicit zero base with MAX_IMPLICIT_ACCESSOR_ROWS = 1_000_000, then apply tightly packed sparse replacements to positions, indices and other attributes. read_glb_parts() now reports malformed JSON chunks as PedAssembleError; two new test files cover sparse GLB round trips and malformed inputs.
Why merge: Valid glTF sparse overrides are no longer silently discarded, and malformed GLBs fail with one diagnostic instead of a traceback.
Verdict: Approve
|
Summary: Why merge: Valid glTF sparse overrides are no longer silently discarded, and malformed GLBs fail with one diagnostic instead of a traceback. Verdict: Approve |
Claimed as BUILD-2045 on the coordination board.
Depends on: #5999. The first two commits are from the input-validation PR. The sparse-import commit is the incremental diff to review.
What changed
The GLB importer previously read only the dense base of a sparse accessor. A valid POSITION override disappeared even when the assembly command returned success. With no base bufferView, the importer could not read the model at all.
The reader now applies the tightly packed replacements to the strided dense base or to an implicit zero base. The same rule applies to primitive indices, positions and the other mesh attributes the importer consumes. It checks replacement ranges, ordering and buffer boundaries before reading them. A single imported GLB may expand up to one million implicit rows in total across its used attributes and mesh instances. Larger models can supply the base explicitly. glTF 2.0 sparse accessors
Verification
Review follow-up
Review of the implicit zero base identified the valid case where both the base bufferView and sparse overrides are absent. The follow-up commit accepts it under the same row budget. Explicit and implicit zero colors now yield byte-identical assembled GLBs. A required Draco payload receives an unsupported-format error, and optional Draco inputs can use their ordinary glTF fallback.
I reran the public Khronos example on the new head. All 36 indexed positions matched. An additional Linux x86-64 container run (amd64 emulation on Apple Silicon) on Python 3.12.16 passed 69 ped assembly and skinning tests, with one optional NumPy test skipped.
AI-assisted. Tested on an Apple M3 Pro with macOS 15.6.1 and Python 3.14.2. The checks used the CPU, synthetic inputs and the public Khronos sample. No game data was used or included.