katachi-runtime 0.3.0 → 0.6.1

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/character.d.ts CHANGED
@@ -1,31 +1,193 @@
1
- import type { PedEntry, PieceEntry } from "./assets";
1
+ import type { FreemodeEntry, PedEntry, PieceEntry } from "./assets";
2
2
  import type { ModelLoader } from "./loader";
3
3
  import { Model } from "./model";
4
+ import { type Overlay, type OverlayName } from "./overlays";
5
+ import type { FocusSphere } from "./stage";
6
+ /** Parts of the body `Character.part` finds, for close-ups with `Stage.focus`. */
7
+ export type BodyPart = "face" | "hands" | "left-hand" | "right-hand" | "feet";
4
8
  /** A worn piece and its texture variant. */
5
9
  interface Selection {
6
10
  piece: PieceEntry;
7
11
  variant?: string;
8
12
  }
9
- /** A character made of a skeleton with swappable clothing and props. */
13
+ /**
14
+ * A freemode face, as the game's head blend makes it: the shape mixed from two parents' heads and the skin from two
15
+ * parents' skins, each mix from 0 (all the first) to 1 (all the second). Parents are the game's head numbers, 0 to 45.
16
+ */
17
+ export interface HeadBlend {
18
+ shapeFirst: number;
19
+ shapeSecond: number;
20
+ shapeMix: number;
21
+ skinFirst: number;
22
+ skinSecond: number;
23
+ skinMix: number;
24
+ }
25
+ /** A colour: CSS, or `[r, g, b]` from 0 to 255. */
26
+ export type Tone = string | readonly [number, number, number];
27
+ /**
28
+ * How a character is dressed and, for freemode characters, how it looks: everything `Character.dress` puts on, in a
29
+ * form that fits a link or a command line with `Character.parseOutfit` and `Character.parseHead`.
30
+ */
31
+ export interface Look {
32
+ /** Pieces by slot, as `index`, `index:variant` or `pack/index:variant`, or `none`: `{ jbib: "5:a", hair: "12:a", p_head: "none" }`. */
33
+ outfit?: Record<string, string>;
34
+ head?: HeadBlend;
35
+ hair?: {
36
+ color: Tone;
37
+ highlight?: Tone;
38
+ };
39
+ /** Eyebrows, beards, makeup and the rest, by name: `{ eyebrows: { style: 3 }, facialHair: { style: 10, color: "#2e221b" } }`. */
40
+ overlays?: Partial<Record<OverlayName, Overlay>>;
41
+ /** The eye colour, 0 to 31 in the game's order. */
42
+ eyes?: number;
43
+ /** Face features by SetPedFaceFeature's number, each from -1 to 1: `[0.5, 0, -0.3]` narrows the nose... */
44
+ features?: number[];
45
+ }
46
+ /** The game's 32 eye colours, by SetPedEyeColor's number. */
47
+ export declare const EYE_COLORS: readonly ["Green", "Emerald", "Light blue", "Ocean blue", "Light brown", "Dark brown", "Hazel", "Dark gray", "Light gray", "Pink", "Yellow", "Purple", "Blackout", "Shades of gray", "Tequila sunrise", "Atomic", "Warp", "ECola", "Space ranger", "Ying yang", "Bullseye", "Lizard", "Dragon", "Extra terrestrial", "Goat", "Smiley", "Possessed", "Demon", "Infected", "Alien", "Undead", "Zombie"];
48
+ /**
49
+ * The game's 20 face features, by SetPedFaceFeature's number: each runs from -1 (its first target) to 1 (its second),
50
+ * except the chin's cleft and the neck, which run from 0 to 1.
51
+ */
52
+ export declare const FACE_FEATURES: readonly [readonly ["noseWidth", "micro_nose_thin", "micro_nose_wide"], readonly ["noseHeight", "micro_nose_up", "micro_nose_down"], readonly ["noseLength", "micro_nose_long", "micro_nose_short"], readonly ["noseProfile", "micro_nose_profile_crooked", "micro_nose_profile_curved"], readonly ["noseTip", "micro_nose_tip_up", "micro_nose_tip_down"], readonly ["noseTwist", "micro_nose_broke_left", "micro_nose_broke_right"], readonly ["browHeight", "micro_brow_up", "micro_brow_down"], readonly ["browDepth", "micro_brow_in", "micro_brow_out"], readonly ["cheekboneHeight", "micro_cheek_up", "micro_cheek_down"], readonly ["cheekboneWidth", "micro_cheek_in", "micro_cheek_out"], readonly ["cheekWidth", "micro_cheek_puffed", "micro_cheek_gaunt"], readonly ["eyeOpening", "micro_eyes_wide", "micro_eyes_squinted"], readonly ["lipThickness", "micro_lips_fat", "micro_lips_thin"], readonly ["jawWidth", "micro_jaw_narrow", "micro_jaw_wide"], readonly ["jawShape", "micro_jaw_round", "micro_jaw_square"], readonly ["chinHeight", "micro_chin_up", "micro_chin_down"], readonly ["chinDepth", "micro_chin_in", "micro_chin_out"], readonly ["chinShape", "micro_chin_pointed", "micro_chin_square"], readonly ["chinCleft", null, "micro_chin_bum"], readonly ["neckThickness", null, "micro_neck_male"]];
53
+ /** A character made of a skeleton with swappable clothing and props, and for freemode characters a face and hair colour. */
10
54
  export declare class Character extends Model {
11
55
  /** The character's manifest entry. */
12
56
  readonly entry: PedEntry;
13
57
  private readonly loader;
58
+ /** What freemode faces are made with: the overlays and eye colours, when the folder holds them. */
59
+ private readonly looks;
60
+ /** Directions for `Stage.view`. `game` is GTA's third-person camera: behind the character, over its right shoulder. */
61
+ static readonly views: {
62
+ readonly front: readonly [0, 0.08, 1];
63
+ readonly back: readonly [0, 0.12, -1];
64
+ readonly left: readonly [1, 0.08, 0];
65
+ readonly right: readonly [-1, 0.08, 0];
66
+ readonly top: readonly [0, 1, 0.02];
67
+ readonly game: readonly [-0.28, 0.32, -1];
68
+ };
14
69
  readonly view: readonly [0.3, 0.08, 0.95];
15
70
  private readonly worn;
16
71
  private readonly selection;
17
72
  private readonly revisions;
73
+ private readonly hair;
74
+ private readonly skin;
75
+ private blend;
76
+ /** The face worn, for changing its mixes in place: its meshes, its skin mix, and its parents' and the body's skin tones. */
77
+ private face;
78
+ private headLoading;
79
+ private readonly defaults;
80
+ private readonly faceOverlays;
81
+ private readonly bodyOverlays;
82
+ private readonly wornOverlays;
83
+ private overlayRevision;
84
+ private readonly eye;
85
+ private defaultBlend;
86
+ private readonly featureValues;
87
+ private featureTargets;
18
88
  private constructor();
19
- static load(name: string, entry: PedEntry, loader: ModelLoader): Promise<Character>;
89
+ /**
90
+ * Loads a character in its default clothes, or straight into a look: the slots and face the look sets load only as
91
+ * the look has them, so nothing loads to be replaced.
92
+ */
93
+ static load(name: string, entry: PedEntry, loader: ModelLoader, looks?: FreemodeEntry | null, look?: Look): Promise<Character>;
94
+ /**
95
+ * Reads `slot=index[:variant],...` as an outfit, such as `jbib=5:a,hair=12:a,p_head=none`. A piece from a DLC pack
96
+ * names its pack, as `jbib=mp_m_freemode_01_mp_m_xmas/5:a`, since every pack numbers its pieces from 0.
97
+ */
98
+ static parseOutfit(text: string): Record<string, string>;
99
+ /** Writes an outfit the way `parseOutfit` reads it. */
100
+ static formatOutfit(outfit: Record<string, string>): string;
101
+ /**
102
+ * Reads a face as `first,second,shapeMix`, which mixes skin like shape, or as
103
+ * `shapeFirst,shapeSecond,shapeMix,skinFirst,skinSecond,skinMix`.
104
+ */
105
+ static parseHead(text: string): HeadBlend;
106
+ /**
107
+ * Reads overlays as `name:style[:opacity[:color]]` items, such as `eyebrows:3,facialHair:10:0.8:#2e221b`.
108
+ */
109
+ static parseOverlays(text: string): Partial<Record<OverlayName, Overlay>>;
110
+ /** Reads face features as `number:value` pairs, the rest at 0, such as `0:0.5,13:-0.4` (or by name, `noseWidth:0.5`). */
111
+ static parseFeatures(text: string): number[];
112
+ /** Writes face features the way `parseFeatures` reads them: only those not at 0. */
113
+ static formatFeatures(values: readonly number[]): string;
114
+ /** Writes overlays the way `parseOverlays` reads them. */
115
+ static formatOverlays(overlays: Partial<Record<OverlayName, Overlay>>): string;
116
+ /** Writes a face the way `parseHead` reads it, in the short form when its skin mixes like its shape. */
117
+ static formatHead(blend: HeadBlend): string;
118
+ /** Where a part of the body is now, as a sphere for `Stage.focus`. */
119
+ part(name: BodyPart): FocusSphere;
120
+ /** The arms (`uppr` number) the game pairs a base freemode top with, or undefined for other tops and characters. */
121
+ armsFor(top: number): number | undefined;
20
122
  /** Returns the piece worn in a component slot, or in a prop slot named `p_<component>`. */
21
123
  selected(slot: string): Selection | undefined;
124
+ /** The face worn, or null for the head piece as it is. */
125
+ get head(): HeadBlend | null;
126
+ /** Whether this is one of the game's online characters, whose faces blend, hair takes a colour, and body takes the face's skin. */
127
+ get freemode(): boolean;
128
+ /** The heads a freemode face is blended from, by the game's head number. */
129
+ heads(): number[];
22
130
  /** Wears a clothing piece, or removes it with `null`. Uses the first texture variant by default. */
23
131
  setComponent(component: string, piece: PieceEntry | null, variant?: string): Promise<void>;
24
132
  /** Wears a prop, or removes it with `null`. Uses the first texture variant by default. */
25
133
  setProp(component: string, piece: PieceEntry | null, variant?: string): Promise<void>;
134
+ /**
135
+ * Gives a freemode character a face blended from two parents, as the game's head blend does, and carries its skin
136
+ * tone to the rest of the body's bare skin. Changing only the mixes of the face worn is immediate.
137
+ */
138
+ setHead(blend: HeadBlend): Promise<void>;
139
+ /** The face features worn, by SetPedFaceFeature's number: 20 values, each from -1 to 1 (the last two from 0). */
140
+ faceFeatures(): number[];
141
+ /**
142
+ * Shapes a freemode face as SetPedFaceFeature does: a feature by its number or name (`FACE_FEATURES`), from -1 to 1,
143
+ * or for the chin's cleft and the neck from 0 to 1.
144
+ */
145
+ setFaceFeature(feature: number | (typeof FACE_FEATURES)[number][0], value: number): void;
146
+ /** Sets every face feature at once, from a list in SetPedFaceFeature's order; missing ones go back to 0. */
147
+ setFaceFeatures(values: readonly number[]): void;
148
+ private loadFeatureTargets;
149
+ private applyFeatures;
150
+ /** How many styles an overlay has, numbered from 0, or 0 when the folder holds no freemode overlays. */
151
+ overlayStyles(name: OverlayName): number;
152
+ /** The overlays worn, by name. */
153
+ overlays(): Partial<Record<OverlayName, Overlay>>;
154
+ /**
155
+ * Puts on a freemode overlay, as SetPedHeadOverlay and SetPedHeadOverlayColor do, or takes it off with `null`: a
156
+ * style by its number in the game's list, how strongly it shows (1 by default), and for eyebrows, beards, chest hair,
157
+ * blush and lipstick a colour.
158
+ */
159
+ setOverlay(name: OverlayName, overlay: Overlay | null): Promise<void>;
160
+ /** Puts on several overlays at once, composing them once. */
161
+ setOverlays(overlays: Partial<Record<OverlayName, Overlay | null>>): Promise<void>;
162
+ /** Gives a freemode character one of the game's 32 eye colours (`EYE_COLORS`), or its face's own with `null`. */
163
+ setEyeColor(color: number | null): Promise<void>;
164
+ /** The eye colour worn, or null for the face's own. */
165
+ get eyeColor(): number | null;
166
+ private composeOverlays;
167
+ /** Colours freemode hair, with highlights in a second colour. */
168
+ setHairColor(color: Tone, highlight?: Tone): void;
169
+ /** The hair's colour and highlight, as CSS colours. */
170
+ hairColor(): {
171
+ color: string;
172
+ highlight: string;
173
+ };
174
+ /**
175
+ * Puts on a look: its outfit first, then its face and hair colour. Returns the outfit's choices this character does
176
+ * not have, such as `jbib=500`, and leaves those slots as they were.
177
+ */
178
+ dress(look: Look): Promise<string[]>;
179
+ /** A look's outfit as it goes on: a base top with the arms the game pairs it with, and no head piece when a face is given. */
180
+ private outfitOf;
181
+ /** The look worn: the slots changed from the character's defaults, its face, and its hair colour once set. */
182
+ look(): Look;
26
183
  /** Removes all clothing and frees the character. */
27
184
  dispose(): void;
185
+ private mixFace;
186
+ private headPieces;
187
+ /** The body's own skin colour, which bare skin is recognised by: the first head's, which the body is painted to match. */
188
+ private readSkin;
28
189
  private wearDefaults;
190
+ private nextRevision;
29
191
  private wear;
30
192
  }
