@plupin/character 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/anime-face.d.ts +42 -0
  2. package/dist/anime-face.js +14 -0
  3. package/dist/blob.d.ts +32 -0
  4. package/dist/blob.js +18 -0
  5. package/dist/body-presets.d.ts +85 -0
  6. package/dist/canvas.js +7 -7
  7. package/dist/chunk-09c5tps4.js +337 -0
  8. package/dist/chunk-60p135hw.js +103 -0
  9. package/dist/chunk-dpb0rnw9.js +37 -0
  10. package/dist/chunk-g1c0wdcj.js +825 -0
  11. package/dist/chunk-kber92gm.js +415 -0
  12. package/dist/{chunk-k5gwaq6t.js → chunk-sa2r1cxz.js} +30 -3
  13. package/dist/chunk-yd5zzkkg.js +313 -0
  14. package/dist/clips.d.ts +40 -0
  15. package/dist/dress.d.ts +4 -0
  16. package/dist/emote.d.ts +5 -3
  17. package/dist/gaze.d.ts +81 -0
  18. package/dist/gaze.js +113 -0
  19. package/dist/hair3d.d.ts +3 -0
  20. package/dist/index.d.ts +9 -2
  21. package/dist/index.js +84 -10
  22. package/dist/listing.d.ts +1 -1
  23. package/dist/listing.js +16 -6
  24. package/dist/platform-body-data.d.ts +9 -0
  25. package/dist/platform-body.d.ts +91 -0
  26. package/dist/plup3d.d.ts +75 -27
  27. package/dist/png.d.ts +19 -2
  28. package/dist/pose.d.ts +7 -1
  29. package/dist/pose.js +1 -1
  30. package/dist/proportions.d.ts +31 -0
  31. package/dist/ragdoll.d.ts +51 -0
  32. package/dist/resolution.d.ts +21 -0
  33. package/dist/skin-map.d.ts +155 -0
  34. package/dist/skin-map.js +55 -0
  35. package/dist/skin-native.d.ts +55 -6
  36. package/dist/texture.d.ts +8 -0
  37. package/dist/three.d.ts +3 -0
  38. package/dist/three.js +1909 -188
  39. package/dist/wear3d.d.ts +99 -0
  40. package/dist/wearables.d.ts +203 -0
  41. package/dist/wearables.js +26 -0
  42. package/package.json +21 -1
  43. package/dist/chunk-ae7gp5cc.js +0 -101
  44. package/dist/chunk-wpbgtn0y.js +0 -179
package/dist/three.js CHANGED
@@ -1,143 +1,1605 @@
1
1
  import {
2
+ BLOB_HEIGHT,
3
+ BLOB_RADIUS,
4
+ BLOB_SEAT,
5
+ blobRadiusAt,
6
+ buildBlobGeometry
7
+ } from "./chunk-dpb0rnw9.js";
8
+ import {
9
+ ANIME_FACE_SIZE,
10
+ ANIME_FACE_UV,
11
+ drawAnimeFace
12
+ } from "./chunk-09c5tps4.js";
13
+ import {
14
+ RAGDOLL_JOINTS,
15
+ createRagdoll,
2
16
  emoteOf
3
- } from "./chunk-ae7gp5cc.js";
17
+ } from "./chunk-yd5zzkkg.js";
18
+ import {
19
+ hairVolume,
20
+ isHairKey,
21
+ wearSlotOf
22
+ } from "./chunk-60p135hw.js";
4
23
  import {
5
24
  boneSkin,
6
25
  clampBodyScale,
26
+ clampPlupBody,
7
27
  nativePartOf,
8
28
  scaleBone
9
- } from "./chunk-k5gwaq6t.js";
10
- import {
11
- FACE_STAMP_PALETTE,
12
- NAMED_FACE_STAMPS
13
- } from "./chunk-aa5nstet.js";
29
+ } from "./chunk-sa2r1cxz.js";
14
30
  import {
15
31
  RIGS,
16
32
  clipLift,
17
33
  mergePoses,
18
34
  resolvePose,
19
35
  sampleClip
20
- } from "./chunk-wpbgtn0y.js";
36
+ } from "./chunk-g1c0wdcj.js";
37
+ import {
38
+ BODY_HEIGHT,
39
+ BODY_SHAPES,
40
+ BODY_WIDTH,
41
+ FACE_COLUMN,
42
+ FACE_ROW,
43
+ SKIN_PALETTE,
44
+ faceStamp
45
+ } from "./chunk-kber92gm.js";
46
+ import {
47
+ FACE_STAMP_PALETTE
48
+ } from "./chunk-aa5nstet.js";
21
49
 
22
50
  // src/three.ts
23
51
  import {
24
- BoxGeometry,
25
- CanvasTexture as CanvasTexture2,
26
- Group as Group2,
27
- Mesh as Mesh2,
52
+ BoxGeometry as BoxGeometry2,
53
+ CanvasTexture as CanvasTexture3,
54
+ Group as Group3,
55
+ Mesh as Mesh3,
28
56
  MeshStandardMaterial,
29
- NearestFilter as NearestFilter2,
30
- SRGBColorSpace as SRGBColorSpace2
57
+ SRGBColorSpace as SRGBColorSpace3
31
58
  } from "three";
32
59
 
33
60
  // src/plup3d.ts
34
61
  import {
35
62
  BackSide,
36
- CanvasTexture,
63
+ CanvasTexture as CanvasTexture2,
37
64
  CapsuleGeometry,
65
+ Color as Color2,
66
+ DoubleSide,
67
+ Group as Group2,
68
+ Mesh as Mesh2,
69
+ MeshBasicMaterial as MeshBasicMaterial2,
70
+ QuadraticBezierCurve3,
71
+ Quaternion,
72
+ RepeatWrapping as RepeatWrapping2,
73
+ ShaderMaterial,
74
+ SphereGeometry as SphereGeometry3,
75
+ SRGBColorSpace as SRGBColorSpace2,
76
+ TubeGeometry,
77
+ Vector3 as Vector32
78
+ } from "three";
79
+
80
+ // src/hair3d.ts
81
+ import {
82
+ BoxGeometry,
83
+ BufferAttribute as BufferAttribute2,
84
+ BufferGeometry as BufferGeometry2,
85
+ CatmullRomCurve3,
86
+ SphereGeometry as SphereGeometry2,
87
+ TorusGeometry as TorusGeometry2,
88
+ Vector3
89
+ } from "three";
90
+
91
+ // src/wear3d.ts
92
+ import {
93
+ AdditiveBlending,
94
+ BufferAttribute,
95
+ BufferGeometry,
96
+ CanvasTexture,
38
97
  Color,
98
+ ConeGeometry,
99
+ CylinderGeometry,
100
+ ExtrudeGeometry,
39
101
  Group,
102
+ IcosahedronGeometry,
103
+ LatheGeometry,
104
+ LinearFilter,
40
105
  Mesh,
41
106
  MeshBasicMaterial,
42
- NearestFilter,
107
+ OctahedronGeometry,
43
108
  RepeatWrapping,
44
- ShaderMaterial,
109
+ Shape,
45
110
  SphereGeometry,
46
- SRGBColorSpace
111
+ SRGBColorSpace,
112
+ TorusGeometry,
113
+ Vector2
47
114
  } from "three";
