katachi-runtime 0.0.0-stage → 0.1.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/loader.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ import * as THREE from "three";
2
+ import type { PieceEntry } from "./assets";
3
+ import { type Paints } from "./material";
4
+ export type TextureRole = "color" | "data";
5
+ export declare function fetchBytes(url: string): Promise<ArrayBuffer>;
6
+ export declare class TextureLibrary {
7
+ private readonly baseUrl;
8
+ private readonly loaded;
9
+ constructor(baseUrl: string);
10
+ load(path: string, role: TextureRole): Promise<THREE.Texture>;
11
+ clear(): void;
12
+ private fetchTexture;
13
+ }
14
+ export interface LoadedModel {
15
+ scene: THREE.Group;
16
+ materials: THREE.MeshPhysicalMaterial[];
17
+ }
18
+ export declare class ModelLoader {
19
+ private readonly baseUrl;
20
+ private readonly gltf;
21
+ private readonly library;
22
+ private readonly pieces;
23
+ private readonly sharedPaints;
24
+ constructor(baseUrl: string);
25
+ texture(path: string): Promise<THREE.Texture>;
26
+ load(path: string, paints?: Paints, diffuse?: string): Promise<LoadedModel>;
27
+ clear(): void;
28
+ piece(piece: PieceEntry, variant: string | undefined): Promise<LoadedModel>;
29
+ }
package/material.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import * as THREE from "three";
2
+ import type { TextureLibrary } from "./loader";
3
+ export interface MaterialExtras {
4
+ shader: string;
5
+ bucket: number;
6
+ textures: Record<string, string>;
7
+ missingDiffuse?: string;
8
+ parameters: Record<string, number[]>;
9
+ }
10
+ type PaintUniform = {
11
+ value: THREE.Color;
12
+ };
13
+ export type Paints = Map<number, PaintUniform>;
14
+ export declare function createPaints(): Paints;
15
+ export interface SecondMap {
16
+ value: THREE.Texture | null;
17
+ }
18
+ export declare function buildMaterial(extras: MaterialExtras, geometry: THREE.BufferGeometry, paints: Paints, library: TextureLibrary): Promise<THREE.MeshPhysicalMaterial>;
19
+ export {};
package/model.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import * as THREE from "three";
2
+ import type { LoadedModel } from "./loader";
3
+ export declare function disposeMesh(object: THREE.Object3D): void;
4
+ export declare function prepareMesh(mesh: THREE.Mesh): void;
5
+ export type RestPose = Map<THREE.Object3D, {
6
+ world: THREE.Matrix4;
7
+ }>;
8
+ export declare function attachModel(model: LoadedModel, bones: Map<string, THREE.Object3D>, root: THREE.Object3D, anchor: THREE.Object3D, rest?: RestPose): THREE.Mesh[];
9
+ export declare function detach(objects: Iterable<THREE.Object3D>): void;
10
+ /** Any converted 3D model. */
11
+ export declare class Model {
12
+ readonly name: string;
13
+ protected readonly source: LoadedModel;
14
+ /** The object to add to a three.js scene. */
15
+ readonly root: THREE.Group<THREE.Object3DEventMap>;
16
+ /** Every named node in the model, by name. */
17
+ readonly bones: Map<string, THREE.Object3D<THREE.Object3DEventMap>>;
18
+ /** The direction, from the model's center, that it is best viewed from. */
19
+ readonly view: readonly [number, number, number];
20
+ /** Wraps a model returned by `ModelLoader.load`. */
21
+ constructor(name: string, source: LoadedModel);
22
+ /** Moves the model to stand centered on the origin, and returns its bounds there. */
23
+ placeAtOrigin(): THREE.Box3;
24
+ /** Frees the model's geometry and materials. */
25
+ dispose(): void;
26
+ }
package/package.json CHANGED
@@ -1,6 +1,13 @@
1
1
  {
2
2
  "name": "katachi-runtime",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Show converted GTA V models in the browser with three.js.",
5
+ "type": "module",
6
+ "exports": {
7
+ "types": "./index.d.ts",
8
+ "default": "./index.js"
9
+ },
10
+ "peerDependencies": {
11
+ "three": "0.187.0"
12
+ }
6
13
  }
