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.

referencescontracts.md

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

Derived from the cocosair-gltf skill and its canonical docs/source pointers; reorganized on 2026-10-11. Source annotations below identify repository inputs, not files guaranteed to ship to npm consumers.

Contracts

  • Two entry points, one pipeline. loadAsync(url) (src/air/assets/gltf/loader.ts:108-113) resolves the URL against document.baseURI (:39-41), derives ext from /\.(gltf|glb)$/i on the query-stripped path and falls back to .glb when there is no suffix (:36-38, :112), then hands off to assetManager.loadRemote with the resolved options under the gltf key. parseAsync (:115-184) is the same work in memory with no cache and an abort signal. It validates every accessor up front (:136) before any image decode or GPU allocation, snapshots handler data at resolveData (:138) before releaseDecodedData() drops the buffers (:181), and on any failure runs context.dispose(); asset.destroy(); throw (:183) so nothing half-built survives. Importing the glTF module registers all of this automatically: src/air/assets/gltf/index.ts:25-26 calls registerGLTFLoader() at import time, and that function is idempotent through a module flag (src/air/assets/gltf/loader.ts:187-189). For both .gltf and .glb it installs a fetch downloader honoring options.header and withCredentials (:191-196), a parser that runs decodeContainer purely as validation (:197-199), and a factory calling parseAsync with a base of new URL('.', absoluteURL(url)).href - or undefined for data: and blob: URLs (:200-202). On factory failure it evicts ${url}@native from the files and parsed caches (:205) so a transient error is not cached permanently. Call registerGLTFLoader() yourself only when importing the loader module directly.
  • Decoders ship beside the bundle, never inside it. build/gltf-decoders/ holds draco3d 1.5.7, meshoptimizer 1.2.0 and the three r168 Basis files with byte counts and sha256 in build/gltf-decoders/MANIFEST.md; tools/verify/decoder-audit.cjs fails the build if the bundle contains WASM magic bytes or a decoder file name. The only application-side entry is the three setters (src/air/assets/gltf/loader.ts:82-90), each accepting null to clear. With nothing injected and a required compression extension in use, the asset is rejected with GLTF_DECODER_MISSING (src/air/assets/gltf/extensions/geometry/draco.ts:75-77). The shipped Draco entry is Node/CommonJS by deliberate ruling, not oversight: browser Draco decode requires an app-supplied browser build (decoders.md).
  • getExtensionSupport() reports a live value, not a build constant. It builds a throwaway probe context (src/air/assets/gltf/loader.ts:95-106) and computes handler.support?.() ?? { name, status: 'supported' }, so a handler with no support() - KHR_materials_unlit and KHR_texture_transform - is unconditionally supported (:100). The same loader reports decoder-required before injection and supported after; examples/gltf-meshopt/src/main.ts:94-97 proves the flip by asserting the handler-level support?.().status === 'supported' once the shipped meshopt decoder is wired in. KNOWN_UNIMPLEMENTED is an empty array (:49-51), so the returned list is exactly the 21 handler entries in registration order. Of the five statuses only supported and decoder-required carry browser evidence; device-dependent is reachable from four support() implementations behind five extension names but appears in no tracked record, and fallback and unsupported are emitted by nothing shipped (extensions-matrix.md).
  • Required and optional extensions behave differently. validateRequired (src/air/assets/gltf/extension-registry.ts:104-124) throws for an unknown or non-supported extension listed in extensionsRequired, mapping decoder-required to GLTF_DECODER_MISSING, device-dependent to GLTF_DEVICE_UNSUPPORTED and fallback to GLTF_EXTENSION_UNSUPPORTED (:55-59, :118-121); the same condition on an optional extension only warns and continues on the core fallback (:122). An unknown optional extension is fully silent - continue with no warning and no report entry (:114).
  • GLTFAsset exposes five read-only collections, not nine. meshes, materials, textures, skeletons and animations are getters over the @internal mutable builder owned (src/air/assets/gltf/asset.ts:52-58); sceneNames, document (the original JSON, including camera and light descriptions and original node names) and warnings are separate members (:59-62), and images plus meshMaterials are @internal (:63-64).
  • Instantiating shares assets and isolates state. instantiate(sceneIndex = json.scene ?? 0) (src/air/assets/gltf/asset.ts:76) computes a visible set by child walk and an included set that additionally pulls in every ancestor of every skin joint (:84-89), rebuilds each clip keeping only tracks whose hierarchy root is included and caches the result per scene index (:90-101), then builds fresh nodes. Skin nodes get a SkinnedMeshRenderer with setUseBakedAnimation(false), skinningRoot = root and the shared skeleton (:139-141) after JOINTS_0 values are range-checked (:135-138); everything else gets a MeshRenderer (:143). The root also carries GLTFWinding (:126), a native Animation with playOnLoad = false, and the private GLTFAnimationPolicy at @executionOrder(100) - one past native Animation's 99 - whose onLoad reapplies per-instance wrap modes that the native rebuild would otherwise drop (:25-38, :159-163).
  • Release is deferred by design. instantiate takes one addRef and one instance count (src/air/assets/gltf/asset.ts:164) and hooks root.once(Node.EventType.NODE_DESTROYED, ...) which decrements in a microtask, because that event precedes child and component teardown (:168-175). destroy() sets destroyRequested, deregisters the uuid from assets, and calls releaseResources() immediately only when instances === 0 (:198-204); otherwise the last instance's hook does it. releaseResources() destroys the Set union of materials, meshes, skeletons, animations, textures, images and every cached scene clip exactly once, then super.destroy() (:205-212). After destroyRequested, instantiate() rejects with asset is destroyed while live instances keep running (:77).
  • GLTFInstance is a plain object, not a class. It is the literal returned at src/air/assets/gltf/asset.ts:176 with root, animations, setAnimationLoop and dispose as closure properties, so no prototype, static, export-wrapper or namespace mechanism can bind to it - which is why neither method has any instrumentation evidence and their proof is the passing examples that call them (loader-api.md).
  • Only some failures are GLTFError. GLTFErrorCode is the closed five-member union at src/air/assets/gltf/diagnostics.ts:2-3; the class sets name = 'GLTFError' and prefixes the message with [glTF] (:6-11), so code is the only reliable discriminator - the registry throws plain Errors with the same prefix for a duplicate handler name (src/air/assets/gltf/extension-registry.ts:86) and a missing dependency (:93), schema.ts check/item/integer throw plain prefix-only Errors for every structural rule (src/air/assets/gltf/schema.ts:55-65), a cancelled load throws DOMException('glTF load aborted', 'AbortError') from both src/air/assets/gltf/loader.ts:117 and src/air/assets/gltf/parser-context.ts:84-85, and setAnimationLoop throws a TypeError tagged AIR_E_GLTF_ANIMATION_OPTIONS (src/air/assets/gltf/asset.ts:177-179) which no instanceof GLTFError check will ever see.
  • Warnings are a second channel. context.warn both records and console.warns with the [glTF] prefix (src/air/assets/gltf/parser-context.ts:90), and asset.warnings exposes the list afterwards. Cameras are kept as descriptions rather than instantiated, and KHR_lights_punctual innerConeAngle is retained as metadata with no engine plateau input - both surface as warnings (src/air/assets/gltf/nodes.ts:16, src/air/assets/gltf/extensions/scene/lights.ts:117).
  • Progress is advisory and uneven. container and objects are always (1, 1); decode and textures report the accessor and texture counts, so loaded === total === 0 means an empty document, not a stall; dependencies is emitted only from inside loadBuffers and never carries a url (src/air/assets/gltf/parser-context.ts:159, :168), while url is populated only when parseAsync got a string (src/air/assets/gltf/loader.ts:120-121). Every emission sits inside the parseAsync try block, so a throwing onProgress fails the load through the normal teardown (diagnostics.md).
  • Keep the three capability layers apart. GLTFLoader, GLTFAsset, GLTFError, GLTFExtensionRegistry, registerGLTFLoader, configureGLTFLoaderDefaults, createDracoDecoder, createMeshoptDecoder, createKTX2Transcoder, isMeshoptAvailable, isKTX2Available, detectImageMime, SUPPORTED_IMAGE_MIMES, KTX2_RAW_MIME, the three geometry factories and the four extension-name constants all resolve by symbol in the single export { ... } block of build/cocosair.module.js (currently :161574); MAX_KTX2_DIMENSION, GLTFParserContext and gltfPhysicalEffect do not. GLTFParserContext does appear 15 times in build/cocosair.module.d.ts but only as the mangled __private._air_assets_gltf_parser_context__GLTFParserContext (:72760), so a TypeScript consumer writing a custom factory cannot name its context parameter and must use Parameters<GLTFExtensionFactory>[0].
  • Browser evidence, stated plainly. At candidate fingerprint 2f089f6ce25eaccd (docs/evidence/examples-verified.json, file-level measuredAt 2026-10-04T05:52:32.537Z), 18 gltf-touching ids are result: PASS and 17 of them carry gltf bindings. Strong: GLTFLoader (scene-ready x10), parseAsync (asset-loaded x10, visible-frame x3), instantiate (asset-loaded x5, visible-frame x2, node-exists x2, scene-ready x2, resource-released x1), destroy (resource-released x10). Real meshopt decode is browser-proven by gltf-meshopt (visible-frame litRatio=0.1606, resource-released held=3 leaked=0, assets/meshopt-khr.glb=1728B fetched). Real Draco decode and real KTX2 transcode are proven nowhere: gltf-draco has no visible-frame validator because what it proves is the refusal path, and no example imports the Basis transcoder. GLTFInstance.setAnimationLoop, GLTFInstance.dispose, configureGLTFLoaderDefaults and registerGLTFLoader have zero bindings.

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