@plupin/character 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/anime-face.d.ts +42 -0
- package/dist/anime-face.js +14 -0
- package/dist/blob.d.ts +32 -0
- package/dist/blob.js +18 -0
- package/dist/body-presets.d.ts +85 -0
- package/dist/canvas.d.ts +79 -0
- package/dist/canvas.js +315 -0
- package/dist/chunk-09c5tps4.js +337 -0
- package/dist/chunk-60p135hw.js +103 -0
- package/dist/chunk-aa5nstet.js +39 -0
- package/dist/chunk-dpb0rnw9.js +37 -0
- package/dist/chunk-g1c0wdcj.js +825 -0
- package/dist/chunk-kber92gm.js +415 -0
- package/dist/chunk-sa2r1cxz.js +342 -0
- package/dist/chunk-yd5zzkkg.js +313 -0
- package/dist/clip-bake.d.ts +48 -0
- package/dist/clip-bake.js +132 -0
- package/dist/clips.d.ts +40 -0
- package/dist/dress.d.ts +4 -0
- package/dist/emote.d.ts +25 -0
- package/dist/faces.d.ts +10 -0
- package/dist/faces.js +12 -0
- package/dist/gaze.d.ts +81 -0
- package/dist/gaze.js +113 -0
- package/dist/hair3d.d.ts +3 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +176 -0
- package/dist/listing.d.ts +195 -0
- package/dist/listing.js +763 -0
- package/dist/named-faces.d.ts +22 -0
- package/dist/platform-body-data.d.ts +9 -0
- package/dist/platform-body.d.ts +91 -0
- package/dist/plup2d.d.ts +29 -0
- package/dist/plup3d.d.ts +121 -0
- package/dist/png.d.ts +78 -0
- package/dist/pose.d.ts +49 -0
- package/dist/pose.js +18 -0
- package/dist/proportions.d.ts +31 -0
- package/dist/ragdoll.d.ts +51 -0
- package/dist/resolution.d.ts +21 -0
- package/dist/rig.d.ts +29 -0
- package/dist/skin-map.d.ts +155 -0
- package/dist/skin-map.js +55 -0
- package/dist/skin-native.d.ts +301 -0
- package/dist/skin.d.ts +35 -0
- package/dist/texture.d.ts +8 -0
- package/dist/three.d.ts +25 -0
- package/dist/three.js +2302 -0
- package/dist/wear3d.d.ts +99 -0
- package/dist/wearables.d.ts +203 -0
- package/dist/wearables.js +26 -0
- package/package.json +78 -4
- package/README.md +0 -3
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// src/clip-bake.ts
|
|
2
|
+
var BAKED_JOINTS = [
|
|
3
|
+
"pelvis",
|
|
4
|
+
"spine",
|
|
5
|
+
"neck",
|
|
6
|
+
"head",
|
|
7
|
+
"shoulder_l",
|
|
8
|
+
"elbow_l",
|
|
9
|
+
"wrist_l",
|
|
10
|
+
"shoulder_r",
|
|
11
|
+
"elbow_r",
|
|
12
|
+
"wrist_r",
|
|
13
|
+
"hip_l",
|
|
14
|
+
"knee_l",
|
|
15
|
+
"ankle_l",
|
|
16
|
+
"toe_l",
|
|
17
|
+
"hip_r",
|
|
18
|
+
"knee_r",
|
|
19
|
+
"ankle_r",
|
|
20
|
+
"toe_r"
|
|
21
|
+
];
|
|
22
|
+
var BAKE_BONES = [
|
|
23
|
+
"armL",
|
|
24
|
+
"armR",
|
|
25
|
+
"legL",
|
|
26
|
+
"legR",
|
|
27
|
+
"torso",
|
|
28
|
+
"head"
|
|
29
|
+
];
|
|
30
|
+
var STUDS_PER_METRE = 5 / 1.75;
|
|
31
|
+
var sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
32
|
+
var unit = (v) => {
|
|
33
|
+
const length = Math.hypot(v[0], v[1], v[2]) || 1;
|
|
34
|
+
return [v[0] / length, v[1] / length, v[2] / length];
|
|
35
|
+
};
|
|
36
|
+
var wrap = (angle) => Math.atan2(Math.sin(angle), Math.cos(angle));
|
|
37
|
+
var unwrap = (angle, near) => near + wrap(angle - near);
|
|
38
|
+
var MAX_TURN = 3.15;
|
|
39
|
+
function limbEuler(d, previous) {
|
|
40
|
+
const r = Math.hypot(d[1], d[2]);
|
|
41
|
+
if (r < 0.0001)
|
|
42
|
+
return { x: previous?.x ?? 0, z: Math.sign(d[0]) * (Math.PI / 2) };
|
|
43
|
+
const below = { x: Math.atan2(-d[2], -d[1]), z: Math.atan2(d[0], r) };
|
|
44
|
+
const above = { x: Math.atan2(d[2], d[1]), z: Math.atan2(d[0], -r) };
|
|
45
|
+
if (!previous)
|
|
46
|
+
return d[1] <= 0 ? below : above;
|
|
47
|
+
const cost = (e) => Math.abs(wrap(e.x - previous.x)) + Math.abs(wrap(e.z - previous.z));
|
|
48
|
+
const near = (e) => ({ x: unwrap(e.x, previous.x), z: unwrap(e.z, previous.z) });
|
|
49
|
+
const inRange = (e) => Math.abs(e.x) <= MAX_TURN && Math.abs(e.z) <= MAX_TURN;
|
|
50
|
+
const ranked = [below, above].sort((a, b) => cost(a) - cost(b)).map(near);
|
|
51
|
+
return ranked.find(inRange) ?? { x: wrap(ranked[0].x), z: wrap(ranked[0].z) };
|
|
52
|
+
}
|
|
53
|
+
function limbDirection(e) {
|
|
54
|
+
return [Math.sin(e.z), -Math.cos(e.z) * Math.cos(e.x), -Math.cos(e.z) * Math.sin(e.x)];
|
|
55
|
+
}
|
|
56
|
+
function uprightEuler(d) {
|
|
57
|
+
return { z: -Math.asin(Math.max(-1, Math.min(1, d[0]))), x: Math.atan2(d[2], d[1]) };
|
|
58
|
+
}
|
|
59
|
+
var round = (value) => Math.round(value * 100) / 100;
|
|
60
|
+
|
|
61
|
+
class BakeError extends Error {
|
|
62
|
+
}
|
|
63
|
+
function bakeToCustomClip(source, options = {}) {
|
|
64
|
+
const joints = source.sendi;
|
|
65
|
+
const index = (name) => {
|
|
66
|
+
const found = joints.indexOf(name);
|
|
67
|
+
if (found < 0)
|
|
68
|
+
throw new BakeError(`The clip has no joint "${name}"; a baked clip carries ${BAKED_JOINTS.join(", ")}.`);
|
|
69
|
+
return found;
|
|
70
|
+
};
|
|
71
|
+
const stride = joints.length * 3;
|
|
72
|
+
if (!source.fps || source.data.length === 0 || source.data.length % stride !== 0)
|
|
73
|
+
throw new BakeError("The clip is empty or its data does not divide into whole frames.");
|
|
74
|
+
const sourceFrames = source.data.length / stride;
|
|
75
|
+
const at = (frame, name) => {
|
|
76
|
+
const base = frame * stride + index(name) * 3;
|
|
77
|
+
return [source.data[base] ?? 0, source.data[base + 1] ?? 0, source.data[base + 2] ?? 0];
|
|
78
|
+
};
|
|
79
|
+
const lerp = (a, b, t) => [
|
|
80
|
+
a[0] + (b[0] - a[0]) * t,
|
|
81
|
+
a[1] + (b[1] - a[1]) * t,
|
|
82
|
+
a[2] + (b[2] - a[2]) * t
|
|
83
|
+
];
|
|
84
|
+
const joint = (time, name) => {
|
|
85
|
+
const position = Math.min(time * source.fps, sourceFrames - 1);
|
|
86
|
+
const lo = Math.floor(position);
|
|
87
|
+
return lerp(at(lo, name), at(Math.min(lo + 1, sourceFrames - 1), name), position - lo);
|
|
88
|
+
};
|
|
89
|
+
const fps = Math.min(Math.round(options.fps ?? 20), Math.round(source.fps));
|
|
90
|
+
const seconds = Math.min(source.durasi || sourceFrames / source.fps, options.maxSeconds ?? 8);
|
|
91
|
+
const count = Math.max(1, Math.floor(seconds * fps));
|
|
92
|
+
const sideOf = (a, b) => at(0, a)[0] >= at(0, b)[0] ? [a, b] : [b, a];
|
|
93
|
+
const [shoulderPlus, shoulderMinus] = sideOf("shoulder_l", "shoulder_r");
|
|
94
|
+
const wristOf = (shoulder) => shoulder.replace("shoulder", "wrist");
|
|
95
|
+
const hipOf = (hip) => hip.replace("hip", "ankle");
|
|
96
|
+
const [hipPlus, hipMinus] = sideOf("hip_l", "hip_r");
|
|
97
|
+
const limbs = [
|
|
98
|
+
[shoulderMinus, wristOf(shoulderMinus)],
|
|
99
|
+
[shoulderPlus, wristOf(shoulderPlus)],
|
|
100
|
+
[hipMinus, hipOf(hipMinus)],
|
|
101
|
+
[hipPlus, hipOf(hipPlus)]
|
|
102
|
+
];
|
|
103
|
+
const restPelvis = at(0, "pelvis")[1];
|
|
104
|
+
const previous = [];
|
|
105
|
+
const frames = [];
|
|
106
|
+
for (let step = 0;step < count; step += 1) {
|
|
107
|
+
const time = step / fps;
|
|
108
|
+
const row = [];
|
|
109
|
+
limbs.forEach(([from, to], slot) => {
|
|
110
|
+
const d = unit(sub(joint(time, to), joint(time, from)));
|
|
111
|
+
const e = limbEuler(d, previous[slot]);
|
|
112
|
+
previous[slot] = e;
|
|
113
|
+
row.push(round(e.x), 0, round(e.z));
|
|
114
|
+
});
|
|
115
|
+
const spine = uprightEuler(unit(sub(joint(time, "neck"), joint(time, "pelvis"))));
|
|
116
|
+
row.push(round(spine.x), 0, round(spine.z));
|
|
117
|
+
const head = uprightEuler(unit(sub(joint(time, "head"), joint(time, "neck"))));
|
|
118
|
+
row.push(round(head.x - spine.x), 0, round(head.z - spine.z));
|
|
119
|
+
row.push(round(Math.max(0, (joint(time, "pelvis")[1] - restPelvis) * STUDS_PER_METRE)));
|
|
120
|
+
frames.push(row);
|
|
121
|
+
}
|
|
122
|
+
return { fps, loop: source.loop === true, bones: [...BAKE_BONES], frames };
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
uprightEuler,
|
|
126
|
+
limbEuler,
|
|
127
|
+
limbDirection,
|
|
128
|
+
bakeToCustomClip,
|
|
129
|
+
BakeError,
|
|
130
|
+
BAKE_BONES,
|
|
131
|
+
BAKED_JOINTS
|
|
132
|
+
};
|
package/dist/clips.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CustomClip } from "./pose";
|
|
2
|
+
import type { CanonicalBone } from "./rig";
|
|
3
|
+
/**
|
|
4
|
+
* The hand-keyed clips: one authored pose at a time, expanded into the same keyframe format a creator
|
|
5
|
+
* ships (`CustomClip`), so the built-in vocabulary and an uploaded animation are one shape. The rig
|
|
6
|
+
* has six bones, and every frame lists them in `AUTHORED_BONES` order, then one lift in studs.
|
|
7
|
+
*
|
|
8
|
+
* A named clip in `CLIPS` is this data sampled at `t`; an emote may name it or ship its own `anim`.
|
|
9
|
+
* Nothing here touches three.js, a DOM or the network, and every number stays inside `ANIM_CAPS`
|
|
10
|
+
* (`listing.ts`) so a creator can copy any of these into a listing unchanged.
|
|
11
|
+
*
|
|
12
|
+
* Angles follow the rig's euler order (x, y, z):
|
|
13
|
+
* - `z` swings a limb out to the side; for arms `armR` is positive and `armL` negative, and about
|
|
14
|
+
* 2.6 rad is overhead.
|
|
15
|
+
* - `x` swings a limb forward (negative) or back (positive); on the torso and head it pitches the
|
|
16
|
+
* body forward (positive) or back.
|
|
17
|
+
* - `y` turns the head left or right.
|
|
18
|
+
* - `lift` raises the whole character in studs. It never goes below 0: the rig has no knees, so a
|
|
19
|
+
* negative lift would push the feet through the floor.
|
|
20
|
+
*/
|
|
21
|
+
export declare const AUTHORED_BONES: readonly CanonicalBone[];
|
|
22
|
+
/** Every clip keyed by hand: the vocabulary an emote or a creator may name. */
|
|
23
|
+
export declare const AUTHORED_CLIP_NAMES: readonly ["recoil", "flail", "topple", "collapse", "sneak", "cheer", "laugh", "pose", "rage", "sob", "nod"];
|
|
24
|
+
export type AuthoredClipName = (typeof AUTHORED_CLIP_NAMES)[number];
|
|
25
|
+
/**
|
|
26
|
+
* The keyed library. Each entry is a motion a viewer can name from the pose alone:
|
|
27
|
+
*
|
|
28
|
+
* - `recoil` snaps the body back with both arms thrown up, then settles: a fright or a flinch.
|
|
29
|
+
* - `flail` is airborne, arms windmilling and legs kicking, held up by `lift`.
|
|
30
|
+
* - `topple` tips over sideways and stays down.
|
|
31
|
+
* - `collapse` buckles at the knees and folds forward until it is still.
|
|
32
|
+
* - `sneak` creeps forward, low, hands up, head scanning left and right.
|
|
33
|
+
* - `cheer` throws both arms overhead and hops.
|
|
34
|
+
* - `laugh` folds forward and shakes, arms hugged across the belly.
|
|
35
|
+
* - `pose` puts a hand on the hip and cocks its head.
|
|
36
|
+
* - `rage` stomps and shakes with the arms clenched low.
|
|
37
|
+
* - `sob` brings both hands to the face while the shoulders heave.
|
|
38
|
+
* - `nod` is a slow, deliberate nod: the quiet yes.
|
|
39
|
+
*/
|
|
40
|
+
export declare const AUTHORED_CLIPS: Readonly<Record<AuthoredClipName, CustomClip>>;
|
package/dist/dress.d.ts
ADDED
package/dist/emote.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { NamedFace } from "./faces";
|
|
2
|
+
import type { ClipName, CustomClip } from "./pose";
|
|
3
|
+
/**
|
|
4
|
+
* An emote is a name, a face and a clip the rig plays. Every clip here is an authored motion: the six
|
|
5
|
+
* procedural loops plus the keyframe library in `clips.ts` (`recoil`, `sneak`, `collapse`, ...), so a
|
|
6
|
+
* label like "Tewas" performs a collapse instead of borrowing idle. `sigmaPrice` 0 is free for
|
|
7
|
+
* everyone; anything else is bought in the shop (wardrobe), and the catalogue row has the same id. A
|
|
8
|
+
* game plays the face and the clip; whether a player may is the platform's to say.
|
|
9
|
+
*/
|
|
10
|
+
export interface Emote {
|
|
11
|
+
/** The catalogue id, also what a game passes: `emote-ngakak`. */
|
|
12
|
+
id: string;
|
|
13
|
+
/** What a screen reader says, and the name in the shop. */
|
|
14
|
+
label: string;
|
|
15
|
+
/** The kaomoji that rises over the character. Pixel-font safe. */
|
|
16
|
+
glyph: string;
|
|
17
|
+
face: NamedFace;
|
|
18
|
+
clip: ClipName;
|
|
19
|
+
/** Keyframes that replace `clip` when the emote ships its own animation; `clip` stays as the fallback. */
|
|
20
|
+
anim?: CustomClip;
|
|
21
|
+
sigmaPrice: number;
|
|
22
|
+
}
|
|
23
|
+
export declare const EMOTES: readonly Emote[];
|
|
24
|
+
/** One emote by id (`emote-ngakak`) or by the short name (`ngakak`); undefined for an unknown name. */
|
|
25
|
+
export declare function emoteOf(name: string): Emote | undefined;
|
package/dist/faces.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NAMED_FACE_STAMPS, type NamedFace } from "./named-faces";
|
|
2
|
+
/**
|
|
3
|
+
* The faces a character can pull, by the names the content films use (kartun/kit.js), so an emote
|
|
4
|
+
* is the same face in a video, in the app and in a game. Each is an 8 x 4 pixel stamp; `.` is
|
|
5
|
+
* transparent and every other key is a colour of `FACE_STAMP_PALETTE`.
|
|
6
|
+
*/
|
|
7
|
+
export { NAMED_FACE_STAMPS, type NamedFace };
|
|
8
|
+
export declare const NAMED_FACES: NamedFace[];
|
|
9
|
+
export declare const FACE_STAMP_PALETTE: Readonly<Record<string, string>>;
|
|
10
|
+
export declare function isNamedFace(name: string): name is NamedFace;
|
package/dist/faces.js
ADDED
package/dist/gaze.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Damped spring step (semi-implicit Euler), shared by Character's squash, sway and gaze springs.
|
|
3
|
+
* Returns the new [value, velocity].
|
|
4
|
+
*/
|
|
5
|
+
/** One step of a damped spring, shared by the gaze and the body. */
|
|
6
|
+
export declare function spring(value: number, velocity: number, target: number, stiffness: number, damping: number, dt: number): readonly [number, number];
|
|
7
|
+
/**
|
|
8
|
+
* Character eye gaze (landing spec section D2; numbers from section 0, N9). The pointer offset from
|
|
9
|
+
* the face, in body widths (BW), becomes one eye cell: X -2..2, Y -1..0 (Q9: the eyes never move down). Only the eyes move; the
|
|
10
|
+
* mouth never does (skin.ts composeSkin). Pure, so the cell table is tested without a renderer.
|
|
11
|
+
*/
|
|
12
|
+
export declare const GAZE: {
|
|
13
|
+
/** Spring: stiffness 400, damping 36 (omega = 20 rad/s, zeta = 0.9). */
|
|
14
|
+
readonly k: 400;
|
|
15
|
+
readonly c: 36;
|
|
16
|
+
/** Gaze units per BW. */
|
|
17
|
+
readonly gain: 1.6;
|
|
18
|
+
readonly clampX: 2.4;
|
|
19
|
+
readonly clampY: 1.4;
|
|
20
|
+
/** An offset under this many BW is a dead zone. */
|
|
21
|
+
readonly deadBW: 0.25;
|
|
22
|
+
/** Beyond nearBW the gaze starts to fade; by farBW it is gone. */
|
|
23
|
+
readonly nearBW: 3;
|
|
24
|
+
readonly farBW: 5;
|
|
25
|
+
/** Cell hysteresis in gaze units: enter 0.6 (1 to 2 at 1.6), leave 0.4 (2 to 1 at 1.4). */
|
|
26
|
+
readonly enter1: 0.6;
|
|
27
|
+
readonly enter2: 1.6;
|
|
28
|
+
readonly exit1: 0.4;
|
|
29
|
+
readonly exit2: 1.4;
|
|
30
|
+
/** Reduced motion (D5): the cell may update at most this often, in seconds. */
|
|
31
|
+
readonly snapEveryS: 0.25;
|
|
32
|
+
};
|
|
33
|
+
export interface Point {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
}
|
|
37
|
+
export interface Spring {
|
|
38
|
+
value: number;
|
|
39
|
+
velocity: number;
|
|
40
|
+
}
|
|
41
|
+
export interface Gaze {
|
|
42
|
+
x: Spring;
|
|
43
|
+
y: Spring;
|
|
44
|
+
cellX: number;
|
|
45
|
+
cellY: number;
|
|
46
|
+
}
|
|
47
|
+
export declare const NO_GAZE: Gaze;
|
|
48
|
+
/** Gaze target for a pointer offset in BW: the D2 mapping, with its dead zone. */
|
|
49
|
+
export declare function gazeTarget(dxBW: number, dyBW: number): Point;
|
|
50
|
+
/** One step of the gaze spring (k 400, c 36). */
|
|
51
|
+
export declare function springStep(s: Spring, target: number, dt: number): Spring;
|
|
52
|
+
/**
|
|
53
|
+
* Eye cell for a gaze value, with hysteresis. `twoCells` lets X reach +-2; Y stops at +-1.
|
|
54
|
+
* Crossing the centre resets the cell, so the eyes never jump across it.
|
|
55
|
+
*/
|
|
56
|
+
export declare function nextCell(prev: number, value: number, twoCells: boolean): number;
|
|
57
|
+
export declare function stepGaze(gaze: Gaze, target: Point, dt: number): Gaze;
|
|
58
|
+
/** Reduced motion (D5): the gaze cell may update only this often (at most 4 times a second). */
|
|
59
|
+
export declare function snapDue(lastAt: number, now: number): boolean;
|
|
60
|
+
/** Reduced motion (D5): no spring, the cell follows the target at once. The caller paces it with snapDue. */
|
|
61
|
+
export declare function snapGaze(gaze: Gaze, target: Point): Gaze;
|
|
62
|
+
/**
|
|
63
|
+
* Where a pointer is from a Character, as a direction whose length grows with distance, levels off below 1
|
|
64
|
+
* and fades to nothing for a pointer that is not near. Pure, so the mapping is tested without a page.
|
|
65
|
+
*/
|
|
66
|
+
export declare function towardFrom(at: {
|
|
67
|
+
px: number;
|
|
68
|
+
py: number;
|
|
69
|
+
moved: boolean;
|
|
70
|
+
}, rect: {
|
|
71
|
+
left: number;
|
|
72
|
+
top: number;
|
|
73
|
+
width: number;
|
|
74
|
+
height: number;
|
|
75
|
+
}): {
|
|
76
|
+
x: number;
|
|
77
|
+
y: number;
|
|
78
|
+
};
|
|
79
|
+
/** How far away (in Character heights) the pointer still draws the eyes and the turn, in full and not at all. */
|
|
80
|
+
export declare const NEAR_FULL = 1.4;
|
|
81
|
+
export declare const NEAR_NONE = 2.4;
|
package/dist/gaze.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// src/gaze.ts
|
|
2
|
+
function spring(value, velocity, target, stiffness, damping, dt) {
|
|
3
|
+
const acceleration = -stiffness * (value - target) - damping * velocity;
|
|
4
|
+
const nextVelocity = velocity + acceleration * dt;
|
|
5
|
+
return [value + nextVelocity * dt, nextVelocity];
|
|
6
|
+
}
|
|
7
|
+
var GAZE = {
|
|
8
|
+
k: 400,
|
|
9
|
+
c: 36,
|
|
10
|
+
gain: 1.6,
|
|
11
|
+
clampX: 2.4,
|
|
12
|
+
clampY: 1.4,
|
|
13
|
+
deadBW: 0.25,
|
|
14
|
+
nearBW: 3,
|
|
15
|
+
farBW: 5,
|
|
16
|
+
enter1: 0.6,
|
|
17
|
+
enter2: 1.6,
|
|
18
|
+
exit1: 0.4,
|
|
19
|
+
exit2: 1.4,
|
|
20
|
+
snapEveryS: 0.25
|
|
21
|
+
};
|
|
22
|
+
var MAX_CELL_Y = 0;
|
|
23
|
+
var lookCellY = (cell) => Math.min(MAX_CELL_Y, cell);
|
|
24
|
+
var NO_GAZE = {
|
|
25
|
+
x: { value: 0, velocity: 0 },
|
|
26
|
+
y: { value: 0, velocity: 0 },
|
|
27
|
+
cellX: 0,
|
|
28
|
+
cellY: 0
|
|
29
|
+
};
|
|
30
|
+
var clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
31
|
+
function gazeTarget(dxBW, dyBW) {
|
|
32
|
+
const dx = Math.abs(dxBW) < GAZE.deadBW ? 0 : dxBW;
|
|
33
|
+
const dy = Math.abs(dyBW) < GAZE.deadBW ? 0 : dyBW;
|
|
34
|
+
const distance = Math.hypot(dxBW, dyBW);
|
|
35
|
+
const near = 1 - clamp((distance - GAZE.nearBW) / (GAZE.farBW - GAZE.nearBW), 0, 1);
|
|
36
|
+
return {
|
|
37
|
+
x: clamp(GAZE.gain * dx, -GAZE.clampX, GAZE.clampX) * near,
|
|
38
|
+
y: clamp(GAZE.gain * dy, -GAZE.clampY, GAZE.clampY) * near
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function springStep(s, target, dt) {
|
|
42
|
+
const [value, velocity] = spring(s.value, s.velocity, target, GAZE.k, GAZE.c, dt);
|
|
43
|
+
return { value, velocity };
|
|
44
|
+
}
|
|
45
|
+
function nextCell(prev, value, twoCells) {
|
|
46
|
+
const magnitude = Math.abs(value);
|
|
47
|
+
const sign = Math.sign(value);
|
|
48
|
+
const prevSign = Math.sign(prev);
|
|
49
|
+
let cell = prevSign !== 0 && sign !== 0 && sign !== prevSign ? 0 : Math.abs(prev);
|
|
50
|
+
if (cell === 0 && magnitude > GAZE.enter1)
|
|
51
|
+
cell = 1;
|
|
52
|
+
if (twoCells && cell === 1 && magnitude > GAZE.enter2)
|
|
53
|
+
cell = 2;
|
|
54
|
+
if (cell === 2 && magnitude < GAZE.exit2)
|
|
55
|
+
cell = 1;
|
|
56
|
+
if (cell === 1 && magnitude < GAZE.exit1)
|
|
57
|
+
cell = 0;
|
|
58
|
+
if (cell === 0)
|
|
59
|
+
return 0;
|
|
60
|
+
return sign < 0 ? -cell : cell;
|
|
61
|
+
}
|
|
62
|
+
function stepGaze(gaze, target, dt) {
|
|
63
|
+
const x = springStep(gaze.x, target.x, dt);
|
|
64
|
+
const y = springStep(gaze.y, target.y, dt);
|
|
65
|
+
return {
|
|
66
|
+
x,
|
|
67
|
+
y,
|
|
68
|
+
cellX: nextCell(gaze.cellX, x.value, true),
|
|
69
|
+
cellY: lookCellY(nextCell(gaze.cellY, y.value, false))
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function snapDue(lastAt, now) {
|
|
73
|
+
return now - lastAt >= GAZE.snapEveryS;
|
|
74
|
+
}
|
|
75
|
+
function snapGaze(gaze, target) {
|
|
76
|
+
const x = { value: target.x, velocity: 0 };
|
|
77
|
+
const y = { value: target.y, velocity: 0 };
|
|
78
|
+
return {
|
|
79
|
+
x,
|
|
80
|
+
y,
|
|
81
|
+
cellX: nextCell(gaze.cellX, x.value, true),
|
|
82
|
+
cellY: lookCellY(nextCell(gaze.cellY, y.value, false))
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function towardFrom(at, rect) {
|
|
86
|
+
if (!at.moved)
|
|
87
|
+
return { x: 0, y: 0 };
|
|
88
|
+
const size = Math.max(1, rect.height);
|
|
89
|
+
const dx = (at.px - (rect.left + rect.width / 2)) / size;
|
|
90
|
+
const dy = (at.py - (rect.top + rect.height * 0.45)) / size;
|
|
91
|
+
const distance = Math.hypot(dx, dy);
|
|
92
|
+
if (distance < 0.0001)
|
|
93
|
+
return { x: 0, y: 0 };
|
|
94
|
+
const reach = Math.tanh(distance * 1.4) / distance;
|
|
95
|
+
const near = 1 - Math.min(1, Math.max(0, (distance - NEAR_FULL) / (NEAR_NONE - NEAR_FULL)));
|
|
96
|
+
return { x: dx * reach * near + 0, y: dy * reach * near + 0 };
|
|
97
|
+
}
|
|
98
|
+
var NEAR_FULL = 1.4;
|
|
99
|
+
var NEAR_NONE = 2.4;
|
|
100
|
+
export {
|
|
101
|
+
towardFrom,
|
|
102
|
+
stepGaze,
|
|
103
|
+
springStep,
|
|
104
|
+
spring,
|
|
105
|
+
snapGaze,
|
|
106
|
+
snapDue,
|
|
107
|
+
nextCell,
|
|
108
|
+
gazeTarget,
|
|
109
|
+
NO_GAZE,
|
|
110
|
+
NEAR_NONE,
|
|
111
|
+
NEAR_FULL,
|
|
112
|
+
GAZE
|
|
113
|
+
};
|
package/dist/hair3d.d.ts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type { BodyPresetId } from "./body-presets";
|
|
2
|
+
export { BODY_PRESETS } from "./body-presets";
|
|
3
|
+
export type { AuthoredClipName } from "./clips";
|
|
4
|
+
export { AUTHORED_BONES, AUTHORED_CLIP_NAMES, AUTHORED_CLIPS } from "./clips";
|
|
5
|
+
export type { Emote } from "./emote";
|
|
6
|
+
export { EMOTES, emoteOf } from "./emote";
|
|
7
|
+
export type { NamedFace } from "./faces";
|
|
8
|
+
export { FACE_STAMP_PALETTE, isNamedFace, NAMED_FACE_STAMPS, NAMED_FACES } from "./faces";
|
|
9
|
+
export type { ClipName, ClipRef, CustomClip, Pose, Rotation } from "./pose";
|
|
10
|
+
export { CLIPS, clipLift, customDuration, isCustomClip, mergePoses, resolvePose, sampleClip, } from "./pose";
|
|
11
|
+
export { createRagdoll, RAGDOLL_JOINTS, type Ragdoll, type RagdollMode } from "./ragdoll";
|
|
12
|
+
export type { Bone, CanonicalBone, Rig, RigId, Vec3 } from "./rig";
|
|
13
|
+
export { boneOf, RIGS } from "./rig";
|
|
14
|
+
export type { FaceName, PartFaces, Rect } from "./skin";
|
|
15
|
+
export { CLASSIC_BONES, CLASSIC_HEIGHT, CLASSIC_LEFT_LIMB, CLASSIC_RIGHT_LIMB, CLASSIC_TORSO, CLASSIC_WIDTH, classicFaceRect, validateClassicTemplate, } from "./skin";
|
|
16
|
+
export type { BodyScale, BodyVariant, BoneSkin, CanonicalBox, CanonicalFootprint, CharacterLook, ClassicConversion, NativeMapping, NativePart, PlupBody, ScaledBone, SkinImage, VariantPart, VariantSheetCheck, VariantSheetFacts, VariantSheetProblem, } from "./skin-native";
|
|
17
|
+
export { BODY_SCALE_LIMITS, boneSkin, CANONICAL_BODY_SCALE, CANONICAL_PLUP_BODY, CLASSIC_TO_NATIVE, canonicalFootprint, clampBodyScale, clampPlupBody, NATIVE_ARM_LEFT, NATIVE_ARM_RIGHT, NATIVE_BONES, NATIVE_HEAD, NATIVE_HEIGHT, NATIVE_LEG_LEFT, NATIVE_LEG_RIGHT, NATIVE_PARTS, NATIVE_PX_PER_STUD, NATIVE_SHEET_CAPS, NATIVE_TORSO, NATIVE_WIDTH, nativeFaceRect, nativePartOf, PLUP_BODY_LIMITS, scaleBone, validateVariantSheet, visualEnvelope, } from "./skin-native";
|
|
18
|
+
export type { WearKey } from "./wearables";
|
|
19
|
+
export { isWearKey, WEAR_KEYS, WEARABLES, wearableItems, wearKeyOf, wearKeysOf, wearSlotOf, wearView, } from "./wearables";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EMOTES,
|
|
3
|
+
RAGDOLL_JOINTS,
|
|
4
|
+
createRagdoll,
|
|
5
|
+
emoteOf
|
|
6
|
+
} from "./chunk-yd5zzkkg.js";
|
|
7
|
+
import {
|
|
8
|
+
WEARABLES,
|
|
9
|
+
WEAR_KEYS,
|
|
10
|
+
isWearKey,
|
|
11
|
+
wearKeyOf,
|
|
12
|
+
wearKeysOf,
|
|
13
|
+
wearSlotOf,
|
|
14
|
+
wearView,
|
|
15
|
+
wearableItems
|
|
16
|
+
} from "./chunk-60p135hw.js";
|
|
17
|
+
import {
|
|
18
|
+
BODY_SCALE_LIMITS,
|
|
19
|
+
CANONICAL_BODY_SCALE,
|
|
20
|
+
CANONICAL_PLUP_BODY,
|
|
21
|
+
CLASSIC_BONES,
|
|
22
|
+
CLASSIC_HEIGHT,
|
|
23
|
+
CLASSIC_LEFT_LIMB,
|
|
24
|
+
CLASSIC_RIGHT_LIMB,
|
|
25
|
+
CLASSIC_TORSO,
|
|
26
|
+
CLASSIC_TO_NATIVE,
|
|
27
|
+
CLASSIC_WIDTH,
|
|
28
|
+
NATIVE_ARM_LEFT,
|
|
29
|
+
NATIVE_ARM_RIGHT,
|
|
30
|
+
NATIVE_BONES,
|
|
31
|
+
NATIVE_HEAD,
|
|
32
|
+
NATIVE_HEIGHT,
|
|
33
|
+
NATIVE_LEG_LEFT,
|
|
34
|
+
NATIVE_LEG_RIGHT,
|
|
35
|
+
NATIVE_PARTS,
|
|
36
|
+
NATIVE_PX_PER_STUD,
|
|
37
|
+
NATIVE_SHEET_CAPS,
|
|
38
|
+
NATIVE_TORSO,
|
|
39
|
+
NATIVE_WIDTH,
|
|
40
|
+
PLUP_BODY_LIMITS,
|
|
41
|
+
boneSkin,
|
|
42
|
+
canonicalFootprint,
|
|
43
|
+
clampBodyScale,
|
|
44
|
+
clampPlupBody,
|
|
45
|
+
classicFaceRect,
|
|
46
|
+
nativeFaceRect,
|
|
47
|
+
nativePartOf,
|
|
48
|
+
scaleBone,
|
|
49
|
+
validateClassicTemplate,
|
|
50
|
+
validateVariantSheet,
|
|
51
|
+
visualEnvelope
|
|
52
|
+
} from "./chunk-sa2r1cxz.js";
|
|
53
|
+
import {
|
|
54
|
+
AUTHORED_BONES,
|
|
55
|
+
AUTHORED_CLIPS,
|
|
56
|
+
AUTHORED_CLIP_NAMES,
|
|
57
|
+
CLIPS,
|
|
58
|
+
RIGS,
|
|
59
|
+
boneOf,
|
|
60
|
+
clipLift,
|
|
61
|
+
customDuration,
|
|
62
|
+
isCustomClip,
|
|
63
|
+
mergePoses,
|
|
64
|
+
resolvePose,
|
|
65
|
+
sampleClip
|
|
66
|
+
} from "./chunk-g1c0wdcj.js";
|
|
67
|
+
import {
|
|
68
|
+
FACE_STAMP_PALETTE,
|
|
69
|
+
NAMED_FACES,
|
|
70
|
+
NAMED_FACE_STAMPS,
|
|
71
|
+
isNamedFace
|
|
72
|
+
} from "./chunk-aa5nstet.js";
|
|
73
|
+
|
|
74
|
+
// src/body-presets.ts
|
|
75
|
+
var BODY_PRESETS = {
|
|
76
|
+
round: { name: "Round", shape: "plup", body: {} },
|
|
77
|
+
"tall-slim": {
|
|
78
|
+
name: "Tall & Slim",
|
|
79
|
+
shape: "tall",
|
|
80
|
+
body: { shoulders: 0.9, waist: 0.84, hips: 0.9, legLength: 2.6, armLength: 1.4, muscle: 0.78 }
|
|
81
|
+
},
|
|
82
|
+
athletic: {
|
|
83
|
+
name: "Athletic",
|
|
84
|
+
shape: "tall",
|
|
85
|
+
body: { shoulders: 1.2, waist: 0.84, hips: 0.95, legLength: 2.1, armLength: 1.3, muscle: 1.35 }
|
|
86
|
+
},
|
|
87
|
+
muscular: {
|
|
88
|
+
name: "Muscular",
|
|
89
|
+
shape: "tall",
|
|
90
|
+
body: {
|
|
91
|
+
shoulders: 1.32,
|
|
92
|
+
waist: 0.82,
|
|
93
|
+
hips: 0.88,
|
|
94
|
+
legLength: 1.7,
|
|
95
|
+
armLength: 1.25,
|
|
96
|
+
muscle: 1.9
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
curvy: {
|
|
100
|
+
name: "Curvy",
|
|
101
|
+
shape: "tall",
|
|
102
|
+
body: { shoulders: 0.9, waist: 0.66, hips: 1.32, legLength: 2.4, armLength: 1.3, muscle: 0.85 }
|
|
103
|
+
},
|
|
104
|
+
chubby: {
|
|
105
|
+
name: "Chubby",
|
|
106
|
+
shape: "wide",
|
|
107
|
+
body: { shoulders: 1, waist: 1.15, hips: 1.25, legLength: 1, armLength: 1, muscle: 1.2 }
|
|
108
|
+
},
|
|
109
|
+
tiny: { name: "Tiny", shape: "mini", body: {} },
|
|
110
|
+
bean: { name: "Bean", shape: "bean", body: { legLength: 1.3 } }
|
|
111
|
+
};
|
|
112
|
+
export {
|
|
113
|
+
wearableItems,
|
|
114
|
+
wearView,
|
|
115
|
+
wearSlotOf,
|
|
116
|
+
wearKeysOf,
|
|
117
|
+
wearKeyOf,
|
|
118
|
+
visualEnvelope,
|
|
119
|
+
validateVariantSheet,
|
|
120
|
+
validateClassicTemplate,
|
|
121
|
+
scaleBone,
|
|
122
|
+
sampleClip,
|
|
123
|
+
resolvePose,
|
|
124
|
+
nativePartOf,
|
|
125
|
+
nativeFaceRect,
|
|
126
|
+
mergePoses,
|
|
127
|
+
isWearKey,
|
|
128
|
+
isNamedFace,
|
|
129
|
+
isCustomClip,
|
|
130
|
+
emoteOf,
|
|
131
|
+
customDuration,
|
|
132
|
+
createRagdoll,
|
|
133
|
+
clipLift,
|
|
134
|
+
classicFaceRect,
|
|
135
|
+
clampPlupBody,
|
|
136
|
+
clampBodyScale,
|
|
137
|
+
canonicalFootprint,
|
|
138
|
+
boneSkin,
|
|
139
|
+
boneOf,
|
|
140
|
+
WEAR_KEYS,
|
|
141
|
+
WEARABLES,
|
|
142
|
+
RIGS,
|
|
143
|
+
RAGDOLL_JOINTS,
|
|
144
|
+
PLUP_BODY_LIMITS,
|
|
145
|
+
NATIVE_WIDTH,
|
|
146
|
+
NATIVE_TORSO,
|
|
147
|
+
NATIVE_SHEET_CAPS,
|
|
148
|
+
NATIVE_PX_PER_STUD,
|
|
149
|
+
NATIVE_PARTS,
|
|
150
|
+
NATIVE_LEG_RIGHT,
|
|
151
|
+
NATIVE_LEG_LEFT,
|
|
152
|
+
NATIVE_HEIGHT,
|
|
153
|
+
NATIVE_HEAD,
|
|
154
|
+
NATIVE_BONES,
|
|
155
|
+
NATIVE_ARM_RIGHT,
|
|
156
|
+
NATIVE_ARM_LEFT,
|
|
157
|
+
NAMED_FACE_STAMPS,
|
|
158
|
+
NAMED_FACES,
|
|
159
|
+
FACE_STAMP_PALETTE,
|
|
160
|
+
EMOTES,
|
|
161
|
+
CLIPS,
|
|
162
|
+
CLASSIC_WIDTH,
|
|
163
|
+
CLASSIC_TO_NATIVE,
|
|
164
|
+
CLASSIC_TORSO,
|
|
165
|
+
CLASSIC_RIGHT_LIMB,
|
|
166
|
+
CLASSIC_LEFT_LIMB,
|
|
167
|
+
CLASSIC_HEIGHT,
|
|
168
|
+
CLASSIC_BONES,
|
|
169
|
+
CANONICAL_PLUP_BODY,
|
|
170
|
+
CANONICAL_BODY_SCALE,
|
|
171
|
+
BODY_SCALE_LIMITS,
|
|
172
|
+
BODY_PRESETS,
|
|
173
|
+
AUTHORED_CLIP_NAMES,
|
|
174
|
+
AUTHORED_CLIPS,
|
|
175
|
+
AUTHORED_BONES
|
|
176
|
+
};
|