@silentstatestudio/perseon 0.0.0-stage → 0.1.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/CHANGELOG.md +192 -0
- package/LICENSE.md +30 -0
- package/README.md +848 -2
- package/dist/authoring/index.cjs +213 -0
- package/dist/authoring/index.d.cts +866 -0
- package/dist/authoring/index.d.ts +866 -0
- package/dist/authoring/index.js +214 -0
- package/dist/authoring/index.js.map +1 -0
- package/dist/chunk-GDXCMDJ6.js +5462 -0
- package/dist/chunk-GDXCMDJ6.js.map +1 -0
- package/dist/chunk-ON4JV4BI.js +8432 -0
- package/dist/chunk-ON4JV4BI.js.map +1 -0
- package/dist/chunk-PT7F7TTB.cjs +8431 -0
- package/dist/chunk-Q2HLLGJ7.cjs +5461 -0
- package/dist/chunk-SVI6WUOB.js +1 -0
- package/dist/chunk-SVI6WUOB.js.map +1 -0
- package/dist/chunk-ZIMCQTYK.cjs +1 -0
- package/dist/colors-CUEeQ78V.d.cts +2247 -0
- package/dist/colors-pshUJaKB.d.ts +2247 -0
- package/dist/core/index.cjs +29 -0
- package/dist/core/index.d.cts +39 -0
- package/dist/core/index.d.ts +39 -0
- package/dist/core/index.js +30 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index.cjs +29 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/pixi-v7/index.cjs +513 -0
- package/dist/pixi-v7/index.d.cts +372 -0
- package/dist/pixi-v7/index.d.ts +372 -0
- package/dist/pixi-v7/index.js +514 -0
- package/dist/pixi-v7/index.js.map +1 -0
- package/dist/pixi-v8/index.cjs +608 -0
- package/dist/pixi-v8/index.d.cts +380 -0
- package/dist/pixi-v8/index.d.ts +380 -0
- package/dist/pixi-v8/index.js +609 -0
- package/dist/pixi-v8/index.js.map +1 -0
- package/dist/rendering-DeUo1BsK.d.cts +237 -0
- package/dist/rendering-DeUo1BsK.d.ts +237 -0
- package/dist/testing/index.cjs +159 -0
- package/dist/testing/index.d.cts +85 -0
- package/dist/testing/index.d.ts +85 -0
- package/dist/testing/index.js +160 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +148 -6
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { ParticleContainer, Filter, Particle, Container, Ticker, ApplicationOptions, Application, Texture, Spritesheet, SpritesheetData } from 'pixi.js';
|
|
2
|
+
import { I as IParticleGroup, b as IParticleVisualState, a as IParticleGroupOptions, c as IRenderRootNode, d as IRenderNode, f as IRenderer, e as ITicker, h as IRendererCapabilities, g as ITextureRef, P as ParticleBlendMode, B as BlendModeSupport } from '../rendering-DeUo1BsK.cjs';
|
|
3
|
+
export { i as IShape } from '../rendering-DeUo1BsK.cjs';
|
|
4
|
+
import { P as PerseonIntegration } from '../colors-CUEeQ78V.cjs';
|
|
5
|
+
export { A as AnimationDescription, a as AnimationPlayOptions, b as AnimationRandomnessOptions, C as CapacityOptions, c as CapsuleArea, d as CircleArea, e as ColorGradientDefinition, f as ColorOptions, g as ColorRandomRange, h as ColorStop, i as CurveDefinition, j as CustomParameterOption, k as CustomParameterSampleScope, l as CustomParameterType, m as CustomParameterValue, D as DiagnosticsPolicy, E as EmissionOptions, n as EmissionTransform, o as Emitter, p as EmitterEventBinding, q as EmitterEventBindings, r as EmitterEventTrigger, s as EmitterEventsByTrigger, t as EmitterOptionPath, u as EmitterOptionType, v as EmitterOptions, w as EventTrigger, x as ExternalForcesFactorOptions, y as ExternalForcesForEmitterUse, z as ExternalForcesOptions, B as ExternalForcesTypes, G as GlobalParameterOption, I as InitialStateOptions, K as KineticsOptions, L as LayerOptionPath, F as LayerOptionType, H as LocalDefaultHandle, J as LocalParameterHandle, M as ModifierBlendMode, N as ModulatableNumber, O as ModulatedValue, Q as ModulatorOptions, R as ModulatorShape, S as NumberOptions, T as NumericDomain, U as OptionNodeKind, V as OptionStage, W as OptionStrategy, X as ParameterDescription, Y as ParameterHandle, Z as ParameterInitOptions, _ as ParameterLinkRelation, $ as ParameterModifier, a0 as ParameterModifierSource, a1 as ParameterUpdateOptions, a2 as ParticleAnimationOptions, a3 as ParticleEventBinding, a4 as ParticleEventBindings, a5 as ParticleEventTrigger, a6 as ParticleEventsByTrigger, a7 as ParticleHookEmitter, a8 as ParticleHookPlayback, a9 as ParticleHookRandom, aa as ParticleItem, ab as ParticleLayer, ac as ParticleLayerOptions, ad as ParticleLimitStrategy, ae as ParticleRegionRef, af as ParticleSnapshot, ag as ParticleSnapshotObject, ah as ParticleSpawnStrategy, ai as ParticleSpriteAnimationParameters, aj as PerformanceOptions, ak as PerseonAnimation, al as PerseonEvent, am as PerseonPlayback, an as PlaybackFinishedReason, ao as PlaybackFinishedResult, ap as PlaybackHost, aq as PlaybackOptionPath, ar as PlaybackOptionType, as as PlaybackOptions, at as PointForceConfig, au as PointForceFalloff, av as PointForceMode, aw as PointValue, ax as PolygonArea, ay as ProbabilityCurveKind, az as ProbabilityCurvePreset, aA as ProbabilityCurvePresetId, aB as RandomListState, aC as RandomValueList, aD as RandomValueListMode, aE as RandomValueRange, aF as RandomnessOptions, aG as RandomnessSeedMode, aH as RectangleArea, aI as RegionBehavior, aJ as RegionOptions, aK as RingArea, aL as ScaleOptions, aM as ShapeArea, aN as SingleTextureOption, aO as SpawnColor, aP as SpawnNumber, aQ as SpawnPoint, aR as SpawnPosition, aS as SpawnVector, aT as SpriteAnimationOptions, aU as SpriteAnimationTexturesOptions, aV as TextDomain, aW as TextureElement, aX as Unsubscribe, aY as ValueProbability, aZ as VectorValue } from '../colors-CUEeQ78V.cjs';
|
|
6
|
+
export { PerseonConfigError, parseAnimationOptions } from '../core/index.cjs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* One render group per particle layer. Wraps a Pixi v8 `ParticleContainer`; each
|
|
10
|
+
* engine particle mirrors a `Pixi.Particle` stored in the container's buffer.
|
|
11
|
+
*
|
|
12
|
+
* The mirror `Pixi.Particle` is stashed on the engine particle's
|
|
13
|
+
* `renderHandle` slot (see `IParticleVisualState.renderHandle`), so the
|
|
14
|
+
* per-frame `syncFrame` reads a direct field instead of a per-particle map
|
|
15
|
+
* lookup in the hot loop. Copying ~10 fields per particle is a tight loop and
|
|
16
|
+
* is dominated by GPU rasterization at any realistic particle count.
|
|
17
|
+
*/
|
|
18
|
+
declare class PixiV8ParticleGroup implements IParticleGroup {
|
|
19
|
+
readonly container: ParticleContainer;
|
|
20
|
+
/**
|
|
21
|
+
* Engine particles mirrored by this group, in the same order as the
|
|
22
|
+
* container's buffer. Kept so `syncFrame` iterates only this layer's
|
|
23
|
+
* particles and reads each one's `renderHandle` directly.
|
|
24
|
+
*/
|
|
25
|
+
protected _particles: IParticleVisualState[];
|
|
26
|
+
/** The advanced blend filter on `container`, if the mode needs one. */
|
|
27
|
+
protected _blendFilter: Filter | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* On the container, where the advanced blend filter also is: hidden, Pixi
|
|
30
|
+
* collects neither its particles nor the filter's pass.
|
|
31
|
+
*/
|
|
32
|
+
get visible(): boolean;
|
|
33
|
+
set visible(value: boolean);
|
|
34
|
+
constructor(options: IParticleGroupOptions);
|
|
35
|
+
get size(): number;
|
|
36
|
+
addParticle(particle: IParticleVisualState, index: number): void;
|
|
37
|
+
removeParticle(particle: IParticleVisualState): void;
|
|
38
|
+
removeAll(): void;
|
|
39
|
+
syncFrame(): void;
|
|
40
|
+
destroy(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Pixi pins the container's texture to the first particle it draws and never
|
|
43
|
+
* lets go. An empty group drops it, so the next particles, whatever image
|
|
44
|
+
* they come from, set it again.
|
|
45
|
+
*/
|
|
46
|
+
protected _releaseTexture(): void;
|
|
47
|
+
/**
|
|
48
|
+
* The blend pass covers the whole screen whether or not the layer has
|
|
49
|
+
* anything to draw. A layer with no live particles turns it off, and Pixi
|
|
50
|
+
* skips a filter stack whose filters are all disabled.
|
|
51
|
+
*/
|
|
52
|
+
protected _syncBlendPass(): void;
|
|
53
|
+
protected _writeState(p: IParticleVisualState, pixi: Particle): void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* One emitter's node in the Pixi v8 scene graph: a plain `Container` whose
|
|
58
|
+
* children are that emitter's Particle Layer groups, in z-order.
|
|
59
|
+
*
|
|
60
|
+
* Destroying a node releases it from the renderer that created it, so a scene
|
|
61
|
+
* that adds and removes emitters leaves nothing behind. Destroy is idempotent —
|
|
62
|
+
* a renderer tearing down after the engine already did must be a no-op.
|
|
63
|
+
*/
|
|
64
|
+
declare class PixiV8RenderNode implements IRenderRootNode<Container> {
|
|
65
|
+
readonly container: Container;
|
|
66
|
+
protected _groups: PixiV8ParticleGroup[];
|
|
67
|
+
/** Child nodes (an emitter's, when this is a playback root). */
|
|
68
|
+
protected _children: PixiV8RenderNode[];
|
|
69
|
+
protected _release: (node: PixiV8RenderNode) => void;
|
|
70
|
+
protected _destroyed: boolean;
|
|
71
|
+
constructor(release: (node: PixiV8RenderNode) => void);
|
|
72
|
+
get hostDestroyed(): boolean;
|
|
73
|
+
get visible(): boolean;
|
|
74
|
+
set visible(value: boolean);
|
|
75
|
+
get x(): number;
|
|
76
|
+
set x(value: number);
|
|
77
|
+
get y(): number;
|
|
78
|
+
set y(value: number);
|
|
79
|
+
/**
|
|
80
|
+
* Attach under a host container, moving the node if it was mounted
|
|
81
|
+
* elsewhere — `addChild` already reparents, so a pooled playback replayed
|
|
82
|
+
* under a different container needs nothing more.
|
|
83
|
+
*
|
|
84
|
+
* Only a playback's root is ever mounted; an emitter's child node is
|
|
85
|
+
* parented by `createChildNode` and never leaves.
|
|
86
|
+
*/
|
|
87
|
+
mount(parent: Container): void;
|
|
88
|
+
unmount(): void;
|
|
89
|
+
createChildNode(): IRenderNode;
|
|
90
|
+
protected _releaseChild(node: PixiV8RenderNode): void;
|
|
91
|
+
createParticleGroup(options: IParticleGroupOptions): IParticleGroup;
|
|
92
|
+
setGroupIndex(group: IParticleGroup, index: number): void;
|
|
93
|
+
destroyParticleGroup(group: IParticleGroup): void;
|
|
94
|
+
destroy(): void;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface PixiV8RendererOptions {
|
|
98
|
+
/**
|
|
99
|
+
* Optional Pixi v8 `Ticker` to drive engine updates. When omitted,
|
|
100
|
+
* `Ticker.shared` is used.
|
|
101
|
+
*/
|
|
102
|
+
ticker?: Ticker;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* PixiJS v8 implementation of `IRenderer`. Creates one detached root
|
|
106
|
+
* `PixiV8RenderNode` per playback, which the host mounts; each emitter gets a
|
|
107
|
+
* child node holding its layer groups (`ParticleContainer`s).
|
|
108
|
+
*/
|
|
109
|
+
declare class PixiV8Renderer implements IRenderer<Container> {
|
|
110
|
+
/** An adapter over `options.ticker`, or over Pixi's shared one, that drives the engine's updates. */
|
|
111
|
+
readonly ticker: ITicker;
|
|
112
|
+
/** What this backend does with each blend mode — see `IRendererCapabilities`. */
|
|
113
|
+
readonly capabilities: IRendererCapabilities;
|
|
114
|
+
protected _textureCache: Map<unknown, ITextureRef>;
|
|
115
|
+
protected _nodes: PixiV8RenderNode[];
|
|
116
|
+
/** @param options - Optional settings; see `PixiV8RendererOptions`. */
|
|
117
|
+
constructor(options?: PixiV8RendererOptions);
|
|
118
|
+
/** Detached: the caller mounts it where the animation should appear. */
|
|
119
|
+
createRootNode(): IRenderRootNode<Container>;
|
|
120
|
+
/** Called by a node when it is destroyed, so the renderer holds only live ones. */
|
|
121
|
+
protected _releaseNode(node: PixiV8RenderNode): void;
|
|
122
|
+
/**
|
|
123
|
+
* The texture a scene's `texture.source` names. The id must have been published to
|
|
124
|
+
* Pixi's `Assets.cache` beforehand (see `PixiV8ParticleAtlas`); an unknown id, or a
|
|
125
|
+
* source that is not a string, resolves to an empty texture. Answers are memoized
|
|
126
|
+
* until `clearTextureCache`.
|
|
127
|
+
*/
|
|
128
|
+
resolveTexture(source: unknown): ITextureRef;
|
|
129
|
+
/** See `IRenderer.clearTextureCache` — what a host calls after republishing an atlas. */
|
|
130
|
+
clearTextureCache(): void;
|
|
131
|
+
/** Destroys every root node this renderer created and empties its texture cache. */
|
|
132
|
+
destroy(): void;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
interface PerseonOptions {
|
|
136
|
+
/**
|
|
137
|
+
* What every animation runs off: the Pixi v8 `Ticker` — `app.ticker`,
|
|
138
|
+
* normally; defaults to `Ticker.shared` — or any `ITicker`, such as the
|
|
139
|
+
* `FakeTicker` of `@silentstatestudio/perseon/testing`, whose frames a test pumps by hand.
|
|
140
|
+
*/
|
|
141
|
+
ticker?: Ticker | ITicker;
|
|
142
|
+
/**
|
|
143
|
+
* What a recoverable misuse does — a Linked source that resolves to nothing,
|
|
144
|
+
* a number a `set` clips to its domain, a stale handle, a value of
|
|
145
|
+
* `setGlobalParameter` an animation that declares the global cannot take:
|
|
146
|
+
* `'warn'` prints it once per animation with the `Perseon - ` prefix,
|
|
147
|
+
* `'throw'` turns it into an error, `'silent'` drops it. Defaults to
|
|
148
|
+
* `'warn'`.
|
|
149
|
+
*/
|
|
150
|
+
diagnostics?: 'warn' | 'throw' | 'silent';
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Perseon on PixiJS v8: the one object an app builds to use particle animations,
|
|
154
|
+
* and the only place the host's renderer and ticker are named.
|
|
155
|
+
*
|
|
156
|
+
* ```ts
|
|
157
|
+
* import { Perseon } from '@silentstatestudio/perseon/pixi-v8'
|
|
158
|
+
*
|
|
159
|
+
* const perseon = new Perseon({ ticker: app.ticker }) // once, in the app
|
|
160
|
+
* const explosion = perseon.createAnimation(explosionConfig) // once per effect
|
|
161
|
+
*
|
|
162
|
+
* explosion.play({ parent: world, x: hit.x, y: hit.y }) // as often as you like
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* The three levels each cost something different, which is why they are three
|
|
166
|
+
* objects: this one is the integration (one per app, free), a `PerseonAnimation`
|
|
167
|
+
* is a compiled config (one per kind of effect, expensive, built at load time),
|
|
168
|
+
* and a playback is one showing of it (many, pooled, cheap).
|
|
169
|
+
*
|
|
170
|
+
* Every playback of every animation shares **one** callback on the host's
|
|
171
|
+
* ticker, so a scene with two hundred effects still registers a single frame
|
|
172
|
+
* subscriber, stepped in a defined order.
|
|
173
|
+
*
|
|
174
|
+
* Everything above the renderer lives in `PerseonIntegration`; what this class
|
|
175
|
+
* adds is the one thing that cannot be shared — what PixiJS v8 in particular
|
|
176
|
+
* has to hand over. `@silentstatestudio/perseon/pixi-v7` exports its own `Perseon` under the same
|
|
177
|
+
* name, so swapping backends is swapping the import.
|
|
178
|
+
*/
|
|
179
|
+
declare class Perseon extends PerseonIntegration<Container> {
|
|
180
|
+
/**
|
|
181
|
+
* Re-typed, not re-assigned: the base declares the renderer as an
|
|
182
|
+
* `IRenderer`, and a host reaching for this one wants the v8 adapter it
|
|
183
|
+
* actually is — its atlas-facing methods included.
|
|
184
|
+
*/
|
|
185
|
+
readonly renderer: PixiV8Renderer;
|
|
186
|
+
constructor(options?: PerseonOptions);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The rendering backend Pixi resolved to. */
|
|
190
|
+
type RendererBackend = 'webgpu' | 'webgl';
|
|
191
|
+
interface CreatePixiApplicationOptions extends Partial<ApplicationOptions> {
|
|
192
|
+
/**
|
|
193
|
+
* Prefer the WebGPU rendering backend. Defaults to `true`.
|
|
194
|
+
*
|
|
195
|
+
* This is a *preference*, not a hard requirement: when WebGPU is
|
|
196
|
+
* unavailable in the host browser Pixi falls back to WebGL on its own, so
|
|
197
|
+
* `true` never breaks a session — it just asks for the faster backend when
|
|
198
|
+
* it exists. Set `false` to force WebGL (e.g. to sidestep a driver bug or
|
|
199
|
+
* to compare backends).
|
|
200
|
+
*
|
|
201
|
+
* Named `preferWebGPU` rather than `webgpu` because Pixi's own
|
|
202
|
+
* `ApplicationOptions.webgpu` is the WebGPU adapter/device config object —
|
|
203
|
+
* a different concern this flag sits above.
|
|
204
|
+
*/
|
|
205
|
+
preferWebGPU?: boolean;
|
|
206
|
+
}
|
|
207
|
+
interface CreatedPixiApplication {
|
|
208
|
+
app: Application;
|
|
209
|
+
/**
|
|
210
|
+
* The backend Pixi actually resolved to after `init`. May differ from the
|
|
211
|
+
* request: asking for `webgpu` on a browser without it yields `'webgl'`.
|
|
212
|
+
*/
|
|
213
|
+
backend: RendererBackend;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Creates and initializes a Pixi v8 `Application`, defaulting to the WebGPU
|
|
217
|
+
* rendering backend with automatic fallback to WebGL. This is the single place
|
|
218
|
+
* the library expresses its backend preference, so a host can opt out with one
|
|
219
|
+
* flag rather than reconstructing the `init` call.
|
|
220
|
+
*
|
|
221
|
+
* An explicit Pixi `preference` takes precedence over `preferWebGPU`. Every
|
|
222
|
+
* other `Application` option is forwarded untouched — callers pass their
|
|
223
|
+
* usual `backgroundAlpha`, `antialias`, `resolution`, `width`, `height`, etc.
|
|
224
|
+
*/
|
|
225
|
+
declare function createPixiApplication(options?: CreatePixiApplicationOptions): Promise<CreatedPixiApplication>;
|
|
226
|
+
/** Reads back the backend a live `Application` is rendering with. */
|
|
227
|
+
declare function resolveRendererBackend(app: Application): RendererBackend;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Adapts a PixiJS v8 `Ticker` to the engine-facing `ITicker` interface.
|
|
231
|
+
* Maintains the function-to-wrapper mapping so `remove(fn)` finds the same
|
|
232
|
+
* wrapper that `add(fn)` previously registered with the Pixi ticker.
|
|
233
|
+
*/
|
|
234
|
+
declare class PixiV8TickerAdapter implements ITicker {
|
|
235
|
+
protected _ticker: Ticker;
|
|
236
|
+
protected _wrapped: Map<(deltaMS: number) => void, (ticker: Ticker) => void>;
|
|
237
|
+
constructor(ticker: Ticker);
|
|
238
|
+
add(fn: (deltaMS: number) => void): void;
|
|
239
|
+
remove(fn: (deltaMS: number) => void): void;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* What the PixiJS v8 adapter can do — see `IRendererCapabilities`.
|
|
244
|
+
*
|
|
245
|
+
* Every mode in the catalog is honored here, the advanced ones by the filter
|
|
246
|
+
* each `PixiV8ParticleGroup` carries; what differs is the price, and that is
|
|
247
|
+
* what a host is told so it can say it.
|
|
248
|
+
*/
|
|
249
|
+
declare class PixiV8RendererCapabilities implements IRendererCapabilities {
|
|
250
|
+
constructor();
|
|
251
|
+
blendModeSupport(mode: ParticleBlendMode): BlendModeSupport;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Resolve the texture a scene names.
|
|
256
|
+
*
|
|
257
|
+
* Every string source is a **cache id**, with no exceptions: an animation names
|
|
258
|
+
* resources the host registered beforehand — `ParticleAnimationOptions` says as
|
|
259
|
+
* much, and this is where it holds — so a source resolves against `Assets.cache`
|
|
260
|
+
* and against nothing else. An id the cache does not know becomes
|
|
261
|
+
* `Texture.EMPTY`: one particle type pointing at a frame that is no longer
|
|
262
|
+
* published must not take an animation down, and a host that wants to report it
|
|
263
|
+
* asks ahead of time against the same cache.
|
|
264
|
+
*
|
|
265
|
+
* A URL is not a special case, and used to be treated as one. Resolving it here
|
|
266
|
+
* cannot work: this runs in the spawn path, loading is asynchronous, and in
|
|
267
|
+
* PixiJS v8 `Texture.from(string)` reads the cache alone — so a URL that was
|
|
268
|
+
* never loaded returned `undefined` from a function typed to return a `Texture`,
|
|
269
|
+
* which then travelled into the renderer as if it were one. What a host does
|
|
270
|
+
* instead is `await Assets.load(url)`, after which the URL *is* a cache id and
|
|
271
|
+
* resolves here like every other source.
|
|
272
|
+
*
|
|
273
|
+
* A source that is not a string is not an id, so it resolves to nothing.
|
|
274
|
+
*/
|
|
275
|
+
declare const textureFromSource: (source: unknown) => Texture;
|
|
276
|
+
|
|
277
|
+
/** Key the atlas is registered under in `Assets.cache` when none is given. */
|
|
278
|
+
declare const PARTICLE_ATLAS_CACHE_KEY = "perseon:particle-atlas";
|
|
279
|
+
/**
|
|
280
|
+
* Host-side loader for the atlas a scene's texture ids point at.
|
|
281
|
+
*
|
|
282
|
+
* A serialized scene carries texture **ids**, not images: every
|
|
283
|
+
* `texture.source` names a frame the host is expected to have registered
|
|
284
|
+
* beforehand, which is what lets one atlas serve every particle in the scene
|
|
285
|
+
* instead of embedding the same image once per use. This class is the other
|
|
286
|
+
* half of that contract — give it the `.png` + `.json` pair the editor exports
|
|
287
|
+
* and the ids in the scene file resolve.
|
|
288
|
+
*
|
|
289
|
+
* Registering the spritesheet in `Assets.cache` is what publishes the frames:
|
|
290
|
+
* Pixi's cache parser for spritesheets adds one entry per frame name, which is
|
|
291
|
+
* what `textureFromSource` reads.
|
|
292
|
+
*
|
|
293
|
+
* Ownership is explicit, because getting it wrong corrupts Pixi's own cache:
|
|
294
|
+
* an image handed in as a `Texture` belongs to the caller, and one loaded here
|
|
295
|
+
* from a URL is released through `Assets.unload` rather than destroyed behind
|
|
296
|
+
* Assets' back (which would leave a dead entry for the next load of that URL).
|
|
297
|
+
* An image `Assets` already held before the load stays the host's and is never
|
|
298
|
+
* unloaded; one this class took is unloaded once no atlas holds it any more.
|
|
299
|
+
*
|
|
300
|
+
* Frame ids are global: each one becomes an unprefixed key in `Assets.cache`.
|
|
301
|
+
* Loading throws, before publishing anything, when an id is already cached by
|
|
302
|
+
* something no atlas published, so a host's own entries are never overwritten
|
|
303
|
+
* or deleted. Between atlases the last one to publish an id wins it, and
|
|
304
|
+
* destroying an atlas gives back only the ids it still owns. Each atlas needs
|
|
305
|
+
* its own `cacheKey`: loading throws when the key already holds an entry that
|
|
306
|
+
* is not this atlas's own sheet.
|
|
307
|
+
*
|
|
308
|
+
* Note on URLs: pass an `http(s):` or `data:` URL. Pixi's texture loader
|
|
309
|
+
* recognizes neither the extension nor the MIME type of a `blob:` URL, so an
|
|
310
|
+
* object URL must be read into a data URL (or a `Texture`) first.
|
|
311
|
+
*/
|
|
312
|
+
declare class PixiV8ParticleAtlas {
|
|
313
|
+
protected _cacheKey: string;
|
|
314
|
+
protected _spritesheet?: Spritesheet;
|
|
315
|
+
/** URL this instance acquired through `Assets`, so it releases exactly what it took. */
|
|
316
|
+
protected _loadedImageUrl?: string;
|
|
317
|
+
/**
|
|
318
|
+
* Generation counter. A host can call `load` again before the previous one
|
|
319
|
+
* settles (a user picking files quickly); without this the loser would
|
|
320
|
+
* publish its sheet over the winner's and leak the winner's.
|
|
321
|
+
*/
|
|
322
|
+
protected _loadToken: number;
|
|
323
|
+
/** @param cacheKey - The key the spritesheet is registered under in `Assets.cache`; give distinct keys to atlases that coexist. */
|
|
324
|
+
constructor(cacheKey?: string);
|
|
325
|
+
/** The spritesheet published by the last successful `load`, or `undefined` before one or after `destroy`. */
|
|
326
|
+
get spritesheet(): Spritesheet | undefined;
|
|
327
|
+
/**
|
|
328
|
+
* Frame ids of this atlas's sheet — the values a scene's `texture.source` may
|
|
329
|
+
* name. Another atlas may have published the same id since, and wins it.
|
|
330
|
+
*/
|
|
331
|
+
get frameIds(): string[];
|
|
332
|
+
/** Whether `frameId` is one of this atlas's frames (a later atlas may have published the same id since). */
|
|
333
|
+
hasFrame(frameId: string): boolean;
|
|
334
|
+
/**
|
|
335
|
+
* Load an atlas and publish its frames. Replaces whatever this instance had
|
|
336
|
+
* loaded before, so a host can swap atlases as the user picks new files.
|
|
337
|
+
*
|
|
338
|
+
* @returns The parsed spritesheet. When a later `load` or `destroy` superseded
|
|
339
|
+
* this call before it finished, nothing was published and the sheet returned
|
|
340
|
+
* is one that never was and is already destroyed.
|
|
341
|
+
* @throws When the data lacks `frames` or `meta`; when a frame id is already
|
|
342
|
+
* cached by something no atlas published; or when this atlas's `cacheKey`
|
|
343
|
+
* already holds an entry that is not its own sheet. Nothing is published, the
|
|
344
|
+
* previous atlas stays loaded, and the image taken for this call is released.
|
|
345
|
+
*/
|
|
346
|
+
load(image: string | Texture, data: SpritesheetData): Promise<Spritesheet>;
|
|
347
|
+
/** Unpublish the frames and release whatever this instance owns. */
|
|
348
|
+
destroy(): Promise<void>;
|
|
349
|
+
/**
|
|
350
|
+
* Two atlases on one key would unpublish each other's frames without either
|
|
351
|
+
* knowing, and a key the host uses would be deleted. Throws instead, before
|
|
352
|
+
* anything is published. The sheet this instance already published is its own.
|
|
353
|
+
*/
|
|
354
|
+
protected _assertCacheKeyFree(): void;
|
|
355
|
+
/**
|
|
356
|
+
* Every frame becomes a global, unprefixed key in `Assets.cache`, so an id
|
|
357
|
+
* the host already uses would be overwritten and then deleted along with the
|
|
358
|
+
* atlas. Throws instead, before anything is published. An entry another atlas
|
|
359
|
+
* published is not the host's: the last atlas to publish an id wins it.
|
|
360
|
+
*/
|
|
361
|
+
protected _assertFrameIdsFree(data: SpritesheetData): void;
|
|
362
|
+
/**
|
|
363
|
+
* Remove the entry published under this atlas's key, and with it the frames
|
|
364
|
+
* of `sheet`. Removing the key deletes every id the sheet published, so an id
|
|
365
|
+
* another atlas has since taken over is put back: it is not this one's to drop.
|
|
366
|
+
*/
|
|
367
|
+
protected _unpublish(sheet: Spritesheet | undefined): void;
|
|
368
|
+
/** Record that an atlas now holds `url`. */
|
|
369
|
+
protected _acquireUrl(url: string): void;
|
|
370
|
+
/** Give back a hold taken for a load that failed before anything was loaded. */
|
|
371
|
+
protected _returnUrl(url: string | undefined): void;
|
|
372
|
+
/**
|
|
373
|
+
* Let go of `url`, unloading it only once no atlas holds it any more.
|
|
374
|
+
* Unknown URLs are ignored, so a load still in flight when `destroy` lands
|
|
375
|
+
* releases its own acquisition without driving the count below zero.
|
|
376
|
+
*/
|
|
377
|
+
protected _releaseUrl(url: string | undefined): Promise<void>;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export { BlendModeSupport, type CreatePixiApplicationOptions, type CreatedPixiApplication, IParticleGroup, IParticleGroupOptions, IParticleVisualState, IRenderNode, IRenderRootNode, IRenderer, IRendererCapabilities, ITextureRef, ITicker, PARTICLE_ATLAS_CACHE_KEY, ParticleBlendMode, Perseon, type PerseonOptions, PixiV8ParticleAtlas, PixiV8ParticleGroup, PixiV8RenderNode, PixiV8Renderer, PixiV8RendererCapabilities, type PixiV8RendererOptions, PixiV8TickerAdapter, type RendererBackend, createPixiApplication, resolveRendererBackend, textureFromSource };
|