Skip to content

BUILD-2045: Apply sparse glTF attributes and indices when assembling GLB parts - #6208

Merged
shayderrr merged 4 commits into
ItsNotRexed:mainfrom
Razdva122:codex/ped-sparse-accessors
Nov 23, 2026
Merged

shayderrr merged 4 commits into
ItsNotRexed:mainfrom
Razdva122:codex/ped-sparse-accessors

Conversation

@Razdva122

@Razdva122 Razdva122 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Repacked the Khronos SimpleSparseAccessor example into a GLB with its original buffer bytes. Compared each indexed output position with the independently decoded expected coordinates. Main got 9 of 36 vertex references wrong; the PR matched all 36.
  • Synthetic CLI round trips cover all three sparse-index widths with interleaved and zero-initialized bases. Tests also cover normalized colors and skin weights, sparse triangle indices, invalid layouts and indices, and the implicit-row budget. Invalid input is checked through the command's error path.
  • Across the ped assembly, GLB and skinned-GLB suites, 177 tests passed and two skipped (Windows sharing semantics and optional NumPy).

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.

enzo-billis and others added 3 commits November 23, 2026 13:44
…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>
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

A valid zero-initialized COLOR_0 accessor still prevents assembly at 9e8424ca. The test triangle has sparse positions and indices. When two color overrides explicitly contain zeros, the command exits 0. Removing only those redundant overrides preserves every decoded color, but the command exits 2 with accessors[1] has no bufferView.

The glTF specification initializes an accessor to zero when it has no buffer view. Sparse overrides are optional. Both color encodings should produce three (0, 0, 0, 0) rows. glTF 2.0 §5.1.1

Run this from the repository root with py -3.14 -I -:

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 7f17f7f6 rejects both encodings. This PR adds support for the explicit-zero case. Please allow the omitted override table on the same zero-base path and charge these rows to the existing per-file limit. On Windows the assembly, GLB and skinned-GLB suites ran 178 tests: 177 passed and one skipped.

AI-assisted.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 --check clean.
  • 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_accessor already zero-fills, so this is a one-line relaxation in _check_glb_document plus charging the rows to MAX_IMPLICIT_SPARSE_ROWS. Not a regression from main (which raises KeyError), but it belongs with this sparse work.
  • 6199 touches the same read_glb_parts region; 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 shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@shayderrr

Copy link
Copy Markdown
Collaborator

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

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.

5 participants