@margoengine/vfx 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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +1642 -3
- package/dist/base-C9upJytz.js +658 -0
- package/dist/base.d.ts +767 -0
- package/dist/base.js +1 -0
- package/dist/blown-sand.d.ts +218 -0
- package/dist/blown-sand.js +700 -0
- package/dist/clouds.d.ts +229 -0
- package/dist/clouds.js +566 -0
- package/dist/compat-CVSEj1Bp.js +217 -0
- package/dist/compat.d.ts +59 -0
- package/dist/curves.d.ts +11 -0
- package/dist/curves.js +59 -0
- package/dist/debris.d.ts +111 -0
- package/dist/debris.js +258 -0
- package/dist/depth-collide.d.ts +7 -0
- package/dist/depth-collide.js +96 -0
- package/dist/emitter.d.ts +10 -0
- package/dist/emitter.js +125 -0
- package/dist/events.d.ts +9 -0
- package/dist/events.js +131 -0
- package/dist/extra-CgGjbojB.js +4 -0
- package/dist/extra.d.ts +2 -0
- package/dist/fields.d.ts +11 -0
- package/dist/fields.js +95 -0
- package/dist/fire-front.d.ts +539 -0
- package/dist/fire-front.js +840 -0
- package/dist/fire.d.ts +119 -0
- package/dist/fire.js +173 -0
- package/dist/flame-ramp-VoBKpYnM.js +75 -0
- package/dist/flame-ramp.d.ts +61 -0
- package/dist/flame.d.ts +260 -0
- package/dist/flame.js +605 -0
- package/dist/flipbook.d.ts +7 -0
- package/dist/flipbook.js +23 -0
- package/dist/fog-B-kBv7g0.js +32 -0
- package/dist/frame-BuvMFBPp.js +4 -0
- package/dist/frame.d.ts +7 -0
- package/dist/gunfire.d.ts +696 -0
- package/dist/gunfire.js +1204 -0
- package/dist/hash-Btsp6fGK.js +7 -0
- package/dist/hash.d.ts +2 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +60 -0
- package/dist/json.d.ts +53 -0
- package/dist/json.js +237 -0
- package/dist/lit.d.ts +11 -0
- package/dist/lit.js +105 -0
- package/dist/mesh.d.ts +14 -0
- package/dist/mesh.js +225 -0
- package/dist/node-system.d.ts +315 -0
- package/dist/node-system.js +384 -0
- package/dist/nodes.d.ts +14 -0
- package/dist/nodes.js +293 -0
- package/dist/obstacles.d.ts +3 -0
- package/dist/obstacles.js +25 -0
- package/dist/over-life.d.ts +14 -0
- package/dist/over-life.js +93 -0
- package/dist/require-webgpu--tUXPsmA.js +7 -0
- package/dist/ribbons.d.ts +20 -0
- package/dist/ribbons.js +151 -0
- package/dist/schedule.d.ts +29 -0
- package/dist/schedule.js +47 -0
- package/dist/settings.d.ts +362 -0
- package/dist/settings.js +707 -0
- package/dist/shader.d.ts +44 -0
- package/dist/shadows.d.ts +26 -0
- package/dist/shadows.js +182 -0
- package/dist/shapes.d.ts +34 -0
- package/dist/shapes.js +81 -0
- package/dist/shared/fog.d.ts +33 -0
- package/dist/shared/pass.d.ts +53 -0
- package/dist/shared/settings.d.ts +89 -0
- package/dist/skinned.d.ts +11 -0
- package/dist/skinned.js +104 -0
- package/dist/smoke.d.ts +215 -0
- package/dist/smoke.js +280 -0
- package/dist/soft.d.ts +17 -0
- package/dist/soft.js +55 -0
- package/dist/solid.d.ts +168 -0
- package/dist/solid.js +403 -0
- package/dist/sort.d.ts +3 -0
- package/dist/sort.js +58 -0
- package/dist/space.d.ts +14 -0
- package/dist/space.js +88 -0
- package/dist/stretch.d.ts +7 -0
- package/dist/stretch.js +40 -0
- package/dist/texture.d.ts +8 -0
- package/dist/texture.js +45 -0
- package/dist/view-RKprOPAy.js +30 -0
- package/dist/view-rect-DkeiiUtw.js +13 -0
- package/dist/wrap.d.ts +3 -0
- package/dist/wrap.js +5 -0
- package/package.json +192 -6
package/dist/hash.d.ts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { EngineKernel } from '@margoengine/core';
|
|
2
|
+
import { VFX as VFXBase, type VFXOptions } from './base.js';
|
|
3
|
+
export type { VFXShape } from './shapes.js';
|
|
4
|
+
export type { VFXSchedule, VFXScheduledBurst } from './schedule.js';
|
|
5
|
+
export type { VFXOverLife } from './over-life.js';
|
|
6
|
+
export type { VFXSpace } from './space.js';
|
|
7
|
+
export type { BurstSpawn } from './base.js';
|
|
8
|
+
export { VFX_TICK_RATE } from './base.js';
|
|
9
|
+
export type { VFXOptions, VFXWind, VFXObstacle, VFXTexture, VFXCurves, VFXEmitter, ParticleAtlas, VFXFeatures, FogLike, VFXRibbons, VFXMeshParticles, VFXEvents, VFXLit, VFXLightSource, VFXDepthCollide, VFXStretch, VFXFields, VFXAttractor, VFXVectorField, VFXSkinned, VFXSkinnedPrimitive, VFXFlipbook, VFXShadows, VFXParticleLight, VFXNodes, VFXNode, VFXNodeSample, } from './base.js';
|
|
10
|
+
/**
|
|
11
|
+
* GPU particles with every optional feature (obstacles, wrap, sort, texture, curves, emitter, soft, ribbons, mesh, events, lit, depthCollide, stretch, fields, skinned, flipbook, shadows, nodes). Effects that use none of them load
|
|
12
|
+
* less with `VFX` from `@margoengine/vfx/base`, adding only the feature entries they use.
|
|
13
|
+
*/
|
|
14
|
+
export declare class VFX extends VFXBase {
|
|
15
|
+
constructor(options?: VFXOptions);
|
|
16
|
+
static attach(instance: EngineKernel, options?: VFXOptions): VFX;
|
|
17
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// @margo/core-built 0.1.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
const C=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
|
+
import { n as e, t } from "./base-C9upJytz.js";
|
|
5
|
+
import { obstacles as n } from "./obstacles.js";
|
|
6
|
+
import { wrap as r } from "./wrap.js";
|
|
7
|
+
import { sort as i } from "./sort.js";
|
|
8
|
+
import { textureFeature as a } from "./texture.js";
|
|
9
|
+
import { curves as o } from "./curves.js";
|
|
10
|
+
import { shapes as s } from "./shapes.js";
|
|
11
|
+
import { soft as c } from "./soft.js";
|
|
12
|
+
import { ribbons as l } from "./ribbons.js";
|
|
13
|
+
import { mesh as u } from "./mesh.js";
|
|
14
|
+
import { events as d } from "./events.js";
|
|
15
|
+
import { lit as f } from "./lit.js";
|
|
16
|
+
import { depthCollide as p } from "./depth-collide.js";
|
|
17
|
+
import { stretch as m } from "./stretch.js";
|
|
18
|
+
import { fields as h } from "./fields.js";
|
|
19
|
+
import { skinned as g } from "./skinned.js";
|
|
20
|
+
import { flipbook as _ } from "./flipbook.js";
|
|
21
|
+
import { shadows as v } from "./shadows.js";
|
|
22
|
+
import { nodes as y } from "./nodes.js";
|
|
23
|
+
import { space as b } from "./space.js";
|
|
24
|
+
import { overLife as x } from "./over-life.js";
|
|
25
|
+
import { schedule as S } from "./schedule.js";
|
|
26
|
+
import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
27
|
+
//#region src/index.ts
|
|
28
|
+
var w = {
|
|
29
|
+
obstacles: n,
|
|
30
|
+
wrap: r,
|
|
31
|
+
sort: i,
|
|
32
|
+
texture: a,
|
|
33
|
+
curves: o,
|
|
34
|
+
emitter: s,
|
|
35
|
+
soft: c,
|
|
36
|
+
ribbons: l,
|
|
37
|
+
mesh: u,
|
|
38
|
+
events: d,
|
|
39
|
+
lit: f,
|
|
40
|
+
depthCollide: p,
|
|
41
|
+
stretch: m,
|
|
42
|
+
fields: h,
|
|
43
|
+
skinned: g,
|
|
44
|
+
flipbook: _,
|
|
45
|
+
shadows: v,
|
|
46
|
+
nodes: y,
|
|
47
|
+
space: b,
|
|
48
|
+
overLife: x,
|
|
49
|
+
schedule: S
|
|
50
|
+
}, T = class e extends t {
|
|
51
|
+
constructor(e = {}) {
|
|
52
|
+
super(e, w);
|
|
53
|
+
}
|
|
54
|
+
static attach(t, n = {}) {__margoAssertCore(t,__margoCoreRequirement("0.1.0",import.meta.url));
|
|
55
|
+
let r = new e(n);
|
|
56
|
+
return C(t).use(r), r;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
60
|
+
export { T as VFX, e as VFX_TICK_RATE };
|
package/dist/json.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { VFX } from '@margoengine/vfx';
|
|
2
|
+
import type { VFX as Base, VFXOptions, FogLike } from './base.js';
|
|
3
|
+
/** Current effect document version. Unknown versions reject instead of silently dropping features. */
|
|
4
|
+
export declare const VFX_JSON_VERSION = 1;
|
|
5
|
+
/** Decoded authoring preset. Contains configuration and fog, not running particle/GPU state. */
|
|
6
|
+
export interface VFXPreset {
|
|
7
|
+
/** Format version, currently 1. */
|
|
8
|
+
version: typeof VFX_JSON_VERSION;
|
|
9
|
+
/** All effect options, including typed array assets and externally resolved bindings. */
|
|
10
|
+
options: VFXOptions;
|
|
11
|
+
/** Fog configuration; default null. */
|
|
12
|
+
fog: FogLike | null;
|
|
13
|
+
}
|
|
14
|
+
/** Resource and allocation limits shared by JSON operations. */
|
|
15
|
+
export interface VFXJSONLimits {
|
|
16
|
+
/** Most UTF-16 code units in serialized text. Default 512 Mi. */
|
|
17
|
+
maxChars?: number;
|
|
18
|
+
/** Most visited values, including typed array elements. Default 100,000,000. */
|
|
19
|
+
maxNodes?: number;
|
|
20
|
+
/** Most nested arrays/objects. Default 64. */
|
|
21
|
+
maxDepth?: number;
|
|
22
|
+
}
|
|
23
|
+
/** Serialization settings; object/function bindings become stable reference IDs. */
|
|
24
|
+
export interface VFXJSONWriteOptions extends VFXJSONLimits {
|
|
25
|
+
/** Explicit external resources, for example a depth supplier, light sink or skinned primitive. Default none. */
|
|
26
|
+
references?: ReadonlyMap<object, string>;
|
|
27
|
+
}
|
|
28
|
+
/** Deserialization settings; all referenced resources must be supplied explicitly. */
|
|
29
|
+
export interface VFXJSONReadOptions extends VFXJSONLimits {
|
|
30
|
+
/** IDs to application-owned objects/functions. Default none; missing IDs reject. */
|
|
31
|
+
bindings?: ReadonlyMap<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
/** URL loader settings, with cancellation propagated to fetch and checked before creating the effect. */
|
|
34
|
+
export interface VFXJSONLoadOptions extends VFXJSONReadOptions {
|
|
35
|
+
/** Cancels the request and effect creation. Default none. */
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
}
|
|
38
|
+
/** Save complete authoring settings as stable, versioned JSON; typed arrays and negative zero retain their values.
|
|
39
|
+
* @throws TypeError or RangeError for invalid settings, cycles or limits; MargoError for unbound external resources.
|
|
40
|
+
*/
|
|
41
|
+
export declare function serializeEffect(source: VFXOptions | Pick<Base, 'options' | 'fog'>, options?: VFXJSONWriteOptions): string;
|
|
42
|
+
/** Decode and validate an effect document, including typed arrays, fog and explicit resource bindings.
|
|
43
|
+
* @throws TypeError or RangeError for malformed data/settings; MargoError for unknown versions or unresolved bindings.
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseEffect(text: string, options?: VFXJSONReadOptions): VFXPreset;
|
|
46
|
+
/** Make an unattached effect from saved JSON or an already decoded preset. The caller owns and disposes it.
|
|
47
|
+
* @throws TypeError, RangeError or MargoError for invalid presets, versions, bindings or limits.
|
|
48
|
+
*/
|
|
49
|
+
export declare function createEffect(source: string | VFXPreset, options?: VFXJSONReadOptions): VFX;
|
|
50
|
+
/** Fetch a saved effect and create it unattached. Uses the platform fetch; AbortSignal cancels all creation.
|
|
51
|
+
* @throws MargoError on a failed HTTP response; propagates fetch/abort and document validation errors.
|
|
52
|
+
*/
|
|
53
|
+
export declare function loadEffect(url: string | URL, options?: VFXJSONLoadOptions): Promise<VFX>;
|
package/dist/json.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { MargoError as e } from "@margoengine/math/errors";
|
|
2
|
+
import { VFX as t } from "@margoengine/vfx";
|
|
3
|
+
//#region src/json.ts
|
|
4
|
+
var n = 1, r = {
|
|
5
|
+
capacity: !0,
|
|
6
|
+
initialCount: !0,
|
|
7
|
+
rate: !0,
|
|
8
|
+
position: !0,
|
|
9
|
+
velocity: !0,
|
|
10
|
+
spread: !0,
|
|
11
|
+
gravity: !0,
|
|
12
|
+
color: !0,
|
|
13
|
+
size: !0,
|
|
14
|
+
lifetime: !0,
|
|
15
|
+
ground: !0,
|
|
16
|
+
bounce: !0,
|
|
17
|
+
turbulence: !0,
|
|
18
|
+
frequency: !0,
|
|
19
|
+
wind: !0,
|
|
20
|
+
angularVelocity: !0,
|
|
21
|
+
emissionExtent: !0,
|
|
22
|
+
intensity: !0,
|
|
23
|
+
clock: !0,
|
|
24
|
+
obstacles: !0,
|
|
25
|
+
wrap: !0,
|
|
26
|
+
sort: !0,
|
|
27
|
+
softness: !0,
|
|
28
|
+
depth: !0,
|
|
29
|
+
texture: !0,
|
|
30
|
+
curves: !0,
|
|
31
|
+
emitter: !0,
|
|
32
|
+
space: !0,
|
|
33
|
+
overLife: !0,
|
|
34
|
+
schedule: !0,
|
|
35
|
+
ribbons: !0,
|
|
36
|
+
mesh: !0,
|
|
37
|
+
events: !0,
|
|
38
|
+
lit: !0,
|
|
39
|
+
depthCollide: !0,
|
|
40
|
+
stretch: !0,
|
|
41
|
+
fields: !0,
|
|
42
|
+
skinned: !0,
|
|
43
|
+
flipbook: !0,
|
|
44
|
+
shadows: !0,
|
|
45
|
+
nodes: !0
|
|
46
|
+
}, i = {
|
|
47
|
+
Int8Array,
|
|
48
|
+
Uint8Array,
|
|
49
|
+
Uint8ClampedArray,
|
|
50
|
+
Int16Array,
|
|
51
|
+
Uint16Array,
|
|
52
|
+
Int32Array,
|
|
53
|
+
Uint32Array,
|
|
54
|
+
Float32Array,
|
|
55
|
+
Float64Array
|
|
56
|
+
}, a = (e) => [
|
|
57
|
+
"__proto__",
|
|
58
|
+
"prototype",
|
|
59
|
+
"constructor",
|
|
60
|
+
"$margo"
|
|
61
|
+
].includes(e), o = "https://margoengine.com/errors#vfx-json";
|
|
62
|
+
function s(e) {
|
|
63
|
+
let t = e.maxChars ?? 536870912, n = e.maxNodes ?? 1e8, r = e.maxDepth ?? 64;
|
|
64
|
+
for (let e of [
|
|
65
|
+
t,
|
|
66
|
+
n,
|
|
67
|
+
r
|
|
68
|
+
]) if (!Number.isSafeInteger(e) || e < 1) throw RangeError("VFX JSON limits must be positive safe integers; choose finite budgets");
|
|
69
|
+
let i = 0;
|
|
70
|
+
return {
|
|
71
|
+
maxChars: t,
|
|
72
|
+
visit(e) {
|
|
73
|
+
if (++i > n || e > r) throw RangeError("VFX JSON exceeds its node/depth budget; simplify the preset or increase the limits");
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function c(n) {
|
|
78
|
+
if (n.version !== 1) throw new e("version", `VFX JSON version is unsupported; migrate to version 1; see ${o}`);
|
|
79
|
+
if (!n.options || typeof n.options != "object" || Array.isArray(n.options)) throw TypeError("VFX JSON options must be an object; pass effect settings");
|
|
80
|
+
for (let e of Object.keys(n.options)) if (!Object.hasOwn(r, e)) throw TypeError(`VFX JSON unknown option ${e}; use a documented VFX option`);
|
|
81
|
+
let i = new t(n.options);
|
|
82
|
+
try {
|
|
83
|
+
i.setFog(n.fog);
|
|
84
|
+
} finally {
|
|
85
|
+
i.dispose();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function l(t, n = {}) {
|
|
89
|
+
if (!t || typeof t != "object") throw TypeError("VFX JSON source must be an effect or options object; pass its authoring settings");
|
|
90
|
+
let r = s(n), l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set();
|
|
91
|
+
for (let e of n.references?.values() ?? []) {
|
|
92
|
+
if (typeof e != "string" || !e || u.has(e)) throw TypeError("VFX JSON reference IDs must be nonempty and unique; give each resource its own ID");
|
|
93
|
+
u.add(e);
|
|
94
|
+
}
|
|
95
|
+
let d = (t, s, c) => {
|
|
96
|
+
if (r.visit(s), t === null || typeof t == "string" || typeof t == "boolean") return t;
|
|
97
|
+
if (typeof t == "number") {
|
|
98
|
+
if (!Number.isFinite(t)) throw RangeError(`VFX JSON ${c} must be finite; replace NaN or Infinity`);
|
|
99
|
+
return Object.is(t, -0) ? { $margo: "negative-zero" } : t;
|
|
100
|
+
}
|
|
101
|
+
if (typeof t == "object" && t || typeof t == "function") {
|
|
102
|
+
let e = n.references?.get(t);
|
|
103
|
+
if (e !== void 0) return {
|
|
104
|
+
$margo: "reference",
|
|
105
|
+
id: e
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
if (typeof t != "object" || !t) throw new e("unsupported", `VFX JSON ${c} cannot be embedded; provide an explicit resource reference; see ${o}`);
|
|
109
|
+
if (l.has(t)) throw TypeError(`VFX JSON ${c} is cyclic; use a resource reference or remove the cycle`);
|
|
110
|
+
l.add(t);
|
|
111
|
+
try {
|
|
112
|
+
if (t instanceof ArrayBuffer) return {
|
|
113
|
+
$margo: "ArrayBuffer",
|
|
114
|
+
data: d(Array.from(new Uint8Array(t)), s + 1, c)
|
|
115
|
+
};
|
|
116
|
+
if (ArrayBuffer.isView(t)) {
|
|
117
|
+
let n = t.constructor.name;
|
|
118
|
+
if (!Object.hasOwn(i, n)) throw new e("unsupported", `VFX JSON ${n} is unsupported; use a numeric typed array or resource reference; see ${o}`);
|
|
119
|
+
return {
|
|
120
|
+
$margo: n,
|
|
121
|
+
data: d(Array.from(t), s + 1, c)
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
if (Array.isArray(t)) return Array.from(t, (e, t) => d(e, s + 1, `${c}[${t}]`));
|
|
125
|
+
if (Object.getPrototypeOf(t) !== Object.prototype && Object.getPrototypeOf(t) !== null) throw new e("unsupported", `VFX JSON ${c} is an external object; bind it by reference; see ${o}`);
|
|
126
|
+
let n = {};
|
|
127
|
+
for (let e of Object.keys(t).sort()) {
|
|
128
|
+
if (a(e)) throw TypeError(`VFX JSON reserved key ${e}; rename the authoring property`);
|
|
129
|
+
let r = Object.getOwnPropertyDescriptor(t, e);
|
|
130
|
+
if (!("value" in r)) throw TypeError(`VFX JSON ${c}.${e} is an accessor; supply a data value or reference`);
|
|
131
|
+
r.value !== void 0 && (n[e] = d(r.value, s + 1, `${c}.${e}`));
|
|
132
|
+
}
|
|
133
|
+
return n;
|
|
134
|
+
} finally {
|
|
135
|
+
l.delete(t);
|
|
136
|
+
}
|
|
137
|
+
}, f = "options" in t, p = f ? t.options : t, m = {
|
|
138
|
+
version: 1,
|
|
139
|
+
options: p.shadows && "buffer" in p.shadows ? {
|
|
140
|
+
...p,
|
|
141
|
+
shadows: Object.fromEntries(Object.entries(p.shadows).filter(([e]) => e !== "buffer"))
|
|
142
|
+
} : p,
|
|
143
|
+
fog: f ? t.fog : null
|
|
144
|
+
};
|
|
145
|
+
if (m.fog && !n.references?.has(m.fog)) {
|
|
146
|
+
let e = {};
|
|
147
|
+
for (let t of [
|
|
148
|
+
"color",
|
|
149
|
+
"near",
|
|
150
|
+
"far",
|
|
151
|
+
"density",
|
|
152
|
+
"heightFalloff",
|
|
153
|
+
"height",
|
|
154
|
+
"enabled"
|
|
155
|
+
]) m.fog[t] !== void 0 && (e[t] = m.fog[t]);
|
|
156
|
+
m.fog = e;
|
|
157
|
+
}
|
|
158
|
+
let h = d({
|
|
159
|
+
format: "margo-vfx",
|
|
160
|
+
version: 1,
|
|
161
|
+
options: m.options,
|
|
162
|
+
fog: m.fog
|
|
163
|
+
}, 0, "effect");
|
|
164
|
+
c(m);
|
|
165
|
+
let g = JSON.stringify(h);
|
|
166
|
+
if (g.length > r.maxChars) throw RangeError("VFX JSON exceeds maxChars; reduce assets or increase the text limit");
|
|
167
|
+
return g;
|
|
168
|
+
}
|
|
169
|
+
function u(t, n = {}) {
|
|
170
|
+
let r = s(n);
|
|
171
|
+
if (typeof t != "string" || t.length > r.maxChars) throw RangeError("VFX JSON needs text within maxChars; pass a smaller JSON string");
|
|
172
|
+
let l;
|
|
173
|
+
try {
|
|
174
|
+
l = JSON.parse(t);
|
|
175
|
+
} catch (e) {
|
|
176
|
+
throw TypeError("VFX JSON syntax is invalid; correct the JSON text", { cause: e });
|
|
177
|
+
}
|
|
178
|
+
if (!l || typeof l != "object" || Array.isArray(l)) throw TypeError("VFX JSON document must be an object; provide a saved effect");
|
|
179
|
+
let u = l;
|
|
180
|
+
if (u.format !== "margo-vfx") throw TypeError("VFX JSON format must be margo-vfx; provide a saved effect");
|
|
181
|
+
if (u.version !== 1) throw new e("version", `VFX JSON version is unsupported; migrate to version 1; see ${o}`);
|
|
182
|
+
if (Object.keys(u).some((e) => ![
|
|
183
|
+
"format",
|
|
184
|
+
"version",
|
|
185
|
+
"options",
|
|
186
|
+
"fog"
|
|
187
|
+
].includes(e))) throw TypeError("VFX JSON has unknown document fields; use format, version, options and fog");
|
|
188
|
+
let d = (t, s) => {
|
|
189
|
+
if (r.visit(s), t === null || typeof t == "string" || typeof t == "boolean") return t;
|
|
190
|
+
if (typeof t == "number") {
|
|
191
|
+
if (!Number.isFinite(t)) throw RangeError("VFX JSON numbers must be finite; correct the value");
|
|
192
|
+
return t;
|
|
193
|
+
}
|
|
194
|
+
if (Array.isArray(t)) return t.map((e) => d(e, s + 1));
|
|
195
|
+
if (!t || typeof t != "object") throw TypeError("VFX JSON value is invalid; use supported JSON data");
|
|
196
|
+
let c = t, l = c.$margo;
|
|
197
|
+
if (l !== void 0) {
|
|
198
|
+
if (l === "negative-zero" && Object.keys(c).length === 1) return -0;
|
|
199
|
+
if (l === "reference" && Object.keys(c).length === 2 && typeof c.id == "string") {
|
|
200
|
+
if (!n.bindings?.has(c.id)) throw new e("state", `VFX JSON resource ${c.id} is missing; supply its binding; see ${o}`);
|
|
201
|
+
return n.bindings.get(c.id);
|
|
202
|
+
}
|
|
203
|
+
if (typeof l == "string" && (l === "ArrayBuffer" || Object.hasOwn(i, l)) && Object.keys(c).length === 2 && Array.isArray(c.data)) {
|
|
204
|
+
let e = d(c.data, s + 1);
|
|
205
|
+
if (!e.every((e) => typeof e == "number" && Number.isFinite(e))) throw TypeError("VFX JSON typed data needs finite numbers; correct the array");
|
|
206
|
+
let t = new (l === "ArrayBuffer" ? Uint8Array : i[l])(e);
|
|
207
|
+
if (e.some((e, n) => !Object.is(e, t[n]))) throw RangeError("VFX JSON typed data is out of range or loses precision; use exact values for its type");
|
|
208
|
+
return l === "ArrayBuffer" ? t.buffer : t;
|
|
209
|
+
}
|
|
210
|
+
throw TypeError("VFX JSON contains an invalid typed/reference tag; use a supported saved value");
|
|
211
|
+
}
|
|
212
|
+
let u = {};
|
|
213
|
+
for (let e of Object.keys(c)) {
|
|
214
|
+
if (a(e)) throw TypeError(`VFX JSON reserved key ${e}; remove it`);
|
|
215
|
+
u[e] = d(c[e], s + 1);
|
|
216
|
+
}
|
|
217
|
+
return u;
|
|
218
|
+
}, f = {
|
|
219
|
+
version: 1,
|
|
220
|
+
options: d(u.options, 0),
|
|
221
|
+
fog: u.fog === void 0 ? null : d(u.fog, 0)
|
|
222
|
+
};
|
|
223
|
+
return c(f), f;
|
|
224
|
+
}
|
|
225
|
+
function d(e, n = {}) {
|
|
226
|
+
let r = typeof e == "string" ? u(e, n) : e;
|
|
227
|
+
return c(r), new t(r.options).setFog(r.fog);
|
|
228
|
+
}
|
|
229
|
+
async function f(t, n = {}) {
|
|
230
|
+
n.signal?.throwIfAborted();
|
|
231
|
+
let r = await fetch(t, { signal: n.signal });
|
|
232
|
+
if (!r.ok) throw new e("failed", `VFX JSON request returned ${r.status}; check the URL; see ${o}`);
|
|
233
|
+
let i = await r.text();
|
|
234
|
+
return n.signal?.throwIfAborted(), d(i, n);
|
|
235
|
+
}
|
|
236
|
+
//#endregion
|
|
237
|
+
export { n as VFX_JSON_VERSION, d as createEffect, f as loadEffect, u as parseEffect, l as serializeEffect };
|
package/dist/lit.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { VFXExtension, VFXLit } from './base.js';
|
|
2
|
+
/** A flame's colour as light, linear RGB (a 1,300 K blackbody's hue, as the flame ramp's edge). */
|
|
3
|
+
export declare const GLOW_COLOR: readonly [number, number, number];
|
|
4
|
+
/**
|
|
5
|
+
* The `lit` feature: billboards lit by the engine's sun (with wrap lighting), its ambient light, `Clustered` point and
|
|
6
|
+
* spot lights and `Shadows` sun shadows, shaded as balls so smoke and dust take light from the side it comes from.
|
|
7
|
+
* Pass it as `{lit}` to `VFX` from `@margoengine/vfx/base`; the root `VFX` has it. `lights` and `shadows` are read at
|
|
8
|
+
* attach; `wrap` and `ambient` every frame. Under an order-independent pass (`addEffect` from `@margoengine/oit/vfx`)
|
|
9
|
+
* the particles are lit the same: the pass's declarations take bind group 1 and the lights and shadows group 2.
|
|
10
|
+
*/
|
|
11
|
+
export declare const lit: VFXExtension<VFXLit>;
|
package/dist/lit.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { MargoError as e } from "@margoengine/math/errors";
|
|
2
|
+
//#region src/lit.ts
|
|
3
|
+
var t = 21;
|
|
4
|
+
function n(t, n, r) {
|
|
5
|
+
if (t.split(n).length !== 2) throw new e("unsupported", "VFX lit needs the billboard shader it was written for; update the lit edits");
|
|
6
|
+
return t.replace(n, r);
|
|
7
|
+
}
|
|
8
|
+
var r = (e, r) => {
|
|
9
|
+
let i = n(e, "@location(0) uv:vec2f,", "@location(0) uv:vec2f,@location(8) litWorld:vec3f,@location(9) litSide:vec4f,");
|
|
10
|
+
i = n(i, "o.clip=f.camera*vec4f(position,1);", "o.clip=f.camera*vec4f(position,1);let litHalf=p.velocitySize.w*0.5*grow;o.litWorld=position;o.litSide=vec4f((position-p.positionLife.xyz)/litHalf,litHalf);"), i = n(i, "@fragment fn fragment(i:Out)->@location(0) vec4f {", "@fragment fn fragment(i:Out)->@location(0) vec4f {return lit(i,unlit(i));}\nfn unlit(i:Out)->vec4f {");
|
|
11
|
+
let a = "base*litFrame.sunColor.rgb*(max(0.0,dot(n,litFrame.sun.xyz)+wrap)/(1.0+wrap)*0.31830989)";
|
|
12
|
+
return i + `
|
|
13
|
+
struct LitFrame {sun:vec4f,sunColor:vec4f,ambient:vec4f,eye:vec4f,glow:vec4f,glowColor:vec4f}
|
|
14
|
+
@group(0) @binding(${t}) var<uniform> litFrame:LitFrame;
|
|
15
|
+
fn lit(i:Out,c:vec4f)->vec4f {
|
|
16
|
+
let toward=cross(f.right.xyz,f.up.xyz);let z=sqrt(max(0.0,1.0-dot(i.uv,i.uv)));
|
|
17
|
+
let n=normalize(i.litSide.xyz+toward*z);let p=i.litWorld+toward*(z*i.litSide.w);let base=c.rgb;let wrap=litFrame.sunColor.w;
|
|
18
|
+
var light=base*litFrame.ambient.rgb+${r.shadows ? `shadowLit(${a},p,n)` : a};
|
|
19
|
+
${r.lights ? "light+=clusterLighting(i.clip.xy,p,n,litFrame.eye.xyz,base,1.0,0.0,vec3f(0.04),1.0);" : ""}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
let toGlow=litFrame.glow.xyz-p;let d2=dot(toGlow,toGlow);
|
|
23
|
+
let e=litFrame.glowColor.w/(12566.37*(d2+litFrame.glow.w*litFrame.glow.w));
|
|
24
|
+
light+=base*litFrame.glowColor.rgb*(e*max(0.0,dot(n,toGlow*inverseSqrt(max(d2,1e-6)))+wrap)/(1.0+wrap));
|
|
25
|
+
return vec4f(light,c.a);
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
};
|
|
29
|
+
function i(e, t) {
|
|
30
|
+
if (e !== void 0 && (!e || typeof e.pbr != "function" || typeof e.bindings != "function")) throw TypeError(`VFX lit ${t} must be ${t === "lights" ? "Clustered" : "Shadows"} or have pbr and bindings`);
|
|
31
|
+
}
|
|
32
|
+
var a = 0, o = [
|
|
33
|
+
1,
|
|
34
|
+
.42,
|
|
35
|
+
.12
|
|
36
|
+
];
|
|
37
|
+
function s(e) {
|
|
38
|
+
if (e === void 0) return;
|
|
39
|
+
let t = (e, t, n) => typeof e == "number" && Number.isFinite(e) && e >= t && e <= n;
|
|
40
|
+
if (!e || typeof e != "object" || !Array.isArray(e.position) || e.position.length !== 3 || !e.position.every((e) => t(e, -1e7, 1e7)) || !t(e.power, 0, 0x9184e72a000) || e.radius !== void 0 && !t(e.radius, .01, 1e5) || e.color !== void 0 && (!Array.isArray(e.color) || e.color.length !== 3 || !e.color.every((e) => t(e, 0, 16)))) throw RangeError("VFX lit glow needs {position: [x, y, z], power: watts 0 to 1e13, radius?: 0.01 to 1e5 m, color?: linear [r, g, b] 0 to 16}");
|
|
41
|
+
}
|
|
42
|
+
var c = {
|
|
43
|
+
validate(e) {
|
|
44
|
+
if (!e || typeof e != "object") throw TypeError("VFX lit must be an object; pass {} for the sun, or {lights, shadows}");
|
|
45
|
+
if (i(e.lights, "lights"), i(e.shadows, "shadows"), e.wrap !== void 0 && !(typeof e.wrap == "number" && e.wrap >= 0 && e.wrap <= 1)) throw RangeError("VFX lit wrap must be 0 to 1; pass e.g. 0.5");
|
|
46
|
+
let t = e.ambient;
|
|
47
|
+
if (t !== void 0 && (!Array.isArray(t) || t.length !== 3 || !t.every((e) => typeof e == "number" && e >= 0 && e <= 16))) throw RangeError("VFX lit ambient must be linear [r, g, b], each 0 to 16");
|
|
48
|
+
s(e.glow);
|
|
49
|
+
},
|
|
50
|
+
billboard: (e, t) => r(e, t),
|
|
51
|
+
create(e, n, r) {
|
|
52
|
+
let { device: i, options: c } = e, l = i.createBuffer({
|
|
53
|
+
size: 96,
|
|
54
|
+
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
55
|
+
});
|
|
56
|
+
r.push(l);
|
|
57
|
+
let u = /* @__PURE__ */ new Float32Array(24), d = !!(n.lights || n.shadows), f = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new WeakMap(), m = (e) => {
|
|
58
|
+
let t = n.lights?.pbr(e).declarations ?? "", r = n.shadows?.pbr(e).declarations ?? "", i = f.get(e);
|
|
59
|
+
return (!i || i.lights !== t || i.shadows !== r) && f.set(e, i = {
|
|
60
|
+
lights: t,
|
|
61
|
+
shadows: r,
|
|
62
|
+
key: ":lit" + ++a
|
|
63
|
+
}), i;
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
render: [{
|
|
67
|
+
binding: t,
|
|
68
|
+
resource: { buffer: l }
|
|
69
|
+
}],
|
|
70
|
+
write(t) {
|
|
71
|
+
if (c.lit !== n) throw TypeError("VFX lit is fixed at attach; change its wrap or ambient in place or attach a new VFX");
|
|
72
|
+
let { direction: r, radiance: i, ambient: a } = e.engine.lighting, d = Math.hypot(r[0], r[1], r[2]), f = d > 0 ? Math.max(0, r[3]) : 0;
|
|
73
|
+
for (let e = 0; e < 3; e++) u[e] = f ? r[e] / d : 0, u[4 + e] = i[e] * f, u[8 + e] = n.ambient ? n.ambient[e] : i[3] * a[e], u[12 + e] = t.camera.position[e];
|
|
74
|
+
u[7] = n.wrap ?? .5;
|
|
75
|
+
let p = n.glow;
|
|
76
|
+
if (s(p), u.fill(0, 16, 24), p && p.power > 0) {
|
|
77
|
+
let e = p.color ?? o;
|
|
78
|
+
for (let t = 0; t < 3; t++) u[16 + t] = p.position[t], u[20 + t] = e[t];
|
|
79
|
+
u[19] = p.radius ?? 1, u[23] = p.power;
|
|
80
|
+
}
|
|
81
|
+
t.device.queue.writeBuffer(l, 0, u);
|
|
82
|
+
},
|
|
83
|
+
...d ? {
|
|
84
|
+
key: (e) => m(e).key,
|
|
85
|
+
shade(e, t) {
|
|
86
|
+
let n = m(t);
|
|
87
|
+
return n.lights + n.shadows + e;
|
|
88
|
+
},
|
|
89
|
+
bind(e, t, r) {
|
|
90
|
+
let a = n.lights?.bindings(), o = n.shadows?.bindings(), s = p.get(t);
|
|
91
|
+
(!s || s.lights !== a || s.shadows !== o) && p.set(t, s = {
|
|
92
|
+
lights: a,
|
|
93
|
+
shadows: o,
|
|
94
|
+
group: i.createBindGroup({
|
|
95
|
+
layout: t.getBindGroupLayout(r),
|
|
96
|
+
entries: [...a ?? [], ...o ?? []]
|
|
97
|
+
})
|
|
98
|
+
}), e.setBindGroup(r, s.group);
|
|
99
|
+
}
|
|
100
|
+
} : {}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
//#endregion
|
|
105
|
+
export { o as GLOW_COLOR, c as lit };
|
package/dist/mesh.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { VFXExtension, VFXMeshParticles } from './base.js';
|
|
2
|
+
/** Most triangles of a particle mesh (each corner takes 32 bytes on the GPU and runs for every drawn particle). */
|
|
3
|
+
export declare const MAX_PARTICLE_MESH_TRIANGLES = 65536;
|
|
4
|
+
/**
|
|
5
|
+
* The mesh's corners as the shader reads them: position (scaled so the farthest vertex from the mesh origin is 1) and
|
|
6
|
+
* normal, two vec4s a corner. Without `normals` each triangle takes its face normal (counter-clockwise faces point out).
|
|
7
|
+
*/
|
|
8
|
+
export declare function meshCorners(m: VFXMeshParticles): Float32Array;
|
|
9
|
+
/**
|
|
10
|
+
* The `mesh` feature: draws each particle as an instance of a small triangle mesh instead of a billboard, tumbling by
|
|
11
|
+
* its spin or following its velocity, lit by one directional light. Pass it as `{mesh}` to `VFX` from
|
|
12
|
+
* `@margoengine/vfx/base`; the root `VFX` has it. The mesh is read at attach; `light`, `color` and `ambient` every frame.
|
|
13
|
+
*/
|
|
14
|
+
export declare const mesh: VFXExtension<VFXMeshParticles>;
|