@thoughts-on-things/vantage-mc 0.1.1 → 0.2.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.
@@ -158,6 +158,17 @@ declare function parseTileQuantized(buffer: ArrayBuffer): QuantizedTile | null;
158
158
  */
159
159
  declare function parseTile(buffer: ArrayBuffer): DecodedTile;
160
160
 
161
+ /** One animated texture's playback metadata (version ≥ 2 files). */
162
+ interface TextureAnimation {
163
+ /** First layer of the baked frame sequence — the layer meshes reference. */
164
+ base: number;
165
+ /** Layers in the sequence (the mcmeta frame order is already unrolled). */
166
+ count: number;
167
+ /** Ticks per frame (20 ticks/second). */
168
+ frametime: number;
169
+ /** Blend adjacent frames instead of stepping. */
170
+ interpolate: boolean;
171
+ }
161
172
  /** A decoded texture array: `layers` images of `width`×`height` RGBA pixels. */
162
173
  interface DecodedTextureArray {
163
174
  width: number;
@@ -165,9 +176,12 @@ interface DecodedTextureArray {
165
176
  layers: number;
166
177
  /** `width * height * layers * 4` tightly-packed RGBA bytes. */
167
178
  pixels: Uint8Array<ArrayBuffer>;
179
+ /** Animated textures (empty for version-1 files, which bake only frame 0). */
180
+ anims: TextureAnimation[];
168
181
  }
169
182
  /**
170
- * Decode a `.vtexarr` buffer.
183
+ * Decode a `.vtexarr` buffer. Version 2 appends an animation table after the
184
+ * pixels; version 1 (no table) still decodes, with `anims` empty.
171
185
  *
172
186
  * @throws if the magic is not `VTA1`.
173
187
  */
@@ -304,4 +318,4 @@ declare function summarizeSurfaceBiomes(surface: SurfaceMap, names: string[], pa
304
318
  */
305
319
  declare function summarizeBiomes(tile: DecodedTile, palette?: Rgb[]): BiomeEntry[];
306
320
 
307
- 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 TileMagic as f, type WorldManifest as g, type WorldSource as h, biomePalette as i, parseTextureArray as j, parseTile as k, parseTileQuantized as l, summarizeBiomes as m, summarizeSurfaceBiomes as n, worldFromFiles as o, parseManifest as p, worldFromUrl as q, stripNamespace as s, tileKey as t, worldFromDirectory as w };
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 };
@@ -1,4 +1,4 @@
1
- import { biomePalette, LOWRES_EMPTY, tileKey, parseLowresTile, maybeInflate, parseTileQuantized, summarizeSurfaceBiomes, parseTile, summarizeBiomes, worldFromUrl, parseManifest, parseTextureArray } from './chunk-O2MEM2GT.js';
1
+ import { biomePalette, LOWRES_EMPTY, tileKey, parseLowresTile, maybeInflate, parseTileQuantized, summarizeSurfaceBiomes, parseTile, summarizeBiomes, worldFromUrl, parseManifest, parseTextureArray } from './chunk-TC3HQWAD.js';
2
2
  import * as THREE2 from 'three';
3
3
 
4
4
  var SKY_TOP = [0.3, 0.52, 0.84];
