Derived from the cocosair-camera 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
- The user surface is the
Cameracomponent (@ccclass('cc.Camera'),src/cocos/misc/camera-component.ts:102), not the render-scenescene.Camera._createCamerabuilds the scene camera duringonLoad(:605,:712); the component's own getters/setters only mirror onto it while it exists (every setter guardsif (this._camera), e.g.:317), so reads are valid before activation but writes beforeonLoadare held in the serializable fields and pushed on the next_createCamera(:726-743). camera.camerais TYPED non-null but ISnulluntil the component activates: the getter returnsthis._camera!(src/cocos/misc/camera-component.ts:202-204) and_camerais only assigned insideonLoad->_createCamera(:713-714), which needs the node active under a scene handed toapp.run. So touchcamera.camera.*(calculateObliqueMat,aspect,width/height,changeTargetWindow) only after the first run frame, and null-check it in code that can run earlier -frameObjectdoes exactly that (src/air/utils/frame-object.ts:44). The same guard silently skips work that looks like it ran: thefovAxissetter's fov conversion sits insideif (this._camera)(camera-component.ts:339-342), so a pre-activationfovAxiswrite converts nothing and thefovnumber you typed is later interpreted against the other axis.frameObjecthits the same null: it substitutesaspect = 1whencamera.camerais missing (src/air/utils/frame-object.ts:44-45), so a call before the first run frame sizes the fit for a square window - harmless when the window is square or wider (the vertical half-fov governs), but on a portrait window the horizontal field is narrower than the fit assumed and the target overflows; call it after activation or increasefov.- Component conversion methods take the INPUT first and an optional
outsecond, returningout:worldToScreen(worldPos, out?)(:654),screenToWorld(screenPos, out?)(:667),screenPointToRay(x, y, out?)(:641). The wrapped render-sceneCamerauses the opposite orderworldToScreen(out, worldPos)etc. (src/cocos/render-scene/scene/camera.ts:1336,:1282,:1243). Call the component version; with noout,screenToWorldallocates one pre-filled with a COPY of the camera node's world position (:668->node.getWorldPosition(), which returns a newVec3when called without an argument,src/cocos/scene-graph/node.ts:2666-2672) - the node's stored position is not mutated, but pass an explicitoutto avoid allocating per call. - Screen space is physical framebuffer pixels with a LEFT-BOTTOM origin (doc comment
src/cocos/misc/camera-component.ts:634, :648).camera.width/camera.heightare the swapchain pixels:resizeonly assigns the size it is handed and derivesaspectfrom it (src/cocos/render-scene/scene/camera.ts:984-991, called with the window size fromchangeTargetWindow:1220-1221), and the effective-DPR scaling happens upstream - DPR =min(devicePixelRatio, cap)with cap default 2 (src/pal/screen-adapter/web/screen-adapter.js:78-81), applied to the CSS size inwindowSize(:83-89).worldToScreenreturnsznormalized to[0,1](camera.ts:1355) and it is PROJECTIVE there (non-linear in world distance);screenToWorlddoes not invert that curve - it re-readsscreenPos.zas a LINEAR near->far fraction (:1310), so the twozconventions do not round-trip: withnear = 0.1,far = 1000a point at depth 5 projects toz ~= 0.98and 0.98 back-projects to depth ~980 on the same ray. Convert first (docs/manual/cameras.md:300, asserted inexamples/render-composite/src/main.ts:232-239) or pick withscreenPointToRay+ an intersection.event.getLocation()already yields left-bottom physical pixels; pass it straight in. - Priority is a draw ORDER key, re-sorted ASCENDING EVERY FRAME:
root._frameMoveEndsorts the extracted camera list witha.priority - b.priority(src/cocos/root.ts:795) right before handing it tothis._pipeline.render(cameraList)(:801), and that list is rebuilt each frame from the render windows (:761,:769-771->src/cocos/render-scene/core/render-window.ts:309-316). So a LOWERpriorityrenders first (background) and a higher one over it, and a runtimecamera.prioritywrite takes effect from the NEXT frame - the render-scene setter is a bare store (src/cocos/render-scene/scene/camera.ts:501-503) because the sort is per-frame, not because writes are ignored. Defaultpriorityis 0 (src/cocos/misc/camera-component.ts:146), UI range[0, 65535](:211). The window's own attach-time sort (render-window.ts:365-367, called only fromattachCamera:331) fixes EXTRACTION order, which is what breaks ties between equal priorities (Array.prototype.sortis stable, so ties keep window push order = node activation order) - set distinct priorities whenever order matters; re-enabling the node does not change order (camera-component.ts:609-614->_attachToScene:749-758->render-scene.ts:268-271touches the render-SCENE list, which rendering does not walk). orthoWidthdefaults to 0, which keeps nativeorthoHeight * aspecthalf-width; a finite non-negative value fixes the half-width independently and perspective ignores it (src/cocos/misc/camera-component.ts:383-391,src/cocos/render-scene/scene/camera.ts:1079). Assigning a negative or non-finite value throwsAIR_E_ORTHO_WIDTHand keeps the old value (camera-component.ts:387,camera.ts:697).- The component viewport is the normalized
camera.rectRect(0,0,1,1)(src/cocos/misc/camera-component.ts:168, :481). Setting the render-sceneviewportdirectly warns (warnID(8302),camera.ts:758-760) and is rerouted throughsetViewportInOrientedSpace(:1115), which flipsywhenscreenSpaceSignY < 0and re-rotates per surface orientation. - The oblique near plane lives on the render object:
camera.camera.calculateObliqueMat(viewSpacePlane: Vec4)rebuilds the ordinary projection first, then rewrites the near row and inverse matrices (camera.ts:1389-1418); a non-finite/zero plane throwsAIR_E_CLIP_PLANE(TypeError,:1392) and a degenerate plane against the projection throwsAIR_E_CLIP_PLANE(RangeError,:1404).getClipSpaceMinz()returns the devicecapabilities.clipSpaceMinZ(:1421): -1 on the WebGL 2/GL path (src/cocos/gfx/base/define.ts:774), 0 only on WebGPU (src/cocos/gfx/webgpu/webgpu-device.ts:544); the WebGPU backend is not a shipped AIR target. - Capability layers, stated separately (source export / default-bundle reachable / browser-verified):
Camera,Camera.ProjectionType/FOVAxis/ClearFlagandframeObjectall resolve by symbol name in the main entry declarationbuild/cocosair.module.d.ts(Cameracurrently :24943,frameObjectcurrently :56816). They are NOT exposed by the narrowcocosair.jsentry, whose declaration has one value export -export declare function createAirApp(currently :3 inbuild/cocosair.module.d.ts) - plus theAirApp/AirAppOptionstype re-export, nor bycocosair.js. No camera behavior here is browser-verified against the current candidate; theexamples/camera-*Gallery apps exercise it, which is not current-candidate evidence.