@margoengine/armies 0.0.0-stage → 1.0.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 +146 -2
- package/dist/bake.d.ts +53 -0
- package/dist/bake.js +92 -0
- package/dist/index.d.ts +141 -0
- package/dist/index.js +156 -0
- package/dist/lod-BR0gNHsn.js +156 -0
- package/dist/lod.d.ts +125 -0
- package/dist/lod.js +1 -0
- package/dist/riders.d.ts +19 -0
- package/dist/riders.js +22 -0
- package/dist/settings.d.ts +24 -0
- package/dist/settings.js +107 -0
- package/dist/shared/settings.d.ts +89 -0
- package/package.json +74 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { a as e, i as t, n, o as r, r as i, s as a, t as o } from "./lod-BR0gNHsn.js";
|
|
2
|
+
import { riderMatrix as s } from "./riders.js";
|
|
3
|
+
import { bakePerson as c } from "./bake.js";
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
var l = (e) => {
|
|
6
|
+
let t = Math.imul(e ^ 2654435769, 2246822507);
|
|
7
|
+
return t = Math.imul(t ^ t >>> 13, 3266489909), ((t ^ t >>> 16) >>> 0) / 4294967296;
|
|
8
|
+
};
|
|
9
|
+
function u(e) {
|
|
10
|
+
let t = Math.max(1e-12, l(e * 2 + 1)), n = l(e * 2 + 2);
|
|
11
|
+
return Math.max(-2.5, Math.min(2.5, Math.sqrt(-2 * Math.log(t)) * Math.cos(2 * Math.PI * n)));
|
|
12
|
+
}
|
|
13
|
+
function d(e, t = {}) {
|
|
14
|
+
let n = e.clips, r = (e, t) => {
|
|
15
|
+
if (typeof e == "number") {
|
|
16
|
+
if (!(Number.isInteger(e) && e >= 0 && e < n.length)) throw RangeError(`addArmy clips.${t} must be a clip index below ${n.length}`);
|
|
17
|
+
return e;
|
|
18
|
+
}
|
|
19
|
+
let r = n.findIndex((n) => n.name === (e ?? t));
|
|
20
|
+
if (r < 0 && e !== void 0) throw RangeError(`addArmy clips.${t}: the bake has no clip named ${e}; it has ${n.map((e) => e.name).join(", ")}`);
|
|
21
|
+
return r < 0 ? void 0 : r;
|
|
22
|
+
}, i = t.clips ?? {}, a = r(i.walk, "walk") ?? 0, o = r(i.run, "run") ?? a, s = r(i.stand, "stand") ?? -1, c = r(i.ride, "ride") ?? s, l = t.strides?.walk ?? 1.524, u = t.strides?.run ?? 1.829, d = t.runAbove ?? 2, f = t.blendBand ?? .4, p = t.standBelow ?? .1;
|
|
23
|
+
if (!(l > 0 && l < 20) || !(u > 0 && u < 20)) throw RangeError("addArmy strides must be above 0 and below 20 m");
|
|
24
|
+
if (!(d > 0 && d < 20) || !(f >= 0 && f < d) || !(p >= 0 && p < d)) throw RangeError("addArmy runAbove must be 0 to 20 m/s, blendBand and standBelow 0 or more and below it");
|
|
25
|
+
return {
|
|
26
|
+
stand: s,
|
|
27
|
+
walk: a,
|
|
28
|
+
run: o,
|
|
29
|
+
ride: c,
|
|
30
|
+
durations: n.map((e) => e.duration),
|
|
31
|
+
walkStride: l,
|
|
32
|
+
runStride: u,
|
|
33
|
+
runAbove: d,
|
|
34
|
+
blendBand: f,
|
|
35
|
+
standBelow: p
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
var f = (e) => e - Math.floor(e);
|
|
39
|
+
function p(e, t, n, r, i, a, o = 0) {
|
|
40
|
+
if (t < e.standBelow) {
|
|
41
|
+
let t = e.stand >= 0 ? e.stand : e.walk, s = e.stand >= 0 ? f(a / e.durations[t] + o) * e.durations[t] : f(n / (e.walkStride * r) + i) * e.durations[t];
|
|
42
|
+
return {
|
|
43
|
+
clip: t,
|
|
44
|
+
offset: s,
|
|
45
|
+
blendClip: t,
|
|
46
|
+
blendOffset: s,
|
|
47
|
+
blend: 0
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
let s = f(n / (e.walkStride * r) + i) * e.durations[e.walk], c = f(n / (e.runStride * r) + i) * e.durations[e.run], l = e.runAbove - e.blendBand / 2, u = e.blendBand > 0 ? Math.min(1, Math.max(0, (t - l) / e.blendBand)) : +(t >= e.runAbove);
|
|
51
|
+
return {
|
|
52
|
+
clip: e.walk,
|
|
53
|
+
offset: s,
|
|
54
|
+
blendClip: e.run,
|
|
55
|
+
blendOffset: c,
|
|
56
|
+
blend: e.run === e.walk ? 0 : u
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async function m(n, r, i) {
|
|
60
|
+
if (!r || !Array.isArray(r.formations) || typeof r.heightAt != "function") throw TypeError("addArmy needs a @margoengine/navmesh/formations Army");
|
|
61
|
+
if (!i?.person?.near) throw TypeError("addArmy needs options.person, a bake from bakePerson");
|
|
62
|
+
let o = i.person, c = d(o, i), m = e(i), h = i.stature ?? .04, g = i.seed ?? 1, _ = i.facing ?? 0, v = (i.step ?? "cadence") === "route", y = i.variants ?? [];
|
|
63
|
+
if (!(h >= 0 && h <= .3)) throw RangeError("addArmy stature must be 0 to 0.3 of the mean height");
|
|
64
|
+
if (i.step !== void 0 && i.step !== "cadence" && i.step !== "route") throw RangeError("addArmy step must be 'cadence' or 'route'");
|
|
65
|
+
if (!Number.isFinite(_) || !Number.isFinite(g)) throw RangeError("addArmy facing and seed must be finite");
|
|
66
|
+
if (!Array.isArray(y) || y.some((e) => e?.offset?.length !== 2 || e?.scale?.length !== 2)) throw RangeError("addArmy variants must be atlas regions {offset: [u, v], scale: [u, v]}");
|
|
67
|
+
let b = {
|
|
68
|
+
height: o.height || 1.75,
|
|
69
|
+
...i.rider,
|
|
70
|
+
facing: _
|
|
71
|
+
};
|
|
72
|
+
s(/* @__PURE__ */ new Float32Array(16), 0, 1, b);
|
|
73
|
+
let x = a(n), S = r.formations.some((e) => e.kind === "cavalry"), C = await t.attach(n, o, {
|
|
74
|
+
...m,
|
|
75
|
+
color: i.color,
|
|
76
|
+
map: i.map,
|
|
77
|
+
roughness: i.roughness,
|
|
78
|
+
metalness: i.metalness
|
|
79
|
+
}), w = null;
|
|
80
|
+
try {
|
|
81
|
+
if (S && i.horses !== !1) {
|
|
82
|
+
let { addHorseCrowd: e } = await import("@margoengine/horses/crowd");
|
|
83
|
+
w = await x.run(() => e(n, {
|
|
84
|
+
ground: (e, t) => r.heightAt(e, t),
|
|
85
|
+
...i.horses || {}
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
} catch (e) {
|
|
89
|
+
throw C.dispose(), e;
|
|
90
|
+
}
|
|
91
|
+
let T = [], E = [], D = [], O = (e) => 1 + h * u(g * 7919 + e), k = (e) => y.length ? y[Math.floor(l(g * 15485863 + e) * y.length)] : void 0, A = (e) => v ? l(g * 104729 + e) : 0, j = Math.cos(_), M = Math.sin(_), N = (e) => {
|
|
92
|
+
for (; T.length <= e;) T.push({
|
|
93
|
+
matrix: /* @__PURE__ */ new Float32Array(16),
|
|
94
|
+
clip: 0,
|
|
95
|
+
offset: 0
|
|
96
|
+
});
|
|
97
|
+
return T[e];
|
|
98
|
+
}, P = !1, F = {
|
|
99
|
+
army: r,
|
|
100
|
+
people: C,
|
|
101
|
+
horses: w,
|
|
102
|
+
get persons() {
|
|
103
|
+
return T;
|
|
104
|
+
},
|
|
105
|
+
update(e, t) {
|
|
106
|
+
if (P) throw RangeError("This army crowd is disposed; call addArmy again for a new one");
|
|
107
|
+
let n = r.members, i = r.time, a = 0;
|
|
108
|
+
E.length = D.length = 0;
|
|
109
|
+
for (let e = 0; e < n.length; e++) {
|
|
110
|
+
let t = n[e];
|
|
111
|
+
if (r.formations[t.formation]?.kind === "cavalry") {
|
|
112
|
+
E.push(t), D.push(e);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
let o = O(e), s = p(c, t.speed, t.distance, o, A(e), i, l(g * 49979687 + e)), u = N(a++), d = t.heading, f = Math.cos(d), m = Math.sin(d), h = f * j + m * M, _ = m * j - f * M;
|
|
116
|
+
u.matrix.set([
|
|
117
|
+
h * o,
|
|
118
|
+
0,
|
|
119
|
+
-_ * o,
|
|
120
|
+
0,
|
|
121
|
+
0,
|
|
122
|
+
o,
|
|
123
|
+
0,
|
|
124
|
+
0,
|
|
125
|
+
_ * o,
|
|
126
|
+
0,
|
|
127
|
+
h * o,
|
|
128
|
+
0,
|
|
129
|
+
t.x,
|
|
130
|
+
r.heightAt(t.x, t.z),
|
|
131
|
+
t.z,
|
|
132
|
+
1
|
|
133
|
+
]), u.clip = s.clip, u.offset = s.offset, u.blendClip = s.blendClip, u.blendOffset = s.blendOffset, u.blend = s.blend, u.uvTransform = k(e);
|
|
134
|
+
}
|
|
135
|
+
return w && E.length && (w.update(E.map((e) => ({
|
|
136
|
+
x: e.x,
|
|
137
|
+
z: e.z,
|
|
138
|
+
heading: e.heading,
|
|
139
|
+
speed: e.speed,
|
|
140
|
+
distance: e.distance
|
|
141
|
+
}))), E.forEach((e, t) => {
|
|
142
|
+
let n = D[t], r = O(n), i = N(a++), o = w.pose(e.speed, e.distance), l = w.clips[o.clip], u = l.duration > 0 ? o.offset / l.duration : 0, d = c.ride >= 0 ? c.ride : c.walk;
|
|
143
|
+
s(w.saddles, t * 16, r, b, i.matrix), i.clip = d, i.offset = f(u) * c.durations[d], i.blendClip = d, i.blendOffset = i.offset, i.blend = 0, i.uvTransform = k(n);
|
|
144
|
+
})), T.length = a, C.update(T, e, t), F;
|
|
145
|
+
},
|
|
146
|
+
dispose() {
|
|
147
|
+
P || (P = !0, C.dispose(), w?.dispose());
|
|
148
|
+
},
|
|
149
|
+
[Symbol.dispose]() {
|
|
150
|
+
F.dispose();
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
return F;
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
export { o as FAR, n as HIDDEN, i as NEAR, t as PersonCrowd, m as addArmy, d as armyGaits, l as armyHash, u as armyNormal, c as bakePerson, e as crowdBudget, r as planCrowd, s as riderMatrix, p as stepPose };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
|
|
4
|
+
//#region ../shared/scene-scope.js
|
|
5
|
+
var e = 0, t = (t, n) => {
|
|
6
|
+
let r = n + e++;
|
|
7
|
+
for (; t.plugins?.has(r);) r += ":";
|
|
8
|
+
return r;
|
|
9
|
+
};
|
|
10
|
+
function n(e) {
|
|
11
|
+
let n;
|
|
12
|
+
if (typeof e?.sceneOf == "function") {
|
|
13
|
+
for (let t of e.plugins?.values() ?? []) if (n = e.sceneOf(t)) break;
|
|
14
|
+
if (!n) {
|
|
15
|
+
let r = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
|
|
16
|
+
name: t(e, "scene-scope:"),
|
|
17
|
+
setup() {
|
|
18
|
+
n = e.sceneOf(r);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
e.use(r), e.removePlugin(r.name);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return r(e, n);
|
|
25
|
+
}
|
|
26
|
+
function r(e, n) {
|
|
27
|
+
return {
|
|
28
|
+
scene: n,
|
|
29
|
+
run(r) {
|
|
30
|
+
if (!n) return r();
|
|
31
|
+
let i, a = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
|
|
32
|
+
name: t(e, "scene-scope:"),
|
|
33
|
+
setup() {
|
|
34
|
+
i = r();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return n.use(a), n.removePlugin(a.name), i;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/lod.ts
|
|
43
|
+
var i = 0, a = 1, o = 2, s = {
|
|
44
|
+
near: 128,
|
|
45
|
+
far: 16384,
|
|
46
|
+
vertices: 8e6,
|
|
47
|
+
nearScreen: .08,
|
|
48
|
+
cullScreen: .002,
|
|
49
|
+
hysteresis: 0
|
|
50
|
+
};
|
|
51
|
+
function c(e = {}) {
|
|
52
|
+
let t = {
|
|
53
|
+
...s,
|
|
54
|
+
...e
|
|
55
|
+
};
|
|
56
|
+
if (!(Number.isInteger(t.near) && t.near >= 0 && t.near <= 65536)) throw RangeError("Crowd budget near must be a whole number from 0 to 65536");
|
|
57
|
+
if (!(Number.isInteger(t.far) && t.far >= 0 && t.far <= 1048576)) throw RangeError("Crowd budget far must be a whole number from 0 to 1048576");
|
|
58
|
+
if (!(t.vertices >= 0 && Number.isFinite(t.vertices))) throw RangeError("Crowd budget vertices must be 0 or more");
|
|
59
|
+
if (!(t.nearScreen > 0 && t.nearScreen <= 10)) throw RangeError("Crowd budget nearScreen must be above 0 and at most 10");
|
|
60
|
+
if (!(t.cullScreen >= 0 && t.cullScreen < t.nearScreen)) throw RangeError("Crowd budget cullScreen must be 0 or more and below nearScreen");
|
|
61
|
+
if (!(t.hysteresis >= 0 && t.hysteresis < 1)) throw RangeError("Crowd budget hysteresis must be 0 or more and below 1");
|
|
62
|
+
return t;
|
|
63
|
+
}
|
|
64
|
+
function l(e, t, n, r, i, a = new Uint8Array(e.length)) {
|
|
65
|
+
let o = c(n), s = e.length, l = t.position, u = Math.tan((t.fov > 0 && t.fov < 180 ? t.fov : 60) * Math.PI / 360), d = t.planes, f = new Float64Array(s), p = [];
|
|
66
|
+
if (a.length < s) throw RangeError("planCrowd out must hold a level per member");
|
|
67
|
+
a.fill(0, 0, s);
|
|
68
|
+
for (let t = 0; t < s; t++) {
|
|
69
|
+
let n = e[t], r = Math.hypot(n.x - l[0], n.y - l[1], n.z - l[2]), i = !0;
|
|
70
|
+
if (d) for (let e = 0; e < 6 && i; e++) i = d[e * 4] * n.x + d[e * 4 + 1] * n.y + d[e * 4 + 2] * n.z + d[e * 4 + 3] >= -n.radius;
|
|
71
|
+
f[t] = r > n.radius ? 2 * n.radius / (2 * r * u) : Infinity, i && f[t] >= o.cullScreen && p.push(t);
|
|
72
|
+
}
|
|
73
|
+
p.sort((e, t) => f[t] - f[e] || e - t);
|
|
74
|
+
let m = 0, h = 0, g = 0;
|
|
75
|
+
for (let e of p) {
|
|
76
|
+
let t = i?.[e] === 2;
|
|
77
|
+
f[e] >= o.nearScreen * (t && o.hysteresis > 0 ? 1 - o.hysteresis : 1) && m < o.near && g + r.near <= o.vertices ? (a[e] = 2, m++, g += r.near) : h < o.far && g + r.far <= o.vertices && (a[e] = 1, h++, g += r.far);
|
|
78
|
+
}
|
|
79
|
+
return a;
|
|
80
|
+
}
|
|
81
|
+
var u = class e {
|
|
82
|
+
constructor(e, t, n, r, i) {
|
|
83
|
+
this.engine = e, this.bake = t, this.near = n, this.far = r, this.levels = /* @__PURE__ */ new Uint8Array(), this.counts = {
|
|
84
|
+
near: 0,
|
|
85
|
+
far: 0,
|
|
86
|
+
hidden: 0
|
|
87
|
+
}, this.posed = 0, this.disposed = !1, this.spheres = [], this.budget = i;
|
|
88
|
+
}
|
|
89
|
+
static async attach(t, r, i = {}) {__margoAssertCore(t,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
90
|
+
if (!r?.near || !r.far || !r.farBones) throw TypeError("PersonCrowd needs a bake from bakePerson");
|
|
91
|
+
let a = n(t), o = c(i), s = {
|
|
92
|
+
color: i.color,
|
|
93
|
+
map: i.map,
|
|
94
|
+
roughness: i.roughness,
|
|
95
|
+
metalness: i.metalness
|
|
96
|
+
}, [{ SkinnedCrowd: l }, { VATCrowd: u }] = await Promise.all([import("@margoengine/animation/instanced-skin"), import("@margoengine/animation/vat")]), d = new l(r.near, s), f = new u(r.far, s);
|
|
97
|
+
return a.run(() => {
|
|
98
|
+
t.use(d), t.use(f);
|
|
99
|
+
}), new e(t, r, d, f, o);
|
|
100
|
+
}
|
|
101
|
+
update(e, t, n) {
|
|
102
|
+
if (this.disposed) throw RangeError("PersonCrowd is disposed; attach a new one with PersonCrowd.attach");
|
|
103
|
+
if (typeof t.update == "function") {
|
|
104
|
+
let e = this.engine.canvas, r = n ?? (e?.width && e.height ? e.width / e.height : 1);
|
|
105
|
+
if (!(r > 0 && Number.isFinite(r))) throw RangeError("PersonCrowd update aspect must be a finite number above 0");
|
|
106
|
+
t.update(r, this.engine.backend === "webgpu");
|
|
107
|
+
}
|
|
108
|
+
let r = e.length, i = this.bake.height || 1, a = this.spheres;
|
|
109
|
+
for (; a.length < r;) a.push({
|
|
110
|
+
x: 0,
|
|
111
|
+
y: 0,
|
|
112
|
+
z: 0,
|
|
113
|
+
radius: 0
|
|
114
|
+
});
|
|
115
|
+
for (let t = 0; t < r; t++) {
|
|
116
|
+
let n = e[t].matrix;
|
|
117
|
+
if (!n || n.length !== 16) throw RangeError("A crowd person needs a 16-number matrix");
|
|
118
|
+
let r = i * Math.hypot(n[4], n[5], n[6]);
|
|
119
|
+
a[t].x = n[12] + n[4] * i * .5, a[t].y = n[13] + n[5] * i * .5, a[t].z = n[14] + n[6] * i * .5, a[t].radius = .55 * r;
|
|
120
|
+
}
|
|
121
|
+
let o = this.levels;
|
|
122
|
+
this.levels = l(a.slice(0, r), t, this.budget, {
|
|
123
|
+
near: this.bake.near.vertexCount,
|
|
124
|
+
far: this.bake.far.vertexCount
|
|
125
|
+
}, o);
|
|
126
|
+
let s = 0, c = 0, u = {};
|
|
127
|
+
for (let t = 0; t < r; t++) {
|
|
128
|
+
let n = this.levels[t];
|
|
129
|
+
if (n === 0) continue;
|
|
130
|
+
let r = e[t], i = r.blend ?? 0;
|
|
131
|
+
if (n === 2) u.matrix = r.matrix, u.clip = r.clip, u.offset = r.offset, u.speed = 0, u.blendClip = r.blendClip ?? r.clip, u.blendOffset = r.blendOffset ?? r.offset, u.blendSpeed = 0, u.blend = i, u.uvTransform = r.uvTransform ?? d, s < this.near.count ? this.near.set(s, u) : this.near.add(u), s++;
|
|
132
|
+
else {
|
|
133
|
+
let e = i > .5 && r.blendClip !== void 0, t = {
|
|
134
|
+
matrix: r.matrix,
|
|
135
|
+
clip: e ? r.blendClip : r.clip,
|
|
136
|
+
offset: e ? r.blendOffset ?? r.offset : r.offset,
|
|
137
|
+
speed: 0,
|
|
138
|
+
uvTransform: r.uvTransform ?? d
|
|
139
|
+
};
|
|
140
|
+
c < this.far.count ? this.far.set(c, t) : this.far.add(t), c++;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return this.near.truncate(s), this.far.truncate(c), this.counts.near = s, this.counts.far = c, this.counts.hidden = r - s - c, this.posed = s * this.bake.near.vertexCount + c * this.bake.far.vertexCount, this;
|
|
144
|
+
}
|
|
145
|
+
dispose() {
|
|
146
|
+
this.disposed || (this.disposed = !0, this.near.dispose(), this.far.dispose());
|
|
147
|
+
}
|
|
148
|
+
[Symbol.dispose]() {
|
|
149
|
+
this.dispose();
|
|
150
|
+
}
|
|
151
|
+
}, d = {
|
|
152
|
+
offset: [0, 0],
|
|
153
|
+
scale: [1, 1]
|
|
154
|
+
};
|
|
155
|
+
//#endregion
|
|
156
|
+
export { c as a, u as i, i as n, l as o, o as r, n as s, a as t };
|
package/dist/lod.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { EngineKernel } from '@margoengine/core';
|
|
3
|
+
import type { SkinnedCrowd } from '@margoengine/animation/instanced-skin';
|
|
4
|
+
import type { VATCrowd, VATCrowdOptions } from '@margoengine/animation/vat';
|
|
5
|
+
import type { PersonBake } from './bake.js';
|
|
6
|
+
/** A member's level: not drawn (off the frustum, too small or over budget). */
|
|
7
|
+
export declare const HIDDEN = 0;
|
|
8
|
+
/** A member's level: the far vertex animation of the simplified mesh. */
|
|
9
|
+
export declare const FAR = 1;
|
|
10
|
+
/** A member's level: skinned near on the GPU, the full mesh with two clips blended. */
|
|
11
|
+
export declare const NEAR = 2;
|
|
12
|
+
/** One person for {@link PersonCrowd.update}. */
|
|
13
|
+
export interface CrowdPerson {
|
|
14
|
+
/** Column-major world matrix, 16 numbers: place, heading and size. */
|
|
15
|
+
readonly matrix: ArrayLike<number>;
|
|
16
|
+
/** Clip index into the bake's clips. */
|
|
17
|
+
readonly clip: number;
|
|
18
|
+
/** Seconds into it. */
|
|
19
|
+
readonly offset: number;
|
|
20
|
+
/** A second clip blended in by the near level (the far level shows whichever has more weight). Default none. */
|
|
21
|
+
readonly blendClip?: number;
|
|
22
|
+
readonly blendOffset?: number;
|
|
23
|
+
/** 0 to 1. Default 0. */
|
|
24
|
+
readonly blend?: number;
|
|
25
|
+
/** Atlas region: an outfit. */
|
|
26
|
+
readonly uvTransform?: {
|
|
27
|
+
readonly offset?: readonly number[];
|
|
28
|
+
readonly scale?: readonly number[];
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** The camera the levels are planned for: a core `Camera` fits. */
|
|
32
|
+
export interface CrowdView {
|
|
33
|
+
/** Eye position. */
|
|
34
|
+
readonly position: ArrayLike<number>;
|
|
35
|
+
/** Vertical field of view, degrees. */
|
|
36
|
+
readonly fov: number;
|
|
37
|
+
/** Frustum planes (six of `[nx, ny, nz, d]`, inside where `n . p + d >= 0`), as a core Camera keeps them. Default none: nothing culled. */
|
|
38
|
+
readonly planes?: ArrayLike<number>;
|
|
39
|
+
/**
|
|
40
|
+
* A core Camera's own update (`camera.update(aspect, webgpu)`): {@link PersonCrowd.update} calls it first, so the
|
|
41
|
+
* planes are this frame's and not the last render's (a core Camera only refreshes them as it renders: before the
|
|
42
|
+
* first render they are all zero, and a moving camera's lag a frame, so a sought frame would plan differently).
|
|
43
|
+
*/
|
|
44
|
+
update?(aspect: number, webgpu: boolean): void;
|
|
45
|
+
}
|
|
46
|
+
/** The crowd budget and level switch points. Every number is a ceiling or a fraction of the viewport height. */
|
|
47
|
+
export interface CrowdBudget {
|
|
48
|
+
/** Most members skinned near. Default 128. */
|
|
49
|
+
near?: number;
|
|
50
|
+
/** Most members drawn far. Default 16384. */
|
|
51
|
+
far?: number;
|
|
52
|
+
/** Most vertices posed a frame, near and far together. Default 8,000,000. */
|
|
53
|
+
vertices?: number;
|
|
54
|
+
/** A member at least this fraction of the viewport tall is skinned near (budget allowing). Default 0.08: about 40 m for a man in a 35 degree view. */
|
|
55
|
+
nearScreen?: number;
|
|
56
|
+
/** A member smaller than this fraction of the viewport is not drawn. Default 0.002: two pixels of a 1080 line view. */
|
|
57
|
+
cullScreen?: number;
|
|
58
|
+
/** While near, a member stays near down to `nearScreen * (1 - hysteresis)`. Default 0: frames depend on nothing but the camera, so a film seeks exactly. */
|
|
59
|
+
hysteresis?: number;
|
|
60
|
+
}
|
|
61
|
+
/** Checks a budget and fills in the defaults. */
|
|
62
|
+
export declare function crowdBudget(budget?: CrowdBudget): Required<CrowdBudget>;
|
|
63
|
+
/** What {@link planCrowd} needs of each member: its bounding sphere. */
|
|
64
|
+
export interface PlannedMember {
|
|
65
|
+
readonly x: number;
|
|
66
|
+
readonly y: number;
|
|
67
|
+
readonly z: number;
|
|
68
|
+
/** Bounding sphere radius. */
|
|
69
|
+
readonly radius: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The level of every member: {@link NEAR}, {@link FAR} or {@link HIDDEN}. Members off the frustum or smaller than
|
|
73
|
+
* `cullScreen` are hidden; the rest, nearest first, go near while they are at least `nearScreen` tall and the near and
|
|
74
|
+
* vertex budgets allow, otherwise far while the far and vertex budgets allow. Pure: the same members, view, budget and
|
|
75
|
+
* `previous` levels give the same plan.
|
|
76
|
+
* @param previous Last frame's levels, for the hysteresis band; ignored when hysteresis is 0.
|
|
77
|
+
*/
|
|
78
|
+
export declare function planCrowd(members: readonly PlannedMember[], view: CrowdView, budget: CrowdBudget, vertices: {
|
|
79
|
+
near: number;
|
|
80
|
+
far: number;
|
|
81
|
+
}, previous?: ArrayLike<number>, out?: Uint8Array): Uint8Array;
|
|
82
|
+
/** Options of {@link PersonCrowd}. */
|
|
83
|
+
export interface PersonCrowdOptions extends VATCrowdOptions, CrowdBudget {
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A crowd of one baked person at every distance: near members skinned, far ones a vertex animation, the rest culled,
|
|
87
|
+
* planned each `update` inside the budget. `near` and `far` are the two draws, for `shadows.add` and `lighting.add`.
|
|
88
|
+
*/
|
|
89
|
+
export declare class PersonCrowd {
|
|
90
|
+
private readonly engine;
|
|
91
|
+
readonly bake: PersonBake;
|
|
92
|
+
readonly near: SkinnedCrowd;
|
|
93
|
+
readonly far: VATCrowd;
|
|
94
|
+
/** Level of each member after the last update. */
|
|
95
|
+
levels: Uint8Array;
|
|
96
|
+
/** Members drawn near, far, and not drawn, after the last update. */
|
|
97
|
+
readonly counts: {
|
|
98
|
+
near: number;
|
|
99
|
+
far: number;
|
|
100
|
+
hidden: number;
|
|
101
|
+
};
|
|
102
|
+
/** Vertices posed by the last update's draws. */
|
|
103
|
+
posed: number;
|
|
104
|
+
readonly budget: Required<CrowdBudget>;
|
|
105
|
+
disposed: boolean;
|
|
106
|
+
private readonly spheres;
|
|
107
|
+
private constructor();
|
|
108
|
+
/**
|
|
109
|
+
* Builds the two draws of `bake` and attaches them to the engine. The crowd draws need WebGPU (or the WebGL2
|
|
110
|
+
* compatibility layer). Loads `@margoengine/animation/instanced-skin` and `/vat` on first use.
|
|
111
|
+
* @example
|
|
112
|
+
* const people = await PersonCrowd.attach(engine, bake, {map: atlas});
|
|
113
|
+
* engine.onUpdate(() => people.update(members, engine.camera));
|
|
114
|
+
*/
|
|
115
|
+
static attach(engine: EngineKernel, bake: PersonBake, options?: PersonCrowdOptions): Promise<PersonCrowd>;
|
|
116
|
+
/**
|
|
117
|
+
* Plans the levels for `view` and writes every drawn member into its draw. Call once a frame, after the members moved
|
|
118
|
+
* and the camera was placed. A core Camera is brought up to date first, at `aspect` (default the canvas's), so the
|
|
119
|
+
* plan depends only on the members and where the camera is now.
|
|
120
|
+
* @throws RangeError for a member with a clip not in the bake or a bad matrix.
|
|
121
|
+
*/
|
|
122
|
+
update(people: readonly CrowdPerson[], view: CrowdView, aspect?: number): this;
|
|
123
|
+
dispose(): void;
|
|
124
|
+
[Symbol.dispose](): void;
|
|
125
|
+
}
|
package/dist/lod.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as FAR, n as HIDDEN, r as NEAR, i as PersonCrowd, a as crowdBudget, o as planCrowd } from "./lod-BR0gNHsn.js";
|
package/dist/riders.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Options of {@link riderMatrix}. */
|
|
2
|
+
export interface RiderPlacement {
|
|
3
|
+
/** The rider's hip joint above the seat point in the saddle frame, metres. Default 0.055 times the rider height (riderSeat). */
|
|
4
|
+
readonly seatHip?: number;
|
|
5
|
+
/** The rider model's hip joint above its root (its feet), model units at scale 1. Default 0.53 of `height`. */
|
|
6
|
+
readonly hipHeight?: number;
|
|
7
|
+
/** Rider standing height, model units. Default 1.75. */
|
|
8
|
+
readonly height?: number;
|
|
9
|
+
/** Share of the horse trunk's pitch the rider takes, 0 to 1. Default 0.4. */
|
|
10
|
+
readonly pitchShare?: number;
|
|
11
|
+
/** The rider model's facing: radians about +Y from +Z. Default 0 (glTF faces +Z). */
|
|
12
|
+
readonly facing?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Where a rider's root goes (16 numbers, column-major) for a horse's seat frame (16 numbers at `at` in `saddles`) and a
|
|
16
|
+
* rider scale. Pure.
|
|
17
|
+
* @throws RangeError for options out of range.
|
|
18
|
+
*/
|
|
19
|
+
export declare function riderMatrix(saddles: ArrayLike<number>, at: number, scale?: number, placement?: RiderPlacement, out?: Float32Array, outAt?: number): Float32Array;
|
package/dist/riders.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/riders.ts
|
|
2
|
+
function e(e, t, n = 1, r = {}, i = /* @__PURE__ */ new Float32Array(16), a = 0) {
|
|
3
|
+
let o = r.height ?? 1.75, s = r.seatHip ?? .055 * o, c = r.hipHeight ?? .53 * o, l = r.pitchShare ?? .4, u = r.facing ?? 0;
|
|
4
|
+
if (!(o > 0) || !(s >= 0 && s < 1) || !(c > 0 && c < 5) || !(l >= 0 && l <= 1) || !Number.isFinite(u) || !(n > 0)) throw RangeError("riderMatrix needs a height above 0, seatHip 0 to 1 m, hipHeight 0 to 5, pitchShare 0 to 1, a finite facing and a scale above 0");
|
|
5
|
+
let d = e, f = d[t + 8], p = d[t + 9], m = d[t + 10], h = Math.atan2(f, m), g = Math.atan2(p, Math.hypot(f, m)) * l, _ = Math.cos(h), v = Math.sin(h), y = Math.cos(g), b = Math.sin(g), x = [
|
|
6
|
+
v * y,
|
|
7
|
+
b,
|
|
8
|
+
_ * y
|
|
9
|
+
], S = [
|
|
10
|
+
-v * b,
|
|
11
|
+
y,
|
|
12
|
+
-_ * b
|
|
13
|
+
], C = [
|
|
14
|
+
S[1] * x[2] - S[2] * x[1],
|
|
15
|
+
S[2] * x[0] - S[0] * x[2],
|
|
16
|
+
S[0] * x[1] - S[1] * x[0]
|
|
17
|
+
], w = d[t + 12] + d[t + 4] * s * n, T = d[t + 13] + d[t + 5] * s * n, E = d[t + 14] + d[t + 6] * s * n, D = Math.cos(u), O = Math.sin(u);
|
|
18
|
+
for (let e = 0; e < 3; e++) i[a + e] = (C[e] * D + x[e] * O) * n, i[a + 4 + e] = S[e] * n, i[a + 8 + e] = (x[e] * D - C[e] * O) * n;
|
|
19
|
+
return i[a + 3] = i[a + 7] = i[a + 11] = 0, i[a + 12] = w - S[0] * c * n, i[a + 13] = T - S[1] * c * n, i[a + 14] = E - S[2] * c * n, i[a + 15] = 1, i;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { e as riderMatrix };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type SettingRow } from './shared/settings.js';
|
|
2
|
+
import type { AddArmyOptions } from './index.js';
|
|
3
|
+
import type { PersonBakeOptions } from './bake.js';
|
|
4
|
+
/** One value of a setting. */
|
|
5
|
+
export type ArmySettingValue = number | string;
|
|
6
|
+
/** Values by setting name; a name left out keeps the default. */
|
|
7
|
+
export type ArmySettingValues = Readonly<Record<string, ArmySettingValue>>;
|
|
8
|
+
/** One control: the shared row shape. */
|
|
9
|
+
export interface ArmySetting extends SettingRow {
|
|
10
|
+
readonly default: ArmySettingValue;
|
|
11
|
+
}
|
|
12
|
+
/** Every army control, in panel order. */
|
|
13
|
+
export declare const ARMY_SETTINGS: readonly ArmySetting[];
|
|
14
|
+
/** Every army setting at its default, as a fresh object to edit. */
|
|
15
|
+
export declare function armySettingDefaults(): Record<string, ArmySettingValue>;
|
|
16
|
+
/**
|
|
17
|
+
* The `addArmy` options (less the person) and the `bakePerson` options the given values make. Only the names given
|
|
18
|
+
* are set.
|
|
19
|
+
* @throws TypeError for an unknown name; RangeError for a value out of range.
|
|
20
|
+
*/
|
|
21
|
+
export declare function armyOptionsFromSettings(values: ArmySettingValues): {
|
|
22
|
+
options: Omit<AddArmyOptions, 'person'>;
|
|
23
|
+
bake: PersonBakeOptions;
|
|
24
|
+
};
|
package/dist/settings.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
//#region ../shared/settings.js
|
|
2
|
+
var e = (e, t, n) => typeof e == "number" && e >= t && e <= n, t = (t, n, r) => Array.isArray(t) && t.length === 3 && t.every((t) => e(t, n, r)), n = (e) => e.stopKey ?? "elevation", r = (e, t, n, r, i, a, o, s, c = !0) => ({
|
|
3
|
+
name: e,
|
|
4
|
+
group: t,
|
|
5
|
+
kind: "number",
|
|
6
|
+
default: n,
|
|
7
|
+
min: r,
|
|
8
|
+
max: i,
|
|
9
|
+
step: a,
|
|
10
|
+
unit: o,
|
|
11
|
+
about: s,
|
|
12
|
+
live: c
|
|
13
|
+
}), i = (e, t, n, r, i = !0) => ({
|
|
14
|
+
name: e,
|
|
15
|
+
group: t,
|
|
16
|
+
kind: "choice",
|
|
17
|
+
default: n[0],
|
|
18
|
+
choices: n,
|
|
19
|
+
unit: "",
|
|
20
|
+
about: r,
|
|
21
|
+
live: i
|
|
22
|
+
});
|
|
23
|
+
function a(e) {
|
|
24
|
+
return Array.isArray(e) ? typeof e[0] == "object" ? e.map((e) => ({
|
|
25
|
+
...e,
|
|
26
|
+
color: [...e.color]
|
|
27
|
+
})) : [...e] : e;
|
|
28
|
+
}
|
|
29
|
+
function o(e) {
|
|
30
|
+
return Object.fromEntries(e.map((e) => [e.name, a(e.default)]));
|
|
31
|
+
}
|
|
32
|
+
var s = (e) => new Map(e.map((e) => [e.name, e]));
|
|
33
|
+
function c(r, i, a) {
|
|
34
|
+
let o = r.min ?? -Infinity, s = r.max ?? Infinity, c;
|
|
35
|
+
if (i === null) c = !!r.nullable;
|
|
36
|
+
else if (r.kind === "number") c = e(i, o, s);
|
|
37
|
+
else if (r.kind === "color") c = t(i, o, s);
|
|
38
|
+
else if (r.kind === "choice") c = r.choices.includes(i);
|
|
39
|
+
else {
|
|
40
|
+
let a = n(r);
|
|
41
|
+
c = Array.isArray(i) && i.length >= 2 && i.length <= 8 && i.every((n, r) => typeof n == "object" && !!n && e(n[a], o, s) && t(n.color, 0, 1) && (r === 0 || n[a] > i[r - 1][a]));
|
|
42
|
+
}
|
|
43
|
+
if (c) return;
|
|
44
|
+
let l = r.nullable ? r.weather ? ` or null (follow the weather's ${r.weather})` : " or null" : "", u = r.kind === "number" ? `a number from ${o} to ${s}${l}` : r.kind === "color" ? `three numbers from ${o} to ${s} (linear RGB)${l}` : r.kind === "choice" ? r.choices.map((e) => `'${e}'`).join(" or ") + l : `2 to 8 stops {${n(r)}, color}, ${n(r)} ${o} to ${s} rising, colours 0 to 1${l}`;
|
|
45
|
+
throw RangeError(`Invalid ${a} setting ${r.name}; use ${u}`);
|
|
46
|
+
}
|
|
47
|
+
function l(e, t, n, r = `the rows in @margoengine/${n}/settings`) {
|
|
48
|
+
let i = e instanceof Map ? e : s(e);
|
|
49
|
+
for (let e of Object.keys(t)) {
|
|
50
|
+
let a = i.get(e);
|
|
51
|
+
if (!a) throw TypeError(`Unknown ${n} setting ${e}; use a name from ${r}`);
|
|
52
|
+
c(a, t[e], n);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/settings.ts
|
|
57
|
+
var u = [
|
|
58
|
+
r("near", "budget", 128, 0, 65536, 1, "", "Most members skinned near (full mesh, two clips blended)."),
|
|
59
|
+
r("far", "budget", 16384, 0, 1048576, 1, "", "Most members drawn far (simplified mesh, vertex animation)."),
|
|
60
|
+
r("vertices", "budget", 8e6, 0, 1e8, 1e3, "", "Most vertices posed a frame, near and far together."),
|
|
61
|
+
r("nearScreen", "levels", .08, .001, 10, .001, "", "A member at least this fraction of the view tall is skinned near."),
|
|
62
|
+
r("cullScreen", "levels", .002, 0, .5, 5e-4, "", "A member smaller than this fraction of the view is not drawn."),
|
|
63
|
+
r("hysteresis", "levels", 0, 0, .9, .01, "", "A near member stays near down to nearScreen times one less this; 0 seeks exactly."),
|
|
64
|
+
r("walkStride", "gait", 1.524, .2, 5, .001, "m", "Ground the walk clip covers in one cycle (two 30 inch steps)."),
|
|
65
|
+
r("runStride", "gait", 1.829, .2, 6, .001, "m", "Ground the run clip covers in one cycle (two 36 inch steps)."),
|
|
66
|
+
r("runAbove", "gait", 2, .5, 10, .05, "m/s", "Speed of the walk-run change."),
|
|
67
|
+
r("blendBand", "gait", .4, 0, 2, .05, "m/s", "Speed band the walk and run blend across."),
|
|
68
|
+
r("standBelow", "gait", .1, 0, .5, .01, "m/s", "Below this a man stands."),
|
|
69
|
+
i("step", "gait", ["cadence", "route"], "Cadence: the men keep step. Route: each his own."),
|
|
70
|
+
r("stature", "people", .04, 0, .3, .005, "", "Spread of heights, one standard deviation as a fraction of the mean."),
|
|
71
|
+
r("facing", "people", 0, -3.1416, 3.1416, .01, "rad", "The person model's facing about +Y from +Z."),
|
|
72
|
+
r("seed", "people", 1, 0, 1e6, 1, "", "Seed of heights, outfits and route-step phases."),
|
|
73
|
+
r("riderPitchShare", "riders", .4, 0, 1, .01, "", "Share of the horse trunk's pitch a rider takes."),
|
|
74
|
+
r("riderHipHeight", "riders", 0, 0, 2, .01, "m", "The rider model's hip above its feet; 0 for 0.53 of its height."),
|
|
75
|
+
r("fps", "bake", 30, 10, 120, 1, "1/s", "Bake rows a second.", !1),
|
|
76
|
+
r("farTriangles", "bake", 3e3, 12, 1e6, 1, "", "Triangles the far mesh keeps, at most.", !1)
|
|
77
|
+
], d = s(u);
|
|
78
|
+
function f() {
|
|
79
|
+
return o(u);
|
|
80
|
+
}
|
|
81
|
+
function p(e) {
|
|
82
|
+
l(d, e, "armies", "the rows in @margoengine/armies/settings");
|
|
83
|
+
let t = e, n = {}, r = {}, i = {};
|
|
84
|
+
for (let e of [
|
|
85
|
+
"near",
|
|
86
|
+
"far",
|
|
87
|
+
"vertices",
|
|
88
|
+
"nearScreen",
|
|
89
|
+
"cullScreen",
|
|
90
|
+
"hysteresis",
|
|
91
|
+
"runAbove",
|
|
92
|
+
"blendBand",
|
|
93
|
+
"standBelow",
|
|
94
|
+
"stature",
|
|
95
|
+
"facing",
|
|
96
|
+
"seed"
|
|
97
|
+
]) e in t && (n[e] = t[e]);
|
|
98
|
+
return ("walkStride" in t || "runStride" in t) && (n.strides = {
|
|
99
|
+
..."walkStride" in t ? { walk: t.walkStride } : {},
|
|
100
|
+
..."runStride" in t ? { run: t.runStride } : {}
|
|
101
|
+
}), "step" in t && (n.step = t.step), "riderPitchShare" in t && (i.pitchShare = t.riderPitchShare), "riderHipHeight" in t && t.riderHipHeight > 0 && (i.hipHeight = t.riderHipHeight), Object.keys(i).length && (n.rider = i), "fps" in t && (r.fps = t.fps), "farTriangles" in t && (r.farTriangles = t.farTriangles), {
|
|
102
|
+
options: n,
|
|
103
|
+
bake: r
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { u as ARMY_SETTINGS, p as armyOptionsFromSettings, f as armySettingDefaults };
|