@plupin/character 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,15 @@
2
2
  import { SphereGeometry } from "three";
3
3
  var BLOB_RADIUS = { x: 0.6, y: 0.56, z: 0.58 };
4
4
  var BLOB_HEIGHT = BLOB_RADIUS.y * (1 + 0.62 + (1 - 0.62) * 0.3);
5
- var ROUND = { shoulders: 1, waist: 1, hips: 1, bust: 0, muscle: 1, figure: 0 };
5
+ var ROUND = {
6
+ shoulders: 1,
7
+ waist: 1,
8
+ hips: 1,
9
+ bust: 0,
10
+ muscle: 1,
11
+ torsoHeight: 1,
12
+ figure: 0
13
+ };
6
14
  var bump = (at, centre, spread) => Math.exp(-(((at - centre) / spread) ** 2));
7
15
  var clamp01 = (v) => Math.max(0, Math.min(1, v));
8
16
  var smoothstep = (e0, e1, x) => {
@@ -57,9 +65,28 @@ var FIGURE_HEAD_BASE_SCALE = 0.46;
57
65
  var FIGURE_NECK_TOP_Y = 0.8;
58
66
  var FIGURE_SHOULDER_Y = 0.64;
59
67
  var FIGURE_HIP_Y = 0.17;
60
- function figureHeadMetrics(headSize = 0.78) {
68
+ function figureTorsoSpan(torsoHeight = 1) {
69
+ const h = Math.max(0.45, Math.min(1.15, torsoHeight));
70
+ const minY = FIGURE_TORSO_MIN_Y;
71
+ const maxY = minY + (FIGURE_TORSO_MAX_Y - FIGURE_TORSO_MIN_Y) * h;
72
+ const centerY = (minY + maxY) / 2;
73
+ const halfH = (maxY - minY) / 2;
74
+ return {
75
+ minY,
76
+ maxY,
77
+ centerY,
78
+ halfH,
79
+ neckTopY: minY + (FIGURE_NECK_TOP_Y - minY) * h,
80
+ shoulderY: minY + (FIGURE_SHOULDER_Y - minY) * h,
81
+ hipY: minY + (FIGURE_HIP_Y - minY) * h,
82
+ waistY: minY + (0.41 - minY) * h,
83
+ bustY: minY + (0.56 - minY) * h
84
+ };
85
+ }
86
+ function figureHeadMetrics(headSize = 0.78, torsoHeight = 1) {
87
+ const span = figureTorsoSpan(torsoHeight);
61
88
  const scale = FIGURE_HEAD_BASE_SCALE * headSize;
62
- const originY = FIGURE_NECK_TOP_Y - 0.03 * scale;
89
+ const originY = span.neckTopY - 0.03 * scale;
63
90
  return { scale, originY, centerY: originY + BLOB_SEAT * scale };
64
91
  }
65
92
  var smin = (a, b, k) => {
@@ -67,7 +94,9 @@ var smin = (a, b, k) => {
67
94
  return b * (1 - h) + a * h - k * h * (1 - h);
68
95
  };
69
96
  function figureTorsoPoint(y, phi, silhouette = ROUND) {
70
- const u = Math.max(-0.985, Math.min(0.985, (y - FIGURE_TORSO_CENTER_Y) / FIGURE_TORSO_HALF_H));
97
+ const span = figureTorsoSpan(silhouette.torsoHeight ?? 1);
98
+ const u = Math.max(-0.985, Math.min(0.985, (y - span.centerY) / span.halfH));
99
+ const compact = Math.min(1, 0.58 + 0.42 * (silhouette.torsoHeight ?? 1));
71
100
  const ux = Math.sin(phi);
72
101
  const uz = Math.cos(phi);
73
102
  const sh = silhouette.shoulders ?? 1;
@@ -99,13 +128,13 @@ function figureTorsoPoint(y, phi, silhouette = ROUND) {
99
128
  let rz = (shoulderW * shoulderRz + ribW * ribRz + waistW * waistRz + hipW * hipRz + 0.08 * 0.12) / wSum;
100
129
  rz = rz * (1 - neckT) + neckRz * neckT;
101
130
  rz *= pelvisRound;
102
- let x = ux * rx;
103
- let z = uz * rz;
131
+ let x = ux * rx * compact;
132
+ let z = uz * rz * compact;
104
133
  if (bust > 0.01 && uz > -0.1) {
105
- const domeR = 0.095 + Math.min(1.4, bust) * 0.038;
106
- const cx = 0.082 + Math.min(1.4, bust) * 0.01;
107
- const cy = FIGURE_TORSO_CENTER_Y + 0.34 * FIGURE_TORSO_HALF_H;
108
- const cz = 0.075 + Math.min(1.4, bust) * 0.024;
134
+ const domeR = (0.095 + Math.min(1.4, bust) * 0.038) * compact;
135
+ const cx = (0.082 + Math.min(1.4, bust) * 0.01) * compact;
136
+ const cy = span.centerY + 0.34 * span.halfH;
137
+ const cz = (0.075 + Math.min(1.4, bust) * 0.024) * compact;
109
138
  const bx = Math.abs(x) - cx;
110
139
  const by = (y - cy) * 1.05;
111
140
  const d2 = bx * bx + by * by;
@@ -177,13 +206,14 @@ function figureHeadRadiusAt(y) {
177
206
  return Math.sqrt(Math.max(0.001, 1 - unit * unit)) * cheek * chinTaper * 0.54;
178
207
  }
179
208
  function buildFigureTorsoGeometry(silhouette = ROUND) {
209
+ const span = figureTorsoSpan(silhouette.torsoHeight ?? 1);
180
210
  const geometry = new SphereGeometry(1, 56, 44);
181
211
  const position = geometry.attributes.position;
182
212
  for (let i = 0;i < position.count; i += 1) {
183
213
  const ux = position.getX(i);
184
214
  const uy = position.getY(i);
185
215
  const uz = position.getZ(i);
186
- const y = FIGURE_TORSO_CENTER_Y + uy * FIGURE_TORSO_HALF_H;
216
+ const y = span.centerY + uy * span.halfH;
187
217
  const phi = Math.atan2(ux, uz);
188
218
  const pt = figureTorsoPoint(y, phi, silhouette);
189
219
  position.setXYZ(i, pt.x, y, pt.z);
@@ -193,4 +223,4 @@ function buildFigureTorsoGeometry(silhouette = ROUND) {
193
223
  return geometry;
194
224
  }
195
225
 
196
- export { BLOB_RADIUS, BLOB_HEIGHT, ROUND, silhouetteAt, BLOB_SEAT, blobRadiusAt, buildBlobGeometry, FIGURE_TORSO_MIN_Y, FIGURE_TORSO_MAX_Y, FIGURE_TORSO_CENTER_Y, FIGURE_TORSO_HALF_H, FIGURE_HEAD_BASE_SCALE, FIGURE_NECK_TOP_Y, FIGURE_SHOULDER_Y, FIGURE_HIP_Y, figureHeadMetrics, figureTorsoPoint, figureTorsoRadiusAt, buildFigureHeadGeometry, figureHeadRadiusAt, buildFigureTorsoGeometry };
226
+ export { BLOB_RADIUS, BLOB_HEIGHT, ROUND, silhouetteAt, BLOB_SEAT, blobRadiusAt, buildBlobGeometry, FIGURE_TORSO_MIN_Y, FIGURE_TORSO_MAX_Y, FIGURE_TORSO_CENTER_Y, FIGURE_TORSO_HALF_H, FIGURE_HEAD_BASE_SCALE, FIGURE_NECK_TOP_Y, FIGURE_SHOULDER_Y, FIGURE_HIP_Y, figureTorsoSpan, figureHeadMetrics, figureTorsoPoint, figureTorsoRadiusAt, buildFigureHeadGeometry, figureHeadRadiusAt, buildFigureTorsoGeometry };
@@ -0,0 +1,27 @@
1
+ import type { JointFrame } from "./ik-skeleton";
2
+ /**
3
+ * High-detail 18-joint 3D IK Viral Dance Choreography Engine (`@plupin/character`).
4
+ *
5
+ * Uses the exact same 18-joint humanoid skeleton, 2-bone analytic knee IK, smootherstep timing,
6
+ * snap-and-drift beat holds, and `sampleLead` overlap/follow-through architecture proven in
7
+ * `content/kartun/tools/klip_tulis.mjs` (Passinho do Jamal), running continuously at full framerate.
8
+ *
9
+ * Every dance is an 8-beat musical phrase with real footwork, grounded foot planting, pelvis weight
10
+ * shift, torso twist, head lag, and accurate hand targets:
11
+ * - `brazil-funk`: Exact Passinho do Jamal 8-beat phrase (cross R/L, knee pop-in & heel-up,
12
+ * spread hop, deep squat fists low, squat bounce, hand-to-mouth "oh!").
13
+ * - `pacu-jalur`: Authentic "Aura Farming" (Rayyan Arkan Dikha, Kuansing Riau) — boat-wave knee
14
+ * balance, chest hand-roll ("gulung tangan"), wide right & left aura sweeps, alternating wave push.
15
+ * - `velocity`: TikTok Velocity / Jedag Jedug — silky slow-motion glide contrasting with razor-sharp
16
+ * beat-drop freezes & moving holds.
17
+ * - `griddy`: Authentic Griddy — alternating heel-dig taps (toe up!) + low-back arm swing curving up
18
+ * into "B / eye goggles" directly in front of the eyes.
19
+ * - `floss`: Authentic Backpack Kid Floss — wide planted stance, crisp opposite-phase pelvis snaps,
20
+ * and 4-beat front-hip / back-hip parallel arm passes.
21
+ * - `caramel`: Authentic Caramelldansen / Idol Bounce — wide bouncy hip sway, alternating heel-pops,
22
+ * raised elbows with double-time flapping cat/bunny-ear hands & joyful hop.
23
+ */
24
+ export type IkDanceName = "brazil-funk" | "pacu-jalur" | "velocity" | "griddy" | "floss" | "caramel";
25
+ export declare function isIkDanceName(name: unknown): name is IkDanceName;
26
+ /** Sample a smooth 18-joint humanoid frame for any of the 6 viral dances at `seconds`. */
27
+ export declare function sampleIkDance(name: IkDanceName, seconds: number): JointFrame;
@@ -0,0 +1,98 @@
1
+ import { Quaternion, Vector3 } from "three";
2
+ import type { BakedClip } from "./clip-bake";
3
+ /**
4
+ * Unified 18-joint humanoid skeleton & Two-Bone Analytic Inverse Kinematics solver for `@plupin/character`.
5
+ *
6
+ * Plays BOTH:
7
+ * - Any Mixamo / Quaternius / CMU BVH mocap clip baked via `content/kartun/tools/klip_bake.mjs` (`BakedClip`)
8
+ * - Our 60fps 18-joint IK viral dance engine (`dance-clips.ts`)
9
+ *
10
+ * Solves exact foot-planted 2-bone knee IK, 2-bone arm IK with bust/torso clearance, pelvis/chest/head
11
+ * basis orientations, and spring follow-through so animations look fluid and grounded — never stiff FK sticks.
12
+ */
13
+ export declare const SKELETON_JOINTS: readonly ["pelvis", "spine", "neck", "head", "shoulder_l", "elbow_l", "wrist_l", "shoulder_r", "elbow_r", "wrist_r", "hip_l", "knee_l", "ankle_l", "toe_l", "hip_r", "knee_r", "ankle_r", "toe_r"];
14
+ export type JointName = (typeof SKELETON_JOINTS)[number];
15
+ /** World/character-space 3D position for every joint (pelvis ~1.0m at rest, floor y = 0, facing +Z). */
16
+ export type JointFrame = Record<JointName, Vector3>;
17
+ export interface RetargetMetrics {
18
+ /** Character pelvis/hip rest height above y = 0. */
19
+ hipHeight: number;
20
+ /** Half-distance between left and right hip pivots. */
21
+ hipHalfWidth: number;
22
+ /** Local hip anchor Y inside `lifted`. */
23
+ hipLocalY: number;
24
+ /** Half-distance between left and right shoulder pivots. */
25
+ shoulderHalfWidth: number;
26
+ /** Local shoulder anchor Y inside `lifted`. */
27
+ shoulderLocalY: number;
28
+ /** Total arm length (upper + lower). */
29
+ armLength: number;
30
+ /** Total leg length (thigh + shin). */
31
+ legLength: number;
32
+ /** Approximate torso clearance radius (x, z) so forearms/wrists never clip into bust/chest. */
33
+ torsoRadiusX: number;
34
+ torsoRadiusZ: number;
35
+ /** Local torso vertical center Y for clearance push-out. */
36
+ torsoCenterY: number;
37
+ /** True for classic round Plup (needs wider out-of-body push). */
38
+ isClassic: boolean;
39
+ }
40
+ export interface RetargetedPose {
41
+ /** Offset of `lifted` relative to character root (includes grounded pelvis drop + lateral hip shift). */
42
+ rootPos: Vector3;
43
+ /** Torso/pelvis world-local orientation. */
44
+ torsoQ: Quaternion;
45
+ /** Head local orientation relative to torso. */
46
+ headQ: Quaternion;
47
+ /** Arms in `lifted`-local space: `[shoulder, elbow, wrist]`. */
48
+ armL: [Vector3, Vector3, Vector3];
49
+ armR: [Vector3, Vector3, Vector3];
50
+ /** Legs in `lifted`-local space: `[hip, knee, ankle]` + foot orientation relative to shin. */
51
+ legL: {
52
+ pts: [Vector3, Vector3, Vector3];
53
+ footPitch: number;
54
+ footYaw: number;
55
+ };
56
+ legR: {
57
+ pts: [Vector3, Vector3, Vector3];
58
+ footPitch: number;
59
+ footYaw: number;
60
+ };
61
+ /** Elastic squash hint derived from vertical pelvis velocity. */
62
+ squash: number;
63
+ }
64
+ /**
65
+ * Exact analytic Two-Bone Inverse Kinematics solver (law of cosines):
66
+ * Given root joint `a`, end-effector target `c`, segment lengths `len1` & `len2`, and bend hint `pole`,
67
+ * returns the exact mid-joint (`elbow` or `knee`) position `b` and clamped reachable target `cOut`.
68
+ */
69
+ export declare function solveTwoBoneIK(a: Vector3, target: Vector3, len1: number, len2: number, poleDir: Vector3): {
70
+ mid: Vector3;
71
+ end: Vector3;
72
+ };
73
+ /**
74
+ * Sample an 18-joint `BakedClip` (Mixamo / Quaternius / CMU JSON from `klip_bake.mjs`) at time `seconds`
75
+ * using smooth Catmull-Rom cubic interpolation across frames.
76
+ */
77
+ export declare function sampleBakedJoints(clip: BakedClip, seconds: number): JointFrame;
78
+ /**
79
+ * Retarget a normalised 18-joint humanoid frame (`pelvis` ~1.0m at rest, floor `y = 0`, facing `+Z`)
80
+ * onto a Plup character (stylized anime Figure or Classic Plup) using exact 2-bone IK for both legs
81
+ * and arms, with floor-grounded foot planting and bust/torso clearance.
82
+ */
83
+ export declare function retarget18JointPose(F: JointFrame, m: RetargetMetrics): RetargetedPose;
84
+ /**
85
+ * Aim a two-segment articulated limb (`upperPivot` -> `lowerPivot` -> `tip`) directly through
86
+ * 3 local points `a -> b -> c` using exact quaternions (zero gimbal lock, zero joint drift!).
87
+ */
88
+ export declare function aimTwoBoneLimb(upperPivot: {
89
+ position: Vector3;
90
+ quaternion: Quaternion;
91
+ }, lowerPivot: {
92
+ position: Vector3;
93
+ quaternion: Quaternion;
94
+ }, a: Vector3, b: Vector3, c: Vector3): void;
95
+ /** Apply foot pitch/yaw cleanly to a shoe mesh inside a shin pivot. */
96
+ export declare function orientFoot(foot: {
97
+ quaternion: Quaternion;
98
+ }, pitch: number, yaw: number): void;
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  RAGDOLL_JOINTS,
5
5
  createRagdoll,
6
6
  emoteOf
7
- } from "./chunk-rqenm9tn.js";
7
+ } from "./chunk-s083mv4f.js";
8
8
  import {
9
9
  WEARABLES,
10
10
  WEAR_KEYS,
@@ -50,7 +50,7 @@ import {
50
50
  validateClassicTemplate,
51
51
  validateVariantSheet,
52
52
  visualEnvelope
53
- } from "./chunk-ew73g2v7.js";
53
+ } from "./chunk-phwn2cn7.js";
54
54
  import {
55
55
  AUTHORED_BONES,
56
56
  AUTHORED_CLIPS,
@@ -64,7 +64,7 @@ import {
64
64
  mergePoses,
65
65
  resolvePose,
66
66
  sampleClip
67
- } from "./chunk-7ry0n8cw.js";
67
+ } from "./chunk-wryfx2sg.js";
68
68
  import {
69
69
  FACE_STAMP_PALETTE,
70
70
  NAMED_FACES,
package/dist/listing.js CHANGED
@@ -7,10 +7,10 @@ import {
7
7
  NATIVE_SHEET_CAPS,
8
8
  NATIVE_TORSO,
9
9
  clampBodyScale
10
- } from "./chunk-ew73g2v7.js";
10
+ } from "./chunk-phwn2cn7.js";
11
11
  import {
12
12
  CLIPS
13
- } from "./chunk-7ry0n8cw.js";
13
+ } from "./chunk-wryfx2sg.js";
14
14
  import {
15
15
  FACE_STAMP_PALETTE,
16
16
  NAMED_FACES,
package/dist/plup3d.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Group, type Object3D, ShaderMaterial, type Texture } from "three";
1
+ import { Group, type Object3D, ShaderMaterial, type Texture, Vector2, Vector3 } from "three";
2
+ import type { BakedClip } from "./clip-bake";
2
3
  import { type Emote } from "./emote";
3
4
  import { type NamedFace } from "./faces";
4
5
  import { type ClipRef, type Pose } from "./pose";
@@ -24,6 +25,11 @@ export interface ToonOptions {
24
25
  back?: string;
25
26
  repeat?: readonly [number, number];
26
27
  sheen?: number;
28
+ /** Shared soft-body jiggle uniform (torso + fitted clothes deform in lockstep with zero clipping). */
29
+ jiggle?: {
30
+ value: Vector3;
31
+ band: Vector2;
32
+ };
27
33
  anime?: {
28
34
  center: readonly [number, number, number];
29
35
  ring?: number;
@@ -57,6 +63,8 @@ export interface PlupOptions {
57
63
  export interface PlupHandle {
58
64
  object: Group;
59
65
  play: (clip: ClipRef) => void;
66
+ /** Play any 18-joint Mixamo / Quaternius / CMU mocap JSON baked via `klip_bake.mjs` using full 2-bone IK. Pass `null` to stop. */
67
+ playBaked: (clip: BakedClip | null) => void;
60
68
  emote: (name: string, custom?: Emote) => Emote | undefined;
61
69
  pose: (pose: Pose) => void;
62
70
  bone: (name: string) => Object3D | undefined;
package/dist/pose.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  mergePoses,
7
7
  resolvePose,
8
8
  sampleClip
9
- } from "./chunk-7ry0n8cw.js";
9
+ } from "./chunk-wryfx2sg.js";
10
10
  export {
11
11
  sampleClip,
12
12
  resolvePose,
@@ -123,13 +123,13 @@ export declare const PLUP_BODY_LIMITS: {
123
123
  readonly min: 0;
124
124
  readonly max: 1.4;
125
125
  };
126
- /** Leg length: 1 is Plup's stubs, 3 is a long-legged runway walker. */
126
+ /** Leg length: 0.65 is tiny chibi, 1 is Plup's stubs, 3 is a long-legged runway walker. */
127
127
  readonly legLength: {
128
- readonly min: 1;
128
+ readonly min: 0.65;
129
129
  readonly max: 3;
130
130
  };
131
131
  readonly armLength: {
132
- readonly min: 0.8;
132
+ readonly min: 0.55;
133
133
  readonly max: 1.8;
134
134
  };
135
135
  /** Arm, shoulder, chest and leg bulk (muscular / kekar build). */
@@ -142,10 +142,15 @@ export declare const PLUP_BODY_LIMITS: {
142
142
  readonly min: 0.2;
143
143
  readonly max: 0.55;
144
144
  };
145
- /** Head size multiplier: lower (0.55–0.8) makes the sculpted body stand out like anime/Roblox; 1+ is chibi. */
145
+ /** Head size multiplier: lower (0.55–0.8) makes the sculpted body stand out like anime/Roblox; 1.25–1.45 is chibi. */
146
146
  readonly headSize: {
147
147
  readonly min: 0.55;
148
- readonly max: 1.25;
148
+ readonly max: 1.45;
149
+ };
150
+ /** Torso height multiplier on stylized figure mode (0.45 = compact cute chibi body, 1.0 = full runway anime). */
151
+ readonly torsoHeight: {
152
+ readonly min: 0.45;
153
+ readonly max: 1.15;
149
154
  };
150
155
  /** 0 = classic round Plup blob, 1 = stylized anime/chibi figure (round head + neck + sculpted torso). */
151
156
  readonly figure: {
@@ -163,6 +168,7 @@ export interface PlupBody {
163
168
  muscle: number;
164
169
  shoulderHeight: number;
165
170
  headSize: number;
171
+ torsoHeight: number;
166
172
  figure: number;
167
173
  }
168
174
  export declare const CANONICAL_PLUP_BODY: PlupBody;
package/dist/three.d.ts CHANGED
@@ -3,9 +3,12 @@ import { type Emote } from "./emote";
3
3
  export { ANIME_FACE_SIZE, ANIME_FACE_UV, drawAnimeFace } from "./anime-face";
4
4
  export { blobRadiusAt, buildBlobGeometry, buildFigureHeadGeometry, buildFigureTorsoGeometry, figureTorsoPoint, } from "./blob";
5
5
  export { BODY_PRESETS } from "./body-presets";
6
+ export type { BakedClip } from "./clip-bake";
6
7
  export { AUTHORED_CLIPS } from "./clips";
8
+ export { type IkDanceName, isIkDanceName, sampleIkDance } from "./dance-clips";
7
9
  export { buildWear } from "./dress";
8
10
  export { EMOTES } from "./emote";
11
+ export { aimTwoBoneLimb, type JointFrame, type JointName, orientFoot, type RetargetedPose, type RetargetMetrics, retarget18JointPose, SKELETON_JOINTS, sampleBakedJoints, solveTwoBoneIK, } from "./ik-skeleton";
9
12
  export { isHighResFace } from "./skin-map";
10
13
  export type { WearKit, WornPiece } from "./wear3d";
11
14
  export { hairVolume, isHairKey, isWearKey, WEARABLES, wearSlotOf } from "./wearables";