@plupin/character 0.2.0 → 0.3.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.
Files changed (44) hide show
  1. package/dist/anime-face.d.ts +42 -0
  2. package/dist/anime-face.js +14 -0
  3. package/dist/blob.d.ts +32 -0
  4. package/dist/blob.js +18 -0
  5. package/dist/body-presets.d.ts +85 -0
  6. package/dist/canvas.js +7 -7
  7. package/dist/chunk-09c5tps4.js +337 -0
  8. package/dist/chunk-60p135hw.js +103 -0
  9. package/dist/chunk-dpb0rnw9.js +37 -0
  10. package/dist/chunk-g1c0wdcj.js +825 -0
  11. package/dist/chunk-kber92gm.js +415 -0
  12. package/dist/{chunk-k5gwaq6t.js → chunk-sa2r1cxz.js} +30 -3
  13. package/dist/chunk-yd5zzkkg.js +313 -0
  14. package/dist/clips.d.ts +40 -0
  15. package/dist/dress.d.ts +4 -0
  16. package/dist/emote.d.ts +5 -3
  17. package/dist/gaze.d.ts +81 -0
  18. package/dist/gaze.js +113 -0
  19. package/dist/hair3d.d.ts +3 -0
  20. package/dist/index.d.ts +9 -2
  21. package/dist/index.js +84 -10
  22. package/dist/listing.d.ts +1 -1
  23. package/dist/listing.js +16 -6
  24. package/dist/platform-body-data.d.ts +9 -0
  25. package/dist/platform-body.d.ts +91 -0
  26. package/dist/plup3d.d.ts +75 -27
  27. package/dist/png.d.ts +19 -2
  28. package/dist/pose.d.ts +7 -1
  29. package/dist/pose.js +1 -1
  30. package/dist/proportions.d.ts +31 -0
  31. package/dist/ragdoll.d.ts +51 -0
  32. package/dist/resolution.d.ts +21 -0
  33. package/dist/skin-map.d.ts +155 -0
  34. package/dist/skin-map.js +55 -0
  35. package/dist/skin-native.d.ts +55 -6
  36. package/dist/texture.d.ts +8 -0
  37. package/dist/three.d.ts +3 -0
  38. package/dist/three.js +1909 -188
  39. package/dist/wear3d.d.ts +99 -0
  40. package/dist/wearables.d.ts +203 -0
  41. package/dist/wearables.js +26 -0
  42. package/package.json +21 -1
  43. package/dist/chunk-ae7gp5cc.js +0 -101
  44. package/dist/chunk-wpbgtn0y.js +0 -179