48
- var SKIN_PALETTE = {
49
- B: "#2f6fed",
50
- L: "#6a96ff",
51
- D: "#1f4fc0",
52
- l: "#a9c4ff",
53
- k: "#161923",
54
- w: "#ffffff",
55
- a: "#8b93a8",
56
- r: "#e2574c",
57
- o: "#e6a23c",
58
- y: "#f2d24b",
59
- g: "#3fae74",
60
- c: "#4cc9e2",
61
- v: "#8a5ad8",
62
- p: "#f08aa8",
63
- n: "#8a5a3c",
64
- s: "#f0b184"
115
+ var DEPTH = BLOB_RADIUS.z / BLOB_RADIUS.x;
116
+ var TOP = BLOB_HEIGHT;
117
+ var EYES_Y = 0.53;
118
+ var COLLAR_Y = 0.27;
119
+ var clamp = (value, min, max) => Math.min(max, Math.max(min, value));
120
+ var smooth = (edge0, edge1, x) => {
121
+ const t = clamp((x - edge0) / (edge1 - edge0), 0, 1);
122
+ return t * t * (3 - 2 * t);
123
+ };
124
+
125
+ class Spring {
126
+ stiffness;
127
+ damping;
128
+ value = 0;
129
+ velocity = 0;
130
+ constructor(stiffness, damping, start = 0) {
131
+ this.stiffness = stiffness;
132
+ this.damping = damping;
133
+ this.value = start;
134
+ }
135
+ step(target, delta) {
136
+ const dt = Math.min(delta, 1 / 30);
137
+ const force = this.stiffness * (target - this.value) - this.damping * this.velocity;
138
+ this.velocity += force * dt;
139
+ this.value += this.velocity * dt;
140
+ return this.value;
141
+ }
142
+ kick(amount) {
143
+ this.velocity += amount;
144
+ }
145
+ }
146
+ var calm = (motion) => ({
147
+ lift: clamp(motion.lift, -4, 4),
148
+ yaw: clamp(motion.yaw, -8, 8)
149
+ });
150
+ function canvasTexture(size, draw) {
151
+ const canvas = document.createElement("canvas");
152
+ canvas.width = canvas.height = size;
153
+ const ctx = canvas.getContext("2d");
154
+ if (ctx)
155
+ draw(ctx, size);
156
+ const texture = new CanvasTexture(canvas);
157
+ texture.colorSpace = SRGBColorSpace;
158
+ texture.wrapS = texture.wrapT = RepeatWrapping;
159
+ texture.magFilter = LinearFilter;
160
+ return texture;
161
+ }
162
+ function tartan(ground, band, line) {
163
+ return canvasTexture(128, (ctx, size) => {
164
+ ctx.fillStyle = ground;
165
+ ctx.fillRect(0, 0, size, size);
166
+ ctx.globalAlpha = 0.55;
167
+ ctx.fillStyle = band;
168
+ for (const at of [0, 64]) {
169
+ ctx.fillRect(at + 8, 0, 26, size);
170
+ ctx.fillRect(0, at + 8, size, 26);
171
+ }
172
+ ctx.globalAlpha = 0.9;
173
+ ctx.fillStyle = line;
174
+ for (const at of [0, 64]) {
175
+ ctx.fillRect(at + 46, 0, 3, size);
176
+ ctx.fillRect(0, at + 46, size, 3);
177
+ }
178
+ ctx.globalAlpha = 1;
179
+ });
180
+ }
181
+ function dots(ground, dot) {
182
+ return canvasTexture(64, (ctx, size) => {
183
+ ctx.fillStyle = ground;
184
+ ctx.fillRect(0, 0, size, size);
185
+ ctx.fillStyle = dot;
186
+ for (const [x, y] of [
187
+ [16, 16],
188
+ [48, 48]
189
+ ]) {
190
+ for (const ox of [-size, 0, size])
191
+ for (const oy of [-size, 0, size]) {
192
+ ctx.beginPath();
193
+ ctx.arc(x + ox, y + oy, 7, 0, Math.PI * 2);
194
+ ctx.fill();
195
+ }
196
+ }
197
+ });
198
+ }
199
+ function knit(ground, stripe) {
200
+ return canvasTexture(64, (ctx, size) => {
201
+ ctx.fillStyle = ground;
202
+ ctx.fillRect(0, 0, size, size);
203
+ ctx.fillStyle = stripe;
204
+ ctx.fillRect(0, 22, size, 7);
205
+ ctx.fillRect(0, 36, size, 7);
206
+ ctx.fillStyle = "rgba(0,0,0,0.16)";
207
+ for (let x = 0;x < size; x += 8)
208
+ ctx.fillRect(x, 0, 3, size);
209
+ ctx.fillStyle = "rgba(255,255,255,0.14)";
210
+ for (let y = 0;y < size; y += 4)
211
+ for (let x = 4;x < size; x += 8)
212
+ ctx.fillRect(x, y, 2, 2);
213
+ });
214
+ }
215
+ function candy(a, b) {
216
+ return canvasTexture(64, (ctx, size) => {
217
+ ctx.fillStyle = a;
218
+ ctx.fillRect(0, 0, size, size);
219
+ ctx.fillStyle = b;
220
+ for (let i = -2;i < 3; i += 1) {
221
+ ctx.beginPath();
222
+ ctx.moveTo(i * 32, size);
223
+ ctx.lineTo(i * 32 + 14, size);
224
+ ctx.lineTo(i * 32 + 14 + size, 0);
225
+ ctx.lineTo(i * 32 + size, 0);
226
+ ctx.closePath();
227
+ ctx.fill();
228
+ }
229
+ ctx.fillStyle = "#ffffff";
230
+ for (let i = 0;i < 6; i += 1) {
231
+ ctx.beginPath();
232
+ ctx.arc(8 + i * 11, 8 + i * 23 % 50, 2.5, 0, Math.PI * 2);
233
+ ctx.fill();
234
+ }
235
+ });
236
+ }
237
+ function earSkin() {
238
+ return canvasTexture(64, (ctx, size) => {
239
+ const fade = ctx.createLinearGradient(0, 0, size, 0);
240
+ fade.addColorStop(0, "#ffe1ec");
241
+ fade.addColorStop(0.3, "#ff9cc2");
242
+ fade.addColorStop(0.5, "#ff86b4");
243
+ fade.addColorStop(0.7, "#ff9cc2");
244
+ fade.addColorStop(1, "#ffe1ec");
245
+ ctx.fillStyle = fade;
246
+ ctx.fillRect(0, 0, size, size);
247
+ ctx.strokeStyle = "rgba(230,90,140,0.45)";
248
+ ctx.lineWidth = 1.5;
249
+ for (const bend of [-6, 0, 6]) {
250
+ ctx.beginPath();
251
+ ctx.moveTo(32, size);
252
+ ctx.quadraticCurveTo(32 + bend, 32, 32 + bend * 1.6, 4);
253
+ ctx.stroke();
254
+ }
255
+ });
256
+ }
257
+ function pleats() {
258
+ return canvasTexture(64, (ctx, size) => {
259
+ ctx.fillStyle = "#fbfaff";
260
+ ctx.fillRect(0, 0, size, size);
261
+ ctx.fillStyle = "rgba(60,50,110,0.12)";
262
+ for (let x = 2;x < size; x += 8)
263
+ ctx.fillRect(x, 0, 2, size);
264
+ });
265
+ }
266
+ function lensGlass() {
267
+ return canvasTexture(64, (ctx, size) => {
268
+ const fade = ctx.createLinearGradient(0, 0, 0, size);
269
+ fade.addColorStop(0, "#0d0a1c");
270
+ fade.addColorStop(1, "#4a3380");
271
+ ctx.fillStyle = fade;
272
+ ctx.fillRect(0, 0, size, size);
273
+ for (const [x, w, alpha] of [
274
+ [10, 8, 0.75],
275
+ [24, 3, 0.4]
276
+ ]) {
277
+ ctx.fillStyle = `rgba(255,255,255,${alpha})`;
278
+ ctx.beginPath();
279
+ ctx.moveTo(x, 44);
280
+ ctx.lineTo(x + w, 44);
281
+ ctx.lineTo(x + w + 24, 12);
282
+ ctx.lineTo(x + 24, 12);
283
+ ctx.closePath();
284
+ ctx.fill();
285
+ }
286
+ });
287
+ }
288
+ function lathe(profile, segments = 32) {
289
+ return new LatheGeometry(profile.map(([r, y]) => new Vector2(Math.max(0.0005, r), y)), segments);
290
+ }
291
+ function slab(shape, depth, bevel) {
292
+ const geometry = new ExtrudeGeometry(shape, {
293
+ depth,
294
+ bevelEnabled: true,
295
+ bevelThickness: bevel,
296
+ bevelSize: bevel,
297
+ bevelSegments: 3,
298
+ curveSegments: 18
299
+ });
300
+ geometry.center();
301
+ geometry.computeVertexNormals();
302
+ return geometry;
303
+ }
304
+ function rounded(width, height, radius, shape = new Shape) {
305
+ const x = -width / 2;
306
+ const y = -height / 2;
307
+ shape.moveTo(x + radius, y);
308
+ shape.lineTo(x + width - radius, y);
309
+ shape.quadraticCurveTo(x + width, y, x + width, y + radius);
310
+ shape.lineTo(x + width, y + height - radius);
311
+ shape.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
312
+ shape.lineTo(x + radius, y + height);
313
+ shape.quadraticCurveTo(x, y + height, x, y + height - radius);
314
+ shape.lineTo(x, y + radius);
315
+ shape.quadraticCurveTo(x, y, x + radius, y);
316
+ return shape;
317
+ }
318
+ function bodyPatch(R, from, to, grow, angle, rows = 18, columns = 48) {
319
+ const positions = [];
320
+ const uvs = [];
321
+ const indices = [];
322
+ for (let i = 0;i <= rows; i += 1) {
323
+ const y = from + (to - from) * i / rows;
324
+ const r = R(y) + grow;
325
+ for (let j = 0;j <= columns; j += 1) {
326
+ const phi = angle(y, j / columns);
327
+ positions.push(Math.sin(phi) * r, y, Math.cos(phi) * r * DEPTH);
328
+ uvs.push(j / columns, i / rows);
329
+ }
330
+ }
331
+ for (let i = 0;i < rows; i += 1)
332
+ for (let j = 0;j < columns; j += 1) {
333
+ const a = i * (columns + 1) + j;
334
+ const b = a + columns + 1;
335
+ indices.push(a, a + 1, b, a + 1, b + 1, b);
336
+ }
337
+ const geometry = new BufferGeometry;
338
+ geometry.setAttribute("position", new BufferAttribute(new Float32Array(positions), 3));
339
+ geometry.setAttribute("uv", new BufferAttribute(new Float32Array(uvs), 2));
340
+ geometry.setIndex(indices);
341
+ geometry.computeVertexNormals();
342
+ return geometry;
343
+ }
344
+ function bendable(geometry, length) {
345
+ const position = geometry.attributes.position;
346
+ const rest = Float32Array.from(position.array);
347
+ return (pitch, roll, from = 0) => {
348
+ for (let i = 0;i < position.count; i += 1) {
349
+ const x = rest[i * 3] ?? 0;
350
+ const y = rest[i * 3 + 1] ?? 0;
351
+ const z = rest[i * 3 + 2] ?? 0;
352
+ const along = clamp((y / length - from) / (1 - from), 0, 1);
353
+ const curl = along * along * (3 - 2 * along);
354
+ const a = pitch * curl;
355
+ const b = roll * curl;
356
+ const y1 = y * Math.cos(a) - z * Math.sin(a);
357
+ const z1 = y * Math.sin(a) + z * Math.cos(a);
358
+ position.setXYZ(i, x * Math.cos(b) - y1 * Math.sin(b), x * Math.sin(b) + y1 * Math.cos(b), z1);
359
+ }
360
+ position.needsUpdate = true;
361
+ geometry.computeVertexNormals();
362
+ };
363
+ }
364
+ function piece(kit, build) {
365
+ const group = new Group;
366
+ const geometries = new Set;
367
+ const materials = new Set;
368
+ const textures = new Set;
369
+ const place = (object, where = {}) => {
370
+ const at = where.at ?? [0, 0, 0];
371
+ object.position.set(at[0], at[1], at[2]);
372
+ if (where.rotate)
373
+ object.rotation.set(where.rotate[0], where.rotate[1], where.rotate[2]);
374
+ if (where.scale)
375
+ object.scale.set(where.scale[0], where.scale[1], where.scale[2]);
376
+ (where.parent ?? group).add(object);
377
+ };
378
+ const tick = build({
379
+ add(geometry, color, where = {}, look = {}) {
380
+ geometries.add(geometry);
381
+ const { outline, ...paint } = look;
382
+ const material = kit.paint(color, paint);
383
+ materials.add(material);
384
+ const mesh = new Mesh(geometry, material);
385
+ place(mesh, where);
386
+ if (outline !== false)
387
+ mesh.add(new Mesh(geometry, kit.ink));
388
+ return mesh;
389
+ },
390
+ glow(geometry, color, opacity, where = {}) {
391
+ geometries.add(geometry);
392
+ const material = new MeshBasicMaterial({
393
+ color: new Color(color),
394
+ transparent: true,
395
+ opacity,
396
+ blending: AdditiveBlending,
397
+ depthWrite: false,
398
+ toneMapped: false
399
+ });
400
+ materials.add(material);
401
+ const mesh = new Mesh(geometry, material);
402
+ place(mesh, where);
403
+ return mesh;
404
+ },
405
+ keep(texture) {
406
+ textures.add(texture);
407
+ return texture;
408
+ },
409
+ node(where = {}) {
410
+ const node = new Group;
411
+ place(node, where);
412
+ return node;
413
+ }
414
+ });
415
+ group.traverse((node) => {
416
+ node.raycast = () => {};
417
+ });
418
+ return {
419
+ object: group,
420
+ ...tick ? { tick } : {},
421
+ dispose() {
422
+ for (const geometry of geometries)
423
+ geometry.dispose();
424
+ for (const material of materials)
425
+ material.dispose();
426
+ for (const texture of textures)
427
+ texture.dispose();
428
+ }
429
+ };
430
+ }
431
+ function bunnyEars(kit) {
432
+ return piece(kit, ({ add, keep, node }) => {
433
+ const length = 0.46;
434
+ const leaf = [
435
+ [0, 0],
436
+ [0.05, 0.012],
437
+ [0.072, 0.06],
438
+ [0.088, 0.15],
439
+ [0.092, 0.24],
440
+ [0.085, 0.32],
441
+ [0.066, 0.39],
442
+ [0.038, 0.44],
443
+ [0, length]
444
+ ];
445
+ const skin = keep(earSkin());
446
+ const ears = [-1, 1].map((side) => {
447
+ const root = node({
448
+ at: [side * 0.13, TOP - 0.075, -0.03],
449
+ rotate: [-0.1, side * 0.18, side * -0.2]
450
+ });
451
+ const outer = lathe(leaf, 28);
452
+ const position = outer.attributes.position;
453
+ for (let i = 0;i < position.count; i += 1) {
454
+ const z = position.getZ(i);
455
+ const x = position.getX(i);
456
+ const width = Math.max(0.001, Math.abs(x) + Math.abs(z));
457
+ const cup = z > 0 ? 0.35 + 0.65 * (Math.abs(x) / width) ** 2 : 1;
458
+ position.setZ(i, z * 0.42 * cup);
459
+ }
460
+ outer.computeVertexNormals();
461
+ const inner = lathe(leaf.slice(1, -1).map(([r, y]) => [r * 0.6, y * 0.9 + 0.025]), 20);
462
+ const innerPosition = inner.attributes.position;
463
+ for (let i = 0;i < innerPosition.count; i += 1)
464
+ innerPosition.setZ(i, innerPosition.getZ(i) * 0.14 + 0.012);
465
+ inner.computeVertexNormals();
466
+ add(outer, "#fbf8ff", { parent: root });
467
+ add(inner, "#ffffff", { parent: root }, { map: skin, outline: false });
468
+ const tuft = new SphereGeometry(0.05, 14, 10);
469
+ for (const [x, y, z] of [
470
+ [-0.03, 0.01, 0.01],
471
+ [0.03, 0, 0],
472
+ [0, 0.03, 0.02]
473
+ ])
474
+ add(tuft, "#fbf8ff", { at: [x, y, z], parent: root }, { outline: false });
475
+ const rest = side === 1 ? 0.95 : 0.16;
476
+ return {
477
+ side,
478
+ bends: [bendable(outer, length), bendable(inner, length)],
479
+ pitch: new Spring(90, 7, rest),
480
+ roll: new Spring(70, 6),
481
+ rest
482
+ };
483
+ });
484
+ let twitch = 2.5;
485
+ return (clock, delta, raw) => {
486
+ const motion = calm(raw);
487
+ twitch -= delta;
488
+ for (const ear of ears) {
489
+ if (twitch < 0 && ear.side === -1)
490
+ ear.pitch.kick(-5);
491
+ const pitch = ear.pitch.step(ear.rest - motion.lift * 0.35, delta);
492
+ const roll = ear.roll.step(motion.yaw * 0.06 * ear.side + Math.sin(clock * 1.7 + ear.side) * 0.04, delta);
493
+ for (const bend of ear.bends)
494
+ bend(pitch, roll, ear.side === 1 ? 0.42 : 0);
495
+ }
496
+ if (twitch < 0)
497
+ twitch = 3 + Math.random() * 3;
498
+ };
499
+ });
500
+ }
501
+ function catEars(kit) {
502
+ return piece(kit, ({ add, node }) => {
503
+ const ear = new Shape;
504
+ ear.moveTo(-0.12, 0);
505
+ ear.quadraticCurveTo(-0.1, 0.12, -0.02, 0.22);
506
+ ear.quadraticCurveTo(0, 0.245, 0.02, 0.22);
507
+ ear.quadraticCurveTo(0.1, 0.12, 0.12, 0);
508
+ ear.quadraticCurveTo(0, -0.03, -0.12, 0);
509
+ const inner = new Shape;
510
+ inner.moveTo(-0.065, 0.02);
511
+ inner.quadraticCurveTo(-0.05, 0.1, -0.01, 0.165);
512
+ inner.quadraticCurveTo(0, 0.18, 0.01, 0.165);
513
+ inner.quadraticCurveTo(0.05, 0.1, 0.065, 0.02);
514
+ inner.quadraticCurveTo(0, 0, -0.065, 0.02);
515
+ const outerGeometry = slab(ear, 0.035, 0.02);
516
+ const innerGeometry = slab(inner, 0.01, 0.006);
517
+ const tuft = new ConeGeometry(0.012, 0.07, 6);
518
+ const ears = [-1, 1].map((side) => {
519
+ const root = node({
520
+ at: [side * 0.19, TOP - 0.1, 0],
521
+ rotate: [-0.15, side * -0.25, side * -0.32]
522
+ });
523
+ add(outerGeometry, "#2a2440", { at: [0, 0.1, 0], parent: root });
524
+ add(innerGeometry, "#ff9cc2", { at: [0, 0.085, 0.03], parent: root }, { outline: false });
525
+ for (const [x, r] of [
526
+ [-0.02, 0.3],
527
+ [0, 0],
528
+ [0.02, -0.3]
529
+ ])
530
+ add(tuft, "#fbf8ff", { at: [x, 0.05, 0.04], rotate: [0.2, 0, r], parent: root }, { outline: false });
531
+ return { root, side, spring: new Spring(160, 10) };
532
+ });
533
+ let next = 2;
534
+ return (_clock, delta, raw) => {
535
+ const motion = calm(raw);
536
+ next -= delta;
537
+ for (const ear2 of ears) {
538
+ if (next < 0 && (ear2.side === 1 || Math.random() < 0.4))
539
+ ear2.spring.kick(9);
540
+ const flick = ear2.spring.step(-motion.lift * 0.08, delta);
541
+ ear2.root.rotation.z = ear2.side * -0.32 + ear2.side * flick * 0.6;
542
+ ear2.root.rotation.x = -0.15 - Math.abs(flick) * 0.4;
543
+ }
544
+ if (next < 0)
545
+ next = 2 + Math.random() * 4;
546
+ };
547
+ });
548
+ }
549
+ function topHat(kit) {
550
+ return piece(kit, ({ add, node }) => {
551
+ const hat = node({ at: [0.04, TOP - 0.04, -0.01], rotate: [-0.08, 0.2, -0.16] });
552
+ const brim = lathe([
553
+ [0.18, 0.012],
554
+ [0.3, 0.008],
555
+ [0.355, 0.022],
556
+ [0.37, 0.042],
557
+ [0.36, 0.05],
558
+ [0.33, 0.034],
559
+ [0.26, 0.026],
560
+ [0.18, 0.03]
561
+ ], 48);
562
+ const position = brim.attributes.position;
563
+ for (let i = 0;i < position.count; i += 1) {
564
+ const x = position.getX(i);
565
+ const z = position.getZ(i);
566
+ const reach = Math.max(0.001, Math.hypot(x, z));
567
+ const lift = smooth(0.2, 0.37, reach) * (0.07 * (x / reach) ** 2 - 0.012 * (z / reach) ** 2);
568
+ position.setY(i, position.getY(i) + lift);
569
+ }
570
+ brim.computeVertexNormals();
571
+ add(brim, "#1b1830", { parent: hat }, { sheen: 0.25, double: true });
572
+ add(lathe([
573
+ [0, 0.4],
574
+ [0.2, 0.4],
575
+ [0.215, 0.385],
576
+ [0.212, 0.3],
577
+ [0.198, 0.15],
578
+ [0.195, 0.03],
579
+ [0, 0.03]
580
+ ]), "#1b1830", { parent: hat }, { sheen: 0.25, double: true });
581
+ add(lathe([
582
+ [0.2, 0.05],
583
+ [0.206, 0.05],
584
+ [0.208, 0.12],
585
+ [0.203, 0.12]
586
+ ]), "#c8323c", { parent: hat }, { sheen: 0.5, outline: false, double: true });
587
+ const buckle = rounded(0.07, 0.06, 0.012);
588
+ buckle.holes.push(rounded(0.04, 0.032, 0.006));
589
+ add(slab(buckle, 0.008, 0.004), "#f2c94c", { at: [0, 0.085, 0.21], parent: hat }, { sheen: 0.8, outline: false });
590
+ return;
591
+ });
592
+ }
593
+ function crown(kit) {
594
+ return piece(kit, ({ add, node }) => {
595
+ const root = node({ at: [0, TOP - 0.07, 0], rotate: [-0.08, 0, 0.08] });
596
+ const radius = 0.225;
597
+ const width = Math.PI * 2 * radius;
598
+ const points = 6;
599
+ const step = width / points;
600
+ const outline = new Shape;
601
+ outline.moveTo(0, 0);
602
+ outline.lineTo(width, 0);
603
+ outline.lineTo(width, 0.08);
604
+ for (let i = points;i > 0; i -= 1) {
605
+ const mid = (i - 0.5) * step;
606
+ outline.quadraticCurveTo(i * step - step / 6, 0.11, mid, 0.2);
607
+ outline.quadraticCurveTo(mid - step / 3, 0.11, (i - 1) * step, 0.08);
608
+ }
609
+ outline.lineTo(0, 0);
610
+ const band = new ExtrudeGeometry(outline, {
611
+ depth: 0.018,
612
+ bevelEnabled: true,
613
+ bevelThickness: 0.006,
614
+ bevelSize: 0.006,
615
+ bevelSegments: 2,
616
+ curveSegments: 10,
617
+ steps: 1
618
+ });
619
+ const position = band.attributes.position;
620
+ for (let i = 0;i < position.count; i += 1) {
621
+ const angle = position.getX(i) / width * Math.PI * 2;
622
+ const r = radius + position.getZ(i);
623
+ position.setXYZ(i, Math.sin(angle) * r, position.getY(i), Math.cos(angle) * r);
624
+ }
625
+ band.computeVertexNormals();
626
+ add(band, "#f2c94c", { parent: root }, { sheen: 0.85, double: true });
627
+ add(new SphereGeometry(radius - 0.01, 24, 12, 0, Math.PI * 2, 0, Math.PI / 2), "#a3173a", {
628
+ at: [0, 0.02, 0],
629
+ scale: [1, 0.55, 1],
630
+ parent: root
631
+ });
632
+ const pearl = new SphereGeometry(0.022, 12, 10);
633
+ const stone = new IcosahedronGeometry(0.03, 0);
634
+ const colors = ["#e2574c", "#4cc9e2", "#3d8b5a"];
635
+ for (let i = 0;i < points; i += 1) {
636
+ const tip = (i + 0.5) / points * Math.PI * 2;
637
+ add(pearl, "#fff8e8", {
638
+ at: [Math.sin(tip) * (radius + 0.01), 0.215, Math.cos(tip) * (radius + 0.01)],
639
+ parent: root
640
+ }, { sheen: 0.7, outline: false });
641
+ add(stone, colors[i % colors.length] ?? "#e2574c", {
642
+ at: [Math.sin(tip) * (radius + 0.026), 0.045, Math.cos(tip) * (radius + 0.026)],
643
+ rotate: [0, tip, 0],
644
+ scale: [1, 1, 0.55],
645
+ parent: root
646
+ }, { sheen: 0.9, outline: false });
647
+ }
648
+ add(new SphereGeometry(0.035, 12, 10), "#f2c94c", { at: [0, 0.14, 0], parent: root }, {
649
+ sheen: 0.85
650
+ });
651
+ add(new OctahedronGeometry(0.03), "#f2c94c", { at: [0, 0.19, 0], scale: [0.6, 1, 0.6], parent: root }, { sheen: 0.85 });
652
+ return;
653
+ });
654
+ }
655
+ function partyHat(kit) {
656
+ return piece(kit, ({ add, keep, node }) => {
657
+ const hat = node({ at: [-0.08, TOP - 0.05, 0.03], rotate: [0.05, 0, 0.24] });
658
+ 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 });
659
+ 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 });
660
+ const puff = new SphereGeometry(0.038, 12, 10);
661
+ const top = node({ at: [0, 0.43, 0], parent: hat });
662
+ for (const [x, y, z, color] of [
663
+ [0, 0, 0, "#fbf8ff"],
664
+ [0.03, 0.02, 0.01, "#ffd84d"],
665
+ [-0.03, 0.015, 0, "#fbf8ff"],
666
+ [0, 0.035, -0.02, "#4cc9e2"],
667
+ [0.01, 0.02, 0.03, "#fbf8ff"],
668
+ [-0.02, -0.01, 0.025, "#ffd84d"]
669
+ ])
670
+ add(puff, color, { at: [x, y, z], parent: top }, { outline: false });
671
+ const sway = new Spring(80, 6);
672
+ return (clock, delta, raw) => {
673
+ const motion = calm(raw);
674
+ const lean = sway.step(-motion.yaw * 0.04 + motion.lift * 0.03, delta);
675
+ hat.rotation.z = 0.24 + lean + Math.sin(clock * 2.2) * 0.015;
676
+ top.scale.setScalar(1 + Math.max(0, -motion.lift) * 0.04);
677
+ };
678
+ });
679
+ }
680
+ function halo(kit) {
681
+ return piece(kit, ({ add, glow, node }) => {
682
+ const ring = node({ at: [0, TOP + 0.17, -0.02], rotate: [Math.PI / 2 - 0.2, 0, 0] });
683
+ add(new TorusGeometry(0.22, 0.03, 14, 56), "#ffe680", { parent: ring }, { sheen: 0.8 });
684
+ glow(new TorusGeometry(0.22, 0.075, 12, 56), "#fff2a8", 0.28, { parent: ring });
685
+ glow(new TorusGeometry(0.22, 0.13, 10, 56), "#ffe680", 0.1, { parent: ring });
686
+ const spark = new OctahedronGeometry(0.022);
687
+ const sparks = [0, 1, 2, 3].map(() => add(spark, "#fffbe0", { parent: ring }, { outline: false, sheen: 1 }));
688
+ return (clock) => {
689
+ ring.position.y = TOP + 0.17 + Math.sin(clock * 2) * 0.022;
690
+ ring.rotation.z = clock * 0.5;
691
+ sparks.forEach((s, i) => {
692
+ const a = clock * 0.9 + i * Math.PI / 2;
693
+ s.position.set(Math.cos(a) * 0.27, Math.sin(a) * 0.27, Math.sin(clock * 3 + i) * 0.03);
694
+ const twinkle = 0.5 + 0.5 * Math.abs(Math.sin(clock * 2.5 + i * 1.7));
695
+ s.scale.set(0.6 * twinkle, 1.6 * twinkle, 0.6 * twinkle);
696
+ });
697
+ };
698
+ });
699
+ }
700
+ function bow(kit) {
701
+ return piece(kit, ({ add, keep, node }) => {
702
+ const root = node({ at: [0.19, TOP - 0.06, 0.06], rotate: [0.25, 0.35, -0.42] });
703
+ const ribbon = keep(dots("#ff5fa2", "#ffffff"));
704
+ const loop = new Shape;
705
+ loop.moveTo(0, 0);
706
+ loop.bezierCurveTo(0.05, 0.11, 0.17, 0.12, 0.17, 0.02);
707
+ loop.bezierCurveTo(0.17, -0.08, 0.05, -0.08, 0, 0);
708
+ const loopGeometry = slab(loop, 0.04, 0.02);
709
+ for (const side of [-1, 1])
710
+ add(loopGeometry, "#ffffff", {
711
+ at: [side * 0.085, 0.01, 0],
712
+ rotate: [0, side === 1 ? 0 : Math.PI, side * 0.05],
713
+ parent: root
714
+ }, { map: ribbon, repeat: [9, 9], sheen: 0.35 });
715
+ 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 });
716
+ const tail = new Shape;
717
+ tail.moveTo(-0.025, 0);
718
+ tail.lineTo(0.025, 0);
719
+ tail.lineTo(0.035, -0.14);
720
+ tail.lineTo(0, -0.115);
721
+ tail.lineTo(-0.035, -0.14);
722
+ tail.closePath();
723
+ const tailGeometry = slab(tail, 0.012, 0.006);
724
+ const tails = [-1, 1].map((side) => {
725
+ const hang = node({ at: [side * 0.02, -0.02, 0.01], parent: root });
726
+ add(tailGeometry, "#ffffff", { at: [0, -0.07, 0], parent: hang }, { map: ribbon, repeat: [9, 9], sheen: 0.35 });
727
+ return { hang, side, spring: new Spring(60, 5) };
728
+ });
729
+ return (clock, delta, raw) => {
730
+ const motion = calm(raw);
731
+ for (const t of tails) {
732
+ 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);
733
+ t.hang.rotation.x = clamp(motion.lift * 0.08, -0.4, 0.4);
734
+ }
735
+ };
736
+ });
737
+ }
738
+ function pleatedSkirt(kit) {
739
+ const R = kit.radiusAt;
740
+ return piece(kit, ({ add, keep, node }) => {
741
+ const top = 0.31;
742
+ const bottom = 0.03;
743
+ const waist = R(top) + 0.018;
744
+ const hem = R(0.12) + 0.12;
745
+ const pleatsAround = 24;
746
+ const geometry = new CylinderGeometry(waist, hem, top - bottom, pleatsAround * 4, 6, true);
747
+ const position = geometry.attributes.position;
748
+ const rest = Float32Array.from(position.array);
749
+ const skirt = node({ at: [0, (top + bottom) / 2, 0], scale: [1, 1, DEPTH] });
750
+ add(geometry, "#ffffff", { parent: skirt }, {
751
+ map: keep(tartan("#c8323c", "#1b1f5e", "#f2d24b")),
752
+ repeat: [6, 1.4],
753
+ double: true,
754
+ back: "#7d1d2a"
755
+ });
756
+ const trim = new TorusGeometry(hem, 0.012, 6, 96);
757
+ const hemRing = add(trim, "#fbf8ff", { at: [0, -(top - bottom) / 2 + 0.002, 0], rotate: [Math.PI / 2, 0, 0], parent: skirt }, { outline: false });
758
+ add(lathe([
759
+ [waist - 0.004, top - 0.03],
760
+ [waist + 0.012, top - 0.03],
761
+ [waist + 0.012, top + 0.012],
762
+ [waist - 0.004, top + 0.012]
763
+ ], 64), "#1b1f5e", { scale: [1, 1, DEPTH] }, { outline: false });
764
+ add(new SphereGeometry(0.018, 10, 8), "#f2c94c", { at: [0.09, top - 0.009, (waist + 0.004) * DEPTH] }, { sheen: 0.8, outline: false });
765
+ const flare = new Spring(70, 6);
766
+ const sway = new Spring(50, 5);
767
+ const half = (top - bottom) / 2;
768
+ return (clock, delta, raw) => {
769
+ const motion = calm(raw);
770
+ const out = flare.step(clamp(-motion.lift * 0.05, -0.04, 0.12), delta);
771
+ const turn = sway.step(-motion.yaw * 0.05, delta);
772
+ for (let i = 0;i < position.count; i += 1) {
773
+ const x = rest[i * 3] ?? 0;
774
+ const y = rest[i * 3 + 1] ?? 0;
775
+ const z = rest[i * 3 + 2] ?? 0;
776
+ const low = clamp((half - y) / (2 * half), 0, 1);
777
+ const angle = Math.atan2(x, z);
778
+ const phase = (angle / (Math.PI * 2) * pleatsAround % 1 + 1) % 1;
779
+ const fold = 1 + (Math.abs(phase * 2 - 1) - 0.5) * 0.08 * low;
780
+ const spread = 1 + out * low * low;
781
+ const lag = turn * low + Math.sin(clock * 2 + angle * 2) * 0.006 * low;
782
+ const r = Math.hypot(x, z) * fold * spread;
783
+ position.setXYZ(i, Math.sin(angle + lag) * r, y, Math.cos(angle + lag) * r);
784
+ }
785
+ position.needsUpdate = true;
786
+ geometry.computeVertexNormals();
787
+ hemRing.scale.setScalar(1 + out);
788
+ };
789
+ });
790
+ }
791
+ function tuxedo(kit) {
792
+ const R = kit.radiusAt;
793
+ return piece(kit, ({ add, keep, node }) => {
794
+ const button = 0.15;
795
+ const collar = 0.34;
796
+ const open = (y) => y > button ? 0.16 + (y - button) / (collar - button) * 0.55 : 0.16 + (button - y) / button * 0.5;
797
+ add(bodyPatch(R, 0.03, collar, 0.024, (y, t) => open(y) + t * (Math.PI * 2 - 2 * open(y))), "#1b1830", {}, { double: true, back: "#3b2a6b", sheen: 0.15 });
798
+ add(bodyPatch(R, 0.05, collar - 0.01, 0.012, (y, t) => (t * 2 - 1) * (open(y) + 0.02), 18, 16), "#ffffff", {}, { map: keep(pleats()), repeat: [3, 1], outline: false });
799
+ for (const side of [-1, 1])
800
+ add(bodyPatch(R, button + 0.005, collar, 0.03, (y, t) => side * (open(y) + t * (0.05 + (y - button) / (collar - button) * 0.16)), 10, 4), "#3b3560", {}, { sheen: 0.6, double: true });
801
+ const front = (y) => R(y) * DEPTH + 0.028;
802
+ const wing = new Shape;
803
+ wing.moveTo(0, 0.012);
804
+ wing.quadraticCurveTo(0.05, 0.05, 0.085, 0.04);
805
+ wing.quadraticCurveTo(0.095, 0, 0.085, -0.04);
806
+ wing.quadraticCurveTo(0.05, -0.05, 0, -0.012);
807
+ wing.closePath();
808
+ const wingGeometry = slab(wing, 0.022, 0.008);
809
+ for (const side of [-1, 1])
810
+ add(wingGeometry, "#14102e", {
811
+ at: [side * 0.048, COLLAR_Y, front(COLLAR_Y) + 0.01],
812
+ rotate: [0, side === 1 ? 0 : Math.PI, side * -0.06]
813
+ }, { sheen: 0.55 });
814
+ add(new SphereGeometry(0.024, 12, 10), "#2e2a4a", { at: [0, COLLAR_Y, front(COLLAR_Y) + 0.02], scale: [1, 1.2, 0.8] }, { sheen: 0.55 });
815
+ const stud = new SphereGeometry(0.013, 10, 8);
816
+ for (const y of [0.22, 0.18])
817
+ add(stud, "#14102e", { at: [0, y, front(y) - 0.012] }, { sheen: 0.8, outline: false });
818
+ add(new CylinderGeometry(0.02, 0.02, 0.01, 16), "#14102e", { at: [0, button, front(button) + 0.001], rotate: [Math.PI / 2, 0, 0] }, { sheen: 0.8 });
819
+ const square = new Shape;
820
+ square.moveTo(-0.035, 0);
821
+ square.lineTo(-0.02, 0.04);
822
+ square.lineTo(0, 0.02);
823
+ square.lineTo(0.02, 0.045);
824
+ square.lineTo(0.035, 0);
825
+ square.closePath();
826
+ const chest = 0.22;
827
+ const chestAngle = 0.95;
828
+ const reach = R(chest) + 0.03;
829
+ add(slab(square, 0.006, 0.003), "#fbf8ff", {
830
+ at: [Math.sin(chestAngle) * reach, chest, Math.cos(chestAngle) * reach * DEPTH],
831
+ rotate: [0, chestAngle, 0]
832
+ });
833
+ const tail = new Shape;
834
+ tail.moveTo(-0.06, 0);
835
+ tail.lineTo(0.06, 0);
836
+ tail.quadraticCurveTo(0.07, -0.14, 0.035, -0.24);
837
+ tail.lineTo(0, -0.2);
838
+ tail.lineTo(-0.035, -0.24);
839
+ tail.quadraticCurveTo(-0.07, -0.14, -0.06, 0);
840
+ const tailGeometry = slab(tail, 0.014, 0.006);
841
+ const tails = [-1, 1].map((side) => {
842
+ const hang = node({
843
+ at: [side * 0.08, 0.12, -(R(0.12) * DEPTH + 0.02)],
844
+ rotate: [0, Math.PI + side * -0.2, 0]
845
+ });
846
+ add(tailGeometry, "#1b1830", { at: [0, -0.1, 0], parent: hang }, { sheen: 0.15 });
847
+ return { hang, spring: new Spring(60, 5), side };
848
+ });
849
+ return (clock, delta, raw) => {
850
+ const motion = calm(raw);
851
+ for (const t of tails) {
852
+ const kick = t.spring.step(-0.15 + clamp(-motion.lift * 0.12, -0.3, 0.5) + Math.abs(motion.yaw) * 0.04, delta);
853
+ t.hang.rotation.x = kick + Math.sin(clock * 1.5 + t.side) * 0.02;
854
+ }
855
+ };
856
+ });
857
+ }
858
+ function heroCape(kit) {
859
+ const R = kit.radiusAt;
860
+ return piece(kit, ({ add }) => {
861
+ const top = 0.6;
862
+ const bottom = 0;
863
+ const across = Math.PI * 0.95;
864
+ const columns = 22;
865
+ const rows = 14;
866
+ const positions = new Float32Array((columns + 1) * (rows + 1) * 3);
867
+ const uvs = [];
868
+ const indices = [];
869
+ for (let i = 0;i <= rows; i += 1)
870
+ for (let j = 0;j <= columns; j += 1)
871
+ uvs.push(j / columns, 1 - i / rows);
872
+ for (let i = 0;i < rows; i += 1)
873
+ for (let j = 0;j < columns; j += 1) {
874
+ const a = i * (columns + 1) + j;
875
+ const b = a + columns + 1;
876
+ indices.push(a, b, a + 1, a + 1, b, b + 1);
877
+ }
878
+ const geometry = new BufferGeometry;
879
+ geometry.setAttribute("position", new BufferAttribute(positions, 3));
880
+ geometry.setAttribute("uv", new BufferAttribute(new Float32Array(uvs), 2));
881
+ geometry.setIndex(indices);
882
+ const drape = (clock, out, lag) => {
883
+ for (let i = 0;i <= rows; i += 1) {
884
+ const v = i / rows;
885
+ const y = top + (bottom - top) * v;
886
+ for (let j = 0;j <= columns; j += 1) {
887
+ const u = j / columns;
888
+ const angle = Math.PI - across / 2 + across * u + lag * v * v;
889
+ const ripple = Math.sin(u * 9 + clock * 2.4) * 0.025 * v * v;
890
+ const r = R(Math.max(y, 0.2)) + 0.045 + v * 0.16 + out * v * v + ripple;
891
+ const k = (i * (columns + 1) + j) * 3;
892
+ positions[k] = Math.sin(angle) * r;
893
+ positions[k + 1] = y + out * v * v * 0.1;
894
+ positions[k + 2] = Math.cos(angle) * r * DEPTH;
895
+ }
896
+ }
897
+ geometry.attributes.position.needsUpdate = true;
898
+ geometry.computeVertexNormals();
899
+ };
900
+ drape(0, 0, 0);
901
+ add(geometry, "#c8323c", {}, { double: true, back: "#f2c94c", sheen: 0.2 });
902
+ add(bodyPatch(R, top - 0.04, top + 0.07, 0.05, (_y, t) => Math.PI * 0.42 + t * (Math.PI * 2 - Math.PI * 0.84), 3, 24), "#9e1f2c", {}, { double: true, back: "#f2c94c" });
903
+ const clasp = new Shape;
904
+ for (let i = 0;i < 10; i += 1) {
905
+ const a = i / 10 * Math.PI * 2;
906
+ const r = i % 2 ? 0.022 : 0.045;
907
+ if (i === 0)
908
+ clasp.moveTo(Math.sin(a) * r, Math.cos(a) * r);
909
+ else
910
+ clasp.lineTo(Math.sin(a) * r, Math.cos(a) * r);
911
+ }
912
+ clasp.closePath();
913
+ const star = slab(clasp, 0.012, 0.005);
914
+ for (const side of [-1, 1]) {
915
+ const angle = side * (Math.PI / 2 - 0.15);
916
+ const r = R(top - 0.02) + 0.05;
917
+ add(star, "#f2c94c", {
918
+ at: [Math.sin(angle) * r, top - 0.02, Math.cos(angle) * r * DEPTH],
919
+ rotate: [0, angle, 0]
920
+ }, { sheen: 0.85 });
921
+ }
922
+ const flare = new Spring(40, 4);
923
+ const trail = new Spring(35, 4);
924
+ return (clock, delta, raw) => {
925
+ const motion = calm(raw);
926
+ const out = flare.step(clamp(Math.abs(motion.yaw) * 0.03 + Math.max(0, -motion.lift) * 0.06, 0, 0.25), delta);
927
+ drape(clock, out, trail.step(-motion.yaw * 0.06, delta));
928
+ };
929
+ });
930
+ }
931
+ function scarf(kit) {
932
+ const R = kit.radiusAt;
933
+ return piece(kit, ({ add, keep, node }) => {
934
+ const wool = keep(knit("#e2574c", "#fbf8ff"));
935
+ const ring = R(COLLAR_Y) + 0.03;
936
+ add(new TorusGeometry(ring, 0.058, 14, 64), "#ffffff", { at: [0, COLLAR_Y, 0], rotate: [Math.PI / 2, 0, 0], scale: [1, DEPTH, 1.05] }, { map: wool, repeat: [14, 1] });
937
+ const knotAngle = 0.55;
938
+ const knotAt = [
939
+ Math.sin(knotAngle) * (ring + 0.03),
940
+ COLLAR_Y - 0.01,
941
+ Math.cos(knotAngle) * (ring + 0.03) * DEPTH
942
+ ];
943
+ add(new SphereGeometry(0.06, 16, 12), "#ffffff", { at: knotAt, scale: [1, 0.85, 0.75] }, { map: wool, repeat: [3, 1] });
944
+ const strip = new CylinderGeometry(0.05, 0.055, 0.26, 12, 6);
945
+ strip.scale(1, 1, 0.35);
946
+ const fringe = new CylinderGeometry(0.006, 0.004, 0.04, 5);
947
+ const tails = [
948
+ { x: -0.01, tilt: 0.12, length: 1 },
949
+ { x: 0.045, tilt: -0.05, length: 0.82 }
950
+ ].map(({ x, tilt, length }) => {
951
+ const hang = node({
952
+ at: [knotAt[0] + x, knotAt[1] - 0.02, knotAt[2] + 0.02],
953
+ rotate: [0.12, knotAngle * 0.6, tilt]
954
+ });
955
+ add(strip, "#ffffff", { at: [0, -0.13 * length, 0], scale: [1, length, 1], parent: hang }, { map: wool, repeat: [2, 2] });
956
+ for (let i = 0;i < 5; i += 1)
957
+ add(fringe, "#e2574c", { at: [-0.04 + i * 0.02, -0.26 * length - 0.02, 0], parent: hang }, { outline: false });
958
+ return { hang, tilt, spring: new Spring(55, 5, tilt) };
959
+ });
960
+ return (clock, delta, raw) => {
961
+ const motion = calm(raw);
962
+ tails.forEach((t, i) => {
963
+ t.hang.rotation.z = t.spring.step(t.tilt - motion.yaw * 0.05 + Math.sin(clock * 1.8 + i) * 0.03, delta);
964
+ t.hang.rotation.x = 0.12 + clamp(motion.lift * 0.1, -0.3, 0.5);
965
+ });
966
+ };
967
+ });
968
+ }
969
+ function sunglasses(kit) {
970
+ const R = kit.radiusAt;
971
+ return piece(kit, ({ add, keep }) => {
972
+ const glass = keep(lensGlass());
973
+ const lens = new Shape;
974
+ lens.moveTo(-0.085, 0.04);
975
+ lens.quadraticCurveTo(0, 0.06, 0.085, 0.04);
976
+ lens.quadraticCurveTo(0.1, -0.02, 0.05, -0.06);
977
+ lens.quadraticCurveTo(0, -0.08, -0.05, -0.06);
978
+ lens.quadraticCurveTo(-0.1, -0.02, -0.085, 0.04);
979
+ const frame = new Shape;
980
+ frame.moveTo(-0.1, 0.05);
981
+ frame.quadraticCurveTo(0, 0.075, 0.1, 0.05);
982
+ frame.quadraticCurveTo(0.12, -0.025, 0.06, -0.075);
983
+ frame.quadraticCurveTo(0, -0.095, -0.06, -0.075);
984
+ frame.quadraticCurveTo(-0.12, -0.025, -0.1, 0.05);
985
+ frame.holes.push(lens);
986
+ const lensGeometry = slab(lens, 0.006, 0.003);
987
+ const uv = lensGeometry.attributes.uv;
988
+ for (let i = 0;i < uv.count; i += 1)
989
+ uv.setXY(i, uv.getX(i) * 5 + 0.5, uv.getY(i) * 5 + 0.5);
990
+ const frameGeometry = slab(frame, 0.014, 0.004);
991
+ const turn = 0.32;
992
+ const z = R(EYES_Y) * DEPTH;
993
+ for (const side of [-1, 1]) {
994
+ const x = side * 0.13;
995
+ const at = [x, EYES_Y, z + 0.035 - Math.abs(x) * 0.18];
996
+ add(lensGeometry, "#ffffff", { at, rotate: [0, side * turn, 0], scale: [side, 1, 1] }, { map: glass, sheen: 0.7, outline: false, double: true });
997
+ 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 });
998
+ 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 });
999
+ }
1000
+ 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 });
1001
+ return;
1002
+ });
1003
+ }
1004
+ var BUILDERS = {
1005
+ "bunny-ears": bunnyEars,
1006
+ "cat-ears": catEars,
1007
+ "top-hat": topHat,
1008
+ crown,
1009
+ "party-hat": partyHat,
1010
+ halo,
1011
+ bow,
1012
+ "pleated-skirt": pleatedSkirt,
1013
+ tuxedo,
1014
+ "hero-cape": heroCape,
1015
+ scarf,
1016
+ sunglasses
65
1017
  };
