katachi-runtime 0.2.1 → 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 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). 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.
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;
@@ -1624,21 +1627,24 @@ class Vehicle extends Model {
1624
1627
 
1625
1628
  // src/assets.ts
1626
1629
  var SECTIONS = { vehicle: "vehicles", character: "peds", object: "models", map: "map" };
1630
+ var VERSIONS = [2, 3];
1627
1631
 
1628
1632
  class Assets {
1629
1633
  manifest;
1630
1634
  loader;
1631
1635
  models;
1636
+ entries = new Map;
1632
1637
  constructor(manifest, loader) {
1633
1638
  this.manifest = manifest;
1634
1639
  this.loader = loader;
1635
1640
  this.models = Object.keys(SECTIONS).flatMap((kind) => Object.keys(manifest[SECTIONS[kind]]).sort().map((name) => ({ kind, name })));
1636
1641
  }
1637
1642
  static async open(baseUrl) {
1638
- const manifest = JSON.parse(new TextDecoder().decode(await fetchBytes(`${baseUrl}manifest.json.gz`)));
1639
- if (manifest.version !== 2)
1643
+ const loader = new ModelLoader(baseUrl);
1644
+ const manifest = await loader.json("manifest.json.gz");
1645
+ if (!VERSIONS.includes(manifest.version))
1640
1646
  throw new Error(`Unsupported manifest version ${manifest.version}`);
1641
- return new Assets(manifest, new ModelLoader(baseUrl));
1647
+ return new Assets(manifest, loader);
1642
1648
  }
1643
1649
  async load(name, props) {
1644
1650
  const { manifest, loader } = this;
@@ -1646,10 +1652,10 @@ class Assets {
1646
1652
  if (!kind)
1647
1653
  throw new Error(`${name} is not in these assets`);
1648
1654
  if (kind === "character")
1649
- return Character.load(name, manifest.peds[name], loader);
1655
+ return Character.load(name, await this.entry(manifest.peds[name]), loader);
1650
1656
  if (kind !== "vehicle")
1651
1657
  return new Model(name, await loader.load(manifest[SECTIONS[kind]][name]));
1652
- 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);
1653
1659
  if (props)
1654
1660
  await vehicle.apply(props);
1655
1661
  return vehicle;
@@ -1657,6 +1663,17 @@ class Assets {
1657
1663
  clear() {
1658
1664
  this.loader.clear();
1659
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
+ }
1660
1677
  }
1661
1678
  // src/stage.ts
1662
1679
  import * as THREE6 from "three";
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "katachi-runtime",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Show converted GTA V models in the browser with three.js.",
5
5
  "type": "module",
6
6
  "exports": {