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

/cocosair-scene-graph

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Build Scene/Node hierarchies, Component lifecycles, layers and events. Use for reparenting, active inheritance, NodePool reuse, scene globals or resource release.

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

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencescontracts.md

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

Derived from the cocosair-scene-graph 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

  • Scene extends Node. A scene is the tree root; call scene.addChild(node). app.run(newScene) and director.loadScene route through runSceneImmediate, which destroys the previous scene; its children are destroyed with it. director.getScene() is the live scene; find defaults to it. Tables: node-ops.md.
  • Component lifecycle runs in this fixed order: __preload -> onLoad -> onEnable -> (first frame) start -> update(dt) -> lateUpdate(dt) -> onDisable -> onDestroy. onLoad runs before any start; start runs before the first update; dt is in seconds. active=false stops update scheduling, not just rendering. node-ops.md.
  • node.destroy() is deferred and narrow: it marks the object ToDestroy; the real teardown runs at end of frame in _destroyImmediate -> _onPreDestroyBase, whose this._eventProcessor.destroy() call clears this node's OWN node-event listeners only. The exception is a scene switch: runSceneImmediate calls the old scene's destroy() and then CCObject._deferredDestroy() within the same call (director.ts:446, :464), so after app.run(newScene) the previous scene already reads isValid === false. input.on/Input.EventType subscriptions, DOM addEventListener, director/game events and callbacks registered on OTHER nodes are out of scope and must be released explicitly (the scene-switch-reentry example unsubscribes input.on in onDisable). node-events.md.
  • addChild(child) returns void; do not chain. setScale(...) and the scale getter act on LOCAL scale; worldScale multiplies the parent chain (setting world scale back-solves local). setParent(value, keepWorldTransform = false) keeps the child's local transform by default. node-ops.md.
  • Layers are a bit mask in node.layer (default Layers.Enum.DEFAULT) tested against camera.visibility; a mismatch draws nothing, and the two passes test it differently: the 3D render queue requires containment, (visibility & node.layer) === node.layer (src/cocos/rendering/scene-culling.ts:198), while the 2D path uses the non-zero test visibility & node.layer (src/cocos/2d/renderer/batcher-2d.ts:265), so an OR-ed multi-bit node.layer must be wholly inside the 3D mask or the 3D pass culls it. The engine default camera mask (CAMERA_DEFAULT_MASK) already includes DEFAULT and every user bit (0-19), so a default Camera draws DEFAULT-layer and registered-custom-layer nodes without touching visibility; only nodes moved to an excluded bit or a replaced mask go unseen. Register custom layers through Layers.addLayer(name, bit) and build masks with makeMaskInclude/makeMaskExclude; do not hand-OR reserved bits. Bit numbers and the reserved range: layers.md.
  • Scene globals (ambient, fog, skybox, shadows, octree, skin, lightProbeInfo) are writable config objects reached via scene.globals, with a two-phase sync. Before activation edits are staged on the config fields; scene activation (_activate -> _globals.activate, scene.ts:204, skipped in TEST) binds them to the render resources on director.root.pipeline.pipelineSceneData (members ambient/fog/skybox/shadows/octree/skin/postSettings/lightProbes, pipeline-scene-data.ts:107-115) and pushes the staged values. After activation the member setters write the bound resource directly (each setter guards if (this._resource)), so post-run edits apply too. scene.renderScene exposes neither ambient nor fog nor skybox; read effective values from scene.globals or the bound pipelineSceneData members. scene-globals.md.
  • Refcount: Asset.addRef() increments _ref (asset.ts:316-319); decRef(autoRelease = true) decrements only while _ref > 0 (asset.ts:331-334) and, when autoRelease, queues a release attempt through releaseManager.tryRelease (asset.ts:335-336). Nothing frees synchronously: the free runs on the next tick and only while the count is zero or circular references are all that remains (release-manager.ts:224-229, :249-253). A loaded SceneAsset (a thin wrapper holding .scene) follows the same rule. Scene.autoReleaseAssets defaults to false; on switch away the release manager calls decRef(TEST || oldScene.autoReleaseAssets) on the old scene's dependencies (release-manager.ts:179, :189), so leaving it false keeps those assets resident until you release them. scene-globals.md.
  • Capability layers, stated separately (source export / default-bundle reachable / browser-verified): every symbol in this skill's surface resolves by symbol name in the main entry declaration build/cocosair.module.d.ts (line-level inventory in node-ops.md, Main entry export surface; re-exported through src/exports/base.ts). Node-tree behavior in examples/node-hierarchy and scene-switch/refcount behavior in examples/scene-switch-reentry carry browser evidence in docs/evidence/examples-verified.json, but that file is measuredAt 2026-10-04 recorded for candidate fingerprint 2f089f6ce25eaccd, while the current tree recomputes to 8f3e573cebbb315f (candidateFingerprint() in tools/verify/api-trace.cjs); cite it as historical until the gate is re-run against the current candidate. A symbol resolving by name does not by itself prove the behavior is browser-verified.

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
[
  "attach or reparent nodes in a scene",
  "understand component lifecycle and update order",
  "a child is inactive or inherits unexpected scale",
  "manage node events, layers or object pools",
  "release scenes and external listeners without leaking"
]
owns
[
  "scene-hierarchy",
  "component-lifecycle",
  "node-events",
  "layers",
  "node-pool",
  "scene-globals"
]
not_for
[
  "native input and action mapping -> cocosair-input-action",
  "app-level scene replacement -> cocosair-application",
  "camera framing and projection -> cocosair-camera"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "使用原生 Scene、Node、Component 构建场景树并管理层、事件、生命周期和资源释放。用于节点组织、组件更新、对象池或场景配置。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-scene-graph