@@ -0,0 +1,313 @@
1
+ // src/emote.ts
2
+ var EMOTES = [
3
+ {
4
+ id: "emote-ngakak",
5
+ label: "Ngakak",
6
+ glyph: "(≧▽≦)",
7
+ face: "teriak",
8
+ clip: "laugh",
9
+ sigmaPrice: 0
10
+ },
11
+ {
12
+ id: "emote-semangat",
13
+ label: "Semangat",
14
+ glyph: "٩(ˊᗜˋ)و",
15
+ face: "yell",
16
+ clip: "cheer",
17
+ sigmaPrice: 0
18
+ },
19
+ { id: "emote-keren", label: "Keren", glyph: "(⌐■_■)", face: "cool", clip: "pose", sigmaPrice: 0 },
20
+ {
21
+ id: "emote-marah",
22
+ label: "Marah",
23
+ glyph: "(╬ Ò﹏Ó)",
24
+ face: "rage",
25
+ clip: "rage",
26
+ sigmaPrice: 0
27
+ },
28
+ {
29
+ id: "emote-nangis",
30
+ label: "Nangis",
31
+ glyph: "(╥﹏╥)",
32
+ face: "cry",
33
+ clip: "sob",
34
+ sigmaPrice: 0
35
+ },
36
+ {
37
+ id: "emote-kaget",
38
+ label: "Kaget",
39
+ glyph: "(⊙_⊙)",
40
+ face: "shock",
41
+ clip: "recoil",
42
+ sigmaPrice: 0
43
+ },
44
+ {
45
+ id: "emote-suka",
46
+ label: "Suka",
47
+ glyph: "(♡˙︶˙♡)",
48
+ face: "sparkle",
49
+ clip: "cheer",
50
+ sigmaPrice: 0
51
+ },
52
+ {
53
+ id: "emote-mantap",
54
+ label: "Mantap",
55
+ glyph: "(•̀ᴗ•́)و",
56
+ face: "smug",
57
+ clip: "cheer",
58
+ sigmaPrice: 0
59
+ },
60
+ {
61
+ id: "emote-meledek",
62
+ label: "Meledek",
63
+ glyph: "(^_-)",
64
+ face: "tongue",
65
+ clip: "wave",
66
+ sigmaPrice: 15
67
+ },
68
+ {
69
+ id: "emote-ide",
70
+ label: "Ide Cemerlang",
71
+ glyph: "(!_!)",
72
+ face: "idea",
73
+ clip: "jump",
74
+ sigmaPrice: 20
75
+ },
76
+ {
77
+ id: "emote-licik",
78
+ label: "Licik",
79
+ glyph: "(¬‿¬)",
80
+ face: "licik",
81
+ clip: "sneak",
82
+ sigmaPrice: 25
83
+ },
84
+ {
85
+ id: "emote-tewas",
86
+ label: "Tewas",
87
+ glyph: "(x_x)",
88
+ face: "dead",
89
+ clip: "collapse",
90
+ sigmaPrice: 30
91
+ },
92
+ {
93
+ id: "emote-bintang",
94
+ label: "Mata Bintang",
95
+ glyph: "(*_*)",
96
+ face: "stars",
97
+ clip: "dance",
98
+ sigmaPrice: 40
99
+ },
100
+ { id: "emote-aduh", label: "Aduh", glyph: "(>_<)", face: "pain", clip: "recoil", sigmaPrice: 50 },
101
+ {
102
+ id: "emote-serius",
103
+ label: "Serius Banget",
104
+ glyph: "(-_-)",
105
+ face: "serious",
106
+ clip: "nod",
107
+ sigmaPrice: 60
108
+ }
109
+ ];
110
+ function emoteOf(name) {
111
+ const id = name.startsWith("emote-") ? name : `emote-${name}`;
112
+ return EMOTES.find((emote) => emote.id === id);
113
+ }
114
+
115
+ // src/ragdoll.ts
116
+ var RAGDOLL_JOINTS = ["armL", "armR", "legL", "legR"];
117
+ var spring = () => ({ at: { x: 0, z: 0 }, speed: { x: 0, z: 0 } });
118
+ function pull(s, target, stiffness, damping, dt) {
119
+ for (const axis of ["x", "z"]) {
120
+ const force = (target[axis] - s.at[axis]) * stiffness - s.speed[axis] * damping;
121
+ s.speed[axis] += force * dt;
122
+ s.at[axis] += s.speed[axis] * dt;
123
+ }
124
+ }
125
+ var TUNE = {
126
+ wobbly: { joint: [70, 7], body: [45, 6.5], kick: 0.09 },
127
+ limp: { joint: [18, 2.6] },
128
+ recover: { joint: [90, 19], body: [40, 12.6] },
129
+ gravity: 9.8,
130
+ topple: 14,
131
+ fallAt: 0.95,
132
+ lying: 1.45,
133
+ bounce: 0.32,
134
+ friction: 5,
135
+ getUp: 1.8
136
+ };
137
+ function createRagdoll(initial = "off", radius = 0.5) {
138
+ let mode = initial;
139
+ let after = initial === "limp" ? "off" : initial;
140
+ const joints = Object.fromEntries(RAGDOLL_JOINTS.map((name) => [name, spring()]));
141
+ const body = spring();
142
+ let lift = 0;
143
+ let liftSpeed = 0;
144
+ const offset = { x: 0, z: 0 };
145
+ const slide = { x: 0, z: 0 };
146
+ let fallen = 0;
147
+ let rising = false;
148
+ let fresh = true;
149
+ let lastVelocity = { x: 0, z: 0 };
150
+ const flop = {
151
+ armL: { x: -0.4, z: -1.25 },
152
+ armR: { x: 0.3, z: 1.1 },
153
+ legL: { x: 0.5, z: -0.35 },
154
+ legR: { x: -0.2, z: 0.45 }
155
+ };
156
+ const fall = () => {
157
+ if (mode === "limp")
158
+ return;
159
+ after = mode;
160
+ mode = "limp";
161
+ fallen = 0;
162
+ };
163
+ return {
164
+ mode: () => mode,
165
+ set(next) {
166
+ if (next === "limp") {
167
+ fall();
168
+ if (Math.hypot(body.speed.x, body.speed.z) < 0.5)
169
+ body.speed.x -= 1.2;
170
+ return;
171
+ }
172
+ after = next;
173
+ if (mode !== "limp")
174
+ mode = next;
175
+ else if (next === "off") {
176
+ mode = "off";
177
+ rising = true;
178
+ }
179
+ },
180
+ push(x, y, z) {
181
+ body.speed.x += z * 1.6;
182
+ body.speed.z -= x * 1.6;
183
+ slide.x += x * 0.6;
184
+ slide.z += z * 0.6;
185
+ liftSpeed += Math.max(0, y);
186
+ for (const name of RAGDOLL_JOINTS) {
187
+ joints[name].speed.x -= z * 4;
188
+ joints[name].speed.z += x * 4;
189
+ }
190
+ if (mode === "off")
191
+ after = "off";
192
+ if (Math.hypot(x, z) > 2.5 || y > 2.5 || mode === "limp")
193
+ fall();
194
+ },
195
+ step(dt, input) {
196
+ dt = Math.min(dt, 1 / 20);
197
+ if (fresh) {
198
+ for (const name of RAGDOLL_JOINTS)
199
+ joints[name].at = { ...input.joints[name] };
200
+ body.at = { ...input.body };
201
+ lift = input.lift;
202
+ fresh = false;
203
+ }
204
+ const accel = {
205
+ x: (input.velocity.x - lastVelocity.x) / Math.max(dt, 0.001),
206
+ z: (input.velocity.z - lastVelocity.z) / Math.max(dt, 0.001)
207
+ };
208
+ lastVelocity = { ...input.velocity };
209
+ const clampAccel = (v) => Math.max(-30, Math.min(30, v));
210
+ accel.x = clampAccel(accel.x);
211
+ accel.z = clampAccel(accel.z);
212
+ if (mode === "limp") {
213
+ fallen += dt;
214
+ const lean = Math.hypot(body.at.x, body.at.z);
215
+ const dir = lean > 0.001 ? { x: body.at.x / lean, z: body.at.z / lean } : { x: -Math.sign(body.speed.x || 1), z: 0 };
216
+ const torque = TUNE.topple * Math.sin(Math.min(lean, Math.PI / 2) + 0.05);
217
+ body.speed.x += dir.x * torque * dt - body.speed.x * 0.6 * dt;
218
+ body.speed.z += dir.z * torque * dt - body.speed.z * 0.6 * dt;
219
+ body.at.x += body.speed.x * dt;
220
+ body.at.z += body.speed.z * dt;
221
+ const next = Math.hypot(body.at.x, body.at.z);
222
+ if (next > TUNE.lying) {
223
+ const k2 = TUNE.lying / next;
224
+ body.at.x *= k2;
225
+ body.at.z *= k2;
226
+ const into = body.speed.x * dir.x + body.speed.z * dir.z;
227
+ if (into > 0) {
228
+ body.speed.x -= (1 + TUNE.bounce) * into * dir.x;
229
+ body.speed.z -= (1 + TUNE.bounce) * into * dir.z;
230
+ for (const name of RAGDOLL_JOINTS) {
231
+ joints[name].speed.x += into * flop[name].x * 2.2;
232
+ joints[name].speed.z += into * flop[name].z * 2.2;
233
+ }
234
+ }
235
+ }
236
+ liftSpeed -= TUNE.gravity * dt;
237
+ lift += liftSpeed * dt;
238
+ const floor = radius * Math.sin(Math.min(Math.hypot(body.at.x, body.at.z), Math.PI / 2));
239
+ if (lift < floor) {
240
+ lift = floor;
241
+ liftSpeed = Math.max(0, -liftSpeed * TUNE.bounce);
242
+ slide.x -= slide.x * TUNE.friction * dt;
243
+ slide.z -= slide.z * TUNE.friction * dt;
244
+ }
245
+ offset.x += slide.x * dt;
246
+ offset.z += slide.z * dt;
247
+ const [k, c] = TUNE.limp.joint;
248
+ for (const name of RAGDOLL_JOINTS) {
249
+ const target = {
250
+ x: -body.at.x * 0.6 + flop[name].x,
251
+ z: -body.at.z * 0.6 + flop[name].z
252
+ };
253
+ pull(joints[name], target, k, c, dt);
254
+ }
255
+ if (after === "wobbly" && fallen > TUNE.getUp) {
256
+ mode = "wobbly";
257
+ rising = true;
258
+ }
259
+ return output(true);
260
+ }
261
+ const wobbly = mode === "wobbly" && !rising;
262
+ if (rising && Math.hypot(body.at.x - input.body.x, body.at.z - input.body.z) < 0.15)
263
+ rising = false;
264
+ const [jk, jc] = wobbly ? TUNE.wobbly.joint : TUNE.recover.joint;
265
+ const [bk, bc] = wobbly ? TUNE.wobbly.body : TUNE.recover.body;
266
+ const kick = wobbly ? TUNE.wobbly.kick : 0;
267
+ for (const name of RAGDOLL_JOINTS) {
268
+ joints[name].speed.x -= accel.z * kick * 3 * dt * 10;
269
+ joints[name].speed.z += accel.x * kick * 3 * dt * 10;
270
+ pull(joints[name], input.joints[name], jk, jc, dt);
271
+ }
272
+ body.speed.x -= accel.z * kick * dt * 10;
273
+ body.speed.z += accel.x * kick * dt * 10;
274
+ pull(body, input.body, bk, bc, dt);
275
+ lift += (input.lift - lift) * Math.min(1, dt * 6);
276
+ liftSpeed = 0;
277
+ offset.x -= offset.x * Math.min(1, dt * 3);
278
+ offset.z -= offset.z * Math.min(1, dt * 3);
279
+ slide.x = slide.z = 0;
280
+ if (wobbly && Math.hypot(body.at.x - input.body.x, body.at.z - input.body.z) > TUNE.fallAt)
281
+ fall();
282
+ if (mode === "off" && settled(input))
283
+ return passthrough(input);
284
+ return output(false);
285
+ }
286
+ };
287
+ function settled(input) {
288
+ const close = (s, t) => Math.abs(s.at.x - t.x) + Math.abs(s.at.z - t.z) < 0.01 && Math.abs(s.speed.x) + Math.abs(s.speed.z) < 0.05;
289
+ return close(body, input.body) && RAGDOLL_JOINTS.every((name) => close(joints[name], input.joints[name])) && Math.abs(offset.x) + Math.abs(offset.z) < 0.005;
290
+ }
291
+ function passthrough(input) {
292
+ for (const name of RAGDOLL_JOINTS) {
293
+ joints[name].at = { ...input.joints[name] };
294
+ joints[name].speed = { x: 0, z: 0 };
295
+ }
296
+ body.at = { ...input.body };
297
+ body.speed = { x: 0, z: 0 };
298
+ lift = input.lift;
299
+ offset.x = offset.z = 0;
300
+ return { ...input, joints: { ...input.joints }, offset: { x: 0, z: 0 }, down: false };
301
+ }
302
+ function output(down) {
303
+ return {
304
+ joints: Object.fromEntries(RAGDOLL_JOINTS.map((name) => [name, { ...joints[name].at }])),
305
+ body: { ...body.at },
306
+ lift,
307
+ offset: { ...offset },
308
+ down
309
+ };
310
+ }
311
+ }
312
+
313
+ export { EMOTES, emoteOf, RAGDOLL_JOINTS, createRagdoll };
@@ -0,0 +1,40 @@
1
+ import type { CustomClip } from "./pose";
2
+ import type { CanonicalBone } from "./rig";
3
+ /**
4
+ * The hand-keyed clips: one authored pose at a time, expanded into the same keyframe format a creator
5
+ * ships (`CustomClip`), so the built-in vocabulary and an uploaded animation are one shape. The rig
6
+ * has six bones, and every frame lists them in `AUTHORED_BONES` order, then one lift in studs.
7
+ *
8
+ * A named clip in `CLIPS` is this data sampled at `t`; an emote may name it or ship its own `anim`.
9
+ * Nothing here touches three.js, a DOM or the network, and every number stays inside `ANIM_CAPS`
10
+ * (`listing.ts`) so a creator can copy any of these into a listing unchanged.
11
+ *
12
+ * Angles follow the rig's euler order (x, y, z):
13
+ * - `z` swings a limb out to the side; for arms `armR` is positive and `armL` negative, and about
14
+ * 2.6 rad is overhead.
15
+ * - `x` swings a limb forward (negative) or back (positive); on the torso and head it pitches the
16
+ * body forward (positive) or back.
17
+ * - `y` turns the head left or right.
18
+ * - `lift` raises the whole character in studs. It never goes below 0: the rig has no knees, so a
19
+ * negative lift would push the feet through the floor.
20
+ */
21
+ export declare const AUTHORED_BONES: readonly CanonicalBone[];
22
+ /** Every clip keyed by hand: the vocabulary an emote or a creator may name. */
23
+ export declare const AUTHORED_CLIP_NAMES: readonly ["recoil", "flail", "topple", "collapse", "sneak", "cheer", "laugh", "pose", "rage", "sob", "nod"];
24
+ export type AuthoredClipName = (typeof AUTHORED_CLIP_NAMES)[number];
25
+ /**
26
+ * The keyed library. Each entry is a motion a viewer can name from the pose alone:
27
+ *
28
+ * - `recoil` snaps the body back with both arms thrown up, then settles: a fright or a flinch.
29
+ * - `flail` is airborne, arms windmilling and legs kicking, held up by `lift`.
30
+ * - `topple` tips over sideways and stays down.
31
+ * - `collapse` buckles at the knees and folds forward until it is still.
32
+ * - `sneak` creeps forward, low, hands up, head scanning left and right.
33
+ * - `cheer` throws both arms overhead and hops.
34
+ * - `laugh` folds forward and shakes, arms hugged across the belly.
35
+ * - `pose` puts a hand on the hip and cocks its head.
36
+ * - `rage` stomps and shakes with the arms clenched low.
37
+ * - `sob` brings both hands to the face while the shoulders heave.
38
+ * - `nod` is a slow, deliberate nod: the quiet yes.
39
+ */
40
+ export declare const AUTHORED_CLIPS: Readonly<Record<AuthoredClipName, CustomClip>>;
@@ -0,0 +1,4 @@
1
+ import { type WearKit, type WornPiece } from "./wear3d";
2
+ import { type WearKey } from "./wearables";
3
+ /** Build any wearable: a hairstyle, a hat, a garment or a face piece. */
4
+ export declare function buildWear(key: WearKey, kit: WearKit): WornPiece;
package/dist/emote.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import type { NamedFace } from "./faces";
2
2
  import type { ClipName, CustomClip } from "./pose";
