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'onAirAppOptions(src/air/app.ts:72); normalized with default'builtin'and anAIR_E_PHYSICS_BACKENDthrow for any other value (src/air/app-config.ts:45-46). The choice lands onGame.EVENT_PRE_SUBSYSTEM_INIT(src/air/bootstrap.ts:141-142) and callsselectPhysicsBackend(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-builtinandphysics-cannonintools/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
selectPhysicsBackendonly warns, keeping the engine's toleratedPHYSICS_NONEstate (src/air/physics-backend.ts:46-52;PHYSICS_NONEgetter atsrc/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);switchToafterwards is not the runtime path (physics-selector.ts:145-164). - Error 9642:
PhysicsSystem.initDefaultMateriallogserrorID(9642)and leaves the material empty whenbuiltinResMgrhas nodefault-physics-material(src/cocos/physics/framework/physics-system.ts:223-230; text at line 420 ofDebugInfos.jsonundersrc/). Benign for builtin (BuiltinShape.setMaterialis an empty function,docs/notes/physics-3d-notes.md:26), fatal for cannon (CannonShape.setMaterialdereferences the missing material,docs/notes/physics-3d-notes.md:390-399). AIR installs an official-namedPhysicsMaterialintobuiltinResMgrat module evaluation and at selection (src/air/physics-backend.ts:74-85), so both cases are covered on thecreateAirApppath. - 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).setGravityis empty (:125-126),syncAfterEventsonly syncs scene to physics so no physics-to-scene write-back exists (:198-200), rigid-body and material setters are component bookkeeping, whileraycast/raycastClosest/lineStripCastare real against the synced world shapes andsweepBox/sweepSpherealways miss withwarnID(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:
PhysicsSystemis aSystemsingleton constructed atDirectorEvent.INIT(src/cocos/physics/framework/physics-system.ts:875,:912) -PhysicsSystem.instance(:92) is null until the app is ready;stepat:442,syncSceneToPhysicsat:452,raycastat:511(results inraycastResults,:275),raycastClosestat:534returning boolean intoraycastClosestResult(:267).RigidBody(src/cocos/physics/framework/components/rigid-body.ts:60) andCollider(src/cocos/physics/framework/components/colliders/collider.ts:46) are ordinary components; trigger callbacks ridecollider.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.collisionMaskdefaults toPhysicsGroup.DEFAULTonly, so setting onlysetGroupsilently removes that body from every pair (docs/notes/physics-3d-notes.md:56-63). - 2D runs the pure-JS box2d port by default:
PhysicsSystem2Dsingleton (src/cocos/physics-2d/framework/physics-system.ts:40,instanceat:200,stepat:345,autoSimulationat:120-125),RigidBody2D(src/cocos/physics-2d/framework/components/rigid-body-2d.ts:39),Collider2D(colliders/collider-2d.ts:39) andBoxCollider2D(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 flatselectorexport is the 2D one - 3D backend identity must be read from the world constructor (docs/notes/physics-3d-notes.md:38-52).