@matchomag/cs2-replay 0.0.0-stage → 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/FORMAT.md +350 -0
- package/README.md +453 -2
- package/bin/demo-replay-darwin-amd64 +0 -0
- package/bin/demo-replay-darwin-arm64 +0 -0
- package/bin/demo-replay-linux-amd64 +0 -0
- package/bin/demo-replay-linux-arm64 +0 -0
- package/bin/demo-replay-windows-amd64.exe +0 -0
- package/bin/demo-replay.js +22 -0
- package/dist/2d/index.js +1 -0
- package/dist/3d/index.js +11 -0
- package/dist/chunks/actors-EZRYEB4I.js +177 -0
- package/dist/chunks/chunk-5BFKVD63.js +1 -0
- package/dist/chunks/chunk-D5ST2XVO.js +106 -0
- package/dist/chunks/chunk-DQPOBPMK.js +1 -0
- package/dist/chunks/chunk-FBSLUYGT.js +1 -0
- package/dist/chunks/chunk-Q37CWKZX.js +12 -0
- package/dist/chunks/chunk-VSIECNZM.js +1 -0
- package/dist/chunks/chunk-YJG3LSSB.js +1 -0
- package/dist/chunks/chunk-YO73RW3Y.js +1 -0
- package/dist/chunks/look-2WBUGHMJ.js +669 -0
- package/dist/index.js +1 -0
- package/dist/maps/index.js +1 -0
- package/dist/parse/index.js +1 -0
- package/dist/parse/wasm/replay.wasm +0 -0
- package/dist/parse/worker.js +1 -0
- package/dist/types/2d/index.d.ts +17 -0
- package/dist/types/2d/radar.d.ts +35 -0
- package/dist/types/3d/actors.d.ts +90 -0
- package/dist/types/3d/characters/anim.d.ts +93 -0
- package/dist/types/3d/characters/ao.d.ts +3 -0
- package/dist/types/3d/characters/body.d.ts +37 -0
- package/dist/types/3d/characters/builder.d.ts +82 -0
- package/dist/types/3d/characters/index.d.ts +74 -0
- package/dist/types/3d/characters/rig.d.ts +73 -0
- package/dist/types/3d/characters/textures.d.ts +4 -0
- package/dist/types/3d/characters/viewmodel.d.ts +51 -0
- package/dist/types/3d/characters/weapons.d.ts +25 -0
- package/dist/types/3d/follow.d.ts +43 -0
- package/dist/types/3d/fx/batch.d.ts +87 -0
- package/dist/types/3d/fx/context.d.ts +34 -0
- package/dist/types/3d/fx/explosion.d.ts +14 -0
- package/dist/types/3d/fx/fire.d.ts +11 -0
- package/dist/types/3d/fx/index.d.ts +84 -0
- package/dist/types/3d/fx/lights.d.ts +25 -0
- package/dist/types/3d/fx/meshes.d.ts +18 -0
- package/dist/types/3d/fx/misc.d.ts +15 -0
- package/dist/types/3d/fx/random.d.ts +21 -0
- package/dist/types/3d/fx/smoke.d.ts +10 -0
- package/dist/types/3d/fx/textures.d.ts +29 -0
- package/dist/types/3d/fx/types.d.ts +117 -0
- package/dist/types/3d/greybox.d.ts +22 -0
- package/dist/types/3d/index.d.ts +127 -0
- package/dist/types/3d/look.d.ts +49 -0
- package/dist/types/3d/markers.d.ts +23 -0
- package/dist/types/3d/smoke/volume.d.ts +95 -0
- package/dist/types/3d/smoke/voxels.d.ts +87 -0
- package/dist/types/3d/world/index.d.ts +179 -0
- package/dist/types/3d/world/look.d.ts +16 -0
- package/dist/types/3d/world/material.d.ts +128 -0
- package/dist/types/3d/world/post.d.ts +75 -0
- package/dist/types/3d/world/probes.d.ts +39 -0
- package/dist/types/3d/world/release.d.ts +28 -0
- package/dist/types/3d/world/stage.d.ts +84 -0
- package/dist/types/core/format.d.ts +163 -0
- package/dist/types/core/live.d.ts +115 -0
- package/dist/types/core/model.d.ts +164 -0
- package/dist/types/core/playback.d.ts +82 -0
- package/dist/types/core/theme.d.ts +46 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/maps/index.d.ts +258 -0
- package/dist/types/parse/index.d.ts +108 -0
- package/dist/types/ui/shell.d.ts +131 -0
- package/dist/types/ui/styles.d.ts +1 -0
- package/package.json +68 -4
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import type { Replay } from "../core/format";
|
|
3
|
+
import type { GameMapStore, GameMapTier, LightmapMode } from "../maps";
|
|
4
|
+
import type { GameMapProgress } from "./world";
|
|
5
|
+
import type { GameStage } from "./world/stage";
|
|
6
|
+
import { type CameraView } from "./follow";
|
|
7
|
+
export type { GameStage } from "./world/stage";
|
|
8
|
+
export type { CameraView } from "./follow";
|
|
9
|
+
import { type Viewer, type ViewerEvents, type ViewerOptions } from "../ui/shell";
|
|
10
|
+
export * from "../index";
|
|
11
|
+
export * from "../maps";
|
|
12
|
+
export type { GameMapProgress } from "./world";
|
|
13
|
+
export interface WorldViewerOptions extends ViewerOptions {
|
|
14
|
+
/** The replay to play; leave out to only look at the map. */
|
|
15
|
+
replay?: Replay | null;
|
|
16
|
+
/** URL of the map's grey-box GLB (meshopt compressed is fine). */
|
|
17
|
+
map: string;
|
|
18
|
+
/** The free camera. "fly" (default): click for mouse look, WASD to move. "orbit": drag to rotate. */
|
|
19
|
+
mode?: "fly" | "orbit";
|
|
20
|
+
/** Where the free camera starts: "persp" (default) looks at the map at an angle, "top" straight down. Not the camera view (`setView`). */
|
|
21
|
+
view?: "persp" | "top";
|
|
22
|
+
/** Initial camera position and angles in grey-box metres: x, y, z, yaw°, pitch°. */
|
|
23
|
+
camera?: [number, number, number, number?, number?];
|
|
24
|
+
/** Mesh categories to hide at start (e.g. roof, ceiling). */
|
|
25
|
+
hide?: string[];
|
|
26
|
+
/** Show a panel to toggle mesh categories (keys 1–9). */
|
|
27
|
+
categories?: boolean;
|
|
28
|
+
/** Show the controls help. */
|
|
29
|
+
help?: boolean;
|
|
30
|
+
/** Scene background color. */
|
|
31
|
+
sky?: string;
|
|
32
|
+
/**
|
|
33
|
+
* "greybox" (default): flat-shaded grey-box map. "game": a map converted by
|
|
34
|
+
* scripts/game-map.mjs, rendered with CS2's textures, lightmaps, sky and sun.
|
|
35
|
+
*/
|
|
36
|
+
look?: "greybox" | "game";
|
|
37
|
+
/**
|
|
38
|
+
* How players are drawn, in both looks. "models" (default): animated CT/T characters
|
|
39
|
+
* holding their weapons. "markers": team-coloured capsules, lighter for weak devices.
|
|
40
|
+
*/
|
|
41
|
+
players?: "models" | "markers";
|
|
42
|
+
/** "game" look: where three.js's basis_transcoder.js/.wasm are (KTX2 textures). Defaults to jsDelivr. */
|
|
43
|
+
transcoderPath?: string;
|
|
44
|
+
/**
|
|
45
|
+
* "game" look: "low" drops MSAA, halves the shadow map, renders at one pixel per CSS pixel
|
|
46
|
+
* and thins out particles and smoke steps. Default "high".
|
|
47
|
+
*/
|
|
48
|
+
quality?: "high" | "low";
|
|
49
|
+
/**
|
|
50
|
+
* Pixels per CSS pixel. Default: the screen's, but at most 1.5 in the game look (1 with
|
|
51
|
+
* quality "low"): on a high-DPI screen that's under half the pixels, with MSAA on top.
|
|
52
|
+
*/
|
|
53
|
+
pixelRatio?: number;
|
|
54
|
+
/**
|
|
55
|
+
* "game" look with a packed map (`map` is a manifest.json from scripts/pack-game-map.mjs):
|
|
56
|
+
* the texture tier, default "low". See "@matchomag/cs2-replay/maps" for sizes and support.
|
|
57
|
+
*/
|
|
58
|
+
tier?: GameMapTier;
|
|
59
|
+
/** Packed maps: "auto" (default), or force the "bc" or "compat" lightmaps. */
|
|
60
|
+
lightmaps?: "auto" | LightmapMode;
|
|
61
|
+
/** Packed maps: keep downloaded files on the device (GameMapStore.open()). */
|
|
62
|
+
store?: GameMapStore | null;
|
|
63
|
+
/** "game" look: download progress. Packed maps report bytes of the whole tier. */
|
|
64
|
+
onProgress?: (p: GameMapProgress) => void;
|
|
65
|
+
/**
|
|
66
|
+
* "game" look: keep the JavaScript copies of the map's geometry and textures after they're
|
|
67
|
+
* uploaded to the GPU. By default they're freed (Overpass `low`: ~0.7 GB less page memory),
|
|
68
|
+
* and the map is downloaded again (from the store, if any) if the WebGL context is lost.
|
|
69
|
+
* Set it if you read the map's vertex or texture data, e.g. to raycast against it.
|
|
70
|
+
*/
|
|
71
|
+
keepCpuCopies?: boolean;
|
|
72
|
+
}
|
|
73
|
+
export interface MapInfo {
|
|
74
|
+
url: string;
|
|
75
|
+
drawCalls: number;
|
|
76
|
+
triangles: number;
|
|
77
|
+
/** Bounding box size in metres. */
|
|
78
|
+
size: [number, number, number];
|
|
79
|
+
loadMs: number;
|
|
80
|
+
/** "game" look: textures streamed in (resolves later than `loaded`). */
|
|
81
|
+
textures?: Promise<void>;
|
|
82
|
+
/** Packed maps: the tier and lightmaps in use, and the tier's download size. */
|
|
83
|
+
tier?: GameMapTier;
|
|
84
|
+
lightmapMode?: LightmapMode;
|
|
85
|
+
bytes?: number;
|
|
86
|
+
}
|
|
87
|
+
export interface WorldViewerEvents extends ViewerEvents {
|
|
88
|
+
/** The camera view or the followed player changed: the switch, a key, the roster, the API, or WASD leaving a follow view. */
|
|
89
|
+
view: {
|
|
90
|
+
view: CameraView;
|
|
91
|
+
player: number | null;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export interface WorldViewer extends Viewer {
|
|
95
|
+
/** Resolves once the map is loaded. */
|
|
96
|
+
readonly loaded: Promise<MapInfo>;
|
|
97
|
+
readonly scene: THREE.Scene;
|
|
98
|
+
readonly camera: THREE.PerspectiveCamera;
|
|
99
|
+
/**
|
|
100
|
+
* "game" look: the stage (sun, smoke volumes, CS2 post-processing). Set
|
|
101
|
+
* `gameStage.fixedDelta` when rendering frame by frame (e.g. capturing video) so wind
|
|
102
|
+
* and auto exposure advance per frame instead of in real time. Its code loads on demand,
|
|
103
|
+
* so it's null until then; it's set by the time `loaded` resolves.
|
|
104
|
+
*/
|
|
105
|
+
readonly gameStage: GameStage | null;
|
|
106
|
+
/** The camera view: "first" or "third" follow a player, "free" is the fly or orbit camera. */
|
|
107
|
+
readonly view: CameraView;
|
|
108
|
+
/** The followed player (index into replay.players), null in the free view. */
|
|
109
|
+
readonly followed: number | null;
|
|
110
|
+
/**
|
|
111
|
+
* Switches the camera view. "first" and "third" follow `player` (index into replay.players);
|
|
112
|
+
* without one they keep the followed player, else take the last one followed, else the first
|
|
113
|
+
* alive player. "free" leaves the camera where it is.
|
|
114
|
+
*/
|
|
115
|
+
setView(view: CameraView, player?: number): void;
|
|
116
|
+
/** Same as `setView`: null is "free", else "first" with `pov`, "third" without. */
|
|
117
|
+
setFollow(index: number | null, pov?: boolean): void;
|
|
118
|
+
/** Moves the camera and switches to the free view: grey-box metres, yaw and pitch in degrees. */
|
|
119
|
+
setCamera(x: number, y: number, z: number, yawDeg?: number, pitchDeg?: number): void;
|
|
120
|
+
/** Switches the free camera between fly and orbit, and to the free view. */
|
|
121
|
+
setMode(mode: "fly" | "orbit"): void;
|
|
122
|
+
on<K extends keyof WorldViewerEvents>(event: K, fn: (value: WorldViewerEvents[K]) => void): () => void;
|
|
123
|
+
}
|
|
124
|
+
/** Mounts a 3D replay on a grey-box map inside `host`. Needs three.js. */
|
|
125
|
+
export declare function createWorldViewer(host: HTMLElement, options: WorldViewerOptions): WorldViewer;
|
|
126
|
+
/** Game (x, y, z), Z up -> grey-box world (VRF glTF export): (y, z, x) in metres. */
|
|
127
|
+
export declare const toWorld: (x: number, y: number, z: number, out?: THREE.Vector3) => THREE.Vector3;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type * as THREE from "three";
|
|
2
|
+
import type { FxLighting } from "./fx/types";
|
|
3
|
+
import type { SmokeVolumes } from "./smoke/volume";
|
|
4
|
+
import type { GameStage } from "./world/stage";
|
|
5
|
+
import type { ProbeGrid } from "./world/probes";
|
|
6
|
+
/** How players and effects are lit and drawn on a stage's map. */
|
|
7
|
+
export interface ActorsSetup {
|
|
8
|
+
lighting: FxLighting;
|
|
9
|
+
/** Light players from the map's baked probes. */
|
|
10
|
+
probes?: ProbeGrid | null;
|
|
11
|
+
/** Volumetric smoke; without it smokes are billboard puffs. */
|
|
12
|
+
smoke?: SmokeVolumes | null;
|
|
13
|
+
/** A soft dark disc under each player, for a stage without real-time shadows. */
|
|
14
|
+
blobShadows?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** A map on stage. */
|
|
17
|
+
export interface StageMap {
|
|
18
|
+
root: THREE.Object3D;
|
|
19
|
+
drawCalls: number;
|
|
20
|
+
triangles: number;
|
|
21
|
+
actors: ActorsSetup;
|
|
22
|
+
/** Textures still streaming in (resolves later than the load). */
|
|
23
|
+
textures?: Promise<void>;
|
|
24
|
+
/** The grey-box's mesh categories (roof, ceiling, …), for toggling them. */
|
|
25
|
+
categories?: Map<string, THREE.Mesh[]>;
|
|
26
|
+
/** Packed game maps: the tier, lightmaps and the tier's download size. */
|
|
27
|
+
tier?: import("../maps").GameMapTier;
|
|
28
|
+
lightmapMode?: import("../maps").LightmapMode;
|
|
29
|
+
bytes?: number;
|
|
30
|
+
}
|
|
31
|
+
/** Loads, lights and draws one look's map. Everything else (players, effects, cameras, labels) is shared. */
|
|
32
|
+
export interface MapStage {
|
|
33
|
+
/**
|
|
34
|
+
* True: players and effects go into the scene before the map is shown (`prepare` runs
|
|
35
|
+
* before its shaders compile). False: the map shows as soon as it's loaded and they're
|
|
36
|
+
* added when they're ready.
|
|
37
|
+
*/
|
|
38
|
+
readonly prepareFirst: boolean;
|
|
39
|
+
/** The game look's stage (sun, smoke, post-processing); null for the grey-box. */
|
|
40
|
+
readonly game: GameStage | null;
|
|
41
|
+
/**
|
|
42
|
+
* Loads the map and puts it on stage. With `prepareFirst`, `prepare` runs before it's shown.
|
|
43
|
+
* `arrived` is called once the map is downloaded, if the stage can tell, and it's parsed next.
|
|
44
|
+
*/
|
|
45
|
+
load(url: string, prepare: ((map: StageMap) => Promise<void>) | null, arrived?: () => void): Promise<StageMap>;
|
|
46
|
+
render(): void;
|
|
47
|
+
setSize(width: number, height: number): void;
|
|
48
|
+
dispose(): void;
|
|
49
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import type { PlayerState } from "../core/model";
|
|
3
|
+
import type { Theme } from "../core/theme";
|
|
4
|
+
/**
|
|
5
|
+
* Players as team-coloured capsules with a nose towards their aim, and a cross where they
|
|
6
|
+
* died: the `players: "markers"` option, for devices that struggle with the characters.
|
|
7
|
+
*/
|
|
8
|
+
export declare class PlayerMarkers {
|
|
9
|
+
readonly object: THREE.Group<THREE.Object3DEventMap>;
|
|
10
|
+
private alive;
|
|
11
|
+
private dead;
|
|
12
|
+
private team;
|
|
13
|
+
private grave;
|
|
14
|
+
private nose;
|
|
15
|
+
private key;
|
|
16
|
+
constructor(players: number);
|
|
17
|
+
/** Makes markers for `players` players (a live replay's players join as they come). */
|
|
18
|
+
grow(players: number): void;
|
|
19
|
+
setTheme(theme: Theme, colorOf: (css: string) => THREE.Color): void;
|
|
20
|
+
/** `hidden`: the first-person player, whose own marker isn't drawn. */
|
|
21
|
+
update(p: PlayerState, hidden: boolean): void;
|
|
22
|
+
dispose(): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import type { ProbeGrid } from "../world/probes";
|
|
3
|
+
export interface SmokeInput {
|
|
4
|
+
/** Stable per smoke (grenade index). */
|
|
5
|
+
id: number;
|
|
6
|
+
/** Grid centre in world metres: the game's m_vSmokeDetonationPos, or where it went off. */
|
|
7
|
+
center: THREE.Vector3;
|
|
8
|
+
/** The game's voxel keyframe (see voxels.ts); null to build one from the map. */
|
|
9
|
+
voxels: Uint8Array | null;
|
|
10
|
+
/** Seconds since the smoke went off. */
|
|
11
|
+
age: number;
|
|
12
|
+
/** Seconds until it's gone. */
|
|
13
|
+
remaining: number;
|
|
14
|
+
}
|
|
15
|
+
/** An HE explosion: clears a hole in nearby smoke that refills over a few seconds. */
|
|
16
|
+
export interface SmokeBlast {
|
|
17
|
+
position: THREE.Vector3;
|
|
18
|
+
age: number;
|
|
19
|
+
}
|
|
20
|
+
export interface SmokeLighting {
|
|
21
|
+
/** Towards the sun. */
|
|
22
|
+
sunDirection: THREE.Vector3;
|
|
23
|
+
/** Linear radiance a white surface facing the sun reflects (sun colour × intensity). */
|
|
24
|
+
sunColor: THREE.Color;
|
|
25
|
+
/** Ambient where there are no probes. */
|
|
26
|
+
ambient: THREE.Color;
|
|
27
|
+
probes?: ProbeGrid | null;
|
|
28
|
+
}
|
|
29
|
+
/** Seconds a smoke takes to thin out and dissolve at the end. */
|
|
30
|
+
export declare const SMOKE_DISSOLVE = 3;
|
|
31
|
+
/**
|
|
32
|
+
* CS2-style volumetric smoke. Each cloud fills the game's own voxel grid around walls
|
|
33
|
+
* (voxels.ts) and is ray-marched against the scene's depth, so it never shows through
|
|
34
|
+
* geometry: it pours around corners and through doorways like in game.
|
|
35
|
+
*
|
|
36
|
+
* The march runs at half resolution, inside the screen rectangle the smokes cover, and
|
|
37
|
+
* is upsampled with the scene's depth so edges against walls and players stay sharp.
|
|
38
|
+
* Each cell's self-shadowing (towards the sun and the sky) is baked when the cloud
|
|
39
|
+
* appears, so a step costs one volume lookup plus the detail noise.
|
|
40
|
+
*
|
|
41
|
+
* Call update() every frame, then render() after the scene when `enabled`.
|
|
42
|
+
*/
|
|
43
|
+
export declare class SmokeVolumes {
|
|
44
|
+
readonly camera: THREE.PerspectiveCamera;
|
|
45
|
+
private clouds;
|
|
46
|
+
/** The voxel data each cloud was built from: a live replay's smoke gets more as it spreads. */
|
|
47
|
+
private cloudSrc;
|
|
48
|
+
private slotOf;
|
|
49
|
+
private slotId;
|
|
50
|
+
private atlas;
|
|
51
|
+
private world;
|
|
52
|
+
private lighting;
|
|
53
|
+
private probe;
|
|
54
|
+
private v;
|
|
55
|
+
private noise;
|
|
56
|
+
private quad;
|
|
57
|
+
private depthMat;
|
|
58
|
+
private marchMat;
|
|
59
|
+
private compositeMat;
|
|
60
|
+
private halfDepth;
|
|
61
|
+
private half;
|
|
62
|
+
private out;
|
|
63
|
+
private size;
|
|
64
|
+
/** Screen rectangle (uv: min x, min y, max x, max y) the active smokes can cover. */
|
|
65
|
+
private rect;
|
|
66
|
+
private corner;
|
|
67
|
+
readonly uniforms: Record<string, THREE.IUniform>;
|
|
68
|
+
/** True when a smoke is on screen this frame (set by update()). */
|
|
69
|
+
enabled: boolean;
|
|
70
|
+
constructor(camera: THREE.PerspectiveCamera, opts?: {
|
|
71
|
+
quality?: "high" | "low";
|
|
72
|
+
});
|
|
73
|
+
/** The map, for smokes without voxel data (their walls are voxelized from it). */
|
|
74
|
+
setWorld(root: THREE.Object3D | null): void;
|
|
75
|
+
setLighting(l: SmokeLighting): void;
|
|
76
|
+
/** Scene fog to apply to the smoke (THREE.Fog). */
|
|
77
|
+
setFog(fog: THREE.Fog | null): void;
|
|
78
|
+
/** Drawing-buffer size of the scene (full resolution). */
|
|
79
|
+
setSize(width: number, height: number): void;
|
|
80
|
+
/** Builds (and caches) a smoke's cloud; null if it can't be built. */
|
|
81
|
+
private cloud;
|
|
82
|
+
private upload;
|
|
83
|
+
/** Smokes alive this frame and recent HE blasts. */
|
|
84
|
+
update(smokes: SmokeInput[], blasts?: SmokeBlast[]): void;
|
|
85
|
+
/** Grows the screen rectangle by a world box (the whole screen if the box reaches behind the camera). */
|
|
86
|
+
private cover;
|
|
87
|
+
/** Smokes with a slot (for stats/tests). */
|
|
88
|
+
get active(): number;
|
|
89
|
+
/**
|
|
90
|
+
* Draws the smokes over `scene` (its colour and depth texture) and returns the result,
|
|
91
|
+
* a full-resolution texture of this pass. Call after update(), when `enabled`.
|
|
92
|
+
*/
|
|
93
|
+
render(renderer: THREE.WebGLRenderer, scene: THREE.WebGLRenderTarget): THREE.Texture;
|
|
94
|
+
dispose(): void;
|
|
95
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import type { Replay } from "../../core/format";
|
|
3
|
+
/**
|
|
4
|
+
* CS2 smoke clouds on the game's own voxel grid.
|
|
5
|
+
*
|
|
6
|
+
* A smoke projectile networks its cloud as `m_VoxelFrameData`: seed cells and 4×4×4
|
|
7
|
+
* bricks of world geometry ("solid" bits) on a 32³ grid of 20-unit cells centred on
|
|
8
|
+
* `m_vSmokeDetonationPos`. Clients fill the cloud from the seeds through open cells.
|
|
9
|
+
* The extractor stores that as one keyframe (FORMAT.md, `grenades[].voxels`):
|
|
10
|
+
*
|
|
11
|
+
* u8 0, u8 3, u8 seeds, seeds × [x, y, z, density, 4 × pad],
|
|
12
|
+
* u16 bricks, bricks × [u16 brick (Morton x,y,z of 8³), u64 solid bits (Morton of 4³)], u8 0
|
|
13
|
+
*
|
|
14
|
+
* The fill rule isn't public. Fitted against which bricks the server sent while the
|
|
15
|
+
* cloud grew (they arrive as the cloud reaches them, ~95 % agreement on de_overpass):
|
|
16
|
+
* a Dijkstra fill over 26 neighbours with Euclidean step costs, upward steps twice as
|
|
17
|
+
* expensive, reaching FILL_REACH cells from the seeds. Diagonal steps need their
|
|
18
|
+
* axis-aligned neighbours open, so the cloud can't leak through cracks. Bricks the
|
|
19
|
+
* server never sent were never reached, so they count as closed.
|
|
20
|
+
*/
|
|
21
|
+
export declare const GRID = 32;
|
|
22
|
+
/** One cell: 20 game units, in metres. */
|
|
23
|
+
export declare const CELL: number;
|
|
24
|
+
/** How far the cloud reaches from its seeds, in cells (Dijkstra distance). */
|
|
25
|
+
export declare const FILL_REACH = 6;
|
|
26
|
+
/** Per-cell bytes in texture order (x = world X, y = world Z, z = world Y). */
|
|
27
|
+
export declare const D_SCALE = 30;
|
|
28
|
+
export declare const R_SCALE = 12;
|
|
29
|
+
export interface SmokeField {
|
|
30
|
+
/** World position of the grid's minimum corner (metres). */
|
|
31
|
+
min: THREE.Vector3;
|
|
32
|
+
/** RG bytes, 32³, texture order: index = (wy * 32 + wz) * 32 + wx. */
|
|
33
|
+
data: Uint8Array;
|
|
34
|
+
/** Filled cells within FILL_REACH. */
|
|
35
|
+
cells: number;
|
|
36
|
+
/** Bounds of cells within FILL_MAX, in texture cell coordinates [min, max). */
|
|
37
|
+
lo: [number, number, number];
|
|
38
|
+
hi: [number, number, number];
|
|
39
|
+
}
|
|
40
|
+
interface Keyframe {
|
|
41
|
+
seeds: [number, number, number][];
|
|
42
|
+
/** 1 = solid, 2 = never sent (closed), 0 = open; game axes, index (z * 32 + y) * 32 + x. */
|
|
43
|
+
solid: Uint8Array;
|
|
44
|
+
}
|
|
45
|
+
/** Decodes a keyframe (see above); null if it doesn't parse. */
|
|
46
|
+
export declare function decodeKeyframe(bytes: Uint8Array): Keyframe | null;
|
|
47
|
+
/**
|
|
48
|
+
* The cloud of one smoke: seed distance (shape and growth) and path distance from the
|
|
49
|
+
* canister (growth) per cell, packed for the volume texture. `center` is the grid
|
|
50
|
+
* centre in world metres.
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildField(kf: Keyframe, center: THREE.Vector3): SmokeField;
|
|
53
|
+
/** Longest optical depth the light bytes hold, in metres of full-density cloud. */
|
|
54
|
+
export declare const OD_MAX = 6;
|
|
55
|
+
/** Light bytes encode sqrt(depth / OD_MAX): fine steps near the surface, where it shows. */
|
|
56
|
+
export declare const encodeDepth: (metres: number) => number;
|
|
57
|
+
export declare const decodeDepth: (byte: number) => number;
|
|
58
|
+
/** The cloud's density once grown, as the shader's edge ramp before noise. */
|
|
59
|
+
export declare function grownDensity(dByte: number): number;
|
|
60
|
+
/**
|
|
61
|
+
* Self-shadowing of the grown cloud, baked per cell so the shader needn't march towards
|
|
62
|
+
* the light at every step: how much cloud lies towards the sun (byte 0), and the same
|
|
63
|
+
* averaged over the sky above (byte 1), encoded with encodeDepth. Texture order like
|
|
64
|
+
* SmokeField.data. `sun` points towards the sun, world axes.
|
|
65
|
+
*/
|
|
66
|
+
export declare function lightField(f: SmokeField, sun: THREE.Vector3): Uint8Array;
|
|
67
|
+
/**
|
|
68
|
+
* For replays without voxel data: seeds like the game's (a lattice in a squat
|
|
69
|
+
* ellipsoid around the canister, ~90 units across), reachable from the canister.
|
|
70
|
+
*/
|
|
71
|
+
export declare function syntheticKeyframe(solid: Uint8Array): Keyframe;
|
|
72
|
+
/**
|
|
73
|
+
* Whether a replay has smokes without the game's voxel cloud (older replays): those are
|
|
74
|
+
* filled around the map's geometry (voxelizeWorld), which then has to stay in memory.
|
|
75
|
+
*/
|
|
76
|
+
export declare function needsWorldVoxels(replay: Replay): boolean;
|
|
77
|
+
/** Surfaces voxelizeWorld treats as walls: opaque ones (not glass, foliage cut-outs or decals). */
|
|
78
|
+
export declare function blocksSmoke(mesh: THREE.Mesh): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Solid cells of a smoke grid from world geometry (for replays without voxel data):
|
|
81
|
+
* samples every triangle near the grid finely enough to mark each cell it crosses.
|
|
82
|
+
* Meshes whose arrays were freed after upload (GameMapOptions.keepPositions) are skipped.
|
|
83
|
+
*/
|
|
84
|
+
export declare function voxelizeWorld(root: THREE.Object3D, center: THREE.Vector3): Uint8Array;
|
|
85
|
+
/** Base64 (JSON []byte) -> bytes. */
|
|
86
|
+
export declare function fromBase64(s: string): Uint8Array;
|
|
87
|
+
export {};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import { type GameMapManifest, type GameMapStore, type GameMapTier, type LightmapMode } from "../../maps";
|
|
3
|
+
import { type WorldUniforms } from "./material";
|
|
4
|
+
import { type ProbeGrid } from "./probes";
|
|
5
|
+
export { createWorldUniforms, type WorldUniforms } from "./material";
|
|
6
|
+
/** scenes[0].extras.cs2, written by scripts/game-map.mjs (packed maps leave lightmaps to the manifest). */
|
|
7
|
+
export interface GameMapEnv {
|
|
8
|
+
version: number;
|
|
9
|
+
lightmaps?: {
|
|
10
|
+
irradiance?: {
|
|
11
|
+
uri: string;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
format: "rgb9e5";
|
|
15
|
+
};
|
|
16
|
+
sunShadow?: {
|
|
17
|
+
uri: string;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
};
|
|
21
|
+
directional?: {
|
|
22
|
+
uri: string;
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
};
|
|
26
|
+
debugChart?: {
|
|
27
|
+
uri: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
sun?: {
|
|
31
|
+
direction: [number, number, number];
|
|
32
|
+
color: [number, number, number];
|
|
33
|
+
brightness: number;
|
|
34
|
+
skyColor?: [number, number, number];
|
|
35
|
+
};
|
|
36
|
+
sky?: {
|
|
37
|
+
uri: string;
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
format: "rgb9e5";
|
|
41
|
+
rotationY: number;
|
|
42
|
+
sunAzimuth: number;
|
|
43
|
+
sunElevation: number;
|
|
44
|
+
};
|
|
45
|
+
fog?: {
|
|
46
|
+
color: [number, number, number];
|
|
47
|
+
start: number;
|
|
48
|
+
end: number;
|
|
49
|
+
maxOpacity: number;
|
|
50
|
+
exponent: number;
|
|
51
|
+
};
|
|
52
|
+
exposure?: {
|
|
53
|
+
min: number;
|
|
54
|
+
max: number;
|
|
55
|
+
};
|
|
56
|
+
tonemap?: {
|
|
57
|
+
whitePoint: number;
|
|
58
|
+
exposureBias: number;
|
|
59
|
+
};
|
|
60
|
+
bloom?: {
|
|
61
|
+
screenStrength: number;
|
|
62
|
+
threshold: number;
|
|
63
|
+
thresholdWidth: number;
|
|
64
|
+
};
|
|
65
|
+
bombsites?: [number, number, number][];
|
|
66
|
+
probes?: {
|
|
67
|
+
uri: string;
|
|
68
|
+
count: number;
|
|
69
|
+
step: number;
|
|
70
|
+
bounds: [number, number, number, number];
|
|
71
|
+
};
|
|
72
|
+
spawns?: {
|
|
73
|
+
T: [number, number, number][];
|
|
74
|
+
CT: [number, number, number][];
|
|
75
|
+
};
|
|
76
|
+
/** env_wind: direction (world, horizontal), base speed and gusts (game units/s), timings (s). */
|
|
77
|
+
wind?: {
|
|
78
|
+
direction: [number, number, number];
|
|
79
|
+
speed: [number, number];
|
|
80
|
+
gust: [number, number];
|
|
81
|
+
gustDelay: [number, number];
|
|
82
|
+
gustDuration: number;
|
|
83
|
+
};
|
|
84
|
+
/** Reflection probes: the map's cubemaps as an octahedral atlas, their volumes and a lookup grid. */
|
|
85
|
+
reflections?: {
|
|
86
|
+
atlas: {
|
|
87
|
+
uri: string;
|
|
88
|
+
width: number;
|
|
89
|
+
height: number;
|
|
90
|
+
format: "rgb9e5";
|
|
91
|
+
tile: [number, number];
|
|
92
|
+
cols: number;
|
|
93
|
+
levels: [number, number, number][];
|
|
94
|
+
};
|
|
95
|
+
volumes: {
|
|
96
|
+
uri: string;
|
|
97
|
+
count: number;
|
|
98
|
+
stride: number;
|
|
99
|
+
};
|
|
100
|
+
grid: {
|
|
101
|
+
uri: string;
|
|
102
|
+
origin: [number, number, number];
|
|
103
|
+
cell: number;
|
|
104
|
+
dims: [number, number, number];
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
export interface GameMapProgress {
|
|
109
|
+
phase: "geometry" | "lightmaps" | "textures";
|
|
110
|
+
/**
|
|
111
|
+
* Packed maps: bytes of the whole tier so far, across phases (files already on
|
|
112
|
+
* the device count as they're read). Otherwise: bytes of the geometry, then
|
|
113
|
+
* textures done.
|
|
114
|
+
*/
|
|
115
|
+
loaded: number;
|
|
116
|
+
total: number;
|
|
117
|
+
}
|
|
118
|
+
export interface GameMapOptions {
|
|
119
|
+
/** Where three.js's basis_transcoder.js/.wasm live (for KTX2 textures). */
|
|
120
|
+
transcoderPath?: string;
|
|
121
|
+
/** Prefer KTX2 (GPU-compressed) textures when the map has them. Default true. Packed maps always use them. */
|
|
122
|
+
ktx2?: boolean;
|
|
123
|
+
/** Parallel texture downloads. */
|
|
124
|
+
concurrency?: number;
|
|
125
|
+
/** World geometry also casts real-time sun shadows. Default false. */
|
|
126
|
+
worldShadows?: boolean;
|
|
127
|
+
/** Packed maps (a manifest.json URL): the quality tier. Default "low", or the nearest the map has. */
|
|
128
|
+
tier?: GameMapTier;
|
|
129
|
+
/** Packed maps: "auto" (default) uses Valve's BC lightmaps when the GPU has BC6H/BC7/BC1, else the compat ones. */
|
|
130
|
+
lightmaps?: "auto" | LightmapMode;
|
|
131
|
+
/** Packed maps: keep downloaded files on the device (GameMapStore.open() from "@matchomag/cs2-replay/maps"). */
|
|
132
|
+
store?: GameMapStore | null;
|
|
133
|
+
onProgress?: (p: GameMapProgress) => void;
|
|
134
|
+
/**
|
|
135
|
+
* Keep the JavaScript copies of the map's geometry and textures once they're on the GPU.
|
|
136
|
+
* Default false: each is freed as soon as it's uploaded (Overpass `low`: ~0.7 GB less page
|
|
137
|
+
* memory), and GameStage reloads the map if the WebGL context is lost. Set it to read the
|
|
138
|
+
* map's vertices or texels yourself (e.g. raycasting against it).
|
|
139
|
+
*/
|
|
140
|
+
keepCpuCopies?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* With copies freed: still keep the vertex positions and indices of opaque surfaces (~60 MB on
|
|
143
|
+
* Overpass). Smokes without voxel data are filled around the walls found in them.
|
|
144
|
+
*/
|
|
145
|
+
keepPositions?: boolean;
|
|
146
|
+
}
|
|
147
|
+
export interface GameMap {
|
|
148
|
+
root: THREE.Group;
|
|
149
|
+
env: GameMapEnv;
|
|
150
|
+
uniforms: WorldUniforms;
|
|
151
|
+
/** Sun direction (towards the sun), world space. */
|
|
152
|
+
sunDirection: THREE.Vector3;
|
|
153
|
+
/** Linear sun colour, premultiplied by brightness. */
|
|
154
|
+
sunColor: THREE.Color;
|
|
155
|
+
/** The equirectangular HDR sky. GameStage turns it into its background and environment, then frees it unless keepCpuCopies. */
|
|
156
|
+
sky: THREE.Texture | null;
|
|
157
|
+
/** Baked light probes for players (sun visibility, ambient), if the map has them. */
|
|
158
|
+
probes: ProbeGrid | null;
|
|
159
|
+
/** Resolves when every texture has arrived. */
|
|
160
|
+
textures: Promise<void>;
|
|
161
|
+
stats: {
|
|
162
|
+
drawCalls: number;
|
|
163
|
+
triangles: number;
|
|
164
|
+
textures: number;
|
|
165
|
+
};
|
|
166
|
+
/** Packed maps: the manifest, the tier and lightmaps in use, and the tier's size in bytes. */
|
|
167
|
+
manifest: GameMapManifest | null;
|
|
168
|
+
tier: GameMapTier | null;
|
|
169
|
+
lightmapMode: LightmapMode | null;
|
|
170
|
+
bytes: number;
|
|
171
|
+
dispose(): void;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Loads a game-look map: either a packed map's manifest.json (scripts/pack-game-map.mjs:
|
|
175
|
+
* quality tiers, Valve's BC lightmaps) or a glTF from scripts/game-map.mjs. Geometry,
|
|
176
|
+
* lightmaps, sky and lighting load first; materials render with placeholder textures
|
|
177
|
+
* while the real ones stream in (biggest surfaces first for packed maps).
|
|
178
|
+
*/
|
|
179
|
+
export declare function loadGameMap(url: string, gl: THREE.WebGLRenderer, opts?: GameMapOptions): Promise<GameMap>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import type { Replay } from "../../core/format";
|
|
3
|
+
import type { MapStage, StageMap } from "../look";
|
|
4
|
+
import { GameStage, type StageOptions } from "./stage";
|
|
5
|
+
export declare class GameLook implements MapStage {
|
|
6
|
+
readonly prepareFirst = true;
|
|
7
|
+
readonly game: GameStage;
|
|
8
|
+
private maps;
|
|
9
|
+
constructor(gl: THREE.WebGLRenderer, scene: THREE.Scene, camera: THREE.PerspectiveCamera, opts: StageOptions, replay: Replay | null);
|
|
10
|
+
load(url: string, prepare: ((map: StageMap) => Promise<void>) | null): Promise<StageMap>;
|
|
11
|
+
/** The same StageMap for the same map, before and after it's shown. */
|
|
12
|
+
private wrap;
|
|
13
|
+
render(): void;
|
|
14
|
+
setSize(width: number, height: number): void;
|
|
15
|
+
dispose(): void;
|
|
16
|
+
}
|