66
- var BODY_SHAPES = {
67
- plup: { x: 1, y: 1 },
68
- tall: { x: 0.88, y: 1.25 },
69
- wide: { x: 1.2, y: 0.85 },
70
- mini: { x: 0.82, y: 0.82 },
71
- bean: { x: 0.72, y: 1.35 }
1018
+ function buildGarment(key, kit) {
1019
+ return BUILDERS[key](kit);
1020
+ }
1021
+
1022
+ // src/hair3d.ts
1023
+ var SKULL = new Vector3(0, BLOB_SEAT + 0.08, 0);
1024
+ var anime = (p, ring = p.ring ?? 1) => ({
1025
+ anime: { center: [SKULL.x, SKULL.y, SKULL.z], ring, tip: p.tip, inner: p.inner }
1026
+ });
1027
+ function onHead(radius, phi, y, out) {
1028
+ const r = Math.max(0.02, radius(Math.min(y, TOP - 0.005))) + out;
1029
+ return new Vector3(Math.sin(phi) * r, y, Math.cos(phi) * r * DEPTH);
1030
+ }
1031
+ var UP = new Vector3(0, 1, 0);
1032
+ var FORWARD = new Vector3(0, 0, 1);
1033
+ function clump(points, width, thickness, tip = 1, twist = 0) {
1034
+ const curve = new CatmullRomCurve3(points, false, "centripetal");
1035
+ const segments = 24;
1036
+ const sides = 10;
1037
+ const positions = [];
1038
+ const along = [];
1039
+ const indices = [];
1040
+ const tangent = new Vector3;
1041
+ const out = new Vector3;
1042
+ const across = new Vector3;
1043
+ const depth = new Vector3;
1044
+ for (let k = 0;k <= segments; k += 1) {
1045
+ const t = k / segments;
1046
+ const p = curve.getPointAt(t);
1047
+ curve.getTangentAt(t, tangent);
1048
+ out.copy(p).sub(SKULL).normalize();
1049
+ across.crossVectors(tangent, out);
1050
+ if (across.lengthSq() < 0.04)
1051
+ across.crossVectors(tangent, FORWARD);
1052
+ if (across.lengthSq() < 0.04)
1053
+ across.crossVectors(tangent, UP);
1054
+ across.normalize();
1055
+ depth.crossVectors(across, tangent).normalize();
1056
+ if (twist) {
1057
+ const turn = twist * t * t;
1058
+ const a = across.clone().multiplyScalar(Math.cos(turn)).addScaledVector(depth, Math.sin(turn));
1059
+ depth.multiplyScalar(Math.cos(turn)).addScaledVector(across, -Math.sin(turn));
1060
+ across.copy(a);
1061
+ }
1062
+ const s = Math.max(1 - tip, (1 - t) ** 0.8) * (1 + 0.45 * Math.sin(Math.min(1, t * 1.6) * Math.PI));
1063
+ for (let m = 0;m <= sides; m += 1) {
1064
+ const a = m / sides * Math.PI * 2;
1065
+ const c = Math.cos(a);
1066
+ const n = Math.sin(a);
1067
+ const w = c * width * s;
1068
+ const d = n * thickness * s * (0.3 + 0.7 * Math.abs(n));
1069
+ positions.push(p.x + across.x * w + depth.x * d, p.y + across.y * w + depth.y * d, p.z + across.z * w + depth.z * d);
1070
+ along.push(t);
1071
+ }
1072
+ }
1073
+ for (let k = 0;k < segments; k += 1)
1074
+ for (let m = 0;m < sides; m += 1) {
1075
+ const a = k * (sides + 1) + m;
1076
+ const c = a + sides + 1;
1077
+ indices.push(a, c, a + 1, a + 1, c, c + 1);
1078
+ }
1079
+ if (tip < 1) {
1080
+ const last = segments * (sides + 1);
1081
+ const end = curve.getPointAt(1);
1082
+ const centre = positions.length / 3;
1083
+ positions.push(end.x, end.y, end.z);
1084
+ along.push(1);
1085
+ for (let m = 0;m < sides; m += 1)
1086
+ indices.push(last + m, centre, last + m + 1);
1087
+ }
1088
+ const geometry = new BufferGeometry2;
1089
+ geometry.setAttribute("position", new BufferAttribute2(new Float32Array(positions), 3));
1090
+ geometry.setAttribute("along", new BufferAttribute2(Float32Array.from(along), 1));
1091
+ geometry.setIndex(indices);
1092
+ geometry.computeVertexNormals();
1093
+ return { geometry, along: Float32Array.from(along), root: points[0] ?? new Vector3 };
1094
+ }
1095
+ function swinger(made) {
1096
+ const position = made.geometry.attributes.position;
1097
+ const rest = Float32Array.from(position.array);
1098
+ const { root, along } = made;
1099
+ return (pitch, roll) => {
1100
+ for (let i = 0;i < position.count; i += 1) {
1101
+ const t = along[i] ?? 0;
1102
+ const k = t * t;
1103
+ const x = (rest[i * 3] ?? 0) - root.x;
1104
+ const y = (rest[i * 3 + 1] ?? 0) - root.y;
1105
+ const z = (rest[i * 3 + 2] ?? 0) - root.z;
1106
+ const a = pitch * k;
1107
+ const b = roll * k;
1108
+ const y1 = y * Math.cos(a) - z * Math.sin(a);
1109
+ const z1 = y * Math.sin(a) + z * Math.cos(a);
1110
+ position.setXYZ(i, root.x + x * Math.cos(b) - y1 * Math.sin(b), root.y + x * Math.sin(b) + y1 * Math.cos(b), root.z + z1);
1111
+ }
1112
+ position.needsUpdate = true;
1113
+ made.geometry.computeVertexNormals();
1114
+ };
1115
+ }
1116
+ function cap(radius, front, back, grow, part = 0) {
1117
+ const rows = 18;
1118
+ const columns = 56;
1119
+ const positions = [];
1120
+ const indices = [];
1121
+ for (let i = 0;i <= rows; i += 1) {
1122
+ const s = i / rows;
1123
+ for (let j = 0;j <= columns; j += 1) {
1124
+ const phi = j / columns * Math.PI * 2;
1125
+ const facing = (1 + Math.cos(phi - part)) / 2;
1126
+ const line = back + (front - back) * facing ** 1.5;
1127
+ const y = TOP + 0.01 - s * (TOP + 0.01 - line);
1128
+ const p = onHead(radius, phi, y, grow * (0.7 + 0.3 * Math.sin(s * Math.PI * 0.6 + 0.4)));
1129
+ positions.push(p.x, p.y + grow * 0.5 * (1 - s), p.z);
1130
+ }
1131
+ }
1132
+ for (let i = 0;i < rows; i += 1)
1133
+ for (let j = 0;j < columns; j += 1) {
1134
+ const a = i * (columns + 1) + j;
1135
+ const b = a + columns + 1;
1136
+ indices.push(a, b, a + 1, a + 1, b, b + 1);
1137
+ }
1138
+ const geometry = new BufferGeometry2;
1139
+ geometry.setAttribute("position", new BufferAttribute2(new Float32Array(positions), 3));
1140
+ geometry.setIndex(indices);
1141
+ geometry.computeVertexNormals();
1142
+ return geometry;
1143
+ }
1144
+ function add(b, p, made) {
1145
+ b.add(made.geometry, p.color, {}, anime(p));
1146
+ return made;
1147
+ }
1148
+ function base(b, radius, p, front, back, grow, part = 0) {
1149
+ b.add(cap(radius, front, back, grow, part), p.color, {}, { ...anime(p), double: true });
1150
+ }
1151
+ function fringe(b, radius, p, bangs, part = 0) {
1152
+ for (const bang of bangs) {
1153
+ const sweep = bang.sweep ?? 0;
1154
+ const root = onHead(radius, part + bang.at * 0.4, TOP - 0.02, 0.03);
1155
+ const crest = onHead(radius, bang.at * 0.75 + sweep * 0.2, 0.86, 0.085);
1156
+ const fall = onHead(radius, bang.at + sweep * 0.55, 0.75, 0.07);
1157
+ const end = onHead(radius, bang.at + sweep, bang.length, 0.05);
1158
+ const made = clump([root, crest, fall, end], bang.width, bang.width * 0.34, bang.blunt ? 0.55 : 1);
1159
+ add(b, p, made);
1160
+ }
1161
+ }
1162
+ function sidelocks(b, radius, p, end, width = 0.075, blunt = false) {
1163
+ for (const side of [-1, 1]) {
1164
+ const skew = side > 0 ? 0.03 : 0;
1165
+ for (const [phi, drop, w] of [
1166
+ [0.9, 0, width],
1167
+ [1.12, 0.07, width * 0.8]
1168
+ ]) {
1169
+ const y = end + drop + skew;
1170
+ const path = [
1171
+ onHead(radius, side * (phi - 0.3), TOP - 0.06, 0.04),
1172
+ onHead(radius, side * phi, 0.78, 0.085),
1173
+ onHead(radius, side * (phi + 0.02), 0.56, 0.07),
1174
+ onHead(radius, side * (phi - 0.05), y + 0.1, 0.06),
1175
+ onHead(radius, side * (phi - (blunt ? 0.05 : 0.17)), y, blunt ? 0.06 : 0.075)
1176
+ ];
1177
+ add(b, p, clump(path, w, w * 0.4, blunt ? 0.6 : 1, side * 0.5));
1178
+ }
1179
+ }
1180
+ }
1181
+ function strays(b, radius, p, at) {
1182
+ for (const [phi, y, length] of at) {
1183
+ const root = onHead(radius, phi, y, 0.06);
1184
+ const out = onHead(radius, phi, y, 1).sub(root).normalize();
1185
+ const path = [
1186
+ root,
1187
+ root.clone().addScaledVector(out, 0.05).add(new Vector3(0, -length * 0.4, 0)),
1188
+ root.clone().addScaledVector(out, 0.07).add(new Vector3(Math.sin(phi * 3) * 0.03, -length, 0))
1189
+ ];
1190
+ add(b, p, clump(path, 0.02, 0.009));
1191
+ }
1192
+ }
1193
+ function ahoge(b, p, lean = 1) {
1194
+ const crown2 = new Vector3(0.02 * lean, TOP + 0.02, -0.02);
1195
+ const made = clump([
1196
+ crown2,
1197
+ crown2.clone().add(new Vector3(0.02 * lean, 0.11, 0.03)),
1198
+ crown2.clone().add(new Vector3(0.07 * lean, 0.17, 0.07)),
1199
+ crown2.clone().add(new Vector3(0.12 * lean, 0.14, 0.1))
1200
+ ], 0.032, 0.014);
1201
+ add(b, p, made);
1202
+ const swing = swinger(made);
1203
+ const spring = new Spring(60, 3);
1204
+ return (_clock, delta, raw) => {
1205
+ const motion = calm(raw);
1206
+ swing(spring.step(clamp(motion.lift * 0.4, -0.8, 0.8), delta), -motion.yaw * 0.05);
1207
+ };
1208
+ }
1209
+ function back(b, radius, p, {
1210
+ count,
1211
+ from,
1212
+ end,
1213
+ width,
1214
+ wave = 0.04,
1215
+ curl = 0.08,
1216
+ blunt = false,
1217
+ layers = 1
1218
+ }) {
1219
+ const made = [];
1220
+ const step = (Math.PI * 2 - from * 2) / (count - 1);
1221
+ for (let n = 0;n < count * layers; n += 1) {
1222
+ const layer = Math.floor(n / count);
1223
+ const i = n % count;
1224
+ const under = layer < layers - 1;
1225
+ if (under && i === count - 1)
1226
+ continue;
1227
+ const phi = from + i * step + (under ? step / 2 : 0);
1228
+ const vary = i * 7 % 5 / 5;
1229
+ const reach = blunt ? end : end - vary * 0.06;
1230
+ const steps = 5;
1231
+ const path = [onHead(radius, phi * 0.85, TOP - 0.02, 0.03)];
1232
+ for (let k = 1;k <= steps; k += 1) {
1233
+ const t = k / steps;
1234
+ const y = TOP - 0.06 - (TOP - 0.06 - reach) * t;
1235
+ const s = Math.sin(t * Math.PI * 1.5 + i * 0.7) * wave;
1236
+ const gap = 0.05 + 0.05 * Math.sin(Math.min(1, t * 2) * Math.PI * 0.5) + t * 0.02 - (under ? 0.018 : 0);
1237
+ const turn = t > 0.8 ? (phi < Math.PI ? -curl : curl) * (t - 0.8) * 5 : 0;
1238
+ path.push(onHead(radius, phi + s + turn, Math.max(0.03, y), gap));
1239
+ }
1240
+ const twist = (i % 3 === 0 ? 0.9 : i % 3 === 1 ? -0.5 : 0.2) * (blunt ? 0.3 : 1);
1241
+ made.push(add(b, p, clump(path, width * (0.85 + vary * 0.3), width * 0.36, blunt ? 0.55 : 1, twist)));
1242
+ }
1243
+ return made;
1244
+ }
1245
+ function hangs(made) {
1246
+ const swings = made.map(swinger);
1247
+ const pitch = new Spring(45, 4.5);
1248
+ const roll = new Spring(40, 4);
1249
+ return (clock, delta, raw) => {
1250
+ const motion = calm(raw);
1251
+ const p = pitch.step(clamp(motion.lift * 0.18, -0.6, 0.6), delta);
1252
+ const r = roll.step(-motion.yaw * 0.07 + Math.sin(clock * 1.3) * 0.03, delta);
1253
+ swings.forEach((swing, i) => {
1254
+ swing(p * (1 + i % 3 * 0.1), r * (1 + i % 2 * 0.15));
1255
+ });
1256
+ };
1257
+ }
1258
+ var together = (...ticks) => (clock, delta, motion) => {
1259
+ for (const tick of ticks)
1260
+ tick?.(clock, delta, motion);
72
1261
  };
73
- var EYES = {
74
- dot: {
75
- open: [".ee..ee.", ".ee..ee."],
76
- blink: ["........", ".ee..ee."],
77
- happy: ["........", ".ee..ee."],
78
- wide: [".ee..ee.", ".ee..ee."],
79
- sad: ["........", ".ee..ee."]
1262
+ function tail(radius, phi, tieY, length, spread, count = 4) {
1263
+ const paths = [];
1264
+ for (let i = 0;i < count; i += 1) {
1265
+ const k = i / Math.max(1, count - 1) - 0.5;
1266
+ const fan = k * spread;
1267
+ const path = [onHead(radius, phi, tieY, 0.05)];
1268
+ const steps = 6;
1269
+ const reach = length * (1 - Math.abs(k) * 0.18);
1270
+ for (let n = 1;n <= steps; n += 1) {
1271
+ const t = n / steps;
1272
+ const y = tieY + 0.06 * Math.sin(t * Math.PI) - reach * t ** 1.25;
1273
+ const gap = 0.12 + 0.12 * Math.sin(Math.min(1, t * 1.8) * Math.PI * 0.5) + Math.abs(k) * 0.05;
1274
+ const s = Math.sin(t * Math.PI * 1.6) * 0.08;
1275
+ path.push(onHead(radius, phi + fan * (0.4 + t) + s * Math.sign(phi || 1), Math.max(0.02, y), gap));
1276
+ }
1277
+ paths.push(path);
1278
+ }
1279
+ return paths;
1280
+ }
1281
+ function ribbon(b, at, facing, color, size = 1) {
1282
+ const node = b.node({ at: [at.x, at.y, at.z], rotate: [0, facing, 0], scale: [size, size, size] });
1283
+ const loop = new TorusGeometry2(0.05, 0.017, 10, 24);
1284
+ for (const side of [-1, 1]) {
1285
+ b.add(loop, color, {
1286
+ at: [side * 0.055, 0.008, 0],
1287
+ rotate: [0, 0, side * 0.35],
1288
+ scale: [1.15, 0.72, 0.6],
1289
+ parent: node
1290
+ });
1291
+ const end = clump([
1292
+ new Vector3(side * 0.01, -0.01, 0.01),
1293
+ new Vector3(side * 0.035, -0.06, 0.012),
1294
+ new Vector3(side * 0.03, -0.11, 0.008)
1295
+ ], 0.022, 0.006, 0.5);
1296
+ b.add(end.geometry, color, { parent: node });
1297
+ }
1298
+ b.add(new SphereGeometry2(0.024, 12, 10), color, { scale: [1, 1, 0.8], parent: node });
1299
+ }
1300
+ function clip(b, at, tilt, color) {
1301
+ const node = b.node({ at: [at.x, at.y, at.z], rotate: [0, Math.atan2(at.x, at.z), tilt] });
1302
+ const bar = new BoxGeometry(0.075, 0.016, 0.012);
1303
+ b.add(bar, color, { rotate: [0, 0, 0.45], parent: node }, { sheen: 0.5 });
1304
+ b.add(bar, color, { rotate: [0, 0, -0.45], parent: node }, { sheen: 0.5 });
1305
+ }
1306
+ var HAIR = {
1307
+ "fluffy-bob": {
1308
+ palette: { color: "#8a5236", tip: "#e7a874", inner: "#5c3640" },
1309
+ build(b, radius, p) {
1310
+ base(b, radius, p, 0.7, 0.38, 0.05);
1311
+ const made = back(b, radius, p, {
1312
+ count: 15,
1313
+ from: 1,
1314
+ end: 0.36,
1315
+ width: 0.13,
1316
+ wave: 0.02,
1317
+ curl: 0.18,
1318
+ layers: 2
1319
+ });
1320
+ fringe(b, radius, p, [
1321
+ { at: -0.62, length: 0.69, width: 0.09, sweep: -0.1 },
1322
+ { at: -0.36, length: 0.62, width: 0.12 },
1323
+ { at: -0.1, length: 0.66, width: 0.1, sweep: 0.04 },
1324
+ { at: 0.14, length: 0.6, width: 0.125, sweep: 0.06 },
1325
+ { at: 0.4, length: 0.65, width: 0.1, sweep: 0.08 },
1326
+ { at: 0.65, length: 0.7, width: 0.085, sweep: 0.12 }
1327
+ ]);
1328
+ sidelocks(b, radius, p, 0.28);
1329
+ strays(b, radius, p, [
1330
+ [0.6, 0.86, 0.12],
1331
+ [-1.5, 0.8, 0.14],
1332
+ [2.4, 0.84, 0.12]
1333
+ ]);
1334
+ clip(b, onHead(radius, 0.55, 0.8, 0.1), -0.4, "#ffd84d");
1335
+ return together(ahoge(b, p), hangs(made));
1336
+ }
80
1337
  },
81
- sparkle: {
82
- open: [".we..we.", ".ee..ee."],
83
- blink: ["........", ".ee..ee."],
84
- happy: ["........", ".ee..ee."],
85
- wide: [".ee..ee.", ".ee..ee."],
86
- sad: ["........", ".ee..ee."]
1338
+ "twin-tails": {
1339
+ palette: { color: "#ff86b8", tip: "#b38cff", inner: "#d65a98" },
1340
+ build(b, radius, p) {
1341
+ base(b, radius, p, 0.72, 0.44, 0.045);
1342
+ fringe(b, radius, p, [
1343
+ { at: -0.55, length: 0.68, width: 0.1, sweep: -0.08 },
1344
+ { at: -0.28, length: 0.62, width: 0.12 },
1345
+ { at: 0, length: 0.65, width: 0.1, sweep: 0.03 },
1346
+ { at: 0.27, length: 0.61, width: 0.12, sweep: 0.06 },
1347
+ { at: 0.56, length: 0.69, width: 0.09, sweep: 0.1 }
1348
+ ]);
1349
+ sidelocks(b, radius, p, 0.32, 0.065);
1350
+ back(b, radius, p, { count: 10, from: 1.5, end: 0.5, width: 0.12, wave: 0.02 });
1351
+ const tails = [];
1352
+ for (const side of [-1, 1]) {
1353
+ const tieY = TOP - 0.1;
1354
+ const tie = onHead(radius, side * 1.3, tieY, 0.07);
1355
+ for (const path of tail(radius, side * 1.3, tieY, 0.95, 0.34, 6))
1356
+ tails.push(add(b, p, clump(path, 0.12, 0.05, 1, side * 0.8)));
1357
+ ribbon(b, tie.add(new Vector3(0, 0.02, 0.02)), side * 1.3, "#5bc8ff", 1.7);
1358
+ }
1359
+ strays(b, radius, p, [
1360
+ [0.75, 0.84, 0.1],
1361
+ [-0.8, 0.83, 0.12]
1362
+ ]);
1363
+ return together(ahoge(b, p, -1), hangs(tails));
1364
+ }
87
1365
  },
88
- sleepy: {
89
- open: ["........", ".ee..ee."],
90
- blink: ["........", ".ee..ee."],
91
- happy: ["........", ".ee..ee."],
92
- wide: [".ee..ee.", ".ee..ee."],
93
- sad: ["........", ".ee..ee."]
1366
+ "spiky-hero": {
1367
+ palette: { color: "#f6c945", tip: "#ff8a3d", inner: "#b07b1e" },
1368
+ build(b, radius, p) {
1369
+ base(b, radius, p, 0.74, 0.5, 0.045);
1370
+ const spikes = [
1371
+ [0, TOP - 0.04, 0.3, 0.6],
1372
+ [0.55, TOP - 0.06, 0.28, 0.5],
1373
+ [-0.55, TOP - 0.06, 0.28, 0.5],
1374
+ [1.2, 0.8, 0.26, 0.35],
1375
+ [-1.2, 0.8, 0.26, 0.35],
1376
+ [1.9, 0.78, 0.24, 0.25],
1377
+ [-1.9, 0.78, 0.24, 0.25],
1378
+ [2.5, 0.8, 0.25, 0.3],
1379
+ [-2.5, 0.8, 0.25, 0.3],
1380
+ [Math.PI, 0.82, 0.26, 0.35],
1381
+ [2.9, TOP - 0.05, 0.3, 0.55],
1382
+ [-2.9, TOP - 0.05, 0.3, 0.55]
1383
+ ];
1384
+ for (const [phi, y, reach, up] of spikes) {
1385
+ const length = reach * 1.45;
1386
+ const root = onHead(radius, phi, y, 0.02);
1387
+ const out = onHead(radius, phi, y, 1).sub(root).normalize();
1388
+ const tip = root.clone().addScaledVector(out, length * (1 - up)).addScaledVector(UP, length * up).add(new Vector3(0, 0, -length * 0.2));
1389
+ const mid = root.clone().lerp(tip, 0.45).addScaledVector(out, 0.03);
1390
+ add(b, p, clump([root, mid, tip], 0.14, 0.07));
1391
+ }
1392
+ fringe(b, radius, p, [
1393
+ { at: -0.4, length: 0.66, width: 0.11, sweep: -0.12 },
1394
+ { at: 0.02, length: 0.62, width: 0.13 },
1395
+ { at: 0.42, length: 0.67, width: 0.11, sweep: 0.12 }
1396
+ ]);
1397
+ return;
1398
+ }
94
1399
  },
95
- derp: {
96
- open: [".ee.....", ".ee..e.."],
97
- blink: ["........", ".ee..ee."],
98
- happy: ["........", ".ee..ee."],
99
- wide: [".ee..ee.", ".ee..ee."],
100
- sad: ["........", ".ee..ee."]
1400
+ afro: {
1401
+ palette: { color: "#3a271b", tip: "#8a5a38", inner: "#24170f", ring: 0.45 },
1402
+ build(b, radius, p) {
1403
+ base(b, radius, p, 0.74, 0.4, 0.05);
1404
+ const puff = new SphereGeometry2(1, 18, 14);
1405
+ for (let i = 0;i < 46; i += 1) {
1406
+ const phi = i * 2.399963;
1407
+ const lat = 1 - (i + 0.5) / 46;
1408
+ const y = 0.62 + lat * (TOP + 0.12 - 0.62);
1409
+ if (Math.cos(phi) > 0.55 && y < 0.82)
1410
+ continue;
1411
+ const at = onHead(radius, phi, Math.min(y, TOP - 0.02), 0.1 + lat * 0.08);
1412
+ const size = 0.1 + lat * 0.05 + i * 7 % 5 * 0.006;
1413
+ b.add(puff, p.color, { at: [at.x, at.y + lat * 0.08, at.z], scale: [size, size * 0.92, size] }, anime(p, 0.6));
1414
+ }
1415
+ return;
1416
+ }
1417
+ },
1418
+ "swoosh-quiff": {
1419
+ palette: { color: "#5b3a86", tip: "#a98be0", inner: "#3a2358" },
1420
+ build(b, radius, p) {
1421
+ base(b, radius, p, 0.72, 0.42, 0.045, -0.4);
1422
+ back(b, radius, p, { count: 12, from: 1.2, end: 0.5, width: 0.11, wave: 0.02 });
1423
+ fringe(b, radius, p, [
1424
+ { at: -0.55, length: 0.74, width: 0.12, sweep: 0.5 },
1425
+ { at: -0.3, length: 0.7, width: 0.14, sweep: 0.55 },
1426
+ { at: -0.05, length: 0.66, width: 0.13, sweep: 0.6 },
1427
+ { at: 0.2, length: 0.64, width: 0.11, sweep: 0.62 }
1428
+ ], -0.4);
1429
+ return ahoge(b, p, -1);
1430
+ }
1431
+ },
1432
+ "long-waves": {
1433
+ palette: { color: "#c25b30", tip: "#ffbf86", inner: "#7a2f2a" },
1434
+ build(b, radius, p) {
1435
+ base(b, radius, p, 0.7, 0.4, 0.05, 0.3);
1436
+ fringe(b, radius, p, [
1437
+ { at: -0.52, length: 0.66, width: 0.1, sweep: -0.1 },
1438
+ { at: -0.24, length: 0.61, width: 0.125, sweep: -0.12 },
1439
+ { at: 0.06, length: 0.64, width: 0.11, sweep: -0.14 },
1440
+ { at: 0.36, length: 0.68, width: 0.1, sweep: -0.1 }
1441
+ ], 0.3);
1442
+ sidelocks(b, radius, p, 0.12, 0.085);
1443
+ const locks = back(b, radius, p, {
1444
+ count: 16,
1445
+ from: 1.15,
1446
+ end: 0.05,
1447
+ width: 0.13,
1448
+ wave: 0.07,
1449
+ curl: 0.12,
1450
+ layers: 2
1451
+ });
1452
+ strays(b, radius, p, [
1453
+ [1.3, 0.7, 0.16],
1454
+ [-2.2, 0.6, 0.18]
1455
+ ]);
1456
+ ribbon(b, onHead(radius, -0.95, 0.86, 0.1), -0.95, "#ffffff", 0.9);
1457
+ return hangs(locks);
1458
+ }
1459
+ },
1460
+ ponytail: {
1461
+ palette: { color: "#f0c96a", tip: "#fff1c2", inner: "#b98a3a" },
1462
+ build(b, radius, p) {
1463
+ base(b, radius, p, 0.72, 0.55, 0.045, 0.2);
1464
+ fringe(b, radius, p, [
1465
+ { at: -0.42, length: 0.68, width: 0.1, sweep: 0.15 },
1466
+ { at: -0.14, length: 0.62, width: 0.12, sweep: 0.2 },
1467
+ { at: 0.16, length: 0.65, width: 0.11, sweep: 0.24 },
1468
+ { at: 0.44, length: 0.7, width: 0.09, sweep: 0.28 }
1469
+ ]);
1470
+ sidelocks(b, radius, p, 0.34, 0.06);
1471
+ const tieY = TOP + 0.01;
1472
+ const locks = tail(radius, Math.PI, tieY, 0.85, 0.4, 6).map((path, i) => add(b, p, clump(path, 0.12, 0.05, 1, (i % 2 ? 1 : -1) * 0.7)));
1473
+ ribbon(b, onHead(radius, Math.PI, tieY, 0.08), Math.PI, "#e2574c", 1.15);
1474
+ return together(ahoge(b, p), hangs(locks));
1475
+ }
1476
+ },
1477
+ mohawk: {
1478
+ palette: { color: "#1fae8f", tip: "#a6f5dd", inner: "#127160" },
1479
+ build(b, radius, p) {
1480
+ base(b, radius, { color: "#2a2440", tip: "#3a3260", inner: "#1d1830", ring: 0.25 }, 0.72, 0.4, 0.014);
1481
+ for (let i = 0;i < 8; i += 1) {
1482
+ const s = i / 7;
1483
+ const phi = s < 0.45 ? 0 : Math.PI;
1484
+ const y = s < 0.45 ? 0.82 + s * 0.3 : TOP - (s - 0.45) * 0.5;
1485
+ const root = onHead(radius, phi, Math.min(y, TOP - 0.01), 0);
1486
+ root.x = 0;
1487
+ 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));
1488
+ const mid = root.clone().lerp(tip, 0.5).add(new Vector3(0, 0.02, 0.02));
1489
+ add(b, p, clump([root, mid, tip], 0.03, 0.09));
1490
+ }
1491
+ return;
1492
+ }
1493
+ },
1494
+ "space-buns": {
1495
+ palette: { color: "#b9a6ff", tip: "#ffc2ec", inner: "#7d6ad1" },
1496
+ build(b, radius, p) {
1497
+ base(b, radius, p, 0.72, 0.42, 0.045);
1498
+ fringe(b, radius, p, [
1499
+ { at: -0.52, length: 0.66, width: 0.1 },
1500
+ { at: -0.24, length: 0.62, width: 0.11, sweep: -0.04 },
1501
+ { at: 0.04, length: 0.65, width: 0.12, sweep: 0.04 },
1502
+ { at: 0.32, length: 0.62, width: 0.1, sweep: 0.06 },
1503
+ { at: 0.58, length: 0.67, width: 0.09, sweep: 0.08 }
1504
+ ]);
1505
+ sidelocks(b, radius, p, 0.3, 0.055);
1506
+ const tufts = [];
1507
+ for (const side of [-1, 1]) {
1508
+ const at = onHead(radius, side * 0.9, TOP - 0.08, 0.1).add(new Vector3(0, 0.05, 0));
1509
+ const coil = [];
1510
+ for (let k = 0;k <= 14; k += 1) {
1511
+ const a = k * 0.9;
1512
+ const r = 0.11 - k * 0.004;
1513
+ coil.push(new Vector3(at.x + Math.cos(a) * r, at.y + (k / 14 - 0.5) * 0.12, at.z + Math.sin(a) * r));
1514
+ }
1515
+ b.add(new SphereGeometry2(0.1, 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 } });
1516
+ add(b, p, clump(coil, 0.06, 0.035, 0.7));
1517
+ ribbon(b, at.clone().add(new Vector3(0, -0.07, 0.06)), side * 0.9, "#ffd84d", 0.8);
1518
+ for (const path of tail(radius, side * 1.05, TOP - 0.16, 0.42, 0.22, 3))
1519
+ tufts.push(add(b, p, clump(path, 0.075, 0.03)));
1520
+ }
1521
+ return hangs(tufts);
1522
+ }
1523
+ },
1524
+ "hime-cut": {
1525
+ palette: { color: "#2d2b52", tip: "#7b68d6", inner: "#1b1934", ring: 1.1 },
1526
+ build(b, radius, p) {
1527
+ base(b, radius, p, 0.72, 0.42, 0.05);
1528
+ fringe(b, radius, p, [
1529
+ { at: -0.6, length: 0.66, width: 0.11, blunt: true },
1530
+ { at: -0.36, length: 0.645, width: 0.12, blunt: true },
1531
+ { at: -0.12, length: 0.64, width: 0.12, blunt: true },
1532
+ { at: 0.12, length: 0.64, width: 0.12, blunt: true },
1533
+ { at: 0.36, length: 0.645, width: 0.12, blunt: true },
1534
+ { at: 0.6, length: 0.66, width: 0.11, blunt: true }
1535
+ ]);
1536
+ sidelocks(b, radius, p, 0.36, 0.09, true);
1537
+ const locks = back(b, radius, p, {
1538
+ count: 18,
1539
+ from: 1.3,
1540
+ end: 0.04,
1541
+ width: 0.13,
1542
+ wave: 0.01,
1543
+ curl: 0,
1544
+ blunt: true,
1545
+ layers: 2
1546
+ });
1547
+ ribbon(b, onHead(radius, Math.PI, TOP - 0.02, 0.07), Math.PI, "#e8475f", 1.3);
1548
+ return hangs(locks);
1549
+ }
101
1550
  }
102
1551
  };
103
- var MOUTHS = {
104
- idle: ["...mm...", "........"],
105
- open: ["...mm...", "...tt..."],
106
- o: ["...mm...", "...mm..."],
107
- frown: ["...mm...", "..m..m.."]
108
- };
109
- var PARTS = {
110
- idle: { eyes: "open", mouth: "idle" },
111
- blink: { eyes: "blink", mouth: "idle" },
112
- happy: { eyes: "happy", mouth: "open" },
113
- surprised: { eyes: "wide", mouth: "o" },
114
- sad: { eyes: "sad", mouth: "frown" },
115
- wee: { eyes: "happy", mouth: "o" }
116
- };
1552
+ function buildHair(key, kit) {
1553
+ const style = HAIR[key];
1554
+ return piece(kit, (b) => style.build(b, kit.radiusAt, style.palette));
1555
+ }
1556
+
1557
+ // src/dress.ts
1558
+ function buildWear(key, kit) {
1559
+ return isHairKey(key) ? buildHair(key, kit) : buildGarment(key, kit);
1560
+ }
1561
+
1562
+ // src/proportions.ts
1563
+ var ARM_LENGTH = 0.3;
1564
+ var BELLY_HALF_WIDTH = 0.6;
1565
+ function plupProportions(shape, scale) {
1566
+ const body = clampBodyScale(scale);
1567
+ const torso = body.width.torso ?? 1;
1568
+ const girth = shape.x * torso;
1569
+ const arm = (width) => width ?? 1;
1570
+ const clear = (width) => girth > 1 ? Math.atan((girth - 1) * BELLY_HALF_WIDTH * 0.55 / (ARM_LENGTH * arm(width))) : 0;
1571
+ return {
1572
+ stature: body.stature,
1573
+ girth,
1574
+ armWidth: [arm(body.width.armL), arm(body.width.armR)],
1575
+ legWidth: [body.width.legL ?? 1, body.width.legR ?? 1],
1576
+ armClear: [clear(body.width.armL), clear(body.width.armR)],
1577
+ lift: body.stature * Math.min(1.2, Math.max(0.7, 1 / Math.sqrt(girth))),
1578
+ squash: Math.min(1.6, Math.max(0.6, girth))
1579
+ };
1580
+ }
1581
+
1582
+ // src/texture.ts
1583
+ import { LinearMipmapLinearFilter, NearestFilter } from "three";
1584
+ function pixelArtFiltering(texture) {
1585
+ texture.magFilter = NearestFilter;
1586
+ texture.minFilter = LinearMipmapLinearFilter;
1587
+ texture.generateMipmaps = true;
1588
+ return texture;
1589
+ }
1590
+
1591
+ // src/plup3d.ts
117
1592
  function stampFor(face, type) {
118
- if (Object.hasOwn(NAMED_FACE_STAMPS, face))
119
- return NAMED_FACE_STAMPS[face];
120
- const parts = PARTS[face] ?? PARTS.idle;
121
- const [eyeTop, eyeBottom] = (EYES[type] ?? EYES.dot)[parts.eyes];
122
- const [mouthTop, mouthBottom] = MOUTHS[parts.mouth];
123
- const blush = type === "derp" ? "........" : "p......p";
124
- const merged = Array.from(mouthTop, (pixel, i) => pixel === "." ? blush[i] ?? "." : pixel).join("");
125
- return [eyeTop, eyeBottom, merged, mouthBottom];
126
- }
127
- var BODY_WIDTH = 48;
128
- var BODY_HEIGHT = 24;
129
- var FACE_COLUMN = 20;
130
- var FACE_ROW = 9;
131
- var RADIUS_X = 0.54;
132
- var RADIUS_Y = 0.64;
133
- var RADIUS_Z = 0.54;
1593
+ return faceStamp(type, face);
1594
+ }
134
1595
  var TOON_VERTEX = `
135
1596
  varying vec3 vNormal;
136
1597
  varying vec2 vUv;
137
1598
  uniform vec2 uvOffset;
1599
+ uniform vec2 uvRepeat;
138
1600
  void main() {
139
1601
  vNormal = normalize(normalMatrix * (length(normal) > 0.001 ? normal : vec3(0.0, 0.0, 1.0)));
140
- vUv = uv + uvOffset;
1602
+ vUv = uv * uvRepeat + uvOffset;
141
1603
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
142
1604
  }`;
143
1605
  var TOON_FRAGMENT = `
@@ -146,27 +1608,132 @@ varying vec2 vUv;
146
1608
  uniform sampler2D map;
147
1609
  uniform float useMap;
148
1610
  uniform vec3 color;
1611
+ uniform vec3 backColor;
1612
+ uniform float sheen;
149
1613
  void main() {
150
- vec3 n = normalize(vNormal);
151
- float light = dot(n, normalize(vec3(-0.35, 0.75, 0.55)));
1614
+ // An open shell (a skirt, a cape) is seen from inside too: its back faces light as front ones,
1615
+ // in their own colour when it has a lining.
1616
+ vec3 n = normalize(vNormal) * (gl_FrontFacing ? 1.0 : -1.0);
1617
+ vec3 toLight = normalize(vec3(-0.35, 0.75, 0.55));
1618
+ float light = dot(n, toLight);
152
1619
  float band = light > 0.2 ? 1.0 : light > -0.3 ? 0.8 : 0.6;
153
- vec3 base = useMap > 0.5 ? texture2D(map, vUv).rgb : color;
1620
+ vec3 tint = gl_FrontFacing ? color : backColor;
1621
+ vec3 base = useMap > 0.5 ? texture2D(map, vUv).rgb * tint : tint;
154
1622
  vec3 lit = base * band;
1623
+ // Satin and metal: one hard highlight band, still a cartoon, never a smooth gradient.
1624
+ float glint = pow(max(dot(n, normalize(toLight + vec3(0.0, 0.0, 1.0))), 0.0), 36.0);
1625
+ if (sheen > 0.0 && glint > 0.45) lit = mix(lit, vec3(1.0), sheen);
155
1626
  float rim = 1.0 - max(n.z, 0.0);
156
1627
  if (rim > 0.82 && n.y > -0.2) lit = mix(lit, vec3(1.0), 0.35);
157
1628
  gl_FragColor = vec4(lit, 1.0);
158
1629
  #include <colorspace_fragment>
159
1630
  }`;
1631
+ var HAIR_VERTEX = `
1632
+ attribute float along;
1633
+ uniform vec3 center;
1634
+ varying vec3 vNormal;
1635
+ varying vec3 vDome;
1636
+ varying vec3 vDir;
1637
+ varying float vAlong;
1638
+ varying float vInward;
1639
+ void main() {
1640
+ vec3 dome = normalize(position - center);
1641
+ vec3 real = length(normal) > 0.001 ? normalize(normal) : dome;
1642
+ vNormal = normalize(normalMatrix * real);
1643
+ vDome = normalize(normalMatrix * normalize(mix(real, dome, 0.78)));
1644
+ vDir = dome;
1645
+ vAlong = along;
1646
+ // The side of a lock that faces the skull: the underside of a ribbon, seen where it twists.
1647
+ vInward = dot(real, dome);
1648
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
1649
+ }`;
1650
+ var HAIR_FRAGMENT = `
1651
+ uniform vec3 color;
1652
+ uniform vec3 tip;
1653
+ uniform vec3 inner;
1654
+ uniform float ring;
1655
+ varying vec3 vNormal;
1656
+ varying vec3 vDome;
1657
+ varying vec3 vDir;
1658
+ varying float vAlong;
1659
+ varying float vInward;
1660
+ void main() {
1661
+ vec3 n = normalize(vDome) * (gl_FrontFacing ? 1.0 : -1.0);
1662
+ vec3 toLight = normalize(vec3(-0.35, 0.75, 0.55));
1663
+ float light = dot(n, toLight);
1664
+ // The colour runs towards the tips (an ombre), and the underside of a lock is its inner colour.
1665
+ float toTip = smoothstep(0.35, 1.0, vAlong);
1666
+ vec3 base = mix(color, tip, toTip);
1667
+ base = mix(base, inner, smoothstep(-0.15, -0.55, vInward));
1668
+ vec3 shadow = base * vec3(0.7, 0.62, 0.86);
1669
+ vec3 deep = base * vec3(0.46, 0.4, 0.68);
1670
+ vec3 lit = light > 0.12 ? base : light > -0.38 ? shadow : deep;
1671
+ // Reflected light: the shaded side of the ends catches a little of the tip colour, so the hair
1672
+ // looks like light passes through it rather than going flat.
1673
+ if (light <= 0.12) lit = mix(lit, tip, 0.38 * toTip);
1674
+ // The angel ring: a band round the skull, its edges zigzagging the way a drawn highlight does.
1675
+ float around = atan(vDir.x, vDir.z);
1676
+ float zig = abs(fract(around * 4.5) - 0.5) * 2.0;
1677
+ float centre = 0.62 + (zig - 0.5) * 0.09;
1678
+ float width = 0.05 * (0.5 + 0.5 * zig);
1679
+ float onRing = step(abs(vDir.y - centre), width) * step(0.0, n.z) * step(0.0, light + 0.2) * (1.0 - toTip);
1680
+ vec3 shine = mix(base, vec3(1.0, 0.98, 1.0), 0.5);
1681
+ lit = mix(lit, shine, onRing * ring);
1682
+ // A hard, thin rim on the lit side separates the hair from what is behind it.
1683
+ float rim = 1.0 - max(normalize(vNormal).z, 0.0);
1684
+ if (rim > 0.86 && n.y > 0.0) lit = mix(lit, vec3(1.0), 0.28);
1685
+ gl_FragColor = vec4(lit, 1.0);
1686
+ #include <colorspace_fragment>
1687
+ }`;
1688
+ function taperedHose(curve, muscle) {
1689
+ const segments = 16;
1690
+ const radial = 10;
1691
+ const tube = new TubeGeometry(curve, segments, 0.046, radial);
1692
+ const position = tube.attributes.position;
1693
+ const centre = new Vector32;
1694
+ for (let i = 0;i <= segments; i += 1) {
1695
+ const t = i / segments;
1696
+ curve.getPointAt(t, centre);
1697
+ const strength = Math.max(0, muscle - 1);
1698
+ const biceps = 1 + strength * 1.1 * Math.exp(-(((t - 0.28) / 0.14) ** 2));
1699
+ const forearm = 1 + strength * 0.8 * Math.exp(-(((t - 0.74) / 0.12) ** 2));
1700
+ const k = (1.12 - 0.3 * t) * biceps * forearm;
1701
+ for (let j = 0;j <= radial; j += 1) {
1702
+ const v = i * (radial + 1) + j;
1703
+ position.setXYZ(v, centre.x + (position.getX(v) - centre.x) * k, centre.y + (position.getY(v) - centre.y) * k, centre.z + (position.getZ(v) - centre.z) * k);
1704
+ }
1705
+ }
1706
+ tube.computeVertexNormals();
1707
+ return tube;
1708
+ }
160
1709
  function toon(options) {
1710
+ if (options.anime)
1711
+ return new ShaderMaterial({
1712
+ ...options.double ? { side: DoubleSide } : {},
1713
+ vertexShader: HAIR_VERTEX,
1714
+ fragmentShader: HAIR_FRAGMENT,
1715
+ toneMapped: false,
1716
+ uniforms: {
1717
+ color: { value: new Color2(options.color ?? "#ffffff") },
1718
+ center: { value: new Vector32(...options.anime.center) },
1719
+ ring: { value: options.anime.ring ?? 1 },
1720
+ tip: { value: new Color2(options.anime.tip ?? options.color ?? "#ffffff") },
1721
+ inner: { value: new Color2(options.anime.inner ?? options.color ?? "#ffffff") }
1722
+ }
1723
+ });
161
1724
  return new ShaderMaterial({
1725
+ ...options.double ? { side: DoubleSide } : {},
162
1726
  vertexShader: TOON_VERTEX,
163
1727
  fragmentShader: TOON_FRAGMENT,
164
1728
  toneMapped: false,
165
1729
  uniforms: {
166
1730
  map: { value: options.map ?? null },
167
1731
  useMap: { value: options.map ? 1 : 0 },
168
- color: { value: new Color(options.color ?? "#ffffff") },
169
- uvOffset: { value: [options.map?.offset.x ?? 0, 0] }
1732
+ color: { value: new Color2(options.color ?? "#ffffff") },
1733
+ backColor: { value: new Color2(options.back ?? options.color ?? "#ffffff") },
1734
+ sheen: { value: options.sheen ?? 0 },
1735
+ uvOffset: { value: [options.map?.offset.x ?? 0, 0] },
1736
+ uvRepeat: { value: options.repeat ?? [1, 1] }
170
1737
  }
171
1738
  });
172
1739
  }
@@ -174,7 +1741,7 @@ function hull(color, width) {
174
1741
  return new ShaderMaterial({
175
1742
  side: BackSide,
176
1743
  toneMapped: false,
177
- uniforms: { color: { value: new Color(color) }, width: { value: width } },
1744
+ uniforms: { color: { value: new Color2(color) }, width: { value: width } },
178
1745
  vertexShader: `
179
1746
  uniform float width;
180
1747
  void main() {
@@ -188,30 +1755,14 @@ void main() {
188
1755
  }`
189
1756
  });
190
1757
  }
191
- function blobGeometry() {
192
- const geometry = new SphereGeometry(1, 40, 28);
193
- const position = geometry.attributes.position;
194
- let minY = Number.POSITIVE_INFINITY;
195
- for (let i = 0;i < position.count; i += 1) {
196
- let y = position.getY(i);
197
- const spread = 1 + 0.16 * -y;
198
- if (y < -0.62)
199
- y = -0.62 + (y + 0.62) * 0.3;
200
- position.setXYZ(i, position.getX(i) * spread * RADIUS_X, y * RADIUS_Y, position.getZ(i) * spread * RADIUS_Z);
201
- minY = Math.min(minY, y * RADIUS_Y);
202
- }
203
- geometry.translate(0, -minY, 0);
204
- geometry.computeVertexNormals();
205
- return geometry;
206
- }
207
1758
  var channel = (hex, at) => Number.parseInt(hex.slice(at, at + 2), 16);
208
1759
  var shade = (hex, toward, amount) => `#${[1, 3, 5].map((at) => Math.round(channel(hex, at) + (toward - channel(hex, at)) * amount).toString(16).padStart(2, "0")).join("")}`;
209
- function paintBody(canvas, color, face, skin) {
1760
+ function paintBody(canvas, color, face, skin, faceType) {
210
1761
  const ctx = canvas.getContext("2d");
211
1762
  if (!ctx)
212
1763
  return;
213
1764
  const px = canvas.width / BODY_WIDTH;
214
- const base = color;
1765
+ const base2 = color;
215
1766
  const light = shade(color, 255, 0.32);
216
1767
  const belly = shade(color, 255, 0.62);
217
1768
  const dark = shade(color, 0, 0.3);
@@ -229,7 +1780,7 @@ function paintBody(canvas, color, face, skin) {
229
1780
  ctx.fillRect(x * px, y * px, px, px);
230
1781
  continue;
231
1782
  }
232
- let fill = base;
1783
+ let fill = base2;
233
1784
  if (y >= 16)
234
1785
  fill = belly;
235
1786
  else if (y === 15)
@@ -251,7 +1802,9 @@ function paintBody(canvas, color, face, skin) {
251
1802
  ])
252
1803
  ctx.fillRect(x * px, y * px, px, px);
253
1804
  }
254
- const stamp = stampFor(face, skin?.faceType ?? "dot");
1805
+ if ((skin?.faceType ?? faceType) === "anime")
1806
+ return;
1807
+ const stamp = stampFor(face, skin?.faceType ?? faceType ?? "dot");
255
1808
  stamp.forEach((row, dy) => {
256
1809
  for (let dx = 0;dx < row.length; dx += 1) {
257
1810
  const key = row[dx] ?? ".";
@@ -263,64 +1816,153 @@ function paintBody(canvas, color, face, skin) {
263
1816
  }
264
1817
  });
265
1818
  }
1819
+ function animeDecal(faceType, face, eyeColor) {
1820
+ if (faceType !== "anime")
1821
+ return null;
1822
+ const canvas = document.createElement("canvas");
1823
+ canvas.width = ANIME_FACE_SIZE.width;
1824
+ canvas.height = ANIME_FACE_SIZE.height;
1825
+ const ctx = canvas.getContext("2d");
1826
+ const map = new CanvasTexture2(canvas);
1827
+ map.colorSpace = SRGBColorSpace2;
1828
+ map.anisotropy = 4;
1829
+ const { u0, u1, v0, v1 } = ANIME_FACE_UV;
1830
+ map.repeat.set(1 / (u1 - u0), 1 / (v1 - v0));
1831
+ map.offset.set(-u0 / (u1 - u0), -v0 / (v1 - v0));
1832
+ const material = new MeshBasicMaterial2({
1833
+ map,
1834
+ transparent: true,
1835
+ depthWrite: false,
1836
+ polygonOffset: true,
1837
+ polygonOffsetFactor: -4
1838
+ });
1839
+ const draw = (next) => {
1840
+ if (!ctx)
1841
+ return;
1842
+ drawAnimeFace(ctx, next, eyeColor);
1843
+ map.needsUpdate = true;
1844
+ };
1845
+ draw(face);
1846
+ return { material, draw };
1847
+ }
266
1848
  var inkHull = null;
267
1849
  var neonHull = null;
1850
+ var fineHull = null;
268
1851
  function createPlup(options = {}) {
269
1852
  inkHull ??= hull("#14102e", 0.022);
270
1853
  neonHull ??= hull("#b9a6ff", 0.04);
1854
+ fineHull ??= hull("#14102e", 0.009);
1855
+ const fine = fineHull;
271
1856
  const ink = inkHull;
272
1857
  const neon = neonHull;
273
1858
  let color = options.color ?? "#3d7bff";
274
1859
  let face = options.face ?? "smug";
275
1860
  const skin = options.skin ?? null;
276
1861
  const shape = BODY_SHAPES[options.shape ?? "plup"] ?? BODY_SHAPES.plup;
1862
+ const fit = plupProportions(shape, options.bodyScale);
1863
+ const build = clampPlupBody(options.body);
1864
+ const silhouette = { shoulders: build.shoulders, waist: build.waist, hips: build.hips };
1865
+ const legRaise = 0.16 * (build.legLength - 1);
277
1866
  const canvas = document.createElement("canvas");
278
1867
  canvas.width = BODY_WIDTH * 4;
279
1868
  canvas.height = BODY_HEIGHT * 4;
280
- paintBody(canvas, color, face, skin);
281
- const texture = new CanvasTexture(canvas);
282
- texture.magFilter = NearestFilter;
283
- texture.minFilter = NearestFilter;
284
- texture.generateMipmaps = false;
285
- texture.colorSpace = SRGBColorSpace;
286
- texture.wrapS = RepeatWrapping;
1869
+ paintBody(canvas, color, face, skin, options.faceType);
1870
+ const texture = new CanvasTexture2(canvas);
1871
+ pixelArtFiltering(texture);
1872
+ texture.colorSpace = SRGBColorSpace2;
1873
+ texture.wrapS = RepeatWrapping2;
287
1874
  texture.offset.x = (FACE_COLUMN + 4) / BODY_WIDTH - 0.25;
1875
+ const anime2 = animeDecal(skin?.faceType ?? options.faceType, face, options.eyeColor);
288
1876
  const bodyMaterial = toon({ map: texture });
289
1877
  const limbMaterial = toon({ color: shade(color, 0, 0.12) });
290
1878
  const tipMaterial = toon({ color: shade(color, 0, 0.3) });
291
- const root = new Group;
292
- const lifted = new Group;
1879
+ const root = new Group2;
1880
+ const lifted = new Group2;
293
1881
  root.add(lifted);
294
- const geometry = blobGeometry();
1882
+ const geometry = buildBlobGeometry(silhouette);
295
1883
  if (!options.model) {
296
- const bodyMesh = new Mesh(geometry, bodyMaterial);
297
- lifted.add(bodyMesh, new Mesh(geometry, ink), new Mesh(geometry, neon));
1884
+ const bodyMesh = new Mesh2(geometry, bodyMaterial);
1885
+ const blobMeshes = [bodyMesh, new Mesh2(geometry, ink), new Mesh2(geometry, neon)];
1886
+ for (const mesh of blobMeshes)
1887
+ mesh.scale.set(fit.girth / shape.x, clampBodyScale(options.bodyScale).head, fit.girth / shape.x);
1888
+ lifted.add(...blobMeshes);
1889
+ if (anime2) {
1890
+ const decal = new Mesh2(geometry, anime2.material);
1891
+ decal.scale.copy(bodyMesh.scale).multiplyScalar(1.006);
1892
+ decal.renderOrder = 1;
1893
+ lifted.add(decal);
1894
+ }
298
1895
  for (const mesh of lifted.children)
299
1896
  mesh.raycast = () => {};
300
1897
  }
1898
+ const wearRoot = new Group2;
1899
+ wearRoot.scale.set(fit.girth / shape.x, clampBodyScale(options.bodyScale).head, fit.girth / shape.x);
1900
+ lifted.add(wearRoot);
1901
+ const worn = new Map;
1902
+ const kit = {
1903
+ radiusAt: (y) => blobRadiusAt(y, silhouette),
1904
+ paint: (paint, more = {}) => toon({ ...more, color: paint }),
1905
+ ink: fine
1906
+ };
1907
+ let lastLift = 0;
1908
+ let lastYaw = 0;
1909
+ const setWear = (next) => {
1910
+ const wanted = new Set(next);
1911
+ for (const [key, piece2] of worn) {
1912
+ if (wanted.has(key))
1913
+ continue;
1914
+ wearRoot.remove(piece2.object);
1915
+ piece2.dispose();
1916
+ worn.delete(key);
1917
+ }
1918
+ for (const key of wanted) {
1919
+ if (worn.has(key))
1920
+ continue;
1921
+ const piece2 = buildWear(key, kit);
1922
+ worn.set(key, piece2);
1923
+ wearRoot.add(piece2.object);
1924
+ }
1925
+ const volume = Math.max(0, ...[...worn.keys()].filter(isHairKey).map(hairVolume));
1926
+ for (const [key, piece2] of worn)
1927
+ if (wearSlotOf(key) === "hat")
1928
+ piece2.object.position.y = volume;
1929
+ };
1930
+ setWear(options.wear ?? []);
301
1931
  const limbGeometry = new CapsuleGeometry(0.075, 0.2, 4, 10);
302
- const handGeometry = new SphereGeometry(0.11, 12, 10);
303
- const footGeometry = new SphereGeometry(0.13, 12, 10);
1932
+ const handGeometry = new SphereGeometry3(0.11, 12, 10);
1933
+ const footGeometry = new SphereGeometry3(0.13, 12, 10);
304
1934
  const pivots = {
305
- armL: new Group,
306
- armR: new Group,
307
- legL: new Group,
308
- legR: new Group
1935
+ armL: new Group2,
1936
+ armR: new Group2,
1937
+ legL: new Group2,
1938
+ legR: new Group2
309
1939
  };
310
- const limb = (name, x, y, length, tip, flat) => {
1940
+ const armGeometries = [];
1941
+ const limb = (name, x, y, length, tip, flat, bow2 = 0) => {
311
1942
  const pivot = pivots[name];
312
1943
  pivot.position.set(x, y, 0);
313
- const tube = new Mesh(limbGeometry, limbMaterial);
314
- tube.position.y = -length / 2;
315
- tube.scale.y = length / 0.35;
316
- const end = new Mesh(tip, tipMaterial);
317
- end.position.y = -length;
1944
+ const curve = bow2 ? new QuadraticBezierCurve3(new Vector32(0, 0.02, 0), new Vector32(bow2 * 0.09, -length * 0.5, 0.03), new Vector32(bow2 * 0.03, -length, 0.04)) : null;
1945
+ const shaft = curve ? taperedHose(curve, build.muscle) : limbGeometry;
1946
+ if (curve)
1947
+ armGeometries.push(shaft);
1948
+ const tube = new Mesh2(shaft, limbMaterial);
1949
+ if (!curve) {
1950
+ tube.position.y = -length / 2;
1951
+ tube.scale.y = length / 0.35;
1952
+ }
1953
+ const end = new Mesh2(tip, tipMaterial);
1954
+ if (curve)
1955
+ end.position.copy(curve.getPoint(1));
1956
+ else
1957
+ end.position.y = -length;
318
1958
  if (flat)
319
1959
  end.scale.set(1.15, 0.5, 1.7);
320
- const inkTube = new Mesh(limbGeometry, ink);
1960
+ else
1961
+ end.scale.setScalar(0.85);
1962
+ const inkTube = new Mesh2(shaft, ink);
321
1963
  inkTube.position.copy(tube.position);
322
1964
  inkTube.scale.copy(tube.scale);
323
- const inkEnd = new Mesh(tip, ink);
1965
+ const inkEnd = new Mesh2(tip, ink);
324
1966
  inkEnd.position.copy(end.position);
325
1967
  inkEnd.scale.copy(end.scale);
326
1968
  pivot.add(tube, end, inkTube, inkEnd);
@@ -336,14 +1978,26 @@ function createPlup(options = {}) {
336
1978
  pivots[name] = found;
337
1979
  }
338
1980
  } else {
339
- limb("armL", -0.6, 0.62, 0.3, handGeometry, false);
340
- limb("armR", 0.6, 0.62, 0.3, handGeometry, false);
341
- limb("legL", -0.22, 0.2, 0.16, footGeometry, true);
342
- limb("legR", 0.22, 0.2, 0.16, footGeometry, true);
1981
+ const torso = fit.girth / shape.x;
1982
+ const shoulderY = BLOB_HEIGHT * build.shoulderHeight;
1983
+ const shoulder = blobRadiusAt(shoulderY, silhouette) * 0.92 * torso;
1984
+ const arm = 0.27 * build.armLength;
1985
+ const hip = blobRadiusAt(BLOB_HEIGHT * 0.18, silhouette) * 0.42 * torso;
1986
+ const leg = 0.16 * build.legLength;
1987
+ limb("armL", -shoulder, shoulderY, arm, handGeometry, false, -1);
1988
+ limb("armR", shoulder, shoulderY, arm, handGeometry, false, 1);
1989
+ const knee = build.legLength > 1.2 ? 0.35 : 0;
1990
+ limb("legL", -hip, BLOB_HEIGHT * 0.18, leg, footGeometry, true, -knee);
1991
+ limb("legR", hip, BLOB_HEIGHT * 0.18, leg, footGeometry, true, knee);
1992
+ const bulk = build.muscle ** 0.6;
1993
+ pivots.armL.scale.set(fit.armWidth[0] * bulk, 1, fit.armWidth[0] * bulk);
1994
+ pivots.armR.scale.set(fit.armWidth[1] * bulk, 1, fit.armWidth[1] * bulk);
1995
+ pivots.legL.scale.set(fit.legWidth[0] * bulk, 1, fit.legWidth[0] * bulk);
1996
+ pivots.legR.scale.set(fit.legWidth[1] * bulk, 1, fit.legWidth[1] * bulk);
343
1997
  }
344
1998
  let shadow = null;
345
1999
  if (options.shadow !== false) {
346
- shadow = new Mesh(new SphereGeometry(0.6, 20, 6), new MeshBasicMaterial({
2000
+ shadow = new Mesh2(new SphereGeometry3(0.6, 20, 6), new MeshBasicMaterial2({
347
2001
  color: "#0b0f18",
348
2002
  transparent: true,
349
2003
  opacity: 0.4,
@@ -354,53 +2008,105 @@ function createPlup(options = {}) {
354
2008
  shadow.raycast = () => {};
355
2009
  root.add(shadow);
356
2010
  }
357
- let clip = "idle";
2011
+ let clip2 = "idle";
358
2012
  let held = {};
2013
+ let ragdoll = null;
2014
+ let down = false;
2015
+ const ragdollOf = () => {
2016
+ ragdoll ??= createRagdoll("off", blobRadiusAt(BLOB_SEAT, silhouette) * fit.girth * fit.stature);
2017
+ return ragdoll;
2018
+ };
2019
+ if (options.ragdoll && options.ragdoll !== "off")
2020
+ ragdollOf().set(options.ragdoll);
2021
+ const here = new Vector32;
2022
+ const last = new Vector32;
2023
+ const turn = new Quaternion;
2024
+ let tracked = false;
359
2025
  let seconds = 0;
360
2026
  let clock = 0;
2027
+ let lastDelta = 0;
361
2028
  const apply = () => {
362
- const pose = resolvePose("plup", mergePoses(sampleClip(clip, seconds), held));
2029
+ const pose = resolvePose("plup", mergePoses(sampleClip(clip2, seconds), held));
363
2030
  const byAlias = {
364
2031
  armL: "LeftArm",
365
2032
  armR: "RightArm",
366
2033
  legL: "LeftLeg",
367
2034
  legR: "RightLeg"
368
2035
  };
2036
+ const targets = {};
369
2037
  for (const name of Object.keys(pivots)) {
370
2038
  const rotation = pose.get(byAlias[name]);
371
- pivots[name].rotation.set(rotation?.x ?? 0, rotation?.y ?? 0, rotation?.z ?? 0);
2039
+ const clearance = name === "armL" ? fit.armClear[0] : name === "armR" ? -fit.armClear[1] : 0;
2040
+ const z = rotation?.z ?? 0;
2041
+ const side = name === "armL" ? -1 : name === "armR" ? 1 : 0;
2042
+ const rest = options.model ? 0 : side * 0.42 * Math.max(0, 1 - Math.abs(z) / 1.4);
2043
+ pivots[name].rotation.set(rotation?.x ?? 0, rotation?.y ?? 0, z + clearance + rest);
2044
+ targets[name] = { x: rotation?.x ?? 0, z: z + clearance + rest };
372
2045
  }
373
2046
  const body = pose.get("Body");
374
2047
  lifted.rotation.set(body?.x ?? 0, body?.y ?? 0, body?.z ?? 0);
375
- const breath = Math.sin(clock * 3.2) * 0.018;
376
- lifted.scale.set(shape.x * (1 - breath), shape.y * (1 + breath), shape.x * (1 - breath));
377
- lifted.position.y = clipLift(clip, seconds) * 0.32;
2048
+ const clipLiftY = legRaise + clipLift(clip2, seconds) * 0.32 * fit.lift;
2049
+ const breath = Math.sin(clock * 3.2) * 0.018 * fit.squash;
2050
+ lifted.scale.set(shape.x * fit.stature * (1 - breath), shape.y * fit.stature * (1 + breath), shape.x * fit.stature * (1 - breath));
2051
+ lifted.position.y = clipLiftY;
2052
+ if (ragdoll) {
2053
+ root.getWorldPosition(here);
2054
+ const step2 = Math.max(0.001, lastDelta);
2055
+ const velocity = tracked ? here.clone().sub(last).divideScalar(step2) : new Vector32;
2056
+ last.copy(here);
2057
+ tracked = true;
2058
+ velocity.applyQuaternion(root.getWorldQuaternion(turn).invert());
2059
+ const out = ragdoll.step(lastDelta, {
2060
+ joints: targets,
2061
+ body: { x: body?.x ?? 0, z: body?.z ?? 0 },
2062
+ lift: clipLiftY,
2063
+ velocity: { x: velocity.x, z: velocity.z }
2064
+ });
2065
+ for (const name of RAGDOLL_JOINTS) {
2066
+ const at = out.joints[name];
2067
+ pivots[name].rotation.x = at.x;
2068
+ pivots[name].rotation.z = at.z;
2069
+ }
2070
+ lifted.rotation.x = out.body.x;
2071
+ lifted.rotation.z = out.body.z;
2072
+ lifted.position.set(out.offset.x, out.lift, out.offset.z);
2073
+ shadow?.position.set(out.offset.x, 0.005, out.offset.z);
2074
+ down = out.down;
2075
+ }
2076
+ const step = Math.max(0.001, lastDelta);
2077
+ const yaw = root.rotation.y + (root.parent?.rotation.y ?? 0);
2078
+ const motion = { lift: (lifted.position.y - lastLift) / step, yaw: (yaw - lastYaw) / step };
2079
+ lastLift = lifted.position.y;
2080
+ lastYaw = yaw;
2081
+ for (const piece2 of worn.values())
2082
+ piece2.tick?.(clock, lastDelta, motion);
378
2083
  if (shadow) {
379
- const air = Math.min(1, lifted.position.y / 0.5);
380
- shadow.scale.set(1 - air * 0.3, 0.02, 0.9 - air * 0.3);
2084
+ const air = Math.min(1, (lifted.position.y - legRaise) / 0.5);
2085
+ shadow.scale.set((1 - air * 0.3) * fit.stature * fit.girth, 0.02, (0.9 - air * 0.3) * fit.stature * fit.girth);
381
2086
  shadow.material.opacity = 0.4 - air * 0.18;
382
2087
  }
383
2088
  };
384
2089
  apply();
385
2090
  const redraw = () => {
386
- paintBody(canvas, color, face, skin);
2091
+ paintBody(canvas, color, face, skin, options.faceType);
387
2092
  texture.needsUpdate = true;
2093
+ anime2?.draw(face);
388
2094
  };
389
2095
  return {
390
2096
  object: root,
391
2097
  play(next) {
392
- if (next !== clip)
2098
+ if (next !== clip2)
393
2099
  seconds = 0;
394
- clip = next;
2100
+ clip2 = next;
395
2101
  },
396
2102
  emote(name, custom) {
397
2103
  const found = custom ?? emoteOf(name);
398
2104
  if (!found)
399
2105
  return;
400
2106
  const next = found.anim ?? found.clip;
401
- if (next !== clip)
2107
+ if (next !== clip2)
402
2108
  seconds = 0;
403
- clip = next;
2109
+ clip2 = next;
404
2110
  if (found.face !== face) {
405
2111
  face = found.face;
406
2112
  redraw();
@@ -413,6 +2119,14 @@ function createPlup(options = {}) {
413
2119
  bone(name) {
414
2120
  return name === "body" ? lifted : pivots[name];
415
2121
  },
2122
+ ragdoll(mode) {
2123
+ ragdollOf().set(mode);
2124
+ },
2125
+ push(x, y, z) {
2126
+ const local = new Vector32(x, y, z).applyQuaternion(root.getWorldQuaternion(turn).invert());
2127
+ ragdollOf().push(local.x, local.y, local.z);
2128
+ },
2129
+ isDown: () => down,
416
2130
  setFace(next) {
417
2131
  if (next === face)
418
2132
  return;
@@ -424,20 +2138,27 @@ function createPlup(options = {}) {
424
2138
  return;
425
2139
  color = next;
426
2140
  redraw();
427
- limbMaterial.uniforms.color = { value: new Color(shade(color, 0, 0.12)) };
428
- tipMaterial.uniforms.color = { value: new Color(shade(color, 0, 0.3)) };
2141
+ limbMaterial.uniforms.color = { value: new Color2(shade(color, 0, 0.12)) };
2142
+ tipMaterial.uniforms.color = { value: new Color2(shade(color, 0, 0.3)) };
429
2143
  },
2144
+ setWear,
430
2145
  update(delta) {
431
2146
  seconds += delta;
432
2147
  clock += delta;
2148
+ lastDelta = delta;
433
2149
  apply();
434
2150
  },
435
2151
  dispose() {
2152
+ setWear([]);
436
2153
  geometry.dispose();
437
2154
  limbGeometry.dispose();
2155
+ for (const arm of armGeometries)
2156
+ arm.dispose();
438
2157
  handGeometry.dispose();
439
2158
  footGeometry.dispose();
440
2159
  texture.dispose();
2160
+ anime2?.material.map?.dispose();
2161
+ anime2?.material.dispose();
441
2162
  bodyMaterial.dispose();
442
2163
  limbMaterial.dispose();
443
2164
  tipMaterial.dispose();
@@ -466,15 +2187,14 @@ function faceTexture(sheet, source, fill) {
466
2187
  }
467
2188
  context.drawImage(sheet, source.x, source.y, source.w, source.h, 0, 0, canvas.width, canvas.height);
468
2189
  }
469
- const texture = new CanvasTexture2(canvas);
470
- texture.magFilter = NearestFilter2;
471
- texture.minFilter = NearestFilter2;
472
- texture.colorSpace = SRGBColorSpace2;
2190
+ const texture = new CanvasTexture3(canvas);
2191
+ pixelArtFiltering(texture);
2192
+ texture.colorSpace = SRGBColorSpace3;
473
2193
  return texture;
474
2194
  }
475
- function plupHandle(look, stature) {
476
- const plup = createPlup({ color: look.bodyColor });
477
- plup.object.scale.setScalar(3.4 / 1.1 * stature);
2195
+ function plupHandle(look, bodyScale) {
2196
+ const plup = createPlup({ color: look.bodyColor, bodyScale });
2197
+ plup.object.scale.setScalar(3.4 / 1.1);
478
2198
  return {
479
2199
  object: plup.object,
480
2200
  play: plup.play,
@@ -487,20 +2207,20 @@ function plupHandle(look, stature) {
487
2207
  }
488
2208
  function createCharacter(rigId = "plup", look = { bodyColor: "#3d7bff" }, bodyScale) {
489
2209
  if (rigId === "plup")
490
- return plupHandle(look, clampBodyScale(bodyScale).stature);
2210
+ return plupHandle(look, bodyScale);
491
2211
  const rig = RIGS[rigId];
492
2212
  const body = clampBodyScale(bodyScale);
493
- const root = new Group2;
2213
+ const root = new Group3;
494
2214
  const joints = new Map;
495
2215
  const materials = [];
496
2216
  const geometries = [];
497
2217
  for (const bone of rig.bones) {
498
2218
  const box = scaleBone(bone, nativePartOf(bone.name), bone.parent ? nativePartOf(bone.parent) : null, body);
499
- const joint = new Group2;
2219
+ const joint = new Group3;
500
2220
  joint.position.set(box.joint[0], box.joint[1], box.joint[2]);
501
2221
  joints.set(bone.name, joint);
502
2222
  (bone.parent ? joints.get(bone.parent) : root)?.add(joint);
503
- const geometry = new BoxGeometry(box.size[0], box.size[1], box.size[2]);
2223
+ const geometry = new BoxGeometry2(box.size[0], box.size[1], box.size[2]);
504
2224
  geometries.push(geometry);
505
2225
  const color = bone.name === "Head" ? look.headColor ?? look.bodyColor : look.bodyColor;
506
2226
  const faces = BOX_FACES.map((face) => {
@@ -520,36 +2240,36 @@ function createCharacter(rigId = "plup", look = { bodyColor: "#3d7bff" }, bodySc
520
2240
  return new MeshStandardMaterial({ color, roughness: 0.8 });
521
2241
  });
522
2242
  materials.push(...faces);
523
- const mesh = new Mesh2(geometry, faces);
2243
+ const mesh = new Mesh3(geometry, faces);
524
2244
  mesh.position.set(box.center[0], box.center[1], box.center[2]);
525
2245
  joint.add(mesh);
526
2246
  }
527
- let clip = "idle";
2247
+ let clip2 = "idle";
528
2248
  let held = {};
529
2249
  let seconds = 0;
530
2250
  const apply = () => {
531
- const pose = resolvePose(rigId, mergePoses(sampleClip(clip, seconds), held));
2251
+ const pose = resolvePose(rigId, mergePoses(sampleClip(clip2, seconds), held));
532
2252
  for (const [name, joint] of joints) {
533
2253
  const rotation = pose.get(name);
534
2254
  joint.rotation.set(rotation?.x ?? 0, rotation?.y ?? 0, rotation?.z ?? 0);
535
2255
  }
536
- root.position.y = clipLift(clip, seconds) * body.stature;
2256
+ root.position.y = clipLift(clip2, seconds) * body.stature;
537
2257
  };
538
2258
  apply();
539
2259
  return {
540
2260
  object: root,
541
2261
  play(next) {
542
- if (next !== clip)
2262
+ if (next !== clip2)
543
2263
  seconds = 0;
544
- clip = next;
2264
+ clip2 = next;
545
2265
  },
546
2266
  emote(name) {
547
2267
  const found = emoteOf(name);
548
2268
  if (found) {
549
2269
  const next = found.anim ?? found.clip;
550
- if (next !== clip)
2270
+ if (next !== clip2)
551
2271
  seconds = 0;
552
- clip = next;
2272
+ clip2 = next;
553
2273
  }
554
2274
  return found;
555
2275
  },
@@ -577,5 +2297,6 @@ function createCharacter(rigId = "plup", look = { bodyColor: "#3d7bff" }, bodySc
577
2297
  }
578
2298
  export {
579
2299
  createPlup,
580
- createCharacter
2300
+ createCharacter,
2301
+ buildWear
581
2302
  };