@thoughts-on-things/vantage-mc 0.2.0 → 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.
@@ -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
- uv: Float32Array;
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
- indices: Uint32Array;
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: every array is a
148
- * zero-copy view and positions/layer/biome stay u16 for the vertex shader to
149
- * dequantize (the streaming fast path — no per-vertex CPU work). Returns `null`
150
- * for any other tile version; callers fall back to {@link parseTile}.
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
  /**
@@ -209,8 +250,12 @@ interface LowresLevel {
209
250
  }
210
251
  /** A parsed `manifest.json` for a tiled world render. */
211
252
  interface WorldManifest {
212
- /** 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`). */
213
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;
214
259
  /** Tile span in chunks per side. */
215
260
  tileChunks: number;
216
261
  /** Tile span in blocks per side (= tileChunks · 16). */
@@ -318,4 +363,4 @@ declare function summarizeSurfaceBiomes(surface: SurfaceMap, names: string[], pa
318
363
  */
319
364
  declare function summarizeBiomes(tile: DecodedTile, palette?: Rgb[]): BiomeEntry[];
320
365
 
321
- export { type BiomeEntry as B, type DecodedTile as D, type LowresLevel as L, type ManifestTile as M, type QuantizedTile as Q, type Rgb as R, type SurfaceMap as S, TEXTURE_MAGIC as T, type WorldFetch as W, type DecodedTextureArray as a, ByteReader as b, type MeshSection as c, type QuantizedSection as d, TILE_MAGIC as e, type TextureAnimation as f, type TileMagic as g, type WorldManifest as h, type WorldSource as i, biomePalette as j, parseTextureArray as k, parseTile as l, parseTileQuantized as m, summarizeBiomes as n, summarizeSurfaceBiomes as o, parseManifest as p, worldFromFiles as q, worldFromUrl as r, stripNamespace as s, tileKey as t, worldFromDirectory as w };
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-TC3HQWAD.js';
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,6 +66,9 @@ 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
74
  // waves catch light. No vertex animation \u2014 motion comes from the animated
@@ -102,6 +116,10 @@ var FRAG = (
102
116
  in float vFog;
103
117
  in float vSky;
104
118
  in float vBlk;
119
+ #ifdef LIGHTMAP
120
+ uniform sampler2D uLightmap; // per-tile baked light+AO atlas
121
+ in vec2 vLmUv;
122
+ #endif
105
123
  out vec4 frag;
106
124
  const vec3 SKY = vec3(0.62, 0.72, 0.88); // hemispheric sky ambient
107
125
  const vec3 GND = vec3(0.34, 0.31, 0.27); // hemispheric ground ambient
@@ -111,16 +129,16 @@ var FRAG = (
111
129
  // Baked sky+block light -> a (brightness, colour) pair. Effective level is the
112
130
  // brighter of (sky * daylight) and block light, eased and floored so caves read
113
131
  // on a map; block-lit areas pick up a warm cast that sunlit ones don't.
114
- void bakedLight(out float amt, out vec3 col) {
115
- float sky = vSky * uDay;
116
- float lvl = max(sky, vBlk);
132
+ void bakedLight(float skyIn, float blkIn, out float amt, out vec3 col) {
133
+ float sky = skyIn * uDay;
134
+ float lvl = max(sky, blkIn);
117
135
  // Minecraft's exact lightmap curve: brightness = l / (4 - 3l) (LightTexture).
118
136
  // Concave \u2014 far darker in the midtones than a smoothstep (a light-7 nook is
119
137
  // ~0.18, not ~0.5). Surface terrain is full skylight (l=1 \u2192 1.0); the curve
120
138
  // only deepens shaded overhangs and caves, matching the game.
121
139
  float curve = lvl / (4.0 - 3.0 * lvl);
122
140
  amt = mix(uAmbient, 1.0, curve);
123
- col = mix(vec3(1.0), TORCH, 0.6 * clamp(vBlk - sky, 0.0, 1.0));
141
+ col = mix(vec3(1.0), TORCH, 0.6 * clamp(blkIn - sky, 0.0, 1.0));
124
142
  }
125
143
 
126
144
  // Pixel-art textures + the colour uniforms are authored in sRGB; decode to
@@ -156,8 +174,20 @@ var FRAG = (
156
174
  }
157
175
 
158
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
159
189
  float lightAmt; vec3 lightCol;
160
- bakedLight(lightAmt, lightCol);
190
+ bakedLight(skyL, blkL, lightAmt, lightCol);
161
191
  // Animated textures (water, lava, magma, kelp, \u2026): the LUT row for this
162
192
  // base layer holds the baked frame count and frametime; frames occupy the
163
193
  // consecutive layers after the base, so playback is base + wrap(frame).
@@ -206,7 +236,7 @@ var FRAG = (
206
236
  return;
207
237
  }
208
238
 
209
- float ao = 1.0 - (1.0 - vTint.a) * uAoStrength; // baked AO (colour alpha), strength-scaled
239
+ float ao = 1.0 - (1.0 - aoV) * uAoStrength; // baked AO, strength-scaled
210
240
  vec3 texcol = t.rgb * toLinear(vTint.rgb);
211
241
  float luma = dot(texcol, vec3(0.299, 0.587, 0.114));
212
242
  // Biome view keeps terrain relief by modulating the flat biome colour by luma.
@@ -286,6 +316,11 @@ function createTerrainMaterial(texData, opts = {}) {
286
316
  // (quantized path only; inert otherwise).
287
317
  uPosMin: { value: new THREE2.Vector3() },
288
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) },
289
324
  uPalette: { value: opts.quantized ? paletteTexture(opts.palette ?? []) : null },
290
325
  uFogCenter: { value: new THREE2.Vector2() },
291
326
  // streaming focus (world XZ)
@@ -326,6 +361,18 @@ function createTerrainMaterial(texData, opts = {}) {
326
361
  alphaToCoverage: true
327
362
  });
328
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
+ }
329
376
  function createWaterMaterial(terrain) {
330
377
  const u = {};
331
378
  for (const k in terrain.uniforms) u[k] = terrain.uniforms[k];
@@ -474,6 +521,30 @@ function baseGeometry(section) {
474
521
  return geom;
475
522
  }
476
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
+ }
477
548
  function buildTileMeshes(tile, palette, material, waterMaterial) {
478
549
  const geom = baseGeometry(tile);
479
550
  applyTexturedAttributes(geom, tile, palette, WATER_FALLBACK);
@@ -496,15 +567,41 @@ function quantizedBox(sec) {
496
567
  const [sx, sy, sz] = sec.posScale;
497
568
  return new THREE2.Box3(new THREE2.Vector3(mx, my, mz), new THREE2.Vector3(mx + 65535 * sx, my + 65535 * sy, mz + 65535 * sz));
498
569
  }
499
- function quantizedMesh(sec, material) {
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) {
500
592
  const geom = new THREE2.BufferGeometry();
501
593
  geom.setAttribute("position", new THREE2.BufferAttribute(sec.positions, 3, false));
502
594
  geom.setAttribute("anrm", new THREE2.BufferAttribute(sec.normals, 4, false));
503
- geom.setAttribute("uv", new THREE2.BufferAttribute(sec.uv, 2));
595
+ geom.setAttribute("uv", new THREE2.BufferAttribute(sec.uv, 2, false));
504
596
  geom.setAttribute("atint", new THREE2.BufferAttribute(sec.colors, 4, true));
505
597
  geom.setAttribute("alayer", new THREE2.BufferAttribute(sec.layer, 1, false));
506
598
  geom.setAttribute("abiome", new THREE2.BufferAttribute(sec.biome, 1, false));
507
- geom.setIndex(new THREE2.BufferAttribute(sec.indices, 1));
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
+ }
508
605
  const box = quantizedBox(sec);
509
606
  geom.boundingBox = box;
510
607
  const sphere = new THREE2.Sphere();
@@ -513,24 +610,43 @@ function quantizedMesh(sec, material) {
513
610
  const mesh = new THREE2.Mesh(geom, material);
514
611
  const posMin = new THREE2.Vector3(...sec.posMin);
515
612
  const posScale = new THREE2.Vector3(...sec.posScale);
613
+ const uvScale = sec.uvScale;
516
614
  mesh.onBeforeRender = (_r, _s, _c, _g, mat) => {
517
615
  const m = mat;
518
616
  m.uniforms["uPosMin"].value.copy(posMin);
519
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
+ }
520
623
  m.uniformsNeedUpdate = true;
521
624
  };
522
625
  return mesh;
523
626
  }
524
- function buildQuantizedTileMeshes(tile, material, waterMaterial) {
525
- const terrain = quantizedMesh(tile.solid, material);
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);
526
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
+ }
527
643
  let water;
528
644
  if (tile.fluid.vertexCount > 0) {
529
645
  water = quantizedMesh(tile.fluid, waterMaterial);
530
646
  water.renderOrder = 1;
531
647
  bounds.union(water.geometry.boundingBox);
532
648
  }
533
- return { terrain, water, bounds };
649
+ return { terrain, terrainLm, lightmapTex, water, bounds };
534
650
  }
