@docyrus/animaguru 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.md +256 -0
- package/README.md +241 -0
- package/dist/animaguru.js +27338 -0
- package/package.json +37 -0
- package/skills/animaguru/SKILL.md +115 -0
- package/skills/animaguru-advertising/SKILL.md +25 -0
- package/skills/animaguru-advertising/references/brand-bumper.md +11 -0
- package/skills/animaguru-advertising/references/comparison.md +11 -0
- package/skills/animaguru-advertising/references/creator-testimonial.md +11 -0
- package/skills/animaguru-advertising/references/editorial-advertorial.md +11 -0
- package/skills/animaguru-advertising/references/game-reward.md +11 -0
- package/skills/animaguru-advertising/references/offer-promotion.md +11 -0
- package/skills/animaguru-advertising/references/product-launch.md +11 -0
- package/skills/animaguru-advertising/references/product-proof.md +11 -0
- package/skills/animaguru-analog-film-tape/SKILL.md +29 -0
- package/skills/animaguru-analog-film-tape/references/recipe.md +23 -0
- package/skills/animaguru-animated-data-visualization/SKILL.md +39 -0
- package/skills/animaguru-animated-data-visualization/references/data-contract.md +16 -0
- package/skills/animaguru-animated-data-visualization/references/variants.md +17 -0
- package/skills/animaguru-art-deco-motion/SKILL.md +29 -0
- package/skills/animaguru-art-deco-motion/references/recipe.md +22 -0
- package/skills/animaguru-ascii-crt/SKILL.md +29 -0
- package/skills/animaguru-ascii-crt/references/recipe.md +22 -0
- package/skills/animaguru-blueprint-drafting/SKILL.md +29 -0
- package/skills/animaguru-blueprint-drafting/references/recipe.md +22 -0
- package/skills/animaguru-cartoon-character-animation/SKILL.md +35 -0
- package/skills/animaguru-cartoon-character-animation/references/variants.md +17 -0
- package/skills/animaguru-cutout-animation/SKILL.md +33 -0
- package/skills/animaguru-cutout-animation/references/production-recipe.md +37 -0
- package/skills/animaguru-cutout-animation/references/variants.md +17 -0
- package/skills/animaguru-cutout-animation/references/visual-style.md +34 -0
- package/skills/animaguru-dark-tech-stage/SKILL.md +29 -0
- package/skills/animaguru-dark-tech-stage/references/recipe.md +23 -0
- package/skills/animaguru-diagram-formula-motion/SKILL.md +36 -0
- package/skills/animaguru-diagram-formula-motion/references/variants.md +17 -0
- package/skills/animaguru-engraved-relief-print/SKILL.md +29 -0
- package/skills/animaguru-engraved-relief-print/references/recipe.md +24 -0
- package/skills/animaguru-flat-vector-motion/SKILL.md +35 -0
- package/skills/animaguru-flat-vector-motion/references/variants.md +17 -0
- package/skills/animaguru-general-video/SKILL.md +20 -0
- package/skills/animaguru-general-video/references/ambient-loop.md +11 -0
- package/skills/animaguru-general-video/references/music-lyrics.md +11 -0
- package/skills/animaguru-general-video/references/short-film.md +11 -0
- package/skills/animaguru-general-video/references/titles-event.md +11 -0
- package/skills/animaguru-general-video/references/visual-essay.md +11 -0
- package/skills/animaguru-generative-light-signal/SKILL.md +29 -0
- package/skills/animaguru-generative-light-signal/references/recipe.md +23 -0
- package/skills/animaguru-glass-mosaic/SKILL.md +29 -0
- package/skills/animaguru-glass-mosaic/references/recipe.md +23 -0
- package/skills/animaguru-halftone-editorial/SKILL.md +29 -0
- package/skills/animaguru-halftone-editorial/references/recipe.md +23 -0
- package/skills/animaguru-holographic-scan/SKILL.md +29 -0
- package/skills/animaguru-holographic-scan/references/recipe.md +22 -0
- package/skills/animaguru-interface-motion/SKILL.md +36 -0
- package/skills/animaguru-interface-motion/references/screen-mapping.md +16 -0
- package/skills/animaguru-interface-motion/references/variants.md +17 -0
- package/skills/animaguru-isometric-worlds/SKILL.md +35 -0
- package/skills/animaguru-isometric-worlds/references/variants.md +17 -0
- package/skills/animaguru-kinetic-typography/SKILL.md +35 -0
- package/skills/animaguru-kinetic-typography/references/variants.md +17 -0
- package/skills/animaguru-miniature-diorama/SKILL.md +29 -0
- package/skills/animaguru-miniature-diorama/references/recipe.md +23 -0
- package/skills/animaguru-painterly-depth-animation/SKILL.md +35 -0
- package/skills/animaguru-painterly-depth-animation/references/variants.md +17 -0
- package/skills/animaguru-paper-popup/SKILL.md +29 -0
- package/skills/animaguru-paper-popup/references/recipe.md +22 -0
- package/skills/animaguru-photo-footage-editorial/SKILL.md +29 -0
- package/skills/animaguru-photo-footage-editorial/references/recipe.md +23 -0
- package/skills/animaguru-pixel-art-animation/SKILL.md +36 -0
- package/skills/animaguru-pixel-art-animation/references/variants.md +17 -0
- package/skills/animaguru-portal-zoom/SKILL.md +29 -0
- package/skills/animaguru-portal-zoom/references/recipe.md +21 -0
- package/skills/animaguru-risograph-print/SKILL.md +29 -0
- package/skills/animaguru-risograph-print/references/recipe.md +23 -0
- package/skills/animaguru-sand-drawing/SKILL.md +29 -0
- package/skills/animaguru-sand-drawing/references/recipe.md +21 -0
- package/skills/animaguru-shadow-theatre/SKILL.md +29 -0
- package/skills/animaguru-shadow-theatre/references/recipe.md +23 -0
- package/skills/animaguru-silkscreen-poster/SKILL.md +29 -0
- package/skills/animaguru-silkscreen-poster/references/recipe.md +22 -0
- package/skills/animaguru-stop-motion-objects/SKILL.md +29 -0
- package/skills/animaguru-stop-motion-objects/references/recipe.md +23 -0
- package/skills/animaguru-studio-product-reveal/SKILL.md +29 -0
- package/skills/animaguru-studio-product-reveal/references/recipe.md +23 -0
- package/skills/animaguru-video/SKILL.md +79 -0
- package/skills/animaguru-whiteboard-line-drawing/SKILL.md +34 -0
- package/skills/animaguru-whiteboard-line-drawing/references/variants.md +17 -0
- package/templates/video/AGENTS.md +34 -0
- package/templates/video/CLAUDE.md +19 -0
- package/templates/video/README.md +101 -0
- package/templates/video/VIDEO-STYLE-NOTICES.txt +54 -0
- package/templates/video/film.config.json +10 -0
- package/templates/video/gitignore +11 -0
- package/templates/video/index.html +14 -0
- package/templates/video/package.json +28 -0
- package/templates/video/public/brand/logo-mark.svg +5 -0
- package/templates/video/scripts/build.mjs +12 -0
- package/templates/video/scripts/export-html.mjs +12 -0
- package/templates/video/scripts/export-mp4.mjs +209 -0
- package/templates/video/scripts/html-export-plugin.mjs +35 -0
- package/templates/video/scripts/html-export.mjs +54 -0
- package/templates/video/scripts/install-example.mjs +32 -0
- package/templates/video/scripts/review-analysis.mjs +29 -0
- package/templates/video/scripts/review-audio.mjs +24 -0
- package/templates/video/scripts/review.mjs +37 -0
- package/templates/video/scripts/starter-film.sha256 +1 -0
- package/templates/video/shared/locales/en/export.json +10 -0
- package/templates/video/shared/locales/en/film.json +42 -0
- package/templates/video/shared/locales/en/player.json +31 -0
- package/templates/video/shared/locales/en/style-studies.json +168 -0
- package/templates/video/shared/locales/en/timeline.json +33 -0
- package/templates/video/src/assets.ts +4 -0
- package/templates/video/src/download.ts +27 -0
- package/templates/video/src/exporter.ts +70 -0
- package/templates/video/src/film-resources.ts +29 -0
- package/templates/video/src/film.ts +132 -0
- package/templates/video/src/main.ts +219 -0
- package/templates/video/src/resource-timeline.ts +193 -0
- package/templates/video/src/review.ts +50 -0
- package/templates/video/src/studies/film.ts +26 -0
- package/templates/video/src/studies/media.ts +46 -0
- package/templates/video/src/studies/model.ts +60 -0
- package/templates/video/src/studies/pixi-renderer.ts +121 -0
- package/templates/video/src/studies/scenes.ts +410 -0
- package/templates/video/src/studies/timing.ts +53 -0
- package/templates/video/src/studies/variants.ts +39 -0
- package/templates/video/src/style.css +111 -0
- package/templates/video/src/timeline-model.ts +55 -0
- package/templates/video/style-source-provenance.json +11 -0
- package/templates/video/tsconfig.json +15 -0
- package/templates/video/vite.config.mjs +9 -0
- package/vendor/pixijs-skills/LICENSE +21 -0
- package/vendor/pixijs-skills/provenance.json +79 -0
- package/vendor/pixijs-skills/skills/pixijs/SKILL.md +66 -0
- package/vendor/pixijs-skills/skills/pixijs/references/index.md +136 -0
- package/vendor/pixijs-skills/skills/pixijs-accessibility/SKILL.md +224 -0
- package/vendor/pixijs-skills/skills/pixijs-application/SKILL.md +293 -0
- package/vendor/pixijs-skills/skills/pixijs-application/references/application-options.md +314 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/SKILL.md +303 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/background.md +137 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/bundles.md +122 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/caching.md +143 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/compressed-textures.md +120 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/fonts.md +205 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/gif.md +171 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/manifests.md +175 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/progress.md +142 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/resolution.md +142 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/spritesheet.md +119 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/svg.md +132 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/video.md +158 -0
- package/vendor/pixijs-skills/skills/pixijs-blend-modes/SKILL.md +215 -0
- package/vendor/pixijs-skills/skills/pixijs-color/SKILL.md +299 -0
- package/vendor/pixijs-skills/skills/pixijs-core-concepts/SKILL.md +132 -0
- package/vendor/pixijs-skills/skills/pixijs-core-concepts/references/render-loop.md +216 -0
- package/vendor/pixijs-skills/skills/pixijs-core-concepts/references/renderers.md +287 -0
- package/vendor/pixijs-skills/skills/pixijs-create/SKILL.md +276 -0
- package/vendor/pixijs-skills/skills/pixijs-custom-rendering/SKILL.md +405 -0
- package/vendor/pixijs-skills/skills/pixijs-custom-rendering/references/advanced-gpu.md +244 -0
- package/vendor/pixijs-skills/skills/pixijs-custom-rendering/references/uniform-types.md +94 -0
- package/vendor/pixijs-skills/skills/pixijs-environments/SKILL.md +243 -0
- package/vendor/pixijs-skills/skills/pixijs-events/SKILL.md +387 -0
- package/vendor/pixijs-skills/skills/pixijs-filters/SKILL.md +300 -0
- package/vendor/pixijs-skills/skills/pixijs-html-source/SKILL.md +228 -0
- package/vendor/pixijs-skills/skills/pixijs-math/SKILL.md +489 -0
- package/vendor/pixijs-skills/skills/pixijs-migration-v8/SKILL.md +415 -0
- package/vendor/pixijs-skills/skills/pixijs-performance/SKILL.md +489 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-container/SKILL.md +345 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/SKILL.md +243 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/constructor-options.md +155 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/container-hierarchy.md +232 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/layers.md +145 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/masking.md +129 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/render-groups.md +140 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/scene-management.md +169 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/transforms.md +198 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-dom-container/SKILL.md +193 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-gif/SKILL.md +233 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-graphics/SKILL.md +576 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/SKILL.md +141 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh-perspective.md +189 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh-plane.md +159 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh-rope.md +176 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh-simple.md +144 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh.md +213 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-particle-container/SKILL.md +323 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/SKILL.md +120 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/references/animated-sprite.md +262 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/references/nineslice-sprite.md +202 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/references/sprite.md +181 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/references/tiling-sprite.md +216 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/SKILL.md +136 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/bitmap-text.md +232 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/html-text.md +192 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/split-bitmap-text.md +187 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/split-text.md +168 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/text.md +311 -0
- package/vendor/pixijs-skills/skills/pixijs-ticker/SKILL.md +292 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# MeshSimple
|
|
2
|
+
|
|
3
|
+
A thin `Mesh` subclass that handles geometry construction for you. Pass `vertices`, optional `uvs`, and optional `indices`, and it builds the `MeshGeometry` internally and auto-updates the vertex buffer each frame. Use `MeshSimple` for quick textured quads, triangles, or any shape where you plan to animate vertex positions.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const texture = await Assets.load("sprite.png");
|
|
9
|
+
|
|
10
|
+
const triangle = new MeshSimple({
|
|
11
|
+
texture,
|
|
12
|
+
vertices: new Float32Array([0, 0, 100, 0, 50, 100]),
|
|
13
|
+
uvs: new Float32Array([0, 0, 1, 0, 0.5, 1]),
|
|
14
|
+
topology: "triangle-list",
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
app.stage.addChild(triangle);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`MeshSimple` wraps `MeshGeometry` creation, exposes `vertices` directly, and auto-updates the position buffer each frame via `onRender`.
|
|
21
|
+
|
|
22
|
+
## Constructor options
|
|
23
|
+
|
|
24
|
+
`new MeshSimple(options: SimpleMeshOptions)`
|
|
25
|
+
|
|
26
|
+
| Option | Type | Default | Description |
|
|
27
|
+
| ---------- | -------------- | ----------------- | --------------------------------------------------------------------------------------------------------------------- |
|
|
28
|
+
| `texture` | `Texture` | — | Texture sampled by the mesh. Required. |
|
|
29
|
+
| `vertices` | `Float32Array` | `undefined` | Flat `x, y` pairs for each vertex. Passed through to `MeshGeometry` as `positions`. |
|
|
30
|
+
| `uvs` | `Float32Array` | `undefined` | Flat `u, v` pairs matching `vertices`. Without UVs the geometry fills zeros and the mesh samples only pixel `(0, 0)`. |
|
|
31
|
+
| `indices` | `Uint32Array` | `undefined` | Triangle indices into `vertices`. Omit for unindexed rendering in vertex order. |
|
|
32
|
+
| `topology` | `Topology` | `'triangle-list'` | `'triangle-list' \| 'triangle-strip' \| 'line-list' \| 'line-strip' \| 'point-list'`. |
|
|
33
|
+
|
|
34
|
+
`MeshSimple` builds its own `MeshGeometry`, so `geometry` is omitted from the options type. Note the option is named `vertices` here (converted to `positions` internally), matching the `mesh.vertices` getter. Other `MeshOptions` fields (`shader`, `state`, `roundPixels`) are inherited from `mesh.md` and behave identically.
|
|
35
|
+
|
|
36
|
+
All `Container` options (`position`, `scale`, `tint`, `label`, `filters`, `zIndex`, etc.) are also valid here — see `skills/pixijs-scene-core-concepts/references/constructor-options.md`.
|
|
37
|
+
|
|
38
|
+
`autoUpdate` is a runtime property (defaults to `true`), not a constructor option. Set `mesh.autoUpdate = false` after construction to suppress the per-frame position-buffer upload.
|
|
39
|
+
|
|
40
|
+
## Core Patterns
|
|
41
|
+
|
|
42
|
+
### Animated vertices
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
app.ticker.add(() => {
|
|
46
|
+
const verts = triangle.vertices;
|
|
47
|
+
verts[5] = 100 + Math.sin(performance.now() / 500) * 20;
|
|
48
|
+
triangle.vertices = verts;
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Because `autoUpdate` defaults to `true`, assigning to `vertices` or mutating the array in place is enough; the buffer is pushed to the GPU automatically during the next render pass.
|
|
53
|
+
|
|
54
|
+
### Indexed quad
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
const quad = new MeshSimple({
|
|
58
|
+
texture,
|
|
59
|
+
vertices: new Float32Array([0, 0, 100, 0, 100, 100, 0, 100]),
|
|
60
|
+
uvs: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
|
|
61
|
+
indices: new Uint32Array([0, 1, 2, 0, 2, 3]),
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Indices are optional; omit them and the mesh uses unindexed vertex order. Useful for a small, simple shape where explicit indexing adds no value.
|
|
66
|
+
|
|
67
|
+
### Manual update mode
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
triangle.autoUpdate = false;
|
|
71
|
+
|
|
72
|
+
app.ticker.add(() => {
|
|
73
|
+
const verts = triangle.vertices;
|
|
74
|
+
verts[1] = Math.sin(performance.now() / 1000) * 20;
|
|
75
|
+
triangle.vertices = verts;
|
|
76
|
+
triangle.geometry.getBuffer("aPosition").update();
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Set `autoUpdate = false` when you want explicit control over when the GPU sees new vertex data; for example, when you only update once per several frames, or when you want to batch multiple vertex mutations before a single upload.
|
|
81
|
+
|
|
82
|
+
### Alternative topologies
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
const lineStrip = new MeshSimple({
|
|
86
|
+
texture,
|
|
87
|
+
vertices: new Float32Array([0, 0, 50, 50, 100, 0, 150, 50]),
|
|
88
|
+
topology: "line-strip",
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`MeshSimple` accepts any topology supported by `MeshGeometry` (`'triangle-list'`, `'triangle-strip'`, `'line-list'`, `'line-strip'`, `'point-list'`). The default is `'triangle-list'`.
|
|
93
|
+
|
|
94
|
+
## Common Mistakes
|
|
95
|
+
|
|
96
|
+
### [HIGH] Using the old `SimpleMesh` name
|
|
97
|
+
|
|
98
|
+
Wrong:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { SimpleMesh } from "pixi.js";
|
|
102
|
+
const mesh = new SimpleMesh(texture, vertices, uvs, indices);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Correct:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import { MeshSimple } from "pixi.js";
|
|
109
|
+
const mesh = new MeshSimple({ texture, vertices, uvs, indices });
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
`SimpleMesh` was renamed to `MeshSimple` in v8. The old name is not exported; the class also switched to an options-object constructor.
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
### [MEDIUM] Forgetting UVs on a textured mesh
|
|
116
|
+
|
|
117
|
+
Wrong:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
const mesh = new MeshSimple({
|
|
121
|
+
texture,
|
|
122
|
+
vertices: new Float32Array([0, 0, 100, 0, 50, 100]),
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Correct:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
const mesh = new MeshSimple({
|
|
130
|
+
texture,
|
|
131
|
+
vertices: new Float32Array([0, 0, 100, 0, 50, 100]),
|
|
132
|
+
uvs: new Float32Array([0, 0, 1, 0, 0.5, 1]),
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Omitting `uvs` makes the underlying `MeshGeometry` fill a zero array, sampling only pixel `(0, 0)` of the texture. Always provide UVs when you want the texture to map across the geometry.
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
## API Reference
|
|
140
|
+
|
|
141
|
+
- [MeshSimple](https://pixijs.download/release/docs/scene.MeshSimple.html.md)
|
|
142
|
+
- [SimpleMeshOptions](https://pixijs.download/release/docs/scene.SimpleMeshOptions.html.md)
|
|
143
|
+
- [Mesh](https://pixijs.download/release/docs/scene.Mesh.html.md)
|
|
144
|
+
- [MeshGeometry](https://pixijs.download/release/docs/scene.MeshGeometry.html.md)
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# Mesh
|
|
2
|
+
|
|
3
|
+
The base mesh class. Combines a `Geometry` (vertex positions, UVs, indices, topology) with a `Texture` or custom `Shader` to render arbitrary 2D (or perspective-projected) graphics. Use `Mesh` when you need vertex-level control, custom shaders, or batched draw calls for geometry that doesn't fit the Sprite / Graphics / Particle model.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const texture = await Assets.load("pattern.png");
|
|
9
|
+
|
|
10
|
+
const geometry = new MeshGeometry({
|
|
11
|
+
positions: new Float32Array([0, 0, 100, 0, 100, 100, 0, 100]),
|
|
12
|
+
uvs: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
|
|
13
|
+
indices: new Uint32Array([0, 1, 2, 0, 2, 3]),
|
|
14
|
+
topology: "triangle-list",
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const mesh = new Mesh({
|
|
18
|
+
geometry,
|
|
19
|
+
texture,
|
|
20
|
+
roundPixels: false,
|
|
21
|
+
});
|
|
22
|
+
app.stage.addChild(mesh);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`Mesh` is a leaf; `allowChildren` is `false`. It owns a reference to its geometry (shareable across meshes) and either a texture or a custom shader.
|
|
26
|
+
|
|
27
|
+
## Constructor options
|
|
28
|
+
|
|
29
|
+
`new Mesh<GEOMETRY, SHADER>(options: MeshOptions<GEOMETRY, SHADER>)`
|
|
30
|
+
|
|
31
|
+
| Option | Type | Default | Description |
|
|
32
|
+
| ------------- | ------------------------------- | --------------- | ------------------------------------------------------------------------------------------------------- |
|
|
33
|
+
| `geometry` | `GEOMETRY extends Geometry` | — | Vertex buffers, indices, UVs, and topology. Required. Shareable across meshes. |
|
|
34
|
+
| `shader` | `SHADER extends Shader \| null` | `null` | Custom vertex/fragment shader. When set, the mesh skips batching and the shader decides what to sample. |
|
|
35
|
+
| `state` | `State` | `State.for2d()` | GPU state (blend, depth, culling). Depth or culling flags disable batching. |
|
|
36
|
+
| `texture` | `Texture` | `Texture.WHITE` | Texture sampled by the default shader. Ignored if a custom `shader` provides its own texture. |
|
|
37
|
+
| `roundPixels` | `boolean` | `false` | Snap `x`/`y` to integer pixels at render time. |
|
|
38
|
+
|
|
39
|
+
All `Container` options (`position`, `scale`, `tint`, `label`, `filters`, `zIndex`, etc.) are also valid here — see `skills/pixijs-scene-core-concepts/references/constructor-options.md`.
|
|
40
|
+
|
|
41
|
+
The constructor assigns `texture` from `shader.texture` when a custom shader is passed without an explicit `texture` option. Passing `null`/`undefined` to the `texture` setter at runtime coerces it to `Texture.EMPTY`.
|
|
42
|
+
|
|
43
|
+
## Core Patterns
|
|
44
|
+
|
|
45
|
+
### MeshGeometry anatomy
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
const geometry = new MeshGeometry({
|
|
49
|
+
positions: new Float32Array([
|
|
50
|
+
0,
|
|
51
|
+
0, // vertex 0: x, y
|
|
52
|
+
100,
|
|
53
|
+
0, // vertex 1
|
|
54
|
+
100,
|
|
55
|
+
100, // vertex 2
|
|
56
|
+
0,
|
|
57
|
+
100, // vertex 3
|
|
58
|
+
]),
|
|
59
|
+
uvs: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
|
|
60
|
+
indices: new Uint32Array([0, 1, 2, 0, 2, 3]),
|
|
61
|
+
topology: "triangle-list",
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
- `positions`: flat x,y pairs in local space.
|
|
66
|
+
- `uvs`: flat u,v pairs in `[0, 1]` texture space. If omitted, defaults to zero-filled.
|
|
67
|
+
- `indices`: triangle indices. If omitted, defaults to a quad `[0, 1, 2, 0, 2, 3]`.
|
|
68
|
+
- `topology`: how indices are interpreted (see below).
|
|
69
|
+
|
|
70
|
+
After construction, read or replace the typed arrays via the getters `geometry.positions`, `geometry.uvs`, `geometry.indices`. They return the underlying buffers' `data` directly; mutating in place is equivalent to mutating `getBuffer('aPosition').data`.
|
|
71
|
+
|
|
72
|
+
### Topology
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
new MeshGeometry({ positions, uvs, indices, topology: "triangle-list" });
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Five topology types:
|
|
79
|
+
|
|
80
|
+
| Topology | Meaning |
|
|
81
|
+
| --------------------------- | ------------------------------------------------ |
|
|
82
|
+
| `'triangle-list'` (default) | Every 3 indices form one triangle |
|
|
83
|
+
| `'triangle-strip'` | Each new index extends the strip by one triangle |
|
|
84
|
+
| `'line-list'` | Pairs of indices form independent lines |
|
|
85
|
+
| `'line-strip'` | Connected line segments |
|
|
86
|
+
| `'point-list'` | Each index renders a point |
|
|
87
|
+
|
|
88
|
+
Topology is set on the **geometry**, not the mesh. The default is `'triangle-list'`; any other data layout needs an explicit topology or the mesh renders garbage.
|
|
89
|
+
|
|
90
|
+
### Batching
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
geometry.batchMode = "auto"; // default
|
|
94
|
+
geometry.batchMode = "batch"; // always batched
|
|
95
|
+
geometry.batchMode = "no-batch"; // never batched
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
A mesh is batched (combined with other draw calls) only when:
|
|
99
|
+
|
|
100
|
+
- It uses `MeshGeometry` (not a custom geometry subclass).
|
|
101
|
+
- It has no custom `shader`.
|
|
102
|
+
- Its `state` has no depth test or culling.
|
|
103
|
+
- The `'auto'` rule: geometry has 100 or fewer vertices.
|
|
104
|
+
|
|
105
|
+
Custom shaders always render independently. For large static meshes, set `batchMode = 'no-batch'` to skip the batch-eligibility check overhead.
|
|
106
|
+
|
|
107
|
+
### Custom shader
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { Shader } from "pixi.js";
|
|
111
|
+
|
|
112
|
+
const shader = Shader.from({
|
|
113
|
+
gl: { vertex: vertSrc, fragment: fragSrc },
|
|
114
|
+
resources: { uTexture: texture.source, uSampler: texture.source.style },
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const mesh = new Mesh({ geometry, shader });
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
When a shader is provided, `texture` is optional; the shader decides what to sample. Custom shaders bypass batching entirely. See the `pixijs-custom-rendering` skill for full shader authoring detail.
|
|
121
|
+
|
|
122
|
+
### Shared geometry
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
const sharedGeom = new MeshGeometry({ positions, uvs, indices });
|
|
126
|
+
|
|
127
|
+
const mesh1 = new Mesh({ geometry: sharedGeom, texture: tex1 });
|
|
128
|
+
const mesh2 = new Mesh({ geometry: sharedGeom, texture: tex2 });
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Geometry is reference-counted. Multiple meshes can share one geometry, saving memory for instances that share a shape but differ in transform or texture.
|
|
132
|
+
|
|
133
|
+
### Updating vertices at runtime
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
mesh.geometry.positions[1] = Math.sin(performance.now() / 500) * 20;
|
|
137
|
+
mesh.geometry.getBuffer("aPosition").update();
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`MeshGeometry` exposes `positions`, `uvs`, and `indices` getters that return the underlying `Float32Array` / `Uint32Array` directly; they point at the same data as `getBuffer('aPosition').data` / `getBuffer('aUV').data` / `getIndex().data`. Mutate in place for the common case, or assign a whole new array via the setter (the setters do `buffer.data = value` with no length check; the real invariant is `uvs.length >= positions.length` so every vertex has a UV).
|
|
141
|
+
|
|
142
|
+
Call `update()` on the buffer after mutating its `data` array to push changes to the GPU. For auto-update behavior, use `MeshSimple` which handles this for you.
|
|
143
|
+
|
|
144
|
+
## Common Mistakes
|
|
145
|
+
|
|
146
|
+
### [HIGH] Positional constructor args
|
|
147
|
+
|
|
148
|
+
Wrong:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
const mesh = new Mesh(geometry, shader);
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Correct:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
const mesh = new Mesh({ geometry, shader });
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
v8 uses an options object. The positional form is deprecated and logs a warning. Note also that the `drawMode` argument was removed; use `geometry.topology` instead.
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
### [HIGH] `vertices` instead of `positions`
|
|
164
|
+
|
|
165
|
+
Wrong:
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
const geometry = new MeshGeometry({
|
|
169
|
+
vertices: new Float32Array([0, 0, 100, 0, 50, 100]),
|
|
170
|
+
});
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Correct:
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
const geometry = new MeshGeometry({
|
|
177
|
+
positions: new Float32Array([0, 0, 100, 0, 50, 100]),
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The `MeshGeometry` option is `positions`. `vertices` is the convenience name used only by `MeshSimple`, where it's converted internally.
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
### [MEDIUM] Forgetting to set topology
|
|
185
|
+
|
|
186
|
+
Wrong:
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
const geometry = new MeshGeometry({
|
|
190
|
+
positions: stripPositions,
|
|
191
|
+
indices: stripIndices,
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Correct:
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
const geometry = new MeshGeometry({
|
|
199
|
+
positions: stripPositions,
|
|
200
|
+
indices: stripIndices,
|
|
201
|
+
topology: "triangle-strip",
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
The default topology is `'triangle-list'`. If your data is organized as a strip or line list, the mesh renders garbage without an explicit topology.
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
## API Reference
|
|
209
|
+
|
|
210
|
+
- [Mesh](https://pixijs.download/release/docs/scene.Mesh.html.md)
|
|
211
|
+
- [MeshOptions](https://pixijs.download/release/docs/scene.MeshOptions.html.md)
|
|
212
|
+
- [MeshGeometry](https://pixijs.download/release/docs/scene.MeshGeometry.html.md)
|
|
213
|
+
- [MeshGeometryOptions](https://pixijs.download/release/docs/scene.MeshGeometryOptions.html.md)
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pixijs-scene-particle-container
|
|
3
|
+
description: "Use this skill when rendering thousands of lightweight sprites in PixiJS v8. Covers ParticleContainer with Particle instances, addParticle/removeParticle, particleChildren array, dynamicProperties (vertex, position, rotation, uvs, color), boundsArea, roundPixels, update, inherited alpha/tint/blendMode from ancestors. Triggers on: ParticleContainer, Particle, IParticle, addParticle, particleChildren, dynamicProperties, boundsArea, particle effects, particle alpha, particle tint, fade particles, constructor options, ParticleContainerOptions, ParticleOptions."
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
`ParticleContainer` is a specialized container for rendering hundreds to tens of thousands of lightweight sprites in a single draw call. Use it for particle effects, bullet patterns, or any case where you need a large number of similar-looking objects with minimal per-object overhead. Particles share a single base texture and have a restricted transform set; they are not full `Container` children.
|
|
8
|
+
|
|
9
|
+
Assumes familiarity with `pixijs-scene-core-concepts`. `ParticleContainer` is a special leaf in a different sense: it contains `Particle` instances in its own `particleChildren` array and rejects normal PixiJS children. Use `addParticle`, not `addChild`, and wrap the whole `ParticleContainer` in a `Container` if you need to group it with other scene objects.
|
|
10
|
+
|
|
11
|
+
The Particle API is new in v8 but is stable for production use.
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
const texture = await Assets.load("particle.png");
|
|
17
|
+
|
|
18
|
+
const container = new ParticleContainer({
|
|
19
|
+
texture,
|
|
20
|
+
boundsArea: new Rectangle(0, 0, app.screen.width, app.screen.height),
|
|
21
|
+
dynamicProperties: {
|
|
22
|
+
position: true,
|
|
23
|
+
rotation: false,
|
|
24
|
+
color: false,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
for (let i = 0; i < 10000; i++) {
|
|
29
|
+
container.addParticle(
|
|
30
|
+
new Particle({
|
|
31
|
+
texture,
|
|
32
|
+
x: Math.random() * app.screen.width,
|
|
33
|
+
y: Math.random() * app.screen.height,
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
app.stage.addChild(container);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Related skills:** `pixijs-scene-core-concepts` (scene graph basics), `pixijs-scene-sprite` (when you need full features per object), `pixijs-assets` (shared textures, atlases), `pixijs-performance` (batching, texture optimization), `pixijs-scene-container` (wrap with other display objects).
|
|
42
|
+
|
|
43
|
+
## Constructor options
|
|
44
|
+
|
|
45
|
+
### ParticleContainerOptions
|
|
46
|
+
|
|
47
|
+
All `Container` options (`position`, `scale`, `tint`, `label`, `filters`, `zIndex`, etc.) are also valid here — see `skills/pixijs-scene-core-concepts/references/constructor-options.md`. Note that `children` is omitted: use `particles` instead.
|
|
48
|
+
|
|
49
|
+
| Option | Type | Default | Description |
|
|
50
|
+
| ------------------- | -------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
51
|
+
| `texture` | `Texture` | `null` | Shared base texture for all particles. If omitted, the container falls back to the texture of the first particle added; every particle must share the same base texture source. |
|
|
52
|
+
| `particles` | `T[]` | `[]` | Initial array of `Particle` (or `IParticle`) instances. Equivalent to calling `addParticle` for each, but skips per-call view updates. |
|
|
53
|
+
| `dynamicProperties` | `ParticleProperties` | `{ vertex: false, position: true, rotation: false, uvs: false, color: false }` | Flags for which particle attributes re-upload to the GPU every frame. Only `position` is dynamic by default; mark what you animate, leave the rest static for speed. |
|
|
54
|
+
| `roundPixels` | `boolean` | `false` | Rounds particle positions to the nearest pixel. Produces crisper rendering for pixel-art styles at the cost of smooth sub-pixel motion. |
|
|
55
|
+
| `shader` | `Shader` | default particle shader | Replaces the default particle shader. The custom shader must declare `aPosition`, `aUV`, `aColor`, plus any dynamic-only attributes enabled via `dynamicProperties`. |
|
|
56
|
+
|
|
57
|
+
`boundsArea` is inherited from `Container` but is effectively required on `ParticleContainer`: the container returns empty bounds `(0, 0, 0, 0)` by default for performance, so without `boundsArea` it is culled as invisible when culling is active and `containsPoint` always misses.
|
|
58
|
+
|
|
59
|
+
### ParticleOptions
|
|
60
|
+
|
|
61
|
+
`Particle` is a lightweight struct, not a `Container` subclass — none of the `ContainerOptions` fields apply. The full option list:
|
|
62
|
+
|
|
63
|
+
| Option | Type | Default | Description |
|
|
64
|
+
| ---------- | ------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
65
|
+
| `texture` | `Texture` | — | Required. Texture used to render this particle. All particles in the same `ParticleContainer` must share the same base texture source. |
|
|
66
|
+
| `x` | `number` | `0` | X position in the container's local space. |
|
|
67
|
+
| `y` | `number` | `0` | Y position in the container's local space. |
|
|
68
|
+
| `scaleX` | `number` | `1` | Horizontal scale factor. |
|
|
69
|
+
| `scaleY` | `number` | `1` | Vertical scale factor. |
|
|
70
|
+
| `anchorX` | `number` | `0` | Horizontal anchor in 0–1 range; `0` is left, `0.5` is center, `1` is right. |
|
|
71
|
+
| `anchorY` | `number` | `0` | Vertical anchor in 0–1 range; `0` is top, `0.5` is center, `1` is bottom. |
|
|
72
|
+
| `rotation` | `number` | `0` | Rotation in radians. |
|
|
73
|
+
| `tint` | `ColorSource` | `0xffffff` | Tint color as hex number or CSS color string. Combined with `alpha` into the internal `color` field. |
|
|
74
|
+
| `alpha` | `number` | `1` | Transparency (0–1). Values outside the range are clamped. Combined with `tint` into the internal `color` field. |
|
|
75
|
+
|
|
76
|
+
The constructor also accepts a bare `Texture` as its sole argument (`new Particle(texture)`), which is shorthand for `new Particle({ texture })` using the defaults above.
|
|
77
|
+
|
|
78
|
+
`Particle.defaultOptions` is a static object you can reassign to change defaults globally; see the "Particle creation" section below.
|
|
79
|
+
|
|
80
|
+
## Core Patterns
|
|
81
|
+
|
|
82
|
+
### Particle creation
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
const particle = new Particle({
|
|
86
|
+
texture,
|
|
87
|
+
x: 100,
|
|
88
|
+
y: 200,
|
|
89
|
+
scaleX: 0.5,
|
|
90
|
+
scaleY: 0.5,
|
|
91
|
+
anchorX: 0.5,
|
|
92
|
+
anchorY: 0.5,
|
|
93
|
+
rotation: Math.PI / 4,
|
|
94
|
+
tint: 0xff0000,
|
|
95
|
+
alpha: 0.8,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
container.addParticle(particle);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`Particle` is a lightweight struct with flat numeric fields: `x`, `y`, `scaleX`, `scaleY`, `anchorX`, `anchorY`, `rotation`, `color`, `texture`. It also exposes `tint` (hex/CSS color) and `alpha` (0-1) as setters that combine into the internal `color` field. No transform hierarchy, no events, no filters.
|
|
102
|
+
|
|
103
|
+
You can pass a `Texture` directly as the sole argument: `new Particle(texture)`.
|
|
104
|
+
|
|
105
|
+
Override `Particle.defaultOptions` to change defaults globally:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
Particle.defaultOptions = {
|
|
109
|
+
...Particle.defaultOptions,
|
|
110
|
+
anchorX: 0.5,
|
|
111
|
+
anchorY: 0.5,
|
|
112
|
+
};
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Pre-populating with the particles option
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
const particles = Array.from(
|
|
119
|
+
{ length: 10000 },
|
|
120
|
+
() =>
|
|
121
|
+
new Particle({
|
|
122
|
+
texture,
|
|
123
|
+
x: Math.random() * 800,
|
|
124
|
+
y: Math.random() * 600,
|
|
125
|
+
}),
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const container = new ParticleContainer({
|
|
129
|
+
texture,
|
|
130
|
+
boundsArea: new Rectangle(0, 0, 800, 600),
|
|
131
|
+
particles,
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Passing `particles` in the constructor is equivalent to creating the container empty and calling `addParticle` for each one, but avoids per-call view updates.
|
|
136
|
+
|
|
137
|
+
### Dynamic vs static properties and update()
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
const container = new ParticleContainer({
|
|
141
|
+
dynamicProperties: {
|
|
142
|
+
rotation: true,
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
`dynamicProperties` controls which particle attributes re-upload to the GPU every frame. The defaults on `ParticleContainer.defaultOptions.dynamicProperties` are:
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
{ vertex: false, position: true, rotation: false, uvs: false, color: false }
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
You only need to override the properties you are animating; the rest inherit the defaults (position dynamic, everything else static). Five properties in total:
|
|
154
|
+
|
|
155
|
+
- `vertex`: scale/anchor vertices
|
|
156
|
+
- `position`
|
|
157
|
+
- `rotation`
|
|
158
|
+
- `uvs`: texture coordinates (for frame-swapped particles)
|
|
159
|
+
- `color`: tint and alpha
|
|
160
|
+
|
|
161
|
+
Mark only what you animate; static properties are cheaper. If you change a static property at runtime, call `container.update()` to re-upload:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
container.particleChildren.forEach((p) => {
|
|
165
|
+
p.tint = 0x00ff00;
|
|
166
|
+
});
|
|
167
|
+
container.update();
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Batch operations on particleChildren
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
// Bulk add
|
|
174
|
+
const batch = [];
|
|
175
|
+
for (let i = 0; i < 5000; i++) {
|
|
176
|
+
batch.push(
|
|
177
|
+
new Particle({ texture, x: Math.random() * 800, y: Math.random() * 600 }),
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
container.particleChildren.push(...batch);
|
|
181
|
+
container.update();
|
|
182
|
+
|
|
183
|
+
// Bulk remove
|
|
184
|
+
container.particleChildren.length = 0;
|
|
185
|
+
container.update();
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
`addParticle`, `addParticleAt`, `removeParticle`, `removeParticleAt`, and `removeParticles` all trigger view updates per call. For large batch operations, direct array manipulation plus a single `update()` is faster.
|
|
189
|
+
|
|
190
|
+
### Texture and shader options
|
|
191
|
+
|
|
192
|
+
`texture` in `ParticleContainerOptions` is optional. If omitted, the container falls back to the texture of the first particle added; every subsequent particle must share the same base texture source. Set it explicitly when you want to declare the atlas up front, or when the first particle might change mid-run:
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
const container = new ParticleContainer({ texture });
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
`shader` lets you replace the default particle shader with any `Shader` instance. The custom shader must declare the attributes the particle pipe uploads (`aPosition`, `aUV`, `aColor`, plus any dynamic-only attributes enabled via `dynamicProperties`). Use this for custom blending math, distance-field sprites, or non-standard effects:
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
const container = new ParticleContainer({ texture, shader: myCustomShader });
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Fading or tinting a whole particle system
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
const burst = new ParticleContainer({ texture, particles });
|
|
208
|
+
const layer = new Container();
|
|
209
|
+
layer.addChild(burst);
|
|
210
|
+
|
|
211
|
+
app.ticker.add(() => {
|
|
212
|
+
layer.alpha -= 0.01; // fades every particle
|
|
213
|
+
});
|
|
214
|
+
burst.tint = 0x66ccff; // tints every particle
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Container `alpha`, `tint`, and `blendMode` cascade into particles the same way they cascade into sprites, so you can fade or recolor an entire system without touching `particleChildren`.
|
|
218
|
+
|
|
219
|
+
### Limitations
|
|
220
|
+
|
|
221
|
+
`ParticleContainer` intentionally sacrifices features for speed:
|
|
222
|
+
|
|
223
|
+
- No filters, masks, or per-particle blend modes. Blend modes apply at the container level: set `blendMode` on the `ParticleContainer` or let it inherit from a parent `Container` (the default `"inherit"` resolves to the ancestor's blend mode, like `Sprite` and `Mesh`). The whole particle batch shares one blend mode. `alpha` and `tint` on the container or any ancestor multiply into every particle, on top of each particle's own `alpha`/`tint`.
|
|
224
|
+
- No nested children on particles.
|
|
225
|
+
- No automatic bounds calculation.
|
|
226
|
+
- All particles must share the same base texture source (atlases work; multiple unrelated textures do not).
|
|
227
|
+
- Custom shaders are supported via the `shader` option.
|
|
228
|
+
|
|
229
|
+
### Container method migration
|
|
230
|
+
|
|
231
|
+
`ParticleContainer` uses a separate child management API optimized for GPU buffer updates. The standard `Container` child methods throw when called on a `ParticleContainer`.
|
|
232
|
+
|
|
233
|
+
| Standard Container method | ParticleContainer equivalent |
|
|
234
|
+
| ---------------------------- | --------------------------------------------------- |
|
|
235
|
+
| `addChild(child)` | `addParticle(particle)` |
|
|
236
|
+
| `removeChild(child)` | `removeParticle(particle)` |
|
|
237
|
+
| `addChildAt(child, index)` | `addParticleAt(particle, index)` |
|
|
238
|
+
| `removeChildAt(index)` | `removeParticleAt(index)` |
|
|
239
|
+
| `removeChildren(begin, end)` | `removeParticles(begin, end)` |
|
|
240
|
+
| `getChildAt(index)` | Access `container.particleChildren[index]` directly |
|
|
241
|
+
| `swapChildren()` | Not available |
|
|
242
|
+
| `reparentChild()` | Not available |
|
|
243
|
+
|
|
244
|
+
## Common Mistakes
|
|
245
|
+
|
|
246
|
+
### [CRITICAL] Adding Sprites to ParticleContainer
|
|
247
|
+
|
|
248
|
+
Wrong:
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
const container = new ParticleContainer();
|
|
252
|
+
const sprite = new Sprite(texture);
|
|
253
|
+
container.addChild(sprite);
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Correct:
|
|
257
|
+
|
|
258
|
+
```ts
|
|
259
|
+
const container = new ParticleContainer();
|
|
260
|
+
const particle = new Particle(texture);
|
|
261
|
+
container.addParticle(particle);
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
`ParticleContainer` does not accept `Sprite` children. `addChild` throws an error. Particles must be `Particle` instances (or any object implementing `IParticle`), added via `addParticle`. This is a complete rework from v7, where `ParticleContainer` accepted `Sprite` children.
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
### [HIGH] Not setting boundsArea on ParticleContainer
|
|
268
|
+
|
|
269
|
+
Wrong:
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
const container = new ParticleContainer();
|
|
273
|
+
// bounds is always (0, 0, 0, 0) — culling and hit testing fail
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Correct:
|
|
277
|
+
|
|
278
|
+
```ts
|
|
279
|
+
const container = new ParticleContainer({
|
|
280
|
+
boundsArea: new Rectangle(0, 0, 800, 600),
|
|
281
|
+
});
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
`ParticleContainer` returns empty bounds `(0, 0, 0, 0)` by default for performance. Without `boundsArea`, the container is culled as invisible when culling is active, and `containsPoint` always misses. Set `boundsArea` to the region your particles occupy.
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
### [HIGH] Using children instead of particleChildren
|
|
288
|
+
|
|
289
|
+
Wrong:
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
container.addParticle(new Particle(texture));
|
|
293
|
+
console.log(container.children.length); // 0
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Correct:
|
|
297
|
+
|
|
298
|
+
```ts
|
|
299
|
+
container.addParticle(new Particle(texture));
|
|
300
|
+
console.log(container.particleChildren.length); // 1
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
Particles are stored in the `particleChildren` array, not `children`. The standard `Container.children` array is empty on a `ParticleContainer`. All particle enumeration, counting, and manipulation must use `particleChildren` plus the `*Particle` methods.
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
### [MEDIUM] Do not use ParticleContainer as a normal container
|
|
307
|
+
|
|
308
|
+
`ParticleContainer` contains particles, not display objects. If you need to group a particle system with a background sprite or UI overlay, wrap the `ParticleContainer` itself inside a plain `Container`:
|
|
309
|
+
|
|
310
|
+
```ts
|
|
311
|
+
const world = new Container();
|
|
312
|
+
world.addChild(backgroundSprite, particleContainer, uiLayer);
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
## API Reference
|
|
317
|
+
|
|
318
|
+
- [ParticleContainer](https://pixijs.download/release/docs/scene.ParticleContainer.html.md)
|
|
319
|
+
- [ParticleContainerOptions](https://pixijs.download/release/docs/scene.ParticleContainerOptions.html.md)
|
|
320
|
+
- [Particle](https://pixijs.download/release/docs/scene.Particle.html.md)
|
|
321
|
+
- [ParticleOptions](https://pixijs.download/release/docs/scene.ParticleOptions.html.md)
|
|
322
|
+
- [IParticle](https://pixijs.download/release/docs/scene.IParticle.html.md)
|
|
323
|
+
- [ParticleProperties](https://pixijs.download/release/docs/scene.ParticleProperties.html.md)
|