@plupin/character 0.0.0-stage → 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 (53) 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.d.ts +79 -0
  7. package/dist/canvas.js +315 -0
  8. package/dist/chunk-09c5tps4.js +337 -0
  9. package/dist/chunk-60p135hw.js +103 -0
  10. package/dist/chunk-aa5nstet.js +39 -0
  11. package/dist/chunk-dpb0rnw9.js +37 -0
  12. package/dist/chunk-g1c0wdcj.js +825 -0
  13. package/dist/chunk-kber92gm.js +415 -0
  14. package/dist/chunk-sa2r1cxz.js +342 -0
  15. package/dist/chunk-yd5zzkkg.js +313 -0
  16. package/dist/clip-bake.d.ts +48 -0
  17. package/dist/clip-bake.js +132 -0
  18. package/dist/clips.d.ts +40 -0
  19. package/dist/dress.d.ts +4 -0
  20. package/dist/emote.d.ts +25 -0
  21. package/dist/faces.d.ts +10 -0
  22. package/dist/faces.js +12 -0
  23. package/dist/gaze.d.ts +81 -0
  24. package/dist/gaze.js +113 -0
  25. package/dist/hair3d.d.ts +3 -0
  26. package/dist/index.d.ts +19 -0
  27. package/dist/index.js +176 -0
  28. package/dist/listing.d.ts +195 -0
  29. package/dist/listing.js +763 -0
  30. package/dist/named-faces.d.ts +22 -0
  31. package/dist/platform-body-data.d.ts +9 -0
  32. package/dist/platform-body.d.ts +91 -0
  33. package/dist/plup2d.d.ts +29 -0
  34. package/dist/plup3d.d.ts +121 -0
  35. package/dist/png.d.ts +78 -0
  36. package/dist/pose.d.ts +49 -0
  37. package/dist/pose.js +18 -0
  38. package/dist/proportions.d.ts +31 -0
  39. package/dist/ragdoll.d.ts +51 -0
  40. package/dist/resolution.d.ts +21 -0
  41. package/dist/rig.d.ts +29 -0
  42. package/dist/skin-map.d.ts +155 -0
  43. package/dist/skin-map.js +55 -0
  44. package/dist/skin-native.d.ts +301 -0
  45. package/dist/skin.d.ts +35 -0
  46. package/dist/texture.d.ts +8 -0
  47. package/dist/three.d.ts +25 -0
  48. package/dist/three.js +2302 -0
  49. package/dist/wear3d.d.ts +99 -0
  50. package/dist/wearables.d.ts +203 -0
  51. package/dist/wearables.js +26 -0
  52. package/package.json +78 -4
  53. package/README.md +0 -3
