Index of every page on this site: llms.txt
All skills
oahc09 avatar

/cocosair-gltf

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Load glTF/GLB models, extensions, decoder injection and instances. Use for Draco/meshopt/KTX2 deployment, GLTF_DECODER_MISSING, uncoded load errors or animation loops.

  • 10 files
  • 110.6 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-gltf

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesextensions-matrix.md

≈6.3k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Derived from src/air/assets/gltf/support.ts, src/air/assets/gltf/loader.ts, src/air/assets/gltf/extension-registry.ts, src/air/assets/gltf/material/transmission-capability.ts, src/air/assets/gltf/extensions/, src/air/assets/gltf/extensions/material/unlit.ts, src/air/assets/gltf/extensions/material/emissive-strength.ts, src/air/assets/gltf/extensions/material/ior.ts, src/air/assets/gltf/extensions/material/specular.ts, src/air/assets/gltf/extensions/material/clearcoat.ts, src/air/assets/gltf/extensions/material/anisotropy.ts, src/air/assets/gltf/extensions/material/iridescence.ts, src/air/assets/gltf/extensions/material/bump.ts, src/air/assets/gltf/extensions/material/transmission.ts, src/air/assets/gltf/extensions/material/volume.ts, src/air/assets/gltf/extensions/material/dispersion.ts, src/air/assets/gltf/extensions/texture/transform.ts, src/air/assets/gltf/extensions/texture/image-formats.ts, src/air/assets/gltf/extensions/texture/basisu.ts, src/air/assets/gltf/extensions/geometry/quantization.ts, src/air/assets/gltf/extensions/geometry/meshopt.ts, src/air/assets/gltf/extensions/geometry/draco.ts, src/air/assets/gltf/extensions/scene/lights.ts, src/air/assets/gltf/extensions/scene/instancing.ts, examples/gltf-catalog/capabilities.json, examples/gltf-meshopt/src/main.ts, docs/evidence/examples-verified.json, docs/gltf/gltf-extension-reference.md, docs/gltf/gltf-runtime.md, package.json (as of 2026-10-09).

The five statuses and what each one obliges

GLTFExtensionStatus = 'supported' | 'decoder-required' | 'device-dependent' | 'fallback' | 'unsupported' (src/air/assets/gltf/support.ts:2), reported as GLTFExtensionSupport { name; status; reason? } with exactly three fields, reason optional (src/air/assets/gltf/support.ts:4-8). A status is a per-parse, per-device value computed by the handler's optional support(), not a build-time constant. The three middle tiers map onto stable GLTFError codes when the extension is listed in extensionsRequired (src/air/assets/gltf/extension-registry.ts:55-59).

Status Emitted by Code when required Browser-proven?
supported every handler; also the unconditional default for a handler with no support() (src/air/assets/gltf/loader.ts:100, src/air/assets/gltf/extension-registry.ts:116) n/a yes, gltf-clearcoat binding (docs/evidence/examples-verified.json:16783-16785)
decoder-required meshopt when options.meshoptDecoder is absent (src/air/assets/gltf/extensions/geometry/meshopt.ts:107-109), draco (src/air/assets/gltf/extensions/geometry/draco.ts:64-66), basisu when options.ktx2Transcoder is absent (src/air/assets/gltf/extensions/texture/basisu.ts:33-37) GLTF_DECODER_MISSING (extension-registry.ts:56) yes, pre-injection only (docs/evidence/examples-verified.json:17138-17140, :18421-18423)
device-dependent webp/avif when the cached decode probe failed (src/air/assets/gltf/extensions/texture/image-formats.ts:71-73); transmission/volume/dispersion while transmissionPipelineAvailable() is false (src/air/assets/gltf/extensions/material/transmission.ts:21-23, src/air/assets/gltf/extensions/material/volume.ts:21-22, src/air/assets/gltf/extensions/material/dispersion.ts:21-22; the flag is renderer-set and read live, src/air/assets/gltf/material/transmission-capability.ts:17-29) GLTF_DEVICE_UNSUPPORTED (extension-registry.ts:57) reachable in code, but zero catalog entries and zero tracked evidence bindings
fallback nothing in the shipped handler set emits it GLTF_EXTENSION_UNSUPPORTED (extension-registry.ts:58) no; declared-only
unsupported nothing shipped emits it; reachable only via a user-registered factory or the empty KNOWN_UNIMPLEMENTED list (src/air/assets/gltf/loader.ts:49-51) ?? 'GLTF_EXTENSION_UNSUPPORTED' (extension-registry.ts:119) no; declared-only

