Skip to content

fix(Gltf): load non-indexed static GLB primitives - #9

Merged
ifBars merged 3 commits into
stablefrom
fix/glb-static-primitives
Sep 28, 2026
Merged

ifBars merged 3 commits into
stablefrom
fix/glb-static-primitives

Conversation

@ifBars

@ifBars ifBars commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

GltfLoader.LoadGlb(byte[], Shader?) currently drops non-indexed primitives and leaves the first primitive using a fallback material with a null material slot. This change imports consecutive vertex triples, preserves submesh/material offsets, and fixes fallback assignment without changing the public API.

Related fixes stay in the active mesh-loading path:

  • Skip points/lines/strips/fans with a warning instead of treating every mode as triangle lists.
  • Reject empty/incomplete/out-of-range triangle indices, missing POSITION, and mismatched decoded attribute counts before appending geometry.
  • Align missing optional attributes across combined primitives. Honor the existing normal/tangent generation switches and retain authored normals/tangents on other primitives.
  • Add an opt-in MelonLoader regression project and exclude its outputs from the main project's candidate assembly search (otherwise a previous Mono test build can contaminate IL2CPP reference resolution).
  • Replace overbroad documentation claims with a concrete static-GLB export/validation profile.

Validation

Backend Build Real Unity runtime
Mono Pass, netstandard2.1 library and test mod 22/22 cases pass in isolated Schedule I 0.4.6f13 Alternate / Unity 2022.3.62f2 / MelonLoader 0.7.3
IL2CPP Pass, net6.0 library and test mod 22/22 cases pass in isolated Schedule I 0.4.6f13 / Unity 2022.3.62f2 / MelonLoader 0.7.0

The initial 17-case suite reproduced the same 13 failures on both runtimes before the implementation change; the existing three unsigned index formats and disabled-generation case passed. The final suite adds material ordering, attribute preservation in both orders, malformed attribute/missing position rejection, and rendering.

Build commands:

dotnet build Tests/Gltf/S1MAPI.Gltf.RuntimeTests.csproj -c Mono -p:UserLibsPath= -p:GeneratePackageOnBuild=false
dotnet build Tests/Gltf/S1MAPI.Gltf.RuntimeTests.csproj -c Il2cpp -p:UserLibsPath= -p:GeneratePackageOnBuild=false

Fresh library builds reported only two existing CS8618 warnings in Building/InteriorNavigatorCore.cs; no new build warnings. Runtime tests go through the public byte-array loader, use synthetic self-contained GLBs, and need only Menu. Both attached 256x256 captures were visually inspected; the render test also checks a minimum red-pixel count. Rendering uses URP Unlit to isolate geometry visibility/winding. Test setup and cleanup are documented in Tests/Gltf/README.md.

DocFX completed with 0 errors and 4 warnings: unresolved 0Harmony/Newtonsoft metadata references, the existing README LICENSE link, and an existing building-guide bookmark. No warnings reference the changed guide or test instructions.

Hosted documentation build: passed (run 36235979636); deployment was correctly skipped for the PR. CodeRabbit review was still pending when this implementation pass finished.

Compatibility boundaries

Supported static profile: dense float32 POSITION/NORMAL/TEXCOORD_0/TANGENT in buffer 0; unsigned 8/16/32-bit indices or consecutive non-indexed TRIANGLES; combined primitives and material slots. Missing UVs are zero-filled where necessary; Unity generates missing normals/tangents by default, preserving authored data. Export authored shading attributes for controlled results.

Still unsupported or unreliable: sparse/normalized integer/quantized vertex attributes, Draco/meshopt, geometry in additional buffers, COLOR_0, extra UV sets/texture transforms, external images, KTX2/Basis, skinning and morph rendering. Only triangle mode is supported. The active path imports all nodes instead of selecting one scene. Required extensions are not comprehensively validated. Animation parsing exists but is not certified here; ImportSkins, ImportBlendShapes, and ReadableMeshes are not wired into the active path. Some malformed accessor/buffer references can still throw, and non-null results can be partial/empty. This is not full glTF compliance or an input-validation API.

The guide documents embedded PNG/JPEG/material implementation paths separately from the tested geometry profile. Texture/PBR fidelity, arbitrary exporter output, mirrored matrix decomposition, loaded-save product/furniture behavior, and networking were not tested.

