@thoughts-on-things/vantage-mc 0.1.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/dist/{biome-BR6bKnti.d.ts → biome-CPP37ieY.d.ts} +72 -13
- package/dist/{chunk-I7TYYQX3.js → chunk-C7GIMQYZ.js} +203 -30
- package/dist/{chunk-O2MEM2GT.js → chunk-M6KVJXCR.js} +231 -12
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.js +3 -3
- package/dist/three/index.d.ts +14 -5
- package/dist/three/index.js +2 -2
- package/dist/{viewer-Bxc0eorS.d.ts → viewer-GsEn9RpF.d.ts} +5 -1
- package/package.json +1 -1
|
@@ -12,8 +12,17 @@ declare const TILE_MAGIC: {
|
|
|
12
12
|
readonly VTL5: "VTL5";
|
|
13
13
|
/** Quantized vertices: u16 positions (bbox transform) + u16 layer/biome. */
|
|
14
14
|
readonly VTL6: "VTL6";
|
|
15
|
+
/** Compact quads: no index array (canonical quad topology is derived),
|
|
16
|
+
* delta-coded u16 positions, i16 fixed-point UV. */
|
|
17
|
+
readonly VTL7: "VTL7";
|
|
18
|
+
/** + a per-tile lightmap atlas: the greedy vertex tail samples baked
|
|
19
|
+
* light/AO from a texture instead of vertices, so lighting gradients no
|
|
20
|
+
* longer fragment greedy merges (~23% fewer vertices). */
|
|
21
|
+
readonly VTL8: "VTL8";
|
|
15
22
|
};
|
|
16
23
|
type TileMagic = (typeof TILE_MAGIC)[keyof typeof TILE_MAGIC];
|
|
24
|
+
/** VTL7 UV fixed-point steps per texture unit (uv = stored / UV_SCALE). */
|
|
25
|
+
declare const UV_SCALE = 128;
|
|
17
26
|
/** Texture-array magic. */
|
|
18
27
|
declare const TEXTURE_MAGIC: "VTA1";
|
|
19
28
|
/**
|
|
@@ -68,6 +77,11 @@ interface MeshSection {
|
|
|
68
77
|
/** `vertexCount` packed saved light `(sky << 4) | block` (each 0..15), carried
|
|
69
78
|
* in the normal's spare 4th byte. Textured tiles only. */
|
|
70
79
|
light?: Uint8Array;
|
|
80
|
+
/** VTL8: the first vertex of the atlas-lit tail (== vertexCount when the
|
|
81
|
+
* whole section is vertex-lit). */
|
|
82
|
+
lmStart?: number;
|
|
83
|
+
/** VTL8: the tail's lightmap UVs in half-texel units (delta coding undone). */
|
|
84
|
+
lmuv?: Uint16Array;
|
|
71
85
|
}
|
|
72
86
|
/**
|
|
73
87
|
* A top-down surface map (VTL5): one column per XZ cell over a world-space
|
|
@@ -103,6 +117,8 @@ interface DecodedTile extends MeshSection {
|
|
|
103
117
|
fluid?: MeshSection;
|
|
104
118
|
/** Top-down surface map for picking (VTL5+). */
|
|
105
119
|
surface?: SurfaceMap;
|
|
120
|
+
/** The baked light+AO atlas (VTL8 with atlas-lit geometry only). */
|
|
121
|
+
lightmap?: Lightmap;
|
|
106
122
|
}
|
|
107
123
|
/**
|
|
108
124
|
* A VTL6 mesh section kept in its on-disk quantized encoding: every array is a
|
|
@@ -120,8 +136,11 @@ interface QuantizedSection {
|
|
|
120
136
|
posMin: [number, number, number];
|
|
121
137
|
/** World units per quantization step, per axis. */
|
|
122
138
|
posScale: [number, number, number];
|
|
123
|
-
/** `2 * vertexCount` texture coordinates
|
|
124
|
-
|
|
139
|
+
/** `2 * vertexCount` texture coordinates — f32 (VTL6) or i16 fixed point
|
|
140
|
+
* (VTL7); multiply by {@link QuantizedSection.uvScale} for texture units. */
|
|
141
|
+
uv: Float32Array | Int16Array;
|
|
142
|
+
/** Texture units per stored uv step (1 for f32, 1/128 for VTL7's i16). */
|
|
143
|
+
uvScale: number;
|
|
125
144
|
/** `4 * vertexCount` RGBA: tint RGB + packed AO/alpha. */
|
|
126
145
|
colors: Uint8Array;
|
|
127
146
|
/** `4 * vertexCount` int8: xyz normal + the packed light byte as the 4th
|
|
@@ -131,23 +150,45 @@ interface QuantizedSection {
|
|
|
131
150
|
layer: Uint16Array;
|
|
132
151
|
/** `vertexCount` u16 biome ids. */
|
|
133
152
|
biome: Uint16Array;
|
|
134
|
-
/** `indexCount` triangle indices
|
|
135
|
-
|
|
153
|
+
/** `indexCount` triangle indices — `null` for VTL7+, whose canonical quad
|
|
154
|
+
* topology `[b,b+1,b+2, b,b+2,b+3]` the renderer derives (and shares one
|
|
155
|
+
* GPU index buffer across every tile). */
|
|
156
|
+
indices: Uint32Array | null;
|
|
157
|
+
/** VTL8: the first vertex of the atlas-lit tail (== vertexCount when the
|
|
158
|
+
* whole section is vertex-lit). */
|
|
159
|
+
lmStart?: number;
|
|
160
|
+
/** VTL8: the tail's lightmap UVs in half-texel units, `2 * (vertexCount -
|
|
161
|
+
* lmStart)` values (delta coding already undone). */
|
|
162
|
+
lmuv?: Uint16Array;
|
|
163
|
+
}
|
|
164
|
+
/** A VTL8 tile's baked light+AO atlas, interleaved RGBA (R sky, G block,
|
|
165
|
+
* B AO, A 255) ready for texture upload; sample bilinearly. */
|
|
166
|
+
interface Lightmap {
|
|
167
|
+
width: number;
|
|
168
|
+
height: number;
|
|
169
|
+
/** `4 * width * height` RGBA bytes. */
|
|
170
|
+
pixels: Uint8Array<ArrayBuffer>;
|
|
136
171
|
}
|
|
137
|
-
/** A VTL6 tile decoded without dequantization (see {@link QuantizedSection}). */
|
|
172
|
+
/** A VTL6/7/8 tile decoded without dequantization (see {@link QuantizedSection}). */
|
|
138
173
|
interface QuantizedTile {
|
|
139
|
-
magic: 'VTL6';
|
|
174
|
+
magic: 'VTL6' | 'VTL7' | 'VTL8';
|
|
140
175
|
version: number;
|
|
141
176
|
solid: QuantizedSection;
|
|
142
177
|
fluid: QuantizedSection;
|
|
143
178
|
surface: SurfaceMap;
|
|
144
179
|
biomeNames: string[];
|
|
180
|
+
/** The baked light+AO atlas (VTL8 with atlas-lit geometry only). */
|
|
181
|
+
lightmap?: Lightmap;
|
|
145
182
|
}
|
|
183
|
+
/** The canonical quad index pattern for `vertexCount` vertices (4 verts / 6
|
|
184
|
+
* indices per face) — the topology every Vantage mesher emits. */
|
|
185
|
+
declare function canonicalQuadIndices(vertexCount: number): Uint32Array;
|
|
146
186
|
/**
|
|
147
|
-
* Decode a VTL6 `.vtile` in its quantized on-disk encoding:
|
|
148
|
-
* zero-copy
|
|
149
|
-
* dequantize (the streaming fast path — no
|
|
150
|
-
* for any other tile version;
|
|
187
|
+
* Decode a VTL6/7 `.vtile` in its quantized on-disk encoding: arrays are
|
|
188
|
+
* zero-copy views (VTL7 positions take one linear delta-decode pass) and stay
|
|
189
|
+
* u16/i16 for the vertex shader to dequantize (the streaming fast path — no
|
|
190
|
+
* per-vertex float expansion). Returns `null` for any other tile version;
|
|
191
|
+
* callers fall back to {@link parseTile}.
|
|
151
192
|
*/
|
|
152
193
|
declare function parseTileQuantized(buffer: ArrayBuffer): QuantizedTile | null;
|
|
153
194
|
/**
|
|
@@ -158,6 +199,17 @@ declare function parseTileQuantized(buffer: ArrayBuffer): QuantizedTile | null;
|
|
|
158
199
|
*/
|
|
159
200
|
declare function parseTile(buffer: ArrayBuffer): DecodedTile;
|
|
160
201
|
|
|
202
|
+
/** One animated texture's playback metadata (version ≥ 2 files). */
|
|
203
|
+
interface TextureAnimation {
|
|
204
|
+
/** First layer of the baked frame sequence — the layer meshes reference. */
|
|
205
|
+
base: number;
|
|
206
|
+
/** Layers in the sequence (the mcmeta frame order is already unrolled). */
|
|
207
|
+
count: number;
|
|
208
|
+
/** Ticks per frame (20 ticks/second). */
|
|
209
|
+
frametime: number;
|
|
210
|
+
/** Blend adjacent frames instead of stepping. */
|
|
211
|
+
interpolate: boolean;
|
|
212
|
+
}
|
|
161
213
|
/** A decoded texture array: `layers` images of `width`×`height` RGBA pixels. */
|
|
162
214
|
interface DecodedTextureArray {
|
|
163
215
|
width: number;
|
|
@@ -165,9 +217,12 @@ interface DecodedTextureArray {
|
|
|
165
217
|
layers: number;
|
|
166
218
|
/** `width * height * layers * 4` tightly-packed RGBA bytes. */
|
|
167
219
|
pixels: Uint8Array<ArrayBuffer>;
|
|
220
|
+
/** Animated textures (empty for version-1 files, which bake only frame 0). */
|
|
221
|
+
anims: TextureAnimation[];
|
|
168
222
|
}
|
|
169
223
|
/**
|
|
170
|
-
* Decode a `.vtexarr` buffer.
|
|
224
|
+
* Decode a `.vtexarr` buffer. Version 2 appends an animation table after the
|
|
225
|
+
* pixels; version 1 (no table) still decodes, with `anims` empty.
|
|
171
226
|
*
|
|
172
227
|
* @throws if the magic is not `VTA1`.
|
|
173
228
|
*/
|
|
@@ -195,8 +250,12 @@ interface LowresLevel {
|
|
|
195
250
|
}
|
|
196
251
|
/** A parsed `manifest.json` for a tiled world render. */
|
|
197
252
|
interface WorldManifest {
|
|
198
|
-
/** Manifest schema version (1 = hires tiles only, 2 adds `lowres
|
|
253
|
+
/** Manifest schema version (1 = hires tiles only, 2 adds `lowres`,
|
|
254
|
+
* 3 = VTL7 compact tiles + `maxSectionVerts`). */
|
|
199
255
|
format: number;
|
|
256
|
+
/** Largest per-section vertex count across every tile (format 3+) — sizes
|
|
257
|
+
* the renderer's one shared quad index buffer before the first tile lands. */
|
|
258
|
+
maxSectionVerts?: number;
|
|
200
259
|
/** Tile span in chunks per side. */
|
|
201
260
|
tileChunks: number;
|
|
202
261
|
/** Tile span in blocks per side (= tileChunks · 16). */
|
|
@@ -304,4 +363,4 @@ declare function summarizeSurfaceBiomes(surface: SurfaceMap, names: string[], pa
|
|
|
304
363
|
*/
|
|
305
364
|
declare function summarizeBiomes(tile: DecodedTile, palette?: Rgb[]): BiomeEntry[];
|
|
306
365
|
|
|
307
|
-
export { type BiomeEntry as B, type DecodedTile as D, type
|
|
366
|
+
export { type BiomeEntry as B, type DecodedTile as D, type Lightmap as L, type ManifestTile as M, type QuantizedTile as Q, type Rgb as R, type SurfaceMap as S, TEXTURE_MAGIC as T, UV_SCALE as U, type WorldFetch as W, type DecodedTextureArray as a, ByteReader as b, type LowresLevel as c, type MeshSection as d, type QuantizedSection as e, TILE_MAGIC as f, type TextureAnimation as g, type TileMagic as h, type WorldManifest as i, type WorldSource as j, biomePalette as k, canonicalQuadIndices as l, parseTextureArray as m, parseTile as n, parseTileQuantized as o, parseManifest as p, summarizeBiomes as q, summarizeSurfaceBiomes as r, stripNamespace as s, tileKey as t, worldFromFiles as u, worldFromUrl as v, worldFromDirectory as w };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { biomePalette, LOWRES_EMPTY, tileKey, parseLowresTile, maybeInflate, parseTileQuantized, summarizeSurfaceBiomes, parseTile, summarizeBiomes, worldFromUrl, parseManifest, parseTextureArray } from './chunk-
|
|
1
|
+
import { biomePalette, LOWRES_EMPTY, tileKey, parseLowresTile, maybeInflate, parseTileQuantized, summarizeSurfaceBiomes, parseTile, summarizeBiomes, worldFromUrl, parseManifest, parseTextureArray } from './chunk-M6KVJXCR.js';
|
|
2
2
|
import * as THREE2 from 'three';
|
|
3
3
|
|
|
4
4
|
var SKY_TOP = [0.3, 0.52, 0.84];
|
|
@@ -18,10 +18,20 @@ var VERT = (
|
|
|
18
18
|
in vec4 anrm;
|
|
19
19
|
uniform vec3 uPosMin;
|
|
20
20
|
uniform vec3 uPosScale;
|
|
21
|
+
uniform float uUvScale; // texture units per stored uv step (1 = f32 VTL6,
|
|
22
|
+
// 1/128 = VTL7's i16 fixed point); set per mesh
|
|
21
23
|
uniform sampler2D uPalette;
|
|
22
24
|
#else
|
|
23
25
|
in vec3 abcol;
|
|
24
26
|
in float alight; // packed (sky<<4)|block, 0..255
|
|
27
|
+
#endif
|
|
28
|
+
#ifdef LIGHTMAP
|
|
29
|
+
// Atlas-lit geometry (VTL8's greedy tail): baked light + AO come from a
|
|
30
|
+
// per-tile texture sampled in the fragment shader \u2014 per-BLOCK gradients on
|
|
31
|
+
// arbitrarily large merged quads \u2014 instead of per-vertex values.
|
|
32
|
+
in vec2 almuv; // half-texel atlas coords
|
|
33
|
+
uniform vec2 uLmSize; // atlas dims in texels
|
|
34
|
+
out vec2 vLmUv;
|
|
25
35
|
#endif
|
|
26
36
|
uniform vec2 uFogCenter; // streaming focus (world XZ)
|
|
27
37
|
uniform float uFogRadial; // 1 = fog by XZ distance from
|
|
@@ -36,17 +46,18 @@ var VERT = (
|
|
|
36
46
|
out float vSky; // saved sky light, 0..1
|
|
37
47
|
out float vBlk; // saved block light, 0..1
|
|
38
48
|
void main() {
|
|
39
|
-
vUv = uv;
|
|
40
49
|
vTint = atint;
|
|
41
50
|
vLayer = alayer;
|
|
42
51
|
vBiome = abiome;
|
|
43
52
|
#ifdef QUANTIZED
|
|
53
|
+
vUv = uv * uUvScale;
|
|
44
54
|
vec3 pos = uPosMin + position * uPosScale;
|
|
45
55
|
vec3 nrm = anrm.xyz;
|
|
46
56
|
// The light byte was stored as the int8 normal's 4th lane; undo the sign.
|
|
47
57
|
float light = anrm.w < 0.0 ? anrm.w + 256.0 : anrm.w;
|
|
48
58
|
vBcol = texelFetch(uPalette, ivec2(int(abiome + 0.5), 0), 0).rgb;
|
|
49
59
|
#else
|
|
60
|
+
vUv = uv;
|
|
50
61
|
vec3 pos = position;
|
|
51
62
|
vec3 nrm = normal;
|
|
52
63
|
float light = alight;
|
|
@@ -55,9 +66,13 @@ var VERT = (
|
|
|
55
66
|
float sky = floor(light / 16.0);
|
|
56
67
|
vSky = sky / 15.0;
|
|
57
68
|
vBlk = (light - sky * 16.0) / 15.0;
|
|
69
|
+
#ifdef LIGHTMAP
|
|
70
|
+
vLmUv = almuv * 0.5 / uLmSize;
|
|
71
|
+
#endif
|
|
58
72
|
// Water surface waves come from real mesh geometry (Minecraft flowing-water
|
|
59
73
|
// heights, baked in the mesher) \u2014 the normal here carries the slope, so the
|
|
60
|
-
// waves catch light. No vertex animation \u2014
|
|
74
|
+
// waves catch light. No vertex animation \u2014 motion comes from the animated
|
|
75
|
+
// texture frames (see the fragment shader's uAnim/uTime).
|
|
61
76
|
vN = normalize(mat3(modelMatrix) * nrm);
|
|
62
77
|
vec4 wp = modelMatrix * vec4(pos, 1.0);
|
|
63
78
|
vec4 mv = viewMatrix * wp;
|
|
@@ -75,6 +90,8 @@ var FRAG = (
|
|
|
75
90
|
precision highp float;
|
|
76
91
|
precision highp sampler2DArray;
|
|
77
92
|
uniform sampler2DArray map;
|
|
93
|
+
uniform sampler2D uAnim; // per-layer animation LUT: frame count, frametime lo/hi, interpolate
|
|
94
|
+
uniform float uTime; // seconds (the viewer advances and wraps it)
|
|
78
95
|
uniform vec3 lightDir;
|
|
79
96
|
uniform float uBiomeMix; // 0 = textured, 1 = biome layer
|
|
80
97
|
uniform float uHi; // highlighted biome id, or -1
|
|
@@ -99,6 +116,10 @@ var FRAG = (
|
|
|
99
116
|
in float vFog;
|
|
100
117
|
in float vSky;
|
|
101
118
|
in float vBlk;
|
|
119
|
+
#ifdef LIGHTMAP
|
|
120
|
+
uniform sampler2D uLightmap; // per-tile baked light+AO atlas
|
|
121
|
+
in vec2 vLmUv;
|
|
122
|
+
#endif
|
|
102
123
|
out vec4 frag;
|
|
103
124
|
const vec3 SKY = vec3(0.62, 0.72, 0.88); // hemispheric sky ambient
|
|
104
125
|
const vec3 GND = vec3(0.34, 0.31, 0.27); // hemispheric ground ambient
|
|
@@ -108,16 +129,16 @@ var FRAG = (
|
|
|
108
129
|
// Baked sky+block light -> a (brightness, colour) pair. Effective level is the
|
|
109
130
|
// brighter of (sky * daylight) and block light, eased and floored so caves read
|
|
110
131
|
// on a map; block-lit areas pick up a warm cast that sunlit ones don't.
|
|
111
|
-
void bakedLight(out float amt, out vec3 col) {
|
|
112
|
-
float sky =
|
|
113
|
-
float lvl = max(sky,
|
|
132
|
+
void bakedLight(float skyIn, float blkIn, out float amt, out vec3 col) {
|
|
133
|
+
float sky = skyIn * uDay;
|
|
134
|
+
float lvl = max(sky, blkIn);
|
|
114
135
|
// Minecraft's exact lightmap curve: brightness = l / (4 - 3l) (LightTexture).
|
|
115
136
|
// Concave \u2014 far darker in the midtones than a smoothstep (a light-7 nook is
|
|
116
137
|
// ~0.18, not ~0.5). Surface terrain is full skylight (l=1 \u2192 1.0); the curve
|
|
117
138
|
// only deepens shaded overhangs and caves, matching the game.
|
|
118
139
|
float curve = lvl / (4.0 - 3.0 * lvl);
|
|
119
140
|
amt = mix(uAmbient, 1.0, curve);
|
|
120
|
-
col = mix(vec3(1.0), TORCH, 0.6 * clamp(
|
|
141
|
+
col = mix(vec3(1.0), TORCH, 0.6 * clamp(blkIn - sky, 0.0, 1.0));
|
|
121
142
|
}
|
|
122
143
|
|
|
123
144
|
// Pixel-art textures + the colour uniforms are authored in sRGB; decode to
|
|
@@ -153,27 +174,59 @@ var FRAG = (
|
|
|
153
174
|
}
|
|
154
175
|
|
|
155
176
|
void main() {
|
|
177
|
+
// Light + AO source: per-vertex (interpolated), or \u2014 for atlas-lit
|
|
178
|
+
// geometry \u2014 the tile lightmap, whose bilinear filter reproduces the
|
|
179
|
+
// per-block-corner values exactly and keeps gradients inside big quads.
|
|
180
|
+
float skyL = vSky;
|
|
181
|
+
float blkL = vBlk;
|
|
182
|
+
float aoV = vTint.a;
|
|
183
|
+
#ifdef LIGHTMAP
|
|
184
|
+
vec3 lmS = texture(uLightmap, vLmUv).rgb;
|
|
185
|
+
skyL = lmS.r;
|
|
186
|
+
blkL = lmS.g;
|
|
187
|
+
aoV = lmS.b;
|
|
188
|
+
#endif
|
|
156
189
|
float lightAmt; vec3 lightCol;
|
|
157
|
-
bakedLight(lightAmt, lightCol);
|
|
158
|
-
|
|
190
|
+
bakedLight(skyL, blkL, lightAmt, lightCol);
|
|
191
|
+
// Animated textures (water, lava, magma, kelp, \u2026): the LUT row for this
|
|
192
|
+
// base layer holds the baked frame count and frametime; frames occupy the
|
|
193
|
+
// consecutive layers after the base, so playback is base + wrap(frame).
|
|
194
|
+
// vLayer is a flat varying \u2014 uniform per primitive \u2014 so the branch and the
|
|
195
|
+
// extra interpolation tap are quad-coherent.
|
|
196
|
+
vec4 anim = texelFetch(uAnim, ivec2(int(vLayer + 0.5), 0), 0) * 255.0;
|
|
197
|
+
float layer = vLayer;
|
|
198
|
+
float blendf = 0.0;
|
|
199
|
+
if (anim.r > 1.5) {
|
|
200
|
+
float ft = max(anim.g + anim.b * 256.0, 1.0); // ticks per frame
|
|
201
|
+
float frames = uTime * 20.0 / ft; // 20 ticks per second
|
|
202
|
+
layer = vLayer + mod(floor(frames), anim.r);
|
|
203
|
+
if (anim.a > 0.5) blendf = fract(frames); // interpolate: blend to next
|
|
204
|
+
}
|
|
205
|
+
vec4 t = texture(map, vec3(vUv, layer), -uSharpness); // negative bias = sharper
|
|
206
|
+
if (blendf > 0.0) {
|
|
207
|
+
float nxt = vLayer + mod(layer - vLayer + 1.0, anim.r);
|
|
208
|
+
t = mix(t, texture(map, vec3(vUv, nxt), -uSharpness), blendf);
|
|
209
|
+
}
|
|
159
210
|
if (t.a < 0.05) discard; // drop only fully-empty texels; the
|
|
160
211
|
// fractional edge becomes MSAA coverage
|
|
161
212
|
t.rgb = toLinear(t.rgb); // work in linear; encode at the end
|
|
162
213
|
vec3 fogCol = toLinear(uFogColor);
|
|
163
214
|
vec3 N = normalize(vN);
|
|
164
215
|
|
|
165
|
-
// Water pass:
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
//
|
|
216
|
+
// Water pass: the animated water texture \xD7 biome tint (the game's own
|
|
217
|
+
// formula \u2014 the texture is authored grey, its average ~0.45 linear, so a
|
|
218
|
+
// lift keeps overall brightness where a flat tint would sit), blended
|
|
219
|
+
// semi-transparently over the normally-lit seabed. The depth read comes
|
|
220
|
+
// from the SEABED darkening (sky light is attenuated through water in the
|
|
221
|
+
// light pass), seen through the clear surface, NOT from fading the water
|
|
222
|
+
// to opaque. So keep the surface fairly transparent so sand/gravel/seagrass
|
|
223
|
+
// show through; the wave look is the real flowing-water mesh geometry,
|
|
224
|
+
// whose sloped normal (vN) catches light.
|
|
171
225
|
if (uWater > 0.5) {
|
|
172
226
|
float depth = vTint.a;
|
|
173
|
-
vec3 wcol = toLinear(vTint.rgb);
|
|
227
|
+
vec3 wcol = t.rgb * toLinear(vTint.rgb) * 2.2;
|
|
174
228
|
wcol = mix(wcol, wcol * vec3(0.55, 0.66, 0.85), depth * 0.7); // deep water cools + deepens
|
|
175
|
-
|
|
176
|
-
float ndl2 = max(dot(Nw, normalize(lightDir)), 0.0);
|
|
229
|
+
float ndl2 = max(dot(N, normalize(lightDir)), 0.0);
|
|
177
230
|
// Flat-lit (mostly the water colour \xD7 baked light); only a small
|
|
178
231
|
// directional term so the wave-slope normals read, no blown-out sun sheen.
|
|
179
232
|
vec3 wlit = grade(wcol * (0.62 + 0.28 * SUN * ndl2) * lightAmt * lightCol * uExposure);
|
|
@@ -183,7 +236,7 @@ var FRAG = (
|
|
|
183
236
|
return;
|
|
184
237
|
}
|
|
185
238
|
|
|
186
|
-
float ao = 1.0 - (1.0 -
|
|
239
|
+
float ao = 1.0 - (1.0 - aoV) * uAoStrength; // baked AO, strength-scaled
|
|
187
240
|
vec3 texcol = t.rgb * toLinear(vTint.rgb);
|
|
188
241
|
float luma = dot(texcol, vec3(0.299, 0.587, 0.114));
|
|
189
242
|
// Biome view keeps terrain relief by modulating the flat biome colour by luma.
|
|
@@ -206,6 +259,24 @@ var FRAG = (
|
|
|
206
259
|
}
|
|
207
260
|
`
|
|
208
261
|
);
|
|
262
|
+
function animLutTexture(layers, anims) {
|
|
263
|
+
const n = Math.max(1, layers);
|
|
264
|
+
const data = new Uint8Array(4 * n);
|
|
265
|
+
for (let i = 0; i < n; i++) data[i * 4] = 1;
|
|
266
|
+
for (const a of anims) {
|
|
267
|
+
if (a.base < 0 || a.base >= n) continue;
|
|
268
|
+
const ft = Math.min(Math.max(a.frametime, 1), 65535);
|
|
269
|
+
data[a.base * 4 + 0] = Math.min(a.count, 255);
|
|
270
|
+
data[a.base * 4 + 1] = ft & 255;
|
|
271
|
+
data[a.base * 4 + 2] = ft >> 8;
|
|
272
|
+
data[a.base * 4 + 3] = a.interpolate ? 255 : 0;
|
|
273
|
+
}
|
|
274
|
+
const tex = new THREE2.DataTexture(data, n, 1, THREE2.RGBAFormat, THREE2.UnsignedByteType);
|
|
275
|
+
tex.magFilter = THREE2.NearestFilter;
|
|
276
|
+
tex.minFilter = THREE2.NearestFilter;
|
|
277
|
+
tex.needsUpdate = true;
|
|
278
|
+
return tex;
|
|
279
|
+
}
|
|
209
280
|
function paletteTexture(palette) {
|
|
210
281
|
const n = Math.max(1, palette.length);
|
|
211
282
|
const data = new Uint8Array(4 * n);
|
|
@@ -238,10 +309,18 @@ function createTerrainMaterial(texData, opts = {}) {
|
|
|
238
309
|
defines: opts.quantized ? { QUANTIZED: "" } : {},
|
|
239
310
|
uniforms: {
|
|
240
311
|
map: { value: tex },
|
|
312
|
+
uAnim: { value: animLutTexture(texData.layers, texData.anims ?? []) },
|
|
313
|
+
uTime: { value: 0 },
|
|
314
|
+
// seconds; the viewer advances it every frame
|
|
241
315
|
// Per-tile dequantization transform, set per-mesh in onBeforeRender
|
|
242
316
|
// (quantized path only; inert otherwise).
|
|
243
317
|
uPosMin: { value: new THREE2.Vector3() },
|
|
244
318
|
uPosScale: { value: new THREE2.Vector3(1, 1, 1) },
|
|
319
|
+
uUvScale: { value: 1 },
|
|
320
|
+
// Per-tile lightmap atlas, set per-mesh (used by the LIGHTMAP sibling
|
|
321
|
+
// material — see createLightmappedMaterial; inert here).
|
|
322
|
+
uLightmap: { value: null },
|
|
323
|
+
uLmSize: { value: new THREE2.Vector2(1, 1) },
|
|
245
324
|
uPalette: { value: opts.quantized ? paletteTexture(opts.palette ?? []) : null },
|
|
246
325
|
uFogCenter: { value: new THREE2.Vector2() },
|
|
247
326
|
// streaming focus (world XZ)
|
|
@@ -282,6 +361,18 @@ function createTerrainMaterial(texData, opts = {}) {
|
|
|
282
361
|
alphaToCoverage: true
|
|
283
362
|
});
|
|
284
363
|
}
|
|
364
|
+
function createLightmappedMaterial(terrain) {
|
|
365
|
+
const u = {};
|
|
366
|
+
for (const k in terrain.uniforms) u[k] = terrain.uniforms[k];
|
|
367
|
+
return new THREE2.ShaderMaterial({
|
|
368
|
+
glslVersion: THREE2.GLSL3,
|
|
369
|
+
defines: { ...terrain.defines, LIGHTMAP: "" },
|
|
370
|
+
uniforms: u,
|
|
371
|
+
vertexShader: VERT,
|
|
372
|
+
fragmentShader: FRAG,
|
|
373
|
+
alphaToCoverage: true
|
|
374
|
+
});
|
|
375
|
+
}
|
|
285
376
|
function createWaterMaterial(terrain) {
|
|
286
377
|
const u = {};
|
|
287
378
|
for (const k in terrain.uniforms) u[k] = terrain.uniforms[k];
|
|
@@ -430,6 +521,30 @@ function baseGeometry(section) {
|
|
|
430
521
|
return geom;
|
|
431
522
|
}
|
|
432
523
|
var WATER_FALLBACK = [0.3, 0.5, 0.85];
|
|
524
|
+
function lightmapTexture(lm) {
|
|
525
|
+
const tex = new THREE2.DataTexture(lm.pixels, lm.width, lm.height, THREE2.RGBAFormat, THREE2.UnsignedByteType);
|
|
526
|
+
tex.magFilter = THREE2.LinearFilter;
|
|
527
|
+
tex.minFilter = THREE2.LinearFilter;
|
|
528
|
+
tex.wrapS = THREE2.ClampToEdgeWrapping;
|
|
529
|
+
tex.wrapT = THREE2.ClampToEdgeWrapping;
|
|
530
|
+
tex.generateMipmaps = false;
|
|
531
|
+
tex.needsUpdate = true;
|
|
532
|
+
return tex;
|
|
533
|
+
}
|
|
534
|
+
function sliceSection(sec, start, end) {
|
|
535
|
+
return {
|
|
536
|
+
...sec,
|
|
537
|
+
vertexCount: end - start,
|
|
538
|
+
indexCount: (end - start) / 4 * 6,
|
|
539
|
+
positions: sec.positions.subarray(start * 3, end * 3),
|
|
540
|
+
uv: sec.uv.subarray(start * 2, end * 2),
|
|
541
|
+
colors: sec.colors.subarray(start * 4, end * 4),
|
|
542
|
+
normals: sec.normals.subarray(start * 4, end * 4),
|
|
543
|
+
layer: sec.layer.subarray(start, end),
|
|
544
|
+
biome: sec.biome.subarray(start, end),
|
|
545
|
+
indices: null
|
|
546
|
+
};
|
|
547
|
+
}
|
|
433
548
|
function buildTileMeshes(tile, palette, material, waterMaterial) {
|
|
434
549
|
const geom = baseGeometry(tile);
|
|
435
550
|
applyTexturedAttributes(geom, tile, palette, WATER_FALLBACK);
|
|
@@ -452,15 +567,41 @@ function quantizedBox(sec) {
|
|
|
452
567
|
const [sx, sy, sz] = sec.posScale;
|
|
453
568
|
return new THREE2.Box3(new THREE2.Vector3(mx, my, mz), new THREE2.Vector3(mx + 65535 * sx, my + 65535 * sy, mz + 65535 * sz));
|
|
454
569
|
}
|
|
455
|
-
|
|
570
|
+
var sharedQuadIndexAttr = null;
|
|
571
|
+
function sharedQuadIndex(vertexCount) {
|
|
572
|
+
const needed = vertexCount / 4 * 6;
|
|
573
|
+
if (!sharedQuadIndexAttr || sharedQuadIndexAttr.count < needed) {
|
|
574
|
+
const verts = Math.ceil(vertexCount * (sharedQuadIndexAttr ? 1.5 : 1) / 4) * 4;
|
|
575
|
+
const out = new Uint32Array(verts / 4 * 6);
|
|
576
|
+
for (let b = 0, o = 0; b < verts; b += 4) {
|
|
577
|
+
out[o++] = b;
|
|
578
|
+
out[o++] = b + 1;
|
|
579
|
+
out[o++] = b + 2;
|
|
580
|
+
out[o++] = b;
|
|
581
|
+
out[o++] = b + 2;
|
|
582
|
+
out[o++] = b + 3;
|
|
583
|
+
}
|
|
584
|
+
sharedQuadIndexAttr = new THREE2.BufferAttribute(out, 1);
|
|
585
|
+
}
|
|
586
|
+
return sharedQuadIndexAttr;
|
|
587
|
+
}
|
|
588
|
+
function isSharedQuadIndex(attr) {
|
|
589
|
+
return attr !== null && attr === sharedQuadIndexAttr;
|
|
590
|
+
}
|
|
591
|
+
function quantizedMesh(sec, material, lm) {
|
|
456
592
|
const geom = new THREE2.BufferGeometry();
|
|
457
593
|
geom.setAttribute("position", new THREE2.BufferAttribute(sec.positions, 3, false));
|
|
458
594
|
geom.setAttribute("anrm", new THREE2.BufferAttribute(sec.normals, 4, false));
|
|
459
|
-
geom.setAttribute("uv", new THREE2.BufferAttribute(sec.uv, 2));
|
|
595
|
+
geom.setAttribute("uv", new THREE2.BufferAttribute(sec.uv, 2, false));
|
|
460
596
|
geom.setAttribute("atint", new THREE2.BufferAttribute(sec.colors, 4, true));
|
|
461
597
|
geom.setAttribute("alayer", new THREE2.BufferAttribute(sec.layer, 1, false));
|
|
462
598
|
geom.setAttribute("abiome", new THREE2.BufferAttribute(sec.biome, 1, false));
|
|
463
|
-
|
|
599
|
+
if (sec.indices) {
|
|
600
|
+
geom.setIndex(new THREE2.BufferAttribute(sec.indices, 1));
|
|
601
|
+
} else {
|
|
602
|
+
geom.setIndex(sharedQuadIndex(sec.vertexCount));
|
|
603
|
+
geom.setDrawRange(0, sec.indexCount);
|
|
604
|
+
}
|
|
464
605
|
const box = quantizedBox(sec);
|
|
465
606
|
geom.boundingBox = box;
|
|
466
607
|
const sphere = new THREE2.Sphere();
|
|
@@ -469,24 +610,43 @@ function quantizedMesh(sec, material) {
|
|
|
469
610
|
const mesh = new THREE2.Mesh(geom, material);
|
|
470
611
|
const posMin = new THREE2.Vector3(...sec.posMin);
|
|
471
612
|
const posScale = new THREE2.Vector3(...sec.posScale);
|
|
613
|
+
const uvScale = sec.uvScale;
|
|
472
614
|
mesh.onBeforeRender = (_r, _s, _c, _g, mat) => {
|
|
473
615
|
const m = mat;
|
|
474
616
|
m.uniforms["uPosMin"].value.copy(posMin);
|
|
475
617
|
m.uniforms["uPosScale"].value.copy(posScale);
|
|
618
|
+
m.uniforms["uUvScale"].value = uvScale;
|
|
619
|
+
if (lm) {
|
|
620
|
+
m.uniforms["uLightmap"].value = lm.tex;
|
|
621
|
+
m.uniforms["uLmSize"].value.copy(lm.size);
|
|
622
|
+
}
|
|
476
623
|
m.uniformsNeedUpdate = true;
|
|
477
624
|
};
|
|
478
625
|
return mesh;
|
|
479
626
|
}
|
|
480
|
-
function buildQuantizedTileMeshes(tile, material, waterMaterial) {
|
|
481
|
-
const
|
|
627
|
+
function buildQuantizedTileMeshes(tile, material, waterMaterial, lmMaterial) {
|
|
628
|
+
const solid = tile.solid;
|
|
629
|
+
const lmStart = solid.lmStart ?? solid.vertexCount;
|
|
630
|
+
const hasLm = tile.lightmap !== void 0 && lmMaterial !== void 0 && lmStart < solid.vertexCount;
|
|
631
|
+
const head = hasLm ? sliceSection(solid, 0, lmStart) : solid;
|
|
632
|
+
const terrain = quantizedMesh(head, material);
|
|
482
633
|
const bounds = terrain.geometry.boundingBox.clone();
|
|
634
|
+
let terrainLm;
|
|
635
|
+
let lightmapTex;
|
|
636
|
+
if (hasLm) {
|
|
637
|
+
const lm = tile.lightmap;
|
|
638
|
+
lightmapTex = lightmapTexture(lm);
|
|
639
|
+
const tail = sliceSection(solid, lmStart, solid.vertexCount);
|
|
640
|
+
terrainLm = quantizedMesh(tail, lmMaterial, { tex: lightmapTex, size: new THREE2.Vector2(lm.width, lm.height) });
|
|
641
|
+
terrainLm.geometry.setAttribute("almuv", new THREE2.BufferAttribute(solid.lmuv, 2, false));
|
|
642
|
+
}
|
|
483
643
|
let water;
|
|
484
644
|
if (tile.fluid.vertexCount > 0) {
|
|
485
645
|
water = quantizedMesh(tile.fluid, waterMaterial);
|
|
486
646
|
water.renderOrder = 1;
|
|
487
647
|
bounds.union(water.geometry.boundingBox);
|
|
488
648
|
}
|
|
489
|
-
return { terrain, water, bounds };
|
|
649
|
+
return { terrain, terrainLm, lightmapTex, water, bounds };
|
|
490
650
|
}
|
|
491
651
|
function buildTerrain(tile, texData) {
|
|
492
652
|
const palette = biomePalette(tile.biomeNames?.length ?? 1);
|
|
@@ -592,11 +752,12 @@ function releaseAfterUpload(geom) {
|
|
|
592
752
|
for (const name of Object.keys(geom.attributes)) {
|
|
593
753
|
geom.getAttribute(name).onUpload(release);
|
|
594
754
|
}
|
|
595
|
-
if (geom.index) geom.index.onUpload(release);
|
|
755
|
+
if (geom.index && !isSharedQuadIndex(geom.index)) geom.index.onUpload(release);
|
|
596
756
|
}
|
|
597
757
|
var TileManager = class {
|
|
598
758
|
opts;
|
|
599
759
|
lowresMaterial;
|
|
760
|
+
lmMaterial;
|
|
600
761
|
index = /* @__PURE__ */ new Map();
|
|
601
762
|
records = /* @__PURE__ */ new Map();
|
|
602
763
|
emitter = new Emitter();
|
|
@@ -625,7 +786,7 @@ var TileManager = class {
|
|
|
625
786
|
minY = 0;
|
|
626
787
|
maxY = 320;
|
|
627
788
|
constructor(options) {
|
|
628
|
-
const { lowresMaterial, ...rest } = options;
|
|
789
|
+
const { lowresMaterial, lmMaterial, ...rest } = options;
|
|
629
790
|
this.opts = {
|
|
630
791
|
viewDistance: 768,
|
|
631
792
|
// Sized to fill the whole view-distance disc for 128-block tiles
|
|
@@ -636,7 +797,9 @@ var TileManager = class {
|
|
|
636
797
|
...rest
|
|
637
798
|
};
|
|
638
799
|
this.lowresMaterial = lowresMaterial ?? null;
|
|
800
|
+
this.lmMaterial = lmMaterial ?? null;
|
|
639
801
|
this.tileBlocks = options.manifest.tileBlocks;
|
|
802
|
+
if (options.manifest.maxSectionVerts) sharedQuadIndex(options.manifest.maxSectionVerts);
|
|
640
803
|
for (const t of options.manifest.tiles) this.index.set(tileKey(t.x, t.z), t);
|
|
641
804
|
this.lowLevels = this.lowresMaterial ? [...options.manifest.lowres?.levels ?? []].sort((a, b) => a.level - b.level) : [];
|
|
642
805
|
for (const lvl of this.lowLevels) {
|
|
@@ -740,6 +903,7 @@ var TileManager = class {
|
|
|
740
903
|
if (!rec || rec.state !== "built") continue;
|
|
741
904
|
rec.state = "ready";
|
|
742
905
|
this.opts.scene.add(rec.terrain);
|
|
906
|
+
if (rec.terrainLm) this.opts.scene.add(rec.terrainLm);
|
|
743
907
|
if (rec.water) this.opts.scene.add(rec.water);
|
|
744
908
|
this.coverageDirty = true;
|
|
745
909
|
this.invalidate();
|
|
@@ -885,7 +1049,7 @@ var TileManager = class {
|
|
|
885
1049
|
if (q) {
|
|
886
1050
|
rec.biomes = summarizeSurfaceBiomes(q.surface, q.biomeNames, this.opts.palette);
|
|
887
1051
|
rec.surface = { ...q.surface, biome: q.surface.biome.slice(), height: q.surface.height.slice() };
|
|
888
|
-
meshes = buildQuantizedTileMeshes(q, this.opts.material, this.opts.waterMaterial);
|
|
1052
|
+
meshes = buildQuantizedTileMeshes(q, this.opts.material, this.opts.waterMaterial, this.lmMaterial ?? void 0);
|
|
889
1053
|
rec.vertexCount = q.solid.vertexCount + q.fluid.vertexCount;
|
|
890
1054
|
rec.triangleCount = (q.solid.indexCount + q.fluid.indexCount) / 3;
|
|
891
1055
|
} else {
|
|
@@ -899,8 +1063,11 @@ var TileManager = class {
|
|
|
899
1063
|
rec.triangleCount = (tile.indexCount + (tile.fluid?.indexCount ?? 0)) / 3;
|
|
900
1064
|
}
|
|
901
1065
|
releaseAfterUpload(meshes.terrain.geometry);
|
|
1066
|
+
if (meshes.terrainLm) releaseAfterUpload(meshes.terrainLm.geometry);
|
|
902
1067
|
if (meshes.water) releaseAfterUpload(meshes.water.geometry);
|
|
903
1068
|
rec.terrain = meshes.terrain;
|
|
1069
|
+
rec.terrainLm = meshes.terrainLm;
|
|
1070
|
+
rec.lightmapTex = meshes.lightmapTex;
|
|
904
1071
|
rec.water = meshes.water;
|
|
905
1072
|
this.minY = Math.min(this.minY, meshes.bounds.min.y);
|
|
906
1073
|
this.maxY = Math.max(this.maxY, meshes.bounds.max.y);
|
|
@@ -921,11 +1088,13 @@ var TileManager = class {
|
|
|
921
1088
|
}
|
|
922
1089
|
unload(key, rec) {
|
|
923
1090
|
rec.abort?.abort();
|
|
924
|
-
for (const mesh of [rec.terrain, rec.water]) {
|
|
1091
|
+
for (const mesh of [rec.terrain, rec.terrainLm, rec.water]) {
|
|
925
1092
|
if (!mesh) continue;
|
|
926
1093
|
this.opts.scene.remove(mesh);
|
|
1094
|
+
if (isSharedQuadIndex(mesh.geometry.index)) mesh.geometry.setIndex(null);
|
|
927
1095
|
mesh.geometry.dispose();
|
|
928
1096
|
}
|
|
1097
|
+
rec.lightmapTex?.dispose();
|
|
929
1098
|
this.records.delete(key);
|
|
930
1099
|
this.failCounts.delete(key);
|
|
931
1100
|
this.coverageDirty = true;
|
|
@@ -2020,6 +2189,7 @@ var VantageViewer = class _VantageViewer {
|
|
|
2020
2189
|
const shader = createTerrainMaterial(texData, { quantized: true, palette });
|
|
2021
2190
|
const waterShader = createWaterMaterial(shader);
|
|
2022
2191
|
shader.uniforms["uFogRadial"].value = 1;
|
|
2192
|
+
const lmShader = manifest.format >= 4 ? createLightmappedMaterial(shader) : void 0;
|
|
2023
2193
|
const lowresShader = manifest.lowres ? createLowresMaterial(shader) : void 0;
|
|
2024
2194
|
this.shader = shader;
|
|
2025
2195
|
this.waterShader = waterShader;
|
|
@@ -2032,6 +2202,7 @@ var VantageViewer = class _VantageViewer {
|
|
|
2032
2202
|
scene: this.scene,
|
|
2033
2203
|
material: shader,
|
|
2034
2204
|
waterMaterial: waterShader,
|
|
2205
|
+
...lmShader ? { lmMaterial: lmShader } : {},
|
|
2035
2206
|
...lowresShader ? { lowresMaterial: lowresShader } : {},
|
|
2036
2207
|
palette,
|
|
2037
2208
|
...this.options.streaming
|
|
@@ -2056,7 +2227,8 @@ var VantageViewer = class _VantageViewer {
|
|
|
2056
2227
|
this.bounds.getSize(size);
|
|
2057
2228
|
this._biomes = [];
|
|
2058
2229
|
this.emitter.emit("load", {
|
|
2059
|
-
|
|
2230
|
+
// Streamed worlds: the tile format follows the manifest schema version.
|
|
2231
|
+
magic: manifest.format >= 4 ? "VTL8" : manifest.format >= 3 ? "VTL7" : "VTL6",
|
|
2060
2232
|
vertexCount: 0,
|
|
2061
2233
|
triangleCount: 0,
|
|
2062
2234
|
size,
|
|
@@ -2523,6 +2695,7 @@ var VantageViewer = class _VantageViewer {
|
|
|
2523
2695
|
this.mixCurrent += (this.mixTarget - this.mixCurrent) * 0.2;
|
|
2524
2696
|
if (Math.abs(this.mixCurrent - this.mixTarget) < 15e-4) this.mixCurrent = this.mixTarget;
|
|
2525
2697
|
this.shader.uniforms["uBiomeMix"].value = this.mixCurrent;
|
|
2698
|
+
this.shader.uniforms["uTime"].value = now / 1e3 % 3600;
|
|
2526
2699
|
}
|
|
2527
2700
|
this.pickHover();
|
|
2528
2701
|
this.renderer.setRenderTarget(this.msaa);
|
|
@@ -11,8 +11,16 @@ var TILE_MAGIC = {
|
|
|
11
11
|
/** + a top-down surface map for O(ray) biome picking. */
|
|
12
12
|
VTL5: "VTL5",
|
|
13
13
|
/** Quantized vertices: u16 positions (bbox transform) + u16 layer/biome. */
|
|
14
|
-
VTL6: "VTL6"
|
|
14
|
+
VTL6: "VTL6",
|
|
15
|
+
/** Compact quads: no index array (canonical quad topology is derived),
|
|
16
|
+
* delta-coded u16 positions, i16 fixed-point UV. */
|
|
17
|
+
VTL7: "VTL7",
|
|
18
|
+
/** + a per-tile lightmap atlas: the greedy vertex tail samples baked
|
|
19
|
+
* light/AO from a texture instead of vertices, so lighting gradients no
|
|
20
|
+
* longer fragment greedy merges (~23% fewer vertices). */
|
|
21
|
+
VTL8: "VTL8"
|
|
15
22
|
};
|
|
23
|
+
var UV_SCALE = 128;
|
|
16
24
|
var TEXTURE_MAGIC = "VTA1";
|
|
17
25
|
var ByteReader = class {
|
|
18
26
|
constructor(buffer, off = 0) {
|
|
@@ -83,6 +91,47 @@ var ByteReader = class {
|
|
|
83
91
|
};
|
|
84
92
|
|
|
85
93
|
// src/core/tile.ts
|
|
94
|
+
function canonicalQuadIndices(vertexCount) {
|
|
95
|
+
const out = new Uint32Array(vertexCount / 4 * 6);
|
|
96
|
+
for (let b = 0, o = 0; b < vertexCount; b += 4) {
|
|
97
|
+
out[o++] = b;
|
|
98
|
+
out[o++] = b + 1;
|
|
99
|
+
out[o++] = b + 2;
|
|
100
|
+
out[o++] = b;
|
|
101
|
+
out[o++] = b + 2;
|
|
102
|
+
out[o++] = b + 3;
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
function decodeDeltaPositions(zz, vertexCount) {
|
|
107
|
+
const out = new Uint16Array(3 * vertexCount);
|
|
108
|
+
let px = 0, py = 0, pz = 0;
|
|
109
|
+
for (let i = 0; i < vertexCount; i++) {
|
|
110
|
+
let z = zz[i * 3];
|
|
111
|
+
px = px + (z >>> 1 ^ -(z & 1)) & 65535;
|
|
112
|
+
out[i * 3] = px;
|
|
113
|
+
z = zz[i * 3 + 1];
|
|
114
|
+
py = py + (z >>> 1 ^ -(z & 1)) & 65535;
|
|
115
|
+
out[i * 3 + 1] = py;
|
|
116
|
+
z = zz[i * 3 + 2];
|
|
117
|
+
pz = pz + (z >>> 1 ^ -(z & 1)) & 65535;
|
|
118
|
+
out[i * 3 + 2] = pz;
|
|
119
|
+
}
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
function decodeDeltaPairs(zz) {
|
|
123
|
+
const out = new Uint16Array(zz.length);
|
|
124
|
+
let pu = 0, pv = 0;
|
|
125
|
+
for (let i = 0; i * 2 < zz.length; i++) {
|
|
126
|
+
let z = zz[i * 2];
|
|
127
|
+
pu = pu + (z >>> 1 ^ -(z & 1)) & 65535;
|
|
128
|
+
out[i * 2] = pu;
|
|
129
|
+
z = zz[i * 2 + 1];
|
|
130
|
+
pv = pv + (z >>> 1 ^ -(z & 1)) & 65535;
|
|
131
|
+
out[i * 2 + 1] = pv;
|
|
132
|
+
}
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
86
135
|
function expandNormals(packed, vertexCount) {
|
|
87
136
|
const out = new Float32Array(3 * vertexCount);
|
|
88
137
|
for (let i = 0; i < vertexCount; i++) {
|
|
@@ -171,18 +220,147 @@ function readQuantizedSectionRaw(r) {
|
|
|
171
220
|
const layer = r.u16a(vertexCount);
|
|
172
221
|
const biome = r.u16a(vertexCount);
|
|
173
222
|
r.align4();
|
|
174
|
-
return { vertexCount, indexCount, positions, posMin, posScale, uv, colors, normals, layer, biome, indices };
|
|
223
|
+
return { vertexCount, indexCount, positions, posMin, posScale, uv, uvScale: 1, colors, normals, layer, biome, indices };
|
|
224
|
+
}
|
|
225
|
+
function readCompactSectionRaw(r) {
|
|
226
|
+
const vertexCount = r.u32();
|
|
227
|
+
const uv = r.i16a(2 * vertexCount);
|
|
228
|
+
const colors = r.u8a(4 * vertexCount);
|
|
229
|
+
const normals = r.i8a(4 * vertexCount);
|
|
230
|
+
const bbox = r.f32(6);
|
|
231
|
+
const posMin = [bbox[0], bbox[1], bbox[2]];
|
|
232
|
+
const posScale = [bbox[3], bbox[4], bbox[5]];
|
|
233
|
+
const positions = decodeDeltaPositions(r.u16a(3 * vertexCount), vertexCount);
|
|
234
|
+
const layer = r.u16a(vertexCount);
|
|
235
|
+
const biome = r.u16a(vertexCount);
|
|
236
|
+
r.align4();
|
|
237
|
+
return {
|
|
238
|
+
vertexCount,
|
|
239
|
+
indexCount: vertexCount / 4 * 6,
|
|
240
|
+
positions,
|
|
241
|
+
posMin,
|
|
242
|
+
posScale,
|
|
243
|
+
uv,
|
|
244
|
+
uvScale: 1 / UV_SCALE,
|
|
245
|
+
colors,
|
|
246
|
+
normals,
|
|
247
|
+
layer,
|
|
248
|
+
biome,
|
|
249
|
+
indices: null
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function readLitSectionRaw(r) {
|
|
253
|
+
const vertexCount = r.u32();
|
|
254
|
+
const lmStart = r.u32();
|
|
255
|
+
const uv = r.i16a(2 * vertexCount);
|
|
256
|
+
const colors = r.u8a(4 * vertexCount);
|
|
257
|
+
const normals = r.i8a(4 * vertexCount);
|
|
258
|
+
const bbox = r.f32(6);
|
|
259
|
+
const posMin = [bbox[0], bbox[1], bbox[2]];
|
|
260
|
+
const posScale = [bbox[3], bbox[4], bbox[5]];
|
|
261
|
+
const positions = decodeDeltaPositions(r.u16a(3 * vertexCount), vertexCount);
|
|
262
|
+
const layer = r.u16a(vertexCount);
|
|
263
|
+
const biome = r.u16a(vertexCount);
|
|
264
|
+
const lmuv = decodeDeltaPairs(r.u16a(2 * (vertexCount - lmStart)));
|
|
265
|
+
r.align4();
|
|
266
|
+
return {
|
|
267
|
+
vertexCount,
|
|
268
|
+
indexCount: vertexCount / 4 * 6,
|
|
269
|
+
positions,
|
|
270
|
+
posMin,
|
|
271
|
+
posScale,
|
|
272
|
+
uv,
|
|
273
|
+
uvScale: 1 / UV_SCALE,
|
|
274
|
+
colors,
|
|
275
|
+
normals,
|
|
276
|
+
layer,
|
|
277
|
+
biome,
|
|
278
|
+
indices: null,
|
|
279
|
+
lmStart,
|
|
280
|
+
lmuv
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
function readLightmap(r) {
|
|
284
|
+
const width = r.u32();
|
|
285
|
+
const height = r.u32();
|
|
286
|
+
const n = width * height;
|
|
287
|
+
if (n === 0) return void 0;
|
|
288
|
+
const sky = r.u8a(n);
|
|
289
|
+
const blk = r.u8a(n);
|
|
290
|
+
const ao = r.u8a(n);
|
|
291
|
+
const pixels = new Uint8Array(4 * n);
|
|
292
|
+
for (let i = 0; i < n; i++) {
|
|
293
|
+
pixels[i * 4 + 0] = sky[i];
|
|
294
|
+
pixels[i * 4 + 1] = blk[i];
|
|
295
|
+
pixels[i * 4 + 2] = ao[i];
|
|
296
|
+
pixels[i * 4 + 3] = 255;
|
|
297
|
+
}
|
|
298
|
+
return { width, height, pixels };
|
|
299
|
+
}
|
|
300
|
+
function expandSection(raw) {
|
|
301
|
+
const { vertexCount, indexCount } = raw;
|
|
302
|
+
const positions = new Float32Array(3 * vertexCount);
|
|
303
|
+
const uv = new Float32Array(2 * vertexCount);
|
|
304
|
+
const layer = new Float32Array(vertexCount);
|
|
305
|
+
const biome = new Float32Array(vertexCount);
|
|
306
|
+
const [mnx, mny, mnz] = raw.posMin;
|
|
307
|
+
const [scx, scy, scz] = raw.posScale;
|
|
308
|
+
for (let i = 0; i < vertexCount; i++) {
|
|
309
|
+
positions[i * 3 + 0] = mnx + raw.positions[i * 3 + 0] * scx;
|
|
310
|
+
positions[i * 3 + 1] = mny + raw.positions[i * 3 + 1] * scy;
|
|
311
|
+
positions[i * 3 + 2] = mnz + raw.positions[i * 3 + 2] * scz;
|
|
312
|
+
uv[i * 2 + 0] = raw.uv[i * 2 + 0] * raw.uvScale;
|
|
313
|
+
uv[i * 2 + 1] = raw.uv[i * 2 + 1] * raw.uvScale;
|
|
314
|
+
layer[i] = raw.layer[i];
|
|
315
|
+
biome[i] = raw.biome[i];
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
vertexCount,
|
|
319
|
+
indexCount,
|
|
320
|
+
positions,
|
|
321
|
+
uv,
|
|
322
|
+
layer,
|
|
323
|
+
biome,
|
|
324
|
+
colors: raw.colors,
|
|
325
|
+
normals: expandNormals(raw.normals, vertexCount),
|
|
326
|
+
light: extractLight(raw.normals, vertexCount),
|
|
327
|
+
indices: canonicalQuadIndices(vertexCount),
|
|
328
|
+
...raw.lmStart !== void 0 ? { lmStart: raw.lmStart, lmuv: raw.lmuv } : {}
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
function readCompactSection(r) {
|
|
332
|
+
return expandSection(readCompactSectionRaw(r));
|
|
333
|
+
}
|
|
334
|
+
function bakeVertexLight(sec, lm) {
|
|
335
|
+
const { lmStart, lmuv } = sec;
|
|
336
|
+
if (lmStart === void 0 || !lmuv || lmStart >= sec.vertexCount) return;
|
|
337
|
+
const colors = sec.colors.slice();
|
|
338
|
+
const light = sec.light;
|
|
339
|
+
for (let i = lmStart; i < sec.vertexCount; i++) {
|
|
340
|
+
const k = i - lmStart;
|
|
341
|
+
const u = lmuv[k * 2] - 1 >> 1;
|
|
342
|
+
const v = lmuv[k * 2 + 1] - 1 >> 1;
|
|
343
|
+
const o = (v * lm.width + u) * 4;
|
|
344
|
+
const sky = Math.round(lm.pixels[o] / 17);
|
|
345
|
+
const blk = Math.round(lm.pixels[o + 1] / 17);
|
|
346
|
+
light[i] = sky << 4 | blk;
|
|
347
|
+
colors[i * 4 + 3] = lm.pixels[o + 2];
|
|
348
|
+
}
|
|
349
|
+
sec.colors = colors;
|
|
175
350
|
}
|
|
176
351
|
function parseTileQuantized(buffer) {
|
|
177
352
|
const r = new ByteReader(buffer);
|
|
178
|
-
|
|
353
|
+
const magic = r.magic();
|
|
354
|
+
if (magic !== TILE_MAGIC.VTL6 && magic !== TILE_MAGIC.VTL7 && magic !== TILE_MAGIC.VTL8) return null;
|
|
179
355
|
r.off = 4;
|
|
180
356
|
const version = r.u32();
|
|
181
|
-
const
|
|
182
|
-
const
|
|
357
|
+
const readSection = magic === TILE_MAGIC.VTL8 ? readLitSectionRaw : magic === TILE_MAGIC.VTL7 ? readCompactSectionRaw : readQuantizedSectionRaw;
|
|
358
|
+
const solid = readSection(r);
|
|
359
|
+
const fluid = readSection(r);
|
|
360
|
+
const lightmap = magic === TILE_MAGIC.VTL8 ? readLightmap(r) : void 0;
|
|
183
361
|
const surface = readSurface(r);
|
|
184
362
|
const biomeNames = readLegend(r);
|
|
185
|
-
return { magic
|
|
363
|
+
return { magic, version, solid, fluid, surface, biomeNames, ...lightmap ? { lightmap } : {} };
|
|
186
364
|
}
|
|
187
365
|
function readSurface(r) {
|
|
188
366
|
const width = r.u32();
|
|
@@ -209,6 +387,32 @@ function parseTile(buffer) {
|
|
|
209
387
|
const magic = r.magic();
|
|
210
388
|
r.off = 4;
|
|
211
389
|
const version = r.u32();
|
|
390
|
+
if (magic === TILE_MAGIC.VTL8) {
|
|
391
|
+
const solid = expandSection(readLitSectionRaw(r));
|
|
392
|
+
const fluid = expandSection(readLitSectionRaw(r));
|
|
393
|
+
const lightmap = readLightmap(r);
|
|
394
|
+
if (lightmap) bakeVertexLight(solid, lightmap);
|
|
395
|
+
const surface = readSurface(r);
|
|
396
|
+
const biomeNames = readLegend(r);
|
|
397
|
+
return {
|
|
398
|
+
magic,
|
|
399
|
+
version,
|
|
400
|
+
textured: true,
|
|
401
|
+
hasBiome: true,
|
|
402
|
+
...solid,
|
|
403
|
+
biomeNames,
|
|
404
|
+
fluid,
|
|
405
|
+
surface,
|
|
406
|
+
...lightmap ? { lightmap } : {}
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
if (magic === TILE_MAGIC.VTL7) {
|
|
410
|
+
const solid = readCompactSection(r);
|
|
411
|
+
const fluid = readCompactSection(r);
|
|
412
|
+
const surface = readSurface(r);
|
|
413
|
+
const biomeNames = readLegend(r);
|
|
414
|
+
return { magic, version, textured: true, hasBiome: true, ...solid, biomeNames, fluid, surface };
|
|
415
|
+
}
|
|
212
416
|
if (magic === TILE_MAGIC.VTL6) {
|
|
213
417
|
const solid = readQuantizedSection(r);
|
|
214
418
|
const fluid = readQuantizedSection(r);
|
|
@@ -270,7 +474,7 @@ function parseTile(buffer) {
|
|
|
270
474
|
indices
|
|
271
475
|
};
|
|
272
476
|
}
|
|
273
|
-
throw new Error(`vantage: unrecognized tile magic "${magic}" (expected VTL1\
|
|
477
|
+
throw new Error(`vantage: unrecognized tile magic "${magic}" (expected VTL1\u2013VTL7)`);
|
|
274
478
|
}
|
|
275
479
|
|
|
276
480
|
// src/core/texture.ts
|
|
@@ -280,12 +484,25 @@ function parseTextureArray(buffer) {
|
|
|
280
484
|
if (magic !== TEXTURE_MAGIC) {
|
|
281
485
|
throw new Error(`vantage: unrecognized texture magic "${magic}" (expected ${TEXTURE_MAGIC})`);
|
|
282
486
|
}
|
|
283
|
-
r.off =
|
|
487
|
+
r.off = 4;
|
|
488
|
+
const version = r.u32();
|
|
284
489
|
const width = r.u32();
|
|
285
490
|
const height = r.u32();
|
|
286
491
|
const layers = r.u32();
|
|
287
492
|
const pixels = r.u8a(width * height * layers * 4);
|
|
288
|
-
|
|
493
|
+
const anims = [];
|
|
494
|
+
if (version >= 2) {
|
|
495
|
+
const n = r.u32();
|
|
496
|
+
for (let i = 0; i < n; i++) {
|
|
497
|
+
const base = r.u32();
|
|
498
|
+
const count = r.u16();
|
|
499
|
+
const frametime = r.u16();
|
|
500
|
+
const interpolate = r.u8() !== 0;
|
|
501
|
+
r.off += 3;
|
|
502
|
+
anims.push({ base, count, frametime, interpolate });
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return { width, height, layers, pixels, anims };
|
|
289
506
|
}
|
|
290
507
|
|
|
291
508
|
// src/core/manifest.ts
|
|
@@ -296,8 +513,8 @@ function parseManifest(data) {
|
|
|
296
513
|
if (typeof data !== "object" || data === null) throw new Error("vantage: manifest is not an object");
|
|
297
514
|
const m = data;
|
|
298
515
|
const format = m["format"];
|
|
299
|
-
if (format !== 1 && format !== 2) {
|
|
300
|
-
throw new Error(`vantage: unsupported manifest format ${String(format)} (expected 1
|
|
516
|
+
if (format !== 1 && format !== 2 && format !== 3 && format !== 4) {
|
|
517
|
+
throw new Error(`vantage: unsupported manifest format ${String(format)} (expected 1..4)`);
|
|
301
518
|
}
|
|
302
519
|
const tileChunks = m["tileChunks"];
|
|
303
520
|
const tileBlocks = m["tileBlocks"];
|
|
@@ -348,11 +565,13 @@ function parseManifest(data) {
|
|
|
348
565
|
if (typeof s === "object" && s !== null && typeof s["x"] === "number" && typeof s["y"] === "number" && typeof s["z"] === "number") {
|
|
349
566
|
spawn = { x: s["x"], y: s["y"], z: s["z"] };
|
|
350
567
|
}
|
|
568
|
+
const maxSectionVerts = m["maxSectionVerts"];
|
|
351
569
|
return {
|
|
352
570
|
format,
|
|
353
571
|
tileChunks,
|
|
354
572
|
tileBlocks,
|
|
355
573
|
textures,
|
|
574
|
+
...typeof maxSectionVerts === "number" && maxSectionVerts > 0 ? { maxSectionVerts } : {},
|
|
356
575
|
...spawn ? { spawn } : {},
|
|
357
576
|
...lowres ? { lowres } : {},
|
|
358
577
|
biomes,
|
|
@@ -558,4 +777,4 @@ function summarizeBiomes(tile, palette) {
|
|
|
558
777
|
return toEntries(counts, names, pal);
|
|
559
778
|
}
|
|
560
779
|
|
|
561
|
-
export { ByteReader, LOWRES_EMPTY, LOWRES_MAGIC, TEXTURE_MAGIC, TILE_MAGIC, biomePalette, isGzip, maybeInflate, parseLowresTile, parseManifest, parseTextureArray, parseTile, parseTileQuantized, stripNamespace, summarizeBiomes, summarizeSurfaceBiomes, tileKey, worldFromDirectory, worldFromFiles, worldFromUrl };
|
|
780
|
+
export { ByteReader, LOWRES_EMPTY, LOWRES_MAGIC, TEXTURE_MAGIC, TILE_MAGIC, UV_SCALE, biomePalette, canonicalQuadIndices, isGzip, maybeInflate, parseLowresTile, parseManifest, parseTextureArray, parseTile, parseTileQuantized, stripNamespace, summarizeBiomes, summarizeSurfaceBiomes, tileKey, worldFromDirectory, worldFromFiles, worldFromUrl };
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { B as BiomeEntry, b as ByteReader, a as DecodedTextureArray, D as DecodedTile, L as LowresLevel, M as ManifestTile,
|
|
1
|
+
export { B as BiomeEntry, b as ByteReader, a as DecodedTextureArray, D as DecodedTile, L as Lightmap, c as LowresLevel, M as ManifestTile, d as MeshSection, e as QuantizedSection, Q as QuantizedTile, R as Rgb, S as SurfaceMap, T as TEXTURE_MAGIC, f as TILE_MAGIC, g as TextureAnimation, h as TileMagic, U as UV_SCALE, W as WorldFetch, i as WorldManifest, j as WorldSource, k as biomePalette, l as canonicalQuadIndices, p as parseManifest, m as parseTextureArray, n as parseTile, o as parseTileQuantized, s as stripNamespace, q as summarizeBiomes, r as summarizeSurfaceBiomes, t as tileKey, w as worldFromDirectory, u as worldFromFiles, v as worldFromUrl } from '../biome-CPP37ieY.js';
|
|
2
2
|
|
|
3
3
|
declare const LOWRES_MAGIC = "VLR1";
|
|
4
4
|
/** Height sentinel for samples with no terrain (unpopulated chunks). */
|
package/dist/core/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ByteReader, LOWRES_EMPTY, LOWRES_MAGIC, TEXTURE_MAGIC, TILE_MAGIC, biomePalette, isGzip, maybeInflate, parseLowresTile, parseManifest, parseTextureArray, parseTile, parseTileQuantized, stripNamespace, summarizeBiomes, summarizeSurfaceBiomes, tileKey, worldFromDirectory, worldFromFiles, worldFromUrl } from '../chunk-
|
|
1
|
+
export { ByteReader, LOWRES_EMPTY, LOWRES_MAGIC, TEXTURE_MAGIC, TILE_MAGIC, UV_SCALE, biomePalette, canonicalQuadIndices, isGzip, maybeInflate, parseLowresTile, parseManifest, parseTextureArray, parseTile, parseTileQuantized, stripNamespace, summarizeBiomes, summarizeSurfaceBiomes, tileKey, worldFromDirectory, worldFromFiles, worldFromUrl } from '../chunk-M6KVJXCR.js';
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { CSSProperties, ReactNode } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
export { D as DecodedTile } from '../biome-
|
|
5
|
-
import { g as TileSource, T as TextureSource, S as StreamingSettings, k as ViewMode, L as LightSettings, a as DisplaySettings, d as TileInfo, i as VantageViewer$1 } from '../viewer-
|
|
6
|
-
export { D as DEFAULT_ORBIT_ANGLE, V as VANILLA_DISPLAY } from '../viewer-
|
|
3
|
+
import { j as WorldSource, B as BiomeEntry } from '../biome-CPP37ieY.js';
|
|
4
|
+
export { D as DecodedTile } from '../biome-CPP37ieY.js';
|
|
5
|
+
import { g as TileSource, T as TextureSource, S as StreamingSettings, k as ViewMode, L as LightSettings, a as DisplaySettings, d as TileInfo, i as VantageViewer$1 } from '../viewer-GsEn9RpF.js';
|
|
6
|
+
export { D as DEFAULT_ORBIT_ANGLE, V as VANILLA_DISPLAY } from '../viewer-GsEn9RpF.js';
|
|
7
7
|
import 'three';
|
|
8
8
|
|
|
9
9
|
interface VantageViewerProps {
|
package/dist/react/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { VantageViewer, DEFAULT_ORBIT_ANGLE } from '../chunk-
|
|
2
|
-
export { DEFAULT_ORBIT_ANGLE, VANILLA_DISPLAY } from '../chunk-
|
|
3
|
-
import '../chunk-
|
|
1
|
+
import { VantageViewer, DEFAULT_ORBIT_ANGLE } from '../chunk-C7GIMQYZ.js';
|
|
2
|
+
export { DEFAULT_ORBIT_ANGLE, VANILLA_DISPLAY } from '../chunk-C7GIMQYZ.js';
|
|
3
|
+
import '../chunk-M6KVJXCR.js';
|
|
4
4
|
import { createContext, forwardRef, useRef, useState, useImperativeHandle, useEffect, useMemo, useContext } from 'react';
|
|
5
5
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
6
6
|
|
package/dist/three/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
|
-
import { R as Rgb, Q as QuantizedTile, D as DecodedTile, a as DecodedTextureArray, S as SurfaceMap } from '../biome-
|
|
3
|
-
export { B as BiomeEntry, b as ByteReader, L as LowresLevel, M as ManifestTile,
|
|
2
|
+
import { R as Rgb, Q as QuantizedTile, D as DecodedTile, a as DecodedTextureArray, S as SurfaceMap } from '../biome-CPP37ieY.js';
|
|
3
|
+
export { B as BiomeEntry, b as ByteReader, L as Lightmap, c as LowresLevel, M as ManifestTile, d as MeshSection, e as QuantizedSection, T as TEXTURE_MAGIC, f as TILE_MAGIC, g as TextureAnimation, h as TileMagic, U as UV_SCALE, W as WorldFetch, i as WorldManifest, j as WorldSource, k as biomePalette, l as canonicalQuadIndices, p as parseManifest, m as parseTextureArray, n as parseTile, o as parseTileQuantized, s as stripNamespace, q as summarizeBiomes, r as summarizeSurfaceBiomes, t as tileKey, w as worldFromDirectory, u as worldFromFiles, v as worldFromUrl } from '../biome-CPP37ieY.js';
|
|
4
4
|
import { LowresTile } from '../core/index.js';
|
|
5
5
|
export { LOWRES_EMPTY, LOWRES_MAGIC, isGzip, maybeInflate, parseLowresTile } from '../core/index.js';
|
|
6
|
-
export { D as DEFAULT_ORBIT_ANGLE, a as DisplaySettings, H as HeightSampler, L as LightSettings, b as LoadOptions, M as MapControls, c as MapControlsOptions, S as StreamingSettings, T as TextureSource, d as TileInfo, e as TileManager, f as TileManagerOptions, g as TileSource, h as TileStats, V as VANILLA_DISPLAY, i as VantageViewer, j as VantageViewerOptions, k as ViewMode } from '../viewer-
|
|
6
|
+
export { D as DEFAULT_ORBIT_ANGLE, a as DisplaySettings, H as HeightSampler, L as LightSettings, b as LoadOptions, M as MapControls, c as MapControlsOptions, S as StreamingSettings, T as TextureSource, d as TileInfo, e as TileManager, f as TileManagerOptions, g as TileSource, h as TileStats, V as VANILLA_DISPLAY, i as VantageViewer, j as VantageViewerOptions, k as ViewMode } from '../viewer-GsEn9RpF.js';
|
|
7
7
|
|
|
8
8
|
/** The objects and metadata produced from a tile. */
|
|
9
9
|
interface TerrainObjects {
|
|
@@ -26,6 +26,11 @@ interface TerrainObjects {
|
|
|
26
26
|
/** The meshes built from one tile with caller-provided (shared) materials. */
|
|
27
27
|
interface TileMeshes {
|
|
28
28
|
terrain: THREE.Mesh;
|
|
29
|
+
/** The atlas-lit tail of the solid geometry (VTL8), drawn with the
|
|
30
|
+
* lightmapped sibling material. */
|
|
31
|
+
terrainLm?: THREE.Mesh;
|
|
32
|
+
/** The tail's lightmap texture — dispose it with the tile. */
|
|
33
|
+
lightmapTex?: THREE.DataTexture;
|
|
29
34
|
water?: THREE.Mesh;
|
|
30
35
|
bounds: THREE.Box3;
|
|
31
36
|
}
|
|
@@ -37,11 +42,15 @@ interface TileMeshes {
|
|
|
37
42
|
*/
|
|
38
43
|
declare function buildTileMeshes(tile: DecodedTile, palette: Rgb[], material: THREE.ShaderMaterial, waterMaterial: THREE.ShaderMaterial): TileMeshes;
|
|
39
44
|
/**
|
|
40
|
-
* Build a VTL6 tile's meshes in the quantized fast path: shared QUANTIZED
|
|
45
|
+
* Build a VTL6/7/8 tile's meshes in the quantized fast path: shared QUANTIZED
|
|
41
46
|
* materials (from `createTerrainMaterial(tex, { quantized: true, palette })`),
|
|
42
47
|
* zero per-vertex CPU work. This is what the streaming TileManager uses.
|
|
48
|
+
*
|
|
49
|
+
* A VTL8 tile's atlas-lit vertex tail becomes its own mesh (`terrainLm`) drawn
|
|
50
|
+
* with `lmMaterial` (from {@link createLightmappedMaterial}) — pass it whenever
|
|
51
|
+
* the world is format 4+, or the tail would render full-bright.
|
|
43
52
|
*/
|
|
44
|
-
declare function buildQuantizedTileMeshes(tile: QuantizedTile, material: THREE.ShaderMaterial, waterMaterial: THREE.ShaderMaterial): TileMeshes;
|
|
53
|
+
declare function buildQuantizedTileMeshes(tile: QuantizedTile, material: THREE.ShaderMaterial, waterMaterial: THREE.ShaderMaterial, lmMaterial?: THREE.ShaderMaterial): TileMeshes;
|
|
45
54
|
/**
|
|
46
55
|
* Build renderable three.js objects from a decoded tile.
|
|
47
56
|
*
|
package/dist/three/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { DEFAULT_ORBIT_ANGLE, MapControls, SKY_HORIZON, SKY_TOP, TileManager, VANILLA_DISPLAY, VantageViewer, buildLowresMesh, buildQuantizedTileMeshes, buildTerrain, buildTileMeshes, createLowresMaterial, createSky, createTerrainMaterial, createWaterMaterial, pickBiome } from '../chunk-
|
|
2
|
-
export { ByteReader, LOWRES_EMPTY, LOWRES_MAGIC, TEXTURE_MAGIC, TILE_MAGIC, biomePalette, isGzip, maybeInflate, parseLowresTile, parseManifest, parseTextureArray, parseTile, parseTileQuantized, stripNamespace, summarizeBiomes, summarizeSurfaceBiomes, tileKey, worldFromDirectory, worldFromFiles, worldFromUrl } from '../chunk-
|
|
1
|
+
export { DEFAULT_ORBIT_ANGLE, MapControls, SKY_HORIZON, SKY_TOP, TileManager, VANILLA_DISPLAY, VantageViewer, buildLowresMesh, buildQuantizedTileMeshes, buildTerrain, buildTileMeshes, createLowresMaterial, createSky, createTerrainMaterial, createWaterMaterial, pickBiome } from '../chunk-C7GIMQYZ.js';
|
|
2
|
+
export { ByteReader, LOWRES_EMPTY, LOWRES_MAGIC, TEXTURE_MAGIC, TILE_MAGIC, UV_SCALE, biomePalette, canonicalQuadIndices, isGzip, maybeInflate, parseLowresTile, parseManifest, parseTextureArray, parseTile, parseTileQuantized, stripNamespace, summarizeBiomes, summarizeSurfaceBiomes, tileKey, worldFromDirectory, worldFromFiles, worldFromUrl } from '../chunk-M6KVJXCR.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
|
-
import {
|
|
2
|
+
import { i as WorldManifest, W as WorldFetch, R as Rgb, B as BiomeEntry, a as DecodedTextureArray, D as DecodedTile, j as WorldSource } from './biome-CPP37ieY.js';
|
|
3
3
|
|
|
4
4
|
interface TileManagerOptions {
|
|
5
5
|
manifest: WorldManifest;
|
|
@@ -11,6 +11,9 @@ interface TileManagerOptions {
|
|
|
11
11
|
material: THREE.ShaderMaterial;
|
|
12
12
|
/** The shared water shader (from {@link createWaterMaterial}). */
|
|
13
13
|
waterMaterial: THREE.ShaderMaterial;
|
|
14
|
+
/** The shared atlas-lit shader (from {@link createLightmappedMaterial});
|
|
15
|
+
* required to draw VTL8 tiles' lightmapped geometry (manifest format 4+). */
|
|
16
|
+
lmMaterial?: THREE.ShaderMaterial;
|
|
14
17
|
/** The shared lowres LOD shader (from {@link createLowresMaterial}); required
|
|
15
18
|
* to stream a format-2 manifest's lowres pyramid. */
|
|
16
19
|
lowresMaterial?: THREE.ShaderMaterial;
|
|
@@ -45,6 +48,7 @@ interface TileEvents extends Record<string, unknown> {
|
|
|
45
48
|
declare class TileManager {
|
|
46
49
|
private readonly opts;
|
|
47
50
|
private readonly lowresMaterial;
|
|
51
|
+
private readonly lmMaterial;
|
|
48
52
|
private readonly index;
|
|
49
53
|
private readonly records;
|
|
50
54
|
private readonly emitter;
|
package/package.json
CHANGED