@plupin/character 0.3.0 → 0.4.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.
@@ -1,3 +1,129 @@
1
+ // src/body-presets.ts
2
+ var BODY_PRESETS = {
3
+ round: { name: "Round", shape: "plup", body: { figure: 0, headSize: 1 } },
4
+ curvy: {
5
+ name: "Curvy",
6
+ shape: "plup",
7
+ body: {
8
+ figure: 1,
9
+ headSize: 0.78,
10
+ shoulders: 0.86,
11
+ bust: 0.9,
12
+ waist: 0.54,
13
+ hips: 1.4,
14
+ legLength: 2.35,
15
+ armLength: 1.35,
16
+ muscle: 0.82
17
+ }
18
+ },
19
+ glam: {
20
+ name: "Hourglass",
21
+ shape: "plup",
22
+ body: {
23
+ figure: 1,
24
+ headSize: 0.74,
25
+ shoulders: 0.84,
26
+ bust: 1.32,
27
+ waist: 0.48,
28
+ hips: 1.54,
29
+ legLength: 2.55,
30
+ armLength: 1.38,
31
+ muscle: 0.8
32
+ }
33
+ },
34
+ ikemen: {
35
+ name: "Ikemen",
36
+ shape: "plup",
37
+ body: {
38
+ figure: 1,
39
+ headSize: 0.72,
40
+ shoulders: 1.28,
41
+ bust: 0,
42
+ waist: 0.74,
43
+ hips: 0.92,
44
+ legLength: 2.6,
45
+ armLength: 1.48,
46
+ muscle: 1.22
47
+ }
48
+ },
49
+ muscular: {
50
+ name: "Muscular",
51
+ shape: "plup",
52
+ body: {
53
+ figure: 1,
54
+ headSize: 0.7,
55
+ shoulders: 1.56,
56
+ bust: 0,
57
+ waist: 0.72,
58
+ hips: 0.96,
59
+ legLength: 2.25,
60
+ armLength: 1.52,
61
+ muscle: 2.15
62
+ }
63
+ },
64
+ "tall-slim": {
65
+ name: "Tall & Slim",
66
+ shape: "plup",
67
+ body: {
68
+ figure: 1,
69
+ headSize: 0.76,
70
+ shoulders: 0.9,
71
+ bust: 0.28,
72
+ waist: 0.66,
73
+ hips: 0.98,
74
+ legLength: 2.5,
75
+ armLength: 1.38,
76
+ muscle: 0.8
77
+ }
78
+ },
79
+ athletic: {
80
+ name: "Athletic",
81
+ shape: "plup",
82
+ body: {
83
+ figure: 1,
84
+ headSize: 0.75,
85
+ shoulders: 1.32,
86
+ bust: 0.12,
87
+ waist: 0.74,
88
+ hips: 1,
89
+ legLength: 2.3,
90
+ armLength: 1.44,
91
+ muscle: 1.55
92
+ }
93
+ },
94
+ chibi: {
95
+ name: "Chibi",
96
+ shape: "plup",
97
+ body: {
98
+ figure: 1,
99
+ headSize: 1.16,
100
+ shoulders: 0.78,
101
+ bust: 0.15,
102
+ waist: 0.84,
103
+ hips: 1.06,
104
+ legLength: 1.25,
105
+ armLength: 0.92,
106
+ muscle: 0.82
107
+ }
108
+ },
109
+ chubby: {
110
+ name: "Chubby",
111
+ shape: "wide",
112
+ body: {
113
+ figure: 0,
114
+ headSize: 1,
115
+ shoulders: 1,
116
+ waist: 1.15,
117
+ hips: 1.25,
118
+ legLength: 1,
119
+ armLength: 1,
120
+ muscle: 1.2
121
+ }
122
+ },
123
+ tiny: { name: "Tiny", shape: "mini", body: { figure: 0, headSize: 1 } },
124
+ bean: { name: "Bean", shape: "bean", body: { figure: 0, headSize: 1, legLength: 1.3 } }
125
+ };
126
+
1
127
  // src/emote.ts