@@ -57,7 +57,8 @@ var VERT = (
57
57
  vBlk = (light - sky * 16.0) / 15.0;
58
58
  // Water surface waves come from real mesh geometry (Minecraft flowing-water
59
59
  // heights, baked in the mesher) \u2014 the normal here carries the slope, so the
60
- // waves catch light. No vertex animation \u2014 the water is static.
60
+ // waves catch light. No vertex animation \u2014 motion comes from the animated
61
+ // texture frames (see the fragment shader's uAnim/uTime).
61
62
  vN = normalize(mat3(modelMatrix) * nrm);
62
63
  vec4 wp = modelMatrix * vec4(pos, 1.0);
63
64
  vec4 mv = viewMatrix * wp;
@@ -75,6 +76,8 @@ var FRAG = (
75
76
  precision highp float;
76
77
  precision highp sampler2DArray;
77
78
  uniform sampler2DArray map;
79
+ uniform sampler2D uAnim; // per-layer animation LUT: frame count, frametime lo/hi, interpolate
80
+ uniform float uTime; // seconds (the viewer advances and wraps it)
78
81
  uniform vec3 lightDir;
79
82
  uniform float uBiomeMix; // 0 = textured, 1 = biome layer
80
83
  uniform float uHi; // highlighted biome id, or -1
@@ -155,25 +158,45 @@ var FRAG = (
155
158
  void main() {
156
159
  float lightAmt; vec3 lightCol;
157
160
  bakedLight(lightAmt, lightCol);
158
- vec4 t = texture(map, vec3(vUv, vLayer), -uSharpness); // negative bias = sharper
161
+ // Animated textures (water, lava, magma, kelp, \u2026): the LUT row for this
162
+ // base layer holds the baked frame count and frametime; frames occupy the
163
+ // consecutive layers after the base, so playback is base + wrap(frame).
164
+ // vLayer is a flat varying \u2014 uniform per primitive \u2014 so the branch and the
165
+ // extra interpolation tap are quad-coherent.
166
+ vec4 anim = texelFetch(uAnim, ivec2(int(vLayer + 0.5), 0), 0) * 255.0;
167
+ float layer = vLayer;
168
+ float blendf = 0.0;
169
+ if (anim.r > 1.5) {
170
+ float ft = max(anim.g + anim.b * 256.0, 1.0); // ticks per frame
171
+ float frames = uTime * 20.0 / ft; // 20 ticks per second
172
+ layer = vLayer + mod(floor(frames), anim.r);
173
+ if (anim.a > 0.5) blendf = fract(frames); // interpolate: blend to next
174
+ }
175
+ vec4 t = texture(map, vec3(vUv, layer), -uSharpness); // negative bias = sharper
176
+ if (blendf > 0.0) {
177
+ float nxt = vLayer + mod(layer - vLayer + 1.0, anim.r);
178
+ t = mix(t, texture(map, vec3(vUv, nxt), -uSharpness), blendf);
179
+ }
159
180
  if (t.a < 0.05) discard; // drop only fully-empty texels; the
160
181
  // fractional edge becomes MSAA coverage
161
182
  t.rgb = toLinear(t.rgb); // work in linear; encode at the end
162
183
  vec3 fogCol = toLinear(uFogColor);
163
184
  vec3 N = normalize(vN);
164
185
 
165
- // Water pass: a semi-transparent blue tint over the normally-lit seabed.
166
- // The depth read comes from the SEABED darkening (sky light is
167
- // attenuated through water in the light pass), seen through the clear surface,
168
- // NOT from fading the water to opaque. So keep the surface fairly transparent
169
- // so sand/gravel/seagrass show through; the wave look is the real flowing-water
170
- // mesh geometry, whose sloped normal (vN) catches light.
186
+ // Water pass: the animated water texture \xD7 biome tint (the game's own
187
+ // formula \u2014 the texture is authored grey, its average ~0.45 linear, so a
188
+ // lift keeps overall brightness where a flat tint would sit), blended
189
+ // semi-transparently over the normally-lit seabed. The depth read comes
190
+ // from the SEABED darkening (sky light is attenuated through water in the
191
+ // light pass), seen through the clear surface, NOT from fading the water
192
+ // to opaque. So keep the surface fairly transparent so sand/gravel/seagrass
193
+ // show through; the wave look is the real flowing-water mesh geometry,
194
+ // whose sloped normal (vN) catches light.
171
195
  if (uWater > 0.5) {
172
196
  float depth = vTint.a;
173
- vec3 wcol = toLinear(vTint.rgb);
197
+ vec3 wcol = t.rgb * toLinear(vTint.rgb) * 2.2;
174
198
  wcol = mix(wcol, wcol * vec3(0.55, 0.66, 0.85), depth * 0.7); // deep water cools + deepens
175
- vec3 Nw = normalize(vN);
176
- float ndl2 = max(dot(Nw, normalize(lightDir)), 0.0);
199
+ float ndl2 = max(dot(N, normalize(lightDir)), 0.0);
177
200
  // Flat-lit (mostly the water colour \xD7 baked light); only a small
178
201
  // directional term so the wave-slope normals read, no blown-out sun sheen.
179
202
  vec3 wlit = grade(wcol * (0.62 + 0.28 * SUN * ndl2) * lightAmt * lightCol * uExposure);
@@ -206,6 +229,24 @@ var FRAG = (
206
229
  }
207
230
  `
208
231
  );
232
+ function animLutTexture(layers, anims) {
233
+ const n = Math.max(1, layers);
234
+ const data = new Uint8Array(4 * n);
235
+ for (let i = 0; i < n; i++) data[i * 4] = 1;
236
+ for (const a of anims) {
237
+ if (a.base < 0 || a.base >= n) continue;
238
+ const ft = Math.min(Math.max(a.frametime, 1), 65535);
239
+ data[a.base * 4 + 0] = Math.min(a.count, 255);
240
+ data[a.base * 4 + 1] = ft & 255;
241
+ data[a.base * 4 + 2] = ft >> 8;
242
+ data[a.base * 4 + 3] = a.interpolate ? 255 : 0;
243
+ }
244
+ const tex = new THREE2.DataTexture(data, n, 1, THREE2.RGBAFormat, THREE2.UnsignedByteType);
245
+ tex.magFilter = THREE2.NearestFilter;
246
+ tex.minFilter = THREE2.NearestFilter;
247
+ tex.needsUpdate = true;
248
+ return tex;
249
+ }
209
250
  function paletteTexture(palette) {
210
251
  const n = Math.max(1, palette.length);
211
252
  const data = new Uint8Array(4 * n);
@@ -238,6 +279,9 @@ function createTerrainMaterial(texData, opts = {}) {
238
279
  defines: opts.quantized ? { QUANTIZED: "" } : {},
239
280
  uniforms: {
240
281
  map: { value: tex },
282
+ uAnim: { value: animLutTexture(texData.layers, texData.anims ?? []) },
283
+ uTime: { value: 0 },
284
+ // seconds; the viewer advances it every frame
241
285
  // Per-tile dequantization transform, set per-mesh in onBeforeRender
242
286
  // (quantized path only; inert otherwise).
243
287
  uPosMin: { value: new THREE2.Vector3() },
@@ -2523,6 +2567,7 @@ var VantageViewer = class _VantageViewer {
2523
2567
  this.mixCurrent += (this.mixTarget - this.mixCurrent) * 0.2;
2524
2568
  if (Math.abs(this.mixCurrent - this.mixTarget) < 15e-4) this.mixCurrent = this.mixTarget;
2525
2569
  this.shader.uniforms["uBiomeMix"].value = this.mixCurrent;
2570
+ this.shader.uniforms["uTime"].value = now / 1e3 % 3600;
2526
2571
  }
2527
2572
  this.pickHover();
2528
2573
  this.renderer.setRenderTarget(this.msaa);
@@ -280,12 +280,25 @@ function parseTextureArray(buffer) {
280
280
  if (magic !== TEXTURE_MAGIC) {
281
281
  throw new Error(`vantage: unrecognized texture magic "${magic}" (expected ${TEXTURE_MAGIC})`);
282
282
  }
283
- r.off = 8;
283
+ r.off = 4;
284
+ const version = r.u32();
284
285
  const width = r.u32();
285
286
  const height = r.u32();
286
287
  const layers = r.u32();
287
288
  const pixels = r.u8a(width * height * layers * 4);
288
- return { width, height, layers, pixels };
289
+ const anims = [];
290
+ if (version >= 2) {
291
+ const n = r.u32();
292
+ for (let i = 0; i < n; i++) {
293
+ const base = r.u32();
294
+ const count = r.u16();
295
+ const frametime = r.u16();
296
+ const interpolate = r.u8() !== 0;
297
+ r.off += 3;
298
+ anims.push({ base, count, frametime, interpolate });
299
+ }
300
+ }
301
+ return { width, height, layers, pixels, anims };
289
302
  }
290
303
 
291
304
  // src/core/manifest.ts
@@ -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 TileMagic, W as WorldFetch, g as WorldManifest, h as WorldSource, i as biomePalette, p as parseManifest, j as parseTextureArray, k as parseTile, l as parseTileQuantized, s as stripNamespace, m as summarizeBiomes, n as summarizeSurfaceBiomes, t as tileKey, w as worldFromDirectory, o as worldFromFiles, q as worldFromUrl } from '../biome-BR6bKnti.js';
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';
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-O2MEM2GT.js';
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,9 +1,9 @@
1
1
  import * as react from 'react';
2
2
  import { CSSProperties, ReactNode } from 'react';
3
- import { h as WorldSource, B as BiomeEntry } from '../biome-BR6bKnti.js';
4
- export { D as DecodedTile } from '../biome-BR6bKnti.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-Bxc0eorS.js';
6
- export { D as DEFAULT_ORBIT_ANGLE, V as VANILLA_DISPLAY } from '../viewer-Bxc0eorS.js';
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';
7
7
  import 'three';
8
8
 
9
9
  interface VantageViewerProps {
@@ -1,6 +1,6 @@
1
- import { VantageViewer, DEFAULT_ORBIT_ANGLE } from '../chunk-I7TYYQX3.js';
2
- export { DEFAULT_ORBIT_ANGLE, VANILLA_DISPLAY } from '../chunk-I7TYYQX3.js';
3
- import '../chunk-O2MEM2GT.js';
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';
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-BR6bKnti.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 TileMagic, W as WorldFetch, g as WorldManifest, h as WorldSource, i as biomePalette, p as parseManifest, j as parseTextureArray, k as parseTile, l as parseTileQuantized, s as stripNamespace, m as summarizeBiomes, n as summarizeSurfaceBiomes, t as tileKey, w as worldFromDirectory, o as worldFromFiles, q as worldFromUrl } from '../biome-BR6bKnti.js';
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';
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-Bxc0eorS.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';
7
7
 
8
8
  /** The objects and metadata produced from a tile. */
9
9
  interface TerrainObjects {
@@ -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-I7TYYQX3.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-O2MEM2GT.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-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,5 +1,5 @@
1
1
  import * as THREE from 'three';
2
- import { g as WorldManifest, W as WorldFetch, R as Rgb, B as BiomeEntry, a as DecodedTextureArray, D as DecodedTile, h as WorldSource } from './biome-BR6bKnti.js';
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';
3
3
 
4
4
  interface TileManagerOptions {
5
5
  manifest: WorldManifest;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thoughts-on-things/vantage-mc",
3
- "version": "0.1.1",
3
+ "version": "0.2.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",