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

/cocosair-math

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Compute vectors, matrices, quaternions, colors and easing. Use for out-first math, frozen Vec3.UP errors, transform composition, rotation units or Mat4.invert.

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

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-math 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

  • math is a namespace object, not a class bag: src/cocos/core/index.ts:28 does import * as math from './math' and :36 exports it, so math.Vec3, math.bits, math.clamp01 are the same bindings as the top-level ones. The namespace surface is exactly src/cocos/core/math/index.ts:34-49 (bits :34, the value types with their factories :35-43, ./utils :44, ./type-define :45, ./math-base :46). easing and the top-level bits come from elsewhere: easing is src/cocos/core/algorithm/index.ts:29, and math.easing does NOT exist.
  • Every static operation on every value type is out-first: it writes fields of out and returns out; none of them allocate except the clone family (Vec3.add<Out extends IVec3Like>(out, a, b): Out, src/cocos/core/math/vec3.ts:112-117). Passing a frozen constant as out throws; passing a live node-owned vector as out mutates the node's stored data.
  • Frozen constants are a hard boundary. freezeVec3 (src/cocos/core/math/vec3.ts:48-50) is Object.freeze(new Vec3(...)), module-local and not exported, and backs the nine statics at :57-65 (UNIT_X/UNIT_Y/UNIT_Z, RIGHT/UP/FORWARD/ZERO/ONE/NEG_ONE) typed Readonly<Vec3>. Equivalent helpers/inline freezes exist per type: vec2.ts:50-51 with five statics (:59-63), vec4.ts:46-47 with seven (:55-61), color.ts:45-46 with ten (:56-65), Mat4.IDENTITY mat4.ts:63, Mat3.IDENTITY mat3.ts:45, Quat.IDENTITY quat.ts:54, Size.ZERO/ONE size.ts:36-37. Rect has no frozen statics. Bundled ESM is always strict mode, so both Vec3.UP.x = 5 and Vec3.UP.set(...) throw TypeError in the strict-mode bundle; the same writes in a sloppy script silently do nothing.
  • Instance fields are plain mutable numbers (public declare x: number, src/cocos/core/math/vec3.ts:884), so a Vec3 is only as private as its holder. The scene graph stores its own private _lpos/_lrot/_lscale and hands them out as Readonly<Vec3> getters; a returned Readonly reference to a node's own storage is a TS marker only and is still mutable at runtime.
  • Color channels are bytes: Color stores private _data = new Uint8ClampedArray(4) (src/cocos/core/math/color.ts:340) and the r/g/b/a accessors index it directly (:346-387), with defaults 0/0/0/255 in set (:721-743). Writing 0.5 into a channel is a byte coercion (clamped and rounded), not 50 percent; the 0-1 view is the compatibility accessors x/y/z/w (:390-397) and Color.toVec4/fromVec4 (:113, :131). There is no premultiply member on Color in this runtime.
  • Composition order is documented as "S->R->T applied in order", which in the column-major storage of Mat4 means out = T * R * S (Mat4.fromSRT, src/cocos/core/math/mat4.ts:964-1000; translation lands in m12/m13/m14). fromRTS (:951) and toRTS (:865) are deprecated aliases that forward to fromSRT/toSRT - the letters in the name are not an order. Mat4.multiply(out, a, b) is out = a * b (:316), and the manual asserts child world = parent.worldMatrix * childLocal (docs/manual/matrix-transformations.md:7).
  • Angles: the euler entry points take DEGREES (Quat.fromEuler multiplies by halfToRad = 0.5 * PI / 180, src/cocos/core/math/quat.ts:557-560, :934; Node.setRotationFromEuler, src/cocos/scene-graph/node.ts:2506-2514), while every axis-angle, Mat4.rotate* and Mat3.toEuler entry point takes radians (quat.ts:475, mat4.ts:441, mat3.ts:649). Unit mixing does not throw - it silently rotates by a factor of about 57.
  • Degenerate input is answered silently, never by a throw: Mat4.invert writes an ALL-ZERO matrix when the determinant is exactly 0 (src/cocos/core/math/mat4.ts:254-255, documented at :229 - the old contents are lost), Vec3.normalize writes (0,0,0) for a zero-length input (src/cocos/core/math/vec3.ts:329-345), Quat.invert produces the zero quaternion (src/cocos/core/math/quat.ts:384-398), and Mat4.toSRT returns identity rotation when any scale is 0 (:894-899). Mirror matrices are handled by taking the sign into the scale: after normalizing the three column vectors, toSRT computes Mat3.determinant and on a negative value negates s.x and column 0 before Quat.fromMat3 (src/cocos/core/math/mat4.ts:914-927).
  • Capability layers, stated separately (source export / default-bundle reachable / browser-verified): the delivered bundle build/cocosair.module.js exports math, easing, bits, the ten value classes, their factory functions (v2/v3/v4/quat/mat4/rect/size/color), all of ./utils (lerp, clamp, randomRange, pseudoRandom, floatToHalf, ...), EPSILON/HALF_PI/TWO_PI and ValueType/MathBase, so all of them are importable from the main entry; preTransforms is engine-internal (src/cocos/core/math/index.ts:49). srgbToLinear/linearToSrgb/linearToSrgb8Bit (src/cocos/core/math/color.ts:781, :793, :800) and AffineTransform (src/cocos/core/math/affine-transform.ts:38) are source exports that are NOT in the bundle export list, and Vec3.random/Vec2.random are reachable only as statics. perlin, fp32/fp16 and toRgba8/fromRgba8 are not present in the declaration. All 40 examples/math-* Gallery apps are recorded PASS for Chromium in docs/evidence/examples-verified.json (measuredAt 2026-10-04T05:52:32Z, candidateFingerprint 2f089f6ce25eaccd) - that is captured browser evidence for that candidate, not for the bundle in build/ today.

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
[
  "normalize or project a direction",
  "compose or decompose a transform matrix",
  "choose quaternion rotation and angle units",
  "convert colors or calculate easing and deterministic random",
  "writing a frozen vector constant throws"
]
owns
[
  "vector-math",
  "matrix-transforms",
  "quaternion",
  "color-values",
  "easing",
  "deterministic-random"
]
not_for
[
  "screen and world camera conversion -> cocosair-camera",
  "native tween playback -> cocosair-animation-tween",
  "node parenting and lifecycle -> cocosair-scene-graph"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "使用 Cocos 数学类型进行向量、矩阵、四元数、颜色和插值计算。用于坐标变换、旋转、颜色处理、缓动或确定性随机。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-math