Claude Cursor Skill

reduce-draw-calls

Use when a PlayCanvas app has too many draw calls or is CPU-bound, before hand-merging meshes or writing custom renderers.

LLM Mart · 0 points · 1 views 0 listing impressions 0 install-command copies
Download playcanvas-skills-skills_reduce-draw-calls-8fd2b26.zip · 1 KB

Install

skills CLI npx skills add https://github.com/playcanvas/skills/tree/main/skills/reduce-draw-calls
Claude Code claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install playcanvas-skills@llmmart
Git git clone https://github.com/playcanvas/skills.git

The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole playcanvas/skills collection as a plugin from our marketplace. Git is the plain clone.

Skill manifest

Cut draw calls

Measure first with app.stats.drawCallCount or MiniStats; the per-pass app.stats.drawCalls breakdown fills only in profiler builds. Also halve the pixel ratio and call app.resizeCanvas(): if frame time drops, the cost is fill rate, not draw calls. Stop at the first rung that meets the budget and report before-and-after counts.

1. Stop drawing hidden things

An element at opacity 0 still draws. Set enabled = false.

2. BatchManager

Call app.batcher.addGroup(name, dynamic, maxAabbSize), then set batchGroupId on render, sprite, or element components. Use dynamic: false for geometry that never moves. Members join when enabled in the live tree, in any order, and groups regenerate automatically when membership changes. Call markGroupDirty(id) only after moving members of a static group. Manual AppOptions bootstraps must set batchManager.

3. Hardware instancing

Use this for many copies of one mesh and material with per-frame transforms. Build a buffer with VertexFormat.getDefaultInstancingFormat(device), one mat4 per instance, and call meshInstance.setInstancing(vb); instancingCount follows the buffer.

There is no per-instance culling. By default the group always draws; setInstancing(vb, true) culls it as one unit against a RenderComponent#customAabb covering every instance. Split large instance sets into spatial chunks. Custom vertex chunks need the INSTANCING path (override-shader-chunks). Start from the graphics/instancing-basic and graphics/instancing-custom examples.

Confirm the image is unchanged with verify-pixels.

Files (skills)
  • SKILL.md 1.7 KB
    ---
    name: reduce-draw-calls
    description: Use when a PlayCanvas app has too many draw calls or is CPU-bound, before hand-merging meshes or writing custom renderers.
    ---
    
    # Cut draw calls
    
    Measure first with `app.stats.drawCallCount` or `MiniStats`; the per-pass `app.stats.drawCalls`
    breakdown fills only in profiler builds. Also halve the pixel ratio and call `app.resizeCanvas()`:
    if frame time drops, the cost is fill rate, not draw calls. Stop at the first rung that meets the
    budget and report before-and-after counts.
    
    ## 1. Stop drawing hidden things
    
    An element at opacity 0 still draws. Set `enabled = false`.
    
    ## 2. BatchManager
    
    Call `app.batcher.addGroup(name, dynamic, maxAabbSize)`, then set `batchGroupId` on render, sprite,
    or element components. Use `dynamic: false` for geometry that never moves. Members join when
    enabled in the live tree, in any order, and groups regenerate automatically when membership
    changes. Call `markGroupDirty(id)` only after moving members of a static group. Manual `AppOptions`
    bootstraps must set `batchManager`.
    
    ## 3. Hardware instancing
    
    Use this for many copies of one mesh and material with per-frame transforms. Build a buffer with
    `VertexFormat.getDefaultInstancingFormat(device)`, one mat4 per instance, and call
    `meshInstance.setInstancing(vb)`; `instancingCount` follows the buffer.
    
    There is no per-instance culling. By default the group always draws; `setInstancing(vb, true)`
    culls it as one unit against a `RenderComponent#customAabb` covering every instance. Split large
    instance sets into spatial chunks. Custom vertex chunks need the `INSTANCING` path
    (`override-shader-chunks`). Start from the `graphics/instancing-basic` and
    `graphics/instancing-custom` examples.
    
    Confirm the image is unchanged with `verify-pixels`.
    

Comments (0)

Sign in to join the conversation.

No comments yet.

Reviews (0)

No reviews yet.