@aethervtt/shard-terrain 0.0.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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/biomes.d.ts +65 -0
- package/dist/biomes.js +163 -0
- package/dist/chunk.d.ts +99 -0
- package/dist/chunk.js +304 -0
- package/dist/colliders.d.ts +86 -0
- package/dist/colliders.js +356 -0
- package/dist/components.d.ts +49 -0
- package/dist/components.js +137 -0
- package/dist/cube.d.ts +51 -0
- package/dist/cube.js +87 -0
- package/dist/frame.d.ts +21 -0
- package/dist/frame.js +63 -0
- package/dist/heights.d.ts +51 -0
- package/dist/heights.js +137 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +193 -0
- package/dist/kernel.d.ts +47 -0
- package/dist/kernel.js +243 -0
- package/dist/lod.d.ts +22 -0
- package/dist/lod.js +44 -0
- package/dist/material.d.ts +14 -0
- package/dist/material.js +426 -0
- package/dist/methods.d.ts +12 -0
- package/dist/methods.js +259 -0
- package/dist/nav.d.ts +14 -0
- package/dist/nav.js +114 -0
- package/dist/overlays.d.ts +6 -0
- package/dist/overlays.js +67 -0
- package/dist/planet.d.ts +106 -0
- package/dist/planet.js +313 -0
- package/dist/plugin.d.ts +23 -0
- package/dist/plugin.js +98 -0
- package/dist/points.d.ts +62 -0
- package/dist/points.js +207 -0
- package/dist/quadtree.d.ts +153 -0
- package/dist/quadtree.js +587 -0
- package/dist/render.d.ts +179 -0
- package/dist/render.js +1222 -0
- package/dist/test-planet.d.ts +59 -0
- package/dist/test-planet.js +189 -0
- package/dist/testing.d.ts +42 -0
- package/dist/testing.js +96 -0
- package/dist/view.d.ts +12 -0
- package/dist/view.js +61 -0
- package/package.json +50 -0
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { type AssetRef, type Entity, type Query, type World } from '@aethervtt/shard-core';
|
|
2
|
+
import type { GpuContext } from '@aethervtt/shard-gpu';
|
|
3
|
+
import { Mesh } from '@aethervtt/shard-mesh';
|
|
4
|
+
import { MaterialAsset } from '@aethervtt/shard-render';
|
|
5
|
+
import type { App } from '@aethervtt/shard-runtime';
|
|
6
|
+
import { Texture } from '@aethervtt/shard-texture';
|
|
7
|
+
import { type ColliderChunk } from './colliders.js';
|
|
8
|
+
import { type KernelGraph } from './kernel.js';
|
|
9
|
+
import type { PlanetRuntime } from './planet.js';
|
|
10
|
+
import { type NodeTree } from './quadtree.js';
|
|
11
|
+
/**
|
|
12
|
+
* One render chunk: an entity drawing its range of an arena's vertex buffers, which a GPU job
|
|
13
|
+
* writes (or a collider chunk's vertices are copied into).
|
|
14
|
+
*/
|
|
15
|
+
interface Slot {
|
|
16
|
+
id: number;
|
|
17
|
+
kind: number;
|
|
18
|
+
mesh: Mesh;
|
|
19
|
+
meshRef: AssetRef;
|
|
20
|
+
entity: Entity;
|
|
21
|
+
/** Tree node it holds, or −1. */
|
|
22
|
+
node: number;
|
|
23
|
+
/** Edge lock bits (two per edge), fade, and InstanceData.x (fade + 2 × mask) now. */
|
|
24
|
+
bits: number;
|
|
25
|
+
fade: number;
|
|
26
|
+
packed: number;
|
|
27
|
+
/** The collider chunk whose vertices it holds (source 1). */
|
|
28
|
+
cpu: ColliderChunk | undefined;
|
|
29
|
+
/** Frame it was last rendered. */
|
|
30
|
+
used: number;
|
|
31
|
+
shown: boolean;
|
|
32
|
+
/** Where its vertices came from: 0 a GPU job, 1 a collider chunk (the collider's own numbers). */
|
|
33
|
+
source: number;
|
|
34
|
+
/** The index set drawn: quadrant mask + 16 × stitched edges (`chunkIndices`). */
|
|
35
|
+
indexKey: number;
|
|
36
|
+
/** A job for it is queued. */
|
|
37
|
+
pending: boolean;
|
|
38
|
+
/** Its GPU mesh holds this node at this planet version (−1: nothing valid). */
|
|
39
|
+
gpuNode: number;
|
|
40
|
+
gpuVersion: number;
|
|
41
|
+
/** Increments per job, so a late readback for an older job is ignored. */
|
|
42
|
+
jobId: number;
|
|
43
|
+
center: Float64Array;
|
|
44
|
+
}
|
|
45
|
+
/** A grid a job samples: its points, their origins per graph, and the kernel's uniform. */
|
|
46
|
+
interface JobGrid {
|
|
47
|
+
count: number;
|
|
48
|
+
points: Float32Array;
|
|
49
|
+
originsH: Int32Array;
|
|
50
|
+
originsT: Int32Array;
|
|
51
|
+
originsM: Int32Array;
|
|
52
|
+
params: ArrayBuffer;
|
|
53
|
+
}
|
|
54
|
+
interface Job extends JobGrid {
|
|
55
|
+
slot: Slot;
|
|
56
|
+
id: number;
|
|
57
|
+
tree: NodeTree;
|
|
58
|
+
node: number;
|
|
59
|
+
kind: number;
|
|
60
|
+
version: number;
|
|
61
|
+
/** Only the normal tile (the slot shows a collider chunk's own vertices). */
|
|
62
|
+
normalsOnly: boolean;
|
|
63
|
+
/** The normal tile's grid (twice the vertex density), with tiles on. */
|
|
64
|
+
fine: JobGrid | undefined;
|
|
65
|
+
}
|
|
66
|
+
interface GridResources {
|
|
67
|
+
params: GPUBuffer;
|
|
68
|
+
points: GPUBuffer;
|
|
69
|
+
pointsSize: number;
|
|
70
|
+
values: GPUBuffer;
|
|
71
|
+
valuesSize: number;
|
|
72
|
+
origins: (GPUBuffer | undefined)[];
|
|
73
|
+
originSizes: number[];
|
|
74
|
+
}
|
|
75
|
+
interface GpuJobResources extends GridResources {
|
|
76
|
+
stats: GPUBuffer;
|
|
77
|
+
fine: GridResources;
|
|
78
|
+
}
|
|
79
|
+
/** GPU state of one planet's generation: kernels and per-job buffers (one set per job per frame). */
|
|
80
|
+
interface PlanetGpu {
|
|
81
|
+
gpu: GpuContext;
|
|
82
|
+
generation: number;
|
|
83
|
+
resources: GpuJobResources[];
|
|
84
|
+
readbacks: GPUBuffer[];
|
|
85
|
+
}
|
|
86
|
+
/** Render-side state of one planet. */
|
|
87
|
+
export declare class PlanetRender {
|
|
88
|
+
readonly slots: Slot[];
|
|
89
|
+
/** Vertex buffers shared by ARENA_SLOTS slots each, so chunks draw without rebinding. */
|
|
90
|
+
readonly arenas: Mesh[];
|
|
91
|
+
material: MaterialAsset;
|
|
92
|
+
materialRef: AssetRef<'Material'>;
|
|
93
|
+
ocean: MaterialAsset;
|
|
94
|
+
oceanRef: AssetRef<'Material'>;
|
|
95
|
+
biomeTexture: Texture | undefined;
|
|
96
|
+
biomeRef: AssetRef | undefined;
|
|
97
|
+
biomeVersion: number;
|
|
98
|
+
/** Every slot's normal tile (TILE_LAYER² layers of `tileGeometry` tiles), grown with the pool. */
|
|
99
|
+
tiles: Texture | undefined;
|
|
100
|
+
tilesRef: AssetRef | undefined;
|
|
101
|
+
jobs: Job[];
|
|
102
|
+
/** Each tree's walk stamp last frame (what was on screen then). */
|
|
103
|
+
lastStamp: number[];
|
|
104
|
+
readonly view: import("./quadtree.js").SelectionView;
|
|
105
|
+
/** The selecting camera in the origin frame (xyz) and pixels per radian / errorPixels (w). */
|
|
106
|
+
readonly camera: Float32Array<ArrayBuffer>;
|
|
107
|
+
hasCamera: boolean;
|
|
108
|
+
gpu: PlanetGpu | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* The planet version on screen. After an edit (hot reload) every chunk keeps its old contents
|
|
111
|
+
* until the new kernels compile; then every visible chunk regenerates in one frame, so old and
|
|
112
|
+
* new never meet at a seam.
|
|
113
|
+
*/
|
|
114
|
+
shownVersion: number;
|
|
115
|
+
/** The version whose generation pipelines are compiled. */
|
|
116
|
+
kernelsReady: number;
|
|
117
|
+
/** Jobs per generation pass (moving average), to turn the pass's GPU time into ms per job. */
|
|
118
|
+
jobsPerPass: number;
|
|
119
|
+
/** GPU milliseconds per job, from timestamp queries (0: not measured). */
|
|
120
|
+
msPerJob: number;
|
|
121
|
+
/** Kernel graphs, refreshed with the planet's version. */
|
|
122
|
+
kernels: {
|
|
123
|
+
version: number;
|
|
124
|
+
terrain: KernelGraph[];
|
|
125
|
+
ocean: KernelGraph[];
|
|
126
|
+
} | undefined;
|
|
127
|
+
stats: {
|
|
128
|
+
generated: number;
|
|
129
|
+
fromColliders: number;
|
|
130
|
+
readbacks: number;
|
|
131
|
+
evicted: number;
|
|
132
|
+
locks: number;
|
|
133
|
+
gpuFrames: number;
|
|
134
|
+
lastFrameJobs: number;
|
|
135
|
+
};
|
|
136
|
+
private jobCounter;
|
|
137
|
+
constructor(world: World);
|
|
138
|
+
nextJobId(): number;
|
|
139
|
+
}
|
|
140
|
+
export declare function renderOf(world: World, rt: PlanetRuntime): PlanetRender;
|
|
141
|
+
/**
|
|
142
|
+
* Chooses each planet's chunks for the selecting camera (spec 0043): walks both quadtrees, gives
|
|
143
|
+
* new nodes pool slots and queues their GPU jobs within the frame's budget (nodes at collider depth
|
|
144
|
+
* near anchors show the collider chunk's own vertices instead, with no job), shows exactly the
|
|
145
|
+
* selected chunks, writes edge locks, and refreshes the planet's materials.
|
|
146
|
+
*/
|
|
147
|
+
export declare const selectChunks: import("@aethervtt/shard-core").SystemDef<{
|
|
148
|
+
cameras: Query;
|
|
149
|
+
}>;
|
|
150
|
+
/**
|
|
151
|
+
* A chunk's normal tile: its grid at twice the vertex density (2(n − 1) + 1 texels a side), and how
|
|
152
|
+
* many fit a layer. Off above 33 vertices per edge: those chunks are dense already, and uv1.x
|
|
153
|
+
* (grid point + n² × tile) must stay exact in f32.
|
|
154
|
+
*/
|
|
155
|
+
export declare function tileGeometry(n: number): {
|
|
156
|
+
size: number;
|
|
157
|
+
perRow: number;
|
|
158
|
+
perLayer: number;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Vertices a slot takes in its arena: its vertex count rounded up to 64, so every attribute's
|
|
162
|
+
* range starts at a multiple of 256 bytes (storage binding offsets must).
|
|
163
|
+
*/
|
|
164
|
+
export declare const slotStride: (vertexCount: number) => number;
|
|
165
|
+
/**
|
|
166
|
+
* Debug shading (0 off, 1 biomes, 2 seams, 3 levels, 4 normals), for tests and tools. The
|
|
167
|
+
* terrain-biomes and terrain-lod overlays turn modes 1 and 3 on too.
|
|
168
|
+
*/
|
|
169
|
+
export declare const TerrainDebug: {
|
|
170
|
+
mode: number;
|
|
171
|
+
/** False shades from vertex normals even where normal tiles exist (comparisons, tests). */
|
|
172
|
+
normalTiles: boolean;
|
|
173
|
+
};
|
|
174
|
+
/** The render graph node: once per frame, every planet's GPU work before anything draws. */
|
|
175
|
+
/** Adds the `terrain/generate` render graph node and the terrain shaders (once the GPU is up). */
|
|
176
|
+
export declare function registerNode(app: App): void;
|
|
177
|
+
/** Despawns a planet's chunk entities and frees its meshes and materials. */
|
|
178
|
+
export declare function cleanupRender(world: World, rt: PlanetRuntime): void;
|
|
179
|
+
export {};
|