The machine-readable catalog examples/gltf-catalog/capabilities.json (tracked in git, regenerated by npm run capabilities, package.json:77) contains 21 entries tallying 17 supported / 4 decoder-required and 17 browser-evidence / 4 smoke; it has no device-dependent, fallback or unsupported entry at all (examples/gltf-catalog/capabilities.json:15-352). Header: generatedAt 2026-10-03T08:31:32.278Z (:4), catalogRevision (:5), the five errorCodes (:8-14). Prose cross-checks: docs/gltf/gltf-extension-reference.md:8 (general contract), :25 (geometry compression, :33 meshopt dual-name, :39 draco), :49 (texture encoding, :51 webp/avif one factory, :57 basisu), :66 (scene, :68 lights, :75 instancing), :82 (materials), :107 (official comparison); docs/gltf/gltf-runtime.md:75 (support boundary table) defers the machine-readable matrix to the catalog (:89).

Reading getExtensionSupport()

src/air/assets/gltf/loader.ts:95-106 merges globalDefaults with instance options (:96), builds a throwaway probe context GLTFParserContext({ asset: { version: '2.0' } }, undefined, resolved) (:97), instantiates handlers in registration order (:99), and computes handler.support?.() ?? { name: handler.name, status: 'supported' }, stamping the handler name onto the result (:100-101). Consequences:

  • No support() means unconditional supported. KHR_materials_unlit (src/air/assets/gltf/extensions/material/unlit.ts:8, 13 lines, no support) and KHR_texture_transform (src/air/assets/gltf/extensions/texture/transform.ts:10, 20 lines, no support) are reported supported purely by this default.
  • KNOWN_UNIMPLEMENTED entries are appended only for names not already covered (src/air/assets/gltf/loader.ts:103-104); the array is empty (:49-51), so the returned list is exactly the 21 handler entries in registration order.
  • Status tracks the currently injected decoders: setDRACODecoder/setMeshoptDecoder/setKTX2Transcoder replace instance options (src/air/assets/gltf/loader.ts:82-90) and each decoder handler re-reads them when its support() runs - meshopt (src/air/assets/gltf/extensions/geometry/meshopt.ts:107) and basisu (src/air/assets/gltf/extensions/texture/basisu.ts:34) read context.options live, while draco snapshots const decoder = context.options.dracoDecoder at factory time (src/air/assets/gltf/extensions/geometry/draco.ts:61) and reports from that const (:64). Handlers are re-instantiated on every getExtensionSupport() call and on every parseAsync (src/air/assets/gltf/loader.ts:99, :127-128), so the snapshot is always taken from the options in force for that call and the three behave identically from a caller's point of view. The same loader reports decoder-required before injection and supported after; examples/gltf-meshopt/src/main.ts proves the flip by importing the shipped meshopt_decoder.mjs through a runtime-concatenated URL (:70-72), wiring createMeshoptDecoder + setMeshoptDecoder (:75-77), then asserting support?.().status === 'supported' for quantization, meshopt and draco handlers (:94-97). Its draco/KTX2 probes are explicit mocks that exercise factory construction and capability contracts, not real decodes (:80-88). The bare-loader teaching path observes the stable GLTF_DECODER_MISSING code (:159-171).

The 21 registrations

src/air/assets/gltf/loader.ts:54-75 registers 21 factories in this order; handler names come from the factory implementations. Factory paths are relative to src/air/assets/gltf/extensions/; catalog line ranges are in examples/gltf-catalog/capabilities.json (format: status / verified.level, officialComparison model and comparison).