31
193
  export {};
package/clip.d.ts ADDED
@@ -0,0 +1,101 @@
1
+ /** What a track drives. Bone tracks name their bone by tag; mover tracks move the whole model. */
2
+ export declare const TrackKind: {
3
+ readonly boneTranslation: 0;
4
+ readonly boneRotation: 1;
5
+ readonly boneScale: 2;
6
+ readonly moverTranslation: 5;
7
+ readonly moverRotation: 6;
8
+ };
9
+ /** How a track stores each frame. */
10
+ export declare const TrackFormat: {
11
+ readonly vector3: 0;
12
+ readonly quaternion: 1;
13
+ readonly float: 2;
14
+ };
15
+ /** A track as the converter writes it. */
16
+ export interface TrackData {
17
+ /** The bone's tag, or 0 for the mover. */
18
+ bone: number;
19
+ kind: number;
20
+ format: number;
21
+ /** `frames × width` numbers, or `width` numbers when the track holds still. */
22
+ values: number[];
23
+ }
24
+ /** An event marked on a clip, such as a footstep, between two phases from 0 to 1. */
25
+ export interface TagData {
26
+ name: string;
27
+ start: number;
28
+ end: number;
29
+ }
30
+ /** A clip as the converter writes it. */
31
+ export interface ClipData {
32
+ version: 1;
33
+ dictionary: string;
34
+ name: string;
35
+ /** The key the game plays the clip by: the hash of its name. */
36
+ hash: number;
37
+ fps: number;
38
+ frames: number;
39
+ flags: number;
40
+ tracks: TrackData[];
41
+ tags: TagData[];
42
+ }
43
+ /** A clip in the manifest. */
44
+ export interface ClipEntry {
45
+ path: string;
46
+ frames: number;
47
+ fps: number;
48
+ }
49
+ /** A clip dictionary in the manifest: the clips the game loads together. */
50
+ export interface AnimationEntry {
51
+ clips: Record<string, ClipEntry>;
52
+ }
53
+ export declare function trackWidth(format: number): number;
54
+ /** One animated property of one bone, or of the mover. */
55
+ export declare class Track {
56
+ readonly bone: number;
57
+ readonly kind: number;
58
+ readonly format: number;
59
+ /** `frames × width` values, or `width` values when the track holds still. */
60
+ readonly values: Float32Array;
61
+ readonly width: number;
62
+ constructor(bone: number, kind: number, format: number,
63
+ /** `frames × width` values, or `width` values when the track holds still. */
64
+ values: Float32Array);
65
+ /** True when the track holds one value for the whole clip. */
66
+ get constant(): boolean;
67
+ /** Writes the value at a fractional frame into `out`, interpolating quaternions along the shortest arc. */
68
+ sample(frame: number, out: Float32Array | number[], offset?: number): void;
69
+ }
70
+ export interface ClipInit {
71
+ dictionary: string;
72
+ name: string;
73
+ hash?: number;
74
+ fps: number;
75
+ frames: number;
76
+ flags?: number;
77
+ tracks: Track[];
78
+ tags?: TagData[];
79
+ }
80
+ /** The game's name hash, which clips, models and bones are keyed by. */
81
+ export declare function joaat(text: string): number;
82
+ /** An animation clip: tracks sampled at a fixed rate, the way the game stores them. */
83
+ export declare class Clip {
84
+ readonly dictionary: string;
85
+ readonly name: string;
86
+ readonly hash: number;
87
+ readonly fps: number;
88
+ readonly frames: number;
89
+ readonly flags: number;
90
+ readonly tracks: readonly Track[];
91
+ readonly tags: readonly TagData[];
92
+ constructor(init: ClipInit);
93
+ /** Reads a clip the converter wrote. */
94
+ static fromJSON(data: ClipData): Clip;
95
+ /** The clip as the converter writes it. */
96
+ toJSON(): ClipData;
97
+ /** Seconds from the first frame to the last. */
98
+ get duration(): number;
99
+ /** The track of a bone, or of the mover with bone 0. */
100
+ track(bone: number, kind: number): Track | undefined;
101
+ }
package/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
- export { Assets, type Manifest, type ModEntry, type ModelEntry, type ModelKind, type PedEntry, type PieceEntry, type VehicleEntry, type WheelEntry } from "./assets";
2
- export { Character } from "./character";
1
+ export { Playback, type PlayOptions } from "./animation";
2
+ export { Assets, type FreemodeEntry, type Manifest, type ModEntry, type OverlayEntry, type ModelEntry, type ModelKind, type PedEntry, type PieceEntry, type VehicleEntry, type WheelEntry } from "./assets";
3
+ export { boneName, PED_BONES } from "./bones";
4
+ export { Character, EYE_COLORS, FACE_FEATURES, type BodyPart, type HeadBlend, type Look, type Tone } from "./character";
5
+ export { OVERLAYS, TINTED, type Overlay, type OverlayName } from "./overlays";
6
+ export { Clip, joaat, Track, TrackFormat, TrackKind, trackWidth, type AnimationEntry, type ClipData, type ClipEntry, type ClipInit, type TagData, type TrackData } from "./clip";
3
7
  export { Model } from "./model";
4
- export { Stage, ThumbnailRenderer, type Direction, type StageInset, type StageLighting, type StageOptions, type ThumbnailFormat } from "./stage";
8
+ export { Stage, ThumbnailRenderer, type Direction, type FocusSphere, type StageInset, type StageLighting, type StageOptions, type ThumbnailFormat } from "./stage";
5
9
  export { Vehicle, type Color, type Opening, type PaintName, type VehicleProps } from "./vehicle";