package/stage.d.ts ADDED
@@ -0,0 +1,49 @@
1
+ import type { Assets } from "./assets";
2
+ import type { Model } from "./model";
3
+ import type { VehicleProps } from "./vehicle";
4
+ export interface StageOptions {
5
+ autoRotate?: boolean;
6
+ zoom?: boolean;
7
+ }
8
+ /** An interactive 3D view of one model, drawn on a canvas. Drag to orbit, scroll to zoom. */
9
+ export declare class Stage {
10
+ private readonly canvas;
11
+ private readonly renderer;
12
+ private readonly scene;
13
+ private readonly camera;
14
+ private readonly controls;
15
+ private readonly lighting;
16
+ private readonly ground;
17
+ private readonly resizer;
18
+ private readonly watcher;
19
+ private subject;
20
+ private showing;
21
+ private visible;
22
+ constructor(canvas: HTMLCanvasElement, options?: StageOptions);
23
+ /** Loads a model and shows it in place of the current one. Resolves to `undefined` if another model was shown meanwhile. */
24
+ show(assets: Assets, name: string, props?: VehicleProps): Promise<Model | undefined>;
25
+ /** Frees the renderer and the model on show. */
26
+ dispose(): void;
27
+ private readonly stopRotating;
28
+ private frame;
29
+ private resize;
30
+ }
31
+ export type ThumbnailFormat = "png" | "webp";
32
+ /** Renders models to square images with a transparent background. */
33
+ export declare class ThumbnailRenderer {
34
+ readonly size: number;
35
+ readonly format: ThumbnailFormat;
36
+ private readonly renderer;
37
+ private readonly scene;
38
+ private readonly camera;
39
+ private readonly lighting;
40
+ private readonly pixels;
41
+ /** Creates a renderer for images of this many pixels per side. */
42
+ constructor(size?: number, format?: ThumbnailFormat);
43
+ /** Renders a model from `view`, filling the image. */
44
+ render(model: Model, view?: readonly [number, number, number]): Promise<Blob>;
45
+ private draw;
46
+ private fit;
47
+ /** Frees the renderer and its lighting. */
48
+ dispose(): void;
49
+ }
package/texture.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ export declare const enum VkFormat {
2
+ BC1 = 133,
3
+ BC2 = 135,
4
+ BC3 = 137,
5
+ BC4 = 139,
6
+ BC5 = 141,
7
+ BC7 = 145
8
+ }
9
+ interface Ktx2Level {
10
+ data: Uint8Array;
11
+ width: number;
12
+ height: number;
13
+ }
14
+ export interface Ktx2Image {
15
+ format: VkFormat;
16
+ width: number;
17
+ height: number;
18
+ levels: Ktx2Level[];
19
+ }
20
+ export declare function parseKtx2(buffer: ArrayBuffer): Ktx2Image;
21
+ export declare function decodeBlocks(format: VkFormat, src: Uint8Array, width: number, height: number): Uint8Array<ArrayBuffer>;
22
+ export {};
package/vehicle.d.ts ADDED
@@ -0,0 +1,123 @@
1
+ import type { ModEntry, VehicleEntry, WheelEntry } from "./assets";
2
+ import type { ModelLoader } from "./loader";
3
+ import { Model } from "./model";
4
+ declare const PAINT_SLOTS: {
5
+ readonly primary: 1;
6
+ readonly secondary: 2;
7
+ readonly pearlescent: 3;
8
+ readonly wheel: 4;
9
+ readonly interior: 6;
10
+ readonly dashboard: 7;
11
+ };
12
+ /** A vehicle's paint slots. */
13
+ export type PaintName = keyof typeof PAINT_SLOTS;
14
+ declare const OPENINGS: {
15
+ readonly frontLeft: {
16
+ readonly bone: "door_dside_f";
17
+ readonly fallback: readonly [0, 0, number];
18
+ };
19
+ readonly frontRight: {
20
+ readonly bone: "door_pside_f";
21
+ readonly fallback: readonly [0, 0, 1.239];
22
+ };
23
+ readonly rearLeft: {
24
+ readonly bone: "door_dside_r";
25
+ readonly fallback: readonly [0, 0, number];
26
+ };
27
+ readonly rearRight: {
28
+ readonly bone: "door_pside_r";
29
+ readonly fallback: readonly [0, 0, 1.239];
30
+ };
31
+ readonly bonnet: {
32
+ readonly bone: "bonnet";
33
+ readonly fallback: readonly [1.239, 0, 0];
34
+ };
35
+ readonly boot: {
36
+ readonly bone: "boot";
37
+ readonly fallback: readonly [number, 0, 0];
38
+ };
39
+ };
40
+ /** A door or panel that can open. */
41
+ export type Opening = keyof typeof OPENINGS;
42
+ /** A color: a game color ID, any CSS color, or `[red, green, blue]` from 0 to 255. */
43
+ export type Color = number | string | readonly [number, number, number];
44
+ /** Vehicle state, using the same numbers as the game. Everything is optional. */
45
+ export type VehicleProps = Partial<Record<PaintName, Color>> & {
46
+ plate?: string;
47
+ /** Index into `wraps()`, or `null` for none. */
48
+ wrap?: number | null;
49
+ /** The option to fit in each game mod slot, or `null` for stock. */
50
+ mods?: Record<number, number | null>;
51
+ extras?: Record<number, boolean>;
52
+ /** The game's window tint ID: 0 none, 1 pure black, 2 dark smoke, 3 light smoke, 4 stock, 5 limo, 6 green. */
53
+ windowTint?: number;
54
+ /** The game's wheel type, which chooses the list that `mods[23]` picks from. */
55
+ wheelType?: number;
56
+ /** Underglow color, or `null` for none. */
57
+ neon?: Color | null;
58
+ lights?: boolean;
59
+ };
60
+ /** A vehicle with paint, tuning, opening parts, extras and a license plate. */
61
+ export declare class Vehicle extends Model {
62
+ /** The vehicle's manifest entry. */
63
+ readonly entry: VehicleEntry;
64
+ private readonly wheelTypes;
65
+ private readonly paints;
66
+ private readonly loader;
67
+ readonly view: readonly [-0.6, 0.25, -0.75];
68
+ private readonly rest;
69
+ private readonly hidden;
70
+ private readonly extraStates;
71
+ private readonly worn;
72
+ private readonly revisions;
73
+ private readonly stockLivery;
74
+ private plate;
75
+ private neon;
76
+ private wheelType;
77
+ private fittedWheels;
78
+ private constructor();
79
+ static load(name: string, entry: VehicleEntry, wheels: WheelEntry[][], loader: ModelLoader): Promise<Vehicle>;
80
+ /** Applies any mix of paint, plate, wrap, tuning, extras and window tint at once. */
81
+ apply(props: VehicleProps): Promise<void>;
82
+ /** Sets the color of a paint slot. Unknown game color IDs are ignored. */
83
+ setPaint(name: PaintName, color: Color): void;
84
+ /** Returns the color of a paint slot as a hex string. */
85
+ paint(name: PaintName): string;
86
+ /** Sets the license plate text. */
87
+ setPlate(text: string): void;
88
+ /** Lists the doors and panels this vehicle can open. */
89
+ openings(): Opening[];
90
+ /** Opens a door or panel, from 0 (closed) to 1 (fully open). */
91
+ setOpen(name: Opening, amount: number): void;
92
+ /** Lists this vehicle's extra IDs. */
93
+ extras(): number[];
94
+ /** Returns whether an extra is shown. */
95
+ extraEnabled(id: number): boolean;
96
+ /** Shows or hides an extra. */
97
+ setExtra(id: number, enabled: boolean): void;
98
+ /** Lists this vehicle's wraps by name. Empty when it has none. */
99
+ wraps(): string[];
100
+ /** Applies a wrap by its index in `wraps()`, or removes it with `null`. */
101
+ setWrap(index: number | null): Promise<void>;
102
+ /** Lists the tuning options of each game mod slot, not counting wraps. */
103
+ mods(): Map<number, ModEntry[]>;
104
+ /** Lists the wheels of each game wheel type. */
105
+ wheels(): WheelEntry[][];
106
+ /** Fits a wheel from a game wheel type, or restores the stock wheels with `null`. */
107
+ setWheels(type: number, option: number | null): Promise<void>;
108
+ /** Fits the option at this index of a game mod slot, or restores the stock part with `null`. Slot 23 picks from the current wheel type. */
109
+ setMod(slot: number, option: number | null): Promise<void>;
110
+ /** Sets the window tint, using the game's tint IDs. */
111
+ setWindowTint(id: number): void;
112
+ /** Shows a colored glow under the vehicle, or removes it with `null`. */
113
+ setNeon(color: Color | null): void;
114
+ /** Turns the headlights and taillights on or off. */
115
+ setLights(on: boolean): void;
116
+ /** Frees the vehicle, its fitted parts and its plate. */
117
+ dispose(): void;
118
+ private linkedMod;
119
+ private options;
120
+ private removeMod;
121
+ private applyWrap;
122
+ }
123
+ export {};