From 67063b02d741e32d8a4af859bb93a4ea8012b7e6 Mon Sep 17 00:00:00 2001 From: piexel Date: Thu, 12 Nov 2026 01:11:31 +0100 Subject: [PATCH] Fix the studio's 3D terrain: blank views, grey blocks, pale colours The 3D views looked for tiles across the world's whole build height. In a pack with a tall sky most of a tile's box is air, so once the camera came close to the ground the planner drew sixteen far tiles and none under the camera. Tiles are now looked for between the lowest and highest ground drawn so far, and ranked by how far they lie from the ground in the middle of the view instead of by their centre point. Saved tiles named blocks without their properties, which matched no model variant, so grass and every plugin block drew as flat grey. Saved and generated tiles now carry the state players see, which for a plugin block is the vanilla state it borrows. Colours went through three.js colour management as if they were linear light and came out pale with flat shading. They are drawn as given now, as v3e does. Gaps in cut-out textures such as leaves take the texture's own colour instead of black. Also in the studio: - Right click or Ctrl+click on 3D terrain teleports there, as on the map. - The land, sea and cave biome layer views are gone. - New icons for the views and the map tools that shared one or said something else. - A saved world with nothing finished says so instead of reading forever. --- .../core/studio/bridge/MapTileEncoding.java | 19 ++- .../core/studio/bridge/SavedTileEncoding.java | 7 +- .../iris/core/studio/bridge/StudioBridge.java | 5 +- .../arcane/iris/core/studio/map/MapLayer.java | 5 - .../core/studio/map/MapPickInspection.java | 2 - .../iris/core/studio/map/MapPickPath.java | 8 +- .../iris/core/studio/map/MapTileRenderer.java | 11 +- .../arcane/iris/core/studio/map/MapView.java | 23 +--- .../iris/core/studio/saved/SavedBlock.java | 28 ++++ .../iris/core/studio/saved/SavedChunk.java | 34 ++++- .../iris/core/studio/saved/SavedRegion.java | 14 +- .../iris/core/studio/saved/SavedTile.java | 8 +- .../core/studio/bridge/StudioBridgeTest.java | 5 - .../studio/map/MapPickInspectionTest.java | 5 - .../iris/core/studio/map/MapPickPathTest.java | 5 - .../core/studio/map/MapTileRendererTest.java | 11 -- .../core/studio/saved/SavedWorldTest.java | 12 +- .../renderer/src/bridge/savedTileDecoding.ts | 5 +- studio/src/renderer/src/bridge/types.ts | 5 +- .../src/renderer/src/components/IdeIcon.tsx | 11 +- studio/src/renderer/src/icons/NOTICE.txt | 3 +- studio/src/renderer/src/icons/actualZoom.svg | 5 + .../renderer/src/icons/actualZoom_dark.svg | 5 + studio/src/renderer/src/icons/borders.svg | 3 + .../src/renderer/src/icons/borders_dark.svg | 3 + studio/src/renderer/src/icons/decoration.svg | 5 + .../renderer/src/icons/decoration_dark.svg | 5 + studio/src/renderer/src/icons/mob.svg | 6 + studio/src/renderer/src/icons/mob_dark.svg | 6 + studio/src/renderer/src/icons/shading.svg | 7 +- .../src/renderer/src/icons/shading_dark.svg | 7 +- studio/src/renderer/src/icons/user.svg | 7 - studio/src/renderer/src/icons/user_dark.svg | 7 - .../src/renderer/src/icons/views/biomes.svg | 13 +- .../renderer/src/icons/views/biomes_dark.svg | 13 +- .../renderer/src/icons/views/cave-biomes.svg | 4 - .../src/icons/views/cave-biomes_dark.svg | 4 - .../renderer/src/icons/views/land-biomes.svg | 6 - .../src/icons/views/land-biomes_dark.svg | 6 - studio/src/renderer/src/icons/views/noise.svg | 4 +- .../renderer/src/icons/views/noise_dark.svg | 4 +- .../src/renderer/src/icons/views/objects.svg | 7 +- .../renderer/src/icons/views/objects_dark.svg | 7 +- .../src/renderer/src/icons/views/regions.svg | 7 +- .../renderer/src/icons/views/regions_dark.svg | 7 +- .../renderer/src/icons/views/sea-biomes.svg | 7 - .../src/icons/views/sea-biomes_dark.svg | 7 - .../src/renderer/src/icons/views/world-3d.svg | 4 +- .../src/icons/views/world-3d_dark.svg | 4 +- studio/src/renderer/src/icons/zoomIn.svg | 6 - studio/src/renderer/src/icons/zoomIn_dark.svg | 6 - studio/src/renderer/src/scene/cameraSight.ts | 29 ++-- studio/src/renderer/src/scene/columnField.ts | 6 + .../renderer/src/scene/savedTerrain.test.ts | 5 +- studio/src/renderer/src/scene/savedTerrain.ts | 6 +- .../src/renderer/src/scene/savedTileSource.ts | 2 +- studio/src/renderer/src/scene/terrainAtlas.ts | 28 +++- studio/src/renderer/src/scene/terrainCover.ts | 2 +- .../renderer/src/scene/terrainStream.test.ts | 18 ++- .../src/renderer/src/scene/terrainStream.ts | 26 +++- studio/src/renderer/src/scene/textureAtlas.ts | 3 +- studio/src/renderer/src/studio/HoverCard.tsx | 10 +- studio/src/renderer/src/studio/NodeCanvas.tsx | 2 +- .../renderer/src/studio/SavedWorldStudio.tsx | 5 +- .../src/renderer/src/studio/SceneViewport.tsx | 124 +++++++++++++++++- .../src/renderer/src/studio/StudioToolbar.tsx | 6 +- studio/src/renderer/src/studio/ViewList.tsx | 5 +- .../src/renderer/src/studio/WorldStudio3D.tsx | 4 +- .../src/renderer/src/studio/shortcuts.test.ts | 2 +- studio/src/renderer/src/studio/shortcuts.ts | 3 - .../renderer/src/studio/useSpotActions.tsx | 46 +++++++ .../renderer/src/studio/useTerrainStream.ts | 1 + 72 files changed, 466 insertions(+), 275 deletions(-) create mode 100644 core/src/main/java/art/arcane/iris/core/studio/saved/SavedBlock.java create mode 100644 studio/src/renderer/src/icons/actualZoom.svg create mode 100644 studio/src/renderer/src/icons/actualZoom_dark.svg create mode 100644 studio/src/renderer/src/icons/borders.svg create mode 100644 studio/src/renderer/src/icons/borders_dark.svg create mode 100644 studio/src/renderer/src/icons/decoration.svg create mode 100644 studio/src/renderer/src/icons/decoration_dark.svg create mode 100644 studio/src/renderer/src/icons/mob.svg create mode 100644 studio/src/renderer/src/icons/mob_dark.svg delete mode 100644 studio/src/renderer/src/icons/user.svg delete mode 100644 studio/src/renderer/src/icons/user_dark.svg delete mode 100644 studio/src/renderer/src/icons/views/cave-biomes.svg delete mode 100644 studio/src/renderer/src/icons/views/cave-biomes_dark.svg delete mode 100644 studio/src/renderer/src/icons/views/land-biomes.svg delete mode 100644 studio/src/renderer/src/icons/views/land-biomes_dark.svg delete mode 100644 studio/src/renderer/src/icons/views/sea-biomes.svg delete mode 100644 studio/src/renderer/src/icons/views/sea-biomes_dark.svg delete mode 100644 studio/src/renderer/src/icons/zoomIn.svg delete mode 100644 studio/src/renderer/src/icons/zoomIn_dark.svg create mode 100644 studio/src/renderer/src/studio/useSpotActions.tsx diff --git a/core/src/main/java/art/arcane/iris/core/studio/bridge/MapTileEncoding.java b/core/src/main/java/art/arcane/iris/core/studio/bridge/MapTileEncoding.java index 973ebdd7c..fc563d26d 100644 --- a/core/src/main/java/art/arcane/iris/core/studio/bridge/MapTileEncoding.java +++ b/core/src/main/java/art/arcane/iris/core/studio/bridge/MapTileEncoding.java @@ -18,6 +18,7 @@ package art.arcane.iris.core.studio.bridge; +import art.arcane.iris.core.link.CustomBlockLook; import art.arcane.iris.core.studio.map.MapLabel; import art.arcane.iris.core.studio.map.MapTile; import com.google.gson.Gson; @@ -26,6 +27,8 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; import java.util.List; +import java.util.Optional; +import java.util.function.Function; /** * A {@link MapTile} as the studio reads it, little endian: @@ -36,7 +39,7 @@ import java.util.List; * i16 ground[grid²] | padding to 4 | i16 cover[grid²], when the header names blocks * * The header holds the size, the scale, the subject kind, the labels the grids index, and the blocks the ground and - * cover grids index when the tile carries the tops of its columns. Every array starts on a + * cover grids index when the tile carries the tops of its columns, each as the state players see. Every array starts on a * multiple of 4 bytes, so the studio views them in place. */ final class MapTileEncoding { @@ -45,12 +48,16 @@ final class MapTileEncoding { private MapTileEncoding() { } - static byte[] encode(MapTile tile, Gson gson) { + /** + * @param pluginLooks the plugin block a server state is with the vanilla state players see in its place; empty for + * every state that is no plugin's block + */ + static byte[] encode(MapTile tile, Gson gson, Function> pluginLooks) { boolean hasHeights = tile.heights() != null; boolean hasPickNoise = tile.pickNoise() != null; MapTile.Blocks blocks = tile.blocks(); byte[] header = gson.toJson(new Header(tile.size(), tile.blocksPerPixel(), tile.subjectKind(), tile.labels(), - hasHeights, hasPickNoise, blocks == null ? null : blocks.names())) + hasHeights, hasPickNoise, blocks == null ? null : statesPlayersSee(blocks.names(), pluginLooks))) .getBytes(StandardCharsets.UTF_8); int cells = tile.gridSize() * tile.gridSize(); int length = aligned(Integer.BYTES + header.length) @@ -91,6 +98,12 @@ final class MapTileEncoding { buffer.position(aligned(buffer.position())); } + private static List statesPlayersSee(List serverStates, Function> pluginLooks) { + return serverStates.stream() + .map(state -> pluginLooks.apply(state).map(CustomBlockLook::shownAs).orElse(state)) + .toList(); + } + private record Header(int size, double blocksPerPixel, MapLabel.Kind subjectKind, List labels, boolean heights, boolean pickNoise, List blocks) { } diff --git a/core/src/main/java/art/arcane/iris/core/studio/bridge/SavedTileEncoding.java b/core/src/main/java/art/arcane/iris/core/studio/bridge/SavedTileEncoding.java index d08bcef6f..aaa7ac334 100644 --- a/core/src/main/java/art/arcane/iris/core/studio/bridge/SavedTileEncoding.java +++ b/core/src/main/java/art/arcane/iris/core/studio/bridge/SavedTileEncoding.java @@ -19,6 +19,7 @@ package art.arcane.iris.core.studio.bridge; import art.arcane.iris.core.studio.map.MapLabel; +import art.arcane.iris.core.studio.saved.SavedBlock; import art.arcane.iris.core.studio.saved.SavedTile; import com.google.gson.Gson; @@ -34,7 +35,7 @@ import java.util.List; * i16 groundY[size²] | padding to 4 | i16 waterSurfaceY[size²] | padding to 4 * i16 blocks[size²] | padding to 4 | i16 biomes[size²] * - * The header holds the size, the scale, the block names and the biome labels the grids index, and the values that mean + * The header holds the size, the scale, the blocks and the biome labels the grids index, and the values that mean * no ground and no water. */ final class SavedTileEncoding { @@ -44,7 +45,7 @@ final class SavedTileEncoding { } static byte[] encode(SavedTile tile, List biomes, Gson gson) { - byte[] header = gson.toJson(new Header(tile.size(), tile.blocksPerPixel(), tile.blockNames(), biomes, + byte[] header = gson.toJson(new Header(tile.size(), tile.blocksPerPixel(), tile.savedBlocks(), biomes, SavedTile.NO_GROUND, SavedTile.NO_WATER)).getBytes(StandardCharsets.UTF_8); List grids = List.of(tile.groundY(), tile.waterSurfaceY(), tile.blocks(), tile.biomes()); int gridBytes = aligned(tile.size() * tile.size() * Short.BYTES); @@ -63,6 +64,6 @@ final class SavedTileEncoding { return (bytes + ALIGNMENT_BYTES - 1) / ALIGNMENT_BYTES * ALIGNMENT_BYTES; } - private record Header(int size, int blocksPerPixel, List blocks, List biomes, int noGround, int noWater) { + private record Header(int size, int blocksPerPixel, List blocks, List biomes, int noGround, int noWater) { } } diff --git a/core/src/main/java/art/arcane/iris/core/studio/bridge/StudioBridge.java b/core/src/main/java/art/arcane/iris/core/studio/bridge/StudioBridge.java index 8105d8f26..e805134e9 100644 --- a/core/src/main/java/art/arcane/iris/core/studio/bridge/StudioBridge.java +++ b/core/src/main/java/art/arcane/iris/core/studio/bridge/StudioBridge.java @@ -335,9 +335,6 @@ public final class StudioBridge implements AutoCloseable { private static MapPickInspection.Inspection picks(Engine engine, Query query) { MapLayer layer = layer(engine, query); - if (!layer.hasPickNoise()) { - throw new RequestError(STATUS_BAD_REQUEST, "The " + layer.view().label() + " view has no picks to inspect"); - } try { MapPickInspection.Area area = new MapPickInspection.Area( query.number("minX"), query.number("minZ"), query.number("maxX"), query.number("maxZ")); @@ -609,7 +606,7 @@ public final class StudioBridge implements AutoCloseable { if (query.has("blocks")) { tile = withBlocks(session, tile, startX, startZ, blockSource(query), cancelled); } - return MapTileEncoding.encode(tile, gson); + return MapTileEncoding.encode(tile, gson, StudioBridge::pluginLookOf); } private static MapTile withBlocks(StudioWorld.Session session, MapTile tile, double startX, double startZ, BlockSource source, diff --git a/core/src/main/java/art/arcane/iris/core/studio/map/MapLayer.java b/core/src/main/java/art/arcane/iris/core/studio/map/MapLayer.java index 137610b8d..45aa95957 100644 --- a/core/src/main/java/art/arcane/iris/core/studio/map/MapLayer.java +++ b/core/src/main/java/art/arcane/iris/core/studio/map/MapLayer.java @@ -49,11 +49,6 @@ public record MapLayer(MapView view, IrisRegion previewRegion) { return previewRegion != null; } - /** Whether the layer can show the noise that picked each spot: the region view, its previews and the biome view. */ - public boolean hasPickNoise() { - return view == MapView.BIOMES || view == MapView.REGIONS; - } - /** Whether each spot is labelled with its region rather than a biome; a preview labels the biomes. */ boolean labelsRegions() { return view.labelsRegions() && !previews(); diff --git a/core/src/main/java/art/arcane/iris/core/studio/map/MapPickInspection.java b/core/src/main/java/art/arcane/iris/core/studio/map/MapPickInspection.java index 102702a52..42197ce91 100644 --- a/core/src/main/java/art/arcane/iris/core/studio/map/MapPickInspection.java +++ b/core/src/main/java/art/arcane/iris/core/studio/map/MapPickInspection.java @@ -46,7 +46,6 @@ public final class MapPickInspection { private MapPickInspection() { } - /** @throws IllegalArgumentException for a view whose spots no noise picks, such as a biome layer's */ public static Inspection measure(Engine engine, MapLayer layer, Area area) { if (layer.previews()) { return measurePreview(engine, layer.previewRegion(), area); @@ -54,7 +53,6 @@ public final class MapPickInspection { return switch (layer.view()) { case REGIONS -> measureRegions(engine, area); case BIOMES -> measureBiomes(engine, area); - default -> throw new IllegalArgumentException("The " + layer.view().label() + " view has no picks to inspect"); }; } diff --git a/core/src/main/java/art/arcane/iris/core/studio/map/MapPickPath.java b/core/src/main/java/art/arcane/iris/core/studio/map/MapPickPath.java index 640a7fcc1..41b7652ce 100644 --- a/core/src/main/java/art/arcane/iris/core/studio/map/MapPickPath.java +++ b/core/src/main/java/art/arcane/iris/core/studio/map/MapPickPath.java @@ -51,13 +51,7 @@ public final class MapPickPath { return path; } path.add(regionStep(engine, region, x, z)); - MapView view = layer.view(); - switch (view) { - case LAND_BIOMES -> addListStep(path, engine, view, region, InferredType.LAND, x, z); - case SEA_BIOMES -> addListStep(path, engine, view, region, InferredType.SEA, x, z); - case CAVE_BIOMES -> addListStep(path, engine, view, region, InferredType.CAVE, x, z); - case BIOMES, REGIONS -> addBaseBiomeSteps(path, engine, view, region, x, z); - } + addBaseBiomeSteps(path, engine, layer.view(), region, x, z); return path; } diff --git a/core/src/main/java/art/arcane/iris/core/studio/map/MapTileRenderer.java b/core/src/main/java/art/arcane/iris/core/studio/map/MapTileRenderer.java index c088e7d73..65e66de2e 100644 --- a/core/src/main/java/art/arcane/iris/core/studio/map/MapTileRenderer.java +++ b/core/src/main/java/art/arcane/iris/core/studio/map/MapTileRenderer.java @@ -49,8 +49,7 @@ public final class MapTileRenderer { /** * The square of {@code size} pixels whose top left pixel samples ({@code startX}, {@code startZ}). * - * @param extras what to sample besides the labels; the height view always has heights, and only a layer that - * {@linkplain MapLayer#hasPickNoise() has pick noise} gets it + * @param extras what to sample besides the labels; the height view always has heights * @throws CancellationException as soon as {@code cancelled} answers true */ public MapTile render(MapLayer layer, double startX, double startZ, double blocksPerPixel, int size, @@ -120,12 +119,10 @@ public final class MapTileRenderer { IrisComplex complex = engine.getComplex(); ProceduralStream regionStream = complex.getRegionStream(); short[] regions = everyCell(grid, (x, z) -> labels.indexOf(regionStream.get(x, z))); - ProceduralStream biomeStream = layer.view().biomeStream(complex); - short[] subjects = layer.labelsRegions() ? regions : everyCell(grid, (x, z) -> labels.indexOf(biomeStream.get(x, z))); + ProceduralStream baseBiomes = complex.getBaseBiomeStream(); + short[] subjects = layer.labelsRegions() ? regions : everyCell(grid, (x, z) -> labels.indexOf(baseBiomes.get(x, z))); float[] heights = extras.contains(MapTile.Extra.HEIGHTS) ? latticeHeights(grid) : null; - float[] pickNoise = extras.contains(MapTile.Extra.PICK_NOISE) && layer.hasPickNoise() - ? MapPickNoise.sample(engine, layer, grid) - : null; + float[] pickNoise = extras.contains(MapTile.Extra.PICK_NOISE) ? MapPickNoise.sample(engine, layer, grid) : null; MapLabel.Kind subjectKind = layer.labelsRegions() ? MapLabel.Kind.REGION : MapLabel.Kind.BIOME; return new MapTile(grid.size() - 2, blocksPerPixel, subjectKind, labels.labels(), subjects, regions, heights, pickNoise, null); } diff --git a/core/src/main/java/art/arcane/iris/core/studio/map/MapView.java b/core/src/main/java/art/arcane/iris/core/studio/map/MapView.java index 8da0d49bb..8068eb8ec 100644 --- a/core/src/main/java/art/arcane/iris/core/studio/map/MapView.java +++ b/core/src/main/java/art/arcane/iris/core/studio/map/MapView.java @@ -18,10 +18,7 @@ package art.arcane.iris.core.studio.map; -import art.arcane.iris.engine.IrisComplex; import art.arcane.iris.engine.framework.render.RenderType; -import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.util.project.stream.ProceduralStream; import java.util.Arrays; import java.util.Optional; @@ -29,12 +26,7 @@ import java.util.Optional; /** The studio map's views of a world drawn from its engine streams, one tile at a time. */ public enum MapView { BIOMES("biomes", "Biomes", "The biome at each spot, in the biome's colour", Group.WORLD, RenderType.BIOME), - REGIONS("regions", "Regions", "The region each spot belongs to", Group.WORLD, RenderType.REGION), - LAND_BIOMES("landBiomes", "Land biomes", "The land biome each spot would get, also where the sea is", - Group.BIOME_LAYERS, RenderType.BIOME_LAND), - SEA_BIOMES("seaBiomes", "Sea biomes", "The sea biome each spot would get, also where the land is", - Group.BIOME_LAYERS, RenderType.BIOME_SEA), - CAVE_BIOMES("caveBiomes", "Cave biomes", "The cave biome under each spot", Group.BIOME_LAYERS, RenderType.CAVE_LAND); + REGIONS("regions", "Regions", "The region each spot belongs to", Group.WORLD, RenderType.REGION); private final String id; private final String label; @@ -80,19 +72,8 @@ public enum MapView { return colorType; } - /** The biome each spot is labelled with: the base biome, before the height corrects it near coasts. */ - ProceduralStream biomeStream(IrisComplex complex) { - return switch (this) { - case LAND_BIOMES -> complex.getLandBiomeStream(); - case SEA_BIOMES -> complex.getSeaBiomeStream(); - case CAVE_BIOMES -> complex.getCaveBiomeStream(); - case BIOMES, REGIONS -> complex.getBaseBiomeStream(); - }; - } - public enum Group { - WORLD("World"), - BIOME_LAYERS("Biome layers"); + WORLD("World"); private final String label; diff --git a/core/src/main/java/art/arcane/iris/core/studio/saved/SavedBlock.java b/core/src/main/java/art/arcane/iris/core/studio/saved/SavedBlock.java new file mode 100644 index 000000000..1ad7b482c --- /dev/null +++ b/core/src/main/java/art/arcane/iris/core/studio/saved/SavedBlock.java @@ -0,0 +1,28 @@ +/* + * Iris is a World Generator for Minecraft Servers + * Copyright (c) 2026 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package art.arcane.iris.core.studio.saved; + +/** + * A block as a region file holds it. + * + * @param name such as {@code minecraft:stone}, without its properties; a plugin's block is named as its plugin does + * @param drawnAs the state it was saved as, such as {@code minecraft:grass_block[snowy=false]}, which is what players see + */ +public record SavedBlock(String name, String drawnAs) { +} diff --git a/core/src/main/java/art/arcane/iris/core/studio/saved/SavedChunk.java b/core/src/main/java/art/arcane/iris/core/studio/saved/SavedChunk.java index 502adfedd..c8fcc9917 100644 --- a/core/src/main/java/art/arcane/iris/core/studio/saved/SavedChunk.java +++ b/core/src/main/java/art/arcane/iris/core/studio/saved/SavedChunk.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.TreeMap; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -91,14 +92,24 @@ final class SavedChunk { /** The block's name, such as {@code minecraft:stone}, without its properties; a plugin's block is named as its plugin does. */ String blockAt(int x, int y, int z) { + return nameOf(paletteBlockAt(x, y, z)); + } + + /** The block with the state it was saved as, which is what players see of it. */ + SavedBlock savedBlockAt(int x, int y, int z) { + Tag block = paletteBlockAt(x, y, z); + return new SavedBlock(nameOf(block), savedStateOf(block)); + } + + private Tag paletteBlockAt(int x, int y, int z) { CompoundTag section = sectionsByY.get(Math.floorDiv(y, BLOCKS_ACROSS)); if (section == null || !section.containsKey("block_states")) { - return AIR; + return new StringTag(AIR); } CompoundTag states = section.getCompoundTag("block_states"); ListTag palette = states.getListTag("palette"); int index = (Math.floorMod(y, BLOCKS_ACROSS) * BLOCKS_ACROSS + z) * BLOCKS_ACROSS + x; - return nameOf(paletteEntry(palette, states.getLongArray("data"), Math.max(SMALLEST_BLOCK_INDEX_BITS, bitsFor(palette.size())), index)); + return paletteEntry(palette, states.getLongArray("data"), Math.max(SMALLEST_BLOCK_INDEX_BITS, bitsFor(palette.size())), index); } /** The biome's key, such as {@code minecraft:plains}; biomes are stored once per 4 blocks across. */ @@ -126,15 +137,28 @@ final class SavedChunk { return entry < palette.size() ? palette.get(entry) : null; } - // A block with properties is a compound naming it under Name; since 26.1 a block without them may be its bare name. private String nameOf(Tag block) { - String name = switch (block) { + return customBlocks.nameSavedAs(vanillaNameOf(block), () -> propertiesOf(block)); + } + + private static String savedStateOf(Tag block) { + Map properties = new TreeMap<>(propertiesOf(block)); + if (properties.isEmpty()) { + return vanillaNameOf(block); + } + return vanillaNameOf(block) + properties.entrySet().stream() + .map(property -> property.getKey() + "=" + property.getValue()) + .collect(Collectors.joining(",", "[", "]")); + } + + // A block with properties is a compound naming it under Name; since 26.1 a block without them may be its bare name. + private static String vanillaNameOf(Tag block) { + return switch (block) { case StringTag text -> text.getValue(); case CompoundTag compound when !compound.getString("Name").isEmpty() -> compound.getString("Name"); case CompoundTag compound when !compound.getString("").isEmpty() -> compound.getString(""); case null, default -> UNKNOWN; }; - return customBlocks.nameSavedAs(name, () -> propertiesOf(block)); } private static Map propertiesOf(Tag block) { diff --git a/core/src/main/java/art/arcane/iris/core/studio/saved/SavedRegion.java b/core/src/main/java/art/arcane/iris/core/studio/saved/SavedRegion.java index 5f761c79c..e01bb37bc 100644 --- a/core/src/main/java/art/arcane/iris/core/studio/saved/SavedRegion.java +++ b/core/src/main/java/art/arcane/iris/core/studio/saved/SavedRegion.java @@ -54,9 +54,9 @@ final class SavedRegion { private final short[] waterSurfaceY = new short[BLOCKS_ACROSS * BLOCKS_ACROSS]; private final short[] blockIds = new short[BLOCKS_ACROSS * BLOCKS_ACROSS]; private final short[] biomeIds = new short[BLOCKS_ACROSS * BLOCKS_ACROSS]; - private final List blocks = new CopyOnWriteArrayList<>(); + private final List blocks = new CopyOnWriteArrayList<>(); private final List biomes = new CopyOnWriteArrayList<>(); - private final Map blockIndex = new HashMap<>(); + private final Map blockIndex = new HashMap<>(); private final Map biomeIndex = new HashMap<>(); private final Map waterColumnsBySurface = new HashMap<>(); private int minY = Integer.MAX_VALUE; @@ -135,7 +135,7 @@ final class SavedRegion { } } - private static short idOf(String name, Map index, List names) { + private static short idOf(Named name, Map index, List names) { return index.computeIfAbsent(name, added -> { names.add(added); return (short) (names.size() - 1); @@ -173,14 +173,14 @@ final class SavedRegion { * @param groundY the top block of the ground, under any water * @param waterSurfaceY the top water block over it, or {@link #NO_WATER} */ - record SavedColumn(int groundY, int waterSurfaceY, String block, String biome) { + record SavedColumn(int groundY, int waterSurfaceY, SavedBlock block, String biome) { } /** One chunk's columns, read without holding the region so other chunks can be read meanwhile. */ - private record ChunkColumns(int minY, short[] groundY, short[] waterSurfaceY, String[] blocks, String[] biomes) { + private record ChunkColumns(int minY, short[] groundY, short[] waterSurfaceY, SavedBlock[] blocks, String[] biomes) { static ChunkColumns of(SavedChunk chunk, SavedGround ground) { ChunkColumns columns = new ChunkColumns(chunk.minY(), new short[CHUNK_COLUMNS], new short[CHUNK_COLUMNS], - new String[CHUNK_COLUMNS], new String[CHUNK_COLUMNS]); + new SavedBlock[CHUNK_COLUMNS], new String[CHUNK_COLUMNS]); for (int z = 0; z < SavedChunk.BLOCKS_ACROSS; z++) { for (int x = 0; x < SavedChunk.BLOCKS_ACROSS; x++) { columns.read(chunk, ground, x, z); @@ -204,7 +204,7 @@ final class SavedRegion { } groundY[column] = (short) y; waterSurfaceY[column] = (short) waterTop; - blocks[column] = block; + blocks[column] = chunk.savedBlockAt(x, y, z); biomes[column] = chunk.biomeAt(x, y, z); } diff --git a/core/src/main/java/art/arcane/iris/core/studio/saved/SavedTile.java b/core/src/main/java/art/arcane/iris/core/studio/saved/SavedTile.java index 47a5494bd..95fde1495 100644 --- a/core/src/main/java/art/arcane/iris/core/studio/saved/SavedTile.java +++ b/core/src/main/java/art/arcane/iris/core/studio/saved/SavedTile.java @@ -31,7 +31,7 @@ import java.util.Map; * @param waterSurfaceY per pixel, the top water block over the ground, or {@link #NO_WATER} */ public record SavedTile(int size, int blocksPerPixel, short[] groundY, short[] waterSurfaceY, short[] blocks, short[] biomes, - List blockNames, List biomeNames) { + List savedBlocks, List biomeNames) { public static final short NO_GROUND = Short.MIN_VALUE; public static final short NO_WATER = (short) SavedRegion.NO_WATER; @@ -43,7 +43,7 @@ public record SavedTile(int size, int blocksPerPixel, short[] groundY, short[] w int pixels = size * size; SavedTile tile = new SavedTile(size, blocksPerPixel, new short[pixels], new short[pixels], new short[pixels], new short[pixels], new ArrayList<>(), new ArrayList<>()); - Map blockIds = new HashMap<>(); + Map blockIds = new HashMap<>(); Map biomeIds = new HashMap<>(); long originX = (long) tileX * size * blocksPerPixel; long originZ = (long) tileZ * size * blocksPerPixel; @@ -59,14 +59,14 @@ public record SavedTile(int size, int blocksPerPixel, short[] groundY, short[] w } tile.groundY[pixel] = (short) saved.groundY(); tile.waterSurfaceY[pixel] = (short) saved.waterSurfaceY(); - tile.blocks[pixel] = idOf(saved.block(), blockIds, tile.blockNames); + tile.blocks[pixel] = idOf(saved.block(), blockIds, tile.savedBlocks); tile.biomes[pixel] = idOf(saved.biome(), biomeIds, tile.biomeNames); } } return tile; } - private static short idOf(String name, Map ids, List names) { + private static short idOf(Named name, Map ids, List names) { return ids.computeIfAbsent(name, added -> { names.add(added); return (short) (names.size() - 1); diff --git a/core/src/test/java/art/arcane/iris/core/studio/bridge/StudioBridgeTest.java b/core/src/test/java/art/arcane/iris/core/studio/bridge/StudioBridgeTest.java index 1069559fb..84ad183ae 100644 --- a/core/src/test/java/art/arcane/iris/core/studio/bridge/StudioBridgeTest.java +++ b/core/src/test/java/art/arcane/iris/core/studio/bridge/StudioBridgeTest.java @@ -183,11 +183,6 @@ public class StudioBridgeTest { assertEquals(400, get("hover?view=regions&preview=nowhere&x=0&z=0").statusCode()); } - @Test - public void aBiomeLayerViewHasNoPicksToInspect() throws Exception { - assertEquals(400, get("picks?view=landBiomes&minX=0&minZ=0&maxX=10&maxZ=10").statusCode()); - } - @Test public void aWorldWithoutAnEngineIsUnavailableUntilItHasOneAgain() throws Exception { Engine engine = running.getAndSet(null); diff --git a/core/src/test/java/art/arcane/iris/core/studio/map/MapPickInspectionTest.java b/core/src/test/java/art/arcane/iris/core/studio/map/MapPickInspectionTest.java index 15f8fea36..886898ee6 100644 --- a/core/src/test/java/art/arcane/iris/core/studio/map/MapPickInspectionTest.java +++ b/core/src/test/java/art/arcane/iris/core/studio/map/MapPickInspectionTest.java @@ -67,11 +67,6 @@ public class MapPickInspectionTest { assertEquals(SPOTS, section.spreads().getFirst().samples()); } - @Test - public void aBiomeLayerViewHasNoPicks() { - assertThrows(IllegalArgumentException.class, () -> measure(MapLayer.of(MapView.LAND_BIOMES))); - } - @Test public void anAreaNeedsItsSecondCornerBeyondItsFirst() { assertThrows(IllegalArgumentException.class, () -> new MapPickInspection.Area(0D, 0D, 0D, 10D)); diff --git a/core/src/test/java/art/arcane/iris/core/studio/map/MapPickPathTest.java b/core/src/test/java/art/arcane/iris/core/studio/map/MapPickPathTest.java index 67d1016fb..d4075ffa8 100644 --- a/core/src/test/java/art/arcane/iris/core/studio/map/MapPickPathTest.java +++ b/core/src/test/java/art/arcane/iris/core/studio/map/MapPickPathTest.java @@ -45,11 +45,6 @@ public class MapPickPathTest { assertBand(bands.get(1), "plains", 0.25D, 1D); } - @Test - public void theLandViewStopsAtTheListPickBecauseItsStreamHasNoChildren() { - assertEquals(List.of(MapPickPath.Kind.REGION, MapPickPath.Kind.BIOME), kinds(explain(MapLayer.of(MapView.LAND_BIOMES)))); - } - @Test public void anImageMappedRegionWasChosenNotPicked() { when(world.imageMap.sampleRegion(X, Z)).thenReturn(world.dry); diff --git a/core/src/test/java/art/arcane/iris/core/studio/map/MapTileRendererTest.java b/core/src/test/java/art/arcane/iris/core/studio/map/MapTileRendererTest.java index 059a5eee0..2a874ef5a 100644 --- a/core/src/test/java/art/arcane/iris/core/studio/map/MapTileRendererTest.java +++ b/core/src/test/java/art/arcane/iris/core/studio/map/MapTileRendererTest.java @@ -87,14 +87,6 @@ public class MapTileRendererTest { assertEquals(Color.RED.getRGB() & 0xFFFFFF, tile.subjectAt(0, 0).color()); } - @Test - public void biomeLayersLabelWithTheirOwnStreamAndColouring() { - MapTile tile = render(MapView.CAVE_BIOMES, -4D, 0D, 1D, false); - - assertEquals("cavern", tile.subjectAt(0, 0).key()); - assertEquals("warm", tile.regionAt(0, 0).key()); - } - @Test public void aFlatWorldStaysFlat() { heights((x, z) -> 70D); @@ -199,12 +191,9 @@ public class MapTileRendererTest { MapTile plain = render(MapView.REGIONS, 0D, 0D, 1D, false); MapTile withNoise = new MapTileRenderer(engine).render(MapLayer.of(MapView.REGIONS), 0D, 0D, 1D, SIZE, Set.of(MapTile.Extra.PICK_NOISE), () -> false); - MapTile caves = new MapTileRenderer(engine).render(MapLayer.of(MapView.CAVE_BIOMES), 0D, 0D, 1D, SIZE, - Set.of(MapTile.Extra.PICK_NOISE), () -> false); assertNull(plain.pickNoise()); assertEquals(0.13F, withNoise.pickNoise()[withNoise.gridIndex(3, 5)], 1e-6F); - assertNull("no noise picks the cave biome layer here", caves.pickNoise()); } private MapTile render(MapView view, double startX, double startZ, double blocksPerPixel, boolean withHeights) { diff --git a/core/src/test/java/art/arcane/iris/core/studio/saved/SavedWorldTest.java b/core/src/test/java/art/arcane/iris/core/studio/saved/SavedWorldTest.java index 95f84143e..c54e0706f 100644 --- a/core/src/test/java/art/arcane/iris/core/studio/saved/SavedWorldTest.java +++ b/core/src/test/java/art/arcane/iris/core/studio/saved/SavedWorldTest.java @@ -79,7 +79,7 @@ public class SavedWorldTest { SavedRegion.SavedColumn underTree = world.columnAt(0, 0); assertEquals(TREE_GROUND_TOP, underTree.groundY()); assertEquals(SavedRegion.NO_WATER, underTree.waterSurfaceY()); - assertEquals("minecraft:stone", underTree.block()); + assertEquals(new SavedBlock("minecraft:stone", "minecraft:stone"), underTree.block()); assertEquals("test:meadow", underTree.biome()); SavedRegion.SavedColumn pond = world.columnAt(1, 0); @@ -96,7 +96,7 @@ public class SavedWorldTest { assertEquals(TREE_GROUND_TOP, world.columnAt(0, 0).groundY()); SavedRegion.SavedColumn snowyGround = world.columnAt(2, 0); assertEquals(PLAIN_GROUND_TOP + 1, snowyGround.groundY()); - assertEquals("minecraft:snow", snowyGround.block()); + assertEquals("minecraft:snow", snowyGround.block().name()); } @Test @@ -105,11 +105,11 @@ public class SavedWorldTest { SavedRegion.SavedColumn plugin = world.columnAt(3, 0); assertEquals(PLAIN_GROUND_TOP + 1, plugin.groundY()); - assertEquals("etopia:grass_block", plugin.block()); + assertEquals(new SavedBlock("etopia:grass_block", "minecraft:tripwire[attached=true]"), plugin.block()); SavedRegion.SavedColumn otherState = world.columnAt(5, 0); assertEquals(PLAIN_GROUND_TOP, otherState.groundY()); - assertEquals("minecraft:stone", otherState.block()); + assertEquals("minecraft:stone", otherState.block().name()); } @Test @@ -118,7 +118,7 @@ public class SavedWorldTest { SavedRegion.SavedColumn borrowed = world.columnAt(3, 0); assertEquals(PLAIN_GROUND_TOP, borrowed.groundY()); - assertEquals("minecraft:stone", borrowed.block()); + assertEquals("minecraft:stone", borrowed.block().name()); } @Test @@ -151,7 +151,7 @@ public class SavedWorldTest { assertEquals(PLAIN_GROUND_TOP + 1, tile.groundY()[1]); assertEquals(PLAIN_GROUND_TOP, tile.groundY()[2]); assertEquals(SavedTile.NO_GROUND, tile.groundY()[8]); - assertEquals(List.of("minecraft:stone", "minecraft:snow"), tile.blockNames()); + assertEquals(List.of("minecraft:stone", "minecraft:snow"), tile.savedBlocks().stream().map(SavedBlock::name).toList()); assertEquals(List.of("test:meadow"), tile.biomeNames()); } diff --git a/studio/src/renderer/src/bridge/savedTileDecoding.ts b/studio/src/renderer/src/bridge/savedTileDecoding.ts index e287d85dc..5e0e3db52 100644 --- a/studio/src/renderer/src/bridge/savedTileDecoding.ts +++ b/studio/src/renderer/src/bridge/savedTileDecoding.ts @@ -5,7 +5,7 @@ const ALIGNMENT_BYTES = 4 interface SavedTileHeader { size: number blocksPerPixel: number - blocks: string[] + blocks: { name: string; drawnAs: string }[] biomes: MapLabel[] noGround: number noWater: number @@ -32,7 +32,8 @@ export function decodeSavedTile(buffer: ArrayBuffer): SavedTile { waterSurfaceY: gridAt(1), blocks: gridAt(2), biomes: gridAt(3), - blockNames: header.blocks, + blockNames: header.blocks.map((block) => block.name), + blocksDrawnAs: header.blocks.map((block) => block.drawnAs), biomeLabels: header.biomes, noGround: header.noGround, noWater: header.noWater diff --git a/studio/src/renderer/src/bridge/types.ts b/studio/src/renderer/src/bridge/types.ts index 1662b396f..19f5ea227 100644 --- a/studio/src/renderer/src/bridge/types.ts +++ b/studio/src/renderer/src/bridge/types.ts @@ -205,10 +205,13 @@ export interface SavedTile { groundY: Int16Array /** The top water block over the ground; {@link noWater} where it is dry. */ waterSurfaceY: Int16Array - /** Indices into {@link blockNames} and {@link biomes}. */ + /** Indices into {@link blockNames}, {@link blocksDrawnAs} and {@link biomeLabels}. */ blocks: Int16Array biomes: Int16Array + /** Each block without its properties; a plugin's block by the name its plugin gives it. */ blockNames: string[] + /** Per block, the state it was saved as, which players see and the studio draws; a plugin block's is the vanilla state it borrows. */ + blocksDrawnAs: string[] biomeLabels: MapLabel[] noGround: number noWater: number diff --git a/studio/src/renderer/src/components/IdeIcon.tsx b/studio/src/renderer/src/components/IdeIcon.tsx index f1e4b0b3c..beaa821e8 100644 --- a/studio/src/renderer/src/components/IdeIcon.tsx +++ b/studio/src/renderer/src/components/IdeIcon.tsx @@ -1,16 +1,19 @@ import { cn } from '@/lib/utils' -// IntelliJ's expui icons (see icons/NOTICE.txt): each has a light file and a "_dark" twin in its own colours. +// IntelliJ's expui icons and the studio's own drawn to match (see icons/NOTICE.txt): each has a light file and a "_dark" twin in its own colours. const ICON_URLS = import.meta.glob('../icons/**/*.svg', { eager: true, query: '?url', import: 'default' }) const DARK_SUFFIX = '_dark' export type IdeIconName = + | 'actualZoom' | 'add' | 'blocks' + | 'borders' | 'checked' | 'closeSmall' | 'chevronLeft' | 'chevronRight' + | 'decoration' | 'delete' | 'exit' | 'grid' @@ -20,6 +23,7 @@ export type IdeIconName = | 'locate' | 'locked' | 'memory' + | 'mob' | 'redo' | 'refresh' | 'reset' @@ -30,19 +34,14 @@ export type IdeIconName = | 'symlink' | 'theme' | 'undo' - | 'user' | 'web' - | 'zoomIn' | 'views/biomes' - | 'views/cave-biomes' - | 'views/land-biomes' | 'views/noise' | 'views/objects' | 'views/palettes' | 'views/procedural' | 'views/regions' | 'views/saved-world' - | 'views/sea-biomes' | 'views/world-3d' function iconUrl(name: string): string { diff --git a/studio/src/renderer/src/icons/NOTICE.txt b/studio/src/renderer/src/icons/NOTICE.txt index 67f83c414..e3d07cdd4 100644 --- a/studio/src/renderer/src/icons/NOTICE.txt +++ b/studio/src/renderer/src/icons/NOTICE.txt @@ -2,4 +2,5 @@ The icons in this folder and its subfolders come from the IntelliJ Platform (htt platform/icons/src/expui, Copyright 2000-2023 JetBrains s.r.o. and contributors, used under the Apache License 2.0 (LICENSE-APACHE-2.0.txt). memory.svg is profileMemory.svg with its profiling badge removed. -theme.svg and blocks.svg are the studio's own, drawn to match. +theme.svg, blocks.svg, borders.svg, shading.svg, mob.svg, actualZoom.svg, decoration.svg, and in views/ biomes.svg, regions.svg, +world-3d.svg, saved-world.svg, noise.svg and objects.svg are the studio's own, drawn to match. diff --git a/studio/src/renderer/src/icons/actualZoom.svg b/studio/src/renderer/src/icons/actualZoom.svg new file mode 100644 index 000000000..08981f5e8 --- /dev/null +++ b/studio/src/renderer/src/icons/actualZoom.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/studio/src/renderer/src/icons/actualZoom_dark.svg b/studio/src/renderer/src/icons/actualZoom_dark.svg new file mode 100644 index 000000000..0cc5f18b6 --- /dev/null +++ b/studio/src/renderer/src/icons/actualZoom_dark.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/studio/src/renderer/src/icons/borders.svg b/studio/src/renderer/src/icons/borders.svg new file mode 100644 index 000000000..4fe3957a7 --- /dev/null +++ b/studio/src/renderer/src/icons/borders.svg @@ -0,0 +1,3 @@ + + + diff --git a/studio/src/renderer/src/icons/borders_dark.svg b/studio/src/renderer/src/icons/borders_dark.svg new file mode 100644 index 000000000..2f7ce7863 --- /dev/null +++ b/studio/src/renderer/src/icons/borders_dark.svg @@ -0,0 +1,3 @@ + + + diff --git a/studio/src/renderer/src/icons/decoration.svg b/studio/src/renderer/src/icons/decoration.svg new file mode 100644 index 000000000..fb2a026ea --- /dev/null +++ b/studio/src/renderer/src/icons/decoration.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/studio/src/renderer/src/icons/decoration_dark.svg b/studio/src/renderer/src/icons/decoration_dark.svg new file mode 100644 index 000000000..0e0b87790 --- /dev/null +++ b/studio/src/renderer/src/icons/decoration_dark.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/studio/src/renderer/src/icons/mob.svg b/studio/src/renderer/src/icons/mob.svg new file mode 100644 index 000000000..bcd9e1a0e --- /dev/null +++ b/studio/src/renderer/src/icons/mob.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/studio/src/renderer/src/icons/mob_dark.svg b/studio/src/renderer/src/icons/mob_dark.svg new file mode 100644 index 000000000..f1b911136 --- /dev/null +++ b/studio/src/renderer/src/icons/mob_dark.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/studio/src/renderer/src/icons/shading.svg b/studio/src/renderer/src/icons/shading.svg index 59538313d..c545e1d8b 100644 --- a/studio/src/renderer/src/icons/shading.svg +++ b/studio/src/renderer/src/icons/shading.svg @@ -1,7 +1,4 @@ - - - - - + + diff --git a/studio/src/renderer/src/icons/shading_dark.svg b/studio/src/renderer/src/icons/shading_dark.svg index 9dc4f2498..cc2b121d0 100644 --- a/studio/src/renderer/src/icons/shading_dark.svg +++ b/studio/src/renderer/src/icons/shading_dark.svg @@ -1,7 +1,4 @@ - - - - - + + diff --git a/studio/src/renderer/src/icons/user.svg b/studio/src/renderer/src/icons/user.svg deleted file mode 100644 index b0d3ad131..000000000 --- a/studio/src/renderer/src/icons/user.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/studio/src/renderer/src/icons/user_dark.svg b/studio/src/renderer/src/icons/user_dark.svg deleted file mode 100644 index 71816fd61..000000000 --- a/studio/src/renderer/src/icons/user_dark.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/studio/src/renderer/src/icons/views/biomes.svg b/studio/src/renderer/src/icons/views/biomes.svg index 8d0d7e5cd..78c98d754 100644 --- a/studio/src/renderer/src/icons/views/biomes.svg +++ b/studio/src/renderer/src/icons/views/biomes.svg @@ -1,7 +1,8 @@ - - - - - - + + + + + + + diff --git a/studio/src/renderer/src/icons/views/biomes_dark.svg b/studio/src/renderer/src/icons/views/biomes_dark.svg index c8ab2b955..731013503 100644 --- a/studio/src/renderer/src/icons/views/biomes_dark.svg +++ b/studio/src/renderer/src/icons/views/biomes_dark.svg @@ -1,7 +1,8 @@ - - - - - - + + + + + + + diff --git a/studio/src/renderer/src/icons/views/cave-biomes.svg b/studio/src/renderer/src/icons/views/cave-biomes.svg deleted file mode 100644 index 9f48d8b1e..000000000 --- a/studio/src/renderer/src/icons/views/cave-biomes.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/studio/src/renderer/src/icons/views/cave-biomes_dark.svg b/studio/src/renderer/src/icons/views/cave-biomes_dark.svg deleted file mode 100644 index aecd83789..000000000 --- a/studio/src/renderer/src/icons/views/cave-biomes_dark.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/studio/src/renderer/src/icons/views/land-biomes.svg b/studio/src/renderer/src/icons/views/land-biomes.svg deleted file mode 100644 index 9a09720fa..000000000 --- a/studio/src/renderer/src/icons/views/land-biomes.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/studio/src/renderer/src/icons/views/land-biomes_dark.svg b/studio/src/renderer/src/icons/views/land-biomes_dark.svg deleted file mode 100644 index 4f189a0e3..000000000 --- a/studio/src/renderer/src/icons/views/land-biomes_dark.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/studio/src/renderer/src/icons/views/noise.svg b/studio/src/renderer/src/icons/views/noise.svg index 622ee6927..e735984cf 100644 --- a/studio/src/renderer/src/icons/views/noise.svg +++ b/studio/src/renderer/src/icons/views/noise.svg @@ -1,5 +1,3 @@ - - - + diff --git a/studio/src/renderer/src/icons/views/noise_dark.svg b/studio/src/renderer/src/icons/views/noise_dark.svg index 0f92bb482..187dd72f4 100644 --- a/studio/src/renderer/src/icons/views/noise_dark.svg +++ b/studio/src/renderer/src/icons/views/noise_dark.svg @@ -1,5 +1,3 @@ - - - + diff --git a/studio/src/renderer/src/icons/views/objects.svg b/studio/src/renderer/src/icons/views/objects.svg index 9c50b9557..6297b050c 100644 --- a/studio/src/renderer/src/icons/views/objects.svg +++ b/studio/src/renderer/src/icons/views/objects.svg @@ -1,7 +1,4 @@ - - - - - + + diff --git a/studio/src/renderer/src/icons/views/objects_dark.svg b/studio/src/renderer/src/icons/views/objects_dark.svg index 5429972cd..4e3d96e86 100644 --- a/studio/src/renderer/src/icons/views/objects_dark.svg +++ b/studio/src/renderer/src/icons/views/objects_dark.svg @@ -1,7 +1,4 @@ - - - - - + + diff --git a/studio/src/renderer/src/icons/views/regions.svg b/studio/src/renderer/src/icons/views/regions.svg index d4ab80fbb..f2848a5ee 100644 --- a/studio/src/renderer/src/icons/views/regions.svg +++ b/studio/src/renderer/src/icons/views/regions.svg @@ -1,7 +1,4 @@ - - - - - + + diff --git a/studio/src/renderer/src/icons/views/regions_dark.svg b/studio/src/renderer/src/icons/views/regions_dark.svg index 2769c3ce0..f28c07a18 100644 --- a/studio/src/renderer/src/icons/views/regions_dark.svg +++ b/studio/src/renderer/src/icons/views/regions_dark.svg @@ -1,7 +1,4 @@ - - - - - + + diff --git a/studio/src/renderer/src/icons/views/sea-biomes.svg b/studio/src/renderer/src/icons/views/sea-biomes.svg deleted file mode 100644 index f24d3b7af..000000000 --- a/studio/src/renderer/src/icons/views/sea-biomes.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/studio/src/renderer/src/icons/views/sea-biomes_dark.svg b/studio/src/renderer/src/icons/views/sea-biomes_dark.svg deleted file mode 100644 index 3fc7dc1b7..000000000 --- a/studio/src/renderer/src/icons/views/sea-biomes_dark.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/studio/src/renderer/src/icons/views/world-3d.svg b/studio/src/renderer/src/icons/views/world-3d.svg index 897fab392..233fbbd78 100644 --- a/studio/src/renderer/src/icons/views/world-3d.svg +++ b/studio/src/renderer/src/icons/views/world-3d.svg @@ -1,4 +1,4 @@ - - + + diff --git a/studio/src/renderer/src/icons/views/world-3d_dark.svg b/studio/src/renderer/src/icons/views/world-3d_dark.svg index 0ca6194ab..46f0ee93d 100644 --- a/studio/src/renderer/src/icons/views/world-3d_dark.svg +++ b/studio/src/renderer/src/icons/views/world-3d_dark.svg @@ -1,4 +1,4 @@ - - + + diff --git a/studio/src/renderer/src/icons/zoomIn.svg b/studio/src/renderer/src/icons/zoomIn.svg deleted file mode 100644 index dc4380e34..000000000 --- a/studio/src/renderer/src/icons/zoomIn.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/studio/src/renderer/src/icons/zoomIn_dark.svg b/studio/src/renderer/src/icons/zoomIn_dark.svg deleted file mode 100644 index 39cb0f660..000000000 --- a/studio/src/renderer/src/icons/zoomIn_dark.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/studio/src/renderer/src/scene/cameraSight.ts b/studio/src/renderer/src/scene/cameraSight.ts index 2fa481a17..41e4e6981 100644 --- a/studio/src/renderer/src/scene/cameraSight.ts +++ b/studio/src/renderer/src/scene/cameraSight.ts @@ -10,8 +10,6 @@ export interface SightView { } const NDC_MIDDLE_DEPTH = 0.5 -const NOT_BEHIND_THE_CAMERA = 0 -const BEHIND_THE_CAMERA = 1e9 /** * What the camera sees of ground that lies between {@code floorY} and {@code topY}: which terrain tiles land in the @@ -20,6 +18,7 @@ const BEHIND_THE_CAMERA = 1e9 export class CameraSight { private readonly frustums = new Map() private readonly position = new Vector3() + private readonly lookedAt: Vector3 constructor( private readonly view: SightView, @@ -28,6 +27,7 @@ export class CameraSight { ) { view.camera.updateMatrixWorld() view.camera.getWorldPosition(this.position) + this.lookedAt = this.groundInMiddleOfView() } get orbitDistance(): number { @@ -52,15 +52,24 @@ export class CameraSight { return blocksPerColumn(tile.level) * pixelsPerBlock } - /** How far the tile's middle lies from the middle of the view on the screen; tiles behind the camera lie furthest. */ - distanceFromMiddle(tile: TerrainTile): number { - const middle = new Vector3(originXOf(tile) + tileBlocks(tile.level) / 2, (this.floorY + this.topY) / 2, originZOf(tile) + tileBlocks(tile.level) / 2) - const behind = middle.clone().applyMatrix4(this.view.camera.matrixWorldInverse).z > NOT_BEHIND_THE_CAMERA - if (behind) { - return BEHIND_THE_CAMERA + middle.distanceTo(this.position) + /** How many blocks the tile lies from the ground in the middle of the view; nothing for the tile that ground is in. */ + distanceFromLookedAt(tile: TerrainTile): number { + const size = tileBlocks(tile.level) + const x = originXOf(tile) + const z = originZOf(tile) + const pastX = Math.max(x - this.lookedAt.x, 0, this.lookedAt.x - (x + size)) + const pastZ = Math.max(z - this.lookedAt.z, 0, this.lookedAt.z - (z + size)) + return Math.hypot(pastX, pastZ) + } + + // Where the line of sight comes down to the middle height of the ground, or under the camera when it never does. + private groundInMiddleOfView(): Vector3 { + const direction = this.view.camera.getWorldDirection(new Vector3()) + const distance = ((this.floorY + this.topY) / 2 - this.position.y) / direction.y + if (!Number.isFinite(distance) || distance < 0) { + return this.position.clone() } - const onScreen = middle.project(this.view.camera) - return Math.hypot(onScreen.x, onScreen.y) + return direction.multiplyScalar(Math.min(distance, this.view.camera.far)).add(this.position) } /** The tiles of {@code level} in sight, widened by {@code margin}. */ diff --git a/studio/src/renderer/src/scene/columnField.ts b/studio/src/renderer/src/scene/columnField.ts index 89fe576da..65fe9f4cd 100644 --- a/studio/src/renderer/src/scene/columnField.ts +++ b/studio/src/renderer/src/scene/columnField.ts @@ -23,6 +23,8 @@ export class ColumnField { readonly looks: (BlockLook | null)[] /** The atlas of the looks, or null where no column has one. */ readonly pictures: TerrainPictures | null + /** How low and high the top faces stand, ground and water alike; null where no column has ground. */ + readonly topRange: { lowest: number; highest: number } | null constructor(surface: TerrainSurface, holes: readonly ColumnArea[] = []) { this.columns = surface.columns @@ -37,6 +39,7 @@ export class ColumnField { this.looks = new Array(count).fill(null) const hasPictures = surface.pictures !== undefined let anyLook = false + let [lowestTop, highestTop] = [Infinity, -Infinity] const inHole = this.holeMask(holes) for (let row = 0; row < this.rows; row++) { for (let column = 0; column < this.columns; column++) { @@ -52,9 +55,12 @@ export class ColumnField { const look = hasPictures ? (surface.lookAt?.(column, row) ?? null) : null this.looks[index] = look anyLook ||= look !== null + lowestTop = Math.min(lowestTop, ground + 1) + highestTop = Math.max(highestTop, ground + 1, water === null ? ground : water + 1) } } this.pictures = anyLook ? (surface.pictures ?? null) : null + this.topRange = lowestTop === Infinity ? null : { lowest: lowestTop, highest: highestTop } } indexOf(column: number, row: number): number { diff --git a/studio/src/renderer/src/scene/savedTerrain.test.ts b/studio/src/renderer/src/scene/savedTerrain.test.ts index 1c6289a23..9925506c0 100644 --- a/studio/src/renderer/src/scene/savedTerrain.test.ts +++ b/studio/src/renderer/src/scene/savedTerrain.test.ts @@ -5,7 +5,7 @@ import type { BlockLook } from './blockLooks' import { SavedTerrain, type ReadSavedTile, type SavedTerrainColoring } from './savedTerrain' import { cellAt, type TerrainPictures } from './terrainAtlas' -const GRASS = 'minecraft:grass_block' +const GRASS = 'minecraft:grass_block[snowy=false]' const STONE = 'minecraft:stone' const FACE = { cell: cellAt(1, 0x808080), tint: 0xffffff, color: 0x808080 } const LOOK: BlockLook = { top: FACE, side: FACE, below: FACE } @@ -19,7 +19,8 @@ const tile = { waterSurfaceY: Int16Array.of(-1, -1, -1, -1), blocks: Int16Array.of(0, 1, 1, 1), biomes: Int16Array.of(0, 0, 0, 0), - blockNames: [GRASS, STONE], + blockNames: ['minecraft:grass_block', STONE], + blocksDrawnAs: [GRASS, STONE], biomeLabels: [{ color: 0x00ff00 }], noGround: -32768, noWater: -1 diff --git a/studio/src/renderer/src/scene/savedTerrain.ts b/studio/src/renderer/src/scene/savedTerrain.ts index ec1660366..aef9a2992 100644 --- a/studio/src/renderer/src/scene/savedTerrain.ts +++ b/studio/src/renderer/src/scene/savedTerrain.ts @@ -7,7 +7,7 @@ import { blocksPerColumn, originXOf, originZOf, type TerrainTile } from './terra export type SavedTerrainColoring = 'biomes' | 'blocks' | 'height' -/** A saved tile, the colour of every block it holds, and the look of each where the tile is fine enough to show textures. */ +/** A saved tile, the colour of every state its blocks are drawn as, and the look of each where the tile is fine enough to show textures. */ export interface ReadSavedTile { tile: SavedTile blockColors: Map @@ -59,7 +59,7 @@ export class SavedTerrain implements TerrainSurface { return null } const { tile, blockLooks } = this.read - return blockLooks.get(tile.blockNames[tile.blocks[this.pixelAt(column, row)]]) ?? null + return blockLooks.get(tile.blocksDrawnAs[tile.blocks[this.pixelAt(column, row)]]) ?? null } colorAt(column: number, row: number): number { @@ -69,7 +69,7 @@ export class SavedTerrain implements TerrainSurface { case 'height': return heightColor(tile.groundY[pixel], this.seaLevel ?? VANILLA_SEA_LEVEL) case 'blocks': - return blockColors.get(tile.blockNames[tile.blocks[pixel]]) ?? UNKNOWN_BLOCK_COLOR + return blockColors.get(tile.blocksDrawnAs[tile.blocks[pixel]]) ?? UNKNOWN_BLOCK_COLOR case 'biomes': return tile.biomeLabels[tile.biomes[pixel]].color } diff --git a/studio/src/renderer/src/scene/savedTileSource.ts b/studio/src/renderer/src/scene/savedTileSource.ts index 77706be74..5adf56a00 100644 --- a/studio/src/renderer/src/scene/savedTileSource.ts +++ b/studio/src/renderer/src/scene/savedTileSource.ts @@ -22,7 +22,7 @@ export function savedTileSource(client: BridgeClient, blockColors: BlockColors, fetch: async (address, layer, signal) => { const tile = await client.savedTile(layer.worldId, address.tileX, address.tileZ, address.blocksPerPixel, TILE_COLUMNS, signal) const textured = address.blocksPerPixel === FINEST_BLOCKS_PER_COLUMN - const [colors, looks] = await Promise.all([blockColors.colorsOf(tile.blockNames), textured ? blockLooks.looksOf(tile.blockNames) : new Map()]) + const [colors, looks] = await Promise.all([blockColors.colorsOf(tile.blocksDrawnAs), textured ? blockLooks.looksOf(tile.blocksDrawnAs) : new Map()]) return { tile, blockColors: colors, blockLooks: looks } }, bytesOf: ({ tile }) => diff --git a/studio/src/renderer/src/scene/terrainAtlas.ts b/studio/src/renderer/src/scene/terrainAtlas.ts index 13bb4d5cf..6f71deed4 100644 --- a/studio/src/renderer/src/scene/terrainAtlas.ts +++ b/studio/src/renderer/src/scene/terrainAtlas.ts @@ -1,4 +1,4 @@ -import { CanvasTexture, NearestFilter, SRGBColorSpace, type Texture } from 'three' +import { CanvasTexture, NearestFilter, type Texture } from 'three' import { averageColor } from './blockColors' import { texturePath, type ImageSource } from './textureAtlas' @@ -30,6 +30,10 @@ const ATLAS_PIXELS = CELLS_PER_SIDE * CELL_PIXELS const PLAIN_CELL = 0 const WHITE = '#ffffff' const WHITE_COLOR = 0xffffff +const OPAQUE_ALPHA = 255 +// The same line blockColors draws between a pixel that counts toward a picture's colour and one that does not. +const OPAQUE_ENOUGH_ALPHA = 128 +const GAP_SHADE = 0.6 /** The cell with this number, counted row by row from the top left. */ export function cellAt(index: number, average: number): UvCell { @@ -70,7 +74,6 @@ export class TerrainAtlas implements TerrainPictures, PictureSource { this.texture.minFilter = NearestFilter this.texture.generateMipmaps = false this.texture.flipY = false - this.texture.colorSpace = SRGBColorSpace } cellOf(textureId: string): Promise { @@ -96,7 +99,26 @@ export class TerrainAtlas implements TerrainPictures, PictureSource { const left = placed.u * ATLAS_PIXELS const top = placed.v * ATLAS_PIXELS this.drawing.drawImage(bitmap, 0, 0, bitmap.width, Math.min(bitmap.width, bitmap.height), left, top, CELL_PIXELS, CELL_PIXELS) + const picture = this.drawing.getImageData(left, top, CELL_PIXELS, CELL_PIXELS) + const average = averageColor(picture) + this.drawing.putImageData(withGapsFilled(picture, average), left, top) this.texture.needsUpdate = true - return { ...placed, average: averageColor(this.drawing.getImageData(left, top, CELL_PIXELS, CELL_PIXELS)) } + return { ...placed, average } } } + +// The terrain draws whole faces, so what a picture leaves open, as leaves do between their twigs, would show as black: +// it takes the picture's own colour instead, darker, as the shade seen through the gaps. +function withGapsFilled(picture: ImageData, average: number): ImageData { + const pixels = picture.data + const gap = [(average >> 16) & 0xff, (average >> 8) & 0xff, average & 0xff].map((channel) => Math.round(channel * GAP_SHADE)) + for (let offset = 0; offset < pixels.length; offset += 4) { + if (pixels[offset + 3] < OPAQUE_ENOUGH_ALPHA) { + pixels[offset] = gap[0] + pixels[offset + 1] = gap[1] + pixels[offset + 2] = gap[2] + } + pixels[offset + 3] = OPAQUE_ALPHA + } + return picture +} diff --git a/studio/src/renderer/src/scene/terrainCover.ts b/studio/src/renderer/src/scene/terrainCover.ts index 8786fb0d9..33aab93c5 100644 --- a/studio/src/renderer/src/scene/terrainCover.ts +++ b/studio/src/renderer/src/scene/terrainCover.ts @@ -134,5 +134,5 @@ function wantedInOrder(sight: CameraSight, backdrop: TerrainTile[], detail: Terr } function nearestFirst(sight: CameraSight): (first: TerrainTile, second: TerrainTile) => number { - return (first, second) => sight.distanceFromMiddle(first) - sight.distanceFromMiddle(second) + return (first, second) => sight.distanceFromLookedAt(first) - sight.distanceFromLookedAt(second) } diff --git a/studio/src/renderer/src/scene/terrainStream.test.ts b/studio/src/renderer/src/scene/terrainStream.test.ts index 58ecfe49b..bf4631edb 100644 --- a/studio/src/renderer/src/scene/terrainStream.test.ts +++ b/studio/src/renderer/src/scene/terrainStream.test.ts @@ -16,6 +16,8 @@ interface FlatLayer { } const COARSEST_LEVEL = 8 +// A source that cannot sample coarser has more tiles in sight than it may draw, so it has to pick the right ones. +const COARSEST_SAVED_LEVEL = 4 const LOOKED_AT = new Vector3(0, 64, 0) const open = Promise.resolve() @@ -34,7 +36,7 @@ const flatStyle: TerrainStyle = { topY: 128 } -function setUp(): { +function setUp(coarsestLevel = COARSEST_LEVEL): { stream: TerrainStream camera: PerspectiveCamera moved(): void @@ -55,7 +57,7 @@ function setUp(): { } const stream = new TerrainStream({ source, - coarsestLevel: COARSEST_LEVEL, + coarsestLevel, focus: focusAround(0, 0, 0, 128), onPending: (pending) => pendingCounts.push(pending), onError: (message) => { @@ -183,6 +185,18 @@ describe('terrain stream', () => { expect(stream.groundInView()!.area.minX).toBeGreaterThan(seen.area.maxX) }) + it('draws the ground under a camera that is close to it in a world with a tall sky', async () => { + const { stream, camera, moved } = setUp(COARSEST_SAVED_LEVEL) + stream.restyle({ ...flatStyle, floorY: -64, topY: 1024 }) + stream.showLayer({ name: 'one', height: 70, gate: open }) + camera.position.set(250, 260, 300) + camera.lookAt(new Vector3(36, 71, 47)) + moved() + await settle() + const sight = new Ray(camera.position.clone(), camera.getWorldDirection(new Vector3())) + expect(stream.content.surfaceAlong!(sight, 2000)!.y).toBeCloseTo(71, 1) + }) + it('stops drawing when it is let go', async () => { const { stream, stopFollowing, requested } = setUp() stream.restyle(flatStyle) diff --git a/studio/src/renderer/src/scene/terrainStream.ts b/studio/src/renderer/src/scene/terrainStream.ts index dcc483473..f4982e9a0 100644 --- a/studio/src/renderer/src/scene/terrainStream.ts +++ b/studio/src/renderer/src/scene/terrainStream.ts @@ -20,7 +20,7 @@ export interface TerrainStreamOptions { source: TileSource /** The coarsest level the source samples: tiles of level n have columns 2^n blocks wide. */ coarsestLevel: number - /** The box the camera frames when the terrain is first shown. */ + /** The box the camera frames when the terrain is first shown; ground is looked for between its heights until tiles show where it really stands. */ focus: Box3 /** Told how many tiles are still on their way, whenever that changes. */ onPending(pending: number): void @@ -66,8 +66,15 @@ export class TerrainStream { private reportedPending = -1 private continuation: ReturnType | null = null private disposed = false + // Tiles are looked for where ground stands, not across the world's whole height: under a tall sky most of a tile's + // box is air, which lands in the view where its ground does not. + private lowestGround: number + private highestGround: number + private groundRangeGrew = false constructor(private readonly options: TerrainStreamOptions) { + this.lowestGround = options.focus.min.y + this.highestGround = options.focus.max.y this.store = new TileStore(options.source, () => this.replan(), options.onError) this.content = { object: this.group, @@ -139,7 +146,7 @@ export class TerrainStream { if (this.disposed || this.layer === null || this.style === null || this.camera === null) { return } - const sight = new CameraSight(this.camera.view(), this.style.floorY, this.style.topY) + const sight = new CameraSight(this.camera.view(), this.lowestGround, this.highestGround) const layer = this.layer const cover = planCover(sight, (tile) => this.stateOf(tile, layer), this.options.coarsestLevel) this.store.want(cover.wanted.map(addressOf), layer) @@ -184,6 +191,10 @@ export class TerrainStream { this.show(key, draw, data, style) } this.camera?.redraw() + if (this.groundRangeGrew) { + this.groundRangeGrew = false + this.continueLater() + } if (behind) { this.continueLater() return @@ -212,6 +223,17 @@ export class TerrainStream { const mesh = buildTerrainMesh(style.surfaceOf(data, draw.tile), style.floorY, draw.holes) this.group.add(mesh.object) this.drawn.set(key, { tile: draw.tile, data, signature: this.signatureOf(draw), mesh }) + this.growGroundRangeOver(mesh.field) + } + + private growGroundRangeOver(field: ColumnField): void { + const tops = field.topRange + if (tops === null || (tops.lowest >= this.lowestGround && tops.highest <= this.highestGround)) { + return + } + this.lowestGround = Math.min(this.lowestGround, tops.lowest) + this.highestGround = Math.max(this.highestGround, tops.highest) + this.groundRangeGrew = true } private hide(key: string, drawn: DrawnMesh): void { diff --git a/studio/src/renderer/src/scene/textureAtlas.ts b/studio/src/renderer/src/scene/textureAtlas.ts index 4bf1599a6..261febd46 100644 --- a/studio/src/renderer/src/scene/textureAtlas.ts +++ b/studio/src/renderer/src/scene/textureAtlas.ts @@ -1,4 +1,4 @@ -import { CanvasTexture, NearestFilter, SRGBColorSpace } from 'three' +import { CanvasTexture, NearestFilter } from 'three' /** Where block textures come from: the bridge's copy of the client's assets. */ export interface ImageSource { @@ -37,7 +37,6 @@ export class TextureAtlas { this.texture.minFilter = NearestFilter this.texture.generateMipmaps = false this.texture.flipY = false - this.texture.colorSpace = SRGBColorSpace } static async of(textureIds: string[], images: ImageSource): Promise { diff --git a/studio/src/renderer/src/studio/HoverCard.tsx b/studio/src/renderer/src/studio/HoverCard.tsx index 8cd2f5d18..d8b003e90 100644 --- a/studio/src/renderer/src/studio/HoverCard.tsx +++ b/studio/src/renderer/src/studio/HoverCard.tsx @@ -46,8 +46,8 @@ export function HoverCard({ hover, point, viewId, previewing, detailed, minY }: }, [point, hover, detailed]) const labelsRegions = viewId === 'regions' && !previewing - const subject = viewId === 'caveBiomes' ? hover.caveBiome : labelsRegions ? hover.region : hover.biome - const groups = detailed ? detailGroups(hover, viewId) : [] + const subject = labelsRegions ? hover.region : hover.biome + const groups = detailed ? detailGroups(hover) : [] const parent = replacedParent(hover.pickPath) return (
= { Group: 'groups', 'Shared part': 'symlink', Material: 'views/palettes', - Decoration: 'views/land-biomes' + Decoration: 'decoration' } const FIT_MARGIN = 24 const LARGEST_FIT_SCALE = 1 diff --git a/studio/src/renderer/src/studio/SavedWorldStudio.tsx b/studio/src/renderer/src/studio/SavedWorldStudio.tsx index 7199ee132..72e23bd09 100644 --- a/studio/src/renderer/src/studio/SavedWorldStudio.tsx +++ b/studio/src/renderer/src/studio/SavedWorldStudio.tsx @@ -18,6 +18,7 @@ import { focusAround, type TerrainStyle } from '../scene/terrainStream' import { SceneViewport } from './SceneViewport' import { Separator } from '@/components/ui/separator' import { HEADER_CHOICE, SidebarPanel, ViewIsland } from './Sidebar' +import { useSpotActions } from './useSpotActions' import { useTerrainStream } from './useTerrainStream' const NUMBER = new Intl.NumberFormat('en-US') @@ -69,6 +70,8 @@ export function SavedWorldStudio({ title, client, world, onSummary, onProgress, const { content, pending } = useTerrainStream(tileSource, COARSEST_SAVED_LEVEL, focus, layer, style, tell) const reading = looking || pending > 0 const tileWork = useRef(new PendingWork()) + const showsStudioWorld = chosen !== null && chosen.id === ownWorldAmong(worlds, world)?.id + const spotActions = useSpotActions(client, tell, showsStudioWorld) useEffect(() => { const completion = tileWork.current.completion(pending) @@ -109,7 +112,7 @@ export function SavedWorldStudio({ title, client, world, onSummary, onProgress, } > - + {reading && chosen !== null &&
Reading {chosen.name}
} {!reading && chosen !== null && start === null &&
Nothing finished is saved in {chosen.name}
} diff --git a/studio/src/renderer/src/studio/SceneViewport.tsx b/studio/src/renderer/src/studio/SceneViewport.tsx index ad7d996a3..b7c7fc644 100644 --- a/studio/src/renderer/src/studio/SceneViewport.tsx +++ b/studio/src/renderer/src/studio/SceneViewport.tsx @@ -1,9 +1,15 @@ -import { useEffect, useRef } from 'react' -import { Box3, MOUSE, PerspectiveCamera, Ray, Raycaster, Scene, Sphere, Vector2, Vector3, WebGLRenderer, type Object3D } from 'three' +import { useEffect, useRef, useState } from 'react' +import { ContextMenu, ContextMenuContent, ContextMenuTrigger } from '@/components/ui/context-menu' +import { Box3, ColorManagement, LinearSRGBColorSpace, MOUSE, PerspectiveCamera, Ray, Raycaster, Scene, Sphere, Vector2, Vector3, WebGLRenderer, type Object3D } from 'three' import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js' import type { SightView } from '../scene/cameraSight' import { surfaceAlong } from '../scene/surfacePick' +// Colours are worked out as Minecraft and v3e do, on the values a screen shows: a texture times its tint times the light +// on its face. Left to manage colours, three.js would take those values for linear light and encode them again, which +// pales every colour and flattens the shading. +ColorManagement.enabled = false + const FIELD_OF_VIEW_DEGREES = 45 // Looking down at the scene from the south east, as v3e's object view opens. const VIEW_DIRECTION = new Vector3(1, 0.8, 1.2).normalize() @@ -22,8 +28,16 @@ const LOWEST_OVER_GROUND_RADIANS = Math.PI / 2 - 0.05 const TURNS_ON_DRAG = { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.PAN, RIGHT: MOUSE.PAN } const MOVES_ON_DRAG = { LEFT: MOUSE.PAN, MIDDLE: MOUSE.ROTATE, RIGHT: MOUSE.ROTATE } +const LEFT_BUTTON = 0 +const RIGHT_BUTTON = 2 + function picks(event: PointerEvent): boolean { - return event.button === 0 && !event.shiftKey && !event.ctrlKey && !event.metaKey + return event.button === LEFT_BUTTON && !event.shiftKey && !event.ctrlKey && !event.metaKey +} + +// As on the map: a right click, or a click while holding Ctrl. +function asksAboutSpot(event: PointerEvent): boolean { + return event.button === RIGHT_BUTTON || (event.button === LEFT_BUTTON && (event.ctrlKey || event.metaKey)) } /** The camera of a viewport, for content that draws only what the camera looks at. */ @@ -57,6 +71,23 @@ interface SceneViewportProps { framing?: unknown /** Called when the content is clicked, not dragged. */ onPick?(picked: PickedSurface): void + /** What a spot on the content offers, as the map does for a spot on it. */ + spotActions?: SpotActions +} + +export interface SpotActions { + /** Called when a spot is clicked while holding Ctrl. */ + onCtrlClick(spot: Vector3): void + /** The items of the menu a right click on a spot opens. */ + menuItems(spot: Vector3): React.ReactNode +} + +/** A spot the user asked about, and where on the screen they did. */ +interface AskedSpot { + spot: Vector3 + gesture: 'ctrlClick' | 'rightClick' + clientX: number + clientY: number } /** @@ -64,9 +95,12 @@ interface SceneViewportProps { * turns on a right drag. Either turns around what is in the middle, and scrolling comes closer to the cursor. The * camera stops with the mouse, and the view is drawn only when it changes. */ -export function SceneViewport({ content, framing, onPick }: SceneViewportProps): React.JSX.Element { +export function SceneViewport({ content, framing, onPick, spotActions }: SceneViewportProps): React.JSX.Element { const host = useRef(null) const stage = useRef(null) + const [menuSpot, setMenuSpot] = useState(null) + const latestSpotActions = useRef(spotActions) + latestSpotActions.current = spotActions useEffect(() => { const created = new Stage(host.current!) @@ -81,7 +115,48 @@ export function SceneViewport({ content, framing, onPick }: SceneViewportProps): useEffect(() => stage.current?.frameShown(), [framing]) useEffect(() => stage.current?.onPick(onPick ?? null), [onPick]) - return
+ const offersSpotActions = spotActions !== undefined + useEffect(() => { + if (!offersSpotActions) { + return + } + stage.current?.onSpotAsked((asked) => { + if (asked.gesture === 'ctrlClick') { + latestSpotActions.current?.onCtrlClick(asked.spot) + return + } + setMenuSpot(asked.spot) + openMenuAt(host.current!, asked.clientX, asked.clientY) + }) + return () => stage.current?.onSpotAsked(null) + }, [offersSpotActions]) + useEffect(() => keepPressFromOpeningMenu(host.current!), []) + + return ( + !open && setMenuSpot(null)}> + +
+ + {menuSpot !== null && spotActions?.menuItems(menuSpot)} + + ) +} + +// A right press turns the view, so the menu waits for a right click that did not: the browser's own request for a menu, +// which comes with the press, is kept from the menu, and the viewport asks for it itself. +function keepPressFromOpeningMenu(host: HTMLElement): () => void { + const swallow = (event: MouseEvent): void => { + if (event.isTrusted) { + event.preventDefault() + event.stopPropagation() + } + } + host.addEventListener('contextmenu', swallow, { capture: true }) + return () => host.removeEventListener('contextmenu', swallow, { capture: true }) +} + +function openMenuAt(host: HTMLElement, clientX: number, clientY: number): void { + host.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true, clientX, clientY })) } /** The renderer, camera and controls of one viewport. What it shows belongs to whoever built it, who frees it. */ @@ -99,8 +174,11 @@ class Stage { private frameRequested = false private pickListener: ((picked: PickedSurface) => void) | null = null private pressedAt: { x: number; y: number } | null = null + private spotListener: ((asked: AskedSpot) => void) | null = null + private spotPressedAt: { x: number; y: number } | null = null constructor(private readonly host: HTMLDivElement) { + this.renderer.outputColorSpace = LinearSRGBColorSpace this.renderer.setPixelRatio(window.devicePixelRatio) this.renderer.setClearAlpha(0) host.appendChild(this.renderer.domElement) @@ -109,9 +187,13 @@ class Stage { this.navigateAs(false) this.renderer.domElement.addEventListener('pointerdown', (event) => { this.pressedAt = picks(event) ? { x: event.clientX, y: event.clientY } : null + this.spotPressedAt = asksAboutSpot(event) ? { x: event.clientX, y: event.clientY } : null this.pivotOnSurfaceInMiddle() }) - this.renderer.domElement.addEventListener('pointerup', (event) => this.pickIfClicked(event)) + this.renderer.domElement.addEventListener('pointerup', (event) => { + this.pickIfClicked(event) + this.askAboutSpotIfClicked(event) + }) this.controls.addEventListener('change', () => { this.fitClipToOrbit() this.notifyMoved() @@ -205,13 +287,41 @@ class Stage { if (Math.hypot(event.clientX - pressed.x, event.clientY - pressed.y) > CLICK_SLOP_PIXELS) { return } + this.pickListener(this.surfaceUnder(event)) + } + + onSpotAsked(listener: ((asked: AskedSpot) => void) | null): void { + this.spotListener = listener + } + + private askAboutSpotIfClicked(event: PointerEvent): void { + const pressed = this.spotPressedAt + this.spotPressedAt = null + if (pressed === null || this.spotListener === null) { + return + } + if (Math.hypot(event.clientX - pressed.x, event.clientY - pressed.y) > CLICK_SLOP_PIXELS) { + return + } + const surface = this.surfaceUnder(event) + if (surface === null) { + return + } + const gesture = event.button === RIGHT_BUTTON ? 'rightClick' : 'ctrlClick' + this.spotListener({ spot: surface.point, gesture, clientX: event.clientX, clientY: event.clientY }) + } + + private surfaceUnder(event: PointerEvent): PickedSurface { + if (this.shown === null) { + return null + } const bounds = this.renderer.domElement.getBoundingClientRect() const pointer = new Vector2(((event.clientX - bounds.left) / bounds.width) * 2 - 1, -((event.clientY - bounds.top) / bounds.height) * 2 + 1) const caster = new Raycaster() this.camera.updateMatrixWorld() caster.setFromCamera(pointer, this.camera) const point = surfaceAlong(this.shown, caster.ray, this.camera.far) - this.pickListener(point === null ? null : { point, direction: caster.ray.direction.clone() }) + return point === null ? null : { point, direction: caster.ray.direction.clone() } } // The pivot slides along the line of sight, so the picture stays put while turning now goes around what is there, diff --git a/studio/src/renderer/src/studio/StudioToolbar.tsx b/studio/src/renderer/src/studio/StudioToolbar.tsx index cb7c3d614..f6b4c9e98 100644 --- a/studio/src/renderer/src/studio/StudioToolbar.tsx +++ b/studio/src/renderer/src/studio/StudioToolbar.tsx @@ -69,7 +69,7 @@ export function MapTools({ toggles, hasPlayers, onToggle, onRefresh, onResetZoom onToggle('regionBorders')}> - + onToggle('shading')}> @@ -79,14 +79,14 @@ export function MapTools({ toggles, hasPlayers, onToggle, onRefresh, onResetZoom onToggle('entities')}> - + onToggle('follow')}> - + diff --git a/studio/src/renderer/src/studio/ViewList.tsx b/studio/src/renderer/src/studio/ViewList.tsx index 57dbe8fc4..e0f85a623 100644 --- a/studio/src/renderer/src/studio/ViewList.tsx +++ b/studio/src/renderer/src/studio/ViewList.tsx @@ -13,15 +13,12 @@ const VIEW_ICONS: Record = { regions: 'views/regions', world3d: 'views/world-3d', savedWorld: 'views/saved-world', - landBiomes: 'views/land-biomes', - seaBiomes: 'views/sea-biomes', - caveBiomes: 'views/cave-biomes', 'iris:terrain/palettes': 'views/palettes', 'iris:objects': 'views/objects', 'iris:objects/procedural': 'views/procedural', noise: 'views/noise' } -const FALLBACK_ICON: IdeIconName = 'views/regions' +const FALLBACK_ICON: IdeIconName = 'blocks' /** Inset, because the stripe scrolls and so clips anything drawn outside its buttons. */ const STRIPE_BUTTON = 'flex size-8 shrink-0 items-center justify-center rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:ring-inset' diff --git a/studio/src/renderer/src/studio/WorldStudio3D.tsx b/studio/src/renderer/src/studio/WorldStudio3D.tsx index 93d237982..f35b451f3 100644 --- a/studio/src/renderer/src/studio/WorldStudio3D.tsx +++ b/studio/src/renderer/src/studio/WorldStudio3D.tsx @@ -13,6 +13,7 @@ import { Legend } from './Legend' import { PickInspector } from './PickInspector' import { SceneViewport } from './SceneViewport' import { usePickInspection } from './usePickInspection' +import { useSpotActions } from './useSpotActions' import { HEADER_CHOICE, Panel, ViewIsland } from './Sidebar' import { useGroundInView, useLongPending, useTerrainStream } from './useTerrainStream' @@ -69,6 +70,7 @@ export function WorldStudio3D({ title, client, world, mapArea, packRevision, onS const pickLayer = useMemo(() => ({ view: pickView, preview: null }), [pickView]) const area = useAreaOf(ground) const inspection = usePickInspection(client, pickLayer, area, inspectsPicks, packRevision) + const spotActions = useSpotActions(client, tell, true) useEffect(() => { onSummary(`Around ${NUMBER.format(centre.x)}, ${NUMBER.format(centre.z)}`) @@ -96,7 +98,7 @@ export function WorldStudio3D({ title, client, world, mapArea, packRevision, onS } > - + {sampling && (
Sampling the terrain diff --git a/studio/src/renderer/src/studio/shortcuts.test.ts b/studio/src/renderer/src/studio/shortcuts.test.ts index 7db452335..886158276 100644 --- a/studio/src/renderer/src/studio/shortcuts.test.ts +++ b/studio/src/renderer/src/studio/shortcuts.test.ts @@ -16,7 +16,7 @@ import { type KeyPress } from './shortcuts' -const DEFAULT_VIEWS = ['biomes', 'regions', 'landBiomes', 'seaBiomes', 'caveBiomes'].map((id) => ({ id, label: id })) +const DEFAULT_VIEWS = ['biomes', 'regions', 'world3d', 'savedWorld', 'noise'].map((id) => ({ id, label: id })) const ROWS = shortcutRows(DEFAULT_VIEWS) function press(key: string, modifiers: Partial> = {}): KeyPress { diff --git a/studio/src/renderer/src/studio/shortcuts.ts b/studio/src/renderer/src/studio/shortcuts.ts index ac163e503..29c6e3f32 100644 --- a/studio/src/renderer/src/studio/shortcuts.ts +++ b/studio/src/renderer/src/studio/shortcuts.ts @@ -71,9 +71,6 @@ const VIEW_KEYS: Record = { biomes: '1', regions: '2', world3d: '4', - landBiomes: '5', - seaBiomes: '6', - caveBiomes: '7', 'iris:terrain/palettes': 'p', 'iris:objects': 'o', 'iris:objects/procedural': 't', diff --git a/studio/src/renderer/src/studio/useSpotActions.tsx b/studio/src/renderer/src/studio/useSpotActions.tsx new file mode 100644 index 000000000..f51105d6a --- /dev/null +++ b/studio/src/renderer/src/studio/useSpotActions.tsx @@ -0,0 +1,46 @@ +import { useMemo } from 'react' +import type { Vector3 } from 'three' +import { ContextMenuItem, ContextMenuSeparator } from '@/components/ui/context-menu' +import type { BridgeClient } from '../bridge/BridgeClient' +import type { SpotActions } from './SceneViewport' + +/** + * What a spot of terrain in 3D offers, as a spot on the map does: teleporting there and copying where it is. + * + * @param inStudioWorld whether the terrain is the studio's own world, the only one the server teleports into + */ +export function useSpotActions(client: BridgeClient, tell: (message: string) => void, inStudioWorld: boolean): SpotActions { + return useMemo(() => { + const teleportTo = (spot: Vector3): void => { + const [blockX, blockZ] = [Math.floor(spot.x), Math.floor(spot.z)] + client + .teleport(blockX, blockZ) + .then(() => tell(`Teleporting to ${blockX}, ${blockZ}`)) + .catch((failure: Error) => tell(failure.message)) + } + const copy = (spot: Vector3): void => { + const coordinates = coordinatesOf(spot) + window.studio.copyText(coordinates) + tell(`Copied ${coordinates}`) + } + return { + onCtrlClick: (spot) => inStudioWorld && teleportTo(spot), + menuItems: (spot) => ( + <> + {inStudioWorld && ( + <> + teleportTo(spot)}>Teleport here + + + )} + copy(spot)}>Copy coordinates ({coordinatesOf(spot)}) + + ) + } + }, [client, tell, inStudioWorld]) +} + +// A top face stands where a player's feet do, so its height is the Y to stand at. +function coordinatesOf(spot: Vector3): string { + return `${Math.floor(spot.x)}, ${Math.round(spot.y)}, ${Math.floor(spot.z)}` +} diff --git a/studio/src/renderer/src/studio/useTerrainStream.ts b/studio/src/renderer/src/studio/useTerrainStream.ts index 3c3719e70..5c4430773 100644 --- a/studio/src/renderer/src/studio/useTerrainStream.ts +++ b/studio/src/renderer/src/studio/useTerrainStream.ts @@ -30,6 +30,7 @@ export function useTerrainStream( return () => { created.dispose() setStream(null) + setPending(0) } }, [source, coarsestLevel, focus]) useEffect(() => {