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

/cocosair-primitives-mesh

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Build primitive geometry, Mesh buffers and MeshRenderer bindings. Use for vertex attributes, indices, wireframes or AIR_E_PRIMITIVE_DESCRIPTOR validation.

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

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencescontracts.md

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

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

  • createPrimitiveGeometry(descriptor) returns IGeometry, never a Mesh; MeshRenderer.mesh takes only a Mesh asset, so the IGeometry must go through utils.MeshUtils.createMesh(geometry) or new Mesh() + reset({ struct, data }) first.
  • The descriptor accepts only type: 'box' | 'sphere' | 'cylinder' | 'cone'; each shape has a fixed field whitelist, segments are integers <= 1024, per-shape predicted-vertex caps are 1_000_000, and arc must be in (0, 2pi]. Any violation throws a RangeError with code = 'AIR_E_PRIMITIVE_DESCRIPTOR' and a field (src/air/primitive-geometry.ts:23-39,58-83). The caps are an allocation guard on this entry point, not a hard Mesh ceiling; larger meshes go through the native generators directly.
  • includeNormal/includeUV validate as optional booleans (src/air/primitive-geometry.ts:48-53) but are no-ops for the four descriptor shapes: box/sphere/cylinder/cone always emit normals and UVs. Among the native generators only plane and quad branch on the flags (src/cocos/primitive/plane.ts:120,145,156, src/cocos/primitive/quad.ts:55,63); circle passes its options through applyDefaultGeometryOptions (src/cocos/primitive/circle.ts:45, src/cocos/primitive/define.ts:57-67) and never reads either flag, so no flag value changes circle's output (src/cocos/primitive/circle.ts:85-92).
  • The mesh setter runs side effects on assignment: it calls val?.initialize(), resets morph weights, rebuilds models and re-attaches to the scene (src/cocos/3d/framework/mesh-renderer.ts:487-503); initialize() needs a live device for a dynamic struct, failing with AIR_E_MESH_NOT_READY before createAirApp resolves (src/cocos/3d/assets/mesh.ts:416).
  • Converter entry points: use the MeshUtils statics, utils.MeshUtils.createMesh(geometry) (src/cocos/3d/misc/create-mesh.ts:406) and utils.MeshUtils.createDynamicMesh(primitiveIndex, geometry, out?, options?) (src/cocos/3d/misc/create-mesh.ts:419). The utils barrel (src/cocos/3d/misc/index.ts:28) also re-exports a free createMesh, but that function is marked @deprecated (src/cocos/3d/misc/create-mesh.ts:44-46). The module-level function createDynamicMesh (src/cocos/3d/misc/create-mesh.ts:262) is NOT exported by the barrel, so the utils namespace has no createDynamicMesh member of its own and calling one throws a TypeError; the same-named static on MeshUtils is the live entry (examples/interactive-geometry/src/main.ts:155). Neither createMesh nor MeshUtils is a name on the build/cocosair.module.js export block (626 entries parsed), so both resolve only through the utils namespace.
  • renderer.bakeSettings is the GI-bake settings object the component constructs for you (src/cocos/3d/framework/mesh-renderer.ts:333, decorated @editable, @disallowAnimation, @displayOrder(3) at :330-332); class ModelBakeSettings extends EventTarget (:125) is NOT a name on the export block, so reach it only as the field renderer.bakeSettings, never imported or constructed by name from the package.
  • Morph weights: renderer.setWeight(weight, subMeshIndex, shapeIndex) (src/cocos/3d/framework/mesh-renderer.ts:720) returns silently, with no throw and no warn, when subMeshIndex >= this._subMeshShapesWeights.length (:722-724) or shapeIndex >= shapeWeights.length (:726-727); a surviving call writes the slot and calls this._uploadSubMeshShapesWeights(subMeshIndex) (:729-730). The weight table is (re)built by the mesh setter, which calls this._initSubMeshShapesWeights() (:491), so replacing the mesh resets weights.
  • Instance writes: renderer.setInstancedAttribute(name, value) (src/cocos/3d/framework/mesh-renderer.ts:733) returns immediately when this.model is falsy (:734-736), i.e. writing an instance attribute before the model exists is a silent no-op; the JSB branch (:738-740) is native-only and the Web branch iterates this.model.subModels and their instancedAttributeBlock from :741.
  • Struct attributes must be new gfx.Attribute(name, format, isNormalized, stream, isInstanced, location) (src/cocos/gfx/base/define.ts:1498-1508); Attribute has a private _token so a plain object is rejected. Attribute, Format, AttributeName, PrimitiveMode and FormatInfo reach the runtime only through the gfx namespace, not as top-level import names.
  • One ISubMesh is one index group and one material slot; every primitive generator and utils.createMesh produce a single-vertex-bundle, single-primitive struct, so box's six faces share one draw group (src/cocos/3d/misc/create-mesh.ts:227-230). Multi-material meshes require authoring several primitives entries.
  • Ownership: utils.createMesh returns a Mesh asset the caller must destroy; createPrimitiveGeometry's IGeometry is plain data and is copied into the buffer at conversion. readIndices hands back a live view over the mesh bytes, readAttribute allocates a fresh typed array each call (src/cocos/3d/assets/mesh.ts:1252,1170).
  • Capability layers: createPrimitiveGeometry, primitives, utils, Mesh, MeshRenderer, Primitive and the gfx namespace are default-bundle reachable (names in the build/cocosair.module.js export block); the shape generators are browser-PASS in recorded candidates of docs/evidence/examples-verified.json, while createPrimitiveGeometry itself is covered only by the jsdom smoke test and the consumer-import check, not by a browser-pixel run. A recorded PASS proves only the candidate fingerprint stored with it, not today's bytes.

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
[
  "generate a box, sphere, cylinder or cone",
  "attach procedural geometry to a renderer",
  "author custom vertex buffers and indices",
  "read or copy mesh attributes",
  "a primitive descriptor fails validation"
]
owns
[
  "primitive-geometry",
  "mesh-buffers",
  "vertex-attributes",
  "mesh-indices",
  "mesh-renderer",
  "wireframe"
]
not_for
[
  "draw-call batching and instancing -> cocosair-performance",
  "skeletal binding or morph weights -> cocosair-skinning-morph",
  "material uniforms and effects -> cocosair-materials-effects"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "构建基本几何和原生 Mesh,检查顶点属性、索引、边界与渲染器写入契约。用于代码生成几何或自定义网格。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-primitives-mesh