# Handler name Factory support() Catalog officialComparison
1 KHR_materials_unlit material/unlit.ts:8 none (default) :16-28 supported / browser-evidence -
2 KHR_texture_transform texture/transform.ts:10 none (default) :29-41 supported / browser-evidence -
3 KHR_mesh_quantization geometry/quantization.ts:56-57 static supported :42-54 supported / smoke (smoke-11) -
4 EXT_meshopt_compression geometry/meshopt.ts:14,103-109 decoder-gated :55-67 decoder-required / smoke -
5 KHR_meshopt_compression geometry/meshopt.ts:13,103-109 decoder-gated :68-80 decoder-required / smoke -
6 KHR_draco_mesh_compression geometry/draco.ts:13,63-66 decoder-gated :81-93 decoder-required / smoke -
7 KHR_materials_emissive_strength material/emissive-strength.ts:12,15 static :94-110 supported / browser-evidence MaterialEmissiveStrengthTest, verified-official-load
8 KHR_materials_ior material/ior.ts:12,15 static :111-127 supported / browser-evidence MaterialIORTest, verified-official-load
9 KHR_materials_specular material/specular.ts:17,20 static :128-144 supported / browser-evidence MaterialsVariantsShading, verified-official-load
10 KHR_materials_clearcoat material/clearcoat.ts:14,24 static :145-161 supported / browser-evidence MaterialsVariantsShading, verified-official-load
11 KHR_materials_anisotropy material/anisotropy.ts:14,17 static :162-178 supported / browser-evidence AnisotropyPlane, verified-official-load
12 KHR_materials_iridescence material/iridescence.ts:15,19 static :179-195 supported / browser-evidence IridescenceDielectricSpheres (available), verified-official-load
13 EXT_materials_bump material/bump.ts:16,19 static, though the shader itself falls back to flat normal on unsupported devices (bump.ts:6) :196-208 supported / browser-evidence -
14 KHR_materials_transmission material/transmission.ts:16,19-23 pipeline-gated :209-227 supported / browser-evidence TransmissionTest (available), verified-official-load
15 KHR_materials_volume material/volume.ts:15,21-22 pipeline-gated :228-246 supported / browser-evidence Volka, verified-official-load
16 KHR_materials_dispersion material/dispersion.ts:15,21-22 pipeline-gated :247-265 supported / browser-evidence DispersionTest (available), verified-official-load
17 KHR_texture_basisu texture/basisu.ts:30,33-37 transcoder-gated :266-282 decoder-required / browser-evidence (smoke-14, gltf-ktx2-browser.js) KhronosBasisuSampleSet, pending-T8
18 EXT_texture_webp texture/image-formats.ts:62-74 async decode probe; optimistic supported until the probe resolves false (:66-74) :283-299 supported / browser-evidence WebpTest, pending-T8
19 EXT_texture_avif texture/image-formats.ts:62-74 (same factory, second name) same probe :300-316 supported / browser-evidence AvifTest, pending-T8
20 KHR_lights_punctual scene/lights.ts:28,79-80 static :317-333 supported / browser-evidence LightingPunctualLights, pending-T8
21 EXT_mesh_gpu_instancing scene/instancing.ts:18,62-64 static, with reason correctness path: expansion to shared-asset child nodes (same reason in the catalog) :334-350 supported / browser-evidence SimpleInstancing (available), pending-T8

Rows 4/5 and 18/19 are one factory function registered twice under different extension names. Each call returns a distinct closure (meshopt.ts:103-104, image-formats.ts:62-63), so the identity-based register dedupe keeps both (src/air/assets/gltf/extension-registry.ts:68-71) and the distinct names pass the duplicate-name guard. The four smoke-level catalog entries are rows 3, 4, 5 and 6; KHR_texture_basisu is decoder-required yet browser-evidence level.

required versus optional in validateRequired

src/air/assets/gltf/extension-registry.ts:104-124 iterates the union of extensionsUsed and extensionsRequired (:106-107):

Case Behavior
unknown extension, listed in extensionsRequired throws GLTFError('GLTF_EXTENSION_UNSUPPORTED', 'unsupported required extension: NAME', NAME) (:111-112)
unknown extension, optional silent continue: no warning, no report entry (:114). Warnings for optional fallbacks come from handlers during load instead (e.g. draco.ts:83)
handler without support() defaults to supported and passes (:116-117)
non-supported status, required throws with SUPPORT_CODES[status] ?? 'GLTF_EXTENSION_UNSUPPORTED' and message required extension NAME: STATUS (REASON) (:118-121)
non-supported status, optional context.warn(...) with the same text; load continues on the core fallback (:122)

Registration order is hook order

The class doc states registration order defines hook execution order (src/air/assets/gltf/extension-registry.ts:61-64); createHandlers instantiates factories in array order (:80-89). A duplicate handler name throws a plain Error [glTF] duplicate extension handler: NAME (:86), and a missing dependency throws a plain Error [glTF] extension NAME requires unregistered extension DEP (:93). Neither is a GLTFError, so error.code branching does not catch them. register is idempotent by factory identity (:68-71); unregister returns a boolean telling whether anything was removed (:72-76).

