katachi-runtime 0.0.0-stage → 0.1.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/README.md CHANGED
@@ -1,3 +1,165 @@
1
- # Temporary Holding Version
1
+ # Katachi
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ GTA V vehicles, characters and objects in the browser, from real game files.
4
+
5
+ ## Quick start
6
+
7
+ You need [Bun](https://bun.sh) and [Zig 0.17](https://ziglang.org/download). Developed on macOS and used on Windows; Linux is untested.
8
+
9
+ ```sh
10
+ git clone https://github.com/arshad-yaseen/katachi.git
11
+ cd katachi
12
+ bun install
13
+ bun run convert path/to/mod
14
+ bun run dev
15
+ ```
16
+
17
+ Open the address it prints to browse what you converted. Click a model to try it in 3D.
18
+
19
+ ## Commands
20
+
21
+ | Command | What it does |
22
+ | --- | --- |
23
+ | `bun run convert <files or folders>` | Converts `.rpf`, `.yft`, `.ydr`, `.ydd`, `.ytd`, `.ytyp`, `.meta` and `.ymt` files into `out/`. |
24
+ | `bun run thumbnails <folder>` | Renders a 512×512 transparent image of each model into `<folder>/thumbnails`, with Google Chrome or Microsoft Edge. Each model fills its image; one with nothing to draw is reported as failed. |
25
+ | `bun run dev [folder]` | Starts the playground. Shows `out/` unless you name another folder. |
26
+
27
+ ### Convert options
28
+
29
+ | Option | Description |
30
+ | --- | --- |
31
+ | `-o <folder>` | Output folder. Defaults to `out`. |
32
+ | `-j <n>` | Worker threads. Defaults to all cores. |
33
+ | `--keys <folder>` | Opens encrypted archives. |
34
+ | `--only <file>` | Converts only the models named in this file, one per line. |
35
+ | `--skeleton <file>` | Ped skeleton `.yft` for clothing that has none nearby. |
36
+
37
+ When a model exists more than once, the first input wins, so list mods before the game folder. Problems are listed in `<output>/report.json`.
38
+
39
+ ### Thumbnail options
40
+
41
+ | Option | Description |
42
+ | --- | --- |
43
+ | `--size <pixels>` | Image size. Defaults to `512`. |
44
+ | `--format <png or webp>` | Image format. Defaults to `png`; `webp` files are several times smaller. |
45
+ | `--only <file>` | Renders only the models named in this file, one per line. |
46
+ | `--views <file>` | A JSON object of camera directions, such as `{ "prop_chair_01": [0, 0.3, 1], "object": [0.6, 0.35, 0.75] }`. Keys are model names or kinds (`vehicle`, `character`, `object`); a name wins over its kind. |
47
+
48
+ Without Chrome or Edge, run `bunx playwright install chromium` once.
49
+
50
+ ### Encrypted archives
51
+
52
+ The base game and many mods are encrypted, and Katachi includes no keys. Make a folder outside this repository with `GTA5.exe` from your own copy of the game, plus `gtav_ng_key.dat` and `gtav_ng_decrypt_tables.dat` from a GTA V modding tool. Then pass it with `--keys`.
53
+
54
+ To pick models from a whole game install:
55
+
56
+ ```sh
57
+ bun run convert path/to/game --keys path/to/keys --only models.txt
58
+ ```
59
+
60
+ ## Playground
61
+
62
+ `playground/` is one plain page, and nothing depends on it. It lists every model. Clicking one opens it in 3D with native controls. Press the left and right arrow keys to step through models. Links open a model with its settings, such as `/#adder?primary=30&wrap=1&mods.0=2`.
63
+
64
+ ## Runtime
65
+
66
+ `katachi-runtime` shows converted models with [three.js](https://threejs.org). Upload your output folder to any static host, such as Cloudflare R2 with CORS enabled. Files are content-hashed, so they can be cached forever and re-uploaded as you add models.
67
+
68
+ ```sh
69
+ npm install katachi-runtime three@0.187.0
70
+ ```
71
+
72
+ ```ts
73
+ import { Assets, Stage } from "katachi-runtime";
74
+
75
+ const assets = await Assets.open("https://assets.example.com/");
76
+ const stage = new Stage(document.querySelector("canvas")!);
77
+ await stage.show(assets, "adder", { primary: 30, secondary: "#ffcc00", wrap: 1, mods: { 0: 2 }, plate: "HELLO" });
78
+ ```
79
+
80
+ Give the canvas a size with CSS. To draw into your own three.js scene, use `await assets.load(name, props)` and add `model.root`.
81
+
82
+ Props use the game's own numbers, so saved vehicle data can be passed straight in:
83
+
84
+ | Prop | Value |
85
+ | --- | --- |
86
+ | `primary`, `secondary`, `pearlescent`, `wheel`, `interior`, `dashboard` | A game color ID, a CSS color, or `[r, g, b]`. |
87
+ | `plate` | License plate text. |
88
+ | `wrap` | Index into `wraps()`. `null` removes it. |
89
+ | `mods` | `{ slot: option }`, using the game's mod slot numbers. `null` restores stock. |
90
+ | `wheelType` | The game's wheel type, `0` to `7`. `mods[23]` picks a wheel from it. |
91
+ | `neon` | Underglow color. `null` removes it. |
92
+ | `lights` | `true` turns the lights on. |
93
+ | `extras` | `{ id: enabled }`. |
94
+ | `windowTint` | The game's tint ID, `0` to `6`. |
95
+
96
+ Not all cars have wraps or tuning, so check `wraps()` and `mods()` before offering them.
97
+
98
+ ### API
99
+
100
+ ```ts
101
+ class Assets {
102
+ static open(baseUrl: string): Promise<Assets>; // baseUrl ends with a slash
103
+ models: { kind: "vehicle" | "character" | "object" | "map"; name: string }[];
104
+ load(name: string, props?: VehicleProps): Promise<Model>; // a Vehicle or Character when that is what it is
105
+ clear(): void; // frees shared textures; dispose models first
106
+ }
107
+
108
+ class Stage {
109
+ constructor(canvas: HTMLCanvasElement, options?: { autoRotate?: boolean; zoom?: boolean }); // drag to orbit, scroll to zoom; zoom: false leaves scrolling to the page; draws nothing while off screen
110
+ show(assets: Assets, name: string, props?: VehicleProps): Promise<Model | undefined>; // undefined if another model was shown meanwhile
111
+ dispose(): void;
112
+ }
113
+
114
+ class Model {
115
+ name: string;
116
+ root: THREE.Group; // add this to your scene
117
+ bones: Map<string, THREE.Object3D>;
118
+ view: [number, number, number]; // best viewing direction
119
+ placeAtOrigin(): THREE.Box3;
120
+ dispose(): void;
121
+ }
122
+
123
+ class Vehicle extends Model {
124
+ entry: VehicleEntry; // includes factory colors
125
+ apply(props: VehicleProps): Promise<void>;
126
+ setPaint(name: PaintName, color: Color): void;
127
+ paint(name: PaintName): string;
128
+ setPlate(text: string): void;
129
+ setWindowTint(id: number): void;
130
+ wraps(): string[];
131
+ setWrap(index: number | null): Promise<void>;
132
+ mods(): Map<number, ModEntry[]>; // tuning options by game mod slot
133
+ setMod(slot: number, option: number | null): Promise<void>;
134
+ wheels(): WheelEntry[][]; // wheels by game wheel type
135
+ setWheels(type: number, option: number | null): Promise<void>;
136
+ setNeon(color: Color | null): void;
137
+ setLights(on: boolean): void;
138
+ openings(): Opening[];
139
+ setOpen(name: Opening, amount: number): void; // 0 to 1
140
+ extras(): number[];
141
+ extraEnabled(id: number): boolean;
142
+ setExtra(id: number, enabled: boolean): void;
143
+ }
144
+
145
+ class Character extends Model {
146
+ entry: PedEntry; // lists components and props
147
+ setComponent(component: string, piece: PieceEntry | null, variant?: string): Promise<void>;
148
+ setProp(component: string, piece: PieceEntry | null, variant?: string): Promise<void>;
149
+ selected(slot: string): { piece: PieceEntry; variant?: string } | undefined; // prop slots are p_<component>
150
+ }
151
+
152
+ class ThumbnailRenderer {
153
+ constructor(size?: number, format?: "png" | "webp"); // defaults to 512 and png
154
+ render(model: Model, view?: [number, number, number]): Promise<Blob>; // transparent image that the model fills, from model.view unless given
155
+ dispose(): void;
156
+ }
157
+ ```
158
+
159
+ ## Not supported yet
160
+
161
+ Tire smoke, dirt and damage, assembled buildings, freemode faces and hair color, server clothing numbers, and animation.
162
+
163
+ ## Legal
164
+
165
+ Katachi is not affiliated with or endorsed by Rockstar Games or Take-Two Interactive and includes no game files. You are responsible for having the rights to anything you convert or publish.
package/assets.d.ts ADDED
@@ -0,0 +1,81 @@
1
+ import { Model } from "./model";
2
+ import { type VehicleProps } from "./vehicle";
3
+ /** A tuning option a vehicle can fit. */
4
+ export interface ModEntry {
5
+ model: string;
6
+ path: string;
7
+ type: string;
8
+ /** The game's mod slot number, or -1 for parts fitted only alongside another. */
9
+ slot: number;
10
+ label: string;
11
+ bone: string;
12
+ /** Bones hidden while this option is fitted. */
13
+ turnOffBones: string[];
14
+ /** Other models fitted together with this one. */
15
+ linkedModels: string[];
16
+ }
17
+ /** A vehicle in the manifest. */
18
+ export interface VehicleEntry {
19
+ model: string;
20
+ flags?: string;
21
+ /** Factory color sets, as game color IDs. */
22
+ colors?: number[][];
23
+ /** Texture paths of the wraps built into the vehicle's paint. */
24
+ liveries?: string[];
25
+ mods: ModEntry[];
26
+ }
27
+ /** A wheel a vehicle can fit. */
28
+ export interface WheelEntry {
29
+ model: string;
30
+ path: string;
31
+ label: string;
32
+ }
33
+ /** A clothing item or prop in the manifest. */
34
+ export interface PieceEntry {
35
+ component: string;
36
+ index: number;
37
+ suffix?: string;
38
+ collection: string;
39
+ mesh: string;
40
+ /** Texture paths by variant name. */
41
+ diffuse: Record<string, string>;
42
+ }
43
+ /** A character in the manifest. */
44
+ export interface PedEntry {
45
+ skeleton?: string;
46
+ components: PieceEntry[];
47
+ props: PieceEntry[];
48
+ }
49
+ /** The index of every converted asset. */
50
+ export interface Manifest {
51
+ version: number;
52
+ vehicles: Record<string, VehicleEntry>;
53
+ /** Wheels by the game's wheel type. */
54
+ wheels: WheelEntry[][];
55
+ peds: Record<string, PedEntry>;
56
+ /** Paths of standalone objects, by name. */
57
+ models: Record<string, string>;
58
+ /** Paths of map pieces, such as buildings, rooms and interior layers, by name. */
59
+ map: Record<string, string>;
60
+ }
61
+ /** The manifest sections a model can come from. */
62
+ export type ModelKind = "vehicle" | "character" | "object" | "map";
63
+ /** A model listed in an assets folder. */
64
+ export interface ModelEntry {
65
+ kind: ModelKind;
66
+ name: string;
67
+ }
68
+ /** A folder of converted models. */
69
+ export declare class Assets {
70
+ private readonly manifest;
71
+ private readonly loader;
72
+ /** Every model in the folder: vehicles, characters, objects, then map pieces, each sorted by name. */
73
+ readonly models: ModelEntry[];
74
+ private constructor();
75
+ /** Opens an assets folder. `baseUrl` must end with a slash. */
76
+ static open(baseUrl: string): Promise<Assets>;
77
+ /** Loads a model by name, ready to show. Vehicles take `props`, and characters wear their default clothing. */
78
+ load(name: string, props?: VehicleProps): Promise<Model>;
79
+ /** Frees every shared texture and clothing piece. Dispose the models using them first. */
80
+ clear(): void;
81
+ }
package/character.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import type { PedEntry, PieceEntry } from "./assets";
2
+ import type { ModelLoader } from "./loader";
3
+ import { Model } from "./model";
4
+ /** A worn piece and its texture variant. */
5
+ interface Selection {
6
+ piece: PieceEntry;
7
+ variant?: string;
8
+ }
9
+ /** A character made of a skeleton with swappable clothing and props. */
10
+ export declare class Character extends Model {
11
+ /** The character's manifest entry. */
12
+ readonly entry: PedEntry;
13
+ private readonly loader;
14
+ readonly view: readonly [0.3, 0.08, 0.95];
15
+ private readonly worn;
16
+ private readonly selection;
17
+ private readonly revisions;
18
+ private constructor();
19
+ static load(name: string, entry: PedEntry, loader: ModelLoader): Promise<Character>;
20
+ /** Returns the piece worn in a component slot, or in a prop slot named `p_<component>`. */
21
+ selected(slot: string): Selection | undefined;
22
+ /** Wears a clothing piece, or removes it with `null`. Uses the first texture variant by default. */
23
+ setComponent(component: string, piece: PieceEntry | null, variant?: string): Promise<void>;
24
+ /** Wears a prop, or removes it with `null`. Uses the first texture variant by default. */
25
+ setProp(component: string, piece: PieceEntry | null, variant?: string): Promise<void>;
26
+ /** Removes all clothing and frees the character. */
27
+ dispose(): void;
28
+ private wearDefaults;
29
+ private wear;
30
+ }
31
+ export {};
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export { Assets, type ModEntry, type ModelEntry, type ModelKind, type PedEntry, type PieceEntry, type VehicleEntry, type WheelEntry } from "./assets";
2
+ export { Character } from "./character";
3
+ export { Model } from "./model";
4
+ export { Stage, ThumbnailRenderer, type StageOptions, type ThumbnailFormat } from "./stage";
5
+ export { Vehicle, type Color, type Opening, type PaintName, type VehicleProps } from "./vehicle";