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

/cocosair-physics

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Choose builtin, cannon or Box2D physics; wire rigid bodies, colliders and raycasts. Use for missing gravity, trigger filters, backend limits or material error 9642.

  • 9 files
  • 37.8 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-physics

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencescontracts.md

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

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

  • physics?: 'builtin' | 'cannon' on AirAppOptions (src/air/app.ts:72); normalized with default 'builtin' and an AIR_E_PHYSICS_BACKEND throw for any other value (src/air/app-config.ts:45-46). The choice lands on Game.EVENT_PRE_SUBSYSTEM_INIT (src/air/bootstrap.ts:141-142) and calls selectPhysicsBackend (src/air/physics-backend.ts:41), which re-registers the chosen wrapper through the official rule "the system will use the last backend registered before initialization" (src/cocos/physics/framework/physics-selector.ts:100-107, register at :127-136).
  • Both 3D backends compile into the default bundle (physics-builtin and physics-cannon in tools/build/build.cjs:41): builtin registers five wrappers - RigidBody, BoxShape, SphereShape, CapsuleShape, PhysicsWorld (src/cocos/physics/cocos/instantiate.ts:34-40), cannon registers the full set (src/cocos/physics/cannon/instantiate.ts:45). Selection is therefore only a re-register, never a download.
  • Zero-backend state: on a module graph with no physics feature the registry is empty and selectPhysicsBackend only warns, keeping the engine's tolerated PHYSICS_NONE state (src/air/physics-backend.ts:46-52; PHYSICS_NONE getter at src/cocos/physics/framework/physics-system.ts:48). A requested backend missing from a non-empty registry throws (src/air/physics-backend.ts:54-56), and selection after the world exists throws too (:58-62); switchTo afterwards is not the runtime path (physics-selector.ts:145-164).
  • Error 9642: PhysicsSystem.initDefaultMaterial logs errorID(9642) and leaves the material empty when builtinResMgr has no default-physics-material (src/cocos/physics/framework/physics-system.ts:223-230; text at line 420 of DebugInfos.json under src/). Benign for builtin (BuiltinShape.setMaterial is an empty function, docs/notes/physics-3d-notes.md:26), fatal for cannon (CannonShape.setMaterial dereferences the missing material, docs/notes/physics-3d-notes.md:390-399). AIR installs an official-named PhysicsMaterial into builtinResMgr at module evaluation and at selection (src/air/physics-backend.ts:74-85), so both cases are covered on the createAirApp path.
  • Builtin boundary, stated precisely: upstream calls it "efficient discrete collision detector, not a full physical simulator" (src/cocos/physics/cocos/builtin-world.ts:50-55). setGravity is empty (:125-126), syncAfterEvents only syncs scene to physics so no physics-to-scene write-back exists (:198-200), rigid-body and material setters are component bookkeeping, while raycast/raycastClosest/lineStripCast are real against the synced world shapes and sweepBox/sweepSphere always miss with warnID(9640) (docs/notes/physics-3d-notes.md:90-111). Under cannon every one of these inverts: free fall, velocity write-back, MeshCollider in the world (docs/notes/physics-3d-notes.md:373-386).
  • The 3D framework surface: PhysicsSystem is a System singleton constructed at DirectorEvent.INIT (src/cocos/physics/framework/physics-system.ts:875, :912) - PhysicsSystem.instance (:92) is null until the app is ready; step at :442, syncSceneToPhysics at :452, raycast at :511 (results in raycastResults, :275), raycastClosest at :534 returning boolean into raycastClosestResult (:267). RigidBody (src/cocos/physics/framework/components/rigid-body.ts:60) and Collider (src/cocos/physics/framework/components/colliders/collider.ts:46) are ordinary components; trigger callbacks ride collider.on('onTriggerEnter' | 'onTriggerStay' | 'onTriggerExit') (examples/physics-3d-basic/main.js:312-314).
  • Filtering is a bidirectional AND of each side's group against the other's mask (src/cocos/physics/cocos/builtin-world.ts:183-186); Collider.collisionMask defaults to PhysicsGroup.DEFAULT only, so setting only setGroup silently removes that body from every pair (docs/notes/physics-3d-notes.md:56-63).
  • 2D runs the pure-JS box2d port by default: PhysicsSystem2D singleton (src/cocos/physics-2d/framework/physics-system.ts:40, instance at :200, step at :345, autoSimulation at :120-125), RigidBody2D (src/cocos/physics-2d/framework/components/rigid-body-2d.ts:39), Collider2D (colliders/collider-2d.ts:39) and BoxCollider2D (colliders/box-collider-2d.ts:36); the world implements the three queries (src/cocos/physics-2d/box2d/physics-world.ts:173, :360, :385).
  • Everything above is reachable from the bundle's single export block (build/cocosair.module.js, currently :161574): selectPhysicsBackend, physics, PhysicsSystem, RigidBody, Collider, PhysicsSystem2D, RigidBody2D, Collider2D, BoxCollider2D, PHYSICS_2D_PTM_RATIO. The flat selector export is the 2D one - 3D backend identity must be read from the world constructor (docs/notes/physics-3d-notes.md:38-52).

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
[
  "dynamic bodies do not fall or stack",
  "triggers stop firing after changing collision groups",
  "choose builtin or cannon before startup",
  "query 2D bodies with raycasts or overlap tests",
  "physics material error 9642 appears"
]
owns
[
  "builtin-physics",
  "cannon",
  "box2d",
  "collision-filter",
  "rigid-body",
  "physics-queries"
]
not_for
[
  "camera pixel-to-ray conversion -> cocosair-camera",
  "node hierarchy and transforms -> cocosair-scene-graph",
  "non-physics startup errors -> cocosair-application"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "选择 builtin 或 cannon,并区分碰撞检测、运动积分和二维 Box2D 的能力。用于刚体、触发器、射线查询或物理后端问题。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-physics