@@ -0,0 +1,342 @@
1
+ import {
2
+ RIGS
3
+ } from "./chunk-g1c0wdcj.js";
4
+
5
+ // src/skin.ts
6
+ var rect = (x, y, w, h) => ({ x, y, w, h });
7
+ var CLASSIC_WIDTH = 585;
8
+ var CLASSIC_HEIGHT = 559;
9
+ var CLASSIC_TORSO = {
10
+ up: rect(231, 8, 128, 64),
11
+ front: rect(231, 74, 128, 128),
12
+ down: rect(231, 204, 128, 64),
13
+ left: rect(361, 74, 64, 128),
14
+ right: rect(165, 74, 64, 128),
15
+ back: rect(427, 74, 128, 128)
16
+ };
17
+ var CLASSIC_RIGHT_LIMB = {
18
+ left: rect(19, 355, 64, 128),
19
+ back: rect(85, 355, 64, 128),
20
+ right: rect(151, 355, 64, 128),
21
+ front: rect(217, 355, 64, 128),
22
+ up: rect(217, 289, 64, 64),
23
+ down: rect(217, 485, 64, 64)
24
+ };
25
+ var CLASSIC_LEFT_LIMB = {
26
+ front: rect(308, 355, 64, 128),
27
+ left: rect(374, 355, 64, 128),
28
+ back: rect(440, 355, 64, 128),
29
+ right: rect(506, 355, 64, 128),
30
+ up: rect(308, 289, 64, 64),
31
+ down: rect(308, 485, 64, 64)
32
+ };
33
+ var CLASSIC_BONES = {
34
+ Torso: { sheet: "shirt", faces: CLASSIC_TORSO },
35
+ LeftArm: { sheet: "shirt", faces: CLASSIC_LEFT_LIMB },
36
+ RightArm: { sheet: "shirt", faces: CLASSIC_RIGHT_LIMB },
37
+ LeftLeg: { sheet: "pants", faces: CLASSIC_LEFT_LIMB },
38
+ RightLeg: { sheet: "pants", faces: CLASSIC_RIGHT_LIMB },
39
+ UpperTorso: { sheet: "shirt", faces: CLASSIC_TORSO, slice: [0, 0.8] },
40
+ LowerTorso: { sheet: "pants", faces: CLASSIC_TORSO, slice: [0.8, 1] },
41
+ LeftUpperArm: { sheet: "shirt", faces: CLASSIC_LEFT_LIMB, slice: [0, 0.5] },
42
+ LeftLowerArm: { sheet: "shirt", faces: CLASSIC_LEFT_LIMB, slice: [0.5, 0.9] },
43
+ LeftHand: { sheet: "shirt", faces: CLASSIC_LEFT_LIMB, slice: [0.9, 1] },
44
+ RightUpperArm: { sheet: "shirt", faces: CLASSIC_RIGHT_LIMB, slice: [0, 0.5] },
45
+ RightLowerArm: { sheet: "shirt", faces: CLASSIC_RIGHT_LIMB, slice: [0.5, 0.9] },
46
+ RightHand: { sheet: "shirt", faces: CLASSIC_RIGHT_LIMB, slice: [0.9, 1] },
47
+ LeftUpperLeg: { sheet: "pants", faces: CLASSIC_LEFT_LIMB, slice: [0, 0.45] },
48
+ LeftLowerLeg: { sheet: "pants", faces: CLASSIC_LEFT_LIMB, slice: [0.45, 0.9] },
49
+ LeftFoot: { sheet: "pants", faces: CLASSIC_LEFT_LIMB, slice: [0.9, 1] },
50
+ RightUpperLeg: { sheet: "pants", faces: CLASSIC_RIGHT_LIMB, slice: [0, 0.45] },
51
+ RightLowerLeg: { sheet: "pants", faces: CLASSIC_RIGHT_LIMB, slice: [0.45, 0.9] },
52
+ RightFoot: { sheet: "pants", faces: CLASSIC_RIGHT_LIMB, slice: [0.9, 1] }
53
+ };
54
+ function classicFaceRect(bone, face) {
55
+ const mapping = CLASSIC_BONES[bone];
56
+ if (!mapping)
57
+ return null;
58
+ const base = mapping.faces[face];
59
+ const slice = mapping.slice;
60
+ if (!slice)
61
+ return base;
62
+ const [from, to] = slice;
63
+ if (face === "up")
64
+ return from === 0 ? base : null;
65
+ if (face === "down")
66
+ return to === 1 ? base : null;
67
+ return rect(base.x, base.y + base.h * from, base.w, base.h * (to - from));
68
+ }
69
+ function validateClassicTemplate(width, height) {
70
+ return width === CLASSIC_WIDTH && height === CLASSIC_HEIGHT ? { ok: true } : { ok: false, reason: "wrong_size" };
71
+ }
72
+
73
+ // src/skin-native.ts
74
+ var NATIVE_PX_PER_STUD = 32;
75
+ var NATIVE_WIDTH = 512;
76
+ var NATIVE_HEIGHT = 256;
77
+ var rect2 = (x, y, w, h) => ({ x, y, w, h });
78
+ var NATIVE_TORSO = {
79
+ up: rect2(32, 0, 64, 32),
80
+ left: rect2(0, 32, 32, 64),
81
+ front: rect2(32, 32, 64, 64),
82
+ right: rect2(96, 32, 32, 64),
83
+ back: rect2(128, 32, 64, 64),
84
+ down: rect2(32, 96, 64, 32)
85
+ };
86
+ var NATIVE_HEAD = {
87
+ up: rect2(224, 0, 64, 32),
88
+ left: rect2(192, 32, 32, 32),
89
+ front: rect2(224, 32, 64, 32),
90
+ right: rect2(288, 32, 32, 32),
91
+ back: rect2(320, 32, 64, 32),
92
+ down: rect2(224, 64, 64, 32)
93
+ };
94
+ var NATIVE_ARM_LEFT = {
95
+ up: rect2(32, 128, 32, 32),
96
+ left: rect2(0, 160, 32, 64),
97
+ front: rect2(32, 160, 32, 64),
98
+ right: rect2(64, 160, 32, 64),
99
+ back: rect2(96, 160, 32, 64),
100
+ down: rect2(32, 224, 32, 32)
101
+ };
102
+ var NATIVE_ARM_RIGHT = {
103
+ up: rect2(160, 128, 32, 32),
104
+ left: rect2(128, 160, 32, 64),
105
+ front: rect2(160, 160, 32, 64),
106
+ right: rect2(192, 160, 32, 64),
107
+ back: rect2(224, 160, 32, 64),
108
+ down: rect2(160, 224, 32, 32)
109
+ };
110
+ var NATIVE_LEG_LEFT = {
111
+ up: rect2(288, 128, 32, 32),
112
+ left: rect2(256, 160, 32, 64),
113
+ front: rect2(288, 160, 32, 64),
114
+ right: rect2(320, 160, 32, 64),
115
+ back: rect2(352, 160, 32, 64),
116
+ down: rect2(288, 224, 32, 32)
117
+ };
118
+ var NATIVE_LEG_RIGHT = {
119
+ up: rect2(416, 128, 32, 32),
120
+ left: rect2(384, 160, 32, 64),
121
+ front: rect2(416, 160, 32, 64),
122
+ right: rect2(448, 160, 32, 64),
123
+ back: rect2(480, 160, 32, 64),
124
+ down: rect2(416, 224, 32, 32)
125
+ };
126
+ var NATIVE_PARTS = {
127
+ torso: { block: rect2(0, 0, 192, 128), studs: [2, 2, 1], faces: NATIVE_TORSO },
128
+ head: { block: rect2(192, 0, 192, 96), studs: [2, 1, 1], faces: NATIVE_HEAD },
129
+ armL: { block: rect2(0, 128, 128, 128), studs: [1, 2, 1], faces: NATIVE_ARM_LEFT },
130
+ armR: { block: rect2(128, 128, 128, 128), studs: [1, 2, 1], faces: NATIVE_ARM_RIGHT },
131
+ legL: { block: rect2(256, 128, 128, 128), studs: [1, 2, 1], faces: NATIVE_LEG_LEFT },
132
+ legR: { block: rect2(384, 128, 128, 128), studs: [1, 2, 1], faces: NATIVE_LEG_RIGHT }
133
+ };
134
+ var NATIVE_BONES = {
135
+ Torso: { part: "torso" },
136
+ Head: { part: "head" },
137
+ Body: { part: "torso" },
138
+ LeftArm: { part: "armL" },
139
+ RightArm: { part: "armR" },
140
+ LeftLeg: { part: "legL" },
141
+ RightLeg: { part: "legR" },
142
+ UpperTorso: { part: "torso", slice: [0, 0.8] },
143
+ LowerTorso: { part: "torso", slice: [0.8, 1] },
144
+ LeftUpperArm: { part: "armL", slice: [0, 0.5] },
145
+ LeftLowerArm: { part: "armL", slice: [0.5, 0.9] },
146
+ LeftHand: { part: "armL", slice: [0.9, 1] },
147
+ RightUpperArm: { part: "armR", slice: [0, 0.5] },
148
+ RightLowerArm: { part: "armR", slice: [0.5, 0.9] },
149
+ RightHand: { part: "armR", slice: [0.9, 1] },
150
+ LeftUpperLeg: { part: "legL", slice: [0, 0.45] },
151
+ LeftLowerLeg: { part: "legL", slice: [0.45, 0.9] },
152
+ LeftFoot: { part: "legL", slice: [0.9, 1] },
153
+ RightUpperLeg: { part: "legR", slice: [0, 0.45] },
154
+ RightLowerLeg: { part: "legR", slice: [0.45, 0.9] },
155
+ RightFoot: { part: "legR", slice: [0.9, 1] }
156
+ };
157
+ function nativePartOf(bone) {
158
+ return NATIVE_BONES[bone]?.part ?? null;
159
+ }
160
+ function nativeFaceRect(bone, face) {
161
+ const mapping = NATIVE_BONES[bone];
162
+ if (!mapping)
163
+ return null;
164
+ const base = NATIVE_PARTS[mapping.part].faces[face];
165
+ const slice = mapping.slice;
166
+ if (!slice)
167
+ return base;
168
+ const [from, to] = slice;
169
+ if (face === "up")
170
+ return from === 0 ? base : null;
171
+ if (face === "down")
172
+ return to === 1 ? base : null;
173
+ const top = Math.round(base.y + base.h * from);
174
+ const bottom = Math.round(base.y + base.h * to);
175
+ return rect2(base.x, top, base.w, bottom - top);
176
+ }
177
+ var BODY_SCALE_LIMITS = {
178
+ stature: { min: 0.5, max: 1.5 },
179
+ width: { min: 0.9, max: 1.3 },
180
+ head: { min: 0.9, max: 1.25 }
181
+ };
182
+ var PLUP_BODY_LIMITS = {
183
+ shoulders: { min: 0.7, max: 1.45 },
184
+ waist: { min: 0.62, max: 1.2 },
185
+ hips: { min: 0.75, max: 1.4 },
186
+ legLength: { min: 1, max: 3 },
187
+ armLength: { min: 0.8, max: 1.8 },
188
+ muscle: { min: 0.7, max: 1.9 },
189
+ shoulderHeight: { min: 0.2, max: 0.55 }
190
+ };
191
+ var CANONICAL_PLUP_BODY = {
192
+ shoulders: 1,
193
+ waist: 1,
194
+ hips: 1,
195
+ legLength: 1,
196
+ armLength: 1,
197
+ muscle: 1,
198
+ shoulderHeight: 0.34
199
+ };
200
+ function clampPlupBody(body) {
201
+ const out = { ...CANONICAL_PLUP_BODY };
202
+ for (const key of Object.keys(PLUP_BODY_LIMITS)) {
203
+ const value = body?.[key];
204
+ if (typeof value === "number" && Number.isFinite(value))
205
+ out[key] = Math.min(PLUP_BODY_LIMITS[key].max, Math.max(PLUP_BODY_LIMITS[key].min, value));
206
+ }
207
+ return out;
208
+ }
209
+ var CANONICAL_BODY_SCALE = { stature: 1, width: {}, head: 1 };
210
+ var WIDTH_PARTS = ["torso", "armL", "armR", "legL", "legR"];
211
+ var clamp = (value, limit) => typeof value === "number" && Number.isFinite(value) ? Math.min(limit.max, Math.max(limit.min, value)) : 1;
212
+ function clampBodyScale(scale) {
213
+ const width = {};
214
+ for (const part of WIDTH_PARTS) {
215
+ const value = scale?.width?.[part];
216
+ if (typeof value === "number")
217
+ width[part] = clamp(value, BODY_SCALE_LIMITS.width);
218
+ }
219
+ return {
220
+ stature: clamp(scale?.stature, BODY_SCALE_LIMITS.stature),
221
+ width,
222
+ head: clamp(scale?.head, BODY_SCALE_LIMITS.head)
223
+ };
224
+ }
225
+ var widthOf = (scale, part) => part && part !== "head" ? scale.width[part] ?? 1 : 1;
226
+ function scaleBone(bone, part, parentPart, scale) {
227
+ const { stature } = scale;
228
+ const across = widthOf(scale, part);
229
+ const acrossParent = widthOf(scale, parentPart);
230
+ const head = part === "head" ? scale.head : 1;
231
+ return {
232
+ joint: [
233
+ bone.joint[0] * stature * acrossParent,
234
+ bone.joint[1] * stature,
235
+ bone.joint[2] * stature * acrossParent
236
+ ],
237
+ size: [
238
+ bone.size[0] * stature * across * head,
239
+ bone.size[1] * stature * head,
240
+ bone.size[2] * stature * across * head
241
+ ],
242
+ center: [
243
+ bone.center[0] * stature * across * head,
244
+ bone.center[1] * stature * head,
245
+ bone.center[2] * stature * across * head
246
+ ]
247
+ };
248
+ }
249
+ function canonicalFootprint(rigId) {
250
+ const rig = RIGS[rigId];
251
+ const joints = new Map;
252
+ const bones = {};
253
+ let minX = Number.POSITIVE_INFINITY;
254
+ let maxX = Number.NEGATIVE_INFINITY;
255
+ let minY = Number.POSITIVE_INFINITY;
256
+ let maxY = Number.NEGATIVE_INFINITY;
257
+ let minZ = Number.POSITIVE_INFINITY;
258
+ let maxZ = Number.NEGATIVE_INFINITY;
259
+ for (const bone of rig.bones) {
260
+ const parent = bone.parent ? joints.get(bone.parent) ?? [0, 0, 0] : [0, 0, 0];
261
+ const joint = [
262
+ parent[0] + bone.joint[0],
263
+ parent[1] + bone.joint[1],
264
+ parent[2] + bone.joint[2]
265
+ ];
266
+ joints.set(bone.name, joint);
267
+ const center = [
268
+ joint[0] + bone.center[0],
269
+ joint[1] + bone.center[1],
270
+ joint[2] + bone.center[2]
271
+ ];
272
+ bones[bone.name] = { size: bone.size, center };
273
+ minX = Math.min(minX, center[0] - bone.size[0] / 2);
274
+ maxX = Math.max(maxX, center[0] + bone.size[0] / 2);
275
+ minY = Math.min(minY, center[1] - bone.size[1] / 2);
276
+ maxY = Math.max(maxY, center[1] + bone.size[1] / 2);
277
+ minZ = Math.min(minZ, center[2] - bone.size[2] / 2);
278
+ maxZ = Math.max(maxZ, center[2] + bone.size[2] / 2);
279
+ }
280
+ return { width: maxX - minX, height: maxY - minY, depth: maxZ - minZ, bones };
281
+ }
282
+ function visualEnvelope(rigId) {
283
+ const footprint = canonicalFootprint(rigId);
284
+ const stature = BODY_SCALE_LIMITS.stature.max;
285
+ return {
286
+ width: footprint.width * stature * BODY_SCALE_LIMITS.width.max,
287
+ height: footprint.height * stature * BODY_SCALE_LIMITS.head.max,
288
+ depth: footprint.depth * stature * BODY_SCALE_LIMITS.width.max
289
+ };
290
+ }
291
+ var NATIVE_SHEET_CAPS = {
292
+ format: "png-24",
293
+ width: NATIVE_WIDTH,
294
+ height: NATIVE_HEIGHT,
295
+ maxBytes: 64 * 1024
296
+ };
297
+ function validateVariantSheet(facts) {
298
+ if (facts.width !== NATIVE_SHEET_CAPS.width || facts.height !== NATIVE_SHEET_CAPS.height)
299
+ return { ok: false, reason: "wrong_size" };
300
+ if (facts.bytes > NATIVE_SHEET_CAPS.maxBytes)
301
+ return { ok: false, reason: "over_byte_cap" };
302
+ return { ok: true };
303
+ }
304
+ var PANTS_BONE = /Leg|Foot/;
305
+ function boneSkin(bone, face, look) {
306
+ const part = nativePartOf(bone);
307
+ const variant = part ? look.variant?.parts[part] : undefined;
308
+ if (variant) {
309
+ const source2 = nativeFaceRect(bone, face);
310
+ return source2 ? { image: variant.image, source: source2, redraw: true } : null;
311
+ }
312
+ if (look.native) {
313
+ const source2 = nativeFaceRect(bone, face);
314
+ if (source2)
315
+ return { image: look.native, source: source2, redraw: false };
316
+ }
317
+ const sheet = PANTS_BONE.test(bone) || bone === "LowerTorso" ? look.pants : look.shirt;
318
+ const source = sheet ? classicFaceRect(bone, face) : null;
319
+ return sheet && source ? { image: sheet, source, redraw: false } : null;
320
+ }
321
+ var CONVERSION_FACES = ["front", "back", "left", "right", "up", "down"];
322
+ var CLASSIC_SOURCES = [
323
+ { part: "torso", bone: "Torso" },
324
+ { part: "armL", bone: "LeftArm" },
325
+ { part: "armR", bone: "RightArm" },
326
+ { part: "legL", bone: "LeftLeg" },
327
+ { part: "legR", bone: "RightLeg" }
328
+ ];
329
+ var CLASSIC_TO_NATIVE = CLASSIC_SOURCES.flatMap(({ part, bone }) => {
330
+ const mapping = CLASSIC_BONES[bone];
331
+ if (!mapping)
332
+ return [];
333
+ return CONVERSION_FACES.map((face) => ({
334
+ part,
335
+ face,
336
+ sheet: mapping.sheet,
337
+ source: mapping.faces[face],
338
+ dest: NATIVE_PARTS[part].faces[face]
339
+ }));
340
+ });
341
+
342
+ export { CLASSIC_WIDTH, CLASSIC_HEIGHT, CLASSIC_TORSO, CLASSIC_RIGHT_LIMB, CLASSIC_LEFT_LIMB, CLASSIC_BONES, classicFaceRect, validateClassicTemplate, NATIVE_PX_PER_STUD, NATIVE_WIDTH, NATIVE_HEIGHT, NATIVE_TORSO, NATIVE_HEAD, NATIVE_ARM_LEFT, NATIVE_ARM_RIGHT, NATIVE_LEG_LEFT, NATIVE_LEG_RIGHT, NATIVE_PARTS, NATIVE_BONES, nativePartOf, nativeFaceRect, BODY_SCALE_LIMITS, PLUP_BODY_LIMITS, CANONICAL_PLUP_BODY, clampPlupBody, CANONICAL_BODY_SCALE, clampBodyScale, scaleBone, canonicalFootprint, visualEnvelope, NATIVE_SHEET_CAPS, validateVariantSheet, boneSkin, CLASSIC_TO_NATIVE };
@@ -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,48 @@
1
+ import type { CustomClip } from "./pose";
2
+ import type { CanonicalBone } from "./rig";
3
+ /**
4
+ * Turns a baked motion clip (the CC0 library: Quaternius UAL, CMU, or a hand-keyed one) into the
5
+ * keyframes an emote ships. The source stores where 18 joints are, frame by frame; the rig wants a
6
+ * rotation per canonical bone. Each limb's direction is solved for the euler order the renderer uses
7
+ * (three's default XYZ: z swings a limb out, x swings it forward or back), and the solution is
8
+ * checked in the tests by applying the euler back to the rest vector and comparing directions.
9
+ */
10
+ /** The 18-joint skeleton a baked clip carries, in file order. */
11
+ export declare const BAKED_JOINTS: readonly ["pelvis", "spine", "neck", "head", "shoulder_l", "elbow_l", "wrist_l", "shoulder_r", "elbow_r", "wrist_r", "hip_l", "knee_l", "ankle_l", "toe_l", "hip_r", "knee_r", "ankle_r", "toe_r"];
12
+ /** The clip file as the content pipeline writes it; only what the bake reads is typed. */
13
+ export interface BakedClip {
14
+ fps: number;
15
+ /** Seconds. */
16
+ durasi: number;
17
+ loop?: boolean;
18
+ sendi: readonly string[];
19
+ /** Frame-major: joint x, y, z for every joint in `sendi`, in metres, facing +z. */
20
+ data: readonly number[];
21
+ }
22
+ /** Which bones a bake drives, in the order a frame lists them. */
23
+ export declare const BAKE_BONES: readonly CanonicalBone[];
24
+ type Vec = readonly [number, number, number];
25
+ type Euler = {
26
+ x: number;
27
+ z: number;
28
+ };
29
+ /**
30
+ * The euler (x then z, XYZ order) that turns a limb hanging straight down onto `d`. Two solutions
31
+ * exist for every direction; the one closest to the previous frame keeps the limb from flipping
32
+ * when it sweeps through the horizontal.
33
+ */
34
+ export declare function limbEuler(d: Vec, previous?: Euler): Euler;
35
+ /** What `limbEuler` must reproduce: where a hanging limb points after the euler. */
36
+ export declare function limbDirection(e: Euler): Vec;
37
+ /** The euler that tips an upright segment (the spine, the neck) onto `d`. */
38
+ export declare function uprightEuler(d: Vec): Euler;
39
+ export interface BakeOptions {
40
+ /** Output frames per second; never more than the source has. Default 20. */
41
+ fps?: number;
42
+ /** Longest clip kept, in seconds. Default 8. */
43
+ maxSeconds?: number;
44
+ }
45
+ export declare class BakeError extends Error {
46
+ }
47
+ export declare function bakeToCustomClip(source: BakedClip, options?: BakeOptions): CustomClip;
48
+ export {};