@plupin/character 0.5.0 → 0.6.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/dist/three.js CHANGED
@@ -82,15 +82,716 @@ import {
82
82
  Mesh as Mesh2,
83
83
  MeshBasicMaterial as MeshBasicMaterial2,
84
84
  QuadraticBezierCurve3,
85
- Quaternion,
85
+ Quaternion as Quaternion2,
86
86
  RepeatWrapping as RepeatWrapping2,
87
87
  ShaderMaterial,
88
88
  SphereGeometry as SphereGeometry3,
89
89
  SRGBColorSpace as SRGBColorSpace2,
90
90
  TubeGeometry,
91
- Vector3 as Vector32
91
+ Vector2 as Vector22,
92
+ Vector3 as Vector34
92
93
  } from "three";
93
94
 
95
+ // src/dance-clips.ts
96
+ import { Vector3 } from "three";
97
+ var IK_DANCE_SET = new Set([
98
+ "brazil-funk",
99
+ "pacu-jalur",
100
+ "velocity",
101
+ "griddy",
102
+ "floss",
103
+ "caramel"
104
+ ]);
105
+ function isIkDanceName(name) {
106
+ return typeof name === "string" && IK_DANCE_SET.has(name);
107
+ }
108
+ var HIPX = 0.1;
109
+ var SHX = 0.19;
110
+ var UA = 0.29;
111
+ var LA = 0.26;
112
+ var TH = 0.47;
113
+ var SH = 0.45;
114
+ var lerp = (a, b, k) => a + (b - a) * k;
115
+ var norm = (v) => {
116
+ const l = Math.hypot(v[0], v[1], v[2]) || 1;
117
+ return [v[0] / l, v[1] / l, v[2] / l];
118
+ };
119
+ var add = (a, b, k = 1) => [
120
+ a[0] + b[0] * k,
121
+ a[1] + b[1] * k,
122
+ a[2] + b[2] * k
123
+ ];
124
+ function rot([x, y, z], yaw, lean, roll) {
125
+ let c = Math.cos(roll);
126
+ let s = Math.sin(roll);
127
+ [x, y] = [x * c - y * s, x * s + y * c];
128
+ c = Math.cos(lean);
129
+ s = Math.sin(lean);
130
+ [y, z] = [y * c - z * s, y * s + z * c];
131
+ c = Math.cos(yaw);
132
+ s = Math.sin(yaw);
133
+ [x, z] = [x * c + z * s, -x * s + z * c];
134
+ return [x, y, z];
135
+ }
136
+ var DOWN_ARM = { u: [0.18, -1, 0], l: [0.08, -1, 0.15] };
137
+ var BASE = {
138
+ drop: 0,
139
+ px: 0,
140
+ pz: 0,
141
+ yaw: 0,
142
+ lean: 0,
143
+ roll: 0,
144
+ headYaw: 0,
145
+ headPitch: 0,
146
+ headRoll: 0,
147
+ l: DOWN_ARM,
148
+ r: DOWN_ARM,
149
+ fl: [0.06, 0, 0, 0.1, 0],
150
+ fr: [0.06, 0, 0, -0.1, 0]
151
+ };
152
+ var full = (p) => ({
153
+ ...BASE,
154
+ ...p,
155
+ l: p.l ?? BASE.l,
156
+ r: p.r ?? BASE.r,
157
+ fl: p.fl ?? BASE.fl,
158
+ fr: p.fr ?? BASE.fr
159
+ });
160
+ function mixArm(a, b, k) {
161
+ return {
162
+ u: [lerp(a.u[0], b.u[0], k), lerp(a.u[1], b.u[1], k), lerp(a.u[2], b.u[2], k)],
163
+ l: [lerp(a.l[0], b.l[0], k), lerp(a.l[1], b.l[1], k), lerp(a.l[2], b.l[2], k)]
164
+ };
165
+ }
166
+ function mixPose(a, b, k) {
167
+ const m5 = (x, y) => [
168
+ lerp(x[0], y[0], k),
169
+ lerp(x[1], y[1], k),
170
+ lerp(x[2], y[2], k),
171
+ lerp(x[3], y[3], k),
172
+ lerp(x[4], y[4], k)
173
+ ];
174
+ return {
175
+ drop: lerp(a.drop, b.drop, k),
176
+ px: lerp(a.px, b.px, k),
177
+ pz: lerp(a.pz, b.pz, k),
178
+ yaw: lerp(a.yaw, b.yaw, k),
179
+ lean: lerp(a.lean, b.lean, k),
180
+ roll: lerp(a.roll, b.roll, k),
181
+ headYaw: lerp(a.headYaw, b.headYaw, k),
182
+ headPitch: lerp(a.headPitch, b.headPitch, k),
183
+ headRoll: lerp(a.headRoll, b.headRoll, k),
184
+ l: mixArm(a.l, b.l, k),
185
+ r: mixArm(a.r, b.r, k),
186
+ fl: m5(a.fl, b.fl),
187
+ fr: m5(a.fr, b.fr)
188
+ };
189
+ }
190
+ var smootherstep = (k) => k * k * k * (k * (k * 6 - 15) + 10);
191
+ function sampleTimeline(keys, t, extra) {
192
+ let i = keys.findIndex((k2) => k2[0] > t);
193
+ if (i < 0)
194
+ i = keys.length;
195
+ const a = keys[Math.max(0, i - 1)];
196
+ const b = keys[Math.min(keys.length - 1, i)];
197
+ let k = b === a ? 1 : (t - a[0]) / (b[0] - a[0]);
198
+ k = Math.min(1, Math.max(0, k / (b[2] ?? 1)));
199
+ const p = mixPose(full(a[1]), full(b[1]), smootherstep(k));
200
+ return extra ? extra(p, t) : p;
201
+ }
202
+ function sampleLayered(keys, dur, seconds, leadArm, lagHead, extra) {
203
+ const wrap = (v) => (v % dur + dur) % dur;
204
+ const t = wrap(seconds);
205
+ const body = sampleTimeline(keys, t, extra);
206
+ const arms = sampleTimeline(keys, wrap(t + leadArm), extra);
207
+ const head = sampleTimeline(keys, wrap(t - lagHead), extra);
208
+ return {
209
+ ...body,
210
+ l: arms.l,
211
+ r: arms.r,
212
+ headYaw: head.headYaw,
213
+ headPitch: head.headPitch,
214
+ headRoll: head.headRoll
215
+ };
216
+ }
217
+ function build18Joints(p) {
218
+ const P = [p.px, 1 - p.drop, p.pz];
219
+ const R = (v) => rot(v, p.yaw, p.lean, p.roll);
220
+ const Rh = (v) => rot(v, p.yaw + p.headYaw, p.lean + p.headPitch, p.roll + p.headRoll);
221
+ const spine = add(P, R([0, 0.25, 0]));
222
+ const neck = add(P, R([0, 0.5, 0]));
223
+ const head = add(neck, Rh([0, 0.16, 0]));
224
+ const J = { pelvis: P, spine, neck, head };
225
+ for (const [sd, sg] of [
226
+ ["l", 1],
227
+ ["r", -1]
228
+ ]) {
229
+ const a = p[sd];
230
+ const side = (v) => [v[0] * sg, v[1], v[2]];
231
+ const sh = add(P, R([sg * SHX, 0.45, 0]));
232
+ const el = add(sh, R(norm(side(a.u))), UA);
233
+ const wr = add(el, R(norm(side(a.l))), LA);
234
+ J[`shoulder_${sd}`] = sh;
235
+ J[`elbow_${sd}`] = el;
236
+ J[`wrist_${sd}`] = wr;
237
+ const hip = add(P, R([sg * HIPX, 0, 0]));
238
+ const f = p[`f${sd}`];
239
+ const an = [sg * (HIPX + f[0]), 0.08 + f[2], f[1]];
240
+ const d = add(an, hip, -1);
241
+ const dl = Math.min(Math.hypot(d[0], d[1], d[2]), TH + SH - 0.001);
242
+ const u = norm(d);
243
+ const x = (TH * TH - SH * SH + dl * dl) / (2 * Math.max(0.0001, dl));
244
+ const h = Math.sqrt(Math.max(0, TH * TH - x * x));
245
+ let pole = norm(add(R([0, 0, 0.35]), [Math.sin(f[3]), 0, Math.cos(f[3])]));
246
+ const dot = pole[0] * u[0] + pole[1] * u[1] + pole[2] * u[2];
247
+ pole = norm(add(pole, u, -dot));
248
+ const kn = add(add(hip, u, x), pole, h);
249
+ const toeY = -0.06 + Math.sin(f[4]) * 0.12;
250
+ const toeFwd = Math.cos(f[4]) * 0.13;
251
+ const toe = add(an, [Math.sin(f[3]) * toeFwd, toeY, Math.cos(f[3]) * toeFwd]);
252
+ J[`hip_${sd}`] = hip;
253
+ J[`knee_${sd}`] = kn;
254
+ J[`ankle_${sd}`] = an;
255
+ J[`toe_${sd}`] = toe;
256
+ }
257
+ const frame = {};
258
+ for (const key of Object.keys(J)) {
259
+ const v = J[key];
260
+ frame[key] = new Vector3(v[0], v[1], v[2]);
261
+ }
262
+ return frame;
263
+ }
264
+ var B_BR = 0.43;
265
+ var ST_BR = 0.22;
266
+ var brCrossR = {
267
+ r: { u: [0.35, -0.3, 0.9], l: [-0.95, 0.32, 0.12] },
268
+ l: { u: [0.3, -0.95, -0.1], l: [0.15, -0.75, 0.6] },
269
+ yaw: 0.26,
270
+ px: 0.06,
271
+ drop: 0.18,
272
+ headYaw: -0.14,
273
+ headRoll: 0.08,
274
+ fl: [ST_BR, 0.02, 0, 0.45, 0],
275
+ fr: [ST_BR - 0.08, 0.14, 0.08, 0.6, -0.25]
276
+ };
277
+ var brCrossL = {
278
+ ...brCrossR,
279
+ l: brCrossR.r,
280
+ r: brCrossR.l,
281
+ yaw: -0.26,
282
+ px: -0.06,
283
+ headYaw: 0.14,
284
+ headRoll: -0.08,
285
+ fr: [ST_BR, 0.02, 0, -0.45, 0],
286
+ fl: [ST_BR - 0.08, 0.14, 0.08, -0.6, -0.25]
287
+ };
288
+ var brSpread = {
289
+ l: { u: [0.95, 0.15, 0.1], l: [0.3, -0.95, 0.2] },
290
+ r: { u: [0.95, 0.15, 0.1], l: [0.3, -0.95, 0.2] },
291
+ lean: -0.08,
292
+ drop: 0.12,
293
+ headPitch: -0.08,
294
+ fl: [ST_BR + 0.12, 0, 0, 0.6, 0],
295
+ fr: [ST_BR + 0.12, 0, 0, -0.6, 0]
296
+ };
297
+ var brFists = {
298
+ l: { u: [0.4, -0.6, 0.7], l: [-0.85, -0.2, 0.45] },
299
+ r: { u: [0.4, -0.6, 0.7], l: [-0.85, -0.2, 0.45] },
300
+ lean: 0.28,
301
+ drop: 0.36,
302
+ headPitch: -0.14,
303
+ fl: [ST_BR + 0.12, 0.04, 0, 0.8, 0],
304
+ fr: [ST_BR + 0.12, 0.04, 0, -0.8, 0]
305
+ };
306
+ var brMouth = {
307
+ r: { u: [0.25, -0.15, 0.95], l: [-0.35, 0.92, 0.25] },
308
+ l: { u: [0.3, -0.95, -0.05], l: [0.1, -0.9, 0.4] },
309
+ lean: -0.12,
310
+ roll: -0.06,
311
+ drop: 0.16,
312
+ headYaw: 0.14,
313
+ headPitch: -0.1,
314
+ fl: [ST_BR - 0.05, 0.1, 0.06, -0.4, -0.2],
315
+ fr: [ST_BR, 0, 0, -0.45, 0]
316
+ };
317
+ var BR_SEQ = [
318
+ brCrossR,
319
+ brCrossL,
320
+ brCrossR,
321
+ brCrossL,
322
+ brSpread,
323
+ brFists,
324
+ { ...brFists, drop: 0.3, lean: 0.24 },
325
+ brMouth
326
+ ];
327
+ var BRAZIL_KEYS = [
328
+ [0, BR_SEQ[0], 1],
329
+ ...BR_SEQ.slice(1).map((p, i) => [(i + 1) * B_BR, p, 0.3]),
330
+ [8 * B_BR, BR_SEQ[0], 0.3]
331
+ ];
332
+ function brazilExtra(p, t) {
333
+ const beat = t / B_BR;
334
+ const ph = beat % 1;
335
+ const n = Math.floor(beat) % 8;
336
+ const out = { ...p, fl: [...p.fl], fr: [...p.fr] };
337
+ out.drop += 0.07 * Math.exp(-ph * 4) * Math.min(1, ph * 12) - 0.02 * Math.sin(ph * Math.PI);
338
+ out.px += 0.025 * Math.sin(beat * Math.PI);
339
+ if (n === 4) {
340
+ const h = Math.sin(Math.min(1, ph / 0.55) * Math.PI);
341
+ out.drop -= 0.22 * h;
342
+ out.fl[2] += 0.14 * h;
343
+ out.fr[2] += 0.14 * h;
344
+ }
345
+ return out;
346
+ }
347
+ var B_PJ = 0.45;
348
+ var ST_PJ = 0.2;
349
+ var pjRoll1 = {
350
+ drop: 0.16,
351
+ px: -0.05,
352
+ yaw: 0.14,
353
+ lean: 0.08,
354
+ roll: -0.05,
355
+ headYaw: -0.1,
356
+ headPitch: 0.04,
357
+ r: { u: [0.32, -0.38, 0.86], l: [-0.85, 0.42, 0.3] },
358
+ l: { u: [0.32, -0.62, 0.7], l: [-0.85, -0.25, 0.45] },
359
+ fl: [ST_PJ, 0.08, 0, 0.25, 0],
360
+ fr: [ST_PJ, -0.06, 0, -0.25, 0]
361
+ };
362
+ var pjRoll2 = {
363
+ ...pjRoll1,
364
+ px: 0.05,
365
+ yaw: -0.14,
366
+ roll: 0.05,
367
+ headYaw: 0.1,
368
+ r: { u: [0.32, -0.62, 0.7], l: [-0.85, -0.25, 0.45] },
369
+ l: { u: [0.32, -0.38, 0.86], l: [-0.85, 0.42, 0.3] }
370
+ };
371
+ var pjSweepRIn = {
372
+ drop: 0.22,
373
+ px: 0.08,
374
+ yaw: 0.34,
375
+ lean: 0.1,
376
+ roll: -0.08,
377
+ headYaw: -0.26,
378
+ r: { u: [0.22, -0.22, 0.94], l: [-0.96, 0.24, 0.16] },
379
+ l: { u: [0.62, -0.68, -0.18], l: [-0.45, -0.2, 0.85] },
380
+ fl: [ST_PJ + 0.04, 0.1, 0, 0.32, 0],
381
+ fr: [ST_PJ, -0.06, 0, -0.3, 0]
382
+ };
383
+ var pjSweepROut = {
384
+ drop: 0.14,
385
+ px: -0.06,
386
+ yaw: -0.24,
387
+ lean: 0.04,
388
+ roll: 0.06,
389
+ headYaw: 0.18,
390
+ headPitch: -0.06,
391
+ r: { u: [0.92, 0.12, 0.36], l: [0.82, 0.06, 0.56] },
392
+ l: { u: [0.45, -0.55, 0.55], l: [-0.85, 0.12, 0.5] },
393
+ fl: [ST_PJ, 0.06, 0, 0.28, 0],
394
+ fr: [ST_PJ + 0.05, -0.04, 0, -0.32, 0]
395
+ };
396
+ var pjSweepLIn = {
397
+ ...pjSweepRIn,
398
+ px: -0.08,
399
+ yaw: -0.34,
400
+ roll: 0.08,
401
+ headYaw: 0.26,
402
+ l: pjSweepRIn.r,
403
+ r: pjSweepRIn.l,
404
+ fr: [ST_PJ + 0.04, 0.1, 0, -0.32, 0],
405
+ fl: [ST_PJ, -0.06, 0, 0.3, 0]
406
+ };
407
+ var pjSweepLOut = {
408
+ ...pjSweepROut,
409
+ px: 0.06,
410
+ yaw: 0.24,
411
+ roll: -0.06,
412
+ headYaw: -0.18,
413
+ l: pjSweepROut.r,
414
+ r: pjSweepROut.l,
415
+ fr: [ST_PJ, 0.06, 0, -0.28, 0],
416
+ fl: [ST_PJ + 0.05, -0.04, 0, 0.32, 0]
417
+ };
418
+ var pjPushR = {
419
+ drop: 0.2,
420
+ px: -0.06,
421
+ yaw: 0.28,
422
+ lean: 0.12,
423
+ roll: -0.06,
424
+ headYaw: -0.2,
425
+ r: { u: [0.42, 0.08, 0.9], l: [0.12, 0.15, 0.98] },
426
+ l: { u: [0.75, -0.25, -0.45], l: [-0.45, 0.35, 0.82] },
427
+ fl: [ST_PJ + 0.04, 0.12, 0, 0.3, 0],
428
+ fr: [ST_PJ + 0.02, -0.08, 0, -0.3, 0]
429
+ };
430
+ var pjPushL = {
431
+ ...pjPushR,
432
+ px: 0.06,
433
+ yaw: -0.28,
434
+ roll: 0.06,
435
+ headYaw: 0.2,
436
+ l: pjPushR.r,
437
+ r: pjPushR.l,
438
+ fr: [ST_PJ + 0.04, 0.12, 0, -0.3, 0],
439
+ fl: [ST_PJ + 0.02, -0.08, 0, 0.3, 0]
440
+ };
441
+ var PJ_SEQ = [
442
+ pjRoll1,
443
+ pjRoll2,
444
+ pjSweepRIn,
445
+ pjSweepROut,
446
+ pjSweepLIn,
447
+ pjSweepLOut,
448
+ pjPushR,
449
+ pjPushL
450
+ ];
451
+ var PACU_KEYS = [
452
+ [0, PJ_SEQ[0], 1],
453
+ ...PJ_SEQ.slice(1).map((p, i) => [(i + 1) * B_PJ, p, 0.72]),
454
+ [8 * B_PJ, PJ_SEQ[0], 0.72]
455
+ ];
456
+ function pacuExtra(p, t) {
457
+ const out = { ...p };
458
+ const wave = Math.sin(t / B_PJ * Math.PI);
459
+ out.drop += 0.045 * (0.5 + 0.5 * wave);
460
+ out.roll += 0.035 * Math.sin(t / (B_PJ * 2) * Math.PI);
461
+ if (t < 2 * B_PJ) {
462
+ const a = t / B_PJ * Math.PI * 2 * 2;
463
+ out.r = { u: [0.32, -0.4 + 0.18 * Math.sin(a), 0.85], l: [-0.85, 0.22 * Math.cos(a), 0.45] };
464
+ out.l = { u: [0.32, -0.4 - 0.18 * Math.sin(a), 0.85], l: [-0.85, -0.22 * Math.cos(a), 0.45] };
465
+ }
466
+ return out;
467
+ }
468
+ var B_VL = 0.4;
469
+ var vlGlide1 = {
470
+ drop: 0.08,
471
+ px: -0.07,
472
+ yaw: 0.2,
473
+ lean: -0.04,
474
+ roll: -0.06,
475
+ headYaw: -0.14,
476
+ r: { u: [0.55, -0.5, 0.65], l: [-0.5, 0.3, 0.8] },
477
+ l: { u: [0.65, -0.65, 0.3], l: [0.2, -0.8, 0.55] },
478
+ fl: [0.16, 0.08, 0, 0.22, 0],
479
+ fr: [0.16, -0.06, 0, -0.2, 0]
480
+ };
481
+ var vlHit1 = {
482
+ drop: 0.28,
483
+ px: 0.09,
484
+ yaw: -0.28,
485
+ lean: 0.18,
486
+ roll: 0.12,
487
+ headYaw: 0.26,
488
+ headPitch: 0.14,
489
+ headRoll: -0.14,
490
+ r: { u: [0.22, -0.25, 0.94], l: [-0.92, 0.35, 0.18] },
491
+ l: { u: [0.22, -0.25, 0.94], l: [-0.92, 0.35, 0.18] },
492
+ fl: [0.22, 0.12, 0, 0.4, 0],
493
+ fr: [0.2, -0.04, 0, -0.35, 0]
494
+ };
495
+ var vlHit1Hold = {
496
+ ...vlHit1,
497
+ drop: 0.24,
498
+ px: 0.11,
499
+ yaw: -0.32,
500
+ headYaw: 0.29
501
+ };
502
+ var vlGlide2 = {
503
+ drop: 0.06,
504
+ px: 0,
505
+ yaw: 0.06,
506
+ lean: 0,
507
+ roll: 0,
508
+ headYaw: -0.04,
509
+ r: { u: [0.4, -0.6, 0.65], l: [-0.4, -0.2, 0.88] },
510
+ l: { u: [0.4, -0.6, 0.65], l: [-0.4, -0.2, 0.88] },
511
+ fl: [0.15, 0, 0, 0.2, 0],
512
+ fr: [0.18, 0.1, 0.06, -0.2, -0.2]
513
+ };
514
+ var vlHit2 = {
515
+ drop: 0.14,
516
+ px: -0.1,
517
+ yaw: 0.34,
518
+ lean: -0.14,
519
+ roll: -0.14,
520
+ headYaw: -0.28,
521
+ headPitch: -0.12,
522
+ headRoll: 0.16,
523
+ l: { u: [0.72, 0.68, 0.18], l: [0.58, 0.8, 0.15] },
524
+ r: { u: [0.35, -0.25, 0.88], l: [-0.9, 0.45, 0.18] },
525
+ fl: [0.22, -0.08, 0, 0.35, 0],
526
+ fr: [0.22, 0.18, 0.04, -0.3, 0.35]
527
+ };
528
+ var vlHit2Hold = {
529
+ ...vlHit2,
530
+ drop: 0.11,
531
+ px: -0.12,
532
+ yaw: 0.38
533
+ };
534
+ var vlHit3 = {
535
+ drop: 0.32,
536
+ px: 0.06,
537
+ yaw: -0.18,
538
+ lean: 0.22,
539
+ roll: 0.08,
540
+ headYaw: 0.18,
541
+ headPitch: 0.12,
542
+ r: { u: [0.82, -0.2, 0.5], l: [0.45, -0.82, 0.35] },
543
+ l: { u: [0.82, -0.2, 0.5], l: [0.45, -0.82, 0.35] },
544
+ fl: [0.24, 0.06, 0, 0.45, 0],
545
+ fr: [0.24, 0.06, 0, -0.45, 0]
546
+ };
547
+ var VELOCITY_KEYS = [
548
+ [0, vlGlide1, 1],
549
+ [1 * B_VL, vlHit1, 0.22],
550
+ [2 * B_VL, vlHit1Hold, 1],
551
+ [3 * B_VL, vlGlide2, 0.9],
552
+ [4 * B_VL, vlHit2, 0.22],
553
+ [5 * B_VL, vlHit2Hold, 1],
554
+ [6 * B_VL, vlHit3, 0.24],
555
+ [7 * B_VL, { ...vlHit3, drop: 0.26, lean: 0.16 }, 1],
556
+ [8 * B_VL, vlGlide1, 0.75]
557
+ ];
558
+ var B_GR = 0.36;
559
+ var grSwingL = {
560
+ drop: 0.14,
561
+ px: -0.05,
562
+ yaw: 0.12,
563
+ lean: 0.22,
564
+ roll: -0.06,
565
+ headPitch: -0.12,
566
+ headYaw: -0.1,
567
+ l: { u: [0.24, -0.78, -0.58], l: [0.12, -0.52, -0.84] },
568
+ r: { u: [0.24, -0.78, -0.58], l: [0.12, -0.52, -0.84] },
569
+ fl: [0.12, 0.26, 0.03, 0.1, 0.58],
570
+ fr: [0.12, -0.12, 0, -0.12, 0]
571
+ };
572
+ var grSwingR = {
573
+ ...grSwingL,
574
+ px: 0.05,
575
+ yaw: -0.12,
576
+ roll: 0.06,
577
+ headYaw: 0.1,
578
+ fr: [0.12, 0.26, 0.03, -0.1, 0.58],
579
+ fl: [0.12, -0.12, 0, 0.12, 0]
580
+ };
581
+ var grGogglesL = {
582
+ drop: 0.2,
583
+ px: -0.06,
584
+ yaw: 0.16,
585
+ lean: 0.16,
586
+ roll: -0.08,
587
+ headPitch: -0.04,
588
+ headYaw: -0.16,
589
+ l: { u: [0.46, -0.12, 0.88], l: [-0.36, 0.9, 0.22] },
590
+ r: { u: [0.46, -0.12, 0.88], l: [-0.36, 0.9, 0.22] },
591
+ fl: [0.14, 0.28, 0.04, 0.14, 0.62],
592
+ fr: [0.12, -0.1, 0, -0.14, 0]
593
+ };
594
+ var grGogglesR = {
595
+ ...grGogglesL,
596
+ px: 0.06,
597
+ yaw: -0.16,
598
+ roll: 0.08,
599
+ headYaw: 0.16,
600
+ fr: [0.14, 0.28, 0.04, -0.14, 0.62],
601
+ fl: [0.12, -0.1, 0, 0.14, 0]
602
+ };
603
+ var GR_SEQ = [
604
+ grSwingL,
605
+ grSwingR,
606
+ grGogglesL,
607
+ grGogglesR,
608
+ grSwingL,
609
+ grSwingR,
610
+ grGogglesL,
611
+ grGogglesR
612
+ ];
613
+ var GRIDDY_KEYS = [
614
+ [0, GR_SEQ[0], 1],
615
+ ...GR_SEQ.slice(1).map((p, i) => [(i + 1) * B_GR, p, 0.58]),
616
+ [8 * B_GR, GR_SEQ[0], 0.58]
617
+ ];
618
+ function griddyExtra(p, t) {
619
+ const ph = t / B_GR % 1;
620
+ const out = { ...p };
621
+ out.drop += 0.055 * Math.cos(ph * Math.PI * 2);
622
+ return out;
623
+ }
624
+ var B_FL = 0.3;
625
+ var ST_FL = 0.22;
626
+ var flFrontR = {
627
+ drop: 0.1,
628
+ px: 0.15,
629
+ yaw: -0.14,
630
+ lean: 0.05,
631
+ roll: -0.16,
632
+ headYaw: 0.12,
633
+ headRoll: 0.14,
634
+ l: { u: [-0.55, -0.78, 0.32], l: [-0.55, -0.78, 0.32] },
635
+ r: { u: [0.76, -0.62, 0.18], l: [0.76, -0.62, 0.18] },
636
+ fl: [ST_FL, 0, 0, 0.22, 0],
637
+ fr: [ST_FL, 0, 0, -0.22, 0]
638
+ };
639
+ var flBackL = {
640
+ drop: 0.08,
641
+ px: -0.15,
642
+ yaw: 0.14,
643
+ lean: 0.06,
644
+ roll: 0.16,
645
+ headYaw: -0.12,
646
+ headRoll: -0.14,
647
+ l: { u: [0.76, -0.62, -0.28], l: [0.76, -0.62, -0.28] },
648
+ r: { u: [-0.55, -0.78, -0.34], l: [-0.55, -0.78, -0.34] },
649
+ fl: [ST_FL, 0, 0, 0.22, 0],
650
+ fr: [ST_FL, 0, 0, -0.22, 0]
651
+ };
652
+ var flBackR = {
653
+ drop: 0.1,
654
+ px: 0.15,
655
+ yaw: -0.14,
656
+ lean: 0.06,
657
+ roll: -0.16,
658
+ headYaw: 0.12,
659
+ headRoll: 0.14,
660
+ l: { u: [-0.55, -0.78, -0.34], l: [-0.55, -0.78, -0.34] },
661
+ r: { u: [0.76, -0.62, -0.28], l: [0.76, -0.62, -0.28] },
662
+ fl: [ST_FL, 0, 0, 0.22, 0],
663
+ fr: [ST_FL, 0, 0, -0.22, 0]
664
+ };
665
+ var flFrontL = {
666
+ drop: 0.08,
667
+ px: -0.15,
668
+ yaw: 0.14,
669
+ lean: 0.05,
670
+ roll: 0.16,
671
+ headYaw: -0.12,
672
+ headRoll: -0.14,
673
+ l: { u: [0.76, -0.62, 0.18], l: [0.76, -0.62, 0.18] },
674
+ r: { u: [-0.55, -0.78, 0.32], l: [-0.55, -0.78, 0.32] },
675
+ fl: [ST_FL, 0, 0, 0.22, 0],
676
+ fr: [ST_FL, 0, 0, -0.22, 0]
677
+ };
678
+ var FL_SEQ = [flFrontR, flBackL, flBackR, flFrontL, flFrontR, flBackL, flBackR, flFrontL];
679
+ var FLOSS_KEYS = [
680
+ [0, FL_SEQ[0], 1],
681
+ ...FL_SEQ.slice(1).map((p, i) => [(i + 1) * B_FL, p, 0.65]),
682
+ [8 * B_FL, FL_SEQ[0], 0.65]
683
+ ];
684
+ var B_CM = 0.36;
685
+ var ST_CM = 0.16;
686
+ var cmLeft = {
687
+ drop: 0.16,
688
+ px: 0.14,
689
+ yaw: -0.14,
690
+ lean: 0.06,
691
+ roll: -0.18,
692
+ headYaw: 0.16,
693
+ headRoll: 0.22,
694
+ l: { u: [0.72, 0.66, 0.2], l: [-0.72, 0.66, 0.2] },
695
+ r: { u: [0.72, 0.66, 0.2], l: [-0.72, 0.66, 0.2] },
696
+ fl: [ST_CM, 0.02, 0, 0.2, 0],
697
+ fr: [ST_CM - 0.04, 0.1, 0.07, -0.3, -0.35]
698
+ };
699
+ var cmUp = {
700
+ drop: 0.02,
701
+ px: 0,
702
+ yaw: 0,
703
+ lean: -0.04,
704
+ roll: 0,
705
+ headPitch: -0.08,
706
+ l: { u: [0.66, 0.72, 0.2], l: [-0.45, 0.86, 0.22] },
707
+ r: { u: [0.66, 0.72, 0.2], l: [-0.45, 0.86, 0.22] },
708
+ fl: [ST_CM, 0, 0.04, 0.16, 0],
709
+ fr: [ST_CM, 0, 0.04, -0.16, 0]
710
+ };
711
+ var cmRight = {
712
+ ...cmLeft,
713
+ px: -0.14,
714
+ yaw: 0.14,
715
+ roll: 0.18,
716
+ headYaw: -0.16,
717
+ headRoll: -0.22,
718
+ fr: [ST_CM, 0.02, 0, -0.2, 0],
719
+ fl: [ST_CM - 0.04, 0.1, 0.07, 0.3, -0.35]
720
+ };
721
+ var cmHop = {
722
+ drop: -0.14,
723
+ px: 0,
724
+ yaw: 0,
725
+ lean: -0.06,
726
+ roll: 0,
727
+ headPitch: -0.12,
728
+ l: { u: [0.55, 0.82, 0.18], l: [-0.3, 0.94, 0.18] },
729
+ r: { u: [0.55, 0.82, 0.18], l: [-0.3, 0.94, 0.18] },
730
+ fl: [ST_CM + 0.06, 0.06, 0.14, 0.25, -0.3],
731
+ fr: [ST_CM + 0.06, 0.06, 0.14, -0.25, -0.3]
732
+ };
733
+ var CM_SEQ = [cmLeft, cmUp, cmRight, cmUp, cmLeft, cmUp, cmRight, cmHop];
734
+ var CARAMEL_KEYS = [
735
+ [0, CM_SEQ[0], 1],
736
+ ...CM_SEQ.slice(1).map((p, i) => [(i + 1) * B_CM, p, 0.68]),
737
+ [8 * B_CM, CM_SEQ[0], 0.68]
738
+ ];
739
+ function caramelExtra(p, t) {
740
+ const flap = Math.sin(t / B_CM * Math.PI * 2) * 0.28;
741
+ return {
742
+ ...p,
743
+ l: { u: p.l.u, l: [p.l.l[0] - flap * 0.6, p.l.l[1] + flap * 0.4, p.l.l[2]] },
744
+ r: { u: p.r.u, l: [p.r.l[0] - flap * 0.6, p.r.l[1] + flap * 0.4, p.r.l[2]] }
745
+ };
746
+ }
747
+ var DANCE_SPECS = {
748
+ "brazil-funk": {
749
+ keys: BRAZIL_KEYS,
750
+ dur: 8 * B_BR,
751
+ leadArm: 0.04,
752
+ lagHead: 0.05,
753
+ extra: brazilExtra
754
+ },
755
+ "pacu-jalur": {
756
+ keys: PACU_KEYS,
757
+ dur: 8 * B_PJ,
758
+ leadArm: 0.05,
759
+ lagHead: 0.07,
760
+ extra: pacuExtra
761
+ },
762
+ velocity: {
763
+ keys: VELOCITY_KEYS,
764
+ dur: 8 * B_VL,
765
+ leadArm: 0.025,
766
+ lagHead: 0.04
767
+ },
768
+ griddy: {
769
+ keys: GRIDDY_KEYS,
770
+ dur: 8 * B_GR,
771
+ leadArm: 0.035,
772
+ lagHead: 0.05,
773
+ extra: griddyExtra
774
+ },
775
+ floss: {
776
+ keys: FLOSS_KEYS,
777
+ dur: 8 * B_FL,
778
+ leadArm: 0.02,
779
+ lagHead: 0.04
780
+ },
781
+ caramel: {
782
+ keys: CARAMEL_KEYS,
783
+ dur: 8 * B_CM,
784
+ leadArm: 0.04,
785
+ lagHead: 0.06,
786
+ extra: caramelExtra
787
+ }
788
+ };
789
+ function sampleIkDance(name, seconds) {
790
+ const spec = DANCE_SPECS[name];
791
+ const pose = sampleLayered(spec.keys, spec.dur, seconds, spec.leadArm, spec.lagHead, spec.extra);
792
+ return build18Joints(pose);
793
+ }
794
+
94
795
  // src/hair3d.ts