No release/version change. No proprietary game files, copied installs, binary fixtures, or smoke logs are committed. The original checkout's unrelated TerrainClearer.cs edit remains untouched.

Mono: public GLB loader renders the synthetic non-indexed triangle

IL2CPP: public GLB loader renders the synthetic non-indexed triangle

  • Added support for non-indexed triangle primitives in GltfLoader.LoadGlb(byte[], Shader?).
  • Preserved vertex, submesh, and material alignment across combined primitives. Added handling for unsupported primitive modes, malformed geometry, missing attributes, and optional normal and tangent generation.
  • Added opt-in Mono and IL2CPP runtime regression tests. The PR author reports 22/22 test cases passed on both backends, with successful builds.
  • Updated GLB loading documentation and excluded test project files from the main project’s default item inclusion.
  • No public API change is reported.
Author Lines added Lines removed
ifBars 439 87

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 93593a29-fc59-481f-a452-eef27c58d565

📥 Commits

Reviewing files that changed from the base of the PR and between 52ac066 and 505930e.

📒 Files selected for processing (7)
  • Gltf/GltfImporter.cs
  • Gltf/Processing/GltfMeshProcessor.cs
  • S1MAPI.csproj
  • Tests/Gltf/GltfRuntimeTests.cs
  • Tests/Gltf/README.md
  • Tests/Gltf/S1MAPI.Gltf.RuntimeTests.csproj
  • docs/gltf-loading.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The GLB mesh processor now validates primitives, assembles accepted geometry, and can generate missing normals and tangents. A Unity runtime test project exercises importer behavior in Mono and IL2CPP. The loading guide documents the importer’s compatibility profile and usage constraints.

Changes

GLTF import behavior

Layer / File(s) Summary
Primitive validation and mesh assembly
Gltf/Processing/GltfMeshProcessor.cs, Gltf/GltfImporter.cs
The importer passes its options to the mesh processor. The processor rejects unsupported or invalid primitives, handles non-indexed geometry, aligns missing attributes, and optionally generates normals and tangents.
Unity runtime regression tests
Tests/Gltf/*, S1MAPI.csproj
A MelonLoader runtime test mod builds synthetic GLBs, checks importer results, and runs a render probe. The runtime project and instructions cover Mono and IL2CPP; the main project excludes Tests/** from default item inclusion.
Importer compatibility and usage guidance
docs/gltf-loading.md
The guide describes the public loading entry point, coordinate conversion, resource cleanup, supported GLB features, validation limits, and test coverage.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 50593

No identified issue blocks merging this GLB importer change after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 50593

The loader accepts more valid model data, but the review found no new privilege or trust-boundary bypass. Handling of every malformed model remains uncertain.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — A caller able to supply GLB bytes can now cause valid non-indexed triangles to become Unity mesh geometry. The reviewed path shows no new credential, tenant, or service authority.

Trust Boundaries and Controls

  • observed — Topology, index, POSITION, and decoded attribute-count checks precede appending a primitive, but accessor decoding occurs before some of those checks. The public loader does not show an exception boundary around the import handoff.

Resilience and Maintainability Implications

  • inferred — Malformed accessor references may still interrupt an import before primitive-level rejection. The readers and public loading path also existed before this change; the reviewed comparison does not establish this as a new PR security condition.

Hardening Proposals

  • proposed — If callers load untrusted models, validate accessor and buffer bounds before decoding and establish a controlled failure outcome for import exceptions.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 50.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 3 files. (4 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is 49 characters, concise, and directly describes the main change: loading non-indexed static GLB primitives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 27.27% which is insufficient. The required threshold is 50.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 3 files. (4 skipped: 4 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks each triangle’s place,
Then fills blank normals with care and grace.
A tiny GLB takes its flight,
The render probe glows red and bright.
PASS marks hop into the file,
While bunny ears perk up and smile.

Comment @coderabbitai help to get the list of available commands.

@ifBars
ifBars merged commit c1825f0 into stable Sep 28, 2026
3 checks passed
@ifBars
ifBars deleted the fix/glb-static-primitives branch September 28, 2026 13:01
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.

1 participant