@silentstatestudio/perseon 0.0.0-stage → 0.1.1
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 +219 -0
- package/LICENSE.md +73 -0
- package/README.md +849 -2
- package/dist/authoring/index.cjs +218 -0
- package/dist/authoring/index.d.cts +964 -0
- package/dist/authoring/index.d.ts +964 -0
- package/dist/authoring/index.js +219 -0
- package/dist/authoring/index.js.map +1 -0
- package/dist/chunk-443SQYAB.cjs +8468 -0
- package/dist/chunk-AVYXWDFD.js +8469 -0
- package/dist/chunk-AVYXWDFD.js.map +1 -0
- package/dist/chunk-BEDH7OYG.js +5484 -0
- package/dist/chunk-BEDH7OYG.js.map +1 -0
- package/dist/chunk-WEQPSGPS.cjs +5482 -0
- package/dist/chunk-ZIMCQTYK.cjs +6 -0
- package/dist/chunk-ZTG42LPX.js +6 -0
- package/dist/chunk-ZTG42LPX.js.map +1 -0
- package/dist/colors-CCeWL9q4.d.cts +2597 -0
- package/dist/colors-CGWrMf4V.d.ts +2597 -0
- package/dist/core/index.cjs +34 -0
- package/dist/core/index.d.cts +40 -0
- package/dist/core/index.d.ts +40 -0
- package/dist/core/index.js +35 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index.cjs +34 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/pixi-v7/index.cjs +587 -0
- package/dist/pixi-v7/index.d.cts +471 -0
- package/dist/pixi-v7/index.d.ts +471 -0
- package/dist/pixi-v7/index.js +588 -0
- package/dist/pixi-v7/index.js.map +1 -0
- package/dist/pixi-v8/index.cjs +679 -0
- package/dist/pixi-v8/index.d.cts +452 -0
- package/dist/pixi-v8/index.d.ts +452 -0
- package/dist/pixi-v8/index.js +680 -0
- package/dist/pixi-v8/index.js.map +1 -0
- package/dist/rendering-dYQXmGTV.d.cts +264 -0
- package/dist/rendering-dYQXmGTV.d.ts +264 -0
- package/dist/testing/index.cjs +182 -0
- package/dist/testing/index.d.cts +103 -0
- package/dist/testing/index.d.ts +103 -0
- package/dist/testing/index.js +184 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +144 -5
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
import { ParticleContainer, Sprite, Container, Ticker, Texture, Spritesheet } 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-dYQXmGTV.js';
|
|
3
|
+
export { i as IShape } from '../rendering-dYQXmGTV.js';
|
|
4
|
+
import { P as PerseonIntegration } from '../colors-CGWrMf4V.js';
|
|
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 ExternalForcesOptions, z as ExternalForcesTypes, G as GlobalParameterOption, I as InitialStateOptions, K as KineticsOptions, L as LayerOptionPath, B as LayerOptionType, F as LocalDefaultHandle, H as LocalParameterHandle, M as ModifierBlendMode, J as ModulatableNumber, N as ModulatedValue, O as ModulatorOptions, Q as ModulatorShape, R as NumberOptions, S as NumericDomain, T as OptionNodeKind, U as OptionStage, V as OptionStrategy, W as ParameterDescription, X as ParameterHandle, Y as ParameterInitOptions, Z as ParameterLinkRelation, _ as ParameterModifier, $ as ParameterModifierSource, a0 as ParameterUpdateOptions, a1 as ParticleAnimationOptions, a2 as ParticleEventBinding, a3 as ParticleEventBindings, a4 as ParticleEventTrigger, a5 as ParticleEventsByTrigger, a6 as ParticleHookEmitter, a7 as ParticleHookPlayback, a8 as ParticleHookRandom, a9 as ParticleItem, aa as ParticleLayer, ab as ParticleLayerOptions, ac as ParticleLimitStrategy, ad as ParticleRegionRef, ae as ParticleSnapshot, af as ParticleSnapshotObject, ag as ParticleSpawnStrategy, ah as ParticleSpriteAnimationParameters, ai as PerformanceOptions, aj as PerseonAnimation, ak as PerseonEvent, al as PerseonPlayback, am as PlaybackFinishedReason, an as PlaybackFinishedResult, ao as PlaybackHost, ap as PlaybackOptionPath, aq as PlaybackOptionType, ar as PlaybackOptions, as as PointForceConfig, at as PointForceFalloff, au as PointForceMode, av as PointValue, aw as PolygonArea, ax as ProbabilityCurveKind, ay as ProbabilityCurvePreset, az as ProbabilityCurvePresetId, aA as RandomListState, aB as RandomValueList, aC as RandomValueListMode, aD as RandomValueRange, aE as RandomnessOptions, aF as RandomnessSeedMode, aG as RectangleArea, aH as RegionBehavior, aI as RegionOptions, aJ as RingArea, aK as ScaleOptions, aL as ShapeArea, aM as SingleTextureOption, aN as SpawnColor, aO as SpawnNumber, aP as SpawnPoint, aQ as SpawnPosition, aR as SpawnVector, aS as SpriteAnimationOptions, aT as SpriteAnimationTexturesOptions, aU as TextDomain, aV as TextureElement, aW as Unsubscribe, aX as ValueProbability, aY as VectorValue } from '../colors-CGWrMf4V.js';
|
|
6
|
+
export { PerseonConfigError, parseAnimationOptions } from '../core/index.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* One render group per particle layer. Wraps a Pixi v7 `ParticleContainer` and keeps
|
|
10
|
+
* a mirror map between engine particles (`IParticleVisualState`) and the
|
|
11
|
+
* `Pixi.Sprite` instances inside the container.
|
|
12
|
+
*
|
|
13
|
+
* v7 differences from v8:
|
|
14
|
+
* - Children are `Sprite`s, not `Particle`s.
|
|
15
|
+
* - `position`, `scale`, `anchor` are `Point` objects (use `.set(x, y)`).
|
|
16
|
+
* - Alpha and tint are independent properties (no encoded color).
|
|
17
|
+
*/
|
|
18
|
+
declare class PixiV7ParticleGroup implements IParticleGroup {
|
|
19
|
+
/**
|
|
20
|
+
* The Pixi `ParticleContainer` that draws this layer's sprites. The render node that created the group adds it to its own container; `destroy` destroys it.
|
|
21
|
+
*/
|
|
22
|
+
readonly container: ParticleContainer;
|
|
23
|
+
/** Pairs each engine particle with the `Sprite` that mirrors it inside the container. */
|
|
24
|
+
protected _mirror: Map<IParticleVisualState, Sprite>;
|
|
25
|
+
get size(): number;
|
|
26
|
+
/** On the container: hidden, its sprites are not drawn and stay in it. */
|
|
27
|
+
get visible(): boolean;
|
|
28
|
+
set visible(value: boolean);
|
|
29
|
+
/**
|
|
30
|
+
* Creates an auto-resizing `ParticleContainer`. Only the properties that `options.dynamicProperties` marks as changing (plus position, always) are re-uploaded each frame, and `options.blendMode` (`normal` when omitted) becomes the container's numeric blend mode. Modes v7 cannot blend on WebGL draw as `normal`; `PixiV7RendererCapabilities` reports them as `unsupported`.
|
|
31
|
+
*
|
|
32
|
+
* @param options - The layer's dynamic properties and blend mode.
|
|
33
|
+
*/
|
|
34
|
+
constructor(options: IParticleGroupOptions);
|
|
35
|
+
addParticle(particle: IParticleVisualState, index: number): void;
|
|
36
|
+
removeParticle(particle: IParticleVisualState): void;
|
|
37
|
+
removeAll(): void;
|
|
38
|
+
syncFrame(): void;
|
|
39
|
+
destroy(): void;
|
|
40
|
+
/** Copies the engine particle's position, scale, rotation, anchor, alpha, tint and texture onto its `Sprite`. */
|
|
41
|
+
protected _writeState(p: IParticleVisualState, sprite: Sprite): void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* One emitter's node in the Pixi v7 scene graph: a plain `Container` whose
|
|
46
|
+
* children are that emitter's Particle Layer groups, in z-order.
|
|
47
|
+
*
|
|
48
|
+
* Destroying a node releases it from the renderer that created it, so a scene
|
|
49
|
+
* that adds and removes emitters leaves nothing behind. Destroy is idempotent —
|
|
50
|
+
* a renderer tearing down after the engine already did must be a no-op.
|
|
51
|
+
*/
|
|
52
|
+
declare class PixiV7RenderNode implements IRenderRootNode<Container> {
|
|
53
|
+
/**
|
|
54
|
+
* The Pixi `Container` this node wraps. It is created with the node and destroyed when the node is destroyed.
|
|
55
|
+
*/
|
|
56
|
+
readonly container: Container;
|
|
57
|
+
/** The particle groups created through this node and not yet removed with `destroyParticleGroup`. They are destroyed with it. */
|
|
58
|
+
protected _groups: PixiV7ParticleGroup[];
|
|
59
|
+
/** Child nodes (an emitter's, when this is a playback root). */
|
|
60
|
+
protected _children: PixiV7RenderNode[];
|
|
61
|
+
/**
|
|
62
|
+
* Callback run once, from `destroy`, so whoever created this node (the renderer for a root, the parent node for a child) stops tracking it.
|
|
63
|
+
*/
|
|
64
|
+
protected _release: (node: PixiV7RenderNode) => void;
|
|
65
|
+
/** Set by the first `destroy`, so that later calls do nothing. */
|
|
66
|
+
protected _destroyed: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Creates the node with an empty Pixi container.
|
|
69
|
+
*
|
|
70
|
+
* @param release - Called with this node when it is destroyed, so its creator can drop it.
|
|
71
|
+
*/
|
|
72
|
+
constructor(release: (node: PixiV7RenderNode) => void);
|
|
73
|
+
get hostDestroyed(): boolean;
|
|
74
|
+
/** Whether the node's container is shown. Hidden, Pixi draws neither it nor anything under it. */
|
|
75
|
+
get visible(): boolean;
|
|
76
|
+
set visible(value: boolean);
|
|
77
|
+
/** Horizontal position of the node's container, in its parent's local coordinates. */
|
|
78
|
+
get x(): number;
|
|
79
|
+
set x(value: number);
|
|
80
|
+
/** Vertical position of the node's container, in its parent's local coordinates. */
|
|
81
|
+
get y(): number;
|
|
82
|
+
set y(value: number);
|
|
83
|
+
/**
|
|
84
|
+
* Attach under a host container, moving the node if it was mounted
|
|
85
|
+
* elsewhere — `addChild` already reparents, so a pooled playback replayed
|
|
86
|
+
* under a different container needs nothing more.
|
|
87
|
+
*
|
|
88
|
+
* Only a playback's root is ever mounted; an emitter's child node is
|
|
89
|
+
* parented by `createChildNode` and never leaves.
|
|
90
|
+
*/
|
|
91
|
+
mount(parent: Container): void;
|
|
92
|
+
unmount(): void;
|
|
93
|
+
createChildNode(): IRenderNode;
|
|
94
|
+
/**
|
|
95
|
+
* Drops a destroyed child node from this node's list. It is the release callback `createChildNode` hands to each child.
|
|
96
|
+
*/
|
|
97
|
+
protected _releaseChild(node: PixiV7RenderNode): void;
|
|
98
|
+
createParticleGroup(options: IParticleGroupOptions): IParticleGroup;
|
|
99
|
+
setGroupIndex(group: IParticleGroup, index: number): void;
|
|
100
|
+
destroyParticleGroup(group: IParticleGroup): void;
|
|
101
|
+
destroy(): void;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Options for `PixiV7Renderer`. */
|
|
105
|
+
interface PixiV7RendererOptions {
|
|
106
|
+
/** Optional Pixi v7 `Ticker`. Falls back to `Ticker.shared` when omitted. */
|
|
107
|
+
ticker?: Ticker;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* PixiJS v7 implementation of `IRenderer`. Same architecture as the v8
|
|
111
|
+
* adapter: one detached root `PixiV7RenderNode` per playback, which the host
|
|
112
|
+
* mounts; each emitter gets a child node holding its layer groups
|
|
113
|
+
* (`ParticleContainer`s of `Sprite`s).
|
|
114
|
+
*/
|
|
115
|
+
declare class PixiV7Renderer implements IRenderer<Container> {
|
|
116
|
+
/** An adapter over `options.ticker`, or over Pixi's shared one, that drives the engine's updates. */
|
|
117
|
+
readonly ticker: ITicker;
|
|
118
|
+
/** What this backend does with each blend mode — see `IRendererCapabilities`. */
|
|
119
|
+
readonly capabilities: IRendererCapabilities;
|
|
120
|
+
/**
|
|
121
|
+
* Textures already resolved, keyed by the `source` value given to `resolveTexture`. Emptied by `clearTextureCache` and `destroy`.
|
|
122
|
+
*/
|
|
123
|
+
protected _textureCache: Map<unknown, ITextureRef>;
|
|
124
|
+
/**
|
|
125
|
+
* The root nodes this renderer created and that are still alive, so `destroy` can tear them down. A node leaves the list when it is destroyed.
|
|
126
|
+
*/
|
|
127
|
+
protected _nodes: PixiV7RenderNode[];
|
|
128
|
+
/**
|
|
129
|
+
* Creates the renderer, wrapping `options.ticker` (or Pixi's shared ticker) in an adapter.
|
|
130
|
+
*
|
|
131
|
+
* @param options - Optional settings; see `PixiV7RendererOptions`.
|
|
132
|
+
*/
|
|
133
|
+
constructor(options?: PixiV7RendererOptions);
|
|
134
|
+
/** Detached: the caller mounts it where the animation should appear. */
|
|
135
|
+
createRootNode(): IRenderRootNode<Container>;
|
|
136
|
+
/** Called by a node when it is destroyed, so the renderer holds only live ones. */
|
|
137
|
+
protected _releaseNode(node: PixiV7RenderNode): void;
|
|
138
|
+
/**
|
|
139
|
+
* The texture a scene's `texture.source` names. The id must have been published to
|
|
140
|
+
* Pixi's `Assets.cache` beforehand (see `PixiV7ParticleAtlas`); an unknown id, or a
|
|
141
|
+
* source that is not a string, resolves to an empty texture. Answers are memoized
|
|
142
|
+
* until `clearTextureCache`, so an id resolved before it was published stays empty
|
|
143
|
+
* until then.
|
|
144
|
+
*/
|
|
145
|
+
resolveTexture(source: unknown): ITextureRef;
|
|
146
|
+
/** See `IRenderer.clearTextureCache` — what a host calls after republishing an atlas. */
|
|
147
|
+
clearTextureCache(): void;
|
|
148
|
+
destroy(): void;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Options for the `Perseon` constructor. Both are optional, so `new Perseon()` works with Pixi's shared ticker. */
|
|
152
|
+
interface PerseonOptions {
|
|
153
|
+
/**
|
|
154
|
+
* What every animation runs off: the Pixi v7 `Ticker` — `app.ticker`,
|
|
155
|
+
* normally; defaults to `Ticker.shared` — or any `ITicker`, such as the
|
|
156
|
+
* `FakeTicker` of `@silentstatestudio/perseon/testing`, whose frames a test pumps by hand.
|
|
157
|
+
*/
|
|
158
|
+
ticker?: Ticker | ITicker;
|
|
159
|
+
/**
|
|
160
|
+
* What a recoverable misuse does — a Linked source that resolves to nothing,
|
|
161
|
+
* a number a `set` clips to its domain, a stale handle, a value of
|
|
162
|
+
* `setGlobalParameter` an animation that declares the global cannot take:
|
|
163
|
+
* `'warn'` prints it once per animation with the `Perseon - ` prefix,
|
|
164
|
+
* `'throw'` turns it into an error, `'silent'` drops it. Defaults to
|
|
165
|
+
* `'warn'`.
|
|
166
|
+
*/
|
|
167
|
+
diagnostics?: 'warn' | 'throw' | 'silent';
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Perseon on PixiJS v7 — the same class, the same name and the same API as the
|
|
171
|
+
* v8 one, an import path apart:
|
|
172
|
+
*
|
|
173
|
+
* ```ts
|
|
174
|
+
* import { Perseon } from '@silentstatestudio/perseon/pixi-v7'
|
|
175
|
+
*
|
|
176
|
+
* const perseon = new Perseon({ ticker: app.ticker })
|
|
177
|
+
* const explosion = perseon.createAnimation(explosionConfig)
|
|
178
|
+
* explosion.play({ parent: world, x: hit.x, y: hit.y })
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* That is the point of the shape rather than a coincidence of it: everything
|
|
182
|
+
* above the renderer is `PerseonIntegration`, so the two backends cannot drift,
|
|
183
|
+
* and moving an app between Pixi majors is one line. What differs is only what
|
|
184
|
+
* this host hands over, which here happens to match v8 — a ticker — and will not
|
|
185
|
+
* for the next backend along.
|
|
186
|
+
*/
|
|
187
|
+
declare class Perseon extends PerseonIntegration<Container> {
|
|
188
|
+
/** Re-typed, not re-assigned — see the v8 integration. */
|
|
189
|
+
readonly renderer: PixiV7Renderer;
|
|
190
|
+
/**
|
|
191
|
+
* Creates the integration for PixiJS v7. A Pixi `Ticker` is wrapped by the renderer this builds; any other
|
|
192
|
+
* `ITicker` is used as the frame source as it is.
|
|
193
|
+
*
|
|
194
|
+
* @param options - Optional settings; see `PerseonOptions`.
|
|
195
|
+
*/
|
|
196
|
+
constructor(options?: PerseonOptions);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Adapts a PixiJS v7 `Ticker` to the engine-facing `ITicker` interface.
|
|
201
|
+
* In v7 the ticker callback receives `dt` (delta time in frames at 60fps),
|
|
202
|
+
* not milliseconds. We read `ticker.deltaMS` from the closure to feed the
|
|
203
|
+
* engine its expected ms-based delta.
|
|
204
|
+
*/
|
|
205
|
+
declare class PixiV7TickerAdapter implements ITicker {
|
|
206
|
+
/** The Pixi ticker being wrapped. */
|
|
207
|
+
protected _ticker: Ticker;
|
|
208
|
+
/**
|
|
209
|
+
* Pairs each function given to `add` with the wrapper registered on the Pixi ticker, so `remove` can unregister that same wrapper.
|
|
210
|
+
*/
|
|
211
|
+
protected _wrapped: Map<(deltaMS: number) => void, () => void>;
|
|
212
|
+
/**
|
|
213
|
+
* Wraps a Pixi ticker. The constructor neither starts nor stops it, but Pixi starts a ticker whose
|
|
214
|
+
* `autoStart` is set (such as `Ticker.shared`) when `add` registers the first function.
|
|
215
|
+
*
|
|
216
|
+
* @param ticker - The Pixi `Ticker` whose frames drive the functions added to this adapter.
|
|
217
|
+
*/
|
|
218
|
+
constructor(ticker: Ticker);
|
|
219
|
+
add(fn: (deltaMS: number) => void): void;
|
|
220
|
+
remove(fn: (deltaMS: number) => void): void;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* What the PixiJS v7 adapter can do — see `IRendererCapabilities`.
|
|
225
|
+
*
|
|
226
|
+
* There is no filter path here to make the rest work: v7 renders particles
|
|
227
|
+
* through its own `ParticleContainer`, whose children never reach the advanced
|
|
228
|
+
* blend pipeline that arrived with v8. So the answer for those modes is
|
|
229
|
+
* `unsupported`, said out loud, rather than a promise the frame will not keep.
|
|
230
|
+
*/
|
|
231
|
+
declare class PixiV7RendererCapabilities implements IRendererCapabilities {
|
|
232
|
+
blendModeSupport(mode: ParticleBlendMode): BlendModeSupport;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Resolve the texture a scene names.
|
|
237
|
+
*
|
|
238
|
+
* Every string source is a **cache id**, with no exceptions: an animation names
|
|
239
|
+
* resources the host registered beforehand — `ParticleAnimationOptions` says as
|
|
240
|
+
* much, and this is where it holds — so a source resolves against `Assets.cache`
|
|
241
|
+
* and against nothing else. (`Assets` is part of PixiJS from 7.0 on, which is
|
|
242
|
+
* the whole of this adapter's peer range.) An id the cache does not know becomes
|
|
243
|
+
* `Texture.EMPTY`: one particle type pointing at a frame that is no longer
|
|
244
|
+
* published must not take an animation down, and a host that wants to report it
|
|
245
|
+
* asks ahead of time against the same cache.
|
|
246
|
+
*
|
|
247
|
+
* A URL is not a special case, and used to be treated as one. In v7 that did
|
|
248
|
+
* resolve — `Texture.from` takes a string it does not know for an image path —
|
|
249
|
+
* which is worse than it sounds: it starts a network request from inside the
|
|
250
|
+
* spawn path and hands back a texture that is not there yet. It also made the
|
|
251
|
+
* same scene file behave differently on each adapter, since v8's `Texture.from`
|
|
252
|
+
* reads the cache alone. What a host does instead is `await Assets.load(url)`,
|
|
253
|
+
* after which the URL *is* a cache id and resolves here like every other source.
|
|
254
|
+
*
|
|
255
|
+
* A source that is not a string is not an id, so it resolves to nothing.
|
|
256
|
+
*/
|
|
257
|
+
declare const textureFromSource: (source: unknown) => Texture;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* The atlas `.json` `load` accepts, written out here because Pixi 7 names it
|
|
261
|
+
* `ISpritesheetData` and Pixi 8 `SpritesheetData`: importing either name would
|
|
262
|
+
* break the declarations for the other major. Structurally the same as both.
|
|
263
|
+
*/
|
|
264
|
+
interface PixiV7SpritesheetData {
|
|
265
|
+
/**
|
|
266
|
+
* The frames of the atlas, keyed by frame id: the ids a scene's `texture.source` names.
|
|
267
|
+
* Each entry is laid out as in Pixi's spritesheet JSON. `frame` is the frame's rectangle
|
|
268
|
+
* in the sheet image, with `x`, `y`, `w` and `h` in pixels. `sourceSize` is the sprite's
|
|
269
|
+
* size before trimming and `spriteSourceSize` the rectangle the frame occupies inside it.
|
|
270
|
+
* `trimmed` and `rotated` say whether the frame was trimmed or rotated when packed.
|
|
271
|
+
* `anchor` is the frame's default anchor (particles use their own anchor instead) and
|
|
272
|
+
* `borders` its 9-slice borders (`left`, `top`, `right`, `bottom`).
|
|
273
|
+
*/
|
|
274
|
+
frames: Record<string, {
|
|
275
|
+
frame: {
|
|
276
|
+
x: number;
|
|
277
|
+
y: number;
|
|
278
|
+
w: number;
|
|
279
|
+
h: number;
|
|
280
|
+
};
|
|
281
|
+
trimmed?: boolean;
|
|
282
|
+
rotated?: boolean;
|
|
283
|
+
sourceSize?: {
|
|
284
|
+
w: number;
|
|
285
|
+
h: number;
|
|
286
|
+
};
|
|
287
|
+
spriteSourceSize?: {
|
|
288
|
+
x: number;
|
|
289
|
+
y: number;
|
|
290
|
+
w?: number;
|
|
291
|
+
h?: number;
|
|
292
|
+
};
|
|
293
|
+
anchor?: {
|
|
294
|
+
x: number;
|
|
295
|
+
y: number;
|
|
296
|
+
};
|
|
297
|
+
borders?: {
|
|
298
|
+
left: number;
|
|
299
|
+
top: number;
|
|
300
|
+
right: number;
|
|
301
|
+
bottom: number;
|
|
302
|
+
};
|
|
303
|
+
}>;
|
|
304
|
+
/** Named animations: each name maps to the ordered list of frame ids that make it up. */
|
|
305
|
+
animations?: Record<string, string[]>;
|
|
306
|
+
/**
|
|
307
|
+
* Metadata about the sheet and its image, as in Pixi's spritesheet format. Only `scale`
|
|
308
|
+
* is required.
|
|
309
|
+
*/
|
|
310
|
+
meta: {
|
|
311
|
+
/** Name of the tool that packed the sheet. */
|
|
312
|
+
app?: string;
|
|
313
|
+
/** Pixel format of the sheet image, as the packing tool reports it. */
|
|
314
|
+
format?: string;
|
|
315
|
+
/** Named frame ranges, each with a first (`from`) and last (`to`) frame number and a `direction`. */
|
|
316
|
+
frameTags?: {
|
|
317
|
+
from: number;
|
|
318
|
+
name: string;
|
|
319
|
+
to: number;
|
|
320
|
+
direction: string;
|
|
321
|
+
}[];
|
|
322
|
+
/** File name or URL of the sheet image. `load` does not read it: the image is its own argument. */
|
|
323
|
+
image?: string;
|
|
324
|
+
/** Layer information from the packing tool: a name, blend mode and opacity per layer. */
|
|
325
|
+
layers?: {
|
|
326
|
+
blendMode: string;
|
|
327
|
+
name: string;
|
|
328
|
+
opacity: number;
|
|
329
|
+
}[];
|
|
330
|
+
/** Resolution of the sheet image, as a number or a numeric string. Pixi reads it with `parseFloat`. */
|
|
331
|
+
scale: number | string;
|
|
332
|
+
/** Size of the sheet image in pixels. */
|
|
333
|
+
size?: {
|
|
334
|
+
w: number;
|
|
335
|
+
h: number;
|
|
336
|
+
};
|
|
337
|
+
/**
|
|
338
|
+
* Named slices defined in the packing tool, each with a `color` and a list of `keys`;
|
|
339
|
+
* each key has a `frame` number and a `bounds` rectangle (`x`, `y`, `w`, `h`).
|
|
340
|
+
*/
|
|
341
|
+
slices?: {
|
|
342
|
+
color: string;
|
|
343
|
+
name: string;
|
|
344
|
+
keys: {
|
|
345
|
+
frame: number;
|
|
346
|
+
bounds: {
|
|
347
|
+
x: number;
|
|
348
|
+
y: number;
|
|
349
|
+
w: number;
|
|
350
|
+
h: number;
|
|
351
|
+
};
|
|
352
|
+
}[];
|
|
353
|
+
}[];
|
|
354
|
+
/** Other sheets of the same multi-pack set. `load` does not follow them; load each sheet into its own atlas. */
|
|
355
|
+
related_multi_packs?: string[];
|
|
356
|
+
/** Version of the packing tool or format that wrote the sheet. */
|
|
357
|
+
version?: string;
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
/** Key the atlas is registered under in `Assets.cache` when none is given. */
|
|
361
|
+
declare const PARTICLE_ATLAS_CACHE_KEY = "perseon:particle-atlas";
|
|
362
|
+
/**
|
|
363
|
+
* Host-side loader for the atlas a scene's texture ids point at — the v7 half of
|
|
364
|
+
* `PixiV8ParticleAtlas`, with the same API and the same ownership rules.
|
|
365
|
+
*
|
|
366
|
+
* A serialized scene carries texture **ids**, not images: every
|
|
367
|
+
* `texture.source` names a frame the host is expected to have registered
|
|
368
|
+
* beforehand, which is what lets one atlas serve every particle in the scene
|
|
369
|
+
* instead of embedding the same image once per use. This class is the other
|
|
370
|
+
* half of that contract — give it the `.png` + `.json` pair that Perseon
|
|
371
|
+
* Particle Studio exports, or any Pixi spritesheet, and the ids in the scene
|
|
372
|
+
* file resolve.
|
|
373
|
+
*
|
|
374
|
+
* `Spritesheet.parse()` also adds every frame to Pixi's global texture cache,
|
|
375
|
+
* which `Texture.from` reads; what `textureFromSource` reads is `Assets.cache`, so
|
|
376
|
+
* registering the sheet there is what publishes the frames.
|
|
377
|
+
*
|
|
378
|
+
* Ownership is explicit, because getting it wrong corrupts Pixi's own cache:
|
|
379
|
+
* an image handed in as a `Texture` belongs to the caller, and one loaded here
|
|
380
|
+
* from a URL is released through `Assets.unload` rather than destroyed behind
|
|
381
|
+
* Assets' back (which would leave a dead entry for the next load of that URL).
|
|
382
|
+
* An image `Assets` already held before the load stays the host's and is never
|
|
383
|
+
* unloaded; one this class took is unloaded once no atlas holds it any more.
|
|
384
|
+
*
|
|
385
|
+
* Frame ids are global: each one becomes an unprefixed key in `Assets.cache`.
|
|
386
|
+
* Loading throws, before publishing anything, when an id is already cached by
|
|
387
|
+
* something no atlas published, so a host's own entries are never overwritten
|
|
388
|
+
* or deleted. Between atlases the last one to publish an id wins it, and
|
|
389
|
+
* destroying an atlas gives back only the ids it still owns. Each atlas needs
|
|
390
|
+
* its own `cacheKey`: loading throws when the key already holds an entry that
|
|
391
|
+
* is not this atlas's own sheet.
|
|
392
|
+
*
|
|
393
|
+
* Note on URLs: pass an `http(s):` or `data:` URL. Pixi's texture loader
|
|
394
|
+
* recognizes neither the extension nor the MIME type of a `blob:` URL, so an
|
|
395
|
+
* object URL must be read into a data URL (or a `Texture`) first.
|
|
396
|
+
*/
|
|
397
|
+
declare class PixiV7ParticleAtlas {
|
|
398
|
+
/** The key the spritesheet is published under in `Assets.cache`. */
|
|
399
|
+
protected _cacheKey: string;
|
|
400
|
+
/** The sheet published by the last successful `load`; cleared by `destroy`. */
|
|
401
|
+
protected _spritesheet?: Spritesheet;
|
|
402
|
+
/** URL this instance acquired through `Assets`, so it releases exactly what it took. */
|
|
403
|
+
protected _loadedImageUrl?: string;
|
|
404
|
+
/**
|
|
405
|
+
* Generation counter. A host can call `load` again before the previous one
|
|
406
|
+
* settles (a user picking files quickly); without this the loser would
|
|
407
|
+
* publish its sheet over the winner's and leak the winner's.
|
|
408
|
+
*/
|
|
409
|
+
protected _loadToken: number;
|
|
410
|
+
/**
|
|
411
|
+
* Creates an empty atlas; nothing is published until `load`.
|
|
412
|
+
*
|
|
413
|
+
* @param cacheKey - The key the spritesheet is registered under in `Assets.cache`; give distinct keys to atlases that coexist.
|
|
414
|
+
*/
|
|
415
|
+
constructor(cacheKey?: string);
|
|
416
|
+
/** The spritesheet published by the last successful `load`, or `undefined` before one or after `destroy`. */
|
|
417
|
+
get spritesheet(): Spritesheet | undefined;
|
|
418
|
+
/**
|
|
419
|
+
* Frame ids of this atlas's sheet — the values a scene's `texture.source` may
|
|
420
|
+
* name. Another atlas may have published the same id since, and wins it.
|
|
421
|
+
*/
|
|
422
|
+
get frameIds(): string[];
|
|
423
|
+
/** Whether `frameId` is one of this atlas's frames (a later atlas may have published the same id since). */
|
|
424
|
+
hasFrame(frameId: string): boolean;
|
|
425
|
+
/**
|
|
426
|
+
* Load an atlas and publish its frames. Replaces whatever this instance had
|
|
427
|
+
* loaded before, so a host can swap atlases as the user picks new files.
|
|
428
|
+
*
|
|
429
|
+
* @returns The parsed spritesheet. When a later `load` or `destroy` superseded
|
|
430
|
+
* this call before it finished, nothing was published and the sheet returned
|
|
431
|
+
* is one that never was and is already destroyed.
|
|
432
|
+
* @throws When the data lacks `frames` or `meta`; when a frame id is already
|
|
433
|
+
* cached by something no atlas published; or when this atlas's `cacheKey`
|
|
434
|
+
* already holds an entry that is not its own sheet. Nothing is published, the
|
|
435
|
+
* previous atlas stays loaded, and the image taken for this call is released.
|
|
436
|
+
*/
|
|
437
|
+
load(image: string | Texture, data: PixiV7SpritesheetData): Promise<Spritesheet>;
|
|
438
|
+
/** Unpublish the frames and release whatever this instance owns. */
|
|
439
|
+
destroy(): Promise<void>;
|
|
440
|
+
/**
|
|
441
|
+
* Two atlases on one key would unpublish each other's frames without either
|
|
442
|
+
* knowing, and a key the host uses would be deleted. Throws instead, before
|
|
443
|
+
* anything is published. The sheet this instance already published is its own.
|
|
444
|
+
*/
|
|
445
|
+
protected _assertCacheKeyFree(): void;
|
|
446
|
+
/**
|
|
447
|
+
* Every frame becomes a global, unprefixed key in `Assets.cache`, so an id
|
|
448
|
+
* the host already uses would be overwritten and then deleted along with the
|
|
449
|
+
* atlas. Throws instead, before anything is published. An entry another atlas
|
|
450
|
+
* published is not the host's: the last atlas to publish an id wins it.
|
|
451
|
+
*/
|
|
452
|
+
protected _assertFrameIdsFree(data: PixiV7SpritesheetData): void;
|
|
453
|
+
/**
|
|
454
|
+
* Remove the entry published under this atlas's key, and with it the frames
|
|
455
|
+
* of `sheet`. Removing the key deletes every id the sheet published, so an id
|
|
456
|
+
* another atlas has since taken over is put back: it is not this one's to drop.
|
|
457
|
+
*/
|
|
458
|
+
protected _unpublish(sheet: Spritesheet | undefined): void;
|
|
459
|
+
/** Record that an atlas now holds `url`. */
|
|
460
|
+
protected _acquireUrl(url: string): void;
|
|
461
|
+
/** Give back a hold taken for a load that failed before anything was loaded. */
|
|
462
|
+
protected _returnUrl(url: string | undefined): void;
|
|
463
|
+
/**
|
|
464
|
+
* Let go of `url`, unloading it only once no atlas holds it any more.
|
|
465
|
+
* Unknown URLs are ignored, so a load still in flight when `destroy` lands
|
|
466
|
+
* releases its own acquisition without driving the count below zero.
|
|
467
|
+
*/
|
|
468
|
+
protected _releaseUrl(url: string | undefined): Promise<void>;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
export { BlendModeSupport, IParticleGroup, IParticleGroupOptions, IParticleVisualState, IRenderNode, IRenderRootNode, IRenderer, IRendererCapabilities, ITextureRef, ITicker, PARTICLE_ATLAS_CACHE_KEY, ParticleBlendMode, Perseon, type PerseonOptions, PixiV7ParticleAtlas, PixiV7ParticleGroup, PixiV7RenderNode, PixiV7Renderer, PixiV7RendererCapabilities, type PixiV7RendererOptions, type PixiV7SpritesheetData, PixiV7TickerAdapter, textureFromSource };
|