95
796
  import {
96
797
  BoxGeometry,
@@ -99,7 +800,7 @@ import {
99
800
  CatmullRomCurve3,
100
801
  SphereGeometry as SphereGeometry2,
101
802
  TorusGeometry as TorusGeometry2,
102
- Vector3
803
+ Vector3 as Vector32
103
804
  } from "three";
104
805
 
105
806
  // src/wear3d.ts
@@ -178,8 +879,10 @@ class Spring {
178
879
  }
179
880
  }
180
881
  var calm = (motion) => ({
181
- lift: clamp(motion.lift, -4, 4),
182
- yaw: clamp(motion.yaw, -8, 8)
882
+ lift: clamp(motion.lift, -6, 6),
883
+ yaw: clamp(motion.yaw, -10, 10),
884
+ swayX: clamp(motion.swayX ?? 0, -6, 6),
885
+ swayZ: clamp(motion.swayZ ?? 0, -6, 6)
183
886
  });
184
887
  function canvasTexture(size, draw) {
185
888
  const canvas = document.createElement("canvas");
@@ -463,7 +1166,7 @@ function piece(kit, build) {
463
1166
  };
464
1167
  }
465
1168
  function bunnyEars(kit) {
466
- return piece(kit, ({ add, keep, node }) => {
1169
+ return piece(kit, ({ add: add2, keep, node }) => {
467
1170
  const length = 0.46;
468
1171
  const leaf = [
469
1172
  [0, 0],
@@ -497,15 +1200,15 @@ function bunnyEars(kit) {
497
1200
  for (let i = 0;i < innerPosition.count; i += 1)
498
1201
  innerPosition.setZ(i, innerPosition.getZ(i) * 0.14 + 0.012);
499
1202
  inner.computeVertexNormals();
500
- add(outer, "#fbf8ff", { parent: root });
501
- add(inner, "#ffffff", { parent: root }, { map: skin, outline: false });
1203
+ add2(outer, "#fbf8ff", { parent: root });
1204
+ add2(inner, "#ffffff", { parent: root }, { map: skin, outline: false });
502
1205
  const tuft = new SphereGeometry(0.05, 14, 10);
503
1206
  for (const [x, y, z] of [
504
1207
  [-0.03, 0.01, 0.01],
505
1208
  [0.03, 0, 0],
506
1209
  [0, 0.03, 0.02]
507
1210
  ])
508
- add(tuft, "#fbf8ff", { at: [x, y, z], parent: root }, { outline: false });
1211
+ add2(tuft, "#fbf8ff", { at: [x, y, z], parent: root }, { outline: false });
509
1212
  const rest = side === 1 ? 0.95 : 0.16;
510
1213
  return {
511
1214
  side,
@@ -522,8 +1225,8 @@ function bunnyEars(kit) {
522
1225
  for (const ear of ears) {
523
1226
  if (twitch < 0 && ear.side === -1)
524
1227
  ear.pitch.kick(-5);
525
- const pitch = ear.pitch.step(ear.rest - motion.lift * 0.35, delta);
526
- const roll = ear.roll.step(motion.yaw * 0.06 * ear.side + Math.sin(clock * 1.7 + ear.side) * 0.04, delta);
1228
+ const pitch = ear.pitch.step(ear.rest - motion.lift * 0.42 - motion.swayZ * 0.25, delta);
1229
+ const roll = ear.roll.step(motion.yaw * 0.08 * ear.side - motion.swayX * 0.35 + Math.sin(clock * 1.7 + ear.side) * 0.04, delta);
527
1230
  for (const bend of ear.bends)
528
1231
  bend(pitch, roll, ear.side === 1 ? 0.42 : 0);
529
1232
  }
@@ -533,7 +1236,7 @@ function bunnyEars(kit) {
533
1236
  });
534
1237
  }
535
1238
  function catEars(kit) {
536
- return piece(kit, ({ add, node }) => {
1239
+ return piece(kit, ({ add: add2, node }) => {
537
1240
  const ear = new Shape;
538
1241
  ear.moveTo(-0.12, 0);
539
1242
  ear.quadraticCurveTo(-0.1, 0.12, -0.02, 0.22);
@@ -554,14 +1257,14 @@ function catEars(kit) {
554
1257
  at: [side * 0.19, TOP - 0.1, 0],
555
1258
  rotate: [-0.15, side * -0.25, side * -0.32]
556
1259
  });
557
- add(outerGeometry, "#2a2440", { at: [0, 0.1, 0], parent: root });
558
- add(innerGeometry, "#ff9cc2", { at: [0, 0.085, 0.03], parent: root }, { outline: false });
1260
+ add2(outerGeometry, "#2a2440", { at: [0, 0.1, 0], parent: root });
1261
+ add2(innerGeometry, "#ff9cc2", { at: [0, 0.085, 0.03], parent: root }, { outline: false });
559
1262
  for (const [x, r] of [
560
1263
  [-0.02, 0.3],
561
1264
  [0, 0],
562
1265
  [0.02, -0.3]
563
1266
  ])
564
- add(tuft, "#fbf8ff", { at: [x, 0.05, 0.04], rotate: [0.2, 0, r], parent: root }, { outline: false });
1267
+ add2(tuft, "#fbf8ff", { at: [x, 0.05, 0.04], rotate: [0.2, 0, r], parent: root }, { outline: false });
565
1268
  return { root, side, spring: new Spring(160, 10) };
566
1269
  });
567
1270
  let next = 2;
@@ -571,9 +1274,9 @@ function catEars(kit) {
571
1274
  for (const ear2 of ears) {
572
1275
  if (next < 0 && (ear2.side === 1 || Math.random() < 0.4))
573
1276
  ear2.spring.kick(9);
574
- const flick = ear2.spring.step(-motion.lift * 0.08, delta);
575
- ear2.root.rotation.z = ear2.side * -0.32 + ear2.side * flick * 0.6;
576
- ear2.root.rotation.x = -0.15 - Math.abs(flick) * 0.4;
1277
+ const flick = ear2.spring.step(-motion.lift * 0.12 - motion.swayX * 0.08 * ear2.side, delta);
1278
+ ear2.root.rotation.z = ear2.side * -0.32 + ear2.side * flick * 0.65;
1279
+ ear2.root.rotation.x = -0.15 - Math.abs(flick) * 0.45;
577
1280
  }
578
1281
  if (next < 0)
579
1282
  next = 2 + Math.random() * 4;
@@ -581,7 +1284,7 @@ function catEars(kit) {
581
1284
  });
582
1285
  }
583
1286
  function topHat(kit) {
584
- return piece(kit, ({ add, node }) => {
1287
+ return piece(kit, ({ add: add2, node }) => {
585
1288
  const hat = node({ at: [0.04, TOP - 0.04, -0.01], rotate: [-0.08, 0.2, -0.16] });
586
1289
  const brim = lathe([
587
1290
  [0.18, 0.012],
@@ -602,8 +1305,8 @@ function topHat(kit) {
602
1305
  position.setY(i, position.getY(i) + lift);
603
1306
  }
604
1307
  brim.computeVertexNormals();
605
- add(brim, "#1b1830", { parent: hat }, { sheen: 0.25, double: true });
606
- add(lathe([
1308
+ add2(brim, "#1b1830", { parent: hat }, { sheen: 0.25, double: true });
1309
+ add2(lathe([
607
1310
  [0, 0.4],
608
1311
  [0.2, 0.4],
609
1312
  [0.215, 0.385],
@@ -612,7 +1315,7 @@ function topHat(kit) {
612
1315
  [0.195, 0.03],
613
1316
  [0, 0.03]
614
1317
  ]), "#1b1830", { parent: hat }, { sheen: 0.25, double: true });
615
- add(lathe([
1318
+ add2(lathe([
616
1319
  [0.2, 0.05],
617
1320
  [0.206, 0.05],
618
1321
  [0.208, 0.12],
@@ -620,12 +1323,12 @@ function topHat(kit) {
620
1323
  ]), "#c8323c", { parent: hat }, { sheen: 0.5, outline: false, double: true });
621
1324
  const buckle = rounded(0.07, 0.06, 0.012);
622
1325
  buckle.holes.push(rounded(0.04, 0.032, 0.006));
623
- add(slab(buckle, 0.008, 0.004), "#f2c94c", { at: [0, 0.085, 0.21], parent: hat }, { sheen: 0.8, outline: false });
1326
+ add2(slab(buckle, 0.008, 0.004), "#f2c94c", { at: [0, 0.085, 0.21], parent: hat }, { sheen: 0.8, outline: false });
624
1327
  return;
625
1328
  });
626
1329
  }
627
1330
  function crown(kit) {
628
- return piece(kit, ({ add, node }) => {
1331
+ return piece(kit, ({ add: add2, node }) => {
629
1332
  const root = node({ at: [0, TOP - 0.07, 0], rotate: [-0.08, 0, 0.08] });
630
1333
  const radius = 0.225;
631
1334
  const width = Math.PI * 2 * radius;
@@ -657,8 +1360,8 @@ function crown(kit) {
657
1360
  position.setXYZ(i, Math.sin(angle) * r, position.getY(i), Math.cos(angle) * r);
658
1361
  }
659
1362
  band.computeVertexNormals();
660
- add(band, "#f2c94c", { parent: root }, { sheen: 0.85, double: true });
661
- add(new SphereGeometry(radius - 0.01, 24, 12, 0, Math.PI * 2, 0, Math.PI / 2), "#a3173a", {
1363
+ add2(band, "#f2c94c", { parent: root }, { sheen: 0.85, double: true });
1364
+ add2(new SphereGeometry(radius - 0.01, 24, 12, 0, Math.PI * 2, 0, Math.PI / 2), "#a3173a", {
662
1365
  at: [0, 0.02, 0],
663
1366
  scale: [1, 0.55, 1],
664
1367
  parent: root
@@ -668,29 +1371,29 @@ function crown(kit) {
668
1371
  const colors = ["#e2574c", "#4cc9e2", "#3d8b5a"];
669
1372
  for (let i = 0;i < points; i += 1) {
670
1373
  const tip = (i + 0.5) / points * Math.PI * 2;
671
- add(pearl, "#fff8e8", {
1374
+ add2(pearl, "#fff8e8", {
672
1375
  at: [Math.sin(tip) * (radius + 0.01), 0.215, Math.cos(tip) * (radius + 0.01)],
673
1376
  parent: root
674
1377
  }, { sheen: 0.7, outline: false });
675
- add(stone, colors[i % colors.length] ?? "#e2574c", {
1378
+ add2(stone, colors[i % colors.length] ?? "#e2574c", {
676
1379
  at: [Math.sin(tip) * (radius + 0.026), 0.045, Math.cos(tip) * (radius + 0.026)],
677
1380
  rotate: [0, tip, 0],
678
1381
  scale: [1, 1, 0.55],
679
1382
  parent: root
680
1383
  }, { sheen: 0.9, outline: false });
681
1384
  }
682
- add(new SphereGeometry(0.035, 12, 10), "#f2c94c", { at: [0, 0.14, 0], parent: root }, {
1385
+ add2(new SphereGeometry(0.035, 12, 10), "#f2c94c", { at: [0, 0.14, 0], parent: root }, {
683
1386
  sheen: 0.85
684
1387
  });
685
- add(new OctahedronGeometry(0.03), "#f2c94c", { at: [0, 0.19, 0], scale: [0.6, 1, 0.6], parent: root }, { sheen: 0.85 });
1388
+ add2(new OctahedronGeometry(0.03), "#f2c94c", { at: [0, 0.19, 0], scale: [0.6, 1, 0.6], parent: root }, { sheen: 0.85 });
686
1389
  return;
687
1390
  });
688
1391
  }
689
1392
  function partyHat(kit) {
690
- return piece(kit, ({ add, keep, node }) => {
1393
+ return piece(kit, ({ add: add2, keep, node }) => {
691
1394
  const hat = node({ at: [-0.08, TOP - 0.05, 0.03], rotate: [0.05, 0, 0.24] });
692
- add(new ConeGeometry(0.17, 0.42, 40, 1, true), "#ffffff", { at: [0, 0.21, 0], parent: hat }, { map: keep(candy("#ff5fa2", "#ffd84d")), repeat: [3, 1], double: true });
693
- add(new TorusGeometry(0.168, 0.022, 10, 40), "#4cc9e2", { at: [0, 0.012, 0], rotate: [Math.PI / 2, 0, 0], parent: hat }, { outline: false });
1395
+ add2(new ConeGeometry(0.17, 0.42, 40, 1, true), "#ffffff", { at: [0, 0.21, 0], parent: hat }, { map: keep(candy("#ff5fa2", "#ffd84d")), repeat: [3, 1], double: true });
1396
+ add2(new TorusGeometry(0.168, 0.022, 10, 40), "#4cc9e2", { at: [0, 0.012, 0], rotate: [Math.PI / 2, 0, 0], parent: hat }, { outline: false });
694
1397
  const puff = new SphereGeometry(0.038, 12, 10);
695
1398
  const top = node({ at: [0, 0.43, 0], parent: hat });
696
1399
  for (const [x, y, z, color] of [
@@ -701,7 +1404,7 @@ function partyHat(kit) {
701
1404
  [0.01, 0.02, 0.03, "#fbf8ff"],
702
1405
  [-0.02, -0.01, 0.025, "#ffd84d"]
703
1406
  ])
704
- add(puff, color, { at: [x, y, z], parent: top }, { outline: false });
1407
+ add2(puff, color, { at: [x, y, z], parent: top }, { outline: false });
705
1408
  const sway = new Spring(80, 6);
706
1409
  return (clock, delta, raw) => {
707
1410
  const motion = calm(raw);
@@ -712,13 +1415,13 @@ function partyHat(kit) {
712
1415
  });
713
1416
  }
714
1417
  function halo(kit) {
715
- return piece(kit, ({ add, glow, node }) => {
1418
+ return piece(kit, ({ add: add2, glow, node }) => {
716
1419
  const ring = node({ at: [0, TOP + 0.17, -0.02], rotate: [Math.PI / 2 - 0.2, 0, 0] });
717
- add(new TorusGeometry(0.22, 0.03, 14, 56), "#ffe680", { parent: ring }, { sheen: 0.8 });
1420
+ add2(new TorusGeometry(0.22, 0.03, 14, 56), "#ffe680", { parent: ring }, { sheen: 0.8 });
718
1421
  glow(new TorusGeometry(0.22, 0.075, 12, 56), "#fff2a8", 0.28, { parent: ring });
719
1422
  glow(new TorusGeometry(0.22, 0.13, 10, 56), "#ffe680", 0.1, { parent: ring });
720
1423
  const spark = new OctahedronGeometry(0.022);
721
- const sparks = [0, 1, 2, 3].map(() => add(spark, "#fffbe0", { parent: ring }, { outline: false, sheen: 1 }));
1424
+ const sparks = [0, 1, 2, 3].map(() => add2(spark, "#fffbe0", { parent: ring }, { outline: false, sheen: 1 }));
722
1425
  return (clock) => {
723
1426
  ring.position.y = TOP + 0.17 + Math.sin(clock * 2) * 0.022;
724
1427
  ring.rotation.z = clock * 0.5;
@@ -732,7 +1435,7 @@ function halo(kit) {
732
1435
  });
733
1436
  }
734
1437
  function bow(kit) {
735
- return piece(kit, ({ add, keep, node }) => {
1438
+ return piece(kit, ({ add: add2, keep, node }) => {
736
1439
  const root = node({ at: [0.19, TOP - 0.06, 0.06], rotate: [0.25, 0.35, -0.42] });
737
1440
  const ribbon = keep(dots("#ff5fa2", "#ffffff"));
738
1441
  const loop = new Shape;
@@ -741,12 +1444,12 @@ function bow(kit) {
741
1444
  loop.bezierCurveTo(0.17, -0.08, 0.05, -0.08, 0, 0);
742
1445
  const loopGeometry = slab(loop, 0.04, 0.02);
743
1446
  for (const side of [-1, 1])
744
- add(loopGeometry, "#ffffff", {
1447
+ add2(loopGeometry, "#ffffff", {
745
1448
  at: [side * 0.085, 0.01, 0],
746
1449
  rotate: [0, side === 1 ? 0 : Math.PI, side * 0.05],
747
1450
  parent: root
748
1451
  }, { map: ribbon, repeat: [9, 9], sheen: 0.35 });
749
- add(new SphereGeometry(0.045, 16, 12), "#ff4f95", { at: [0, 0.01, 0.015], scale: [1, 1.15, 0.8], parent: root }, { sheen: 0.4 });
1452
+ add2(new SphereGeometry(0.045, 16, 12), "#ff4f95", { at: [0, 0.01, 0.015], scale: [1, 1.15, 0.8], parent: root }, { sheen: 0.4 });
750
1453
  const tail = new Shape;
751
1454
  tail.moveTo(-0.025, 0);
752
1455
  tail.lineTo(0.025, 0);
@@ -757,14 +1460,14 @@ function bow(kit) {
757
1460
  const tailGeometry = slab(tail, 0.012, 0.006);
758
1461
  const tails = [-1, 1].map((side) => {
759
1462
  const hang = node({ at: [side * 0.02, -0.02, 0.01], parent: root });
760
- add(tailGeometry, "#ffffff", { at: [0, -0.07, 0], parent: hang }, { map: ribbon, repeat: [9, 9], sheen: 0.35 });
1463
+ add2(tailGeometry, "#ffffff", { at: [0, -0.07, 0], parent: hang }, { map: ribbon, repeat: [9, 9], sheen: 0.35 });
761
1464
  return { hang, side, spring: new Spring(60, 5) };
762
1465
  });
763
1466
  return (clock, delta, raw) => {
764
1467
  const motion = calm(raw);
765
1468
  for (const t of tails) {
766
- t.hang.rotation.z = t.spring.step(t.side * 0.35 - motion.yaw * 0.05 + Math.sin(clock * 1.6 + t.side) * 0.05, delta);
767
- t.hang.rotation.x = clamp(motion.lift * 0.08, -0.4, 0.4);
1469
+ t.hang.rotation.z = t.spring.step(t.side * 0.35 - motion.yaw * 0.06 - motion.swayX * 0.25 + Math.sin(clock * 1.6 + t.side) * 0.05, delta);
1470
+ t.hang.rotation.x = clamp(motion.lift * 0.12 - motion.swayZ * 0.15, -0.45, 0.45);
768
1471
  }
769
1472
  };
770
1473
  });
@@ -844,57 +1547,69 @@ function aLineSkirtPatch(kit, bottom, top, flareOut, pleatCount, pleatAmp, rows
844
1547
  function pleatedSkirt(kit) {
845
1548
  const z = zonesOf(kit);
846
1549
  const surf = surfaceOf(kit);
847
- return piece(kit, ({ add, keep }) => {
1550
+ return piece(kit, ({ add: add2, keep }) => {
848
1551
  const top = kit.isFigure ? z.waistY + 0.02 : 0.25;
849
1552
  const bottom = kit.isFigure ? z.bottomY - 0.14 : 0.02;
850
- const geometry = aLineSkirtPatch(kit, bottom, top, kit.isFigure ? 0.11 : 0.09, 22, 0.026, 10, 88);
1553
+ const geometry = aLineSkirtPatch(kit, bottom, top, kit.isFigure ? 0.15 : 0.09, 22, 0.026, 10, 88);
851
1554
  const position = geometry.attributes.position;
852
1555
  const rest = Float32Array.from(position.array);
853
- add(geometry, "#ffffff", {}, {
1556
+ add2(geometry, "#ffffff", {}, {
854
1557
  map: keep(tartan("#c8323c", "#1b1f5e", "#f2d24b")),
855
1558
  repeat: [6, 1.4],
856
1559
  double: true,
857
1560
  back: "#7d1d2a"
858
1561
  });
859
- add(fittedPatch(kit, top - 0.032, top + 0.014, 0.028, (_y, t) => t * Math.PI * 2, 3, 48), "#1b1f5e", {}, { double: true, outline: false });
860
- add(aLineSkirtPatch(kit, bottom, bottom + 0.028, kit.isFigure ? 0.114 : 0.094, 22, 0.026, 2, 88), "#fbf8ff", {}, { double: true, outline: false });
1562
+ add2(fittedPatch(kit, top - 0.032, top + 0.014, 0.028, (_y, t) => t * Math.PI * 2, 3, 48), "#1b1f5e", {}, { double: true, outline: false });
1563
+ const hemGeo = aLineSkirtPatch(kit, bottom, bottom + 0.028, kit.isFigure ? 0.154 : 0.094, 22, 0.026, 2, 88);
1564
+ const hemPos = hemGeo.attributes.position;
1565
+ const hemRest = Float32Array.from(hemPos.array);
1566
+ add2(hemGeo, "#fbf8ff", {}, { double: true, outline: false });
861
1567
  const frontBtn = surf(top - 0.008, 0.18, 0.034);
862
- add(new SphereGeometry(0.016, 10, 8), "#f2c94c", { at: [frontBtn.x, top - 0.008, frontBtn.z] }, { sheen: 0.8, outline: false });
863
- const flare = new Spring(70, 6);
864
- const sway = new Spring(50, 5);
865
- return (clock, delta, raw) => {
866
- const motion = calm(raw);
867
- const out = flare.step(clamp(-motion.lift * 0.05, -0.04, 0.14), delta);
868
- const turn = sway.step(-motion.yaw * 0.05, delta);
869
- for (let i = 0;i < position.count; i += 1) {
870
- const x = rest[i * 3] ?? 0;
871
- const y = rest[i * 3 + 1] ?? 0;
872
- const z0 = rest[i * 3 + 2] ?? 0;
1568
+ add2(new SphereGeometry(0.016, 10, 8), "#f2c94c", { at: [frontBtn.x, top - 0.008, frontBtn.z] }, { sheen: 0.8, outline: false });
1569
+ const flare = new Spring(75, 3.4);
1570
+ const sway = new Spring(60, 3.2);
1571
+ const shiftX = new Spring(65, 3.2);
1572
+ const shiftZ = new Spring(65, 3.4);
1573
+ const deform = (pAttr, base, geo, out, turn, lagX, lagZ, clock) => {
1574
+ for (let i = 0;i < pAttr.count; i += 1) {
1575
+ const x = base[i * 3] ?? 0;
1576
+ const y = base[i * 3 + 1] ?? 0;
1577
+ const z0 = base[i * 3 + 2] ?? 0;
873
1578
  const low = clamp((top - y) / Math.max(0.05, top - bottom), 0, 1);
1579
+ const low2 = low * low;
874
1580
  const angle = Math.atan2(x, z0);
875
- const spread = 1 + out * low * low;
876
- const lag = turn * low + Math.sin(clock * 2 + angle * 2) * 0.006 * low;
1581
+ const spread = 1 + out * low2;
1582
+ const lag = turn * low + Math.sin(clock * 2.4 + angle * 2) * 0.008 * low;
877
1583
  const r = Math.hypot(x, z0) * spread;
878
- position.setXYZ(i, Math.sin(angle + lag) * r, y, Math.cos(angle + lag) * r);
1584
+ pAttr.setXYZ(i, Math.sin(angle + lag) * r + lagX * low2, y + Math.abs(out) * 0.022 * low2, Math.cos(angle + lag) * r + lagZ * low2);
879
1585
  }
880
- position.needsUpdate = true;
881
- geometry.computeVertexNormals();
1586
+ pAttr.needsUpdate = true;
1587
+ geo.computeVertexNormals();
1588
+ };
1589
+ return (clock, delta, raw) => {
1590
+ const motion = calm(raw);
1591
+ const out = flare.step(clamp(-motion.lift * 0.12 + Math.abs(motion.swayX) * 0.08, -0.05, 0.28), delta);
1592
+ const turn = sway.step(-motion.yaw * 0.08, delta);
1593
+ const lagX = shiftX.step(-motion.swayX * 0.08, delta);
1594
+ const lagZ = shiftZ.step(-motion.swayZ * 0.06, delta);
1595
+ deform(position, rest, geometry, out, turn, lagX, lagZ, clock);
1596
+ deform(hemPos, hemRest, hemGeo, out, turn, lagX, lagZ, clock);
882
1597
  };
883
1598
  });
884
1599
  }
885
1600
  function tuxedo(kit) {
886
1601
  const z = zonesOf(kit);
887
1602
  const surf = surfaceOf(kit);
888
- return piece(kit, ({ add, keep, node }) => {
1603
+ return piece(kit, ({ add: add2, keep, node }) => {
889
1604
  const bottom = kit.isFigure ? z.hipY - 0.04 : 0.03;
890
1605
  const button = kit.isFigure ? z.waistY + 0.02 : 0.15;
891
1606
  const collar = kit.isFigure ? z.shoulderY + 0.04 : 0.34;
892
1607
  const bowY = kit.isFigure ? collar - 0.04 : COLLAR_Y;
893
1608
  const open = (y) => y > button ? 0.14 + (y - button) / Math.max(0.05, collar - button) * 0.52 : 0.14 + (button - y) / Math.max(0.05, button - bottom) * 0.42;
894
- add(fittedPatch(kit, bottom, collar, 0.026, (y, t) => open(y) + t * (Math.PI * 2 - 2 * open(y))), "#1b1830", {}, { double: true, back: "#3b2a6b", sheen: 0.15 });
895
- add(fittedPatch(kit, bottom + 0.02, collar - 0.01, 0.014, (y, t) => (t * 2 - 1) * (open(y) + 0.04), 16, 16), "#ffffff", {}, { map: keep(pleats()), repeat: [3, 1], outline: false });
1609
+ add2(fittedPatch(kit, bottom, collar, 0.026, (y, t) => open(y) + t * (Math.PI * 2 - 2 * open(y))), "#1b1830", {}, { double: true, back: "#3b2a6b", sheen: 0.15 });
1610
+ add2(fittedPatch(kit, bottom + 0.02, collar - 0.01, 0.014, (y, t) => (t * 2 - 1) * (open(y) + 0.04), 16, 16), "#ffffff", {}, { map: keep(pleats()), repeat: [3, 1], outline: false });
896
1611
  for (const side of [-1, 1])
897
- add(fittedPatch(kit, button + 0.005, collar, 0.032, (y, t) => side * (open(y) + t * (0.05 + (y - button) / Math.max(0.05, collar - button) * 0.16)), 10, 4), "#3b3560", {}, { sheen: 0.6, double: true });
1612
+ add2(fittedPatch(kit, button + 0.005, collar, 0.032, (y, t) => side * (open(y) + t * (0.05 + (y - button) / Math.max(0.05, collar - button) * 0.16)), 10, 4), "#3b3560", {}, { sheen: 0.6, double: true });
898
1613
  const frontZ = (y) => surf(y, 0, 0.028).z;
899
1614
  const wing = new Shape;
900
1615
  wing.moveTo(0, 0.01);
@@ -904,12 +1619,12 @@ function tuxedo(kit) {
904
1619
  wing.closePath();
905
1620
  const wingGeometry = slab(wing, 0.018, 0.007);
906
1621
  for (const side of [-1, 1])
907
- add(wingGeometry, "#14102e", {
1622
+ add2(wingGeometry, "#14102e", {
908
1623
  at: [side * 0.042, bowY, frontZ(bowY) + 0.008],
909
1624
  rotate: [0, side === 1 ? 0 : Math.PI, side * -0.06]
910
1625
  }, { sheen: 0.55 });
911
- add(new SphereGeometry(0.02, 12, 10), "#2e2a4a", { at: [0, bowY, frontZ(bowY) + 0.016], scale: [1, 1.2, 0.8] }, { sheen: 0.55 });
912
- add(new CylinderGeometry(0.018, 0.018, 0.01, 16), "#14102e", { at: [0, button, frontZ(button) + 0.002], rotate: [Math.PI / 2, 0, 0] }, { sheen: 0.8 });
1626
+ add2(new SphereGeometry(0.02, 12, 10), "#2e2a4a", { at: [0, bowY, frontZ(bowY) + 0.016], scale: [1, 1.2, 0.8] }, { sheen: 0.55 });
1627
+ add2(new CylinderGeometry(0.018, 0.018, 0.01, 16), "#14102e", { at: [0, button, frontZ(button) + 0.002], rotate: [Math.PI / 2, 0, 0] }, { sheen: 0.8 });
913
1628
  const tail = new Shape;
914
1629
  tail.moveTo(-0.055, 0);
915
1630
  tail.lineTo(0.055, 0);
@@ -924,13 +1639,13 @@ function tuxedo(kit) {
924
1639
  at: [side * 0.07, bottom + 0.06, backPt.z],
925
1640
  rotate: [0, Math.PI + side * -0.18, 0]
926
1641
  });
927
- add(tailGeometry, "#1b1830", { at: [0, -0.09, 0], parent: hang }, { sheen: 0.15 });
1642
+ add2(tailGeometry, "#1b1830", { at: [0, -0.09, 0], parent: hang }, { sheen: 0.15 });
928
1643
  return { hang, spring: new Spring(60, 5), side };
929
1644
  });
930
1645
  return (clock, delta, raw) => {
931
1646
  const motion = calm(raw);
932
1647
  for (const t of tails) {
933
- const kick = t.spring.step(-0.14 + clamp(-motion.lift * 0.12, -0.3, 0.5) + Math.abs(motion.yaw) * 0.04, delta);
1648
+ const kick = t.spring.step(-0.14 + clamp(-motion.lift * 0.14 - motion.swayZ * 0.12, -0.35, 0.55) + Math.abs(motion.yaw) * 0.05 + Math.abs(motion.swayX) * 0.12, delta);
934
1649
  t.hang.rotation.x = kick + Math.sin(clock * 1.5 + t.side) * 0.02;
935
1650
  }
936
1651
  };
@@ -939,7 +1654,7 @@ function tuxedo(kit) {
939
1654
  function heroCape(kit) {
940
1655
  const z = zonesOf(kit);
941
1656
  const surf = surfaceOf(kit);
942
- return piece(kit, ({ add }) => {
1657
+ return piece(kit, ({ add: add2 }) => {
943
1658
  const top = kit.isFigure ? z.shoulderY + 0.04 : 0.6;
944
1659
  const bottom = kit.isFigure ? -0.1 : 0;
945
1660
  const across = Math.PI * 0.95;
@@ -981,8 +1696,8 @@ function heroCape(kit) {
981
1696
  geometry.computeVertexNormals();
982
1697
  };
983
1698
  drape(0, 0, 0);
984
- add(geometry, "#c8323c", {}, { double: true, back: "#f2c94c", sheen: 0.2 });
985
- add(fittedPatch(kit, top - 0.04, top + 0.06, 0.045, (_y, t) => Math.PI * 0.42 + t * (Math.PI * 2 - Math.PI * 0.84), 3, 24), "#9e1f2c", {}, { double: true, back: "#f2c94c" });
1699
+ add2(geometry, "#c8323c", {}, { double: true, back: "#f2c94c", sheen: 0.2 });
1700
+ add2(fittedPatch(kit, top - 0.04, top + 0.06, 0.045, (_y, t) => Math.PI * 0.42 + t * (Math.PI * 2 - Math.PI * 0.84), 3, 24), "#9e1f2c", {}, { double: true, back: "#f2c94c" });
986
1701
  const clasp = new Shape;
987
1702
  for (let i = 0;i < 10; i += 1) {
988
1703
  const a = i / 10 * Math.PI * 2;
@@ -997,29 +1712,29 @@ function heroCape(kit) {
997
1712
  for (const side of [-1, 1]) {
998
1713
  const angle = side * (Math.PI / 2 - 0.22);
999
1714
  const pt = surf(top - 0.02, angle, 0.04);
1000
- add(star, "#f2c94c", { at: [pt.x, top - 0.02, pt.z], rotate: [0, angle, 0] }, { sheen: 0.85 });
1715
+ add2(star, "#f2c94c", { at: [pt.x, top - 0.02, pt.z], rotate: [0, angle, 0] }, { sheen: 0.85 });
1001
1716
  }
1002
- const flare = new Spring(40, 4);
1003
- const trail = new Spring(35, 4);
1717
+ const flare = new Spring(48, 3.2);
1718
+ const trail = new Spring(42, 3.2);
1004
1719
  return (clock, delta, raw) => {
1005
1720
  const motion = calm(raw);
1006
- const out = flare.step(clamp(Math.abs(motion.yaw) * 0.03 + Math.max(0, -motion.lift) * 0.06, 0, 0.25), delta);
1007
- drape(clock, out, trail.step(-motion.yaw * 0.06, delta));
1721
+ const out = flare.step(clamp(Math.abs(motion.yaw) * 0.04 + Math.max(0, -motion.lift) * 0.08 + Math.abs(motion.swayX) * 0.08 - motion.swayZ * 0.06, 0, 0.32), delta);
1722
+ drape(clock, out, trail.step(-motion.yaw * 0.07 - motion.swayX * 0.18, delta));
1008
1723
  };
1009
1724
  });
1010
1725
  }
1011
1726
  function scarf(kit) {
1012
1727
  const z = zonesOf(kit);
1013
1728
  const surf = surfaceOf(kit);
1014
- return piece(kit, ({ add, keep, node }) => {
1729
+ return piece(kit, ({ add: add2, keep, node }) => {
1015
1730
  const wool = keep(knit("#e2574c", "#fbf8ff"));
1016
1731
  const y = kit.isFigure ? z.neckY - 0.03 : COLLAR_Y;
1017
1732
  const r = Math.max(0.11, kit.radiusAt(y)) + 0.025;
1018
- add(new TorusGeometry(r, kit.isFigure ? 0.048 : 0.058, 14, 64), "#ffffff", { at: [0, y, 0], rotate: [Math.PI / 2, 0, 0], scale: [1, DEPTH, 1.05] }, { map: wool, repeat: [14, 1] });
1733
+ add2(new TorusGeometry(r, kit.isFigure ? 0.048 : 0.058, 14, 64), "#ffffff", { at: [0, y, 0], rotate: [Math.PI / 2, 0, 0], scale: [1, DEPTH, 1.05] }, { map: wool, repeat: [14, 1] });
1019
1734
  const knotAngle = 0.52;
1020
1735
  const knotPt = surf(y, knotAngle, 0.045);
1021
1736
  const knotAt = [knotPt.x, y - 0.01, knotPt.z];
1022
- add(new SphereGeometry(0.05, 16, 12), "#ffffff", { at: knotAt, scale: [1, 0.85, 0.75] }, { map: wool, repeat: [3, 1] });
1737
+ add2(new SphereGeometry(0.05, 16, 12), "#ffffff", { at: knotAt, scale: [1, 0.85, 0.75] }, { map: wool, repeat: [3, 1] });
1023
1738
  const strip = new CylinderGeometry(0.046, 0.05, 0.26, 12, 6);
1024
1739
  strip.scale(1, 1, 0.35);
1025
1740
  const fringeGeo = new CylinderGeometry(0.006, 0.004, 0.04, 5);
@@ -1031,16 +1746,16 @@ function scarf(kit) {
1031
1746
  at: [knotAt[0] + x, knotAt[1] - 0.02, knotAt[2] + 0.02],
1032
1747
  rotate: [0.12, knotAngle * 0.6, tilt]
1033
1748
  });
1034
- add(strip, "#ffffff", { at: [0, -0.13 * length, 0], scale: [1, length, 1], parent: hang }, { map: wool, repeat: [2, 2] });
1749
+ add2(strip, "#ffffff", { at: [0, -0.13 * length, 0], scale: [1, length, 1], parent: hang }, { map: wool, repeat: [2, 2] });
1035
1750
  for (let i = 0;i < 5; i += 1)
1036
- add(fringeGeo, "#e2574c", { at: [-0.036 + i * 0.018, -0.26 * length - 0.02, 0], parent: hang }, { outline: false });
1751
+ add2(fringeGeo, "#e2574c", { at: [-0.036 + i * 0.018, -0.26 * length - 0.02, 0], parent: hang }, { outline: false });
1037
1752
  return { hang, tilt, spring: new Spring(55, 5, tilt) };
1038
1753
  });
1039
1754
  return (clock, delta, raw) => {
1040
1755
  const motion = calm(raw);
1041
1756
  tails.forEach((t, i) => {
1042
- t.hang.rotation.z = t.spring.step(t.tilt - motion.yaw * 0.05 + Math.sin(clock * 1.8 + i) * 0.03, delta);
1043
- t.hang.rotation.x = 0.12 + clamp(motion.lift * 0.1, -0.3, 0.5);
1757
+ t.hang.rotation.z = t.spring.step(t.tilt - motion.yaw * 0.06 - motion.swayX * 0.24 + Math.sin(clock * 1.8 + i) * 0.03, delta);
1758
+ t.hang.rotation.x = 0.12 + clamp(motion.lift * 0.12 - motion.swayZ * 0.14, -0.35, 0.55);
1044
1759
  });
1045
1760
  };
1046
1761
  });
@@ -1048,85 +1763,97 @@ function scarf(kit) {
1048
1763
  function ribbonDress(kit) {
1049
1764
  const z = zonesOf(kit);
1050
1765
  const surf = surfaceOf(kit);
1051
- return piece(kit, ({ add, keep, node }) => {
1766
+ return piece(kit, ({ add: add2, keep, node }) => {
1052
1767
  const bodiceTop = kit.isFigure ? z.bustY + 0.09 : 0.36;
1053
1768
  const waist = kit.isFigure ? z.waistY : 0.24;
1054
1769
  const hem = kit.isFigure ? z.bottomY - 0.16 : 0.02;
1055
- add(fittedPatch(kit, waist, bodiceTop, 0.028, (_y, t) => t * Math.PI * 2, 20, 56), "#ff6fa8", {}, { double: true, back: "#c43f76", sheen: 0.32 });
1056
- add(fittedPatch(kit, bodiceTop - 0.022, bodiceTop + 0.008, 0.033, (_y, t) => t * Math.PI * 2, 2, 56), "#fff7fb", {}, { double: true, outline: false });
1770
+ add2(fittedPatch(kit, waist, bodiceTop, 0.028, (_y, t) => t * Math.PI * 2, 20, 56), "#ff6fa8", {}, { double: true, back: "#c43f76", sheen: 0.32 });
1771
+ add2(fittedPatch(kit, bodiceTop - 0.022, bodiceTop + 0.008, 0.033, (_y, t) => t * Math.PI * 2, 2, 56), "#fff7fb", {}, { double: true, outline: false });
1057
1772
  if (kit.isFigure) {
1058
1773
  for (const side of [-1, 1]) {
1059
1774
  const shPt = surf(z.shoulderY, side * 1.15, 0.015);
1060
- add(new SphereGeometry(0.055, 14, 12), "#fff7fb", { at: [shPt.x, z.shoulderY - 0.02, shPt.z], scale: [1.1, 0.85, 1] }, { sheen: 0.25 });
1775
+ add2(new SphereGeometry(0.055, 14, 12), "#fff7fb", { at: [shPt.x, z.shoulderY - 0.02, shPt.z], scale: [1.1, 0.85, 1] }, { sheen: 0.25 });
1061
1776
  }
1062
1777
  }
1063
- add(fittedPatch(kit, waist - 0.026, waist + 0.024, 0.032, (_y, t) => t * Math.PI * 2, 3, 56), "#fff7fb", {}, { double: true, sheen: 0.45 });
1778
+ add2(fittedPatch(kit, waist - 0.026, waist + 0.024, 0.032, (_y, t) => t * Math.PI * 2, 3, 56), "#fff7fb", {}, { double: true, sheen: 0.45 });
1064
1779
  const frontW = surf(waist, 0, 0.04);
1065
1780
  const bowNode = node({ at: [frontW.x, waist, frontW.z] });
1066
1781
  const loopGeo = new TorusGeometry(0.038, 0.013, 10, 20);
1067
1782
  for (const side of [-1, 1])
1068
- add(loopGeo, "#ff3d8b", {
1783
+ add2(loopGeo, "#ff3d8b", {
1069
1784
  at: [side * 0.04, 0, 0],
1070
1785
  rotate: [0, 0, side * 0.3],
1071
1786
  scale: [1.15, 0.72, 0.55],
1072
1787
  parent: bowNode
1073
1788
  }, { sheen: 0.5 });
1074
- add(new SphereGeometry(0.018, 10, 8), "#ff3d8b", { parent: bowNode }, { sheen: 0.5 });
1075
- const skirtGeo = aLineSkirtPatch(kit, hem, waist, kit.isFigure ? 0.14 : 0.1, 16, 0.02, 10, 72);
1789
+ add2(new SphereGeometry(0.018, 10, 8), "#ff3d8b", { parent: bowNode }, { sheen: 0.5 });
1790
+ const skirtGeo = aLineSkirtPatch(kit, hem, waist, kit.isFigure ? 0.185 : 0.1, 16, 0.02, 10, 72);
1076
1791
  const pos = skirtGeo.attributes.position;
1077
1792
  const rest = Float32Array.from(pos.array);
1078
- add(skirtGeo, "#ff6fa8", {}, {
1793
+ add2(skirtGeo, "#ff6fa8", {}, {
1079
1794
  map: keep(dots("#ff7eb6", "#ffe3f0")),
1080
1795
  repeat: [8, 3],
1081
1796
  double: true,
1082
1797
  back: "#ffe8f3",
1083
1798
  sheen: 0.22
1084
1799
  });
1085
- add(aLineSkirtPatch(kit, hem - 0.032, hem + 0.025, kit.isFigure ? 0.145 : 0.105, 22, 0.016, 3, 72), "#fffaff", {}, { double: true, outline: false });
1086
- const flare = new Spring(65, 5.5);
1087
- return (clock, delta, raw) => {
1088
- const motion = calm(raw);
1089
- const out = flare.step(clamp(-motion.lift * 0.06, -0.03, 0.15), delta);
1090
- for (let i = 0;i < pos.count; i += 1) {
1091
- const x = rest[i * 3] ?? 0;
1092
- const y = rest[i * 3 + 1] ?? 0;
1093
- const z0 = rest[i * 3 + 2] ?? 0;
1094
- const low = clamp((waist - y) / Math.max(0.05, waist - hem), 0, 1);
1800
+ const pettiGeo = aLineSkirtPatch(kit, hem - 0.032, hem + 0.025, kit.isFigure ? 0.19 : 0.105, 22, 0.016, 3, 72);
1801
+ const pettiPos = pettiGeo.attributes.position;
1802
+ const pettiRest = Float32Array.from(pettiPos.array);
1803
+ add2(pettiGeo, "#fffaff", {}, { double: true, outline: false });
1804
+ const flare = new Spring(75, 3.2);
1805
+ const swayX = new Spring(65, 3);
1806
+ const swayZ = new Spring(65, 3.3);
1807
+ const deform = (pAttr, base, geo, out, lagX, lagZ, clock) => {
1808
+ for (let i = 0;i < pAttr.count; i += 1) {
1809
+ const x = base[i * 3] ?? 0;
1810
+ const y = base[i * 3 + 1] ?? 0;
1811
+ const z0 = base[i * 3 + 2] ?? 0;
1812
+ const low = clamp((waist - y) / Math.max(0.05, waist - hem), 0, 1.12);
1813
+ const low2 = low * low;
1095
1814
  const a = Math.atan2(x, z0);
1096
- const r = Math.hypot(x, z0) * (1 + out * low * low + Math.sin(clock * 2.2 + a * 3) * 0.008 * low);
1097
- pos.setXYZ(i, Math.sin(a) * r, y, Math.cos(a) * r);
1815
+ const r = Math.hypot(x, z0) * (1 + out * low2 + Math.sin(clock * 2.5 + a * 3) * 0.01 * low);
1816
+ pAttr.setXYZ(i, Math.sin(a) * r + lagX * low2, y + Math.abs(out) * 0.025 * low2, Math.cos(a) * r + lagZ * low2);
1098
1817
  }
1099
- pos.needsUpdate = true;
1100
- skirtGeo.computeVertexNormals();
1818
+ pAttr.needsUpdate = true;
1819
+ geo.computeVertexNormals();
1820
+ };
1821
+ return (clock, delta, raw) => {
1822
+ const motion = calm(raw);
1823
+ const out = flare.step(clamp(-motion.lift * 0.12 + Math.abs(motion.swayX) * 0.08, -0.05, 0.28), delta);
1824
+ const lagX = swayX.step(-motion.swayX * 0.085 - motion.yaw * 0.018, delta);
1825
+ const lagZ = swayZ.step(-motion.swayZ * 0.06, delta);
1826
+ deform(pos, rest, skirtGeo, out, lagX, lagZ, clock);
1827
+ deform(pettiPos, pettiRest, pettiGeo, out, lagX, lagZ, clock);
1101
1828
  };
1102
1829
  });
1103
1830
  }
1104
1831
  function cropHoodie(kit) {
1105
1832
  const z = zonesOf(kit);
1106
1833
  const surf = surfaceOf(kit);
1107
- return piece(kit, ({ add, node }) => {
1834
+ return piece(kit, ({ add: add2, node }) => {
1108
1835
  const bottom = kit.isFigure ? z.waistY + 0.06 : 0.2;
1109
1836
  const top = kit.isFigure ? z.shoulderY + 0.06 : 0.39;
1110
- add(fittedPatch(kit, bottom, top, (v) => 0.03 + (1 - v) * 0.012, (_y, t) => t * Math.PI * 2, 18, 56), "#d8b8ff", {}, { double: true, back: "#8f6ec4", sheen: 0.1 });
1111
- add(fittedPatch(kit, bottom - 0.022, bottom + 0.012, 0.036, (_y, t) => t * Math.PI * 2, 3, 56), "#fffaff", {}, { double: true, outline: false });
1837
+ add2(fittedPatch(kit, bottom, top, (v) => 0.03 + (1 - v) * 0.012, (_y, t) => t * Math.PI * 2, 18, 56), "#d8b8ff", {}, { double: true, back: "#8f6ec4", sheen: 0.1 });
1838
+ add2(fittedPatch(kit, bottom - 0.022, bottom + 0.012, 0.036, (_y, t) => t * Math.PI * 2, 3, 56), "#fffaff", {}, { double: true, outline: false });
1112
1839
  const neckY = kit.isFigure ? z.neckY - 0.02 : top;
1113
1840
  const backPt = surf(neckY, Math.PI, 0.05);
1114
- add(new SphereGeometry(kit.isFigure ? 0.12 : 0.16, 16, 12), "#c69eff", { at: [0, neckY - 0.01, backPt.z - 0.05], scale: [1.35, 0.72, 0.95] }, { sheen: 0.1 });
1841
+ add2(new SphereGeometry(kit.isFigure ? 0.12 : 0.16, 16, 12), "#c69eff", { at: [0, neckY - 0.01, backPt.z - 0.05], scale: [1.35, 0.72, 0.95] }, { sheen: 0.1 });
1115
1842
  if (kit.isFigure) {
1116
- add(fittedPatch(kit, z.bottomY - 0.02, z.hipY + 0.09, 0.024, (_y, t) => t * Math.PI * 2, 12, 56), "#2c2448", {}, { double: true });
1843
+ add2(fittedPatch(kit, z.bottomY - 0.02, z.hipY + 0.09, 0.024, (_y, t) => t * Math.PI * 2, 12, 56), "#2c2448", {}, { double: true });
1117
1844
  }
1118
1845
  const frontNeck = surf(top - 0.02, 0, 0.04);
1119
1846
  const strings = [-1, 1].map((side) => {
1120
1847
  const hang = node({ at: [side * 0.042, top - 0.02, frontNeck.z] });
1121
- add(new CylinderGeometry(0.008, 0.008, 0.14, 8), "#fffaff", { at: [0, -0.07, 0], parent: hang }, { outline: false });
1122
- add(new SphereGeometry(0.013, 8, 8), "#ff7eb8", { at: [0, -0.14, 0], parent: hang }, { outline: false });
1848
+ add2(new CylinderGeometry(0.008, 0.008, 0.14, 8), "#fffaff", { at: [0, -0.07, 0], parent: hang }, { outline: false });
1849
+ add2(new SphereGeometry(0.013, 8, 8), "#ff7eb8", { at: [0, -0.14, 0], parent: hang }, { outline: false });
1123
1850
  return { hang, side, spring: new Spring(60, 4.5) };
1124
1851
  });
1125
1852
  return (clock, delta, raw) => {
1126
1853
  const motion = calm(raw);
1127
1854
  for (const s of strings) {
1128
- s.hang.rotation.z = s.spring.step(-motion.yaw * 0.04 + Math.sin(clock * 2.1 + s.side) * 0.05, delta);
1129
- s.hang.rotation.x = clamp(motion.lift * 0.08, -0.25, 0.35);
1855
+ s.hang.rotation.z = s.spring.step(-motion.yaw * 0.05 - motion.swayX * 0.24 + Math.sin(clock * 2.1 + s.side) * 0.05, delta);
1856
+ s.hang.rotation.x = clamp(motion.lift * 0.1 - motion.swayZ * 0.12, -0.3, 0.4);
1130
1857
  }
1131
1858
  };
1132
1859
  });
@@ -1134,54 +1861,84 @@ function cropHoodie(kit) {
1134
1861
  function idolSet(kit) {
1135
1862
  const z = zonesOf(kit);
1136
1863
  const surf = surfaceOf(kit);
1137
- return piece(kit, ({ add, node }) => {
1864
+ return piece(kit, ({ add: add2, node }) => {
1138
1865
  const topBottom = kit.isFigure ? z.waistY + 0.05 : 0.24;
1139
1866
  const topHigh = kit.isFigure ? z.shoulderY + 0.05 : 0.38;
1140
1867
  const skirtTop = kit.isFigure ? z.waistY - 0.01 : 0.22;
1141
1868
  const skirtBot = kit.isFigure ? z.bottomY - 0.12 : 0.02;
1142
- add(fittedPatch(kit, topBottom, topHigh, 0.028, (_y, t) => t * Math.PI * 2, 16, 56), "#ffffff", {}, { double: true, sheen: 0.2 });
1143
- add(fittedPatch(kit, topHigh - 0.1, topHigh + 0.01, 0.034, (_y, t) => t * Math.PI * 2, 6, 56), "#1f2b6c", {}, { double: true });
1144
- add(fittedPatch(kit, topHigh - 0.09, topHigh - 0.075, 0.038, (_y, t) => t * Math.PI * 2, 2, 56), "#ffd84d", {}, { double: true, outline: false, sheen: 0.7 });
1869
+ add2(fittedPatch(kit, topBottom, topHigh, 0.028, (_y, t) => t * Math.PI * 2, 16, 56), "#ffffff", {}, { double: true, sheen: 0.2 });
1870
+ add2(fittedPatch(kit, topHigh - 0.1, topHigh + 0.01, 0.034, (_y, t) => t * Math.PI * 2, 6, 56), "#1f2b6c", {}, { double: true });
1871
+ add2(fittedPatch(kit, topHigh - 0.09, topHigh - 0.075, 0.038, (_y, t) => t * Math.PI * 2, 2, 56), "#ffd84d", {}, { double: true, outline: false, sheen: 0.7 });
1145
1872
  const chest = surf(topHigh - 0.09, 0, 0.045);
1146
1873
  const bow2 = node({ at: [0, topHigh - 0.09, chest.z] });
1147
1874
  const loop = new TorusGeometry(0.038, 0.013, 10, 20);
1148
1875
  for (const side of [-1, 1]) {
1149
- add(loop, "#ff3b6b", { at: [side * 0.038, 0, 0], scale: [1.15, 0.75, 0.5], parent: bow2 }, { sheen: 0.45 });
1150
- add(new CylinderGeometry(0.015, 0.022, 0.095, 8), "#ff3b6b", {
1876
+ add2(loop, "#ff3b6b", { at: [side * 0.038, 0, 0], scale: [1.15, 0.75, 0.5], parent: bow2 }, { sheen: 0.45 });
1877
+ add2(new CylinderGeometry(0.015, 0.022, 0.095, 8), "#ff3b6b", {
1151
1878
  at: [side * 0.024, -0.055, 0],
1152
1879
  rotate: [0, 0, side * 0.24],
1153
1880
  scale: [1, 1, 0.3],
1154
1881
  parent: bow2
1155
1882
  }, { outline: false });
1156
1883
  }
1157
- add(aLineSkirtPatch(kit, skirtBot, skirtTop, kit.isFigure ? 0.11 : 0.085, 22, 0.02, 8, 72), "#1f2b6c", {}, { double: true, back: "#ff6fa8" });
1158
- add(aLineSkirtPatch(kit, skirtBot + 0.016, skirtBot + 0.038, kit.isFigure ? 0.105 : 0.08, 22, 0.018, 2, 72), "#ffd84d", {}, { double: true, outline: false, sheen: 0.75 });
1159
- return;
1884
+ const idolSkirtGeo = aLineSkirtPatch(kit, skirtBot, skirtTop, kit.isFigure ? 0.155 : 0.085, 22, 0.02, 8, 72);
1885
+ const idolRest = new Float32Array(idolSkirtGeo.attributes.position.array);
1886
+ const idolPos = idolSkirtGeo.attributes.position;
1887
+ add2(idolSkirtGeo, "#1f2b6c", {}, { double: true, back: "#ff6fa8" });
1888
+ const trimGeo = aLineSkirtPatch(kit, skirtBot + 0.016, skirtBot + 0.038, kit.isFigure ? 0.15 : 0.08, 22, 0.018, 2, 72);
1889
+ const trimRest = new Float32Array(trimGeo.attributes.position.array);
1890
+ const trimPos = trimGeo.attributes.position;
1891
+ add2(trimGeo, "#ffd84d", {}, { double: true, outline: false, sheen: 0.75 });
1892
+ const flare = new Spring(80, 3.4);
1893
+ const swayX = new Spring(65, 3.2);
1894
+ const swayZ = new Spring(65, 3.5);
1895
+ const deform = (pAttr, base, geo, out, lx, lz, clock) => {
1896
+ for (let i = 0;i < pAttr.count; i += 1) {
1897
+ const x = base[i * 3] ?? 0;
1898
+ const y = base[i * 3 + 1] ?? 0;
1899
+ const z0 = base[i * 3 + 2] ?? 0;
1900
+ const low = clamp((skirtTop - y) / Math.max(0.05, skirtTop - skirtBot), 0, 1);
1901
+ const low2 = low * low;
1902
+ const a = Math.atan2(x, z0);
1903
+ const r = Math.hypot(x, z0) * (1 + out * low2 + Math.sin(clock * 2.6 + a * 3) * 0.008 * low);
1904
+ pAttr.setXYZ(i, Math.sin(a) * r + lx * low2, y + Math.abs(out) * 0.02 * low2, Math.cos(a) * r + lz * low2);
1905
+ }
1906
+ pAttr.needsUpdate = true;
1907
+ geo.computeVertexNormals();
1908
+ };
1909
+ return (clock, delta, raw) => {
1910
+ const motion = calm(raw);
1911
+ const out = flare.step(clamp(-motion.lift * 0.1 + Math.abs(motion.swayX) * 0.06, -0.05, 0.25), delta);
1912
+ const lx = swayX.step(-motion.swayX * 0.075 - motion.yaw * 0.015, delta);
1913
+ const lz = swayZ.step(-motion.swayZ * 0.055, delta);
1914
+ deform(idolPos, idolRest, idolSkirtGeo, out, lx, lz, clock);
1915
+ deform(trimPos, trimRest, trimGeo, out, lx, lz, clock);
1916
+ };
1160
1917
  });
1161
1918
  }
1162
1919
  function streetJacket(kit) {
1163
1920
  const z = zonesOf(kit);
1164
1921
  const surf = surfaceOf(kit);
1165
- return piece(kit, ({ add }) => {
1922
+ return piece(kit, ({ add: add2 }) => {
1166
1923
  const bottom = kit.isFigure ? z.hipY - 0.04 : 0.04;
1167
1924
  const top = kit.isFigure ? z.shoulderY + 0.06 : 0.39;
1168
1925
  if (kit.isFigure) {
1169
- add(fittedPatch(kit, z.bottomY - 0.03, z.waistY + 0.02, 0.022, (_y, t) => t * Math.PI * 2, 12, 48), "#161622", {}, { double: true });
1926
+ add2(fittedPatch(kit, z.bottomY - 0.03, z.waistY + 0.02, 0.022, (_y, t) => t * Math.PI * 2, 12, 48), "#161622", {}, { double: true });
1170
1927
  }
1171
- add(fittedPatch(kit, bottom + 0.02, top - 0.01, 0.026, (_y, t) => t * Math.PI * 2, 16, 48), "#181726", {}, { double: true });
1928
+ add2(fittedPatch(kit, bottom + 0.02, top - 0.01, 0.026, (_y, t) => t * Math.PI * 2, 16, 48), "#181726", {}, { double: true });
1172
1929
  const gap = 0.34;
1173
- add(fittedPatch(kit, bottom, top, (v) => 0.04 + (1 - v) * 0.008, (_y, t) => gap + t * (Math.PI * 2 - gap * 2), 18, 48), "#2c2f48", {}, { double: true, back: "#ff4f7a", sheen: 0.25 });
1930
+ add2(fittedPatch(kit, bottom, top, (v) => 0.04 + (1 - v) * 0.008, (_y, t) => gap + t * (Math.PI * 2 - gap * 2), 18, 48), "#2c2f48", {}, { double: true, back: "#ff4f7a", sheen: 0.25 });
1174
1931
  for (const side of [-1, 1]) {
1175
- add(fittedPatch(kit, bottom, top, 0.045, (_y, t) => side * (gap + t * 0.08), 12, 3), "#ff4f7a", {}, { double: true, outline: false });
1932
+ add2(fittedPatch(kit, bottom, top, 0.045, (_y, t) => side * (gap + t * 0.08), 12, 3), "#ff4f7a", {}, { double: true, outline: false });
1176
1933
  }
1177
- add(fittedPatch(kit, top - 0.02, top + 0.065, 0.042, (_y, t) => gap * 1.1 + t * (Math.PI * 2 - gap * 2.2), 4, 32), "#1b1d2e", {}, { double: true, back: "#ff4f7a" });
1934
+ add2(fittedPatch(kit, top - 0.02, top + 0.065, 0.042, (_y, t) => gap * 1.1 + t * (Math.PI * 2 - gap * 2.2), 4, 32), "#1b1d2e", {}, { double: true, back: "#ff4f7a" });
1178
1935
  const chainY = kit.isFigure ? z.bustY + 0.04 : top - 0.08;
1179
1936
  const bead = new SphereGeometry(0.011, 8, 8);
1180
1937
  for (let i = -5;i <= 5; i += 1) {
1181
1938
  const phi = i * 0.08;
1182
1939
  const drop = Math.cos(i / 5 * Math.PI * 0.5) * 0.065;
1183
1940
  const pt = surf(chainY - drop, phi, 0.036);
1184
- add(bead, "#e4ebff", { at: [pt.x, chainY - drop, pt.z] }, { sheen: 0.9, outline: false });
1941
+ add2(bead, "#e4ebff", { at: [pt.x, chainY - drop, pt.z] }, { sheen: 0.9, outline: false });
1185
1942
  }
1186
1943
  return;
1187
1944
  });
@@ -1189,27 +1946,27 @@ function streetJacket(kit) {
1189
1946
  function blazerCoat(kit) {
1190
1947
  const z = zonesOf(kit);
1191
1948
  const surf = surfaceOf(kit);
1192
- return piece(kit, ({ add }) => {
1949
+ return piece(kit, ({ add: add2 }) => {
1193
1950
  const bottom = kit.isFigure ? z.hipY - 0.05 : 0.03;
1194
1951
  const waist = kit.isFigure ? z.waistY + 0.02 : 0.18;
1195
1952
  const top = kit.isFigure ? z.shoulderY + 0.05 : 0.37;
1196
1953
  const vOpen = (y) => y > waist ? 0.1 + (y - waist) / Math.max(0.05, top - waist) * 0.45 : 0.06;
1197
1954
  if (kit.isFigure) {
1198
- add(fittedPatch(kit, z.bottomY - 0.03, z.waistY, 0.022, (_y, t) => t * Math.PI * 2, 10, 48), "#1c223c", {}, { double: true });
1955
+ add2(fittedPatch(kit, z.bottomY - 0.03, z.waistY, 0.022, (_y, t) => t * Math.PI * 2, 10, 48), "#1c223c", {}, { double: true });
1199
1956
  }
1200
- add(fittedPatch(kit, bottom + 0.02, top, 0.024, (_y, t) => t * Math.PI * 2, 16, 48), "#f8f9ff", {}, { double: true, outline: false });
1201
- add(fittedPatch(kit, bottom, top, 0.036, (y, t) => vOpen(y) + t * (Math.PI * 2 - 2 * vOpen(y)), 18, 48), "#232b4f", {}, { double: true, back: "#3c4a7d", sheen: 0.18 });
1957
+ add2(fittedPatch(kit, bottom + 0.02, top, 0.024, (_y, t) => t * Math.PI * 2, 16, 48), "#f8f9ff", {}, { double: true, outline: false });
1958
+ add2(fittedPatch(kit, bottom, top, 0.036, (y, t) => vOpen(y) + t * (Math.PI * 2 - 2 * vOpen(y)), 18, 48), "#232b4f", {}, { double: true, back: "#3c4a7d", sheen: 0.18 });
1202
1959
  for (const side of [-1, 1]) {
1203
- add(fittedPatch(kit, waist, top, 0.041, (y, t) => side * (vOpen(y) + t * 0.09), 10, 3), "#f2c94c", {}, { double: true, outline: false, sheen: 0.75 });
1960
+ add2(fittedPatch(kit, waist, top, 0.041, (y, t) => side * (vOpen(y) + t * 0.09), 10, 3), "#f2c94c", {}, { double: true, outline: false, sheen: 0.75 });
1204
1961
  }
1205
- add(fittedPatch(kit, waist - 0.02, top - 0.02, 0.034, (y, t) => {
1962
+ add2(fittedPatch(kit, waist - 0.02, top - 0.02, 0.034, (y, t) => {
1206
1963
  const w = y > top - 0.07 ? 0.08 : 0.12 - (y - waist) / Math.max(0.05, top - waist) * 0.05;
1207
1964
  return (t * 2 - 1) * w;
1208
1965
  }, 10, 6), "#d6354a", {}, { double: true });
1209
1966
  const btn = new SphereGeometry(0.014, 8, 8);
1210
1967
  for (const by of [waist, waist - 0.065]) {
1211
1968
  const pt = surf(by, 0.16, 0.042);
1212
- add(btn, "#f2c94c", { at: [pt.x, by, pt.z] }, { sheen: 0.85, outline: false });
1969
+ add2(btn, "#f2c94c", { at: [pt.x, by, pt.z] }, { sheen: 0.85, outline: false });
1213
1970
  }
1214
1971
  return;
1215
1972
  });
@@ -1217,36 +1974,36 @@ function blazerCoat(kit) {
1217
1974
  function brawlerVest(kit) {
1218
1975
  const z = zonesOf(kit);
1219
1976
  const surf = surfaceOf(kit);
1220
- return piece(kit, ({ add }) => {
1977
+ return piece(kit, ({ add: add2 }) => {
1221
1978
  const bottom = kit.isFigure ? z.waistY - 0.08 : 0.05;
1222
1979
  const top = kit.isFigure ? z.shoulderY + 0.03 : 0.36;
1223
1980
  if (kit.isFigure) {
1224
- add(fittedPatch(kit, z.bottomY - 0.04, z.waistY - 0.02, 0.026, (_y, t) => t * Math.PI * 2, 12, 48), "#2b2538", {}, { double: true });
1981
+ add2(fittedPatch(kit, z.bottomY - 0.04, z.waistY - 0.02, 0.026, (_y, t) => t * Math.PI * 2, 12, 48), "#2b2538", {}, { double: true });
1225
1982
  }
1226
- add(fittedPatch(kit, bottom, top, (v) => 0.028 + (v > 0.7 ? 0.008 : 0), (_y, t) => t * Math.PI * 2, 20, 56), "#232030", {}, { double: true, sheen: 0.12 });
1227
- add(fittedPatch(kit, (top + bottom) * 0.54, (top + bottom) * 0.65, 0.036, (_y, t) => t * Math.PI * 2, 4, 56), "#ff5733", {}, { double: true, outline: false });
1983
+ add2(fittedPatch(kit, bottom, top, (v) => 0.028 + (v > 0.7 ? 0.008 : 0), (_y, t) => t * Math.PI * 2, 20, 56), "#232030", {}, { double: true, sheen: 0.12 });
1984
+ add2(fittedPatch(kit, (top + bottom) * 0.54, (top + bottom) * 0.65, 0.036, (_y, t) => t * Math.PI * 2, 4, 56), "#ff5733", {}, { double: true, outline: false });
1228
1985
  const beltY = kit.isFigure ? z.waistY - 0.04 : 0.14;
1229
- add(fittedPatch(kit, beltY - 0.028, beltY + 0.028, 0.036, (_y, t) => t * Math.PI * 2, 3, 48), "#4a2b1d", {}, { double: true });
1986
+ add2(fittedPatch(kit, beltY - 0.028, beltY + 0.028, 0.036, (_y, t) => t * Math.PI * 2, 3, 48), "#4a2b1d", {}, { double: true });
1230
1987
  const bucklePt = surf(beltY, 0, 0.045);
1231
- add(new CylinderGeometry(0.032, 0.032, 0.016, 6), "#ffd24a", { at: [bucklePt.x, beltY, bucklePt.z], rotate: [Math.PI / 2, 0, 0] }, { sheen: 0.85 });
1988
+ add2(new CylinderGeometry(0.032, 0.032, 0.016, 6), "#ffd24a", { at: [bucklePt.x, beltY, bucklePt.z], rotate: [Math.PI / 2, 0, 0] }, { sheen: 0.85 });
1232
1989
  return;
1233
1990
  });
1234
1991
  }
1235
1992
  function martialGi(kit) {
1236
1993
  const z = zonesOf(kit);
1237
1994
  const surf = surfaceOf(kit);
1238
- return piece(kit, ({ add, node }) => {
1995
+ return piece(kit, ({ add: add2, node }) => {
1239
1996
  const bottom = kit.isFigure ? z.bottomY - 0.03 : 0.03;
1240
1997
  const waist = kit.isFigure ? z.waistY - 0.02 : 0.16;
1241
1998
  const top = kit.isFigure ? z.shoulderY + 0.04 : 0.37;
1242
1999
  const vOpen = (y) => y > waist ? 0.08 + (y - waist) / Math.max(0.05, top - waist) * 0.44 : 0;
1243
- add(fittedPatch(kit, bottom, top, (v) => 0.032 + (1 - v) * 0.014, (y, t) => vOpen(y) + t * (Math.PI * 2 - 2 * vOpen(y)), 20, 56), "#f4f1ea", {}, { double: true, back: "#d8d1c5" });
2000
+ add2(fittedPatch(kit, bottom, top, (v) => 0.032 + (1 - v) * 0.014, (y, t) => vOpen(y) + t * (Math.PI * 2 - 2 * vOpen(y)), 20, 56), "#f4f1ea", {}, { double: true, back: "#d8d1c5" });
1244
2001
  for (const side of [-1, 1]) {
1245
- add(fittedPatch(kit, waist, top, 0.038, (y, t) => side * (vOpen(y) + t * 0.1), 10, 3), "#1b2042", {}, { double: true, outline: false });
2002
+ add2(fittedPatch(kit, waist, top, 0.038, (y, t) => side * (vOpen(y) + t * 0.1), 10, 3), "#1b2042", {}, { double: true, outline: false });
1246
2003
  }
1247
- add(fittedPatch(kit, waist - 0.032, waist + 0.032, 0.042, (_y, t) => t * Math.PI * 2, 4, 48), "#181624", {}, { double: true });
2004
+ add2(fittedPatch(kit, waist - 0.032, waist + 0.032, 0.042, (_y, t) => t * Math.PI * 2, 4, 48), "#181624", {}, { double: true });
1248
2005
  const knotPt = surf(waist, 0, 0.052);
1249
- add(new SphereGeometry(0.038, 12, 10), "#181624", { at: [knotPt.x, waist, knotPt.z] });
2006
+ add2(new SphereGeometry(0.038, 12, 10), "#181624", { at: [knotPt.x, waist, knotPt.z] });
1250
2007
  const tailGeo = new CylinderGeometry(0.022, 0.028, 0.22, 8);
1251
2008
  tailGeo.scale(1, 1, 0.3);
1252
2009
  const tails = [-1, 1].map((side) => {
@@ -1254,13 +2011,13 @@ function martialGi(kit) {
1254
2011
  at: [knotPt.x + side * 0.028, waist - 0.02, knotPt.z + 0.008],
1255
2012
  rotate: [0.08, 0, side * 0.24]
1256
2013
  });
1257
- add(tailGeo, "#181624", { at: [0, -0.1, 0], parent: hang });
2014
+ add2(tailGeo, "#181624", { at: [0, -0.1, 0], parent: hang });
1258
2015
  return { hang, side, spring: new Spring(55, 5) };
1259
2016
  });
1260
2017
  return (clock, delta, raw) => {
1261
2018
  const motion = calm(raw);
1262
2019
  for (const t of tails) {
1263
- t.hang.rotation.z = t.spring.step(t.side * 0.24 - motion.yaw * 0.04 + Math.sin(clock * 2 + t.side) * 0.04, delta);
2020
+ t.hang.rotation.z = t.spring.step(t.side * 0.24 - motion.yaw * 0.05 - motion.swayX * 0.22 + Math.sin(clock * 2 + t.side) * 0.04, delta);
1264
2021
  }
1265
2022
  };
1266
2023
  });
@@ -1268,20 +2025,20 @@ function martialGi(kit) {
1268
2025
  function chibiOveralls(kit) {
1269
2026
  const z = zonesOf(kit);
1270
2027
  const surf = surfaceOf(kit);
1271
- return piece(kit, ({ add }) => {
2028
+ return piece(kit, ({ add: add2 }) => {
1272
2029
  const bottom = kit.isFigure ? z.bottomY - 0.02 : 0.03;
1273
2030
  const waist = kit.isFigure ? z.waistY + 0.02 : 0.22;
1274
2031
  const top = kit.isFigure ? z.shoulderY + 0.04 : 0.36;
1275
- add(fittedPatch(kit, waist - 0.02, top, 0.014, (_y, t) => t * Math.PI * 2, 12, 48), "#fff3d9", {}, { double: true, outline: false });
1276
- add(fittedPatch(kit, bottom, waist + 0.03, 0.022, (_y, t) => t * Math.PI * 2, 12, 48), "#5b8ff9", {}, { double: true, back: "#3d66bf" });
1277
- add(fittedPatch(kit, waist, top - 0.05, 0.026, (_y, t) => (t * 2 - 1) * 0.55, 8, 12), "#5b8ff9", {}, { double: true });
2032
+ add2(fittedPatch(kit, waist - 0.02, top, 0.014, (_y, t) => t * Math.PI * 2, 12, 48), "#fff3d9", {}, { double: true, outline: false });
2033
+ add2(fittedPatch(kit, bottom, waist + 0.03, 0.022, (_y, t) => t * Math.PI * 2, 12, 48), "#5b8ff9", {}, { double: true, back: "#3d66bf" });
2034
+ add2(fittedPatch(kit, waist, top - 0.05, 0.026, (_y, t) => (t * 2 - 1) * 0.55, 8, 12), "#5b8ff9", {}, { double: true });
1278
2035
  for (const side of [-1, 1]) {
1279
- add(fittedPatch(kit, top - 0.07, top + 0.02, 0.028, (_y, t) => side * (0.36 + t * 0.2), 6, 4), "#5b8ff9", {}, { double: true, outline: false });
2036
+ add2(fittedPatch(kit, top - 0.07, top + 0.02, 0.028, (_y, t) => side * (0.36 + t * 0.2), 6, 4), "#5b8ff9", {}, { double: true, outline: false });
1280
2037
  const btnPt = surf(top - 0.07, side * 0.44, 0.034);
1281
- add(new SphereGeometry(0.018, 10, 8), "#ffd84d", { at: [btnPt.x, top - 0.07, btnPt.z] }, { sheen: 0.85 });
2038
+ add2(new SphereGeometry(0.018, 10, 8), "#ffd84d", { at: [btnPt.x, top - 0.07, btnPt.z] }, { sheen: 0.85 });
1282
2039
  }
1283
2040
  const pockPt = surf(waist + 0.06, 0, 0.033);
1284
- add(new CylinderGeometry(0.045, 0.045, 0.012, 12), "#ffd84d", {
2041
+ add2(new CylinderGeometry(0.045, 0.045, 0.012, 12), "#ffd84d", {
1285
2042
  at: [pockPt.x, waist + 0.06, pockPt.z],
1286
2043
  rotate: [Math.PI / 2, 0, 0],
1287
2044
  scale: [1.1, 1, 0.85]
@@ -1291,7 +2048,7 @@ function chibiOveralls(kit) {
1291
2048
  }
1292
2049
  function sunglasses(kit) {
1293
2050
  const R = kit.radiusAt;
1294
- return piece(kit, ({ add, keep }) => {
2051
+ return piece(kit, ({ add: add2, keep }) => {
1295
2052
  const glass = keep(lensGlass());
1296
2053
  const lens = new Shape;
1297
2054
  lens.moveTo(-0.085, 0.04);
@@ -1316,11 +2073,11 @@ function sunglasses(kit) {
1316
2073
  for (const side of [-1, 1]) {
1317
2074
  const x = side * 0.13;
1318
2075
  const at = [x, EYES_Y, z + 0.035 - Math.abs(x) * 0.18];
1319
- add(lensGeometry, "#ffffff", { at, rotate: [0, side * turn, 0], scale: [side, 1, 1] }, { map: glass, sheen: 0.7, outline: false, double: true });
1320
- add(frameGeometry, "#1b1830", { at: [at[0], at[1], at[2] + 0.002], rotate: [0, side * turn, 0], scale: [side, 1, 1] }, { sheen: 0.6, double: true });
1321
- add(bodyPatch(R, EYES_Y + 0.022, EYES_Y + 0.038, 0.012, (_y, t) => side * (0.42 + t * 0.95), 1, 10), "#1b1830", {}, { double: true, outline: false, sheen: 0.5 });
2076
+ add2(lensGeometry, "#ffffff", { at, rotate: [0, side * turn, 0], scale: [side, 1, 1] }, { map: glass, sheen: 0.7, outline: false, double: true });
2077
+ add2(frameGeometry, "#1b1830", { at: [at[0], at[1], at[2] + 0.002], rotate: [0, side * turn, 0], scale: [side, 1, 1] }, { sheen: 0.6, double: true });
2078
+ add2(bodyPatch(R, EYES_Y + 0.022, EYES_Y + 0.038, 0.012, (_y, t) => side * (0.42 + t * 0.95), 1, 10), "#1b1830", {}, { double: true, outline: false, sheen: 0.5 });
1322
2079
  }
1323
- add(new TorusGeometry(0.03, 0.007, 6, 12, Math.PI), "#1b1830", { at: [0, EYES_Y + 0.025, z + 0.045] }, { sheen: 0.6, outline: false });
2080
+ add2(new TorusGeometry(0.03, 0.007, 6, 12, Math.PI), "#1b1830", { at: [0, EYES_Y + 0.025, z + 0.045] }, { sheen: 0.6, outline: false });
1324
2081
  return;
1325
2082
  });
1326
2083
  }
@@ -1351,7 +2108,7 @@ function buildGarment(key, kit) {
1351
2108
  }
1352
2109
 
1353
2110
  // src/hair3d.ts
1354
- var SKULL = new Vector3(0, BLOB_SEAT + 0.08, 0);
2111
+ var SKULL = new Vector32(0, BLOB_SEAT + 0.08, 0);
1355
2112
  var hexCh = (hex, i) => Number.parseInt(hex.slice(1 + i * 2, 3 + i * 2), 16);
1356
2113
  var tintHex = (a, b, t) => `#${[0, 1, 2].map((i) => Math.max(0, Math.min(255, Math.round(hexCh(a, i) + (hexCh(b, i) - hexCh(a, i)) * t))).toString(16).padStart(2, "0")).join("")}`;
1357
2114
  function resolvePalette(base, override) {
@@ -1369,10 +2126,10 @@ var anime = (p, ring = p.ring ?? 1) => ({
1369
2126
  });
1370
2127
  function onHead(radius, phi, y, out) {
1371
2128
  const r = Math.max(0.02, radius(Math.min(y, TOP - 0.005))) + out;
1372
- return new Vector3(Math.sin(phi) * r, y, Math.cos(phi) * r * DEPTH);
2129
+ return new Vector32(Math.sin(phi) * r, y, Math.cos(phi) * r * DEPTH);
1373
2130
  }
1374
- var UP = new Vector3(0, 1, 0);
1375
- var FORWARD = new Vector3(0, 0, 1);
2131
+ var UP = new Vector32(0, 1, 0);
2132
+ var FORWARD = new Vector32(0, 0, 1);
1376
2133
  function clump(points, width, thickness, tip = 1, twist = 0) {
1377
2134
  const curve = new CatmullRomCurve3(points, false, "centripetal");
1378
2135
  const segments = 22;
@@ -1380,10 +2137,10 @@ function clump(points, width, thickness, tip = 1, twist = 0) {
1380
2137
  const positions = [];
1381
2138
  const along = [];
1382
2139
  const indices = [];
1383
- const tangent = new Vector3;
1384
- const out = new Vector3;
1385
- const across = new Vector3;
1386
- const depth = new Vector3;
2140
+ const tangent = new Vector32;
2141
+ const out = new Vector32;
2142
+ const across = new Vector32;
2143
+ const depth = new Vector32;
1387
2144
  for (let k = 0;k <= segments; k += 1) {
1388
2145
  const t = k / segments;
1389
2146
  const p = curve.getPointAt(t);
@@ -1435,7 +2192,7 @@ function clump(points, width, thickness, tip = 1, twist = 0) {
1435
2192
  geometry.setAttribute("along", new BufferAttribute2(new Float32Array(along), 1));
1436
2193
  geometry.setIndex(indices);
1437
2194
  geometry.computeVertexNormals();
1438
- return { geometry, along: Float32Array.from(along), root: points[0] ?? new Vector3 };
2195
+ return { geometry, along: Float32Array.from(along), root: points[0] ?? new Vector32 };
1439
2196
  }
1440
2197
  function swinger(made) {
1441
2198
  const position = made.geometry.attributes.position;
@@ -1473,8 +2230,9 @@ function cap(radius, front, back, grow, part = 0, partLift = 0.03) {
1473
2230
  const y = TOP + 0.015 - s * (TOP + 0.015 - line);
1474
2231
  const dPart = Math.sin(phi - part);
1475
2232
  const lobe = Math.abs(dPart) * (1 - s * 0.65) * partLift;
2233
+ const apexClose = Math.min(1, s * 6);
1476
2234
  const p = onHead(radius, phi, y, grow * (0.78 + 0.32 * Math.sin(s * Math.PI * 0.72 + 0.25)) + lobe);
1477
- positions.push(p.x, p.y + grow * 0.55 * (1 - s) + lobe * 0.65, p.z);
2235
+ positions.push(p.x * apexClose, p.y + grow * 0.62 * (1 - s) + lobe * 0.65, p.z * apexClose);
1478
2236
  along.push(s * 0.45);
1479
2237
  }
1480
2238
  }
@@ -1491,7 +2249,7 @@ function cap(radius, front, back, grow, part = 0, partLift = 0.03) {
1491
2249
  geometry.computeVertexNormals();
1492
2250
  return geometry;
1493
2251
  }
1494
- function add(b, p, made) {
2252
+ function add2(b, p, made) {
1495
2253
  b.add(made.geometry, p.color, {}, anime(p));
1496
2254
  return made;
1497
2255
  }
@@ -1512,7 +2270,7 @@ function fringe(b, radius, p, bangs, part = 0) {
1512
2270
  const fall = onHead(radius, bang.at + mid, 0.7 + yShift * 0.5, 0.115 + lift * 0.85);
1513
2271
  const end = onHead(radius, bang.at + sweep, bang.length + yShift, 0.075 + lift * 0.45 + flick);
1514
2272
  const made = clump([root, crest, fall, end], bang.width * wBoost, bang.width * wBoost * 0.38, bang.blunt ? 0.56 : 1, bang.twist ?? sweep * 0.55);
1515
- add(b, p, made);
2273
+ add2(b, p, made);
1516
2274
  }
1517
2275
  }
1518
2276
  function sidelocks(b, radius, p, end, width = 0.09, {
@@ -1537,7 +2295,7 @@ function sidelocks(b, radius, p, end, width = 0.09, {
1537
2295
  onHead(radius, side * (phi - (blunt ? 0.03 : curlIn * 0.5)), y + 0.12, out * 0.88 + flick * 0.35),
1538
2296
  onHead(radius, side * (phi - (blunt ? 0.04 : curlIn)), y, endOut)
1539
2297
  ];
1540
- add(b, p, clump(path, w, w * 0.4, blunt ? 0.58 : 1, side * (blunt ? 0.2 : 0.55)));
2298
+ add2(b, p, clump(path, w, w * 0.4, blunt ? 0.58 : 1, side * (blunt ? 0.2 : 0.55)));
1541
2299
  }
1542
2300
  }
1543
2301
  }
@@ -1545,9 +2303,9 @@ function crownTufts(b, radius, p, tufts) {
1545
2303
  for (const [phi, y, len, liftOut, w] of tufts) {
1546
2304
  const root = onHead(radius, phi, y, 0.05);
1547
2305
  const out = onHead(radius, phi, y, 1).sub(root).normalize();
1548
- const mid = root.clone().addScaledVector(out, liftOut).add(new Vector3(Math.sin(phi + 0.6) * 0.05, len * 0.35, Math.cos(phi + 0.6) * 0.03));
1549
- const tip = mid.clone().addScaledVector(out, liftOut * 0.85).add(new Vector3(Math.sin(phi + 1.1) * 0.08, -len * 0.45, Math.cos(phi + 1.1) * 0.05));
1550
- add(b, p, clump([root, mid, tip], w, w * 0.42, 1, Math.sin(phi) * 0.5));
2306
+ const mid = root.clone().addScaledVector(out, liftOut).add(new Vector32(Math.sin(phi + 0.6) * 0.05, len * 0.35, Math.cos(phi + 0.6) * 0.03));
2307
+ const tip = mid.clone().addScaledVector(out, liftOut * 0.85).add(new Vector32(Math.sin(phi + 1.1) * 0.08, -len * 0.45, Math.cos(phi + 1.1) * 0.05));
2308
+ add2(b, p, clump([root, mid, tip], w, w * 0.42, 1, Math.sin(phi) * 0.5));
1551
2309
  }
1552
2310
  }
1553
2311
  function strays(b, radius, p, at) {
@@ -1556,26 +2314,29 @@ function strays(b, radius, p, at) {
1556
2314
  const out = onHead(radius, phi, y, 1).sub(root).normalize();
1557
2315
  const path = [
1558
2316
  root,
1559
- root.clone().addScaledVector(out, 0.065).add(new Vector3(Math.cos(phi) * 0.025, -length * 0.35, 0)),
1560
- root.clone().addScaledVector(out, 0.1).add(new Vector3(Math.sin(phi * 3.1) * 0.055, -length, Math.cos(phi * 2.3) * 0.03))
2317
+ root.clone().addScaledVector(out, 0.065).add(new Vector32(Math.cos(phi) * 0.025, -length * 0.35, 0)),
2318
+ root.clone().addScaledVector(out, 0.1).add(new Vector32(Math.sin(phi * 3.1) * 0.055, -length, Math.cos(phi * 2.3) * 0.03))
1561
2319
  ];
1562
- add(b, p, clump(path, 0.028, 0.012, 1, 0.4));
2320
+ add2(b, p, clump(path, 0.028, 0.012, 1, 0.4));
1563
2321
  }
1564
2322
  }
1565
2323
  function ahoge(b, p, lean = 1, size = 1) {
1566
- const crown2 = new Vector3(0.02 * lean, TOP + 0.035, -0.02);
2324
+ const crown2 = new Vector32(0.02 * lean, TOP + 0.035, -0.02);
1567
2325
  const made = clump([
1568
2326
  crown2,
1569
- crown2.clone().add(new Vector3(0.03 * lean * size, 0.13 * size, 0.03)),
1570
- crown2.clone().add(new Vector3(0.09 * lean * size, 0.19 * size, 0.08)),
1571
- crown2.clone().add(new Vector3(0.15 * lean * size, 0.14 * size, 0.11))
2327
+ crown2.clone().add(new Vector32(0.03 * lean * size, 0.13 * size, 0.03)),
2328
+ crown2.clone().add(new Vector32(0.09 * lean * size, 0.19 * size, 0.08)),
2329
+ crown2.clone().add(new Vector32(0.15 * lean * size, 0.14 * size, 0.11))
1572
2330
  ], 0.038 * size, 0.016 * size);
1573
- add(b, p, made);
2331
+ add2(b, p, made);
1574
2332
  const swing = swinger(made);
1575
- const spring = new Spring(60, 3);
2333
+ const spring = new Spring(75, 2.4);
2334
+ const sideSpring = new Spring(65, 2.6);
1576
2335
  return (_clock, delta, raw) => {
1577
2336
  const motion = calm(raw);
1578
- swing(spring.step(clamp(motion.lift * 0.4, -0.8, 0.8), delta), -motion.yaw * 0.05);
2337
+ const p2 = spring.step(clamp(motion.lift * 0.65 - motion.swayZ * 0.35, -1, 1), delta);
2338
+ const r = sideSpring.step(clamp(-motion.yaw * 0.08 - motion.swayX * 0.45, -0.9, 0.9), delta);
2339
+ swing(p2, r);
1579
2340
  };
1580
2341
  }
1581
2342
  function back(b, radius, p, {
@@ -1612,21 +2373,21 @@ function back(b, radius, p, {
1612
2373
  path.push(onHead(radius, phi + s + turn, y, gap));
1613
2374
  }
1614
2375
  const twist = (i % 3 === 0 ? 0.85 : i % 3 === 1 ? -0.55 : 0.25) * (blunt ? 0.25 : 1);
1615
- made.push(add(b, p, clump(path, width * (0.86 + vary * 0.34) * (under ? 1.08 : 0.92), width * 0.38, blunt ? 0.56 : 1, twist)));
2376
+ made.push(add2(b, p, clump(path, width * (0.86 + vary * 0.34) * (under ? 1.08 : 0.92), width * 0.38, blunt ? 0.56 : 1, twist)));
1616
2377
  }
1617
2378
  }
1618
2379
  return made;
1619
2380
  }
1620
2381
  function hangs(made) {
1621
2382
  const swings = made.map(swinger);
1622
- const pitch = new Spring(45, 4.5);
1623
- const roll = new Spring(40, 4);
2383
+ const pitch = new Spring(58, 2.7);
2384
+ const roll = new Spring(52, 2.5);
1624
2385
  return (clock, delta, raw) => {
1625
2386
  const motion = calm(raw);
1626
- const p = pitch.step(clamp(motion.lift * 0.18, -0.6, 0.6), delta);
1627
- const r = roll.step(-motion.yaw * 0.07 + Math.sin(clock * 1.3) * 0.03, delta);
2387
+ const p = pitch.step(clamp(motion.lift * 0.32 - motion.swayZ * 0.25, -0.85, 0.85), delta);
2388
+ const r = roll.step(clamp(-motion.yaw * 0.1 - motion.swayX * 0.38 + Math.sin(clock * 1.4) * 0.035, -0.85, 0.85), delta);
1628
2389
  swings.forEach((swing, i) => {
1629
- swing(p * (1 + i % 3 * 0.1), r * (1 + i % 2 * 0.15));
2390
+ swing(p * (1 + i % 3 * 0.14), r * (1 + i % 2 * 0.18));
1630
2391
  });
1631
2392
  };
1632
2393
  }
@@ -1660,7 +2421,7 @@ function ringlet(origin, length, spiralR, turns, dir) {
1660
2421
  const t = k / steps;
1661
2422
  const a = t * turns * Math.PI * 2 * dir;
1662
2423
  const r = spiralR * (0.35 + 0.75 * Math.sin(t * Math.PI * 0.85));
1663
- pts.push(new Vector3(origin.x + Math.cos(a) * r + dir * t * 0.08, origin.y - t * length, origin.z + Math.sin(a) * r + t * 0.04));
2424
+ pts.push(new Vector32(origin.x + Math.cos(a) * r + dir * t * 0.08, origin.y - t * length, origin.z + Math.sin(a) * r + t * 0.04));
1664
2425
  }
1665
2426
  return pts;
1666
2427
  }
@@ -1675,9 +2436,9 @@ function ribbon(b, at, facing, color, size = 1) {
1675
2436
  parent: node
1676
2437
  });
1677
2438
  const end = clump([
1678
- new Vector3(side * 0.01, -0.01, 0.01),
1679
- new Vector3(side * 0.038, -0.065, 0.014),
1680
- new Vector3(side * 0.034, -0.13, 0.008)
2439
+ new Vector32(side * 0.01, -0.01, 0.01),
2440
+ new Vector32(side * 0.038, -0.065, 0.014),
2441
+ new Vector32(side * 0.034, -0.13, 0.008)
1681
2442
  ], 0.024, 0.006, 0.5);
1682
2443
  b.add(end.geometry, color, { parent: node });
1683
2444
  }
@@ -1923,8 +2684,8 @@ var HAIR = {
1923
2684
  const curls = [];
1924
2685
  for (const side of [-1, 1]) {
1925
2686
  const origin = onHead(radius, side * 1.18, 0.58, 0.12);
1926
- curls.push(add(b, p, clump(ringlet(origin, 0.92, 0.095, 2.3, side), 0.1, 0.062, 1, side * 1.2)));
1927
- curls.push(add(b, p, clump(ringlet(origin.clone().add(new Vector3(side * 0.04, -0.04, -0.06)), 0.78, 0.08, 2, -side), 0.075, 0.045, 1, -side * 0.9)));
2687
+ curls.push(add2(b, p, clump(ringlet(origin, 0.92, 0.095, 2.3, side), 0.1, 0.062, 1, side * 1.2)));
2688
+ curls.push(add2(b, p, clump(ringlet(origin.clone().add(new Vector32(side * 0.04, -0.04, -0.06)), 0.78, 0.08, 2, -side), 0.075, 0.045, 1, -side * 0.9)));
1928
2689
  }
1929
2690
  ribbon(b, onHead(radius, Math.PI, 0.84, 0.12), Math.PI, "#ffffff", 1.55);
1930
2691
  return together(ahoge(b, p, 1, 0.85), hangs([...backLocks, ...curls]));
@@ -1974,10 +2735,10 @@ var HAIR = {
1974
2735
  const tiePos = onHead(radius, 0.82, 0.08, 0.2);
1975
2736
  tiePos.y = -0.34;
1976
2737
  ribbon(b, tiePos, 0.6, "#ff789e", 1.15);
1977
- const braidTip = add(b, p, clump([
2738
+ const braidTip = add2(b, p, clump([
1978
2739
  tiePos.clone(),
1979
- tiePos.clone().add(new Vector3(0.02, -0.16, 0.04)),
1980
- tiePos.clone().add(new Vector3(-0.02, -0.3, 0.06))
2740
+ tiePos.clone().add(new Vector32(0.02, -0.16, 0.04)),
2741
+ tiePos.clone().add(new Vector32(-0.02, -0.3, 0.06))
1981
2742
  ], 0.085, 0.045, 1, 0.4));
1982
2743
  return together(ahoge(b, p, -1, 0.85), hangs([...backLocks, braidTip]));
1983
2744
  }
@@ -2034,8 +2795,8 @@ var HAIR = {
2034
2795
  const tieY = TOP - 0.1;
2035
2796
  const tie = onHead(radius, side * 1.28, tieY, 0.085);
2036
2797
  for (const path of tail(radius, side * 1.28, tieY, 1.15, 0.38, 6))
2037
- tails.push(add(b, p, clump(path, 0.135, 0.058, 1, side * 0.75)));
2038
- ribbon(b, tie.add(new Vector3(0, 0.02, 0.02)), side * 1.28, "#5bc8ff", 1.75);
2798
+ tails.push(add2(b, p, clump(path, 0.135, 0.058, 1, side * 0.75)));
2799
+ ribbon(b, tie.add(new Vector32(0, 0.02, 0.02)), side * 1.28, "#5bc8ff", 1.75);
2039
2800
  }
2040
2801
  strays(b, radius, p, [
2041
2802
  [0.75, 0.82, 0.13],
@@ -2066,9 +2827,9 @@ var HAIR = {
2066
2827
  const length = reach * 1.48;
2067
2828
  const root = onHead(radius, phi, y, 0.03);
2068
2829
  const out = onHead(radius, phi, y, 1).sub(root).normalize();
2069
- const tip = root.clone().addScaledVector(out, length * (1 - up)).addScaledVector(UP, length * up).add(new Vector3(0, 0, -length * 0.2));
2830
+ const tip = root.clone().addScaledVector(out, length * (1 - up)).addScaledVector(UP, length * up).add(new Vector32(0, 0, -length * 0.2));
2070
2831
  const mid = root.clone().lerp(tip, 0.45).addScaledVector(out, 0.035);
2071
- add(b, p, clump([root, mid, tip], 0.15, 0.075));
2832
+ add2(b, p, clump([root, mid, tip], 0.15, 0.075));
2072
2833
  }
2073
2834
  fringe(b, radius, p, [
2074
2835
  { at: -0.52, length: 0.56, width: 0.125, sweep: -0.14 },
@@ -2170,7 +2931,7 @@ var HAIR = {
2170
2931
  ], 0.18);
2171
2932
  sidelocks(b, radius, p, 0.24, 0.075, { curlIn: 0.24 });
2172
2933
  const tieY = TOP + 0.01;
2173
- const locks = tail(radius, Math.PI, tieY, 1.05, 0.44, 6).map((path, i) => add(b, p, clump(path, 0.135, 0.055, 1, (i % 2 ? 1 : -1) * 0.7)));
2934
+ const locks = tail(radius, Math.PI, tieY, 1.05, 0.44, 6).map((path, i) => add2(b, p, clump(path, 0.135, 0.055, 1, (i % 2 ? 1 : -1) * 0.7)));
2174
2935
  ribbon(b, onHead(radius, Math.PI, tieY, 0.095), Math.PI, "#e2574c", 1.25);
2175
2936
  return together(ahoge(b, p), hangs(locks));
2176
2937
  }
@@ -2185,9 +2946,9 @@ var HAIR = {
2185
2946
  const y = s < 0.45 ? 0.82 + s * 0.3 : TOP - (s - 0.45) * 0.5;
2186
2947
  const root = onHead(radius, phi, Math.min(y, TOP - 0.01), 0);
2187
2948
  root.x = 0;
2188
- const tip = root.clone().add(new Vector3(0, 0.22 - Math.abs(s - 0.4) * 0.14, 0)).add(new Vector3(0, 0, -0.08 - s * 0.05));
2189
- const mid = root.clone().lerp(tip, 0.5).add(new Vector3(0, 0.02, 0.02));
2190
- add(b, p, clump([root, mid, tip], 0.032, 0.095));
2949
+ const tip = root.clone().add(new Vector32(0, 0.22 - Math.abs(s - 0.4) * 0.14, 0)).add(new Vector32(0, 0, -0.08 - s * 0.05));
2950
+ const mid = root.clone().lerp(tip, 0.5).add(new Vector32(0, 0.02, 0.02));
2951
+ add2(b, p, clump([root, mid, tip], 0.032, 0.095));
2191
2952
  }
2192
2953
  return;
2193
2954
  }
@@ -2207,18 +2968,18 @@ var HAIR = {
2207
2968
  sidelocks(b, radius, p, 0.22, 0.072, { curlIn: 0.24 });
2208
2969
  const tufts = [];
2209
2970
  for (const side of [-1, 1]) {
2210
- const at = onHead(radius, side * 0.9, TOP - 0.08, 0.11).add(new Vector3(0, 0.05, 0));
2971
+ const at = onHead(radius, side * 0.9, TOP - 0.08, 0.11).add(new Vector32(0, 0.05, 0));
2211
2972
  const coil = [];
2212
2973
  for (let k = 0;k <= 14; k += 1) {
2213
2974
  const a = k * 0.9;
2214
2975
  const r = 0.115 - k * 0.004;
2215
- coil.push(new Vector3(at.x + Math.cos(a) * r, at.y + (k / 14 - 0.5) * 0.12, at.z + Math.sin(a) * r));
2976
+ coil.push(new Vector32(at.x + Math.cos(a) * r, at.y + (k / 14 - 0.5) * 0.12, at.z + Math.sin(a) * r));
2216
2977
  }
2217
2978
  b.add(new SphereGeometry2(0.105, 20, 16), p.color, { at: [at.x, at.y, at.z] }, { anime: { center: [at.x, at.y, at.z], ring: 0.8, tip: p.tip, inner: p.inner } });
2218
- add(b, p, clump(coil, 0.065, 0.038, 0.7));
2219
- ribbon(b, at.clone().add(new Vector3(0, -0.07, 0.06)), side * 0.9, "#ffd84d", 0.88);
2979
+ add2(b, p, clump(coil, 0.065, 0.038, 0.7));
2980
+ ribbon(b, at.clone().add(new Vector32(0, -0.07, 0.06)), side * 0.9, "#ffd84d", 0.88);
2220
2981
  for (const path of tail(radius, side * 1.05, TOP - 0.16, 0.48, 0.24, 3))
2221
- tufts.push(add(b, p, clump(path, 0.085, 0.034)));
2982
+ tufts.push(add2(b, p, clump(path, 0.085, 0.034)));
2222
2983
  }
2223
2984
  return hangs(tufts);
2224
2985
  }
@@ -2265,6 +3026,241 @@ function buildWear(key, kit) {
2265
3026
  return isHairKey(key) ? buildHair(key, kit) : buildGarment(key, kit);
2266
3027
  }
2267
3028
 
3029
+ // src/ik-skeleton.ts
3030
+ import { Euler, Matrix4, Quaternion, Vector3 as Vector33 } from "three";
3031
+ var SKELETON_JOINTS = [
3032
+ "pelvis",
3033
+ "spine",
3034
+ "neck",
3035
+ "head",
3036
+ "shoulder_l",
3037
+ "elbow_l",
3038
+ "wrist_l",
3039
+ "shoulder_r",
3040
+ "elbow_r",
3041
+ "wrist_r",
3042
+ "hip_l",
3043
+ "knee_l",
3044
+ "ankle_l",
3045
+ "toe_l",
3046
+ "hip_r",
3047
+ "knee_r",
3048
+ "ankle_r",
3049
+ "toe_r"
3050
+ ];
3051
+ var UP2 = new Vector33(0, 1, 0);
3052
+ var FWD = new Vector33(0, 0, 1);
3053
+ var DOWN = new Vector33(0, -1, 0);
3054
+ var QI = new Quaternion;
3055
+ var clamp2 = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
3056
+ function solveTwoBoneIK(a, target, len1, len2, poleDir) {
3057
+ const dir = target.clone().sub(a);
3058
+ const rawDist = dir.length();
3059
+ const minReach = Math.abs(len1 - len2) + 0.001;
3060
+ const maxReach = (len1 + len2) * 0.996;
3061
+ const d = clamp2(rawDist, minReach, maxReach);
3062
+ const u = rawDist > 0.00001 ? dir.divideScalar(rawDist) : DOWN.clone();
3063
+ const end = a.clone().addScaledVector(u, d);
3064
+ const along = (len1 * len1 - len2 * len2 + d * d) / (2 * d);
3065
+ const perpSq = Math.max(0, len1 * len1 - along * along);
3066
+ const perp = Math.sqrt(perpSq);
3067
+ const p = poleDir.clone().addScaledVector(u, -poleDir.dot(u));
3068
+ if (p.lengthSq() < 0.000001) {
3069
+ p.set(0, 0, 1).addScaledVector(u, -u.z);
3070
+ if (p.lengthSq() < 0.000001)
3071
+ p.set(1, 0, 0);
3072
+ }
3073
+ p.normalize();
3074
+ const mid = a.clone().addScaledVector(u, along).addScaledVector(p, perp);
3075
+ return { mid, end };
3076
+ }
3077
+ function basisQuat(leftVec, upVec) {
3078
+ const x = leftVec.clone().normalize();
3079
+ const y = upVec.clone().addScaledVector(x, -x.dot(upVec));
3080
+ if (y.lengthSq() < 0.000001)
3081
+ y.copy(UP2);
3082
+ y.normalize();
3083
+ const z = new Vector33().crossVectors(x, y).normalize();
3084
+ x.crossVectors(y, z).normalize();
3085
+ const m = new Matrix4().makeBasis(x, y, z);
3086
+ return new Quaternion().setFromRotationMatrix(m);
3087
+ }
3088
+ function calmTilt(q, keepTilt) {
3089
+ const f = FWD.clone().applyQuaternion(q);
3090
+ const yaw = new Quaternion().setFromAxisAngle(UP2, Math.atan2(f.x, f.z));
3091
+ const local = yaw.clone().invert().multiply(q);
3092
+ return yaw.multiply(QI.clone().slerp(local, keepTilt));
3093
+ }
3094
+ function pushOutOfTorso(pt, metrics) {
3095
+ const dy = pt.y - metrics.torsoCenterY;
3096
+ const halfH = metrics.isClassic ? 0.56 : 0.42;
3097
+ if (Math.abs(dy) > halfH * 1.05)
3098
+ return pt;
3099
+ const yn = clamp2(dy / halfH, -0.99, 0.99);
3100
+ const profile = Math.sqrt(Math.max(0.05, 1 - yn * yn));
3101
+ const rx = metrics.torsoRadiusX * profile + 0.045;
3102
+ const rz = metrics.torsoRadiusZ * profile + 0.045;
3103
+ const e = Math.hypot(pt.x / rx, pt.z / rz);
3104
+ if (e >= 1)
3105
+ return pt;
3106
+ const out = pt.clone();
3107
+ if (e < 0.0001) {
3108
+ out.z = rz;
3109
+ } else {
3110
+ out.x /= e;
3111
+ out.z /= e;
3112
+ }
3113
+ return out;
3114
+ }
3115
+ function sampleBakedJoints(clip2, seconds) {
3116
+ const stride = clip2.sendi.length * 3;
3117
+ const frameCount = Math.max(1, Math.floor(clip2.data.length / stride));
3118
+ const dur = clip2.durasi > 0 ? clip2.durasi : (frameCount - 1) / Math.max(1, clip2.fps);
3119
+ const tSec = clip2.loop ? (seconds % dur + dur) % dur : clamp2(seconds, 0, Math.max(0, dur - 0.0001));
3120
+ const fPos = tSec / Math.max(0.0001, dur) * (frameCount - 1);
3121
+ const i1 = Math.floor(fPos);
3122
+ const u = fPos - i1;
3123
+ const wrapIdx = (i) => clip2.loop ? (i % (frameCount - 1 || 1) + (frameCount - 1 || 1)) % (frameCount - 1 || 1) : clamp2(i, 0, frameCount - 1);
3124
+ const i0 = wrapIdx(i1 - 1);
3125
+ const i2 = wrapIdx(i1 + 1);
3126
+ const i3 = wrapIdx(i1 + 2);
3127
+ const u2 = u * u;
3128
+ const u3 = u2 * u;
3129
+ const idxOf = new Map;
3130
+ clip2.sendi.forEach((name, idx) => idxOf.set(name, idx));
3131
+ const out = {};
3132
+ for (const name of SKELETON_JOINTS) {
3133
+ const j = idxOf.get(name);
3134
+ if (j === undefined) {
3135
+ out[name] = new Vector33;
3136
+ continue;
3137
+ }
3138
+ const read = (fi, c) => clip2.data[fi * stride + j * 3 + c] ?? 0;
3139
+ const cr = (c) => {
3140
+ const v0 = read(i0, c);
3141
+ const v1 = read(i1, c);
3142
+ const v2 = read(i2, c);
3143
+ const v3 = read(i3, c);
3144
+ return 0.5 * (2 * v1 + (-v0 + v2) * u + (2 * v0 - 5 * v1 + 4 * v2 - v3) * u2 + (-v0 + 3 * v1 - 3 * v2 + v3) * u3);
3145
+ };
3146
+ out[name] = new Vector33(cr(0), cr(1), cr(2));
3147
+ }
3148
+ return out;
3149
+ }
3150
+ function retarget18JointPose(F, m) {
3151
+ const srcLegL = F.hip_l.distanceTo(F.knee_l) + F.knee_l.distanceTo(F.ankle_l);
3152
+ const srcLegR = F.hip_r.distanceTo(F.knee_r) + F.knee_r.distanceTo(F.ankle_r);
3153
+ const srcLegLen = Math.max(0.7, (srcLegL + srcLegR) * 0.5);
3154
+ const legScale = m.legLength / srcLegLen;
3155
+ const hipMid = F.hip_l.clone().add(F.hip_r).multiplyScalar(0.5);
3156
+ const pelvisUp = F.spine.clone().sub(hipMid);
3157
+ const pelvisLeft = F.hip_l.clone().sub(F.hip_r);
3158
+ const rawHipsQ = basisQuat(pelvisLeft, pelvisUp);
3159
+ const chestUp = F.neck.clone().sub(F.spine);
3160
+ const chestLeft = F.shoulder_l.clone().sub(F.shoulder_r);
3161
+ const rawChestQ = basisQuat(chestLeft, chestUp);
3162
+ const torsoQ = calmTilt(rawHipsQ.clone().slerp(rawChestQ, 0.55), m.isClassic ? 0.42 : 0.56);
3163
+ const invTorsoQ = torsoQ.clone().invert();
3164
+ const headUp = F.head.clone().sub(F.neck);
3165
+ const headWorldQ = calmTilt(basisQuat(chestLeft, headUp), 0.55);
3166
+ const headQ = calmTilt(invTorsoQ.clone().multiply(headWorldQ), 0.72);
3167
+ const soleH = m.isClassic ? 0.055 : 0.045;
3168
+ const minSrcAnkleY = Math.min(F.ankle_l.y, F.ankle_r.y);
3169
+ const airLift = Math.max(0, minSrcAnkleY - 0.095) * legScale;
3170
+ const hipAboveStance = Math.max(0.24, hipMid.y - minSrcAnkleY) * legScale;
3171
+ const pelvisWorldY = soleH + airLift + hipAboveStance;
3172
+ const rootPos = new Vector33(hipMid.x * legScale * (m.isClassic ? 0.75 : 0.92), Math.max(0.01, pelvisWorldY - m.hipLocalY), hipMid.z * legScale * 0.65);
3173
+ const worldToLocal = (w) => w.clone().sub(rootPos).applyQuaternion(invTorsoQ);
3174
+ const solveLeg = (srcSide, anchorX) => {
3175
+ const hipLocal = new Vector33(anchorX, m.hipLocalY, 0);
3176
+ const hipWorld = hipLocal.clone().applyQuaternion(torsoQ).add(rootPos);
3177
+ const srcHip = F[`hip_${srcSide}`];
3178
+ const srcKnee = F[`knee_${srcSide}`];
3179
+ const srcAnkle = F[`ankle_${srcSide}`];
3180
+ const srcToe = F[`toe_${srcSide}`];
3181
+ const ankleOffset = srcAnkle.clone().sub(srcHip).multiplyScalar(legScale);
3182
+ const ankleWorld = hipWorld.clone().add(ankleOffset);
3183
+ const floorY = soleH + Math.max(0, srcAnkle.y - 0.095) * legScale;
3184
+ ankleWorld.y = Math.max(soleH, floorY);
3185
+ const srcMid = srcHip.clone().add(srcAnkle).multiplyScalar(0.5);
3186
+ const poleWorld = srcKnee.clone().sub(srcMid);
3187
+ if (poleWorld.lengthSq() < 0.00001) {
3188
+ poleWorld.copy(FWD).applyQuaternion(torsoQ);
3189
+ }
3190
+ poleWorld.normalize();
3191
+ const thighLen = m.legLength * 0.52;
3192
+ const shinLen = m.legLength * 0.48;
3193
+ const { mid: kneeWorld, end: endWorld } = solveTwoBoneIK(hipWorld, ankleWorld, thighLen, shinLen, poleWorld);
3194
+ const toeDir = srcToe.clone().sub(srcAnkle);
3195
+ const toeLen = toeDir.length() || 1;
3196
+ toeDir.divideScalar(toeLen);
3197
+ const footPitch = clamp2(-Math.asin(clamp2(toeDir.y, -0.95, 0.95)) - 0.43, -0.7, 0.75);
3198
+ const footYaw = clamp2(Math.atan2(toeDir.x, Math.max(0.05, toeDir.z)), -0.8, 0.8);
3199
+ return {
3200
+ pts: [hipLocal, worldToLocal(kneeWorld), worldToLocal(endWorld)],
3201
+ footPitch,
3202
+ footYaw
3203
+ };
3204
+ };
3205
+ const legL = solveLeg("r", -m.hipHalfWidth);
3206
+ const legR = solveLeg("l", m.hipHalfWidth);
3207
+ const solveArm = (srcSide, anchorX) => {
3208
+ const shLocal = new Vector33(anchorX, m.shoulderLocalY, 0.01);
3209
+ const shWorld = shLocal.clone().applyQuaternion(torsoQ).add(rootPos);
3210
+ const srcSh = F[`shoulder_${srcSide}`];
3211
+ const srcEl = F[`elbow_${srcSide}`];
3212
+ const srcWr = F[`wrist_${srcSide}`];
3213
+ const uDir = srcEl.clone().sub(srcSh);
3214
+ const lDir = srcWr.clone().sub(srcEl);
3215
+ const uLen = uDir.length() || 0.29;
3216
+ const lLen = lDir.length() || 0.26;
3217
+ uDir.divideScalar(uLen);
3218
+ lDir.divideScalar(lLen);
3219
+ const upperLen = m.armLength * 0.5;
3220
+ const lowerLen = m.armLength * 0.5;
3221
+ const rawElWorld = shWorld.clone().addScaledVector(uDir, upperLen);
3222
+ const rawWrWorld = rawElWorld.clone().addScaledVector(lDir, lowerLen);
3223
+ let wrLocal = pushOutOfTorso(worldToLocal(rawWrWorld), m);
3224
+ const elHintLocal = pushOutOfTorso(worldToLocal(rawElWorld), m);
3225
+ const poleLocal = elHintLocal.clone().sub(shLocal.clone().add(wrLocal).multiplyScalar(0.5));
3226
+ if (poleLocal.lengthSq() < 0.00001) {
3227
+ poleLocal.set(Math.sign(anchorX) * 0.6, -0.4, -0.7);
3228
+ }
3229
+ poleLocal.normalize();
3230
+ const { mid: elLocal, end: finalWr } = solveTwoBoneIK(shLocal, wrLocal, upperLen, lowerLen, poleLocal);
3231
+ const clearedEl = pushOutOfTorso(elLocal, m);
3232
+ const elDir = clearedEl.sub(shLocal);
3233
+ const elFixed = elDir.lengthSq() > 0.000001 ? shLocal.clone().addScaledVector(elDir.normalize(), upperLen) : elLocal;
3234
+ const wrDir = finalWr.clone().sub(elFixed);
3235
+ wrLocal = wrDir.lengthSq() > 0.000001 ? elFixed.clone().addScaledVector(wrDir.normalize(), lowerLen) : finalWr;
3236
+ return [shLocal, elFixed, wrLocal];
3237
+ };
3238
+ const armL = solveArm("r", -m.shoulderHalfWidth);
3239
+ const armR = solveArm("l", m.shoulderHalfWidth);
3240
+ const dip = clamp2(1 - F.pelvis.y, -0.25, 0.45);
3241
+ const squash = clamp2(-dip * 0.14, -0.06, 0.05);
3242
+ return { rootPos, torsoQ, headQ, armL, armR, legL, legR, squash };
3243
+ }
3244
+ function aimTwoBoneLimb(upperPivot, lowerPivot, a, b, c) {
3245
+ upperPivot.position.copy(a);
3246
+ const d1 = b.clone().sub(a);
3247
+ const len1 = d1.length();
3248
+ if (len1 > 0.00001) {
3249
+ d1.divideScalar(len1);
3250
+ upperPivot.quaternion.setFromUnitVectors(DOWN, d1);
3251
+ }
3252
+ const invUpper = upperPivot.quaternion.clone().invert();
3253
+ const d2World = c.clone().sub(b);
3254
+ const len2 = d2World.length();
3255
+ if (len2 > 0.00001) {
3256
+ const d2Local = d2World.divideScalar(len2).applyQuaternion(invUpper).normalize();
3257
+ lowerPivot.quaternion.setFromUnitVectors(DOWN, d2Local);
3258
+ }
3259
+ }
3260
+ function orientFoot(foot, pitch, yaw) {
3261
+ foot.quaternion.setFromEuler(new Euler(pitch, yaw, 0, "YXZ"));
3262
+ }
3263
+
2268
3264
  // src/proportions.ts
2269
3265
  var ARM_LENGTH = 0.3;
2270
3266
  var BELLY_HALF_WIDTH = 0.6;
@@ -2298,15 +3294,36 @@ function pixelArtFiltering(texture) {
2298
3294
  function stampFor(face, type) {
2299
3295
  return faceStamp(type, face);
2300
3296
  }
3297
+ var JIGGLE_DEFORM_GLSL = `
3298
+ vec3 applyJiggle(vec3 p, vec3 jiggle, vec2 band) {
3299
+ if (dot(jiggle, jiggle) < 1e-8) return p;
3300
+ float hN = clamp((p.y - band.x) / max(0.05, band.y - band.x), 0.0, 1.0);
3301
+ float softBell = sin(hN * 3.14159265);
3302
+ float topLag = hN * hN;
3303
+ float bustBoost = 1.0 + smoothstep(0.09, 0.28, p.z) * 0.65;
3304
+ vec3 q = p;
3305
+ q.y += jiggle.y * (0.45 * topLag + 0.55 * softBell * bustBoost);
3306
+ float bulge = clamp(1.0 - jiggle.y * 0.45 * softBell, 0.90, 1.12);
3307
+ q.x *= bulge;
3308
+ q.z *= bulge;
3309
+ q.x += jiggle.x * (0.38 * topLag + 0.62 * softBell * bustBoost);
3310
+ q.z += jiggle.z * (0.38 * topLag + 0.62 * softBell * bustBoost);
3311
+ return q;
3312
+ }
3313
+ `;
2301
3314
  var TOON_VERTEX = `
2302
3315
  varying vec3 vNormal;
2303
3316
  varying vec2 vUv;
2304
3317
  uniform vec2 uvOffset;
2305
3318
  uniform vec2 uvRepeat;
3319
+ uniform vec3 uJiggle;
3320
+ uniform vec2 uJiggleBand;
3321
+ ${JIGGLE_DEFORM_GLSL}
2306
3322
  void main() {
2307
3323
  vNormal = normalize(normalMatrix * (length(normal) > 0.001 ? normal : vec3(0.0, 0.0, 1.0)));
2308
3324
  vUv = uv * uvRepeat + uvOffset;
2309
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
3325
+ vec3 pos = applyJiggle(position, uJiggle, uJiggleBand);
3326
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
2310
3327
  }`;
2311
3328
  var TOON_FRAGMENT = `
2312
3329
  varying vec3 vNormal;
@@ -2395,7 +3412,7 @@ function taperedHose(curve, muscle, baseRadius = 0.046) {
2395
3412
  const radial = 14;
2396
3413
  const tube = new TubeGeometry(curve, segments, baseRadius, radial);
2397
3414
  const position = tube.attributes.position;
2398
- const centre = new Vector32;
3415
+ const centre = new Vector34;
2399
3416
  const strength = Math.max(0, muscle - 1);
2400
3417
  const slim = muscle < 1 ? 0.72 + 0.28 * muscle : 1;
2401
3418
  for (let i = 0;i <= segments; i += 1) {
@@ -2418,7 +3435,7 @@ function sculptedLeg(curve, hips, muscle) {
2418
3435
  const radial = 14;
2419
3436
  const tube = new TubeGeometry(curve, segments, 0.095, radial);
2420
3437
  const position = tube.attributes.position;
2421
- const centre = new Vector32;
3438
+ const centre = new Vector34;
2422
3439
  const thighScale = 0.88 + Math.max(0, hips - 0.85) * 0.52 + Math.max(0, muscle - 1) * 0.36;
2423
3440
  const calfScale = 0.78 + Math.max(0, muscle - 1) * 0.34 + Math.max(0, hips - 1) * 0.14;
2424
3441
  for (let i = 0;i <= segments; i += 1) {
@@ -2436,6 +3453,8 @@ function sculptedLeg(curve, hips, muscle) {
2436
3453
  tube.computeVertexNormals();
2437
3454
  return tube;
2438
3455
  }
3456
+ var ZERO_JIGGLE = new Vector34(0, 0, 0);
3457
+ var DEFAULT_JIGGLE_BAND = new Vector22(0, 1);
2439
3458
  function toon(options) {
2440
3459
  if (options.anime)
2441
3460
  return new ShaderMaterial({
@@ -2445,7 +3464,7 @@ function toon(options) {
2445
3464
  toneMapped: false,
2446
3465
  uniforms: {
2447
3466
  color: { value: new Color2(options.color ?? "#ffffff") },
2448
- center: { value: new Vector32(...options.anime.center) },
3467
+ center: { value: new Vector34(...options.anime.center) },
2449
3468
  ring: { value: options.anime.ring ?? 1 },
2450
3469
  tip: { value: new Color2(options.anime.tip ?? options.color ?? "#ffffff") },
2451
3470
  inner: { value: new Color2(options.anime.inner ?? options.color ?? "#ffffff") }
@@ -2463,19 +3482,30 @@ function toon(options) {
2463
3482
  backColor: { value: new Color2(options.back ?? options.color ?? "#ffffff") },
2464
3483
  sheen: { value: options.sheen ?? 0 },
2465
3484
  uvOffset: { value: [options.map?.offset.x ?? 0, 0] },
2466
- uvRepeat: { value: options.repeat ?? [1, 1] }
3485
+ uvRepeat: { value: options.repeat ?? [1, 1] },
3486
+ uJiggle: { value: options.jiggle?.value ?? ZERO_JIGGLE },
3487
+ uJiggleBand: { value: options.jiggle?.band ?? DEFAULT_JIGGLE_BAND }
2467
3488
  }
2468
3489
  });
2469
3490
  }
2470
- function hull(color, width) {
3491
+ function hull(color, width, jiggle) {
2471
3492
  return new ShaderMaterial({
2472
3493
  side: BackSide,
2473
3494
  toneMapped: false,
2474
- uniforms: { color: { value: new Color2(color) }, width: { value: width } },
3495
+ uniforms: {
3496
+ color: { value: new Color2(color) },
3497
+ width: { value: width },
3498
+ uJiggle: { value: jiggle?.value ?? ZERO_JIGGLE },
3499
+ uJiggleBand: { value: jiggle?.band ?? DEFAULT_JIGGLE_BAND }
3500
+ },
2475
3501
  vertexShader: `
2476
3502
  uniform float width;
3503
+ uniform vec3 uJiggle;
3504
+ uniform vec2 uJiggleBand;
3505
+ ${JIGGLE_DEFORM_GLSL}
2477
3506
  void main() {
2478
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position + normal * width, 1.0);
3507
+ vec3 pos = applyJiggle(position, uJiggle, uJiggleBand);
3508
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(pos + normal * width, 1.0);
2479
3509
  }`,
2480
3510
  fragmentShader: `
2481
3511
  uniform vec3 color;
@@ -2487,13 +3517,13 @@ void main() {
2487
3517
  }
2488
3518
  function hexChannels(hex) {
2489
3519
  const bare = hex.startsWith("#") ? hex.slice(1) : hex;
2490
- const full = bare.length === 3 || bare.length === 4 ? `${bare[0]}${bare[0]}${bare[1]}${bare[1]}${bare[2]}${bare[2]}` : bare.length === 6 || bare.length === 8 ? bare.slice(0, 6) : "";
2491
- if (!/^[0-9a-f]{6}$/i.test(full))
3520
+ const full2 = bare.length === 3 || bare.length === 4 ? `${bare[0]}${bare[0]}${bare[1]}${bare[1]}${bare[2]}${bare[2]}` : bare.length === 6 || bare.length === 8 ? bare.slice(0, 6) : "";
3521
+ if (!/^[0-9a-f]{6}$/i.test(full2))
2492
3522
  return [0, 0, 0];
2493
3523
  return [
2494
- Number.parseInt(full.slice(0, 2), 16),
2495
- Number.parseInt(full.slice(2, 4), 16),
2496
- Number.parseInt(full.slice(4, 6), 16)
3524
+ Number.parseInt(full2.slice(0, 2), 16),
3525
+ Number.parseInt(full2.slice(2, 4), 16),
3526
+ Number.parseInt(full2.slice(4, 6), 16)
2497
3527
  ];
2498
3528
  }
2499
3529
  var shade = (hex, toward, amount) => `#${hexChannels(hex).map((value) => Math.max(0, Math.min(255, Math.round(value + (toward - value) * amount))).toString(16).padStart(2, "0")).join("")}`;
@@ -2601,19 +3631,16 @@ var OUTFIT_LEG_COLOR = {
2601
3631
  "chibi-overalls": "#5b8ff9"
2602
3632
  };
2603
3633
  var inkHull = null;
2604
- var neonHull = null;
2605
3634
  var fineHull = null;
2606
3635
  var hairHull = null;
2607
3636
  var figureHull = null;
2608
3637
  function createPlup(options = {}) {
2609
3638
  inkHull ??= hull("#14102e", 0.022);
2610
3639
  figureHull ??= hull("#1b1438", 0.013);
2611
- neonHull ??= hull("#b9a6ff", 0.04);
2612
3640
  fineHull ??= hull("#191233", 0.007);
2613
3641
  hairHull ??= hull("#1c1433", 0.0045);
2614
3642
  const fine = fineHull;
2615
3643
  const ink = inkHull;
2616
- const neon = neonHull;
2617
3644
  const figureInk = figureHull;
2618
3645
  const hairInk = hairHull;
2619
3646
  let color = options.color ?? "#3d7bff";
@@ -2644,8 +3671,16 @@ function createPlup(options = {}) {
2644
3671
  texture.wrapS = RepeatWrapping2;
2645
3672
  texture.offset.x = (FACE_COLUMN + 4) / BODY_WIDTH - 0.25;
2646
3673
  const anime2 = animeDecal(skin?.faceType ?? options.faceType, face, options.eyeColor, isFigure);
2647
- const bodyMaterial = toon({ map: texture });
2648
- const torsoMaterial = toon({ color });
3674
+ const jiggleUniform = {
3675
+ value: new Vector34(0, 0, 0),
3676
+ band: new Vector22(isFigure ? span.minY : 0, isFigure ? span.maxY : BLOB_HEIGHT)
3677
+ };
3678
+ const torsoInkMat = hull("#1b1438", 0.013, jiggleUniform);
3679
+ const blobInkMat = hull("#14102e", 0.022, jiggleUniform);
3680
+ const blobNeonMat = hull("#b9a6ff", 0.04, jiggleUniform);
3681
+ const garmentInkMat = hull("#191233", 0.007, jiggleUniform);
3682
+ const bodyMaterial = toon({ map: texture, ...isFigure ? {} : { jiggle: jiggleUniform } });
3683
+ const torsoMaterial = toon({ color, jiggle: jiggleUniform });
2649
3684
  const limbMaterial = toon({ color: isFigure ? shade(color, 0, 0.05) : shade(color, 0, 0.12) });
2650
3685
  const legMaterial = toon({ color: isFigure ? shade(color, 0, 0.05) : shade(color, 0, 0.12) });
2651
3686
  const tipMaterial = toon({ color: isFigure ? shade(color, 0, 0.12) : shade(color, 0, 0.3) });
@@ -2660,7 +3695,7 @@ function createPlup(options = {}) {
2660
3695
  if (!options.model) {
2661
3696
  if (isFigure && torsoGeometry) {
2662
3697
  const torsoMesh = new Mesh2(torsoGeometry, torsoMaterial);
2663
- const torsoInk = new Mesh2(torsoGeometry, figureInk);
3698
+ const torsoInk = new Mesh2(torsoGeometry, torsoInkMat);
2664
3699
  lifted.add(torsoMesh, torsoInk);
2665
3700
  headGroup.position.set(0, headMetrics.originY, 0);
2666
3701
  headGroup.scale.setScalar(headMetrics.scale);
@@ -2676,7 +3711,7 @@ function createPlup(options = {}) {
2676
3711
  lifted.add(headGroup);
2677
3712
  } else {
2678
3713
  const bodyMesh = new Mesh2(geometry, bodyMaterial);
2679
- const blobMeshes = [bodyMesh, new Mesh2(geometry, ink), new Mesh2(geometry, neon)];
3714
+ const blobMeshes = [bodyMesh, new Mesh2(geometry, blobInkMat), new Mesh2(geometry, blobNeonMat)];
2680
3715
  for (const mesh of blobMeshes)
2681
3716
  mesh.scale.set(fit.girth / shape.x, clampBodyScale(options.bodyScale).head, fit.girth / shape.x);
2682
3717
  lifted.add(...blobMeshes);
@@ -2720,8 +3755,8 @@ function createPlup(options = {}) {
2720
3755
  const r = blobRadiusAt(y, silhouette) + grow;
2721
3756
  return { x: Math.sin(phi) * r, z: Math.cos(phi) * r * (BLOB_RADIUS.z / BLOB_RADIUS.x) };
2722
3757
  },
2723
- paint: (paint, more = {}) => toon({ ...more, color: paint }),
2724
- ink: fine,
3758
+ paint: (paint, more = {}) => toon({ ...more, color: paint, jiggle: jiggleUniform }),
3759
+ ink: garmentInkMat,
2725
3760
  hairColor: options.hairColor,
2726
3761
  isFigure,
2727
3762
  zones: isFigure ? {
@@ -2784,7 +3819,7 @@ function createPlup(options = {}) {
2784
3819
  const limb = (name, x, y, length, tip, flat, bow2 = 0, legStyle = false) => {
2785
3820
  const pivot = pivots[name];
2786
3821
  pivot.position.set(x, y, 0);
2787
- const curve = bow2 ? new QuadraticBezierCurve3(new Vector32(0, 0.02, 0), new Vector32(bow2 * (legStyle ? 0.025 : 0.07), -length * 0.5, legStyle ? 0.02 : 0.03), new Vector32(bow2 * (legStyle ? 0.01 : 0.03), -length, legStyle ? 0.01 : 0.04)) : null;
3822
+ const curve = bow2 ? new QuadraticBezierCurve3(new Vector34(0, 0.02, 0), new Vector34(bow2 * (legStyle ? 0.025 : 0.07), -length * 0.5, legStyle ? 0.02 : 0.03), new Vector34(bow2 * (legStyle ? 0.01 : 0.03), -length, legStyle ? 0.01 : 0.04)) : null;
2788
3823
  const shaft = curve ? legStyle ? sculptedLeg(curve, build.hips, build.muscle) : taperedHose(curve, build.muscle, isFigure ? 0.042 : 0.046) : limbGeometry;
2789
3824
  if (curve)
2790
3825
  armGeometries.push(shaft);
@@ -2815,7 +3850,27 @@ function createPlup(options = {}) {
2815
3850
  lifted.add(pivot);
2816
3851
  };
2817
3852
  const subPivots = { elbowL: null, elbowR: null, kneeL: null, kneeR: null };
3853
+ const shoePivots = { legL: null, legR: null };
3854
+ const restAnchors = {
3855
+ armL: new Vector34,
3856
+ armR: new Vector34,
3857
+ legL: new Vector34,
3858
+ legR: new Vector34
3859
+ };
2818
3860
  let figureLegLen = 0.44;
3861
+ let ikMetrics = {
3862
+ hipHeight: 0.56,
3863
+ hipHalfWidth: 0.1,
3864
+ hipLocalY: 0.14,
3865
+ shoulderHalfWidth: 0.18,
3866
+ shoulderLocalY: 0.5,
3867
+ armLength: 0.34,
3868
+ legLength: 0.44,
3869
+ torsoRadiusX: 0.18,
3870
+ torsoRadiusZ: 0.15,
3871
+ torsoCenterY: 0.35,
3872
+ isClassic: !isFigure
3873
+ };
2819
3874
  const articulatedArm = (name, elbowKey, x, y, length) => {
2820
3875
  const pivot = pivots[name];
2821
3876
  pivot.position.set(x, y, 0);
@@ -2876,17 +3931,21 @@ function createPlup(options = {}) {
2876
3931
  knee.position.set(0, -upperLen, 0);
2877
3932
  const shinMesh = new Mesh2(shinGeo, legMaterial);
2878
3933
  const shinInk = new Mesh2(shinGeo, figureInk);
3934
+ const shoePivot = new Group2;
3935
+ shoePivot.position.set(0, -lowerLen, 0);
2879
3936
  const shoe = new Mesh2(footGeometry, shoeMaterial);
2880
- shoe.position.set(0, -lowerLen, 0.025 * compact);
3937
+ shoe.position.set(0, 0, 0.025 * compact);
2881
3938
  shoe.scale.set(1.02 * compact, 0.62 * compact, 1.58 * compact);
2882
3939
  const shoeInk = new Mesh2(footGeometry, figureInk);
2883
3940
  shoeInk.position.copy(shoe.position);
2884
3941
  shoeInk.scale.copy(shoe.scale);
2885
- knee.add(shinMesh, shinInk, shoe, shoeInk);
3942
+ shoePivot.add(shoe, shoeInk);
3943
+ knee.add(shinMesh, shinInk, shoePivot);
2886
3944
  pivot.add(thighMesh, thighInk, jointMesh, knee);
2887
- for (const m of [...pivot.children, ...knee.children])
3945
+ for (const m of [...pivot.children, ...knee.children, ...shoePivot.children])
2888
3946
  m.raycast = () => {};
2889
3947
  subPivots[kneeKey] = knee;
3948
+ shoePivots[name] = shoePivot;
2890
3949
  lifted.add(pivot);
2891
3950
  };
2892
3951
  if (options.model) {
@@ -2913,23 +3972,53 @@ function createPlup(options = {}) {
2913
3972
  pivots.armR.scale.set(fit.armWidth[1], 1, fit.armWidth[1]);
2914
3973
  pivots.legL.scale.set(fit.legWidth[0], 1, fit.legWidth[0]);
2915
3974
  pivots.legR.scale.set(fit.legWidth[1], 1, fit.legWidth[1]);
3975
+ ikMetrics = {
3976
+ hipHeight: legRaise + hipAnchorY,
3977
+ hipHalfWidth: hipX,
3978
+ hipLocalY: hipAnchorY,
3979
+ shoulderHalfWidth: shoulderX,
3980
+ shoulderLocalY: span.shoulderY,
3981
+ armLength: arm,
3982
+ legLength: leg,
3983
+ torsoRadiusX: Math.max(0.12, figureTorsoPoint(span.bustY, Math.PI / 2, silhouette).x),
3984
+ torsoRadiusZ: Math.max(0.11, figureTorsoPoint(span.bustY, 0, silhouette).z),
3985
+ torsoCenterY: (span.minY + span.maxY) * 0.5,
3986
+ isClassic: false
3987
+ };
2916
3988
  } else {
2917
3989
  const torso = fit.girth / shape.x;
2918
3990
  const shoulderY = BLOB_HEIGHT * build.shoulderHeight;
2919
3991
  const shoulder = blobRadiusAt(shoulderY, silhouette) * 0.92 * torso;
2920
3992
  const arm = 0.27 * build.armLength;
2921
- const hip = blobRadiusAt(BLOB_HEIGHT * 0.18, silhouette) * 0.42 * torso;
3993
+ const hipY = BLOB_HEIGHT * 0.18;
3994
+ const hip = blobRadiusAt(hipY, silhouette) * 0.42 * torso;
2922
3995
  const leg = 0.16 * build.legLength;
2923
3996
  limb("armL", -shoulder, shoulderY, arm, handGeometry, false, -1);
2924
3997
  limb("armR", shoulder, shoulderY, arm, handGeometry, false, 1);
2925
3998
  const knee = build.legLength > 1.2 ? 0.35 : 0;
2926
- limb("legL", -hip, BLOB_HEIGHT * 0.18, leg, footGeometry, true, -knee);
2927
- limb("legR", hip, BLOB_HEIGHT * 0.18, leg, footGeometry, true, knee);
3999
+ limb("legL", -hip, hipY, leg, footGeometry, true, -knee);
4000
+ limb("legR", hip, hipY, leg, footGeometry, true, knee);
2928
4001
  const bulk = build.muscle ** 0.6;
2929
4002
  pivots.armL.scale.set(fit.armWidth[0] * bulk, 1, fit.armWidth[0] * bulk);
2930
4003
  pivots.armR.scale.set(fit.armWidth[1] * bulk, 1, fit.armWidth[1] * bulk);
2931
4004
  pivots.legL.scale.set(fit.legWidth[0] * bulk, 1, fit.legWidth[0] * bulk);
2932
4005
  pivots.legR.scale.set(fit.legWidth[1] * bulk, 1, fit.legWidth[1] * bulk);
4006
+ ikMetrics = {
4007
+ hipHeight: legRaise + hipY,
4008
+ hipHalfWidth: hip,
4009
+ hipLocalY: hipY,
4010
+ shoulderHalfWidth: shoulder,
4011
+ shoulderLocalY: shoulderY,
4012
+ armLength: arm,
4013
+ legLength: leg,
4014
+ torsoRadiusX: blobRadiusAt(BLOB_HEIGHT * 0.45, silhouette) * torso,
4015
+ torsoRadiusZ: blobRadiusAt(BLOB_HEIGHT * 0.45, silhouette) * torso * (BLOB_RADIUS.z / BLOB_RADIUS.x),
4016
+ torsoCenterY: BLOB_HEIGHT * 0.48,
4017
+ isClassic: true
4018
+ };
4019
+ }
4020
+ for (const name of Object.keys(pivots)) {
4021
+ restAnchors[name].copy(pivots[name].position);
2933
4022
  }
2934
4023
  let shadow = null;
2935
4024
  if (options.shadow !== false) {
@@ -2945,6 +4034,7 @@ function createPlup(options = {}) {
2945
4034
  root.add(shadow);
2946
4035
  }
2947
4036
  let clip2 = "idle";
4037
+ let bakedClip = null;
2948
4038
  let held = {};
2949
4039
  let ragdoll = null;
2950
4040
  let down = false;
@@ -2954,13 +4044,31 @@ function createPlup(options = {}) {
2954
4044
  };
2955
4045
  if (options.ragdoll && options.ragdoll !== "off")
2956
4046
  ragdollOf().set(options.ragdoll);
2957
- const here = new Vector32;
2958
- const last = new Vector32;
2959
- const turn = new Quaternion;
4047
+ const here = new Vector34;
4048
+ const last = new Vector34;
4049
+ const turn = new Quaternion2;
4050
+ const DOWN_AXIS = new Vector34(0, -1, 0);
4051
+ const IDENTITY_Q = new Quaternion2;
4052
+ const headBobQ = new Quaternion2;
4053
+ const clampNum = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
2960
4054
  let tracked = false;
2961
4055
  let seconds = 0;
2962
4056
  let clock = 0;
2963
4057
  let lastDelta = 0;
4058
+ let lastPosX = 0;
4059
+ let lastPosZ = 0;
4060
+ let lastRotX = 0;
4061
+ let lastRotZ = 0;
4062
+ let prevVelX = 0;
4063
+ let prevVelY = 0;
4064
+ let prevVelZ = 0;
4065
+ let resetKinematics = true;
4066
+ const jiggleX = new Spring(105, 3.4);
4067
+ const jiggleY = new Spring(135, 3.8);
4068
+ const jiggleZ = new Spring(105, 3.4);
4069
+ const headBobX = new Spring(85, 3.4);
4070
+ const headBobZ = new Spring(85, 3.2);
4071
+ const jiggleGain = isFigure ? 0.9 + Math.max(0, build.bust - 1) * 0.42 + Math.max(0, build.hips - 1) * 0.28 : 1.3;
2964
4072
  const danceKinematics = (active, t) => {
2965
4073
  const out = {
2966
4074
  elbowLx: -0.14,
@@ -2976,88 +4084,7 @@ function createPlup(options = {}) {
2976
4084
  if (typeof active !== "string")
2977
4085
  return out;
2978
4086
  const TAU = Math.PI * 2;
2979
- const smooth01 = (v) => {
2980
- const c = Math.max(0, Math.min(1, v));
2981
- return c * c * (3 - 2 * c);
2982
- };
2983
- if (active === "brazil-funk") {
2984
- const p = t % 1.6 / 1.6;
2985
- const beat = 0.5 - 0.5 * Math.cos(p * TAU * 4);
2986
- const sway = Math.sin(p * TAU * 2);
2987
- out.elbowLx = -1.45 - 0.3 * Math.max(0, sway);
2988
- out.elbowLz = 0.42 + 0.18 * sway;
2989
- out.elbowRx = -1.45 - 0.3 * Math.max(0, -sway);
2990
- out.elbowRz = -0.42 + 0.18 * sway;
2991
- out.kneeL = 0.52 * beat + 0.18 * Math.max(0, sway);
2992
- out.kneeR = 0.52 * beat + 0.18 * Math.max(0, -sway);
2993
- out.hipX = sway * 0.11;
2994
- out.crouch = 0.085 * beat;
2995
- out.squash = -0.042 * beat + 0.018;
2996
- } else if (active === "pacu-jalur") {
2997
- const p = t % 2.4 / 2.4;
2998
- const wave = Math.sin(p * TAU);
2999
- const bounce = 0.5 - 0.5 * Math.cos(p * TAU * 2);
3000
- out.elbowLx = -1.15 - 0.38 * wave;
3001
- out.elbowLz = 0.35 + 0.38 * wave;
3002
- out.elbowRx = -1.15 + 0.38 * wave;
3003
- out.elbowRz = -0.35 + 0.38 * wave;
3004
- out.kneeL = 0.52 + 0.22 * bounce + 0.12 * Math.max(0, wave);
3005
- out.kneeR = 0.52 + 0.22 * bounce + 0.12 * Math.max(0, -wave);
3006
- out.hipX = wave * 0.1;
3007
- out.crouch = 0.095 + 0.055 * bounce;
3008
- out.squash = -0.032 * bounce + 0.014;
3009
- } else if (active === "velocity") {
3010
- const p = t % 2 / 2;
3011
- const hit1 = smooth01((p - 0.2) / 0.07) * (1 - smooth01((p - 0.46) / 0.12));
3012
- const hit2 = smooth01((p - 0.63) / 0.07) * (1 - smooth01((p - 0.88) / 0.1));
3013
- out.elbowLx = -0.55 - 1.15 * hit1 + 0.35 * hit2;
3014
- out.elbowLz = 0.72 * hit1 - 0.15 * hit2;
3015
- out.elbowRx = -0.55 - 1.15 * hit1 - 1.05 * hit2;
3016
- out.elbowRz = -0.72 * hit1 - 0.55 * hit2;
3017
- out.kneeL = 0.16 + 0.58 * hit1 + 0.22 * hit2;
3018
- out.kneeR = 0.16 + 0.58 * hit1 + 0.34 * hit2;
3019
- out.hipX = -0.08 * hit1 + 0.1 * hit2;
3020
- out.crouch = 0.02 + 0.11 * hit1 + 0.04 * hit2;
3021
- out.squash = -0.055 * hit1 + 0.028 * hit2;
3022
- } else if (active === "griddy") {
3023
- const p = t % 1.6 / 1.6;
3024
- const goggles = 0.5 - 0.5 * Math.cos(p * TAU * 2);
3025
- const step = Math.sin(p * TAU * 2);
3026
- out.elbowLx = -0.25 - 1.85 * goggles;
3027
- out.elbowLz = 0.46 * goggles;
3028
- out.elbowRx = -0.25 - 1.85 * goggles;
3029
- out.elbowRz = -0.46 * goggles;
3030
- out.kneeL = 0.15 + 0.62 * Math.max(0, -step) + 0.18 * goggles;
3031
- out.kneeR = 0.15 + 0.62 * Math.max(0, step) + 0.18 * goggles;
3032
- out.hipX = step * 0.05;
3033
- out.crouch = 0.045 + 0.055 * goggles;
3034
- out.squash = -0.036 * goggles + 0.015;
3035
- } else if (active === "floss") {
3036
- const p = t % 1.6 / 1.6;
3037
- const swing = Math.cos(p * TAU * 2);
3038
- const beat = Math.abs(swing);
3039
- out.elbowLx = -0.08;
3040
- out.elbowRx = -0.08;
3041
- out.kneeL = 0.2 + 0.16 * beat;
3042
- out.kneeR = 0.2 + 0.16 * beat;
3043
- out.hipX = -swing * 0.17;
3044
- out.crouch = 0.035 * beat;
3045
- out.squash = -0.026 * beat + 0.01;
3046
- } else if (active === "caramel") {
3047
- const p = t % 1.6 / 1.6;
3048
- const sway = Math.cos(p * TAU);
3049
- const beat = 0.5 - 0.5 * Math.cos(p * TAU * 2);
3050
- const flap = Math.sin(p * TAU * 4) * 0.26;
3051
- out.elbowLx = -0.35;
3052
- out.elbowLz = -1.2 + flap;
3053
- out.elbowRx = -0.35;
3054
- out.elbowRz = 1.2 - flap;
3055
- out.kneeL = 0.45 * (1 - beat) + 0.15 * Math.max(0, sway);
3056
- out.kneeR = 0.45 * (1 - beat) + 0.15 * Math.max(0, -sway);
3057
- out.hipX = -sway * 0.14;
3058
- out.crouch = 0.075 * (1 - beat);
3059
- out.squash = -0.042 * (1 - beat) + 0.024 * beat;
3060
- } else if (active === "walk" || active === "run") {
4087
+ if (active === "walk" || active === "run") {
3061
4088
  const rate = active === "run" ? 2.4 : 1.4;
3062
4089
  const stride = Math.sin(t * rate * TAU);
3063
4090
  const bend = active === "run" ? 0.95 : 0.42;
@@ -3077,58 +4104,100 @@ function createPlup(options = {}) {
3077
4104
  return out;
3078
4105
  };
3079
4106
  const apply = () => {
3080
- const pose = resolvePose("plup", mergePoses(sampleClip(clip2, seconds), held));
3081
- const kin = danceKinematics(clip2, seconds);
3082
- const byAlias = {
3083
- armL: "LeftArm",
3084
- armR: "RightArm",
3085
- legL: "LeftLeg",
3086
- legR: "RightLeg"
3087
- };
4107
+ const useIk = !options.model && (bakedClip !== null || typeof clip2 === "string" && isIkDanceName(clip2));
4108
+ let baseSquash = 0;
4109
+ let clipLiftY = legRaise;
3088
4110
  const targets = {};
3089
- for (const name of Object.keys(pivots)) {
3090
- const rotation = pose.get(byAlias[name]);
3091
- const clearance = name === "armL" ? fit.armClear[0] : name === "armR" ? -fit.armClear[1] : 0;
3092
- const z = rotation?.z ?? 0;
3093
- const side = name === "armL" ? -1 : name === "armR" ? 1 : 0;
3094
- const restAngle = isFigure ? 0.14 : 0.42;
3095
- const rest = options.model ? 0 : side * restAngle * Math.max(0, 1 - Math.abs(z) / 1.4);
3096
- const kneeComp = isFigure && name === "legL" ? -kin.kneeL * 0.45 : isFigure && name === "legR" ? -kin.kneeR * 0.45 : 0;
3097
- const rx = (rotation?.x ?? 0) + kneeComp;
3098
- pivots[name].rotation.set(rx, rotation?.y ?? 0, z + clearance + rest);
3099
- targets[name] = { x: rx, z: z + clearance + rest };
3100
- }
3101
- if (subPivots.elbowL)
3102
- subPivots.elbowL.rotation.set(kin.elbowLx, 0, kin.elbowLz);
3103
- if (subPivots.elbowR)
3104
- subPivots.elbowR.rotation.set(kin.elbowRx, 0, kin.elbowRz);
3105
- if (subPivots.kneeL)
3106
- subPivots.kneeL.rotation.set(kin.kneeL, 0, 0);
3107
- if (subPivots.kneeR)
3108
- subPivots.kneeR.rotation.set(kin.kneeR, 0, 0);
3109
- const body = pose.get("Body");
3110
- const head = pose.get("Head");
3111
- lifted.rotation.set(body?.x ?? 0, body?.y ?? 0, body?.z ?? 0);
3112
- if (isFigure) {
3113
- headGroup.rotation.set(head?.x ?? 0, head?.y ?? 0, head?.z ?? 0);
3114
- }
3115
- const crouchDrop = isFigure ? kin.crouch * (figureLegLen / 0.44) : kin.crouch * 0.4;
3116
- const clipLiftY = Math.max(0, legRaise + clipLift(clip2, seconds) * 0.32 * fit.lift - crouchDrop);
3117
- const breath = Math.sin(clock * 3.2) * (isFigure ? 0.01 : 0.018) * fit.squash;
3118
- const sy = 1 + breath + kin.squash;
3119
- const sxz = 1 / Math.sqrt(Math.max(0.75, sy));
3120
- lifted.scale.set((isFigure ? 1 : shape.x) * fit.stature * sxz, (isFigure ? 1 : shape.y) * fit.stature * sy, (isFigure ? 1 : shape.x) * fit.stature * sxz);
3121
- lifted.position.set(kin.hipX, clipLiftY, 0);
4111
+ let bodyTilt = { x: 0, z: 0 };
4112
+ if (useIk) {
4113
+ const frame = bakedClip ? sampleBakedJoints(bakedClip, seconds) : sampleIkDance(clip2, seconds);
4114
+ const ik = retarget18JointPose(frame, ikMetrics);
4115
+ lifted.quaternion.copy(ik.torsoQ);
4116
+ lifted.position.copy(ik.rootPos).multiplyScalar(fit.stature);
4117
+ clipLiftY = lifted.position.y;
4118
+ baseSquash = ik.squash;
4119
+ if (isFigure && subPivots.elbowL && subPivots.elbowR && subPivots.kneeL && subPivots.kneeR) {
4120
+ aimTwoBoneLimb(pivots.armL, subPivots.elbowL, ik.armL[0], ik.armL[1], ik.armL[2]);
4121
+ aimTwoBoneLimb(pivots.armR, subPivots.elbowR, ik.armR[0], ik.armR[1], ik.armR[2]);
4122
+ aimTwoBoneLimb(pivots.legL, subPivots.kneeL, ik.legL.pts[0], ik.legL.pts[1], ik.legL.pts[2]);
4123
+ aimTwoBoneLimb(pivots.legR, subPivots.kneeR, ik.legR.pts[0], ik.legR.pts[1], ik.legR.pts[2]);
4124
+ if (shoePivots.legL)
4125
+ orientFoot(shoePivots.legL, ik.legL.footPitch, ik.legL.footYaw);
4126
+ if (shoePivots.legR)
4127
+ orientFoot(shoePivots.legR, ik.legR.footPitch, ik.legR.footYaw);
4128
+ headGroup.quaternion.copy(ik.headQ);
4129
+ } else {
4130
+ const aimSingle = (pivot, from, to) => {
4131
+ pivot.position.copy(from);
4132
+ const dir = to.clone().sub(from);
4133
+ if (dir.lengthSq() > 0.000001)
4134
+ pivot.quaternion.setFromUnitVectors(DOWN_AXIS, dir.normalize());
4135
+ };
4136
+ aimSingle(pivots.armL, ik.armL[0], ik.armL[2]);
4137
+ aimSingle(pivots.armR, ik.armR[0], ik.armR[2]);
4138
+ aimSingle(pivots.legL, ik.legL.pts[0], ik.legL.pts[2]);
4139
+ aimSingle(pivots.legR, ik.legR.pts[0], ik.legR.pts[2]);
4140
+ }
4141
+ for (const name of Object.keys(pivots)) {
4142
+ targets[name] = { x: pivots[name].rotation.x, z: pivots[name].rotation.z };
4143
+ }
4144
+ bodyTilt = { x: lifted.rotation.x, z: lifted.rotation.z };
4145
+ } else {
4146
+ const pose = resolvePose("plup", mergePoses(sampleClip(clip2, seconds), held));
4147
+ const kin = danceKinematics(clip2, seconds);
4148
+ const byAlias = {
4149
+ armL: "LeftArm",
4150
+ armR: "RightArm",
4151
+ legL: "LeftLeg",
4152
+ legR: "RightLeg"
4153
+ };
4154
+ for (const name of Object.keys(pivots)) {
4155
+ pivots[name].position.copy(restAnchors[name]);
4156
+ const rotation = pose.get(byAlias[name]);
4157
+ const clearance = name === "armL" ? fit.armClear[0] : name === "armR" ? -fit.armClear[1] : 0;
4158
+ const z = rotation?.z ?? 0;
4159
+ const side = name === "armL" ? -1 : name === "armR" ? 1 : 0;
4160
+ const restAngle = isFigure ? 0.14 : 0.42;
4161
+ const rest = options.model ? 0 : side * restAngle * Math.max(0, 1 - Math.abs(z) / 1.4);
4162
+ const kneeComp = isFigure && name === "legL" ? -kin.kneeL * 0.45 : isFigure && name === "legR" ? -kin.kneeR * 0.45 : 0;
4163
+ const rx = (rotation?.x ?? 0) + kneeComp;
4164
+ pivots[name].rotation.set(rx, rotation?.y ?? 0, z + clearance + rest);
4165
+ targets[name] = { x: rx, z: z + clearance + rest };
4166
+ }
4167
+ if (subPivots.elbowL)
4168
+ subPivots.elbowL.rotation.set(kin.elbowLx, 0, kin.elbowLz);
4169
+ if (subPivots.elbowR)
4170
+ subPivots.elbowR.rotation.set(kin.elbowRx, 0, kin.elbowRz);
4171
+ if (subPivots.kneeL)
4172
+ subPivots.kneeL.rotation.set(kin.kneeL, 0, 0);
4173
+ if (subPivots.kneeR)
4174
+ subPivots.kneeR.rotation.set(kin.kneeR, 0, 0);
4175
+ if (shoePivots.legL)
4176
+ shoePivots.legL.quaternion.copy(IDENTITY_Q);
4177
+ if (shoePivots.legR)
4178
+ shoePivots.legR.quaternion.copy(IDENTITY_Q);
4179
+ const body = pose.get("Body");
4180
+ const head = pose.get("Head");
4181
+ lifted.rotation.set(body?.x ?? 0, body?.y ?? 0, body?.z ?? 0);
4182
+ if (isFigure) {
4183
+ headGroup.rotation.set(head?.x ?? 0, head?.y ?? 0, head?.z ?? 0);
4184
+ }
4185
+ const crouchDrop = isFigure ? kin.crouch * (figureLegLen / 0.44) : kin.crouch * 0.4;
4186
+ clipLiftY = Math.max(0, legRaise + clipLift(clip2, seconds) * 0.32 * fit.lift - crouchDrop);
4187
+ baseSquash = kin.squash;
4188
+ lifted.position.set(kin.hipX, clipLiftY, 0);
4189
+ bodyTilt = { x: body?.x ?? 0, z: body?.z ?? 0 };
4190
+ }
3122
4191
  if (ragdoll) {
3123
4192
  root.getWorldPosition(here);
3124
- const step2 = Math.max(0.001, lastDelta);
3125
- const velocity = tracked ? here.clone().sub(last).divideScalar(step2) : new Vector32;
4193
+ const step = Math.max(0.001, lastDelta);
4194
+ const velocity = tracked ? here.clone().sub(last).divideScalar(step) : new Vector34;
3126
4195
  last.copy(here);
3127
4196
  tracked = true;
3128
4197
  velocity.applyQuaternion(root.getWorldQuaternion(turn).invert());
3129
4198
  const out = ragdoll.step(lastDelta, {
3130
4199
  joints: targets,
3131
- body: { x: body?.x ?? 0, z: body?.z ?? 0 },
4200
+ body: bodyTilt,
3132
4201
  lift: clipLiftY,
3133
4202
  velocity: { x: velocity.x, z: velocity.z }
3134
4203
  });
@@ -3143,16 +4212,69 @@ function createPlup(options = {}) {
3143
4212
  shadow?.position.set(out.offset.x, 0.005, out.offset.z);
3144
4213
  down = out.down;
3145
4214
  }
3146
- const step = Math.max(0.001, lastDelta);
3147
- const yaw = root.rotation.y + (root.parent?.rotation.y ?? 0);
3148
- const motion = { lift: (lifted.position.y - lastLift) / step, yaw: (yaw - lastYaw) / step };
3149
- lastLift = lifted.position.y;
3150
- lastYaw = yaw;
4215
+ const yaw = root.rotation.y + (root.parent?.rotation.y ?? 0) + lifted.rotation.y;
4216
+ let velX = 0;
4217
+ let velY = 0;
4218
+ let velZ = 0;
4219
+ let yawRate = 0;
4220
+ if (resetKinematics || lastDelta <= 0) {
4221
+ lastPosX = lifted.position.x;
4222
+ lastLift = lifted.position.y;
4223
+ lastPosZ = lifted.position.z;
4224
+ lastYaw = yaw;
4225
+ lastRotX = lifted.rotation.x;
4226
+ lastRotZ = lifted.rotation.z;
4227
+ prevVelX = 0;
4228
+ prevVelY = 0;
4229
+ prevVelZ = 0;
4230
+ resetKinematics = false;
4231
+ } else {
4232
+ const step = Math.max(0.001, lastDelta);
4233
+ velX = clampNum((lifted.position.x - lastPosX) / step, -6, 6);
4234
+ velY = clampNum((lifted.position.y - lastLift) / step, -6, 6);
4235
+ velZ = clampNum((lifted.position.z - lastPosZ) / step, -6, 6);
4236
+ yawRate = clampNum((yaw - lastYaw) / step, -12, 12);
4237
+ const rotVelX = clampNum((lifted.rotation.x - lastRotX) / step, -10, 10);
4238
+ const rotVelZ = clampNum((lifted.rotation.z - lastRotZ) / step, -10, 10);
4239
+ const accX = clampNum((velX - prevVelX) / step, -32, 32);
4240
+ const accY = clampNum((velY - prevVelY) / step, -32, 32);
4241
+ const accZ = clampNum((velZ - prevVelZ) / step, -32, 32);
4242
+ jiggleX.kick((-accX * 0.02 + rotVelZ * 0.045) * jiggleGain);
4243
+ jiggleY.kick((-accY * 0.024 - Math.abs(accX) * 0.005) * jiggleGain);
4244
+ jiggleZ.kick((-accZ * 0.02 - rotVelX * 0.045) * jiggleGain);
4245
+ const jx = clampNum(jiggleX.step(-velX * 0.022 * jiggleGain, lastDelta), -0.065, 0.065);
4246
+ const jy = clampNum(jiggleY.step(-velY * 0.028 * jiggleGain, lastDelta), -0.075, 0.075);
4247
+ const jz = clampNum(jiggleZ.step(-velZ * 0.022 * jiggleGain, lastDelta), -0.065, 0.065);
4248
+ jiggleUniform.value.set(jx, jy, jz);
4249
+ if (isFigure) {
4250
+ headGroup.position.y = headMetrics.originY + jy * 0.35;
4251
+ const hPitch = clampNum(headBobX.step(-velY * 0.045 - velZ * 0.05, lastDelta), -0.16, 0.16);
4252
+ const hRoll = clampNum(headBobZ.step(velX * 0.065, lastDelta), -0.18, 0.18);
4253
+ headBobQ.set(hPitch * 0.5, 0, hRoll * 0.5, 1).normalize();
4254
+ headGroup.quaternion.multiply(headBobQ);
4255
+ }
4256
+ lastPosX = lifted.position.x;
4257
+ lastLift = lifted.position.y;
4258
+ lastPosZ = lifted.position.z;
4259
+ lastYaw = yaw;
4260
+ lastRotX = lifted.rotation.x;
4261
+ lastRotZ = lifted.rotation.z;
4262
+ prevVelX = velX;
4263
+ prevVelY = velY;
4264
+ prevVelZ = velZ;
4265
+ }
4266
+ const breath = Math.sin(clock * 3.2) * (isFigure ? 0.01 : 0.018) * fit.squash;
4267
+ const sy = clampNum(1 + breath + baseSquash + jiggleUniform.value.y * 0.55, 0.84, 1.16);
4268
+ const sxz = 1 / Math.sqrt(Math.max(0.75, sy));
4269
+ lifted.scale.set((isFigure ? 1 : shape.x) * fit.stature * sxz, (isFigure ? 1 : shape.y) * fit.stature * sy, (isFigure ? 1 : shape.x) * fit.stature * sxz);
4270
+ const motion = { lift: velY, yaw: yawRate, swayX: velX, swayZ: velZ };
3151
4271
  for (const piece2 of worn.values())
3152
4272
  piece2.tick?.(clock, lastDelta, motion);
3153
4273
  if (shadow) {
3154
- const air = Math.min(1, (lifted.position.y - legRaise) / 0.5);
4274
+ const air = Math.max(0, Math.min(1, (lifted.position.y - legRaise * fit.stature) / 0.5));
3155
4275
  const shadowR = isFigure ? 0.72 : 1;
4276
+ shadow.position.x = lifted.position.x;
4277
+ shadow.position.z = lifted.position.z;
3156
4278
  shadow.scale.set((1 - air * 0.3) * fit.stature * fit.girth * shadowR, 0.02, (0.9 - air * 0.3) * fit.stature * fit.girth * shadowR);
3157
4279
  shadow.material.opacity = 0.4 - air * 0.18;
3158
4280
  }
@@ -3166,17 +4288,30 @@ function createPlup(options = {}) {
3166
4288
  return {
3167
4289
  object: root,
3168
4290
  play(next) {
3169
- if (next !== clip2)
4291
+ if (next !== clip2 || bakedClip !== null) {
3170
4292
  seconds = 0;
4293
+ resetKinematics = true;
4294
+ }
4295
+ bakedClip = null;
3171
4296
  clip2 = next;
3172
4297
  },
4298
+ playBaked(next) {
4299
+ if (next !== bakedClip) {
4300
+ seconds = 0;
4301
+ resetKinematics = true;
4302
+ }
4303
+ bakedClip = next;
4304
+ },
3173
4305
  emote(name, custom) {
3174
4306
  const found = custom ?? emoteOf(name);
3175
4307
  if (!found)
3176
4308
  return;
3177
4309
  const next = found.anim ?? found.clip;
3178
- if (next !== clip2)
4310
+ if (next !== clip2 || bakedClip !== null) {
3179
4311
  seconds = 0;
4312
+ resetKinematics = true;
4313
+ }
4314
+ bakedClip = null;
3180
4315
  clip2 = next;
3181
4316
  if (found.face !== face) {
3182
4317
  face = found.face;
@@ -3194,7 +4329,7 @@ function createPlup(options = {}) {
3194
4329
  ragdollOf().set(mode);
3195
4330
  },
3196
4331
  push(x, y, z) {
3197
- const local = new Vector32(x, y, z).applyQuaternion(root.getWorldQuaternion(turn).invert());
4332
+ const local = new Vector34(x, y, z).applyQuaternion(root.getWorldQuaternion(turn).invert());
3198
4333
  ragdollOf().push(local.x, local.y, local.z);
3199
4334
  },
3200
4335
  isDown: () => down,
@@ -3242,6 +4377,10 @@ function createPlup(options = {}) {
3242
4377
  anime2?.material.dispose();
3243
4378
  bodyMaterial.dispose();
3244
4379
  torsoMaterial.dispose();
4380
+ torsoInkMat.dispose();
4381
+ blobInkMat.dispose();
4382
+ blobNeonMat.dispose();
4383
+ garmentInkMat.dispose();
3245
4384
  limbMaterial.dispose();
3246
4385
  legMaterial.dispose();
3247
4386
  tipMaterial.dispose();
@@ -3382,7 +4521,13 @@ function createCharacter(rigId = "plup", look = { bodyColor: "#3d7bff" }, bodySc
3382
4521
  export {
3383
4522
  wearSlotOf,
3384
4523
  toon,
4524
+ solveTwoBoneIK,
4525
+ sampleIkDance,
4526
+ sampleBakedJoints,
4527
+ retarget18JointPose,
4528
+ orientFoot,
3385
4529
  isWearKey,
4530
+ isIkDanceName,
3386
4531
  isHighResFace,
3387
4532
  isHairKey,
3388
4533
  hairVolume,
@@ -3395,7 +4540,9 @@ export {
3395
4540
  buildFigureHeadGeometry,
3396
4541
  buildBlobGeometry,
3397
4542
  blobRadiusAt,
4543
+ aimTwoBoneLimb,
3398
4544
  WEARABLES,
4545
+ SKELETON_JOINTS,
3399
4546
  EMOTES,
3400
4547
  BODY_PRESETS,
3401
4548
  AUTHORED_CLIPS,