katachi-runtime 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.
- package/README.md +11 -2
- package/assets.d.ts +5 -3
- package/index.d.ts +1 -1
- package/index.js +51 -19
- package/loader.d.ts +1 -0
- package/package.json +1 -1
- package/stage.d.ts +1 -0
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ Open the address it prints to browse what you converted. Click a model to try it
|
|
|
22
22
|
| --- | --- |
|
|
23
23
|
| `bun run convert <files or folders>` | Converts `.rpf`, `.yft`, `.ydr`, `.ydd`, `.ytd`, `.ytyp`, `.meta` and `.ymt` files into `out/`. |
|
|
24
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 pack <folder> <web folder>` | Prepares a converted folder for the web. Each vehicle and character moves into its own small file that loads when it is first shown, so the index stays small however many models there are. Files are linked rather than copied when both folders are on one disk. |
|
|
25
26
|
| `bun run dev [folder]` | Starts the playground. Shows `out/` unless you name another folder. |
|
|
26
27
|
|
|
27
28
|
### Convert options
|
|
@@ -47,6 +48,14 @@ When a model exists more than once, the first input wins, so list mods before th
|
|
|
47
48
|
|
|
48
49
|
Without Chrome or Edge, run `bunx playwright install chromium` once.
|
|
49
50
|
|
|
51
|
+
### Pack options
|
|
52
|
+
|
|
53
|
+
| Option | Description |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| `--only <file>` | Keeps only the models named in this file, one per line, with the parts, wheels and textures they use. |
|
|
56
|
+
|
|
57
|
+
Packing again into the same folder adds what is new and rewrites the index last. It stops without writing an index if a file the models use is missing.
|
|
58
|
+
|
|
50
59
|
### Encrypted archives
|
|
51
60
|
|
|
52
61
|
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`.
|
|
@@ -63,7 +72,7 @@ bun run convert path/to/game --keys path/to/keys --only models.txt
|
|
|
63
72
|
|
|
64
73
|
## Runtime
|
|
65
74
|
|
|
66
|
-
`katachi-runtime` shows converted models with [three.js](https://threejs.org).
|
|
75
|
+
`katachi-runtime` shows converted models with [three.js](https://threejs.org). Pack your output folder with `bun run pack`, then upload the packed folder to any static host, such as Cloudflare R2 with CORS enabled. Every file but `manifest.json.gz` is content-hashed, so it can be cached forever; upload `manifest.json.gz` last, with a short cache time. The runtime also opens an unpacked output folder, as the playground does.
|
|
67
76
|
|
|
68
77
|
```sh
|
|
69
78
|
npm install katachi-runtime three@0.187.0
|
|
@@ -165,7 +174,7 @@ class Character extends Model {
|
|
|
165
174
|
|
|
166
175
|
class ThumbnailRenderer {
|
|
167
176
|
constructor(size?: number, format?: "png" | "webp"); // defaults to 512 and png
|
|
168
|
-
render(model: Model, view?: [number, number, number]): Promise<Blob>; // transparent image that the model fills, from model.view unless given
|
|
177
|
+
render(model: Model, view?: [number, number, number]): Promise<Blob>; // transparent image that the model's body fills (a neon glow spills past it), from model.view unless given
|
|
169
178
|
dispose(): void;
|
|
170
179
|
}
|
|
171
180
|
```
|
package/assets.d.ts
CHANGED
|
@@ -46,13 +46,13 @@ export interface PedEntry {
|
|
|
46
46
|
components: PieceEntry[];
|
|
47
47
|
props: PieceEntry[];
|
|
48
48
|
}
|
|
49
|
-
/** The index of every converted asset. */
|
|
49
|
+
/** The index of every converted asset. In version 3, made by `bun run pack`, each vehicle and character is a path to its own entry file. */
|
|
50
50
|
export interface Manifest {
|
|
51
51
|
version: number;
|
|
52
|
-
vehicles: Record<string, VehicleEntry>;
|
|
52
|
+
vehicles: Record<string, VehicleEntry | string>;
|
|
53
53
|
/** Wheels by the game's wheel type. */
|
|
54
54
|
wheels: WheelEntry[][];
|
|
55
|
-
peds: Record<string, PedEntry>;
|
|
55
|
+
peds: Record<string, PedEntry | string>;
|
|
56
56
|
/** Paths of standalone objects, by name. */
|
|
57
57
|
models: Record<string, string>;
|
|
58
58
|
/** Paths of map pieces, such as buildings, rooms and interior layers, by name. */
|
|
@@ -71,6 +71,7 @@ export declare class Assets {
|
|
|
71
71
|
private readonly loader;
|
|
72
72
|
/** Every model in the folder: vehicles, characters, objects, then map pieces, each sorted by name. */
|
|
73
73
|
readonly models: ModelEntry[];
|
|
74
|
+
private readonly entries;
|
|
74
75
|
private constructor();
|
|
75
76
|
/** Opens an assets folder. `baseUrl` must end with a slash. */
|
|
76
77
|
static open(baseUrl: string): Promise<Assets>;
|
|
@@ -78,4 +79,5 @@ export declare class Assets {
|
|
|
78
79
|
load(name: string, props?: VehicleProps): Promise<Model>;
|
|
79
80
|
/** Frees every shared texture and clothing piece. Dispose the models using them first. */
|
|
80
81
|
clear(): void;
|
|
82
|
+
private entry;
|
|
81
83
|
}
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Assets, type ModEntry, type ModelEntry, type ModelKind, type PedEntry, type PieceEntry, type VehicleEntry, type WheelEntry } from "./assets";
|
|
1
|
+
export { Assets, type Manifest, type ModEntry, type ModelEntry, type ModelKind, type PedEntry, type PieceEntry, type VehicleEntry, type WheelEntry } from "./assets";
|
|
2
2
|
export { Character } from "./character";
|
|
3
3
|
export { Model } from "./model";
|
|
4
4
|
export { Stage, ThumbnailRenderer, type Direction, type StageInset, type StageLighting, type StageOptions, type ThumbnailFormat } from "./stage";
|
package/index.js
CHANGED
|
@@ -1170,6 +1170,9 @@ class ModelLoader {
|
|
|
1170
1170
|
texture(path) {
|
|
1171
1171
|
return this.library.load(path, "color");
|
|
1172
1172
|
}
|
|
1173
|
+
async json(path) {
|
|
1174
|
+
return JSON.parse(new TextDecoder().decode(await fetchBytes(`${this.baseUrl}${path}`)));
|
|
1175
|
+
}
|
|
1173
1176
|
async load(path, paints = this.sharedPaints, diffuse) {
|
|
1174
1177
|
const gltf = await this.gltf.parseAsync(await fetchBytes(`${this.baseUrl}${path}`), this.baseUrl);
|
|
1175
1178
|
const scene = gltf.scene;
|
|
@@ -1570,6 +1573,7 @@ class Vehicle extends Model {
|
|
|
1570
1573
|
this.neon = new THREE4.Mesh(new THREE4.PlaneGeometry(size.x * 1.7, size.z * 1.35), new THREE4.MeshBasicMaterial({ map: glowTexture(), transparent: true, depthWrite: false }));
|
|
1571
1574
|
this.neon.rotation.x = -Math.PI / 2;
|
|
1572
1575
|
this.neon.position.set(center.x, box.min.y + size.y * 0.01, center.z);
|
|
1576
|
+
this.neon.userData.decoration = true;
|
|
1573
1577
|
this.root.add(this.neon);
|
|
1574
1578
|
}
|
|
1575
1579
|
setColor(this.neon.material.color, color);
|
|
@@ -1623,21 +1627,24 @@ class Vehicle extends Model {
|
|
|
1623
1627
|
|
|
1624
1628
|
// src/assets.ts
|
|
1625
1629
|
var SECTIONS = { vehicle: "vehicles", character: "peds", object: "models", map: "map" };
|
|
1630
|
+
var VERSIONS = [2, 3];
|
|
1626
1631
|
|
|
1627
1632
|
class Assets {
|
|
1628
1633
|
manifest;
|
|
1629
1634
|
loader;
|
|
1630
1635
|
models;
|
|
1636
|
+
entries = new Map;
|
|
1631
1637
|
constructor(manifest, loader) {
|
|
1632
1638
|
this.manifest = manifest;
|
|
1633
1639
|
this.loader = loader;
|
|
1634
1640
|
this.models = Object.keys(SECTIONS).flatMap((kind) => Object.keys(manifest[SECTIONS[kind]]).sort().map((name) => ({ kind, name })));
|
|
1635
1641
|
}
|
|
1636
1642
|
static async open(baseUrl) {
|
|
1637
|
-
const
|
|
1638
|
-
|
|
1643
|
+
const loader = new ModelLoader(baseUrl);
|
|
1644
|
+
const manifest = await loader.json("manifest.json.gz");
|
|
1645
|
+
if (!VERSIONS.includes(manifest.version))
|
|
1639
1646
|
throw new Error(`Unsupported manifest version ${manifest.version}`);
|
|
1640
|
-
return new Assets(manifest,
|
|
1647
|
+
return new Assets(manifest, loader);
|
|
1641
1648
|
}
|
|
1642
1649
|
async load(name, props) {
|
|
1643
1650
|
const { manifest, loader } = this;
|
|
@@ -1645,10 +1652,10 @@ class Assets {
|
|
|
1645
1652
|
if (!kind)
|
|
1646
1653
|
throw new Error(`${name} is not in these assets`);
|
|
1647
1654
|
if (kind === "character")
|
|
1648
|
-
return Character.load(name, manifest.peds[name], loader);
|
|
1655
|
+
return Character.load(name, await this.entry(manifest.peds[name]), loader);
|
|
1649
1656
|
if (kind !== "vehicle")
|
|
1650
1657
|
return new Model(name, await loader.load(manifest[SECTIONS[kind]][name]));
|
|
1651
|
-
const vehicle = await Vehicle.load(name, manifest.vehicles[name], manifest.wheels, loader);
|
|
1658
|
+
const vehicle = await Vehicle.load(name, await this.entry(manifest.vehicles[name]), manifest.wheels, loader);
|
|
1652
1659
|
if (props)
|
|
1653
1660
|
await vehicle.apply(props);
|
|
1654
1661
|
return vehicle;
|
|
@@ -1656,6 +1663,17 @@ class Assets {
|
|
|
1656
1663
|
clear() {
|
|
1657
1664
|
this.loader.clear();
|
|
1658
1665
|
}
|
|
1666
|
+
entry(entry) {
|
|
1667
|
+
if (typeof entry !== "string")
|
|
1668
|
+
return Promise.resolve(entry);
|
|
1669
|
+
let loaded = this.entries.get(entry);
|
|
1670
|
+
if (!loaded) {
|
|
1671
|
+
loaded = this.loader.json(entry);
|
|
1672
|
+
this.entries.set(entry, loaded);
|
|
1673
|
+
loaded.catch(() => this.entries.delete(entry));
|
|
1674
|
+
}
|
|
1675
|
+
return loaded;
|
|
1676
|
+
}
|
|
1659
1677
|
}
|
|
1660
1678
|
// src/stage.ts
|
|
1661
1679
|
import * as THREE6 from "three";
|
|
@@ -2145,28 +2163,42 @@ class ThumbnailRenderer {
|
|
|
2145
2163
|
this.lighting.fit(radius);
|
|
2146
2164
|
this.scene.add(model.root);
|
|
2147
2165
|
try {
|
|
2148
|
-
this.draw(model
|
|
2166
|
+
this.draw(model);
|
|
2149
2167
|
} finally {
|
|
2150
2168
|
this.scene.remove(model.root);
|
|
2151
2169
|
this.camera.clearViewOffset();
|
|
2152
2170
|
}
|
|
2153
2171
|
return new Promise((resolve, reject) => this.renderer.domElement.toBlob((blob) => blob ? resolve(blob) : reject(new Error(`Could not encode ${model.name}`)), `image/${this.format}`, WEBP_QUALITY));
|
|
2154
2172
|
}
|
|
2155
|
-
draw(
|
|
2173
|
+
draw(model) {
|
|
2174
|
+
const decorations = [];
|
|
2175
|
+
model.root.traverse((object) => {
|
|
2176
|
+
if (object.visible && object.userData.decoration)
|
|
2177
|
+
decorations.push(object);
|
|
2178
|
+
});
|
|
2156
2179
|
let frame = { x: 0, y: 0, side: this.size };
|
|
2157
|
-
for (
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2180
|
+
for (const object of decorations)
|
|
2181
|
+
object.visible = false;
|
|
2182
|
+
try {
|
|
2183
|
+
for (let pass = 1;pass < FRAMING_PASSES; pass++) {
|
|
2184
|
+
this.shoot(frame);
|
|
2185
|
+
const fitted = this.fit(frame);
|
|
2186
|
+
if (!fitted)
|
|
2187
|
+
throw new Error(`${model.name} has nothing to show`);
|
|
2188
|
+
const pixel = frame.side / this.size;
|
|
2189
|
+
if (Math.max(Math.abs(fitted.x - frame.x), Math.abs(fitted.y - frame.y), Math.abs(fitted.side - frame.side)) < 2 * pixel)
|
|
2190
|
+
break;
|
|
2191
|
+
frame = fitted;
|
|
2192
|
+
}
|
|
2193
|
+
} finally {
|
|
2194
|
+
for (const object of decorations)
|
|
2195
|
+
object.visible = true;
|
|
2169
2196
|
}
|
|
2197
|
+
this.shoot(frame);
|
|
2198
|
+
}
|
|
2199
|
+
shoot({ x, y, side }) {
|
|
2200
|
+
this.camera.setViewOffset(this.size, this.size, x, y, side, side);
|
|
2201
|
+
this.renderer.render(this.scene, this.camera);
|
|
2170
2202
|
}
|
|
2171
2203
|
fit(frame) {
|
|
2172
2204
|
const { size, pixels } = this;
|
package/loader.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare class ModelLoader {
|
|
|
23
23
|
private readonly sharedPaints;
|
|
24
24
|
constructor(baseUrl: string);
|
|
25
25
|
texture(path: string): Promise<THREE.Texture>;
|
|
26
|
+
json<T>(path: string): Promise<T>;
|
|
26
27
|
load(path: string, paints?: Paints, diffuse?: string): Promise<LoadedModel>;
|
|
27
28
|
clear(): void;
|
|
28
29
|
piece(piece: PieceEntry, variant: string | undefined): Promise<LoadedModel>;
|
package/package.json
CHANGED
package/stage.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ export declare class ThumbnailRenderer {
|
|
|
72
72
|
/** Renders a model from `view`, filling the image. */
|
|
73
73
|
render(model: Model, view?: readonly [number, number, number]): Promise<Blob>;
|
|
74
74
|
private draw;
|
|
75
|
+
private shoot;
|
|
75
76
|
private fit;
|
|
76
77
|
/** Frees the renderer and its lighting. */
|
|
77
78
|
dispose(): void;
|