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

/cocosair-skinning-morph

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Bind skeletons, restore bind poses and drive morph weights. Use for realtime/baked deformation, AIR_E_SKINNING_JOINT_PATH or AIR_E_SKINNING_CAPACITY.

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

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencesquick-start.md

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

Derived from the cocosair-skinning-morph 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.

Environment: the HTML examples using /build/ require the AIR development server and an existing bundle. In npm applications use the installed package name and the application's own bundler/server; resolve docs and declarations from that package. Do not copy repository URLs into a consumer app. Browser behavior is verified only for explicitly tested snippets and candidates.

Quick Start

<canvas id="GameCanvas"></canvas>
<script type="importmap">
  { "imports": { "cocosair": "/build/cocosair.module.js" } }
</script>
<script type="module">
import { createAirApp, Scene, Node, Camera, DirectionalLight, Component, Material, Color, Vec3,
         SkinnedMeshRenderer, Mesh, gfx, buildSkeletonTree, restoreBindPose, frameObject } from 'cocosair';

const app = await createAirApp({ canvas: '#GameCanvas' });   // #GameCanvas must exist before this import
const scene = new Scene('skinning');
const camNode = new Node('Main Camera'); scene.addChild(camNode); camNode.setPosition(new Vec3(0, 2.4, 6.5));
const camera = camNode.addComponent(Camera);
camera.projection = Camera.ProjectionType.PERSPECTIVE; camera.fov = 45; camera.near = 0.1; camera.far = 1000;
camera.clearFlags = Camera.ClearFlag.SOLID_COLOR; camera.clearColor = new Color(28, 36, 52, 255);
const lightNode = new Node('Main Light');
scene.addChild(lightNode); lightNode.setPosition(new Vec3(0, 8, 0)); lightNode.setRotationFromEuler(-45, -30, 0);
lightNode.addComponent(DirectionalLight).illuminance = 55000;

// 1) bones: joint paths resolve with getChildByPath from the skinning root, so write FULL paths
const armature = new Node('Armature');
const bone0 = new Node('bone0'); armature.addChild(bone0);
const bone1 = new Node('bone1'); bone0.addChild(bone1); bone1.setPosition(0, 1.5, 0);
const bone2 = new Node('bone2'); bone1.addChild(bone2); bone2.setPosition(0, 1.5, 0);
const jointPaths = ['bone0', 'bone0/bone1', 'bone0/bone1/bone2'];

// 2) rigidly weighted ribbon: a_position + a_normal (RGB32F), a_joints + a_weights (RGBA32F), stride 56
const ROWS = 9, COLS = 4, SEG = 0.5, X = [-0.25, 0.25, 0.25, -0.25], Z = [-0.25, -0.25, 0.25, 0.25];
const vert = new Float32Array(ROWS * COLS * 14), tri = [];
for (let r = 0; r < ROWS; r++) {
    const y = r * SEG, joint = y < 1.5 ? 0 : (y < 3.0 ? 1 : 2);   // joint INDEX into jointPaths, not a name
    for (let c = 0; c < COLS; c++) {
        const o = (r * COLS + c) * 14;
        vert[o] = X[c]; vert[o + 1] = y; vert[o + 2] = Z[c]; vert[o + 5] = -1;   // normal (0, 0, -1)
        vert[o + 6] = joint; vert[o + 10] = 1;                                  // per-vertex weights sum to 1
        if (r < ROWS - 1) { const c2 = (c + 1) % COLS, a = r * COLS + c, d = (r + 1) * COLS + c, e = (r + 1) * COLS + c2; tri.push(a, d, e, a, e, r * COLS + c2); }
    }
}
const indexData = new Uint16Array(tri); const data = new Uint8Array(vert.byteLength + indexData.byteLength);
data.set(new Uint8Array(vert.buffer), 0); data.set(new Uint8Array(indexData.buffer), vert.byteLength);
const mesh = new Mesh();
mesh.reset({
    struct: {
        vertexBundles: [{ view: { offset: 0, length: vert.byteLength, count: ROWS * COLS, stride: 56 }, attributes: [
            { name: 'a_position', format: gfx.Format.RGB32F, isInstanced: false }, { name: 'a_normal', format: gfx.Format.RGB32F, isInstanced: false },
            { name: 'a_joints', format: gfx.Format.RGBA32F, isInstanced: false }, { name: 'a_weights', format: gfx.Format.RGBA32F, isInstanced: false }] }],
        primitives: [{ primitiveMode: gfx.PrimitiveMode.TRIANGLE_LIST, vertexBundelIndices: [0],
            indexView: { offset: vert.byteLength, length: indexData.byteLength, count: tri.length, stride: 2 } }],
        minPosition: { x: -0.25, y: 0, z: -0.25 }, maxPosition: { x: 0.25, y: (ROWS - 1) * SEG, z: 0.25 },
    },
    data,
});

// 3) bindpose = inverse(bone world matrix right now): capture before any bone is moved
const skeleton = buildSkeletonTree(armature, jointPaths);

// 4) mesh + skeleton + root must all exist before enabling; with no enabled SkeletalAnimation on the
//    root the native association path picks realtime skinning, so live bone edits drive the pose
const renderer = armature.addComponent(SkinnedMeshRenderer);
renderer.enabled = false;
renderer.mesh = mesh; renderer.skeleton = skeleton; renderer.skinningRoot = armature;
const material = new Material();
material.initialize({ effectName: 'builtin-standard' }); material.setProperty('mainColor', new Color(240, 160, 40, 255));
renderer.setSharedMaterial(material, 0);
renderer.enabled = true;
scene.addChild(armature);

// 5) edit real joint nodes; bounds and the joint upload complete on the next engine frame
class TentacleDriver extends Component {
    constructor () { super(); this.t = 0; }
    update (dt) { this.t += dt; bone1.setRotationFromEuler(0, 0, Math.sin(this.t * 1.6) * 40); bone2.setRotationFromEuler(0, 0, Math.sin(this.t * 1.6 + 0.9) * 50); }
}
armature.addComponent(TentacleDriver);
restoreBindPose(armature, skeleton);   // back to the pose buildSkeletonTree captured
frameObject(camera, armature);
app.run(scene);                        // async render loop: frame 1 lands on a later tick

function teardown() { renderer.destroy(); mesh.destroy(); skeleton.destroy(); material.destroy(); }
</script>

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
[
  "build or bind a skeleton from joint paths",
  "a skinned mesh stays in its rest pose",
  "bone edits stop working in baked mode",
  "restore the captured bind pose",
  "morph weight changes appear to be ignored"
]
owns
[
  "skeletal-skinning",
  "joint-paths",
  "bind-pose",
  "baked-pose",
  "joint-capacity",
  "morph-weights"
]
not_for
[
  "glTF loading and decoder deployment -> cocosair-gltf",
  "clip playback and tweens -> cocosair-animation-tween",
  "generic mesh buffer authoring -> cocosair-primitives-mesh"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "配置骨骼路径、蒙皮、绑定姿态、Morph 权重和烘焙动画。用于骨骼变形、绑定姿态恢复或 Morph 问题。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-skinning-morph