3
3
  /**
4
- * An emote is a name, a face and a clip the rig already has: nothing new to animate. `sigmaPrice` 0
5
- * is free for everyone; anything else is bought in the shop (wardrobe), and the catalogue row has the
6
- * same id. A game plays the face and the clip; whether a player may is the platform's to say.
4
+ * An emote is a name, a face and a clip the rig plays. Every clip here is an authored motion: the six
5
+ * procedural loops plus the keyframe library in `clips.ts` (`recoil`, `sneak`, `collapse`, ...), so a
6
+ * label like "Tewas" performs a collapse instead of borrowing idle. `sigmaPrice` 0 is free for
7
+ * everyone; anything else is bought in the shop (wardrobe), and the catalogue row has the same id. A
8
+ * game plays the face and the clip; whether a player may is the platform's to say.
7
9
  */
8
10
  export interface Emote {
9
11
  /** The catalogue id, also what a game passes: `emote-ngakak`. */
package/dist/gaze.d.ts ADDED
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Damped spring step (semi-implicit Euler), shared by Character's squash, sway and gaze springs.
3
+ * Returns the new [value, velocity].
4
+ */
5
+ /** One step of a damped spring, shared by the gaze and the body. */
6
+ export declare function spring(value: number, velocity: number, target: number, stiffness: number, damping: number, dt: number): readonly [number, number];
7
+ /**
8
+ * Character eye gaze (landing spec section D2; numbers from section 0, N9). The pointer offset from
9
+ * the face, in body widths (BW), becomes one eye cell: X -2..2, Y -1..0 (Q9: the eyes never move down). Only the eyes move; the
10
+ * mouth never does (skin.ts composeSkin). Pure, so the cell table is tested without a renderer.
11
+ */
12
+ export declare const GAZE: {
13
+ /** Spring: stiffness 400, damping 36 (omega = 20 rad/s, zeta = 0.9). */
14
+ readonly k: 400;
15
+ readonly c: 36;
16
+ /** Gaze units per BW. */
17
+ readonly gain: 1.6;
18
+ readonly clampX: 2.4;
19
+ readonly clampY: 1.4;
20
+ /** An offset under this many BW is a dead zone. */
21
+ readonly deadBW: 0.25;
22
+ /** Beyond nearBW the gaze starts to fade; by farBW it is gone. */
23
+ readonly nearBW: 3;
24
+ readonly farBW: 5;
25
+ /** Cell hysteresis in gaze units: enter 0.6 (1 to 2 at 1.6), leave 0.4 (2 to 1 at 1.4). */
26
+ readonly enter1: 0.6;
27
+ readonly enter2: 1.6;
28
+ readonly exit1: 0.4;
29
+ readonly exit2: 1.4;
30
+ /** Reduced motion (D5): the cell may update at most this often, in seconds. */
31
+ readonly snapEveryS: 0.25;
32
+ };
33
+ export interface Point {
34
+ x: number;
35
+ y: number;
36
+ }
37
+ export interface Spring {
38
+ value: number;
39
+ velocity: number;
40
+ }
41
+ export interface Gaze {
42
+ x: Spring;
43
+ y: Spring;
44
+ cellX: number;
45
+ cellY: number;
46
+ }
47
+ export declare const NO_GAZE: Gaze;
48
+ /** Gaze target for a pointer offset in BW: the D2 mapping, with its dead zone. */
49
+ export declare function gazeTarget(dxBW: number, dyBW: number): Point;
50
+ /** One step of the gaze spring (k 400, c 36). */
51
+ export declare function springStep(s: Spring, target: number, dt: number): Spring;
52
+ /**
53
+ * Eye cell for a gaze value, with hysteresis. `twoCells` lets X reach +-2; Y stops at +-1.
54
+ * Crossing the centre resets the cell, so the eyes never jump across it.
55
+ */
56
+ export declare function nextCell(prev: number, value: number, twoCells: boolean): number;
57
+ export declare function stepGaze(gaze: Gaze, target: Point, dt: number): Gaze;
58
+ /** Reduced motion (D5): the gaze cell may update only this often (at most 4 times a second). */
59
+ export declare function snapDue(lastAt: number, now: number): boolean;
60
+ /** Reduced motion (D5): no spring, the cell follows the target at once. The caller paces it with snapDue. */
61
+ export declare function snapGaze(gaze: Gaze, target: Point): Gaze;
62
+ /**
63
+ * Where a pointer is from a Character, as a direction whose length grows with distance, levels off below 1
64
+ * and fades to nothing for a pointer that is not near. Pure, so the mapping is tested without a page.
65
+ */
66
+ export declare function towardFrom(at: {
67
+ px: number;
68
+ py: number;
69
+ moved: boolean;
70
+ }, rect: {
71
+ left: number;
72
+ top: number;
73
+ width: number;
74
+ height: number;
75
+ }): {
76
+ x: number;
77
+ y: number;
78
+ };
79
+ /** How far away (in Character heights) the pointer still draws the eyes and the turn, in full and not at all. */
80
+ export declare const NEAR_FULL = 1.4;
81
+ export declare const NEAR_NONE = 2.4;
package/dist/gaze.js ADDED
@@ -0,0 +1,113 @@
1
+ // src/gaze.ts
2
+ function spring(value, velocity, target, stiffness, damping, dt) {
3
+ const acceleration = -stiffness * (value - target) - damping * velocity;
4
+ const nextVelocity = velocity + acceleration * dt;
5
+ return [value + nextVelocity * dt, nextVelocity];
6
+ }
7
+ var GAZE = {
8
+ k: 400,
9
+ c: 36,
10
+ gain: 1.6,
11
+ clampX: 2.4,
12
+ clampY: 1.4,
13
+ deadBW: 0.25,
14
+ nearBW: 3,
15
+ farBW: 5,
16
+ enter1: 0.6,
17
+ enter2: 1.6,
18
+ exit1: 0.4,
19
+ exit2: 1.4,
20
+ snapEveryS: 0.25
21
+ };
22
+ var MAX_CELL_Y = 0;
23
+ var lookCellY = (cell) => Math.min(MAX_CELL_Y, cell);
24
+ var NO_GAZE = {
25
+ x: { value: 0, velocity: 0 },
26
+ y: { value: 0, velocity: 0 },
27
+ cellX: 0,
28
+ cellY: 0
29
+ };
30
+ var clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
31
+ function gazeTarget(dxBW, dyBW) {
32
+ const dx = Math.abs(dxBW) < GAZE.deadBW ? 0 : dxBW;
33
+ const dy = Math.abs(dyBW) < GAZE.deadBW ? 0 : dyBW;
34
+ const distance = Math.hypot(dxBW, dyBW);
35
+ const near = 1 - clamp((distance - GAZE.nearBW) / (GAZE.farBW - GAZE.nearBW), 0, 1);
36
+ return {
37
+ x: clamp(GAZE.gain * dx, -GAZE.clampX, GAZE.clampX) * near,
38
+ y: clamp(GAZE.gain * dy, -GAZE.clampY, GAZE.clampY) * near
39
+ };
40
+ }
41
+ function springStep(s, target, dt) {
42
+ const [value, velocity] = spring(s.value, s.velocity, target, GAZE.k, GAZE.c, dt);
43
+ return { value, velocity };
44
+ }
45
+ function nextCell(prev, value, twoCells) {
46
+ const magnitude = Math.abs(value);
47
+ const sign = Math.sign(value);
48
+ const prevSign = Math.sign(prev);
49
+ let cell = prevSign !== 0 && sign !== 0 && sign !== prevSign ? 0 : Math.abs(prev);
50
+ if (cell === 0 && magnitude > GAZE.enter1)
51
+ cell = 1;
52
+ if (twoCells && cell === 1 && magnitude > GAZE.enter2)
53
+ cell = 2;
54
+ if (cell === 2 && magnitude < GAZE.exit2)
55
+ cell = 1;
56
+ if (cell === 1 && magnitude < GAZE.exit1)
57
+ cell = 0;
58
+ if (cell === 0)
59
+ return 0;
60
+ return sign < 0 ? -cell : cell;
61
+ }
62
+ function stepGaze(gaze, target, dt) {
63
+ const x = springStep(gaze.x, target.x, dt);
64
+ const y = springStep(gaze.y, target.y, dt);
65
+ return {
66
+ x,
67
+ y,
68
+ cellX: nextCell(gaze.cellX, x.value, true),
69
+ cellY: lookCellY(nextCell(gaze.cellY, y.value, false))
70
+ };
71
+ }
72
+ function snapDue(lastAt, now) {
73
+ return now - lastAt >= GAZE.snapEveryS;
74
+ }
75
+ function snapGaze(gaze, target) {
76
+ const x = { value: target.x, velocity: 0 };
77
+ const y = { value: target.y, velocity: 0 };
78
+ return {
79
+ x,
80
+ y,
81
+ cellX: nextCell(gaze.cellX, x.value, true),
82
+ cellY: lookCellY(nextCell(gaze.cellY, y.value, false))
83
+ };
84
+ }
85
+ function towardFrom(at, rect) {
86
+ if (!at.moved)
87
+ return { x: 0, y: 0 };
88
+ const size = Math.max(1, rect.height);
89
+ const dx = (at.px - (rect.left + rect.width / 2)) / size;
90
+ const dy = (at.py - (rect.top + rect.height * 0.45)) / size;
91
+ const distance = Math.hypot(dx, dy);
92
+ if (distance < 0.0001)
93
+ return { x: 0, y: 0 };
94
+ const reach = Math.tanh(distance * 1.4) / distance;
95
+ const near = 1 - Math.min(1, Math.max(0, (distance - NEAR_FULL) / (NEAR_NONE - NEAR_FULL)));
96
+ return { x: dx * reach * near + 0, y: dy * reach * near + 0 };
97
+ }
98
+ var NEAR_FULL = 1.4;
99
+ var NEAR_NONE = 2.4;
100
+ export {
101
+ towardFrom,
102
+ stepGaze,
103
+ springStep,
104
+ spring,
105
+ snapGaze,
106
+ snapDue,
107
+ nextCell,
108
+ gazeTarget,
109
+ NO_GAZE,
110
+ NEAR_NONE,
111
+ NEAR_FULL,
112
+ GAZE
113
+ };
@@ -0,0 +1,3 @@
1
+ import { type WearKit, type WornPiece } from "./wear3d";
2
+ import type { HairKey } from "./wearables";
3
+ export declare function buildHair(key: HairKey, kit: WearKit): WornPiece;
package/dist/index.d.ts CHANGED
@@ -1,12 +1,19 @@
1
+ export type { BodyPresetId } from "./body-presets";
2
+ export { BODY_PRESETS } from "./body-presets";
3
+ export type { AuthoredClipName } from "./clips";
4
+ export { AUTHORED_BONES, AUTHORED_CLIP_NAMES, AUTHORED_CLIPS } from "./clips";
1
5
  export type { Emote } from "./emote";
2
6
  export { EMOTES, emoteOf } from "./emote";
3
7
  export type { NamedFace } from "./faces";
4
8
  export { FACE_STAMP_PALETTE, isNamedFace, NAMED_FACE_STAMPS, NAMED_FACES } from "./faces";
5
9
  export type { ClipName, ClipRef, CustomClip, Pose, Rotation } from "./pose";
6
10
  export { CLIPS, clipLift, customDuration, isCustomClip, mergePoses, resolvePose, sampleClip, } from "./pose";
11
+ export { createRagdoll, RAGDOLL_JOINTS, type Ragdoll, type RagdollMode } from "./ragdoll";
7
12
  export type { Bone, CanonicalBone, Rig, RigId, Vec3 } from "./rig";
8
13
  export { boneOf, RIGS } from "./rig";
9
14
  export type { FaceName, PartFaces, Rect } from "./skin";
10
15
  export { CLASSIC_BONES, CLASSIC_HEIGHT, CLASSIC_LEFT_LIMB, CLASSIC_RIGHT_LIMB, CLASSIC_TORSO, CLASSIC_WIDTH, classicFaceRect, validateClassicTemplate, } from "./skin";
11
- export type { BodyScale, BodyVariant, BoneSkin, CanonicalBox, CanonicalFootprint, CharacterLook, ClassicConversion, NativeMapping, NativePart, ScaledBone, SkinImage, VariantPart, VariantSheetCheck, VariantSheetFacts, VariantSheetProblem, } from "./skin-native";
12
- export { BODY_SCALE_LIMITS, boneSkin, CANONICAL_BODY_SCALE, CLASSIC_TO_NATIVE, canonicalFootprint, clampBodyScale, NATIVE_ARM_LEFT, NATIVE_ARM_RIGHT, NATIVE_BONES, NATIVE_HEAD, NATIVE_HEIGHT, NATIVE_LEG_LEFT, NATIVE_LEG_RIGHT, NATIVE_PARTS, NATIVE_PX_PER_STUD, NATIVE_SHEET_CAPS, NATIVE_TORSO, NATIVE_WIDTH, nativeFaceRect, nativePartOf, scaleBone, validateVariantSheet, visualEnvelope, } from "./skin-native";
16
+ export type { BodyScale, BodyVariant, BoneSkin, CanonicalBox, CanonicalFootprint, CharacterLook, ClassicConversion, NativeMapping, NativePart, PlupBody, ScaledBone, SkinImage, VariantPart, VariantSheetCheck, VariantSheetFacts, VariantSheetProblem, } from "./skin-native";
17
+ export { BODY_SCALE_LIMITS, boneSkin, CANONICAL_BODY_SCALE, CANONICAL_PLUP_BODY, CLASSIC_TO_NATIVE, canonicalFootprint, clampBodyScale, clampPlupBody, NATIVE_ARM_LEFT, NATIVE_ARM_RIGHT, NATIVE_BONES, NATIVE_HEAD, NATIVE_HEIGHT, NATIVE_LEG_LEFT, NATIVE_LEG_RIGHT, NATIVE_PARTS, NATIVE_PX_PER_STUD, NATIVE_SHEET_CAPS, NATIVE_TORSO, NATIVE_WIDTH, nativeFaceRect, nativePartOf, PLUP_BODY_LIMITS, scaleBone, validateVariantSheet, visualEnvelope, } from "./skin-native";
18
+ export type { WearKey } from "./wearables";
19
+ export { isWearKey, WEAR_KEYS, WEARABLES, wearableItems, wearKeyOf, wearKeysOf, wearSlotOf, wearView, } from "./wearables";