2
128
  var EMOTES = [
3
129
  {
@@ -105,6 +231,54 @@ var EMOTES = [
105
231
  face: "serious",
106
232
  clip: "nod",
107
233
  sigmaPrice: 60
234
+ },
235
+ {
236
+ id: "emote-brazil-funk",
237
+ label: "Brazil Funk",
238
+ glyph: "♪(┌・。・)┌",
239
+ face: "cool",
240
+ clip: "brazil-funk",
241
+ sigmaPrice: 25
242
+ },
243
+ {
244
+ id: "emote-pacu-jalur",
245
+ label: "Pacu Jalur",
246
+ glyph: "ᕙ(•̀ᴗ•́)ᕗ",
247
+ face: "smug",
248
+ clip: "pacu-jalur",
249
+ sigmaPrice: 20
250
+ },
251
+ {
252
+ id: "emote-velocity",
253
+ label: "Jedag Jedug",
254
+ glyph: "✧(•̀ᴗ•́)✧",
255
+ face: "stars",
256
+ clip: "velocity",
257
+ sigmaPrice: 35
258
+ },
259
+ {
260
+ id: "emote-griddy",
261
+ label: "Griddy",
262
+ glyph: "(⌐■_■)ノ",
263
+ face: "smirk",
264
+ clip: "griddy",
265
+ sigmaPrice: 45
266
+ },
267
+ {
268
+ id: "emote-floss",
269
+ label: "Floss",
270
+ glyph: "ヾ(•̀_•́)ノ",
271
+ face: "sparkle",
272
+ clip: "floss",
273
+ sigmaPrice: 40
274
+ },
275
+ {
276
+ id: "emote-caramel",
277
+ label: "Idol Bounce",
278
+ glyph: "(♡˙︶˙♡)♪",
279
+ face: "sparkle",
280
+ clip: "caramel",
281
+ sigmaPrice: 55
108
282
  }
109
283
  ];
110
284
  function emoteOf(name) {
@@ -310,4 +484,4 @@ function createRagdoll(initial = "off", radius = 0.5) {
310
484
  }
311
485
  }
312
486
 
313
- export { EMOTES, emoteOf, RAGDOLL_JOINTS, createRagdoll };
487
+ export { BODY_PRESETS, EMOTES, emoteOf, RAGDOLL_JOINTS, createRagdoll };
@@ -0,0 +1,196 @@
1
+ // src/blob.ts
2
+ import { SphereGeometry } from "three";
3
+ var BLOB_RADIUS = { x: 0.6, y: 0.56, z: 0.58 };
4
+ var BLOB_HEIGHT = BLOB_RADIUS.y * (1 + 0.62 + (1 - 0.62) * 0.3);
5
+ var ROUND = { shoulders: 1, waist: 1, hips: 1, bust: 0, muscle: 1, figure: 0 };
6
+ var bump = (at, centre, spread) => Math.exp(-(((at - centre) / spread) ** 2));
7
+ var clamp01 = (v) => Math.max(0, Math.min(1, v));
8
+ var smoothstep = (e0, e1, x) => {
9
+ const t = clamp01((x - e0) / (e1 - e0));
10
+ return t * t * (3 - 2 * t);
11
+ };
12
+ function silhouetteAt(unitY, silhouette = ROUND) {
13
+ const shoulders = bump(unitY, -0.2, 0.2);
14
+ const waist = bump(unitY, -0.42, 0.12);
15
+ const hips = bump(unitY, -0.58, 0.14);
16
+ const rest = 0.35;
17
+ return (rest + shoulders * silhouette.shoulders + waist * silhouette.waist + hips * silhouette.hips) / (rest + shoulders + waist + hips);
18
+ }
19
+ var BLOB_SEAT = BLOB_RADIUS.y * (0.62 + (1 - 0.62) * 0.3);
20
+ function blobRadiusAt(y, silhouette = ROUND) {
21
+ const unit = Math.max(-0.62, Math.min(1, (y - BLOB_SEAT) / BLOB_RADIUS.y));
22
+ return Math.sqrt(Math.max(0, 1 - unit * unit)) * (1 + 0.16 * -unit) * BLOB_RADIUS.x * silhouetteAt(unit, silhouette);
23
+ }
24
+ function buildBlobGeometry(silhouette = ROUND) {
25
+ const geometry = new SphereGeometry(1, 44, 30);
26
+ const position = geometry.attributes.position;
27
+ let minY = Number.POSITIVE_INFINITY;
28
+ const bust = Math.max(0, silhouette.bust ?? 0);
29
+ for (let i = 0;i < position.count; i += 1) {
30
+ const ux = position.getX(i);
31
+ let y = position.getY(i);
32
+ const uz = position.getZ(i);
33
+ const spread = (1 + 0.16 * -y) * silhouetteAt(y, silhouette);
34
+ const rx = ux * spread * BLOB_RADIUS.x;
35
+ let rz = uz * spread * BLOB_RADIUS.z;
36
+ if (bust > 0 && uz > 0) {
37
+ const phi = Math.atan2(ux, uz);
38
+ const chestY = bump(y, -0.22, 0.18);
39
+ const twin = bump(Math.abs(phi), 0.38, 0.42);
40
+ rz += bust * 0.11 * chestY * twin * uz;
41
+ }
42
+ if (y < -0.62)
43
+ y = -0.62 + (y + 0.62) * 0.3;
44
+ position.setXYZ(i, rx, y * BLOB_RADIUS.y, rz);
45
+ minY = Math.min(minY, y * BLOB_RADIUS.y);
46
+ }
47
+ geometry.translate(0, -minY, 0);
48
+ geometry.computeBoundingBox();
49
+ geometry.computeVertexNormals();
50
+ return geometry;
51
+ }
52
+ var FIGURE_TORSO_MIN_Y = 0.04;
53
+ var FIGURE_TORSO_MAX_Y = 0.84;
54
+ var FIGURE_TORSO_CENTER_Y = (FIGURE_TORSO_MIN_Y + FIGURE_TORSO_MAX_Y) / 2;
55
+ var FIGURE_TORSO_HALF_H = (FIGURE_TORSO_MAX_Y - FIGURE_TORSO_MIN_Y) / 2;
56
+ var FIGURE_HEAD_BASE_SCALE = 0.46;
57
+ var FIGURE_NECK_TOP_Y = 0.8;
58
+ var FIGURE_SHOULDER_Y = 0.64;
59
+ var FIGURE_HIP_Y = 0.17;
60
+ function figureHeadMetrics(headSize = 0.78) {
61
+ const scale = FIGURE_HEAD_BASE_SCALE * headSize;
62
+ const originY = FIGURE_NECK_TOP_Y - 0.03 * scale;
63
+ return { scale, originY, centerY: originY + BLOB_SEAT * scale };
64
+ }
65
+ var smin = (a, b, k) => {
66
+ const h = clamp01(0.5 + 0.5 * (b - a) / k);
67
+ return b * (1 - h) + a * h - k * h * (1 - h);
68
+ };
69
+ function figureTorsoPoint(y, phi, silhouette = ROUND) {
70
+ const u = Math.max(-0.985, Math.min(0.985, (y - FIGURE_TORSO_CENTER_Y) / FIGURE_TORSO_HALF_H));
71
+ const ux = Math.sin(phi);
72
+ const uz = Math.cos(phi);
73
+ const sh = silhouette.shoulders ?? 1;
74
+ const wa = silhouette.waist ?? 1;
75
+ const hi = silhouette.hips ?? 1;
76
+ const bust = Math.max(0, silhouette.bust ?? 0);
77
+ const muscle = Math.max(0.7, silhouette.muscle ?? 1);
78
+ const mExtra = Math.max(0, muscle - 1.05);
79
+ const neckT = smoothstep(0.68, 0.92, u);
80
+ const shoulderW = bump(u, 0.56, 0.28);
81
+ const ribW = bump(u, 0.28, 0.26);
82
+ const waistW = bump(u, -0.06, 0.25);
83
+ const hipW = bump(u, -0.58, 0.36);
84
+ const pelvisRound = u < -0.74 ? Math.sqrt(clamp01((1 + u) / 0.26)) : 1;
85
+ const neckRx = 0.068 + mExtra * 0.036;
86
+ const shoulderRx = 0.205 * sh + mExtra * 0.04;
87
+ const ribRx = 0.165 * (0.52 + 0.48 * sh) + mExtra * 0.025;
88
+ const waistRx = 0.175 * wa;
89
+ const hipRx = 0.205 * hi;
90
+ const wSum = shoulderW + ribW + waistW + hipW + 0.08;
91
+ let rx = (shoulderW * shoulderRx + ribW * ribRx + waistW * waistRx + hipW * hipRx + 0.08 * 0.14) / wSum;
92
+ rx = rx * (1 - neckT) + neckRx * neckT;
93
+ rx *= pelvisRound;
94
+ const neckRz = 0.066 + mExtra * 0.024;
95
+ const shoulderRz = 0.13 + mExtra * 0.032;
96
+ const ribRz = 0.132 + mExtra * 0.024;
97
+ const waistRz = 0.122 * Math.min(1, wa * 0.88 + 0.1);
98
+ const hipRz = 0.155 * (0.5 + 0.5 * hi);
99
+ let rz = (shoulderW * shoulderRz + ribW * ribRz + waistW * waistRz + hipW * hipRz + 0.08 * 0.12) / wSum;
100
+ rz = rz * (1 - neckT) + neckRz * neckT;
101
+ rz *= pelvisRound;
102
+ let x = ux * rx;
103
+ let z = uz * rz;
104
+ if (bust > 0.01 && uz > -0.1) {
105
+ const domeR = 0.095 + Math.min(1.4, bust) * 0.038;
106
+ const cx = 0.082 + Math.min(1.4, bust) * 0.01;
107
+ const cy = FIGURE_TORSO_CENTER_Y + 0.34 * FIGURE_TORSO_HALF_H;
108
+ const cz = 0.075 + Math.min(1.4, bust) * 0.024;
109
+ const bx = Math.abs(x) - cx;
110
+ const by = (y - cy) * 1.05;
111
+ const d2 = bx * bx + by * by;
112
+ if (d2 < domeR * domeR * 1.45) {
113
+ const inner = Math.max(0, domeR * domeR - d2);
114
+ const sphereZ = cz + Math.sqrt(inner) * (0.95 + Math.min(1.4, bust) * 0.25);
115
+ const edgeFade = smoothstep(domeR * 1.2, domeR * 0.45, Math.sqrt(d2)) * smoothstep(-0.05, 0.28, uz);
116
+ const targetZ = -smin(-z, -sphereZ, 0.035);
117
+ z = z + (targetZ - z) * edgeFade;
118
+ if (Math.abs(x) > cx * 0.5) {
119
+ x += Math.sign(x) * 0.022 * Math.min(1.4, bust) * edgeFade;
120
+ }
121
+ }
122
+ }
123
+ if (mExtra > 0.05) {
124
+ if (uz > 0) {
125
+ const pecVert = bump(u, 0.42, 0.22);
126
+ const pecWidth = Math.max(0, uz) ** 0.7 * (1 - 0.25 * bump(Math.abs(phi), 0, 0.16));
127
+ z += mExtra * 0.068 * pecVert * pecWidth;
128
+ const coreVert = bump(u, 0, 0.24);
129
+ z += mExtra * 0.02 * coreVert * Math.max(0, uz) ** 0.8;
130
+ }
131
+ const latVert = bump(u, 0.42, 0.25);
132
+ x += Math.sign(ux) * mExtra * 0.038 * latVert * Math.abs(ux);
133
+ }
134
+ const hipExtra = Math.max(0, hi - 0.94);
135
+ if (hipExtra > 0.01 && uz < 0.1) {
136
+ const gluteVert = bump(u, -0.58, 0.3);
137
+ const backFactor = smoothstep(0.1, -0.45, uz);
138
+ const gluteTwin = 0.65 + 0.35 * bump(Math.abs(Math.PI - Math.abs(phi)), 0.42, 0.52);
139
+ z -= hipExtra * 0.115 * gluteVert * gluteTwin * backFactor * pelvisRound;
140
+ }
141
+ return { x, z };
142
+ }
143
+ function figureTorsoRadiusAt(y, silhouette = ROUND, phi = Math.PI / 2) {
144
+ const p = figureTorsoPoint(y, phi, silhouette);
145
+ return Math.hypot(p.x, p.z);
146
+ }
147
+ function buildFigureHeadGeometry() {
148
+ const geometry = new SphereGeometry(1, 48, 32);
149
+ const position = geometry.attributes.position;
150
+ let minY = Number.POSITIVE_INFINITY;
151
+ for (let i = 0;i < position.count; i += 1) {
152
+ const ux = position.getX(i);
153
+ let y = position.getY(i);
154
+ const uz = position.getZ(i);
155
+ const cheek = 1 + 0.035 * bump(y, -0.22, 0.32);
156
+ const chinTaper = y < -0.2 ? 1 - 0.28 * clamp01((-0.2 - y) / 0.8) ** 1.3 : 1;
157
+ const chinForward = y < -0.35 && uz > 0 ? 0.035 * clamp01((-0.35 - y) / 0.65) * uz : 0;
158
+ if (y < -0.82)
159
+ y = -0.82 + (y + 0.82) * 0.5;
160
+ const rx = ux * cheek * chinTaper * 0.54;
161
+ const ry = y * 0.59;
162
+ const rz = (uz * cheek * chinTaper + chinForward) * 0.54;
163
+ position.setXYZ(i, rx, ry, rz);
164
+ minY = Math.min(minY, ry);
165
+ }
166
+ geometry.translate(0, -minY, 0);
167
+ geometry.computeBoundingBox();
168
+ geometry.computeVertexNormals();
169
+ return geometry;
170
+ }
171
+ function figureHeadRadiusAt(y) {
172
+ const minY = (-0.82 + -0.18 * 0.5) * 0.59;
173
+ const rawY = y + minY;
174
+ const unit = Math.max(-0.98, Math.min(0.995, rawY / 0.59));
175
+ const cheek = 1 + 0.035 * bump(unit, -0.22, 0.32);
176
+ const chinTaper = unit < -0.2 ? 1 - 0.28 * clamp01((-0.2 - unit) / 0.8) ** 1.3 : 1;
177
+ return Math.sqrt(Math.max(0.001, 1 - unit * unit)) * cheek * chinTaper * 0.54;
178
+ }
179
+ function buildFigureTorsoGeometry(silhouette = ROUND) {
180
+ const geometry = new SphereGeometry(1, 56, 44);
181
+ const position = geometry.attributes.position;
182
+ for (let i = 0;i < position.count; i += 1) {
183
+ const ux = position.getX(i);
184
+ const uy = position.getY(i);
185
+ const uz = position.getZ(i);
186
+ const y = FIGURE_TORSO_CENTER_Y + uy * FIGURE_TORSO_HALF_H;
187
+ const phi = Math.atan2(ux, uz);
188
+ const pt = figureTorsoPoint(y, phi, silhouette);
189
+ position.setXYZ(i, pt.x, y, pt.z);
190
+ }
191
+ geometry.computeBoundingBox();
192
+ geometry.computeVertexNormals();
193
+ return geometry;
194
+ }
195
+
196
+ export { BLOB_RADIUS, BLOB_HEIGHT, ROUND, silhouetteAt, BLOB_SEAT, blobRadiusAt, buildBlobGeometry, FIGURE_TORSO_MIN_Y, FIGURE_TORSO_MAX_Y, FIGURE_TORSO_CENTER_Y, FIGURE_TORSO_HALF_H, FIGURE_HEAD_BASE_SCALE, FIGURE_NECK_TOP_Y, FIGURE_SHOULDER_Y, FIGURE_HIP_Y, figureHeadMetrics, figureTorsoPoint, figureTorsoRadiusAt, buildFigureHeadGeometry, figureHeadRadiusAt, buildFigureTorsoGeometry };
package/dist/clips.d.ts CHANGED
@@ -20,7 +20,7 @@ import type { CanonicalBone } from "./rig";
20
20
  */
21
21
  export declare const AUTHORED_BONES: readonly CanonicalBone[];
22
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"];
23
+ export declare const AUTHORED_CLIP_NAMES: readonly ["recoil", "flail", "topple", "collapse", "sneak", "cheer", "laugh", "pose", "rage", "sob", "nod", "brazil-funk", "pacu-jalur", "velocity", "griddy", "floss", "caramel"];
24
24
  export type AuthoredClipName = (typeof AUTHORED_CLIP_NAMES)[number];
25
25
  /**
26
26
  * The keyed library. Each entry is a motion a viewer can name from the pose alone:
package/dist/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import {
2
+ BODY_PRESETS,
2
3
  EMOTES,
3
4
  RAGDOLL_JOINTS,
4
5
  createRagdoll,
5
6
  emoteOf
6
- } from "./chunk-yd5zzkkg.js";
7
+ } from "./chunk-rqenm9tn.js";
7
8
  import {
8
9
  WEARABLES,
9
10
  WEAR_KEYS,
@@ -13,7 +14,7 @@ import {
13
14
  wearSlotOf,
14
15
  wearView,
15
16
  wearableItems
16
- } from "./chunk-60p135hw.js";
17
+ } from "./chunk-kf7f1tdx.js";
17
18
  import {
18
19
  BODY_SCALE_LIMITS,
19
20
  CANONICAL_BODY_SCALE,
@@ -49,7 +50,7 @@ import {
49
50
  validateClassicTemplate,
50
51
  validateVariantSheet,
51
52
  visualEnvelope
52
- } from "./chunk-sa2r1cxz.js";
53
+ } from "./chunk-ew73g2v7.js";
53
54
  import {
54
55
  AUTHORED_BONES,
55
56
  AUTHORED_CLIPS,
@@ -63,52 +64,13 @@ import {
63
64
  mergePoses,
64
65
  resolvePose,
65
66
  sampleClip
66
- } from "./chunk-g1c0wdcj.js";
67
+ } from "./chunk-7ry0n8cw.js";
67
68
  import {
68
69
  FACE_STAMP_PALETTE,
69
70
  NAMED_FACES,
70
71
  NAMED_FACE_STAMPS,
71
72
  isNamedFace
72
73
  } from "./chunk-aa5nstet.js";
73
-
74
- // src/body-presets.ts
75
- var BODY_PRESETS = {
76
- round: { name: "Round", shape: "plup", body: {} },
77
- "tall-slim": {
78
- name: "Tall & Slim",
79
- shape: "tall",
80
- body: { shoulders: 0.9, waist: 0.84, hips: 0.9, legLength: 2.6, armLength: 1.4, muscle: 0.78 }
81
- },
82
- athletic: {
83
- name: "Athletic",
84
- shape: "tall",
85
- body: { shoulders: 1.2, waist: 0.84, hips: 0.95, legLength: 2.1, armLength: 1.3, muscle: 1.35 }
86
- },
87
- muscular: {
88
- name: "Muscular",
89
- shape: "tall",
90
- body: {
91
- shoulders: 1.32,
92
- waist: 0.82,
93
- hips: 0.88,
94
- legLength: 1.7,
95
- armLength: 1.25,
96
- muscle: 1.9
97
- }
98
- },
99
- curvy: {
100
- name: "Curvy",
101
- shape: "tall",
102
- body: { shoulders: 0.9, waist: 0.66, hips: 1.32, legLength: 2.4, armLength: 1.3, muscle: 0.85 }
103
- },
104
- chubby: {
105
- name: "Chubby",
106
- shape: "wide",
107
- body: { shoulders: 1, waist: 1.15, hips: 1.25, legLength: 1, armLength: 1, muscle: 1.2 }
108
- },
109
- tiny: { name: "Tiny", shape: "mini", body: {} },
110
- bean: { name: "Bean", shape: "bean", body: { legLength: 1.3 } }
111
- };
112
74
  export {
113
75
  wearableItems,
114
76
  wearView,
package/dist/listing.js CHANGED
@@ -7,10 +7,10 @@ import {
7
7
  NATIVE_SHEET_CAPS,
8
8
  NATIVE_TORSO,
9
9
  clampBodyScale
10
- } from "./chunk-sa2r1cxz.js";
10
+ } from "./chunk-ew73g2v7.js";
11
11
  import {
12
12
  CLIPS
13
- } from "./chunk-g1c0wdcj.js";
13
+ } from "./chunk-7ry0n8cw.js";
14
14
  import {
15
15
  FACE_STAMP_PALETTE,
16
16
  NAMED_FACES,
@@ -19,7 +19,7 @@ import {
19
19
  } from "./chunk-aa5nstet.js";
20
20
 
21
21
  // src/png.ts
22
- import { unzlibSync, zlibSync } from "fflate";
22
+ import { Unzlib, zlibSync } from "fflate";
23
23
  var MAX_PIXELS = 4000000;
24
24
  var SIGNATURE = [137, 80, 78, 71, 13, 10, 26, 10];
25
25
  var CHANNELS = { 0: 1, 2: 3, 4: 2, 6: 4 };
@@ -115,6 +115,37 @@ function unfilter(raw, width, height, channels) {
115
115
  }
116
116
  return out;
117
117
  }
118
+ var INFLATE_INPUT_CHUNK = 512;
119
+ var INFLATE_OVERFLOW = new Error("zlib output cap exceeded");
120
+ function unzlibBounded(compressed, maxBytes) {
121
+ if (compressed.length < 6)
122
+ return null;
123
+ const bodyEnd = compressed.length - 4;
124
+ const output = [];
125
+ let total = 0;
126
+ const stream = new Unzlib((data) => {
127
+ total += data.length;
128
+ if (total > maxBytes)
129
+ throw INFLATE_OVERFLOW;
130
+ if (data.length > 0)
131
+ output.push(data);
132
+ });
133
+ try {
134
+ for (let at2 = 0;at2 < bodyEnd; at2 += INFLATE_INPUT_CHUNK) {
135
+ stream.push(compressed.subarray(at2, Math.min(at2 + INFLATE_INPUT_CHUNK, bodyEnd)), false);
136
+ }
137
+ stream.push(compressed.subarray(bodyEnd), true);
138
+ } catch {
139
+ return null;
140
+ }
141
+ const raw = new Uint8Array(total);
142
+ let at = 0;
143
+ for (const part of output) {
144
+ raw.set(part, at);
145
+ at += part.length;
146
+ }
147
+ return raw;
148
+ }
118
149
  function decodePng(bytes) {
119
150
  const header = readPngHeader(bytes);
120
151
  if (!header.ok)
@@ -141,13 +172,9 @@ function decodePng(bytes) {
141
172
  compressed.set(part, offset);
142
173
  offset += part.length;
143
174
  }
144
- let raw;
145
- try {
146
- raw = unzlibSync(compressed);
147
- } catch {
148
- return { ok: false, reason: "corrupt" };
149
- }
150
- if (raw.length < (width * channels + 1) * height)
175
+ const expected = (width * channels + 1) * height;
176
+ const raw = unzlibBounded(compressed, expected + 1024);
177
+ if (!raw || raw.length < expected)
151
178
  return { ok: false, reason: "corrupt" };
152
179
  const pixels = unfilter(raw, width, height, channels);
153
180
  if (!pixels)
@@ -603,10 +630,9 @@ function drawnFace(assetConfig) {
603
630
  }
604
631
  function namedFace(assetConfig) {
605
632
  const face = assetConfig.face;
606
- if (typeof face !== "string")
633
+ if (typeof face !== "string" || !Object.hasOwn(NAMED_FACE_STAMPS, face))
607
634
  return null;
608
- const rows = NAMED_FACE_STAMPS[face];
609
- return rows ?? null;
635
+ return NAMED_FACE_STAMPS[face] ?? null;
610
636
  }
611
637
  function escapeXml(value) {
612
638
  return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&apos;");
package/dist/plup3d.d.ts CHANGED
@@ -7,17 +7,12 @@ import { BODY_SHAPES, type BodyShapeId } from "./skin-map";
7
7
  import { type BodyScale, type PlupBody } from "./skin-native";
8
8
  import { type WearKey } from "./wearables";
9
9
  /**
10
- * Plup in three.js: the round mascot the lobby shows, as a plain scene object any game can add.
11
- *
12
- * What makes it Plup and not a box: a bottom-heavy blob body wearing a 48 x 24 pixel map (sampled
13
- * with no filtering, so the pixels stay pixels), a hard-banded toon shader with a rim, a dark ink
14
- * outline and a neon edge from inverted hulls, rubber stub arms with round hands, flat round feet and
15
- * a face stamped from the same named faces the films and the emotes use. Poses come from the same
16
- * clips as every rig (a built-in, an emote's keyframes, a CC0 bake), so one animation moves it.
17
- *
18
- * Feet stand at y = 0, it faces +z, and the body is about 1.1 units tall: scale the group to taste.
10
+ * Plup in three.js: supports both the classic round toon mascot (`figure = 0`) and the stylized
11
+ * anime/Roblox-proportioned figure (`figure = 1`) with a sleek customizable head (`headSize`),
12
+ * slender neck, and sculpted directional torso (bust/chest, pinched waist, curvy hips, or broad
13
+ * V-taper muscular shoulders & arms). Both modes share the same animation clips, wearables, hair,
14
+ * anime/ikemen faces, and optional active ragdoll.
19
15
  */
20
- /** The expressions a face rule shows (the 8 x 4 stamp is built by `faceStamp` in skin-map, shared with the app). */
21
16
  export type Expression = "idle" | "blink" | "happy" | "surprised" | "sad" | "wee";
22
17
  export type PlupFace = NamedFace | Expression;
23
18
  export type { BodyShapeId, FaceType } from "./skin-map";
@@ -25,95 +20,51 @@ export { BODY_SHAPES };
25
20
  export interface ToonOptions {
26
21
  map?: Texture;
27
22
  color?: string;
28
- /** Seen from both sides (an open shell). */
29
23
  double?: boolean;
30
- /** The inside's colour, for a lined cape; the outside's by default. */
31
24
  back?: string;
32
- /** How many times the map repeats across the surface. */
33
25
  repeat?: readonly [number, number];
34
- /** 0 cloth, ~0.5 satin, ~0.8 metal and glass. */
35
26
  sheen?: number;
36
- /** Anime hair: the skull's centre the shading wraps round, and how strong its angel ring is. */
37
27
  anime?: {
38
28
  center: readonly [number, number, number];
39
29
  ring?: number;
40
- /** The colour the hair runs to at the tips. */
41
30
  tip?: string;
42
- /** The underside of a lock, seen where it twists. */
43
31
  inner?: string;
44
32
  };
45
33
  }
46
34
  export declare function toon(options: ToonOptions): ShaderMaterial;
47
- /** A player's drawn skin: 24 rows of 48 palette letters and the face type they chose. */
48
35
  export interface PlupSkin {
49
36
  body: readonly string[];
50
37
  faceType?: string;
51
38
  }
52
39
  export interface PlupOptions {
53
- /** The body colour. Default Plup blue. */
54
40
  color?: string;
55
- /** A named face or an expression. Default `smug`. */
56
41
  face?: PlupFace;
57
- /** The player's own pixel skin (the platform's look). Without one the default Plup is drawn. */
58
42
  skin?: PlupSkin;
59
- /** The face type (dot, sparkle, sleepy, derp, anime) when no drawn skin is given. Default dot. */
43
+ /** The face type (`dot`, `sparkle`, `sleepy`, `derp`, `anime`, `ikemen`). Default `dot`. */
60
44
  faceType?: string;
61
- /** The iris colour of the anime face. Default violet. */
45
+ /** The iris colour of `anime` or `ikemen` eyes. */
62
46
  eyeColor?: string;
63
- /** The body proportions the player picked. Default `plup`. */
47
+ /** Optional hair colour override (derives matching tip/inner shades automatically). */
48
+ hairColor?: string;
64
49
  shape?: BodyShapeId;
65
- /**
66
- * An unusual body: stature, how thick the belly, arms and legs are, how big the head. The clips keep their
67
- * angles and adapt (arms clear a wide belly, a heavy body jumps lower), see `plupProportions`.
68
- */
69
50
  bodyScale?: Partial<BodyScale> | null;
70
- /** A soft contact shadow under the feet. Default true. */
71
51
  shadow?: boolean;
72
- /**
73
- * A body of a different shape. The 48 x 24 pixel map, the blob and the stub limbs are only the
74
- * default Plup: pass any scene object (a glTF scene, a hand-built mesh) and it is posed instead.
75
- * Nodes named `armL`, `armR`, `legL`, `legR` follow the clips; a model with none still gets the
76
- * clip's lift and sway, so any animation plays on any shape.
77
- */
78
52
  model?: Object3D;
79
- /**
80
- * The outline and limbs: broad shoulders, a pinched waist, full hips, long legs, thick arms. With
81
- * `shape` and `bodyScale` this is how a muscular, a curvy or a tall-and-slim Plup is made; see
82
- * `BODY_PRESETS`. Everything it wears is fitted to it.
83
- */
84
53
  body?: Partial<PlupBody> | null;
85
- /** What it has on: real 3D pieces (`WEARABLES`), hair, headwear and clothes at once. */
86
54
  wear?: readonly WearKey[];
87
- /**
88
- * A floppy body (see `ragdoll.ts`): `wobbly` limbs lag and overshoot like Human: Fall Flat, `limp`
89
- * falls over. Default `off`: the clip is played exactly. A game can switch it any time with `ragdoll`.
90
- */
91
55
  ragdoll?: RagdollMode;
92
56
  }
93
57
  export interface PlupHandle {
94
- /** Add this to a scene. Feet at y = 0, facing +z, about 1.1 units tall. */
95
58
  object: Group;
96
- /** Set the current clip (a name or keyframes). Call `update` every frame. */
97
59
  play: (clip: ClipRef) => void;
98
- /** Play an emote by name and pull its face. Returns it so the game can show its glyph. */
99
60
  emote: (name: string, custom?: Emote) => Emote | undefined;
100
- /** Hold a joint on top of the clip, e.g. `{ armR: { x: -1.2 } }`. Pass `{}` to let go. */
101
61
  pose: (pose: Pose) => void;
102
- /** A joint to attach things to (`armR`, `armL`, `legR`, `legL`) or the lifted body (`body`). */
103
62
  bone: (name: string) => Object3D | undefined;
104
63
  setFace: (face: PlupFace) => void;
105
- /** Switch the floppy body: `off`, `wobbly` (active ragdoll) or `limp` (falls over). */
106
64
  ragdoll: (mode: RagdollMode) => void;
107
- /**
108
- * Shove it, in world units per second. A small push makes a wobbly body stagger; a big one (over about
109
- * 2.5) knocks any body over. A body knocked over while `off` stays down until `ragdoll("off")`; a
110
- * wobbly one gets back up by itself.
111
- */
112
65
  push: (x: number, y: number, z: number) => void;
113
- /** Lying on the ground after a fall. */
114
66
  isDown: () => boolean;
115
67
  setColor: (color: string) => void;
116
- /** Put these on (and take off anything else). */
117
68
  setWear: (wear: readonly WearKey[]) => void;
118
69
  update: (deltaSeconds: number) => void;
119
70
  dispose: () => void;