What the browser evidence actually covers

docs/evidence/examples-verified.json (file-level measuredAt 2026-10-04T05:52:32.537Z at :2, top-level candidateFingerprint 2f089f6ce25eaccd at :7; each results[] entry carries its own fingerprint and no measuredAt) contains exactly three capability-status validator bindings in the whole file, all in gltf examples: gltf-clearcoat asserts KHR_materials_clearcoat=supported (:16783-16785), gltf-draco asserts KHR_draco_mesh_compression=decoder-required (:17138-17140), and gltf-meshopt asserts both meshopt names decoder-required (:18421-18423). GLTFLoader.getExtensionSupport itself has exactly one apiProof binding, in gltf-draco: executed twice, bound to capability-status (:16884-16898). Eighteen gltf-touching example ids are result: PASS (id lines :1902, :14927, :15100, :15289, :15966, :16399, :16426, :16810, :17177, :17814, :18470, :18961, :19546, :28771, :59940, :63167, :76397, :78841): animated-character-showcase, glass-refraction, gltf-animation-contract, gltf-asset-readonly, gltf-basic, gltf-catalog, gltf-clearcoat, gltf-draco, gltf-loader-registry, gltf-meshopt, gltf-morph, gltf-skin, gltf-viewer, material-transparent, mesh-multi-material, model-character-interaction, product-viewer, runtime-asset-release.

Real meshopt decode from the shipped .mjs decoder is browser-proven by gltf-meshopt: assets/meshopt-khr.glb=1728B proven fetched (docs/evidence/examples-verified.json:18408), visible-frame litRatio=0.1606 (:18428), resource-released held=3 leaked=0 (:18433). gltf-draco has no visible-frame validator (its list ends at capability-status, entry :16810, list end :17142): what is proven there is the pre-injection refusal state, not a decode. docs/gltf/gltf-runtime.md:91-93 records the same boundary: the bundled Draco entry is Node/CommonJS form and the draco verification level is smoke, so bundled-browser draco decode is not accepted.

What is not proven

Only supported and decoder-required (pre-injection) have browser-evidence bindings. device-dependent is reachable at runtime from four support() implementations behind five extension names - webp and avif from one factory, plus transmission, volume and dispersion - but appears in no catalog entry and no tracked evidence. fallback and unsupported are never emitted by any shipped handler: they exist only in the type union and the code map. Draco browser decode and KTX2 transcode are not bound to any capability-status evidence entry; the catalog's browser-evidence level for KHR_texture_basisu (examples/gltf-catalog/capabilities.json:266-282) cites the gltf-ktx2-browser.js script, not docs/evidence/examples-verified.json, and the meshopt example's draco/KTX2 probes are mocks by their own comment (examples/gltf-meshopt/src/main.ts:80-81). EXT_materials_bump reports supported unconditionally even where its shader degrades to a flat normal (bump.ts:6, :19), so that degradation is invisible to getExtensionSupport(). The catalog is a snapshot generated 2026-10-03, one day before the evidence measuredAt; regenerate it with npm run capabilities (package.json:77) before treating either as current for a new build.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at ed38648. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
layer
subsystem
All 1 allowed tools
Read Edit Write Bash
Other metadata
compatibility
Cocos AIR source checkout or installed cocosair.js package. Browser rendering requires WebGL 2; source tooling requires Node.js >=18. Use the host-provided tools and user-authorized workspace.
when_to_use
[
  "load a glTF or GLB from URL or bytes",
  "compressed model will not load",
  "which glTF extensions are supported",
  "instance animation will not loop",
  "destroying a model leaves GPU resources"
]
owns
[
  "gltf",
  "glb",
  "decoder-injection",
  "extension-support",
  "model-instancing",
  "gltf-errors"
]
not_for
[
  "generic asset caching -> cocosair-assets",
  "edit imported shared materials -> cocosair-materials-effects",
  "skeleton bind poses or morph weights -> cocosair-skinning-morph"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "加载 glTF 和 GLB,配置解码器、扩展、进度、实例和错误处理。用于模型加载、压缩资源部署和加载器能力诊断。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-gltf