@thoughts-on-things/vantage-mc 0.2.0 → 0.4.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.
@@ -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-HGHIERQW.js';
2
+ export { DEFAULT_ORBIT_ANGLE, VANILLA_DISPLAY } from '../chunk-HGHIERQW.js';
3
+ import '../chunk-ILHVIGCI.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
 
@@ -181,6 +181,63 @@ var CSS = `
181
181
  }
182
182
  .vtg-coords b { color: var(--vtg-dim); font-weight: 600; margin-right: 1px; }
183
183
 
184
+ /* --- cave-view depth gauge ------------------------------------------------- */
185
+ .vtg-depth {
186
+ position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
187
+ display: flex; flex-direction: column; align-items: center; gap: 8px;
188
+ padding: 10px 8px; width: 58px;
189
+ animation: vtg-rise-y 0.3s cubic-bezier(0.4, 0, 0.2, 1) both;
190
+ }
191
+ .vtg-depth-val {
192
+ font: 11px var(--vtg-mono); color: var(--vtg-text); font-variant-numeric: tabular-nums;
193
+ display: flex; flex-direction: column; align-items: center; line-height: 1.3;
194
+ }
195
+ .vtg-depth-val b { color: var(--vtg-dim); font-weight: 600; font-size: 9px; letter-spacing: 0.08em; }
196
+ /* The interactive rail: the thumb and landmark labels hang outside the track,
197
+ so the rail stays unclipped while the track clips its own paint. */
198
+ .vtg-depth-rail {
199
+ position: relative; width: 14px; height: min(320px, 38vh);
200
+ cursor: ns-resize; touch-action: none;
201
+ }
202
+ .vtg-depth-rail:focus-visible { outline: 2px solid var(--vtg-accent); outline-offset: 4px; border-radius: 7px; }
203
+ .vtg-depth-track {
204
+ position: absolute; inset: 0; border-radius: 7px; overflow: hidden; pointer-events: none;
205
+ /* A core sample: sky, grass, stone, deepslate, bedrock. */
206
+ background: linear-gradient(180deg, #6f9bce 0%, #6e9150 12%, #6e6f74 48%, #3e424b 76%, #16181d 100%);
207
+ border: 1px solid var(--vtg-line);
208
+ box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.45);
209
+ }
210
+ /* The stratum the slice removed: struck through with hazard stripes. */
211
+ .vtg-depth-cut {
212
+ position: absolute; inset: 0 0 auto 0;
213
+ background: repeating-linear-gradient(-45deg, rgba(10, 13, 19, 0.75) 0 4px, rgba(24, 30, 42, 0.55) 4px 8px);
214
+ }
215
+ .vtg-depth-thumb {
216
+ position: absolute; left: -3px; right: -3px; height: 0; pointer-events: none;
217
+ }
218
+ .vtg-depth-thumb::before {
219
+ content: ''; position: absolute; left: 0; right: 0; top: -1.5px; height: 3px;
220
+ background: var(--vtg-accent); border-radius: 2px;
221
+ box-shadow: 0 0 6px rgba(91, 155, 255, 0.8), 0 1px 2px rgba(0, 0, 0, 0.6);
222
+ }
223
+ .vtg-depth-mark {
224
+ position: absolute; left: 0; right: 0; height: 0; pointer-events: none;
225
+ }
226
+ .vtg-depth-mark i { position: absolute; left: -4px; width: 4px; top: -0.5px; height: 1px; background: rgba(230, 238, 251, 0.55); }
227
+ .vtg-depth-mark span {
228
+ position: absolute; left: 17px; top: -5px; font: 9px var(--vtg-mono); color: var(--vtg-dim);
229
+ text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
230
+ }
231
+ .vtg-depth-close {
232
+ width: 24px; height: 24px; flex: none; display: grid; place-items: center;
233
+ border-radius: 7px; border: 1px solid transparent; background: transparent;
234
+ color: var(--vtg-muted); cursor: pointer; padding: 0;
235
+ transition: background 0.15s, color 0.15s, border-color 0.15s;
236
+ }
237
+ .vtg-depth-close:hover { background: rgba(132, 170, 230, 0.14); color: var(--vtg-text); border-color: var(--vtg-line); }
238
+ .vtg-depth-close svg { width: 13px; height: 13px; display: block; }
239
+ @keyframes vtg-rise-y { from { opacity: 0; transform: translate(-8px, -50%); } to { opacity: 1; transform: translate(0, -50%); } }
240
+
184
241
  /* --- centre reticle (navigation reference) -------------------------------- */
185
242
  .vtg-reticle {
186
243
  position: absolute; left: 50%; top: 50%; width: 30px; height: 30px;
@@ -604,19 +661,64 @@ var Icon = {
604
661
  fly: /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round", strokeLinejoin: "round", children: [
605
662
  /* @__PURE__ */ jsx("path", { d: "M14.5 1.5 1.2 6.6l5 1.7 1.7 5z" }),
606
663
  /* @__PURE__ */ jsx("path", { d: "M14.5 1.5 7.9 8.1" })
664
+ ] }),
665
+ camera: /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round", strokeLinejoin: "round", children: [
666
+ /* @__PURE__ */ jsx("path", { d: "M2 5h2.2L6 3h4l1.8 2H14v8H2z" }),
667
+ /* @__PURE__ */ jsx("circle", { cx: "8", cy: "9", r: "2.4" })
668
+ ] }),
669
+ layers: /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round", strokeLinejoin: "round", children: [
670
+ /* @__PURE__ */ jsx("path", { d: "M8 2.2 14 5.4 8 8.6 2 5.4z" }),
671
+ /* @__PURE__ */ jsx("path", { d: "M2.8 8.5 8 11.3l5.2-2.8" }),
672
+ /* @__PURE__ */ jsx("path", { d: "M2.8 11.3 8 14.1l5.2-2.8" })
673
+ ] }),
674
+ expand: /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", children: [
675
+ /* @__PURE__ */ jsx("path", { d: "M6 2.5H2.5V6" }),
676
+ /* @__PURE__ */ jsx("path", { d: "M10 2.5h3.5V6" }),
677
+ /* @__PURE__ */ jsx("path", { d: "M6 13.5H2.5V10" }),
678
+ /* @__PURE__ */ jsx("path", { d: "M10 13.5h3.5V10" })
679
+ ] }),
680
+ compress: /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", children: [
681
+ /* @__PURE__ */ jsx("path", { d: "M2.5 6H6V2.5" }),
682
+ /* @__PURE__ */ jsx("path", { d: "M13.5 6H10V2.5" }),
683
+ /* @__PURE__ */ jsx("path", { d: "M2.5 10H6v3.5" }),
684
+ /* @__PURE__ */ jsx("path", { d: "M13.5 10H10v3.5" })
607
685
  ] })
608
686
  };
609
- function MapNav({ compass = true, tilt = true, fly = true, zoom = true, home = true, coords = true, className }) {
610
- const { viewer } = useVantage();
687
+ function MapNav({
688
+ compass = true,
689
+ tilt = true,
690
+ fly = true,
691
+ zoom = true,
692
+ home = true,
693
+ coords = true,
694
+ caves = true,
695
+ screenshot = true,
696
+ fullscreen = true,
697
+ className
698
+ }) {
699
+ const { viewer, info } = useVantage();
700
+ const navRef = useRef(null);
611
701
  const needleRef = useRef(null);
612
702
  const coordRef = useRef(null);
613
703
  const tiltRef = useRef(null);
614
704
  const [flying, setFlying] = useState(false);
705
+ const [isFs, setIsFs] = useState(false);
706
+ const [sliced, setSliced] = useState(false);
615
707
  useEffect(() => {
616
708
  if (!viewer) return;
617
709
  setFlying(viewer.isFlying);
618
710
  return viewer.on("mode", ({ fly: fly2 }) => setFlying(fly2));
619
711
  }, [viewer]);
712
+ useEffect(() => {
713
+ if (!viewer) return;
714
+ setSliced(viewer.slice !== null);
715
+ return viewer.on("slice", ({ y }) => setSliced(y !== null));
716
+ }, [viewer]);
717
+ useEffect(() => {
718
+ const sync = () => setIsFs(document.fullscreenElement != null);
719
+ document.addEventListener("fullscreenchange", sync);
720
+ return () => document.removeEventListener("fullscreenchange", sync);
721
+ }, []);
620
722
  useEffect(() => {
621
723
  if (!viewer) return;
622
724
  let raf = 0;
@@ -653,7 +755,23 @@ function MapNav({ compass = true, tilt = true, fly = true, zoom = true, home = t
653
755
  }, [viewer]);
654
756
  if (!viewer) return null;
655
757
  const toggleTilt = () => viewer.tilt > TILT_THRESHOLD ? viewer.flatten() : viewer.setTilt(DEFAULT_ORBIT_ANGLE);
656
- return /* @__PURE__ */ jsxs("div", { className: className ? `vtg-nav vtg-glass ${className}` : "vtg-nav vtg-glass", role: "group", "aria-label": "map navigation", children: [
758
+ const takeScreenshot = () => {
759
+ const p = viewer.controls.position;
760
+ const a = document.createElement("a");
761
+ a.href = viewer.screenshot();
762
+ a.download = `vantage_${Math.round(p.x)}_${Math.round(p.z)}.png`;
763
+ a.click();
764
+ };
765
+ const showCaves = caves && info !== null && (viewer.hasCaves || sliced);
766
+ const canFullscreen = typeof document !== "undefined" && document.fullscreenEnabled;
767
+ const toggleFullscreen = () => {
768
+ if (document.fullscreenElement != null) document.exitFullscreen().catch(() => {
769
+ });
770
+ else
771
+ (navRef.current?.closest(".vtg-root") ?? document.documentElement).requestFullscreen().catch(() => {
772
+ });
773
+ };
774
+ return /* @__PURE__ */ jsxs("div", { ref: navRef, className: className ? `vtg-nav vtg-glass ${className}` : "vtg-nav vtg-glass", role: "group", "aria-label": "map navigation", children: [
657
775
  compass && /* @__PURE__ */ jsx("button", { type: "button", className: "vtg-compass", title: "Face north", "aria-label": "Face north", onClick: () => viewer.resetNorth(), children: /* @__PURE__ */ jsxs("svg", { viewBox: "-16 -16 32 32", "aria-hidden": "true", children: [
658
776
  /* @__PURE__ */ jsx("circle", { cx: "0", cy: "0", r: "14.5", fill: "none", stroke: "rgba(140,178,238,0.18)", strokeWidth: "1" }),
659
777
  /* @__PURE__ */ jsxs("g", { ref: needleRef, children: [
@@ -675,16 +793,135 @@ function MapNav({ compass = true, tilt = true, fly = true, zoom = true, home = t
675
793
  children: Icon.fly
676
794
  }
677
795
  ),
796
+ showCaves && /* @__PURE__ */ jsx(
797
+ "button",
798
+ {
799
+ type: "button",
800
+ className: sliced ? "vtg-navbtn vtg-on" : "vtg-navbtn",
801
+ title: sliced ? "Close the cave view (C)" : "Cave view \u2014 slice into the world (C)",
802
+ "aria-label": "Toggle cave view",
803
+ "aria-pressed": sliced,
804
+ onClick: () => viewer.toggleSlice(),
805
+ children: Icon.layers
806
+ }
807
+ ),
678
808
  coords && /* @__PURE__ */ jsxs("span", { className: "vtg-coords", title: "World X, Z at view centre", children: [
679
809
  /* @__PURE__ */ jsx("b", { children: "xz" }),
680
810
  /* @__PURE__ */ jsx("span", { ref: coordRef, children: "0, 0" })
681
811
  ] }),
682
- !flying && (zoom || home) && /* @__PURE__ */ jsx("span", { className: "vtg-nav-sep" }),
812
+ (screenshot || fullscreen && canFullscreen || !flying && (zoom || home)) && /* @__PURE__ */ jsx("span", { className: "vtg-nav-sep" }),
683
813
  zoom && !flying && /* @__PURE__ */ jsxs(Fragment, { children: [
684
814
  /* @__PURE__ */ jsx("button", { type: "button", className: "vtg-navbtn", title: "Zoom out", "aria-label": "Zoom out", onClick: () => viewer.zoomBy(-1), children: Icon.minus }),
685
815
  /* @__PURE__ */ jsx("button", { type: "button", className: "vtg-navbtn", title: "Zoom in", "aria-label": "Zoom in", onClick: () => viewer.zoomBy(1), children: Icon.plus })
686
816
  ] }),
687
- home && !flying && /* @__PURE__ */ jsx("button", { type: "button", className: "vtg-navbtn", title: "Reset view", "aria-label": "Reset view", onClick: () => viewer.resetView(), children: Icon.home })
817
+ home && !flying && /* @__PURE__ */ jsx("button", { type: "button", className: "vtg-navbtn", title: "Reset view", "aria-label": "Reset view", onClick: () => viewer.resetView(), children: Icon.home }),
818
+ screenshot && /* @__PURE__ */ jsx("button", { type: "button", className: "vtg-navbtn", title: "Save a screenshot (PNG)", "aria-label": "Save a screenshot", onClick: takeScreenshot, children: Icon.camera }),
819
+ fullscreen && canFullscreen && /* @__PURE__ */ jsx(
820
+ "button",
821
+ {
822
+ type: "button",
823
+ className: isFs ? "vtg-navbtn vtg-on" : "vtg-navbtn",
824
+ title: isFs ? "Exit fullscreen" : "Fullscreen",
825
+ "aria-label": "Toggle fullscreen",
826
+ "aria-pressed": isFs,
827
+ onClick: toggleFullscreen,
828
+ children: isFs ? Icon.compress : Icon.expand
829
+ }
830
+ )
831
+ ] });
832
+ }
833
+ function isTypingTarget2(t) {
834
+ if (!(t instanceof HTMLElement)) return false;
835
+ return t.isContentEditable || t.tagName === "INPUT" || t.tagName === "TEXTAREA";
836
+ }
837
+ function DepthSlider({ toggleKey = "c", step = 4, className }) {
838
+ const { viewer, info } = useVantage();
839
+ const trackRef = useRef(null);
840
+ const [sliceY, setSliceY] = useState(null);
841
+ useEffect(() => {
842
+ if (!viewer) return;
843
+ setSliceY(viewer.slice);
844
+ return viewer.on("slice", ({ y }) => setSliceY(y));
845
+ }, [viewer]);
846
+ useEffect(() => {
847
+ if (!viewer) return;
848
+ const onKey = (e) => {
849
+ if (isTypingTarget2(e.target)) return;
850
+ if (toggleKey && e.key.toLowerCase() === toggleKey.toLowerCase()) {
851
+ if (viewer.hasCaves || viewer.slice !== null) viewer.toggleSlice();
852
+ } else if (viewer.slice !== null && (e.key === "[" || e.key === "]")) {
853
+ viewer.setSlice(viewer.slice + (e.key === "]" ? step : -step));
854
+ }
855
+ };
856
+ window.addEventListener("keydown", onKey);
857
+ return () => window.removeEventListener("keydown", onKey);
858
+ }, [viewer, toggleKey, step]);
859
+ if (!viewer || !info || sliceY === null) return null;
860
+ const { min, max } = viewer.sliceRange;
861
+ const frac = (y) => Math.min(Math.max((max - y) / (max - min), 0), 1);
862
+ const thumbTop = frac(sliceY) * 100;
863
+ const setFromPointer = (e) => {
864
+ const track = trackRef.current;
865
+ if (!track) return;
866
+ const r = track.getBoundingClientRect();
867
+ const t = Math.min(Math.max((e.clientY - r.top) / r.height, 0), 1);
868
+ viewer.setSlice(Math.round(max - t * (max - min)));
869
+ };
870
+ const onPointerDown = (e) => {
871
+ e.preventDefault();
872
+ e.currentTarget.setPointerCapture(e.pointerId);
873
+ setFromPointer(e);
874
+ };
875
+ const marks = [];
876
+ if (63 > min && 63 < max) marks.push({ y: 63, label: "sea" });
877
+ if (0 > min && 0 < max) marks.push({ y: 0, label: "0" });
878
+ return /* @__PURE__ */ jsxs("div", { className: className ? `vtg-depth vtg-glass ${className}` : "vtg-depth vtg-glass", role: "group", "aria-label": "cave view depth", children: [
879
+ /* @__PURE__ */ jsxs("div", { className: "vtg-depth-val", title: "Slice depth (world Y)", children: [
880
+ /* @__PURE__ */ jsx("b", { children: "Y" }),
881
+ Math.round(sliceY)
882
+ ] }),
883
+ /* @__PURE__ */ jsxs(
884
+ "div",
885
+ {
886
+ ref: trackRef,
887
+ className: "vtg-depth-rail",
888
+ role: "slider",
889
+ "aria-label": "Slice depth",
890
+ "aria-valuemin": min,
891
+ "aria-valuemax": max,
892
+ "aria-valuenow": Math.round(sliceY),
893
+ "aria-orientation": "vertical",
894
+ tabIndex: 0,
895
+ onPointerDown,
896
+ onPointerMove: (e) => e.buttons === 1 && setFromPointer(e),
897
+ onKeyDown: (e) => {
898
+ if (e.key === "ArrowUp") viewer.setSlice(sliceY + 1);
899
+ else if (e.key === "ArrowDown") viewer.setSlice(sliceY - 1);
900
+ },
901
+ children: [
902
+ /* @__PURE__ */ jsx("div", { className: "vtg-depth-track", children: /* @__PURE__ */ jsx("div", { className: "vtg-depth-cut", style: { height: `${thumbTop}%` } }) }),
903
+ marks.map((m) => /* @__PURE__ */ jsxs("div", { className: "vtg-depth-mark", style: { top: `${frac(m.y) * 100}%` }, children: [
904
+ /* @__PURE__ */ jsx("i", {}),
905
+ /* @__PURE__ */ jsx("span", { children: m.label })
906
+ ] }, m.label)),
907
+ /* @__PURE__ */ jsx("div", { className: "vtg-depth-thumb", style: { top: `${thumbTop}%` } })
908
+ ]
909
+ }
910
+ ),
911
+ /* @__PURE__ */ jsx(
912
+ "button",
913
+ {
914
+ type: "button",
915
+ className: "vtg-depth-close",
916
+ title: "Close the cave view",
917
+ "aria-label": "Close the cave view",
918
+ onClick: () => viewer.setSlice(null),
919
+ children: /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", children: [
920
+ /* @__PURE__ */ jsx("path", { d: "M4.5 4.5 11.5 11.5" }),
921
+ /* @__PURE__ */ jsx("path", { d: "M11.5 4.5 4.5 11.5" })
922
+ ] })
923
+ }
924
+ )
688
925
  ] });
689
926
  }
690
927
  function Reticle({ className }) {
@@ -712,4 +949,4 @@ function Reticle({ className }) {
712
949
  ] });
713
950
  }
714
951
 
715
- export { BiomeLayer, CSS, LightPanel, MapNav, Panel, QUALITY_PRESETS, Reticle, SettingsPanel, VantageViewer2 as VantageViewer, injectStyles, useVantage };
952
+ export { BiomeLayer, CSS, DepthSlider, LightPanel, MapNav, Panel, QUALITY_PRESETS, Reticle, SettingsPanel, VantageViewer2 as VantageViewer, injectStyles, useVantage };
@@ -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-uodZHCCI.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-uodZHCCI.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-Ba31QN1M.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-HGHIERQW.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-ILHVIGCI.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-uodZHCCI.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;
@@ -18,7 +21,8 @@ interface TileManagerOptions {
18
21
  palette: Rgb[];
19
22
  /** Stream-in radius around the focus, in blocks. Default `768`. */
20
23
  viewDistance?: number;
21
- /** Hard cap on resident tiles (nearest win). Default `96`. */
24
+ /** Hard cap on resident tiles (nearest win). Default `120` (fills the
25
+ * default view-distance disc; matches the settings panel's "med" preset). */
22
26
  maxTiles?: number;
23
27
  /** Concurrent tile fetches. Default `4`. */
24
28
  concurrency?: number;
@@ -45,6 +49,7 @@ interface TileEvents extends Record<string, unknown> {
45
49
  declare class TileManager {
46
50
  private readonly opts;
47
51
  private readonly lowresMaterial;
52
+ private readonly lmMaterial;
48
53
  private readonly index;
49
54
  private readonly records;
50
55
  private readonly emitter;
@@ -55,6 +60,8 @@ declare class TileManager {
55
60
  private readonly lowIndex;
56
61
  /** Set when residency changed and lowres visibility needs recomputing. */
57
62
  private coverageDirty;
63
+ /** Tiles mid stream-in fade; drained by update(), keeps the viewer drawing. */
64
+ private readonly fadingKeys;
58
65
  private queue;
59
66
  /** Built tiles awaiting scene insertion — flushed ONE per update() call so
60
67
  * multi-MB GPU uploads never pile into a single frame. */
@@ -93,6 +100,16 @@ declare class TileManager {
93
100
  * loading hundreds of tiles) it drains faster so the map sharpens in a
94
101
  * couple of seconds instead of many. */
95
102
  private flushOne;
103
+ /** Stream-in fade length. Long enough to read as a dissolve, short enough
104
+ * that a fast pan still feels instant. */
105
+ static readonly FADE_MS = 280;
106
+ /** Whether any tile is mid stream-in fade — the viewer keeps drawing while
107
+ * true so the dissolve actually animates under render-on-demand. */
108
+ get fading(): boolean;
109
+ /** Chain a per-draw uFade write onto each mesh's onBeforeRender (after the
110
+ * dequantize-uniform hook terrain.ts installs). Every TileManager mesh gets
111
+ * one — the materials are shared, so each draw must set its own fade. */
112
+ private attachFade;
96
113
  /**
97
114
  * Hide every lowres tile whose footprint is fully SHOWN by finer data.
98
115
  * "Shown" is transitive, computed bottom-up: a hires tile shows its area by
@@ -418,6 +435,13 @@ interface VantageViewerOptions {
418
435
  * or pasted into the address bar — is applied to the camera. Default `false`
419
436
  * (the React `<VantageViewer>` turns it on). */
420
437
  urlState?: boolean;
438
+ /** Render only when something changed (camera, streaming tiles, settings) —
439
+ * plus a steady ~10 fps tick while animated textures (water, lava) are
440
+ * loaded, matching their baked 2-tick frametime. An idle view costs ~0
441
+ * GPU/CPU instead of a full render loop; input still renders the same
442
+ * frame it arrives. Default `true`; set `false` to render every frame
443
+ * (e.g. when driving external per-frame effects off the viewer's scene). */
444
+ renderOnDemand?: boolean;
421
445
  }
422
446
  /** A tile source: a URL to fetch, a raw buffer, or already-decoded data. */
423
447
  type TileSource = string | ArrayBuffer | DecodedTile;
@@ -460,6 +484,10 @@ interface ViewerEvents extends Record<string, unknown> {
460
484
  mode: {
461
485
  fly: boolean;
462
486
  };
487
+ /** The depth slice (cave view) moved or toggled. `null` = off. */
488
+ slice: {
489
+ y: number | null;
490
+ };
463
491
  }
464
492
  declare class VantageViewer {
465
493
  readonly renderer: THREE.WebGLRenderer;
@@ -492,6 +520,13 @@ declare class VantageViewer {
492
520
  private highlight;
493
521
  private mixTarget;
494
522
  private mixCurrent;
523
+ private sliceTarget;
524
+ private sliceCurrent;
525
+ private sliceActive;
526
+ /** The last depth used, so re-opening the cave view returns there. */
527
+ private lastSliceY;
528
+ /** The dark "unexplored rock" floor under a sliced world. */
529
+ private slicePlane;
495
530
  private light;
496
531
  private display;
497
532
  private readonly raycaster;
@@ -501,6 +536,9 @@ declare class VantageViewer {
501
536
  private dragging;
502
537
  private lastHover;
503
538
  private lastFrameMs;
539
+ private needsRender;
540
+ private hasAnims;
541
+ private lastRenderMs;
504
542
  private framedState;
505
543
  private hashTimer;
506
544
  private lastWrittenHash;
@@ -567,13 +605,49 @@ declare class VantageViewer {
567
605
  * immediately, no re-bake). */
568
606
  setLight(settings: LightSettings): void;
569
607
  private applyLight;
608
+ /** Whether the loaded world was baked with full cave geometry
609
+ * (`vantage render --caves full`) — i.e. the depth slice has real caves to
610
+ * reveal. The slice API works regardless; this is the "show the UI?" bit. */
611
+ get hasCaves(): boolean;
612
+ /** The world-Y bounds for the depth slice, from the manifest's baked extent
613
+ * (falling back to the loaded bounds / vanilla build limits). */
614
+ get sliceRange(): {
615
+ min: number;
616
+ max: number;
617
+ };
618
+ /** The current depth-slice Y, or `null` when the cave view is off. */
619
+ get slice(): number | null;
620
+ /** Slice the world at world-Y `y` (everything above is cut away, exposing
621
+ * the caves below — the cave / X-ray view); `null` turns it off. The plane
622
+ * eases to its target, so toggling peels the world open. Emits `'slice'`. */
623
+ setSlice(y: number | null): void;
624
+ /** Toggle the cave view: off → the last used depth (or a sensible cave
625
+ * depth on first open), on → off. */
626
+ toggleSlice(): void;
627
+ /** Push slice state to the shader + scene: clip uniform, ambient floor, and
628
+ * the void floor's presence. Also called on (re)load to seed a fresh shader. */
629
+ private applySlice;
630
+ /** The "unexplored rock" floor under a sliced world: a huge dark plane at
631
+ * the world's bottom, so solid ground reads as solid where no cave is
632
+ * exposed (instead of sky bleeding through the planet). Carries a faint
633
+ * 16-block chunk grid for scale and shares the terrain's fog uniforms so
634
+ * its distance haze matches. Follows the camera focus each frame. */
635
+ private buildSlicePlane;
636
+ /** Install the terrain-follow height source, wrapped so the controls' pivot
637
+ * never rides the (now invisible) surface above an open depth slice —
638
+ * zooming in descends to the exposed cave level instead of stopping at the
639
+ * clipped-away hilltops. */
640
+ private setHeightSampler;
570
641
  /** The current live display fidelity (sharpness, colour grade, fog, scale). */
571
642
  get displaySettings(): Required<DisplaySettings>;
572
643
  /** Update the live display fidelity (merges with current; immediate, no
573
644
  * re-bake). `renderScale` resizes the framebuffer; the rest are shader uniforms. */
574
645
  setDisplay(settings: DisplaySettings): void;
575
646
  /** devicePixelRatio × renderScale, capped by maxPixelRatio (and a hard 4 so a
576
- * fat-fingered scale can't allocate a giant framebuffer). */
647
+ * fat-fingered scale can't allocate a giant framebuffer). Floored at 0.25:
648
+ * a hidden/headless window can report devicePixelRatio 0, which would
649
+ * otherwise zero the framebuffer and break screenshot() and the first
650
+ * visible frame. */
577
651
  private targetPixelRatio;
578
652
  private applyDisplay;
579
653
  /** The current streaming settings (view distance, tile budget, concurrency). */
@@ -583,15 +657,19 @@ declare class VantageViewer {
583
657
  * range follow) and persists for future loads. The fidelity dial: raise
584
658
  * viewDistance/maxTiles to see farther, lower them on weak hardware. */
585
659
  setStreaming(settings: StreamingSettings): void;
586
- /** The current view serialized as a `#@x,y,z,dist,rot,tilt` hash fragment —
587
- * paste-able into any URL serving the same world. */
660
+ /** The current view serialized as a `#@x,y,z,dist,rot,tilt[,sliceY]` hash
661
+ * fragment — paste-able into any URL serving the same world. The trailing
662
+ * component appears only while the cave view is open, so those deep links
663
+ * reopen sliced at the same depth. */
588
664
  getViewHash(): string;
