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

/cocosair-camera

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Configure Camera projection, viewports, framing and screen/world conversion. Use for split-screen, pointer rays, wrong screenToWorld results or AIR_E_ORTHO_WIDTH.

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

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencescommon-mistakes.md

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

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.

Common Mistakes

[HIGH] Dividing screen pixels by devicePixelRatio before screenToWorld

Wrong:

// cssPos came from getBoundingClientRect(), and you "undo" DPR by hand
const world = camera.screenToWorld(new Vec3(cssPos.x / window.devicePixelRatio,
                                           cssPos.y / window.devicePixelRatio, 0.5));

Correct:

// event.getLocation() is already left-bottom-origin physical pixels; feed it through directly
const p = event.getLocation();
const world = camera.screenToWorld(new Vec3(p.x, p.y, 0.5), new Vec3());

worldToScreen/screenToWorld operate in the framebuffer's physical pixels (camera.width/camera.height are the effective-DPR swapchain size), so an agent that reads "screen space" as CSS pixels divides by devicePixelRatio a second time; the result is a world ray/point scaled by 1/dpr^2 that lands off-target, and the extra y flip the manual CSS conversion needs is silently skipped, so the pick is vertically inverted too.

[HIGH] Copying the render-camera argument order onto the component

Wrong:

const out = new Vec3();
camera.worldToScreen(out, worldPos);   // scene-camera order: the component reads `out` as worldPos
camera.screenToWorld(out, screenPos);  // reads out (zeros) as the screen pixel and writes the world point into screenPos

Correct:

const out = new Vec3();
camera.worldToScreen(worldPos, out);   // component order: input first, optional out second
camera.screenToWorld(screenPos, out);

Upstream Cocos docs and the internal scene.Camera use worldToScreen(out, worldPos), so an agent transcribes that order onto the user-facing component: out (zeros) is then treated as the world position, the real point is dropped, and the call returns a value with no throw - the object just silently contains the projection of the wrong input. The mirrored swap on screenToWorld is equally silent and reads the other way: the zeroed out is CONSUMED as the screen pixel, the world point is written into screenPos (the object you meant as input), and out keeps its zeros - nothing is ignored, both arguments change role.

[MEDIUM] Stacking two cameras and trusting creation order for draw order

Wrong:

const base = baseNode.addComponent(Camera);      // priority 0 (default)
const overlay = overlayNode.addComponent(Camera); // also priority 0
overlay.clearFlags = Camera.ClearFlag.DEPTH_ONLY;
// both are 0, so the attach order decides who wins - and the overlay sometimes paints under

Correct:

base.priority = 0;                                // drawn first (background)
overlay.priority = 1;                             // drawn after, composited over base
overlay.clearFlags = Camera.ClearFlag.DEPTH_ONLY;  // keep base color, write only depth+overlay

Both cameras then tie at 0, and ties fall back to extraction order - the render window's own list order, which is node activation order, because Array.prototype.sort is stable and the per-frame ascending sort at src/cocos/root.ts:795 leaves equal values in the order extractRenderCameras pushed them. Activation order shifts as nodes enable in different frames, so an unset priority makes the overlay draw order nondeterministic. Set distinct values; a runtime priority write does apply, but from the next frame, and re-enabling the node changes nothing about order. Recipe values: multi-camera.md.

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
[
  "switch perspective and orthographic views",
  "fit a loaded model in view",
  "stack cameras or create split-screen views",
  "convert pointer pixels to a world ray",
  "screenToWorld results or orthographic width are wrong"
]
owns
[
  "projection",
  "viewport",
  "camera-framing",
  "screen-world",
  "camera-order",
  "oblique-plane"
]
not_for
[
  "register node layer bits -> cocosair-scene-graph",
  "offscreen render targets -> cocosair-rendering",
  "physics collision queries -> cocosair-physics"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "配置相机投影、视口、可见层和多相机顺序,并进行坐标转换、射线拾取与模型取景。用于相机配置或屏幕与世界坐标问题。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-camera