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

/cocosair-materials-effects

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Configure materials, effects, uniforms, defines and GLSL. Diagnose black/invisible effects, missing textures, setProperty, AIR_E_MATERIAL_NOT_READY or AIR_E_MATERIAL_TYPE.

  • 12 files
  • 116 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-materials-effects

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencesquick-start.md

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

Derived from the cocosair-materials-effects 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, MeshRenderer, Material,
         Texture2D, ImageAsset, Layers, Vec3, Vec4, Color, primitives, utils,
         inspectAirMaterial } from 'cocosair'; // page alias, not the package name

const app = await createAirApp({ canvas: '#GameCanvas' }); // device first: passes need root.device
const scene = new Scene('materials');

const camNode = new Node('Main Camera');
scene.addChild(camNode); camNode.setPosition(new Vec3(0, 1.8, 6.5)); camNode.lookAt(new Vec3(0, 0.6, 0));
const camera = camNode.addComponent(Camera);
camera.projection = Camera.ProjectionType.PERSPECTIVE; camera.visibility = Layers.Enum.DEFAULT;

const texture = new Texture2D(); // procedural source, no asset files
texture.image = new ImageAsset({ width: 8, height: 8, _data: new Uint8Array(8 * 8 * 4).fill(255), _compressed: false, format: Texture2D.PixelFormat.RGBA8888 });

function addCube (name, x, init, configure) {
    const node = new Node(name); node.layer = Layers.Enum.DEFAULT; scene.addChild(node);
    node.setPosition(new Vec3(x, 0.7, 0));
    const renderer = node.addComponent(MeshRenderer);
    renderer.mesh = utils.createMesh(primitives.box({ width: 1.1, height: 1.1, length: 1.1 }));
    const material = new Material();          // one instance per object: never mutate a shared builtin
    material.initialize(init); configure(material); // defines must be complete at initialize
    renderer.setSharedMaterial(material, 0);  // shared reference: setProperty on `material` drives pixels
    return material;
}

addCube('lit', -2.2, { effectName: 'builtin-standard' }, (m) => {
    m.setProperty('mainColor', new Color(90, 200, 220, 255)); // bytes 0-255, written as 0-1 fractions
    m.setProperty('metallic', 0.0); m.setProperty('roughness', 0.35); // float uniforms take plain numbers
});
addCube('flat', 0, { effectName: 'builtin-unlit' }, (m) => m.setProperty('mainColor', new Color(230, 120, 60, 255)));
const mapped = addCube('mapped', 2.2, { effectName: 'builtin-unlit', defines: { USE_TEXTURE: true } }, (m) => {
    m.setProperty('mainTexture', texture);   // without the macro the write succeeds and the map is never sampled
    m.setProperty('tilingOffset', new Vec4(2, 2, 0, 0)); // x/y tiling, z/w offset
});

console.log(inspectAirMaterial(mapped));      // one frozen record per pass: program, depth/blend/cull, bound textures
app.run(scene);
</script>

Entry choice and the importmap alias belong to cocosair-project-setup; createAirApp and run to cocosair-application.

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
[
  "setProperty changes nothing",
  "texture missing after setProperty",
  "different colors for each renderer",
  "change blend or depth state",
  "custom GLSL shader fails"
]
owns
[
  "material",
  "effect",
  "uniform-types",
  "shader-defines",
  "custom-glsl",
  "material-instance"
]
not_for
[
  "lighting, shadows or post-process -> cocosair-rendering",
  "glTF material import -> cocosair-gltf",
  "mesh geometry and sub-models -> cocosair-primitives-mesh"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "配置材质、效果、属性类型、宏和自定义 GLSL。用于 USE_TEXTURE、uniform 类型、效果初始化或材质诊断问题。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-materials-effects