Weltkarte: schematische 5-Layer-Optik

Layer 1: Flachfarben aus Splatmap (Coarse 512px filtert dünne Texturen <4m heraus, kein Hillshading)
Layer 2: Wasser-Füllung (PNG) + Küstenlinie (Canvas-Vektor), eine Checkbox
Layer 3: Wald – 50% alpha grün + dunkelgrüne Randlinie (vorgebacken)
Layer 4: Klippen – graue Füllung + Kammlinie + Fußlinie (vorgebacken, buildCliffOverlay)
Layer 5: Areas – gestrichelte Vektorpolygone (Canvas)

Entfernt: Wellenmarken, Wasserfall-Symbole, Zonen, Modell-Punkte, Orte-Labels, Baum-Symbole

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-03 16:32:18 +02:00
parent e8896c7a4d
commit ddec931ee8
2 changed files with 198 additions and 455 deletions

View File

@@ -38,9 +38,6 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import javafx.geometry.VPos;
import javafx.scene.text.TextAlignment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -75,7 +72,6 @@ public class WorldMapView extends VBox {
private static final double WAVE_W = 20.0; // konstante Wellengröße in Bildschirmpixeln
private static final int SEA_MASK_SIZE = 1024;
private static final Font AREA_FONT = Font.font("SansSerif", FontWeight.BOLD, 11);
private static final Font LOC_FONT = Font.font("SansSerif", FontWeight.BOLD, 12);
private final Canvas canvas = new Canvas(100, 100);
private final Label statusLbl = new Label("Karte noch nicht geladen");
@@ -83,14 +79,11 @@ public class WorldMapView extends VBox {
private final StackPane canvasPane = new StackPane(canvas);
// Layer-Checkboxen (im MenuButton gebündelt)
private final CheckBox cbTerrain = layerCheck("Gelände");
private final CheckBox cbWater = layerCheck("Wasser");
private final CheckBox cbCoastline = layerCheck("Küstenlinie");
private final CheckBox cbWaterfalls = layerCheck("Wasserfälle");
private final CheckBox cbTerrain = layerCheck("Basis");
private final CheckBox cbWater = layerCheck("Wasser/Küste");
private final CheckBox cbForest = layerCheck("Wald");
private final CheckBox cbCliffs = layerCheck("Klippen");
private final CheckBox cbAreas = layerCheck("Areas");
private final CheckBox cbZones = layerCheck("Zonen");
private final CheckBox cbLocations = layerCheck("Orte");
private final CheckBox cbModels = layerCheck("Modelle");
private final ToggleButton labelBtn = new ToggleButton("Label");
private final Button fullscreenBtn = new Button(">>");
@@ -103,11 +96,7 @@ public class WorldMapView extends VBox {
private WritableImage mapFxImage;
private BufferedImage mapBuffered;
// Canvas-level Tile-Overlay: zoom-unabhängige Kacheldarstellung
private static final int CAT_SIZE = 2048;
private byte[] categoryMap = null;
private float[] heightMap = null; // terrain+voxel, CAT_SIZE×CAT_SIZE (für Klippen)
private float[] heightMapTerrain = null; // terrain-only, CAT_SIZE×CAT_SIZE (für Wasser-Füllung)
private WritableImage bakedCliffOverlay = null;
private static final int ZOOM_LEVELS = 5;
private static final double ZOOM_MAX_SCALE = 4.0; // 1 Canvas-Pixel = 0,25 WU = 0,25m
private static final int ZOOM_HIRES_CUTOFF = 3; // ab diesem Index Chunk-Rendering
@@ -130,9 +119,6 @@ public class WorldMapView extends VBox {
private volatile boolean chunkRedrawPending = false;
private WritableImage bakedForestOverlay = null;
// Wasser-Fill-Overlay entfernt: ocean + PlacedWater sind bereits in mapFxImage korrekt gerendert
// PlacedWater-Wasserhoehe pro Zelle (0 = kein PlacedWater); fuer glatte Uebergaenge
private float[] waterHeightMap = null;
private List<PlacedArea> cachedAreas = new ArrayList<>();
private List<Location> cachedLocs = new ArrayList<>();
@@ -205,15 +191,12 @@ public class WorldMapView extends VBox {
// ── Layer-Auswahl als MenuButton mit Checkboxen ───────────────────────
cbTerrain.selectedProperty().addListener((obs, o, n) -> rerenderFromModel());
cbWater.selectedProperty().addListener((obs, o, n) -> rerenderFromModel());
cbWaterfalls.selectedProperty().addListener((obs, o, n) -> rerenderFromModel());
cbZones.selectedProperty().addListener((obs, o, n) -> rerenderFromModel());
cbModels.selectedProperty().addListener((obs, o, n) -> redraw());
cbForest.selectedProperty().addListener((obs, o, n) -> redraw());
cbCliffs.selectedProperty().addListener((obs, o, n) -> redraw());
cbAreas.selectedProperty().addListener((obs, o, n) -> redraw());
cbLocations.selectedProperty().addListener((obs, o, n) -> redraw());
cbCoastline.selectedProperty().addListener((obs, o, n) -> redraw());
MenuButton layerMenu = new MenuButton("Layer ▾");
for (CheckBox cb : new CheckBox[]{cbTerrain, cbWater, cbCoastline, cbWaterfalls, cbAreas, cbZones, cbLocations, cbModels}) {
for (CheckBox cb : new CheckBox[]{cbTerrain, cbWater, cbForest, cbCliffs, cbAreas}) {
CustomMenuItem item = new CustomMenuItem(cb, false);
item.setHideOnClick(false);
layerMenu.getItems().add(item);
@@ -369,18 +352,12 @@ public class WorldMapView extends VBox {
Platform.runLater(() -> statusLbl.setText("Rendere Karte…"));
long t1 = System.currentTimeMillis();
BufferedImage bi = WorldMapRenderer.render(model, RENDER_SIZE, buildBackgroundOptions());
float[] hMap = WorldMapRenderer.buildTerrainSamples(
model.mapData(), CAT_SIZE, model.voxelSurface());
float[] hMapT = WorldMapRenderer.buildTerrainSamples(
model.mapData(), CAT_SIZE, null);
byte[] catMap = WorldMapRenderer.buildCategoryMap(
model.mapData(), CAT_SIZE, model.voxelSurface(), model.waters(), model.slotColorsRGB());
float[] whMap = WorldMapRenderer.buildWaterHeightMap(model.waters(), CAT_SIZE);
log.debug("[WorldMap] Hintergrund-PNG + Kategorie-Karte gerendert ({}×{} px, {} ms)",
log.debug("[WorldMap] Hintergrund-PNG gerendert ({}×{} px, {} ms)",
RENDER_SIZE, RENDER_SIZE, System.currentTimeMillis() - t1);
float[] fDensity = computeForestDensity(model);
int[] bakedFstPx = computeForestPixels(model, fDensity, 2.0f);
int[] cliffPx = WorldMapRenderer.buildCliffOverlay(model.mapData(), model.voxelSurface());
// Hires-Chunks im Hintergrund generieren (nach dem UI-Update, nicht-blockierend)
final WorldMapRenderModel chunkModel = model;
@@ -397,16 +374,12 @@ public class WorldMapView extends VBox {
cachedLocs = new ArrayList<>(model.locations());
mapBuffered = bi;
mapFxImage = SwingFXUtils.toFXImage(bi, null);
heightMap = hMap;
heightMapTerrain = hMapT;
categoryMap = catMap;
waterHeightMap = whMap;
bakedForestOverlay = toWritableImage(bakedFstPx, RENDER_SIZE);
bakedCliffOverlay = toWritableImage(cliffPx, WorldMapRenderer.COLOR_MAP_SIZE);
fitToView();
redraw();
progress.setVisible(false);
statusLbl.setText("Bereit – " + model.areas().size() + " Areas, " +
model.locations().size() + " Orte, " + model.waters().size() + " Wasser");
statusLbl.setText("Bereit – " + model.areas().size() + " Areas, " + model.waters().size() + " Wasser");
loading.set(false);
log.debug("[WorldMap] Gesamt-Ladezeit: {} ms", System.currentTimeMillis() - t0);
});
@@ -436,8 +409,7 @@ public class WorldMapView extends VBox {
Thread t = new Thread(() -> {
log.debug("[WorldMap] PNG-Rerender aus gecachtem Modell gestartet ({}×{})", RENDER_SIZE, RENDER_SIZE);
long t0 = System.currentTimeMillis();
// Nur das PNG neu rendern — heightMap/catMap/waterHeightMap kommen aus Stage 1
// und sind bereits in den Instanz-Feldern vorhanden
// Nur das PNG neu rendern — Overlays (Forest, Cliff) bleiben aus dem letzten Modell-Build
BufferedImage bi = WorldMapRenderer.render(model, RENDER_SIZE, buildBackgroundOptions());
log.debug("[WorldMap] PNG-Rerender fertig ({} ms)", System.currentTimeMillis() - t0);
Platform.runLater(() -> {
@@ -478,13 +450,15 @@ public class WorldMapView extends VBox {
} else {
gc.drawImage(mapFxImage, panX, panY, mapFxImage.getWidth() * scale, mapFxImage.getHeight() * scale);
}
// Layer 1: Wasser (glatte Küste via seaCoastPaths)
if (cbWater.isSelected()) drawWaterOverlay(gc);
// Layer 2: Wald-Overlay (nach Wasser, damit Bäume nicht im Wasser erscheinen)
drawForestOverlay(gc);
if (cbAreas.isSelected()) drawAreasOverlay(gc);
if (cbLocations.isSelected()) drawLocationsOverlay(gc);
if (!isFullscreen) drawCameraIndicator(gc);
// Layer 2: Küstenlinie (Vektor)
if (cbWater.isSelected()) drawWaterOverlay(gc);
// Layer 3: Wald (Füllung + Rand)
if (cbForest.isSelected()) drawForestOverlay(gc);
// Layer 4: Klippen (Grau-Füllung + Kantenlinien)
if (cbCliffs.isSelected()) drawCliffOverlay(gc);
// Layer 5: Areas (Vektoren)
if (cbAreas.isSelected()) drawAreasOverlay(gc);
if (!isFullscreen) drawCameraIndicator(gc);
}
private void drawHiresChunks(GraphicsContext gc) {
@@ -583,6 +557,12 @@ public class WorldMapView extends VBox {
gc.drawImage(bakedForestOverlay, -panX / scale, -panY / scale, cW / scale, cH / scale, 0, 0, cW, cH);
}
private void drawCliffOverlay(GraphicsContext gc) {
if (bakedCliffOverlay == null) return;
int cW = (int) canvas.getWidth(), cH = (int) canvas.getHeight();
gc.drawImage(bakedCliffOverlay, -panX / scale, -panY / scale, cW / scale, cH / scale, 0, 0, cW, cH);
}
// ── Wald-Baking (läuft im Background-Thread) ─────────────────────────────
private static float[] computeForestDensity(WorldMapRenderModel model) {
@@ -610,13 +590,10 @@ public class WorldMapView extends VBox {
private static int[] computeForestPixels(WorldMapRenderModel model, float[] density, float threshold) {
final int SIZE = RENDER_SIZE, FD = 512;
final float WH = WorldMapRenderer.WORLD_HALF, WS = WorldMapRenderer.WORLD_SIZE;
final int[][] tilePx = model.mapTilePixels();
final int forestArgb = (tilePx != null && WorldMapRenderer.TILE_FOREST < tilePx.length
&& tilePx[WorldMapRenderer.TILE_FOREST] != null)
? tileSample(tilePx, WorldMapRenderer.TILE_FOREST, 0, 0, 0, 0, 1f, 0f, 0f, 0f)
: 0x3D7A28;
final int forestColor = 0x80000000 | (forestArgb & 0x00FFFFFF);
final int forestFill = 0x80_4a9a28; // 50% alpha grün
final int forestOutline = 0xCC_2d6316; // 80% alpha dunkelgrün
final int[] px = new int[SIZE * SIZE];
boolean[] isFill = new boolean[SIZE * SIZE];
for (int py = 0; py < SIZE; py++) {
float wz = (float) py / (SIZE - 1) * WS - WH;
for (int bx = 0; bx < SIZE; bx++) {
@@ -628,7 +605,22 @@ public class WorldMapView extends VBox {
float fstx=fsfx-fsx0, fstz=fsfz-fsz0;
float fd=(density[fsz0*FD+fsx0]*(1-fstx)+density[fsz0*FD+fsx1]*fstx)*(1-fstz)
+(density[fsz1*FD+fsx0]*(1-fstx)+density[fsz1*FD+fsx1]*fstx)*fstz;
px[py*SIZE+bx] = (fd > threshold) ? forestColor : 0x00000000;
if (fd > threshold) {
px[py * SIZE + bx] = forestFill;
isFill[py * SIZE + bx] = true;
}
}
}
// Randlinie: Füll-Pixel mit mindestens einem Nicht-Füll-Nachbarn
for (int py = 1; py < SIZE - 1; py++) {
for (int bx = 1; bx < SIZE - 1; bx++) {
int idx = py * SIZE + bx;
if (!isFill[idx]) { continue; }
boolean edge = !isFill[idx - 1] || !isFill[idx + 1]
|| !isFill[idx - SIZE] || !isFill[idx + SIZE]
|| !isFill[idx - SIZE - 1] || !isFill[idx - SIZE + 1]
|| !isFill[idx + SIZE - 1] || !isFill[idx + SIZE + 1];
if (edge) { px[idx] = forestOutline; }
}
}
return px;
@@ -698,42 +690,22 @@ public class WorldMapView extends VBox {
gc.restore();
}
private void drawLocationsOverlay(GraphicsContext gc) {
if (cachedLocs.isEmpty()) return;
gc.save();
gc.setFont(LOC_FONT);
for (Location loc : cachedLocs) {
if (!loc.isShowOnMap()) continue;
if (loc.getId() == null || loc.getId().isEmpty()) continue;
double lx = toCanvasX(Float.isNaN(loc.getLabelX()) ? loc.getCenterX() : loc.getLabelX());
double lz = toCanvasZ(Float.isNaN(loc.getLabelZ()) ? loc.getCenterZ() : loc.getLabelZ());
drawCanvasLabel(gc, locLabel(loc.getId()), lx, lz);
}
gc.restore();
}
private void drawWaterOverlay(GraphicsContext gc) {
if (currentModel == null) return;
// Wasser-Füllung kommt aus mapFxImage (bereits korrekt gerendert).
// Hier nur noch Küstenlinie und Wellen-Vektoren.
// ── Küstenlinie ───────────────────────────────────────────────────────────
List<float[][]> seaCoastPaths = currentModel.coastPaths();
if (cbCoastline.isSelected() && seaCoastPaths != null && !seaCoastPaths.isEmpty()) {
double canvasW = canvas.getWidth(), canvasH = canvas.getHeight();
gc.setLineDashes(null);
gc.setLineCap(StrokeLineCap.ROUND);
gc.setLineJoin(StrokeLineJoin.ROUND);
if (seaCoastPaths == null || seaCoastPaths.isEmpty()) { return; }
double canvasW = canvas.getWidth(), canvasH = canvas.getHeight();
gc.setLineDashes(null);
gc.setLineCap(StrokeLineCap.ROUND);
gc.setLineJoin(StrokeLineJoin.ROUND);
gc.setStroke(Color.color(0, 0, 0, 0.22));
gc.setLineWidth(7.0);
for (float[][] path : seaCoastPaths) { drawCoastPath(gc, path, canvasW, canvasH, 8); }
gc.setStroke(Color.color(0, 0, 0, 0.22));
gc.setLineWidth(7.0);
for (float[][] path : seaCoastPaths) { drawCoastPath(gc, path, canvasW, canvasH, 8); }
gc.setStroke(Color.BLACK);
gc.setLineWidth(3.0);
for (float[][] path : seaCoastPaths) { drawCoastPath(gc, path, canvasW, canvasH, 4); }
}
gc.setStroke(Color.BLACK);
gc.setLineWidth(3.0);
for (float[][] path : seaCoastPaths) { drawCoastPath(gc, path, canvasW, canvasH, 4); }
}
private void drawCanvasLabel(GraphicsContext gc, String text, double x, double y) {
@@ -770,19 +742,6 @@ public class WorldMapView extends VBox {
float wx = toWorldX(canvasX);
float wz = toWorldZ(canvasY);
// Locations: Treffer innerhalb 2× Radius
for (Location loc : cachedLocs) {
float dx = wx - loc.getCenterX(), dz = wz - loc.getCenterZ(), r = loc.getRadius();
if (dx * dx + dz * dz <= r * r * 4) {
loc.setLabelX(wx);
loc.setLabelZ(wz);
try { LocationIO.save(cachedLocs); } catch (IOException e) { statusLbl.setText("Fehler: " + e.getMessage()); return; }
redraw();
statusLbl.setText(String.format("Label %s → (%.0f, %.0f)", loc.getId(), wx, wz));
return;
}
}
// Areas: kleinste enthaltende Area
PlacedArea best = null;
int bestIdx = -1;
@@ -803,48 +762,6 @@ public class WorldMapView extends VBox {
}
}
// Zoom-Schwelle: darüber Einzelbaum-Symbole, darunter Wald-Cluster-Symbol
private static final double TREE_INDIVIDUAL_SCALE = 3.0;
// Farbe der Baum-/Waldsymbole
private static final Color TREE_COLOR = Color.rgb(25, 90, 25);
private void drawTreeOverlay(GraphicsContext gc) {
if (currentModel == null) { return; }
List<List<PlacedModel>> treeClusters = currentModel.treeClusters();
if (treeClusters == null || treeClusters.isEmpty()) { return; }
double cW = canvas.getWidth(), cH = canvas.getHeight();
gc.save();
gc.setFill(TREE_COLOR);
gc.setTextAlign(TextAlignment.CENTER);
gc.setTextBaseline(VPos.CENTER);
if (scale >= TREE_INDIVIDUAL_SCALE) {
// Einzelne Bäume – ein Symbol pro Baum
gc.setFont(Font.font("SansSerif", 11));
for (List<PlacedModel> cluster : treeClusters) {
for (PlacedModel t : cluster) {
double cx = toCanvasX(t.x()), cz = toCanvasZ(t.z());
if (cx < -15 || cx > cW + 15 || cz < -15 || cz > cH + 15) { continue; }
gc.fillText("♣", cx, cz);
}
}
} else {
// Wald-Modus – ein Symbol pro Cluster (am Schwerpunkt)
gc.setFont(Font.font("SansSerif", FontWeight.BOLD, 14));
for (List<PlacedModel> cluster : treeClusters) {
double sumX = 0, sumZ = 0;
for (PlacedModel t : cluster) { sumX += t.x(); sumZ += t.z(); }
double cx = toCanvasX((float)(sumX / cluster.size()));
double cz = toCanvasZ((float)(sumZ / cluster.size()));
if (cx < -20 || cx > cW + 20 || cz < -20 || cz > cH + 20) { continue; }
gc.fillText("♣", cx, cz);
}
}
gc.restore();
}
private static List<List<PlacedModel>> clusterTreeModels(List<PlacedModel> trees, float radius) {
int n = trees.size();
int[] parent = new int[n];
@@ -1201,11 +1118,6 @@ public class WorldMapView extends VBox {
return s.isBlank() ? null : s;
}
private static String locLabel(String id) {
String s = id.replace("location.", "").replace(".name", "");
return s.isEmpty() ? id : s;
}
private void exportPng() {
FileChooser fc = new FileChooser();
fc.setTitle("Karte als PNG exportieren");
@@ -1245,34 +1157,14 @@ public class WorldMapView extends VBox {
t.start();
}
/** Hintergrund-PNG: ohne Areas und Locations (die werden live auf Canvas gezeichnet). */
private RenderOptions buildBackgroundOptions() {
return new RenderOptions(
cbTerrain.isSelected(),
cbTerrain.isSelected(),
cbWater.isSelected(),
false, // Wellen im Editor über Canvas gezeichnet
false,
cbZones.isSelected(),
false,
cbModels.isSelected(),
cbWaterfalls.isSelected()
);
return new RenderOptions(cbTerrain.isSelected(), cbTerrain.isSelected(),
cbWater.isSelected(), false, false, false, false, false, false);
}
/** Export-PNG: alle Layer gebacken. */
private RenderOptions buildExportOptions() {
return new RenderOptions(
cbTerrain.isSelected(),
cbTerrain.isSelected(),
cbWater.isSelected(),
false,
cbAreas.isSelected(),
cbZones.isSelected(),
cbLocations.isSelected(),
cbModels.isSelected(),
cbWaterfalls.isSelected()
);
return new RenderOptions(cbTerrain.isSelected(), cbTerrain.isSelected(),
cbWater.isSelected(), false, cbAreas.isSelected(), false, false, false, false);
}
private static CheckBox layerCheck(String label) {