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)returnsIGeometry, never aMesh;MeshRenderer.meshtakes only aMeshasset, so the IGeometry must go throughutils.MeshUtils.createMesh(geometry)ornew Mesh()+reset({ struct, data })first.- The descriptor accepts only
type: 'box' | 'sphere' | 'cylinder' | 'cone'; each shape has a fixed field whitelist,segmentsare integers<= 1024, per-shape predicted-vertex caps are1_000_000, andarcmust be in(0, 2pi]. Any violation throws aRangeErrorwithcode = 'AIR_E_PRIMITIVE_DESCRIPTOR'and afield(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/includeUVvalidate as optional booleans (src/air/primitive-geometry.ts:48-53) but are no-ops for the four descriptor shapes:box/sphere/cylinder/conealways emit normals and UVs. Among the native generators onlyplaneandquadbranch on the flags (src/cocos/primitive/plane.ts:120,145,156,src/cocos/primitive/quad.ts:55,63);circlepasses its options throughapplyDefaultGeometryOptions(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
meshsetter runs side effects on assignment: it callsval?.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 withAIR_E_MESH_NOT_READYbeforecreateAirAppresolves (src/cocos/3d/assets/mesh.ts:416). - Converter entry points: use the
MeshUtilsstatics,utils.MeshUtils.createMesh(geometry)(src/cocos/3d/misc/create-mesh.ts:406) andutils.MeshUtils.createDynamicMesh(primitiveIndex, geometry, out?, options?)(src/cocos/3d/misc/create-mesh.ts:419). Theutilsbarrel (src/cocos/3d/misc/index.ts:28) also re-exports a freecreateMesh, but that function is marked@deprecated(src/cocos/3d/misc/create-mesh.ts:44-46). The module-levelfunction createDynamicMesh(src/cocos/3d/misc/create-mesh.ts:262) is NOT exported by the barrel, so theutilsnamespace has nocreateDynamicMeshmember of its own and calling one throws aTypeError; the same-named static onMeshUtilsis the live entry (examples/interactive-geometry/src/main.ts:155). NeithercreateMeshnorMeshUtilsis a name on thebuild/cocosair.module.jsexport block (626 entries parsed), so both resolve only through theutilsnamespace. renderer.bakeSettingsis 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 fieldrenderer.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, whensubMeshIndex >= this._subMeshShapesWeights.length(:722-724) orshapeIndex >= shapeWeights.length(:726-727); a surviving call writes the slot and callsthis._uploadSubMeshShapesWeights(subMeshIndex)(:729-730). The weight table is (re)built by themeshsetter, which callsthis._initSubMeshShapesWeights()(:491), so replacing the mesh resets weights. - Instance writes:
renderer.setInstancedAttribute(name, value)(src/cocos/3d/framework/mesh-renderer.ts:733) returns immediately whenthis.modelis 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 iteratesthis.model.subModelsand theirinstancedAttributeBlockfrom:741. - Struct attributes must be
new gfx.Attribute(name, format, isNormalized, stream, isInstanced, location)(src/cocos/gfx/base/define.ts:1498-1508);Attributehas a private_tokenso a plain object is rejected.Attribute,Format,AttributeName,PrimitiveModeandFormatInforeach the runtime only through thegfxnamespace, not as top-level import names. - One
ISubMeshis one index group and one material slot; every primitive generator andutils.createMeshproduce a single-vertex-bundle, single-primitive struct, sobox's six faces share one draw group (src/cocos/3d/misc/create-mesh.ts:227-230). Multi-material meshes require authoring severalprimitivesentries. - Ownership:
utils.createMeshreturns aMeshasset the caller must destroy;createPrimitiveGeometry'sIGeometryis plain data and is copied into the buffer at conversion.readIndiceshands back a live view over the mesh bytes,readAttributeallocates a fresh typed array each call (src/cocos/3d/assets/mesh.ts:1252,1170). - Capability layers:
createPrimitiveGeometry,primitives,utils,Mesh,MeshRenderer,Primitiveand thegfxnamespace are default-bundle reachable (names in thebuild/cocosair.module.jsexport block); the shape generators are browser-PASS in recorded candidates ofdocs/evidence/examples-verified.json, whilecreatePrimitiveGeometryitself is covered only by the jsdom smoke test and the consumer-import check, not by a browser-pixel run. A recordedPASSproves only the candidate fingerprint stored with it, not today's bytes.