@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,244 @@
|
|
|
1
|
+
# Advanced GPU features
|
|
2
|
+
|
|
3
|
+
Lower-level rendering APIs for custom draw code. Items marked WebGPU only are ignored or unavailable on the WebGL renderer; branch on `renderer.name === "webgpu"` before relying on them.
|
|
4
|
+
|
|
5
|
+
## Partial buffer updates
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { Buffer, BufferUsage } from "pixi.js";
|
|
9
|
+
|
|
10
|
+
const buffer = new Buffer({
|
|
11
|
+
data: new Float32Array(4096),
|
|
12
|
+
usage: BufferUsage.VERTEX | BufferUsage.COPY_DST,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
buffer.data.set(newVertices, 256);
|
|
16
|
+
buffer.update(newVertices.byteLength, 256 * 4); // size and offset in bytes
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`update()` with no arguments re-uploads the whole buffer. Pass a byte size and byte offset to upload only the range you changed. Works on WebGL and WebGPU.
|
|
20
|
+
|
|
21
|
+
## Partial texture uploads
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { BufferImageSource } from "pixi.js";
|
|
25
|
+
|
|
26
|
+
const data = new Float32Array(4096 * 64 * 4); // rgba32float: 4 floats per texel
|
|
27
|
+
const source = new BufferImageSource({ resource: data, width: 4096, height: 64 });
|
|
28
|
+
|
|
29
|
+
data.fill(1, 100 * 4, 116 * 4); // change texels 100 to 115
|
|
30
|
+
source.update(100, 116); // upload only those 16 texels
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Texel `i` sits at `x = i % width`, `y = floor(i / width)`, and `end` is exclusive. The range applies to that call only, so track the lowest and highest changed texel yourself and call `update` once per frame. `update()` with no arguments uploads the whole texture. Works on WebGL and WebGPU. A 3D texture (`depth`) or 2D array (`arrayLayerCount`) always uploads whole, so call `update()` with no range.
|
|
34
|
+
|
|
35
|
+
## Vertex count, index count, winding, and culling
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
const count = geometry.vertexCount; // cached, from the first non-instanced attribute
|
|
39
|
+
|
|
40
|
+
// several geometries share one index buffer sized for the biggest batch;
|
|
41
|
+
// each draws only the prefix it currently uses
|
|
42
|
+
const quads = new Geometry({
|
|
43
|
+
attributes: { aPosition: positions },
|
|
44
|
+
indexBuffer: sharedIndices,
|
|
45
|
+
indexCount: liveQuads * 6,
|
|
46
|
+
});
|
|
47
|
+
quads.indexCount = 12; // read at draw time; no re-upload
|
|
48
|
+
|
|
49
|
+
const state = new State();
|
|
50
|
+
state.culling = true;
|
|
51
|
+
state.clockwiseFrontFace = true; // or state.cullMode = "front"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`geometry.getSize()` is deprecated since 8.20.0; read `vertexCount` instead. `indexCount` of `0` (the default) draws the whole index buffer; any other value draws that many indices. A `size` passed to `encoder.draw()` still wins. `clockwiseFrontFace` selects which winding counts as front-facing on both renderers. When rendering into a texture PixiJS inverts the winding to match the flipped projection; call `renderer.renderTarget.isFrontFaceInverted()` if your own code needs the resolved orientation, or `isFrontFaceInverted(target, flipY)` to ask about a `RenderTarget` before binding it (`renderer.renderTarget.getRenderTarget(texture)` returns one for a texture).
|
|
55
|
+
|
|
56
|
+
## WGSL override constants (WebGPU only)
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
const source = /* wgsl */ `
|
|
60
|
+
override BLUR_STEPS: u32 = 4u;
|
|
61
|
+
// ...
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
const shader = Shader.from({
|
|
65
|
+
gpu: {
|
|
66
|
+
vertex: { source, entryPoint: "vsMain" },
|
|
67
|
+
fragment: { source, entryPoint: "fsMain" },
|
|
68
|
+
},
|
|
69
|
+
resources: { uniforms },
|
|
70
|
+
overrides: { BLUR_STEPS: 8 },
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`overrides` takes a plain `Record<string, number>` or a `ShaderOverrides` instance. Values are fixed when the shader is created and become part of the pipeline cache key, so every distinct set compiles its own pipeline. To change a value, create a new shader. On browsers without pipeline constants (Safari) PixiJS substitutes the values into the WGSL source; `renderer.limits.supportsOverrideConstants` tells you which path is active. WebGL ignores `overrides` entirely.
|
|
75
|
+
|
|
76
|
+
## Custom bind group layout (WebGPU only)
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { GpuProgram, extractStructAndGroups, generateGpuLayoutGroups } from "pixi.js";
|
|
80
|
+
|
|
81
|
+
const gpuLayout = generateGpuLayoutGroups(extractStructAndGroups(source));
|
|
82
|
+
|
|
83
|
+
// narrow one texture binding to the fragment stage
|
|
84
|
+
gpuLayout[0][1].visibility = GPUShaderStage.FRAGMENT;
|
|
85
|
+
|
|
86
|
+
const program = new GpuProgram({
|
|
87
|
+
vertex: { source, entryPoint: "vsMain" },
|
|
88
|
+
fragment: { source, entryPoint: "fsMain" },
|
|
89
|
+
gpuLayout,
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`generateGpuLayoutGroups` is the same generator `GpuProgram` runs when `gpuLayout` is omitted, and it marks every binding visible to both stages. Generate the default, edit the entries you care about, and pass the whole array back rather than hand-writing the layout.
|
|
94
|
+
|
|
95
|
+
## Sampling a depth texture with TextureView (WebGPU only)
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { RenderTarget, Shader, State, TextureSource, TextureView } from "pixi.js";
|
|
99
|
+
|
|
100
|
+
const depth = new TextureSource({ width: 512, height: 512, format: "depth24plus-stencil8" });
|
|
101
|
+
const color = new TextureSource({ width: 512, height: 512 });
|
|
102
|
+
|
|
103
|
+
// pass 1: write depth
|
|
104
|
+
const writeTarget = new RenderTarget({
|
|
105
|
+
colorAttachments: [{ texture: color, loadOp: "clear", clearValue: [0, 0, 0, 1] }],
|
|
106
|
+
depthStencilAttachment: { texture: depth, depthLoadOp: "clear", depthClearValue: 1 },
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// pass 2: keep the same depth attached read-only while sampling it
|
|
110
|
+
const readTarget = new RenderTarget({
|
|
111
|
+
colorAttachments: [{ texture: color, loadOp: "load" }],
|
|
112
|
+
depthStencilAttachment: { texture: depth, depthReadOnly: true },
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const shader = Shader.from({
|
|
116
|
+
gpu: { vertex: { source, entryPoint: "vsMain" }, fragment: { source, entryPoint: "fsMain" } },
|
|
117
|
+
resources: { uDepthTexture: new TextureView(depth, { aspect: "depth-only" }) },
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Declare `@group(0) @binding(1) var uDepthTexture: texture_depth_2d;` in WGSL and read it with `textureLoad`. Use a `State` with `depthMask = false` in the read pass. A `TextureView` is a bind resource like a `TextureSource`; on WebGL it binds the underlying source and the descriptor is ignored.
|
|
122
|
+
|
|
123
|
+
## Integer textures
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { BufferImageSource, Shader } from "pixi.js";
|
|
127
|
+
|
|
128
|
+
const ids = new BufferImageSource({
|
|
129
|
+
resource: new Uint32Array([1, 2, 3, 4]), // picks rgba32uint
|
|
130
|
+
width: 1,
|
|
131
|
+
height: 1,
|
|
132
|
+
scaleMode: "nearest",
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const shader = Shader.from({
|
|
136
|
+
gl: { vertex: vertSrc, fragment: fragSrc },
|
|
137
|
+
gpu: { vertex: { source, entryPoint: "vsMain" }, fragment: { source, entryPoint: "fsMain" } },
|
|
138
|
+
resources: { uIds: ids },
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Integer formats (`*uint`, `*sint`) hold exact integers. Use them where a float texture would lose bits, since small integers are denormal floats and GPUs may flush them to zero. They can't be filtered, so set `scaleMode: "nearest"`. `BufferImageSource` infers `rgba32uint` from a `Uint32Array` and `rgba16uint` from a `Uint16Array`; pass `format: "rgba32sint"` (or another signed format) explicitly for signed data. It defaults integer formats to `alphaMode: "no-premultiply-alpha"` because integer data can't be premultiplied on upload.
|
|
143
|
+
|
|
144
|
+
In GLSL ES 3.0, declare `uniform usampler2D uIds;` (or `isampler2D`) and read it with `texelFetch(uIds, ivec2(x, y), 0)`. GLSL ES 3.0 gives integer samplers no default precision, so PixiJS declares `highp` for them and you don't need a precision line. A precision line you write yourself is kept. In WGSL, declare `@group(0) @binding(1) var uIds: texture_2d<u32>;` (or `<i32>`) and read it with `textureLoad(uIds, vec2<i32>(x, y), 0)`; the generated bind group layout takes its `sampleType` from the `<u32>` / `<i32>` suffix. PixiJS can't render into integer textures yet.
|
|
145
|
+
|
|
146
|
+
## 3D and array textures
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import { BufferImageSource } from "pixi.js";
|
|
150
|
+
|
|
151
|
+
const size = 64;
|
|
152
|
+
const noise = new BufferImageSource({
|
|
153
|
+
resource: new Uint8Array(size * size * size * 4), // slice after slice, row-major
|
|
154
|
+
width: size,
|
|
155
|
+
height: size,
|
|
156
|
+
depth: size, // or arrayLayerCount: n for a 2D array
|
|
157
|
+
format: "rgba8unorm",
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
`depth` on a `TextureSource` or `BufferImageSource` makes a `"3d"` texture, and `arrayLayerCount > 1` makes a `"2d-array"` texture. A texture can't have both, and TypeScript rejects options that set both. Pass `viewDimension` only when the size doesn't decide it, such as `"cube"` for 6 layers. `dimensions` is deprecated; leave it out. These textures need WebGL2 or WebGPU; WebGL1 has no 3D or array textures.
|
|
162
|
+
|
|
163
|
+
The buffer holds the slices (or layers) one after another, each in row-major order, so texel `(x, y, z)` sits at index `x + y * width + z * width * height`. `resolution` doesn't scale `depth`. A 3D or array `BufferImageSource` defaults to `alphaMode: "no-premultiply-alpha"` and always uploads whole, so `update()` takes no range.
|
|
164
|
+
|
|
165
|
+
In GLSL ES 3.0, declare `uniform sampler3D` or `uniform sampler2DArray`. In WGSL, declare `texture_3d<f32>` or `texture_2d_array<f32>`. PixiJS adds the precision line for `sampler3D` and `sampler2DArray`, as for integer samplers above.
|
|
166
|
+
|
|
167
|
+
`rgba32float`, the default for a `Float32Array`, needs an optional feature for linear filtering that PixiJS doesn't request on WebGPU. Use `scaleMode: "nearest"` with it, or pick `rgba8unorm`, `r8unorm` or `rgba16float` for smooth sampling.
|
|
168
|
+
|
|
169
|
+
To draw into one slice or layer, pass the source itself as `target` and pick the slice with `layer`: `renderer.render({ container, target: noise, layer: z, clear: true })`. `layer` selects an array layer, a cube face, or a 3D depth slice. `RenderTexture.create` doesn't take `depth`, so use the `TextureSource` directly. `renderer.renderTarget.push({ target, layer })` takes `layer` too.
|
|
170
|
+
|
|
171
|
+
## Storage textures (WebGPU only)
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
import { TextureSource } from "pixi.js";
|
|
175
|
+
|
|
176
|
+
const volume = new TextureSource({ width: 64, height: 64, depth: 64, format: "rgba8unorm", storage: true });
|
|
177
|
+
|
|
178
|
+
// bind this view to a texture_storage_3d<rgba8unorm, write> in your own compute pass
|
|
179
|
+
const view = renderer.texture.getGpuSource(volume).createView();
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
`storage: true` adds `GPUTextureUsage.STORAGE_BINDING`, so your own compute pass can write the texture through `renderer.texture.getGpuSource(source).createView()`. PixiJS still samples it like any other texture. WebGL ignores the option.
|
|
183
|
+
|
|
184
|
+
Every device accepts `rgba8unorm`, `rgba16float`, `r32float`, `rg32float`, `rgba32float` and the matching integer formats as storage textures. `bgra8unorm` needs the `bgra8unorm-storage` feature, and formats such as `r8unorm` or `r16float` need `texture-formats-tier1`. PixiJS enables both features when the GPU has them. WebGPU rejects any other format when the texture is created.
|
|
185
|
+
|
|
186
|
+
`autoGenerateMipmaps` on a 3D texture uses `gl.generateMipmap` on WebGL. WebGPU writes the mips with a compute shader, so the texture needs `storage: true` and the `rgba8unorm` or `rgba16float` format.
|
|
187
|
+
|
|
188
|
+
## Render bundles (WebGPU only)
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
import { RenderContainer } from "pixi.js";
|
|
192
|
+
import type { RenderBundle, WebGPURenderer } from "pixi.js";
|
|
193
|
+
|
|
194
|
+
let bundle: RenderBundle | null = null;
|
|
195
|
+
|
|
196
|
+
const props = new RenderContainer({
|
|
197
|
+
render: (renderer) => {
|
|
198
|
+
const encoder = (renderer as WebGPURenderer).encoder;
|
|
199
|
+
|
|
200
|
+
if (!bundle || !encoder.isBundleValid(bundle)) {
|
|
201
|
+
encoder.beginBundle("static-props");
|
|
202
|
+
encoder.draw({ geometry, shader, state });
|
|
203
|
+
bundle = encoder.endBundle();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
encoder.executeBundle(bundle);
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
A bundle records draw calls once and replays them on later frames. It bakes the render target it was recorded in (formats, sample count, winding) and the device, so `isBundleValid` returns `false` after the target changes (a filter wrapping the container, `flipY` flipping) or after a device loss. Re-record when it does; otherwise WebGPU rejects the frame or draws inside out. Pass an array to `executeBundle` to replay several bundles in one call. The optional label names the bundle in GPU captures.
|
|
212
|
+
|
|
213
|
+
## Pooled scratch textures
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
import { TexturePool } from "pixi.js";
|
|
217
|
+
|
|
218
|
+
const scratch = TexturePool.getOptimalTexture({
|
|
219
|
+
width: bounds.width,
|
|
220
|
+
height: bounds.height,
|
|
221
|
+
resolution: renderer.resolution,
|
|
222
|
+
antialias: true,
|
|
223
|
+
scaleMode: "nearest",
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const { width, height } = TexturePool.getOptimalSize(bounds.width, bounds.height, renderer.resolution);
|
|
227
|
+
|
|
228
|
+
TexturePool.returnTexture(scratch);
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
`getOptimalTexture` takes one request object: `width` and `height` are the minimum frame size; `resolution`, `antialias`, `autoGenerateMipmaps`, `format`, and `scaleMode` are optional, and each combination has its own bucket, so ask for a float or depth format directly instead of restyling a returned texture. Each axis is rounded up to the next power of two or the renderer's screen size, whichever is smaller. `getOptimalSize` reports that backing size without taking a texture, and `getSameSizeTexture(texture)` matches an existing texture's frame and resolution. The positional `getOptimalTexture(width, height, resolution, antialias)` form, `TexturePool.textureStyle`, and `enableFullScreen` are deprecated since 8.21.0.
|
|
232
|
+
|
|
233
|
+
## API Reference
|
|
234
|
+
|
|
235
|
+
- [TexturePool](https://pixijs.download/release/docs/rendering.TexturePool.html.md)
|
|
236
|
+
- [Buffer](https://pixijs.download/release/docs/rendering.Buffer.html.md)
|
|
237
|
+
- [Geometry](https://pixijs.download/release/docs/rendering.Geometry.html.md)
|
|
238
|
+
- [State](https://pixijs.download/release/docs/rendering.State.html.md)
|
|
239
|
+
- [ShaderOverrides](https://pixijs.download/release/docs/rendering.ShaderOverrides.html.md)
|
|
240
|
+
- [GpuProgram](https://pixijs.download/release/docs/rendering.GpuProgram.html.md)
|
|
241
|
+
- [TextureView](https://pixijs.download/release/docs/rendering.TextureView.html.md)
|
|
242
|
+
- [RenderTarget](https://pixijs.download/release/docs/rendering.RenderTarget.html.md)
|
|
243
|
+
- [GpuEncoderSystem](https://pixijs.download/release/docs/rendering.GpuEncoderSystem.html.md)
|
|
244
|
+
- [RenderBundle](https://pixijs.download/release/docs/rendering.RenderBundle.html.md)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Uniform Types Reference
|
|
2
|
+
|
|
3
|
+
All supported PixiJS v8 uniform types for use with `UniformGroup`. These type strings are passed in the `type` field of each uniform definition.
|
|
4
|
+
|
|
5
|
+
## Type Table
|
|
6
|
+
|
|
7
|
+
| PixiJS type | WGSL equivalent | GLSL equivalent | JS value |
|
|
8
|
+
| ------------- | --------------- | --------------- | ----------------------------- |
|
|
9
|
+
| `f32` | `f32` | `float` | `number` |
|
|
10
|
+
| `i32` | `i32` | `int` | `number` |
|
|
11
|
+
| `vec2<f32>` | `vec2<f32>` | `vec2` | `Float32Array(2)` or `[x, y]` |
|
|
12
|
+
| `vec3<f32>` | `vec3<f32>` | `vec3` | `Float32Array(3)` |
|
|
13
|
+
| `vec4<f32>` | `vec4<f32>` | `vec4` | `Float32Array(4)` |
|
|
14
|
+
| `vec2<i32>` | `vec2<i32>` | `ivec2` | `Int32Array(2)` |
|
|
15
|
+
| `vec3<i32>` | `vec3<i32>` | `ivec3` | `Int32Array(3)` |
|
|
16
|
+
| `vec4<i32>` | `vec4<i32>` | `ivec4` | `Int32Array(4)` |
|
|
17
|
+
| `mat2x2<f32>` | `mat2x2<f32>` | `mat2` | `Float32Array(4)` |
|
|
18
|
+
| `mat3x3<f32>` | `mat3x3<f32>` | `mat3` | `Float32Array(9)` or `Matrix` |
|
|
19
|
+
| `mat4x4<f32>` | `mat4x4<f32>` | `mat4` | `Float32Array(16)` |
|
|
20
|
+
| `mat3x2<f32>` | `mat3x2<f32>` | `mat3x2` | `Float32Array(6)` |
|
|
21
|
+
| `mat4x2<f32>` | `mat4x2<f32>` | `mat4x2` | `Float32Array(8)` |
|
|
22
|
+
| `mat2x3<f32>` | `mat2x3<f32>` | `mat2x3` | `Float32Array(6)` |
|
|
23
|
+
| `mat4x3<f32>` | `mat4x3<f32>` | `mat4x3` | `Float32Array(12)` |
|
|
24
|
+
| `mat2x4<f32>` | `mat2x4<f32>` | `mat2x4` | `Float32Array(8)` |
|
|
25
|
+
| `mat3x4<f32>` | `mat3x4<f32>` | `mat3x4` | `Float32Array(12)` |
|
|
26
|
+
|
|
27
|
+
## Array Uniforms
|
|
28
|
+
|
|
29
|
+
For arrays of a type, use the `size` property instead of array syntax in the type:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { UniformGroup } from "pixi.js";
|
|
33
|
+
|
|
34
|
+
// Array of 10 vec4 values
|
|
35
|
+
const uniforms = new UniformGroup({
|
|
36
|
+
uColors: { value: new Float32Array(40), type: "vec4<f32>", size: 10 },
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Using `array<vec4<f32>, 10>` in the type field will throw an error directing you to use the `size` property instead.
|
|
41
|
+
|
|
42
|
+
## Usage Examples
|
|
43
|
+
|
|
44
|
+
### Scalars
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { UniformGroup } from "pixi.js";
|
|
48
|
+
|
|
49
|
+
const uniforms = new UniformGroup({
|
|
50
|
+
uTime: { value: 0, type: "f32" },
|
|
51
|
+
uIndex: { value: 0, type: "i32" },
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
uniforms.uniforms.uTime = 1.5;
|
|
55
|
+
uniforms.uniforms.uIndex = 3;
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Vectors
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { UniformGroup } from "pixi.js";
|
|
62
|
+
|
|
63
|
+
const uniforms = new UniformGroup({
|
|
64
|
+
uPosition: { value: new Float32Array([100, 200]), type: "vec2<f32>" },
|
|
65
|
+
uDirection: { value: new Float32Array([0, 1, 0]), type: "vec3<f32>" },
|
|
66
|
+
uColor: { value: new Float32Array([1, 0, 0, 1]), type: "vec4<f32>" },
|
|
67
|
+
uGridSize: { value: new Int32Array([16, 16]), type: "vec2<i32>" },
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Matrices
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { UniformGroup, Matrix } from "pixi.js";
|
|
75
|
+
|
|
76
|
+
const uniforms = new UniformGroup({
|
|
77
|
+
uTransform: { value: new Matrix(), type: "mat3x3<f32>" },
|
|
78
|
+
uProjection: { value: new Float32Array(16), type: "mat4x4<f32>" },
|
|
79
|
+
uRotation: { value: new Float32Array(4), type: "mat2x2<f32>" },
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
PixiJS `Matrix` (2D affine transform) maps to `mat3x3<f32>`. For 3D projection matrices, use a raw `Float32Array(16)` with `mat4x4<f32>`.
|
|
84
|
+
|
|
85
|
+
## UBO Constraints
|
|
86
|
+
|
|
87
|
+
When using `{ ubo: true }` on a UniformGroup:
|
|
88
|
+
|
|
89
|
+
- `f32` and `i32` based types are supported (scalars and vectors)
|
|
90
|
+
- Matrices are float-only (`mat*<f32>`)
|
|
91
|
+
- `u32` is not in the supported `UniformGroup` type list
|
|
92
|
+
- Samplers and textures cannot be placed in UBOs
|
|
93
|
+
- Field names and order must exactly match the shader's uniform block declaration
|
|
94
|
+
- The resource key in the shader must match the UBO block name
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pixijs-environments
|
|
3
|
+
description: "Use this skill when running PixiJS v8 outside a standard browser: Web Workers, OffscreenCanvas, Node/SSR, or CSP-restricted contexts. Covers DOMAdapter.set, BrowserAdapter, WebWorkerAdapter, custom Adapter interface, pixi.js/unsafe-eval for strict CSP. Triggers on: DOMAdapter, BrowserAdapter, WebWorkerAdapter, Web Worker, OffscreenCanvas, Node, headless, SSR, CSP, unsafe-eval, Adapter."
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
`DOMAdapter` abstracts every piece of DOM access PixiJS does (canvas creation, Image loading, fetch, XML parsing) so the library can run in non-browser contexts. Call `DOMAdapter.set(...)` before `app.init()` to swap in a different adapter.
|
|
8
|
+
|
|
9
|
+
## Quick Start
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
// worker.ts — OffscreenCanvas posted from main thread
|
|
13
|
+
DOMAdapter.set(WebWorkerAdapter);
|
|
14
|
+
|
|
15
|
+
self.onmessage = async (event) => {
|
|
16
|
+
const app = new Application();
|
|
17
|
+
await app.init({
|
|
18
|
+
canvas: event.data.canvas,
|
|
19
|
+
width: 800,
|
|
20
|
+
height: 600,
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
For CSP contexts that block `unsafe-eval`, import the polyfill before any renderer init:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import "pixi.js/unsafe-eval";
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Related skills:** `pixijs-application` (standard browser init), `pixijs-migration-v8` (settings removal, adapter changes).
|
|
32
|
+
|
|
33
|
+
## Core Patterns
|
|
34
|
+
|
|
35
|
+
### Web Worker with OffscreenCanvas
|
|
36
|
+
|
|
37
|
+
Transfer an OffscreenCanvas from the main thread, then initialize PixiJS in the worker:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
// main.ts
|
|
41
|
+
const canvas = document.createElement("canvas");
|
|
42
|
+
canvas.width = 800;
|
|
43
|
+
canvas.height = 600;
|
|
44
|
+
document.body.appendChild(canvas);
|
|
45
|
+
|
|
46
|
+
const offscreen = canvas.transferControlToOffscreen();
|
|
47
|
+
const worker = new Worker("worker.ts", { type: "module" });
|
|
48
|
+
worker.postMessage({ canvas: offscreen }, [offscreen]);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
// worker.ts
|
|
53
|
+
import { Application, DOMAdapter, WebWorkerAdapter } from "pixi.js";
|
|
54
|
+
|
|
55
|
+
DOMAdapter.set(WebWorkerAdapter);
|
|
56
|
+
|
|
57
|
+
self.onmessage = async (event) => {
|
|
58
|
+
const app = new Application();
|
|
59
|
+
await app.init({
|
|
60
|
+
canvas: event.data.canvas,
|
|
61
|
+
width: 800,
|
|
62
|
+
height: 600,
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`DOMAdapter.set(WebWorkerAdapter)` must happen before `new Application()`. The WebWorkerAdapter uses `OffscreenCanvas` instead of `document.createElement('canvas')` and `@xmldom/xmldom` for XML parsing.
|
|
68
|
+
|
|
69
|
+
Features that do **not** work inside a Web Worker (no DOM access):
|
|
70
|
+
|
|
71
|
+
- `DOMContainer` — there is no real DOM node to overlay.
|
|
72
|
+
- `AccessibilitySystem` — depends on live DOM focus and screen reader hooks.
|
|
73
|
+
- `FontFace` loading via the Font Loading API — use pre-converted bitmap fonts (`BitmapFont.install` or `.fnt` assets) instead.
|
|
74
|
+
|
|
75
|
+
### Environment-specific subpath imports
|
|
76
|
+
|
|
77
|
+
Instead of importing `pixi.js`, you can pull in a curated bundle for each environment:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import "pixi.js/browser"; // accessibility, dom, events, spritesheet, rendering, filters
|
|
81
|
+
import "pixi.js/webworker"; // spritesheet, rendering, filters (no DOM-only modules)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`pixi.js/webworker` deliberately omits `accessibility`, `dom`, and `events` because they require the DOM. Use these subpath entries when you want static, synchronous module registration instead of relying on `loadEnvironmentExtensions` to dynamic-import the right set at renderer init.
|
|
85
|
+
|
|
86
|
+
### loadEnvironmentExtensions
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { loadEnvironmentExtensions } from "pixi.js";
|
|
90
|
+
|
|
91
|
+
await loadEnvironmentExtensions(false); // false = load defaults; true = skip
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`loadEnvironmentExtensions(skip)` replaces the deprecated `autoDetectEnvironment` helper (since 8.1.6). Pass `true` to opt out of auto-loading the default browser extensions when you are bootstrapping a custom environment. `autoDetectEnvironment(add)` still exists as a shim that forwards to `loadEnvironmentExtensions(!add)`.
|
|
95
|
+
|
|
96
|
+
### CSP-compliant setup
|
|
97
|
+
|
|
98
|
+
PixiJS uses `new Function()` internally for shader compilation and uniform syncing. In Content Security Policy environments that block `unsafe-eval`, import the polyfill:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import "pixi.js/unsafe-eval";
|
|
102
|
+
import { Application } from "pixi.js";
|
|
103
|
+
|
|
104
|
+
const app = new Application();
|
|
105
|
+
await app.init({ width: 800, height: 600 });
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The `pixi.js/unsafe-eval` import replaces eval-based code generation with static polyfills for shader sync, UBO sync, uniform sync, and particle buffer updates. The import must come before any PixiJS renderer initialization.
|
|
109
|
+
|
|
110
|
+
**Tension note:** The name `pixi.js/unsafe-eval` is counterintuitive. It does not enable unsafe eval; it removes the need for it. The name refers to the CSP directive it works around.
|
|
111
|
+
|
|
112
|
+
### Custom adapter
|
|
113
|
+
|
|
114
|
+
For non-standard environments (Node.js, headless testing, SSR), implement the full Adapter interface:
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import { DOMAdapter } from "pixi.js";
|
|
118
|
+
import type { Adapter } from "pixi.js";
|
|
119
|
+
import { createCanvas, Image } from "canvas";
|
|
120
|
+
import { DOMParser } from "@xmldom/xmldom";
|
|
121
|
+
|
|
122
|
+
const HeadlessAdapter: Adapter = {
|
|
123
|
+
createCanvas: (width, height) => createCanvas(width ?? 0, height ?? 0),
|
|
124
|
+
createImage: () => new Image(),
|
|
125
|
+
getCanvasRenderingContext2D: () => CanvasRenderingContext2D,
|
|
126
|
+
getWebGLRenderingContext: () => WebGLRenderingContext,
|
|
127
|
+
getNavigator: () => ({ userAgent: "HeadlessAdapter", gpu: null }),
|
|
128
|
+
getBaseUrl: () => "file://",
|
|
129
|
+
getFontFaceSet: () => null,
|
|
130
|
+
fetch: (url, options) => fetch(url, options),
|
|
131
|
+
parseXML: (xml) => new DOMParser().parseFromString(xml, "text/xml"),
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
DOMAdapter.set(HeadlessAdapter);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
The Adapter interface requires these methods: `createCanvas`, `createImage`, `getCanvasRenderingContext2D`, `getWebGLRenderingContext`, `getNavigator`, `getBaseUrl`, `getFontFaceSet`, `fetch`, `parseXML`.
|
|
138
|
+
|
|
139
|
+
### Checking the current adapter
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import { DOMAdapter } from "pixi.js";
|
|
143
|
+
|
|
144
|
+
const adapter = DOMAdapter.get();
|
|
145
|
+
const canvas = adapter.createCanvas(256, 256);
|
|
146
|
+
const img = adapter.createImage();
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
`DOMAdapter.get()` returns whatever adapter is currently set. Use this for any DOM access within PixiJS-adjacent code instead of calling `document` or `Image` directly.
|
|
150
|
+
|
|
151
|
+
## Common Mistakes
|
|
152
|
+
|
|
153
|
+
### [CRITICAL] Not setting adapter before app.init()
|
|
154
|
+
|
|
155
|
+
Wrong:
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
const app = new Application();
|
|
159
|
+
await app.init({ width: 800, height: 600 });
|
|
160
|
+
DOMAdapter.set(WebWorkerAdapter); // too late; adapter already read during init
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Correct:
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
DOMAdapter.set(WebWorkerAdapter);
|
|
167
|
+
const app = new Application();
|
|
168
|
+
await app.init({ width: 800, height: 600 });
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
`DOMAdapter.set()` must be called before `app.init()` in non-browser environments. PixiJS reads the adapter during `app.init()` when the renderer is created. `new Application()` itself only creates the stage Container and does not read the adapter.
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
### [HIGH] Using document or Image directly
|
|
175
|
+
|
|
176
|
+
Wrong:
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
const img = new Image();
|
|
180
|
+
img.src = "texture.png";
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Correct:
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
import { DOMAdapter } from "pixi.js";
|
|
187
|
+
|
|
188
|
+
const img = DOMAdapter.get().createImage();
|
|
189
|
+
img.src = "texture.png";
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
All DOM access in PixiJS goes through DOMAdapter. Direct use of `document`, `Image`, or other browser globals breaks Web Worker and SSR compatibility.
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
### [HIGH] CSP unsafe-eval import name confusion
|
|
196
|
+
|
|
197
|
+
Wrong:
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
// CSP environment, omitting the import
|
|
201
|
+
import { Application } from "pixi.js";
|
|
202
|
+
// Throws: "Current environment does not allow unsafe-eval,
|
|
203
|
+
// please use pixi.js/unsafe-eval module to enable support."
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Correct:
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
import "pixi.js/unsafe-eval";
|
|
210
|
+
import { Application } from "pixi.js";
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
The `pixi.js/unsafe-eval` import removes the need for `eval()` / `new Function()` in shader compilation. Despite the name suggesting it enables unsafe eval, it does the opposite: it installs static polyfills so PixiJS works under strict CSP.
|
|
214
|
+
|
|
215
|
+
PixiJS detects CSP blocking at renderer init and throws the error above. The browser may also log its own CSP violation before PixiJS reports; both point to the same fix.
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
### [HIGH] Using old settings.ADAPTER pattern
|
|
219
|
+
|
|
220
|
+
Wrong:
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
import { settings, WebWorkerAdapter } from "pixi.js";
|
|
224
|
+
settings.ADAPTER = WebWorkerAdapter;
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Correct:
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
import { DOMAdapter, WebWorkerAdapter } from "pixi.js";
|
|
231
|
+
DOMAdapter.set(WebWorkerAdapter);
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
The `settings` object was removed in v8. All adapter configuration uses `DOMAdapter.set()`.
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
## API Reference
|
|
238
|
+
|
|
239
|
+
- [DOMAdapter](https://pixijs.download/release/docs/environment.DOMAdapter.html.md)
|
|
240
|
+
- [BrowserAdapter](https://pixijs.download/release/docs/environment.BrowserAdapter.html.md)
|
|
241
|
+
- [WebWorkerAdapter](https://pixijs.download/release/docs/environment.WebWorkerAdapter.html.md)
|
|
242
|
+
- [autoDetectEnvironment](https://pixijs.download/release/docs/environment.autoDetectEnvironment.html.md)
|
|
243
|
+
- [loadEnvironmentExtensions](https://pixijs.download/release/docs/environment.loadEnvironmentExtensions.html.md)
|