589
- /** Apply a `#@x,y,z,dist,rot,tilt` hash to the camera (leading `#` optional).
590
- * Returns whether the hash parsed. */
665
+ /** Apply a `#@x,y,z,dist,rot,tilt[,sliceY]` hash to the camera (leading `#`
666
+ * optional). Returns whether the hash parsed. */
591
667
  applyViewHash(hash: string): boolean;
592
668
  /** Debounced camera→hash sync plus hashchange→camera (pasted links apply
593
669
  * live). `history.replaceState` avoids history spam and hashchange echo. */
594
670
  private bindUrlState;
671
+ /** Debounce a hash write — camera motion and slice changes funnel here. */
672
+ private queueHashWrite;
595
673
  private writeHash;
596
674
  /** Smoothly zoom by `steps` wheel-notches (positive = in). Drives the same
597
675
  * inertial zoom as the wheel, so on-screen buttons feel identical. */
@@ -621,7 +699,19 @@ declare class VantageViewer {
621
699
  private bindInput;
622
700
  private emitHover;
623
701
  private pickHover;
702
+ /** Request a redraw on the next animation frame. The viewer invalidates
703
+ * itself for everything it owns (camera motion, tile streaming, settings,
704
+ * the biome layer); call this only if you mutate the scene from outside. */
705
+ invalidate(): void;
706
+ /** Idle animation cadence (ms). Water/lava bake at a 2-tick frametime
707
+ * (100 ms), so a 10 fps tick steps them at exactly their authored rate. */
708
+ private static readonly ANIM_TICK_MS;
624
709
  private frame;
710
+ private draw;
711
+ /** Draw a fresh frame and return the canvas as a PNG data URL, for a
712
+ * screenshot button / download link. Draws synchronously first because the
713
+ * default framebuffer is not preserved between the on-demand renders. */
714
+ screenshot(): string;
625
715
  private resize;
626
716
  private disposeCurrent;
627
717
  /** Tear down the renderer, controls, observers, and remove the canvas. */
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.4.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",
@@ -49,6 +49,7 @@
49
49
  "dev": "vite",
50
50
  "build": "tsup",
51
51
  "build:demo": "vite build",
52
+ "build:viewer": "vite build -c vite.viewer.config.ts",
52
53
  "preview": "vite preview",
53
54
  "typecheck": "tsc --noEmit",
54
55
  "test": "vitest run",