535
651
  function buildTerrain(tile, texData) {
536
652
  const palette = biomePalette(tile.biomeNames?.length ?? 1);
@@ -636,11 +752,12 @@ function releaseAfterUpload(geom) {
636
752
  for (const name of Object.keys(geom.attributes)) {
637
753
  geom.getAttribute(name).onUpload(release);
638
754
  }
639
- if (geom.index) geom.index.onUpload(release);
755
+ if (geom.index && !isSharedQuadIndex(geom.index)) geom.index.onUpload(release);
640
756
  }
641
757
  var TileManager = class {
642
758
  opts;
643
759
  lowresMaterial;
760
+ lmMaterial;
644
761
  index = /* @__PURE__ */ new Map();
645
762
  records = /* @__PURE__ */ new Map();
646
763
  emitter = new Emitter();
@@ -669,7 +786,7 @@ var TileManager = class {
669
786
  minY = 0;
670
787
  maxY = 320;
671
788
  constructor(options) {
672
- const { lowresMaterial, ...rest } = options;
789
+ const { lowresMaterial, lmMaterial, ...rest } = options;
673
790
  this.opts = {
674
791
  viewDistance: 768,
675
792
  // Sized to fill the whole view-distance disc for 128-block tiles
@@ -680,7 +797,9 @@ var TileManager = class {
680
797
  ...rest
681
798
  };
682
799
  this.lowresMaterial = lowresMaterial ?? null;
800
+ this.lmMaterial = lmMaterial ?? null;
683
801
  this.tileBlocks = options.manifest.tileBlocks;
802
+ if (options.manifest.maxSectionVerts) sharedQuadIndex(options.manifest.maxSectionVerts);
684
803
  for (const t of options.manifest.tiles) this.index.set(tileKey(t.x, t.z), t);
685
804
  this.lowLevels = this.lowresMaterial ? [...options.manifest.lowres?.levels ?? []].sort((a, b) => a.level - b.level) : [];
686
805
  for (const lvl of this.lowLevels) {
@@ -784,6 +903,7 @@ var TileManager = class {
784
903
  if (!rec || rec.state !== "built") continue;
785
904
  rec.state = "ready";
786
905
  this.opts.scene.add(rec.terrain);
906
+ if (rec.terrainLm) this.opts.scene.add(rec.terrainLm);
787
907
  if (rec.water) this.opts.scene.add(rec.water);
788
908
  this.coverageDirty = true;
789
909
  this.invalidate();
@@ -929,7 +1049,7 @@ var TileManager = class {
929
1049
  if (q) {
930
1050
  rec.biomes = summarizeSurfaceBiomes(q.surface, q.biomeNames, this.opts.palette);
931
1051
  rec.surface = { ...q.surface, biome: q.surface.biome.slice(), height: q.surface.height.slice() };
932
- meshes = buildQuantizedTileMeshes(q, this.opts.material, this.opts.waterMaterial);
1052
+ meshes = buildQuantizedTileMeshes(q, this.opts.material, this.opts.waterMaterial, this.lmMaterial ?? void 0);
933
1053
  rec.vertexCount = q.solid.vertexCount + q.fluid.vertexCount;
934
1054
  rec.triangleCount = (q.solid.indexCount + q.fluid.indexCount) / 3;
935
1055
  } else {
@@ -943,8 +1063,11 @@ var TileManager = class {
943
1063
  rec.triangleCount = (tile.indexCount + (tile.fluid?.indexCount ?? 0)) / 3;
944
1064
  }
945
1065
  releaseAfterUpload(meshes.terrain.geometry);
1066
+ if (meshes.terrainLm) releaseAfterUpload(meshes.terrainLm.geometry);
946
1067
  if (meshes.water) releaseAfterUpload(meshes.water.geometry);
947
1068
  rec.terrain = meshes.terrain;
1069
+ rec.terrainLm = meshes.terrainLm;
1070
+ rec.lightmapTex = meshes.lightmapTex;
948
1071
  rec.water = meshes.water;
949
1072
  this.minY = Math.min(this.minY, meshes.bounds.min.y);
950
1073
  this.maxY = Math.max(this.maxY, meshes.bounds.max.y);
@@ -965,11 +1088,13 @@ var TileManager = class {
965
1088
  }
966
1089
  unload(key, rec) {
967
1090
  rec.abort?.abort();
968
- for (const mesh of [rec.terrain, rec.water]) {
1091
+ for (const mesh of [rec.terrain, rec.terrainLm, rec.water]) {
969
1092
  if (!mesh) continue;
970
1093
  this.opts.scene.remove(mesh);
1094
+ if (isSharedQuadIndex(mesh.geometry.index)) mesh.geometry.setIndex(null);
971
1095
  mesh.geometry.dispose();
972
1096
  }
1097
+ rec.lightmapTex?.dispose();
973
1098
  this.records.delete(key);
974
1099
  this.failCounts.delete(key);
975
1100
  this.coverageDirty = true;
@@ -2064,6 +2189,7 @@ var VantageViewer = class _VantageViewer {
2064
2189
  const shader = createTerrainMaterial(texData, { quantized: true, palette });
2065
2190
  const waterShader = createWaterMaterial(shader);
2066
2191
  shader.uniforms["uFogRadial"].value = 1;
2192
+ const lmShader = manifest.format >= 4 ? createLightmappedMaterial(shader) : void 0;
2067
2193
  const lowresShader = manifest.lowres ? createLowresMaterial(shader) : void 0;
2068
2194
  this.shader = shader;
2069
2195
  this.waterShader = waterShader;
@@ -2076,6 +2202,7 @@ var VantageViewer = class _VantageViewer {
2076
2202
  scene: this.scene,
2077
2203
  material: shader,
2078
2204
  waterMaterial: waterShader,
2205
+ ...lmShader ? { lmMaterial: lmShader } : {},
2079
2206
  ...lowresShader ? { lowresMaterial: lowresShader } : {},
2080
2207
  palette,
2081
2208
  ...this.options.streaming
@@ -2100,7 +2227,8 @@ var VantageViewer = class _VantageViewer {
2100
2227
  this.bounds.getSize(size);
2101
2228
  this._biomes = [];
2102
2229
  this.emitter.emit("load", {
2103
- magic: "VTL6",
2230
+ // Streamed worlds: the tile format follows the manifest schema version.
2231
+ magic: manifest.format >= 4 ? "VTL8" : manifest.format >= 3 ? "VTL7" : "VTL6",
2104
2232
  vertexCount: 0,
2105
2233
  triangleCount: 0,
2106
2234
  size,
@@ -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
- if (r.magic() !== TILE_MAGIC.VTL6) return null;
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 solid = readQuantizedSectionRaw(r);
182
- const fluid = readQuantizedSectionRaw(r);
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: TILE_MAGIC.VTL6, version, solid, fluid, surface, biomeNames };
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\u2013VTL6)`);
477
+ throw new Error(`vantage: unrecognized tile magic "${magic}" (expected VTL1\u2013VTL7)`);
274
478
  }
275
479
 
276
480
  // src/core/texture.ts
@@ -309,8 +513,8 @@ function parseManifest(data) {
309
513
  if (typeof data !== "object" || data === null) throw new Error("vantage: manifest is not an object");
310
514
  const m = data;
311
515
  const format = m["format"];
312
- if (format !== 1 && format !== 2) {
313
- throw new Error(`vantage: unsupported manifest format ${String(format)} (expected 1 or 2)`);
516
+ if (format !== 1 && format !== 2 && format !== 3 && format !== 4) {
517
+ throw new Error(`vantage: unsupported manifest format ${String(format)} (expected 1..4)`);
314
518
  }
315
519
  const tileChunks = m["tileChunks"];
316
520
  const tileBlocks = m["tileBlocks"];
@@ -361,11 +565,13 @@ function parseManifest(data) {
361
565
  if (typeof s === "object" && s !== null && typeof s["x"] === "number" && typeof s["y"] === "number" && typeof s["z"] === "number") {
362
566
  spawn = { x: s["x"], y: s["y"], z: s["z"] };
363
567
  }
568
+ const maxSectionVerts = m["maxSectionVerts"];
364
569
  return {
365
570
  format,
366
571
  tileChunks,
367
572
  tileBlocks,
368
573
  textures,
574
+ ...typeof maxSectionVerts === "number" && maxSectionVerts > 0 ? { maxSectionVerts } : {},
369
575
  ...spawn ? { spawn } : {},
370
576
  ...lowres ? { lowres } : {},
371
577
  biomes,
@@ -571,4 +777,4 @@ function summarizeBiomes(tile, palette) {
571
777
  return toEntries(counts, names, pal);
572
778
  }
573
779
 
574
- 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 };
@@ -1,4 +1,4 @@
1
- export { B as BiomeEntry, b as ByteReader, a as DecodedTextureArray, D as DecodedTile, L as LowresLevel, M as ManifestTile, c as MeshSection, d as QuantizedSection, Q as QuantizedTile, R as Rgb, S as SurfaceMap, T as TEXTURE_MAGIC, e as TILE_MAGIC, f as TextureAnimation, g as TileMagic, W as WorldFetch, h as WorldManifest, i as WorldSource, j as biomePalette, p as parseManifest, k as parseTextureArray, l as parseTile, m as parseTileQuantized, s as stripNamespace, n as summarizeBiomes, o as summarizeSurfaceBiomes, t as tileKey, w as worldFromDirectory, q as worldFromFiles, r as worldFromUrl } from '../biome-CO419Coy.js';
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). */
@@ -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-TC3HQWAD.js';
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';
@@ -1,9 +1,9 @@
1
1
  import * as react from 'react';
2
2
  import { CSSProperties, ReactNode } from 'react';
3
- import { i as WorldSource, B as BiomeEntry } from '../biome-CO419Coy.js';
4
- export { D as DecodedTile } from '../biome-CO419Coy.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-D8UWlNNc.js';
6
- export { D as DEFAULT_ORBIT_ANGLE, V as VANILLA_DISPLAY } from '../viewer-D8UWlNNc.js';
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 {
@@ -1,6 +1,6 @@
1
- import { VantageViewer, DEFAULT_ORBIT_ANGLE } from '../chunk-576KSRE6.js';
2
- export { DEFAULT_ORBIT_ANGLE, VANILLA_DISPLAY } from '../chunk-576KSRE6.js';
3
- import '../chunk-TC3HQWAD.js';
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
 
@@ -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-CO419Coy.js';
3
- export { B as BiomeEntry, b as ByteReader, L as LowresLevel, M as ManifestTile, c as MeshSection, d as QuantizedSection, T as TEXTURE_MAGIC, e as TILE_MAGIC, f as TextureAnimation, g as TileMagic, W as WorldFetch, h as WorldManifest, i as WorldSource, j as biomePalette, p as parseManifest, k as parseTextureArray, l as parseTile, m as parseTileQuantized, s as stripNamespace, n as summarizeBiomes, o as summarizeSurfaceBiomes, t as tileKey, w as worldFromDirectory, q as worldFromFiles, r as worldFromUrl } from '../biome-CO419Coy.js';
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-D8UWlNNc.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-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
  *
@@ -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-576KSRE6.js';
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-TC3HQWAD.js';
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 { h as WorldManifest, W as WorldFetch, R as Rgb, B as BiomeEntry, a as DecodedTextureArray, D as DecodedTile, i as WorldSource } from './biome-CO419Coy.js';
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thoughts-on-things/vantage-mc",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Render a Minecraft (Java) world as a fast, beautiful 3D web map. The web frontend for the Vantage generator.",
5
5
  "type": "module",
6
6
  "license": "MIT",