@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,140 @@
|
|
|
1
|
+
# Render Groups
|
|
2
|
+
|
|
3
|
+
A render group is a `Container` whose transform (position, scale, rotation, alpha, tint) is applied on the GPU as a single operation rather than being recalculated per-child on the CPU every frame. Use render groups for large stable sub-trees such as a game world, a HUD, or a parallax strip. Each render group owns its own instruction set and cannot batch with other groups.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const world = new Container({ isRenderGroup: true });
|
|
9
|
+
const hud = new Container({ isRenderGroup: true });
|
|
10
|
+
|
|
11
|
+
app.stage.addChild(world, hud);
|
|
12
|
+
|
|
13
|
+
for (let i = 0; i < 5000; i++) {
|
|
14
|
+
const bunny = new Sprite(bunnyTexture);
|
|
15
|
+
bunny.x = Math.random() * 2000;
|
|
16
|
+
bunny.y = Math.random() * 2000;
|
|
17
|
+
world.addChild(bunny);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
world.x = 100; // applied once on the GPU, not 5000 times on the CPU
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Flag a container with `isRenderGroup: true` at construction, or call `enableRenderGroup()` at runtime.
|
|
24
|
+
|
|
25
|
+
## Core Patterns
|
|
26
|
+
|
|
27
|
+
### Construction options
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
const world = new Container({ isRenderGroup: true });
|
|
31
|
+
|
|
32
|
+
const hud = new Container();
|
|
33
|
+
hud.enableRenderGroup();
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Both forms work. Pre-declare via the options object for static setups; call `enableRenderGroup()` when you want to flip the flag at runtime.
|
|
37
|
+
|
|
38
|
+
### The three transform levels
|
|
39
|
+
|
|
40
|
+
When a render group is in the chain, PixiJS composes three matrices:
|
|
41
|
+
|
|
42
|
+
1. `localTransform`; from the container's own position, scale, rotation, pivot, skew.
|
|
43
|
+
2. `groupTransform`; the child's position relative to the render group it belongs to.
|
|
44
|
+
3. `worldTransform`; the scene-root-space matrix.
|
|
45
|
+
|
|
46
|
+
For children inside a render group, the CPU only maintains `localTransform` and `groupTransform`. The GPU applies the group's own `worldTransform` once, then draws all the children. This is the performance win: the per-child CPU matrix math is cut from "one full walk per frame" to "one walk when children move."
|
|
47
|
+
|
|
48
|
+
### When to use render groups
|
|
49
|
+
|
|
50
|
+
Good fits:
|
|
51
|
+
|
|
52
|
+
- Game world with thousands of static entities.
|
|
53
|
+
- UI layer that mostly stays put.
|
|
54
|
+
- Parallax background strips.
|
|
55
|
+
- A menu or HUD overlay that scales or translates as a whole.
|
|
56
|
+
|
|
57
|
+
Bad fits:
|
|
58
|
+
|
|
59
|
+
- Small sub-trees (a dozen children). Overhead outweighs the save.
|
|
60
|
+
- Constantly-changing structure (children being added / removed per frame).
|
|
61
|
+
- Sub-trees that need to batch with other objects outside the group.
|
|
62
|
+
|
|
63
|
+
### Profile before adding
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
// Start without explicit render groups
|
|
67
|
+
const world = new Container();
|
|
68
|
+
|
|
69
|
+
// Measure frames, identify bottleneck
|
|
70
|
+
|
|
71
|
+
// Add if CPU transform updates dominate
|
|
72
|
+
world.enableRenderGroup();
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Most scenes don't need explicit render groups beyond the auto-created root. The scene root container passed to `renderer.render()` is automatically a render group. Add explicit groups only when profiling shows CPU transform costs dominating.
|
|
76
|
+
|
|
77
|
+
### Render groups vs cacheAsTexture
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const hud = new Container();
|
|
81
|
+
hud.cacheAsTexture({ antialias: true });
|
|
82
|
+
|
|
83
|
+
const world = new Container({ isRenderGroup: true });
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
- `cacheAsTexture()` rasterizes the sub-tree once to a texture and draws that texture each frame. Best for things that don't change visually.
|
|
87
|
+
- `isRenderGroup` keeps normal drawing but moves the group transform work to the GPU. Best for sub-trees whose children animate freely but whose structure is stable.
|
|
88
|
+
|
|
89
|
+
Render groups are lighter than cacheAsTexture and preserve dynamic children. Use cacheAsTexture only when the sub-tree is genuinely static.
|
|
90
|
+
|
|
91
|
+
## Common Mistakes
|
|
92
|
+
|
|
93
|
+
### [MEDIUM] Overusing render groups
|
|
94
|
+
|
|
95
|
+
Wrong:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
for (const enemy of enemies) {
|
|
99
|
+
enemy.enableRenderGroup();
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Each render group has its own instruction set and can't batch with other groups. A scene with many small render groups generates many separate draw buckets, which is slower than a single batched draw. Apply render groups at a coarse level (world, HUD), not per-entity.
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
### [HIGH] Nesting many render groups
|
|
107
|
+
|
|
108
|
+
Wrong:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
const world = new Container({ isRenderGroup: true });
|
|
112
|
+
const section = new Container({ isRenderGroup: true });
|
|
113
|
+
const tile = new Container({ isRenderGroup: true });
|
|
114
|
+
world.addChild(section);
|
|
115
|
+
section.addChild(tile);
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Correct:
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
const world = new Container({ isRenderGroup: true });
|
|
122
|
+
const section = new Container();
|
|
123
|
+
const tile = new Container();
|
|
124
|
+
world.addChild(section);
|
|
125
|
+
section.addChild(tile);
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Deep nesting of render groups multiplies the instruction set overhead. Pick a single level (usually one per "subsystem") and let the children be normal containers.
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
### [MEDIUM] Constantly adding/removing from a render group
|
|
132
|
+
|
|
133
|
+
If the sub-tree structure changes every frame (not just child transforms), the render group's instruction set is rebuilt each time, negating the performance benefit. Render groups help stable structures with animated children; not dynamic structures.
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
## API Reference
|
|
137
|
+
|
|
138
|
+
- [RenderGroup](https://pixijs.download/release/docs/rendering.RenderGroup.html.md)
|
|
139
|
+
- [Container](https://pixijs.download/release/docs/scene.Container.html.md)
|
|
140
|
+
- [ContainerOptions](https://pixijs.download/release/docs/scene.ContainerOptions.html.md)
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# Scene Management: Render Groups, Layers, and Culling
|
|
2
|
+
|
|
3
|
+
Organize PixiJS scenes with render groups (GPU-level transforms), RenderLayer (decoupled render order), culling (offscreen optimization), zIndex sorting, and boundsArea optimization.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const world = new Container({ isRenderGroup: true });
|
|
9
|
+
const hud = new Container({ isRenderGroup: true });
|
|
10
|
+
app.stage.addChild(world, hud);
|
|
11
|
+
|
|
12
|
+
const bgLayer = new RenderLayer();
|
|
13
|
+
const entityLayer = new RenderLayer();
|
|
14
|
+
const uiLayer = new RenderLayer();
|
|
15
|
+
app.stage.addChild(bgLayer, entityLayer, uiLayer);
|
|
16
|
+
|
|
17
|
+
const player = new Sprite(texture);
|
|
18
|
+
world.addChild(player);
|
|
19
|
+
entityLayer.attach(player);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Core Patterns
|
|
23
|
+
|
|
24
|
+
### Render groups for GPU-level transforms
|
|
25
|
+
|
|
26
|
+
A render group is a container whose transform (position, scale, rotation, alpha, tint) is applied on the GPU as a single operation rather than being recalculated per-child on the CPU. The root container passed to `renderer.render()` is automatically a render group.
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
const gameWorld = new Container({ isRenderGroup: true });
|
|
30
|
+
const uiLayer = new Container({ isRenderGroup: true });
|
|
31
|
+
|
|
32
|
+
scene.addChild(gameWorld, uiLayer);
|
|
33
|
+
|
|
34
|
+
gameWorld.x += 10;
|
|
35
|
+
|
|
36
|
+
const panel = new Container();
|
|
37
|
+
panel.enableRenderGroup();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Use render groups for large stable sub-trees (the structure stays the same even though children move/rotate). Children inside can still animate freely; "stable" means children are not being constantly added/removed.
|
|
41
|
+
|
|
42
|
+
The scene has three matrix levels:
|
|
43
|
+
|
|
44
|
+
1. `localTransform` - based on the container's own position/scale/rotation
|
|
45
|
+
2. `groupTransform` - relative to the render group it belongs to
|
|
46
|
+
3. `worldTransform` - relative to the scene root
|
|
47
|
+
|
|
48
|
+
### RenderLayer for decoupled render order
|
|
49
|
+
|
|
50
|
+
RenderLayer separates render order from scene graph hierarchy. Objects keep their logical parent for transforms but render at the layer's position in the scene.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
const bgLayer = new RenderLayer();
|
|
54
|
+
const entityLayer = new RenderLayer();
|
|
55
|
+
const uiLayer = new RenderLayer();
|
|
56
|
+
|
|
57
|
+
app.stage.addChild(bgLayer, entityLayer, uiLayer);
|
|
58
|
+
|
|
59
|
+
const player = new Sprite(texture);
|
|
60
|
+
const world = new Container();
|
|
61
|
+
world.addChild(player);
|
|
62
|
+
entityLayer.attach(player);
|
|
63
|
+
|
|
64
|
+
entityLayer.detach(player);
|
|
65
|
+
entityLayer.detachAll();
|
|
66
|
+
|
|
67
|
+
const sortedLayer = new RenderLayer({
|
|
68
|
+
sortableChildren: true,
|
|
69
|
+
sortFunction: (a, b) => a.position.y - b.position.y,
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Key constraints:
|
|
74
|
+
|
|
75
|
+
- `addChild()` / `removeChild()` on RenderLayer throws an error. Use `attach()` / `detach()`.
|
|
76
|
+
- Objects removed from their scene graph parent via `removeChild()` are automatically detached from their layer.
|
|
77
|
+
- Re-adding an object to the scene graph does NOT automatically re-attach it to the layer. You must call `attach()` again.
|
|
78
|
+
- Layers and their children must belong to the same render group.
|
|
79
|
+
|
|
80
|
+
### Culling
|
|
81
|
+
|
|
82
|
+
Culling skips rendering objects outside the visible area. In v8, culling is manual; it does not happen automatically during render.
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
const stage = new Container();
|
|
86
|
+
|
|
87
|
+
for (let i = 0; i < 1000; i++) {
|
|
88
|
+
const sprite = Sprite.from("bunny.png");
|
|
89
|
+
sprite.x = Math.random() * 5000;
|
|
90
|
+
sprite.y = Math.random() * 5000;
|
|
91
|
+
sprite.cullable = true;
|
|
92
|
+
stage.addChild(sprite);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const view = { x: 0, y: 0, width: 800, height: 600 };
|
|
96
|
+
Culler.shared.cull(stage, view);
|
|
97
|
+
renderer.render(stage);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
For automatic culling with Application, register CullerPlugin:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { extensions, CullerPlugin } from "pixi.js";
|
|
104
|
+
extensions.add(CullerPlugin);
|
|
105
|
+
|
|
106
|
+
const app = new Application();
|
|
107
|
+
await app.init({ width: 800, height: 600 });
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Set `cullArea` on a container to define a custom cull region instead of computing bounds:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
container.cullArea = new Rectangle(0, 0, 1000, 1000);
|
|
114
|
+
container.cullable = true;
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### zIndex sorting
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
const parent = new Container({ sortableChildren: true });
|
|
121
|
+
|
|
122
|
+
const bg = new Sprite(bgTexture);
|
|
123
|
+
bg.zIndex = 0;
|
|
124
|
+
|
|
125
|
+
const player = new Sprite(playerTexture);
|
|
126
|
+
player.zIndex = 10;
|
|
127
|
+
|
|
128
|
+
const fg = new Sprite(fgTexture);
|
|
129
|
+
fg.zIndex = 20;
|
|
130
|
+
|
|
131
|
+
parent.addChild(fg, bg, player);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Setting `zIndex` on a child automatically enables `sortableChildren` on its parent, so the explicit constructor option is only needed when you want sorting enabled before any child sets a zIndex.
|
|
135
|
+
|
|
136
|
+
### boundsArea optimization
|
|
137
|
+
|
|
138
|
+
Setting `boundsArea` on a container prevents recursive bounds measurement of all children. Useful for containers with many children whose aggregate bounds are known.
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
const particles = new Container();
|
|
142
|
+
particles.boundsArea = new Rectangle(0, 0, 800, 600);
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Common Mistakes
|
|
146
|
+
|
|
147
|
+
### MEDIUM: Overusing render groups
|
|
148
|
+
|
|
149
|
+
Each render group has its own instruction set and cannot batch with other groups. Use render groups at a broad level (game world, HUD), not per-child. Profile before adding them; most scenes do not need any explicit render groups beyond the auto-created root.
|
|
150
|
+
|
|
151
|
+
### HIGH: Expecting automatic culling
|
|
152
|
+
|
|
153
|
+
v8 culling is explicit. Setting `cullable=true` only marks the container as eligible. You must call `Culler.shared.cull()` before rendering, or register `CullerPlugin` for automatic culling with Application.
|
|
154
|
+
|
|
155
|
+
### MEDIUM: Expecting filters on ancestors to apply to layer children
|
|
156
|
+
|
|
157
|
+
RenderLayer children are rendered outside their parent's filter scope. Filters capture children into a texture via push/pop, but layer-attached children skip their parent's collection and render at the layer's position instead. Apply filters directly to the child when using RenderLayer.
|
|
158
|
+
|
|
159
|
+
### HIGH: Using addChild on RenderLayer
|
|
160
|
+
|
|
161
|
+
RenderLayer overrides `addChild`, `removeChild`, and related methods to throw errors. Use `attach()` and `detach()` for layer membership. The object still needs a scene graph parent via `addChild` on a regular Container for transforms.
|
|
162
|
+
|
|
163
|
+
## API Reference
|
|
164
|
+
|
|
165
|
+
- [RenderLayer](https://pixijs.download/release/docs/scene.RenderLayer.html.md)
|
|
166
|
+
- [Container](https://pixijs.download/release/docs/scene.Container.html.md)
|
|
167
|
+
- [Culler](https://pixijs.download/release/docs/scene.Culler.html.md)
|
|
168
|
+
- [CullerPlugin](https://pixijs.download/release/docs/app.CullerPlugin.html.md)
|
|
169
|
+
- [RenderGroup](https://pixijs.download/release/docs/rendering.RenderGroup.html.md)
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# Transforms and Coordinate Spaces
|
|
2
|
+
|
|
3
|
+
Every `Container` has a transform: position, scale, rotation, pivot, skew, and origin. These combine into a `localTransform` matrix, which compounds with ancestors to produce the `worldTransform`. Use this reference for coordinate-space conversion and the details of setting vs. animating transforms. For matrix math, see `pixijs-math`.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const hero = new Container();
|
|
9
|
+
hero.x = 100;
|
|
10
|
+
hero.y = 200;
|
|
11
|
+
hero.scale.set(2);
|
|
12
|
+
hero.rotation = Math.PI / 4;
|
|
13
|
+
|
|
14
|
+
const worldPoint = hero.toGlobal({ x: 0, y: 0 });
|
|
15
|
+
const localPoint = hero.toLocal({ x: 300, y: 300 });
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Transforms are local to the parent. `toGlobal` and `toLocal` convert between coordinate spaces.
|
|
19
|
+
|
|
20
|
+
## Core Patterns
|
|
21
|
+
|
|
22
|
+
### Position, scale, rotation
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
container.x = 100;
|
|
26
|
+
container.y = 200;
|
|
27
|
+
container.position.set(100, 200);
|
|
28
|
+
|
|
29
|
+
container.scale.set(2); // uniform
|
|
30
|
+
container.scale.set(1.5, 0.8); // non-uniform
|
|
31
|
+
container.scale.x = 2;
|
|
32
|
+
|
|
33
|
+
container.rotation = Math.PI / 4; // radians
|
|
34
|
+
container.angle = 45; // degrees (convenience)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`position`, `scale`, and `pivot` are `ObservablePoint` instances; direct assignment via `x` / `y` works, or call `set(x, y?)`. Setting them triggers the parent's transform update flag.
|
|
38
|
+
|
|
39
|
+
### Pivot
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
sprite.pivot.set(sprite.width / 2, sprite.height / 2);
|
|
43
|
+
sprite.x = 200;
|
|
44
|
+
sprite.y = 200;
|
|
45
|
+
sprite.rotation += 0.01;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`pivot` is the point around which rotation and scale apply; in the **container's own local pixel space**. A pivot of `(w/2, h/2)` rotates around the center.
|
|
49
|
+
|
|
50
|
+
For `Sprite`, prefer `anchor` (normalized 0–1) which only shifts the texture draw origin without offsetting the position. Pivot shifts the position too.
|
|
51
|
+
|
|
52
|
+
### Origin (new in v8)
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
container.origin.set(100, 50);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`origin` is an alternative transform origin that shifts the rotation/scale pivot **without offsetting the visual position**. Think of it as "pivot, but without the position shift." Useful when you want to spin a large container around an off-center point while keeping it visually anchored to its `x` / `y`.
|
|
59
|
+
|
|
60
|
+
### Skew
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
container.skew.set(0.1, 0);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Rarely used. Skew shears the coordinate space by `x` / `y` radians. Useful for fake perspective and isometric effects.
|
|
67
|
+
|
|
68
|
+
### Coordinate conversion
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
const globalPoint = container.toGlobal({ x: 10, y: 20 });
|
|
72
|
+
|
|
73
|
+
const localPoint = container.toLocal({ x: 400, y: 300 });
|
|
74
|
+
|
|
75
|
+
const localFromSprite = container.toLocal({ x: 0, y: 0 }, otherSprite);
|
|
76
|
+
|
|
77
|
+
const cached = container.getGlobalPosition();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
- `toGlobal(localPoint)`: convert from this container's local space to global (scene root) space.
|
|
81
|
+
- `toLocal(point, from?)`: convert from global (or another container's) space to this container's local space.
|
|
82
|
+
- `getGlobalPosition()`: shortcut for `toGlobal({ x: 0, y: 0 })`; this container's origin in global space.
|
|
83
|
+
|
|
84
|
+
All three accept an optional `point` argument to write into (reduces allocation in hot paths) and a `skipUpdate` flag that uses the cached transform (faster but can be stale).
|
|
85
|
+
|
|
86
|
+
### The three matrices
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
container.localTransform; // from this node's own position/scale/rotation/pivot/skew
|
|
90
|
+
container.groupTransform; // relative to the render group it belongs to
|
|
91
|
+
container.worldTransform; // relative to the scene root
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Each frame, PixiJS composes these three levels:
|
|
95
|
+
|
|
96
|
+
1. `localTransform`; derived from the container's own transform setters.
|
|
97
|
+
2. `groupTransform`; if an ancestor is a render group, this is the transform relative to that group.
|
|
98
|
+
3. `worldTransform`; relative to the scene root; what the renderer consumes.
|
|
99
|
+
|
|
100
|
+
For normal code, set `x` / `y` / `scale` / `rotation` and let the renderer compose the rest. Reading `worldTransform` directly is useful for hit testing, custom rendering, or integrating with physics.
|
|
101
|
+
|
|
102
|
+
### Sizing via width, height, setSize
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
container.width = 100;
|
|
106
|
+
container.height = 200;
|
|
107
|
+
|
|
108
|
+
container.setSize(100, 200);
|
|
109
|
+
const { width, height } = container.getSize();
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Setting `width` and `height` scales the container to fit the requested dimensions; internally they assign `scale.x` / `scale.y` based on the measured bounds. Assigning the two setters independently re-measures the subtree twice, which is wasteful. Use `setSize(width, height?)` to assign both in a single pass, and `getSize()` to read them back as `{ width, height }`.
|
|
113
|
+
|
|
114
|
+
### Bounds in different spaces
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
const localBounds = container.getLocalBounds();
|
|
118
|
+
const globalBounds = container.getBounds();
|
|
119
|
+
|
|
120
|
+
const reusable = new Bounds();
|
|
121
|
+
container.getBounds(true, reusable); // skipUpdate + in-place
|
|
122
|
+
|
|
123
|
+
const rect = container.getBounds().rectangle;
|
|
124
|
+
rect.contains(pointerX, pointerY);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- `getLocalBounds()`: rectangle in the container's own local space.
|
|
128
|
+
- `getBounds(skipUpdate?, bounds?)`: rectangle in world space (accounts for all ancestor transforms). Pass `true` for `skipUpdate` to reuse the cached transform instead of forcing a fresh pass, and pass an existing `Bounds` instance as the second argument to avoid allocating a new one.
|
|
129
|
+
|
|
130
|
+
Both methods return a `Bounds` instance, not a `Rectangle`. `Bounds` exposes `x`, `y`, `width`, and `height` getters plus a `.rectangle` accessor for APIs like `Rectangle.contains()`.
|
|
131
|
+
|
|
132
|
+
Bounds are recalculated lazily. Call them sparingly; each call walks the container's sub-tree. For containers with many cheap children (particles, tile layers), set `container.boundsArea = new Rectangle(0, 0, w, h)` so `getBounds()` returns that rectangle directly without recursing.
|
|
133
|
+
|
|
134
|
+
### Global, local, and screen coordinates
|
|
135
|
+
|
|
136
|
+
PixiJS uses three coordinate spaces:
|
|
137
|
+
|
|
138
|
+
- **Local**: relative to the object's parent. This is what `container.x` / `container.y` and `position.set()` always operate on.
|
|
139
|
+
- **Global** (a.k.a. "world"): relative to the scene root. `toGlobal()`, `toLocal()`, and `getGlobalPosition()` convert between local and global space.
|
|
140
|
+
- **Screen** (a.k.a. "viewport"): relative to the top-left of the canvas element PixiJS is rendering into. DOM events and native mouse clicks use screen space.
|
|
141
|
+
|
|
142
|
+
Global and screen usually match, but they diverge when the canvas is CSS-scaled or rendered at a non-1 resolution. PixiJS's event system handles this conversion automatically for pointer events, so `onPointerDown` handlers always receive global coordinates. When you need raw screen coordinates, read `renderer.events.pointer`; use `toLocal` / `toGlobal` for the world side.
|
|
143
|
+
|
|
144
|
+
### Cumulative alpha (getGlobalAlpha)
|
|
145
|
+
|
|
146
|
+
`container.alpha` is local to the container; the cumulative alpha (parent × this × ancestors) is exposed via `container.getGlobalAlpha(skipUpdate?)`. It's computed during render, so reading it before the first frame returns 1 on a freshly-added subtree. Useful for custom render hooks that need to know how transparent the renderer will actually draw this node.
|
|
147
|
+
|
|
148
|
+
## Common Mistakes
|
|
149
|
+
|
|
150
|
+
### [HIGH] Setting scale to 0
|
|
151
|
+
|
|
152
|
+
Wrong:
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
container.scale.set(0);
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Correct:
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
container.scale.set(0.01); // or use visible = false
|
|
162
|
+
container.visible = false;
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Scale of exactly 0 collapses the transform matrix to zero, and any subsequent `toLocal` / `toGlobal` / inverse calculations divide by zero. Use `visible = false` to hide, or scale to a tiny non-zero value if you need an animation.
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
### [MEDIUM] Reading world transform before first render
|
|
169
|
+
|
|
170
|
+
Wrong:
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
const pos = container.getGlobalPosition();
|
|
174
|
+
console.log(pos); // { x: 0, y: 0 } even though container.x is set
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Correct:
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
app.stage.addChild(container);
|
|
181
|
+
await new Promise((r) => requestAnimationFrame(r));
|
|
182
|
+
const pos = container.getGlobalPosition();
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
`worldTransform` is computed during render. Before the first render, it's identity. If you need a live position before rendering, use `container.toGlobal({x:0, y:0})` which walks the transforms explicitly.
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
### [MEDIUM] Confusing anchor and pivot
|
|
189
|
+
|
|
190
|
+
On `Sprite`, `anchor` is normalized (0–1) and shifts only the draw origin. `pivot` is in pixel space and shifts both the transform origin AND the visual position. For centering a sprite, use `anchor`. For off-center rotation of a Container (which has no `anchor`), use `pivot`.
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
## API Reference
|
|
194
|
+
|
|
195
|
+
- [Container](https://pixijs.download/release/docs/scene.Container.html.md)
|
|
196
|
+
- [ToLocalGlobalMixin](https://pixijs.download/release/docs/scene.ToLocalGlobalMixin.html.md)
|
|
197
|
+
- [Matrix](https://pixijs.download/release/docs/maths.Matrix.html.md)
|
|
198
|
+
- [ObservablePoint](https://pixijs.download/release/docs/maths.ObservablePoint.html.md)
|