Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChunkyCloud support #21

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8ff2b7f
Bring back support for the render service.
leMaik Oct 4, 2020
1631246
Remove render jobs after they are done.
leMaik Oct 7, 2020
88b11a8
Fix memory/thread leak when creating scenes for the remote renderer.
leMaik Oct 7, 2020
862f7a0
Implement submitting region files to the render service instead of cr…
leMaik Oct 19, 2020
cc3cc96
Re-use region files that were already uploaded to the render service.
leMaik Oct 20, 2020
e0277af
Add api keys for the render service.
leMaik Oct 23, 2020
18d89a5
Fix okio response body leaking warning.
leMaik Nov 19, 2020
2979239
Update okhttp to fix proxy issues.
leMaik Nov 19, 2020
b4733e0
Cancel jobs that failed rendering (e.g. timed out).
leMaik Nov 22, 2020
69fd6af
Drop duplicate method declaration.
leMaik Nov 22, 2020
2cefb07
Ensure that chunks only get added once to a scene.
leMaik Nov 22, 2020
4bce69e
Make local rendering work again.
leMaik Nov 22, 2020
7327d61
Fix texturepacks.
leMaik Dec 17, 2020
0febfef
Put failed tiles back into the tile queue by default.
leMaik Dec 17, 2020
45894db
Redirect Chunky log output to the plugin logger, suppress chunky conf…
leMaik Jan 16, 2021
4d361fd
Fix dependency warning when loading the plugin.
leMaik Jan 16, 2021
8e45f8d
Reduce ChunkyCloud timeouts, ensure that all response bodies are closed.
leMaik Jan 16, 2021
9cbcb19
Fix typo in the readme, explain nested options.
leMaik May 5, 2021
abcef42
Add a ChunkyCloud example configuration.
leMaik May 5, 2021
50f25bd
Fix concurrent modification exception when getting the world path.
leMaik Oct 10, 2021
5d61884
Use Greenfield image in the readme.
leMaik Oct 10, 2021
60bf195
Refactor chunky map and tile implementations to more closely map dynm…
leMaik Oct 10, 2021
e00206b
Update to dynmap 3.2 or later.
leMaik Oct 10, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ The maps can be configured by adding options to the map's section in the `world.
| `chunkyCpuLoad` | Percentage of CPU time to use, per Chunky thread. Note that this only throttles the CPU usage during rendering, not during scene loading or post processing. | 100 |
| `texturepack` | Texturepack path, relative to `plugins/dynmap`. Use this option to specify a texturepack for a map. The texturepack in Dynmap's `configuration.txt` is ignored by ChunkyMap. | _None_ |
| `chunkPadding` | Radius of additional chunks to be loaded around each chunk that is required to render a tile of the map. This can be used to reduce artifacts caused by shadows and reflections. | 0 |
| `requeueFailedTiles` | Put tiles that failed to render back into the tile queue. | true |
| `templateScene` | Path to a Chunky scene file (JSON), relative to `plugins/dynmap`. Use this option to customize the scene that is used for rendering the tiles, e.g. to change the water color. | _None_ |
| `texturepackVersion` | The Minecraft version that should be used as fallback textures | 1.16.2 |
| `denoiser.enabled` | Enable denoising using [Intel Open Image Denoise](https://openimagedenoise.github.io/). Only works on Linux | false |
| `denoiser.albedoSamplesPerPixel` | Samples per pixel for the albedo map. Setting this to 0 will disable the albedo and normal map. | 4 |
| `denoiser.normalSamplesPerPixel` | Samples per pixel for the normal map. Setting this to 0 will disable the normal map. | 4 |
| `denoiser/enabled` | Enable denoising using [Intel Open Image Denoise](https://openimagedenoise.github.io/). Only works on Linux | false |
| `denoiser/albedoSamplesPerPixel` | Samples per pixel for the albedo map. Setting this to 0 will disable the albedo and normal map. | 4 |
| `denoiser/normalSamplesPerPixel` | Samples per pixel for the normal map. Setting this to 0 will disable the normal map. | 4 |
| `chunkycloud/enabled` | Render tiles using the Chunky Cloud render service | false |
| `chunkycloud/apiKey` | API Key for the Chunky Cloud render service | |
| `chunkycloud/initializeLocally` | Generate the octree locally. Less data to upload, faster render times but will use a lot of CPU locally. | true |

:warning: A forward slash (`/`) in the option name means that the right part is a nested option and needs to be put into the next line and indented properly. Take a look at the examples below.

## Example configurations

Expand Down Expand Up @@ -99,6 +105,25 @@ perspectives:
maximumheight: 100 # the bedrock layer is at 127
```

### Rendering ChunkyMap on ChunkyCloud

`plugins/dynmap/worlds.txt`:

```yml
worlds:
- name: world
maps:
- class: de.lemaik.chunkymap.dynmap.ChunkyMap
name: chunky
title: Chunky
perspective: iso_SE_30_hires
samplesPerPixel: 20
chunkycloud:
enabled: true
initializeLocally: false
apiKey: your-secret-api-key
```

### Customizing the look of a map with template scenes

You can change how the map looks by providing a template scene. That can be any Chunky scene (`.json`) file or a partial scene file (i.e. a `.json` file that only contains the values that should be changed). ChunkyMap will import many scene options from the template scene, including the sun position, fog and water configuration.
Expand Down
Binary file modified banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 13 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.lemaik.chunkymap</groupId>
<artifactId>ChunkyMap</artifactId>
<version>2.5.2</version>
<version>2.6.0-pre3</version>

<licenses>
<license>
Expand All @@ -19,7 +17,7 @@
<jdk.version>1.8</jdk.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<chunky.version>2.3.0-30-g82f6ab17</chunky.version>
<chunky.version>2.3.0-32-g9623108f</chunky.version>
</properties>

<repositories>
Expand Down Expand Up @@ -64,16 +62,22 @@
<version>3.2</version>
</dependency>
<dependency>
<!-- this is an older version, but 3.0-SNAPSHOT can't be installed and this works, too -->
<groupId>us.dynmap</groupId>
<artifactId>DynmapCore</artifactId>
<version>2.3</version>
<version>3.2.1</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<!-- downloading fails -->
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.4.1</version>
<version>3.14.9</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down Expand Up @@ -174,4 +178,4 @@
</resource>
</resources>
</build>
</project>
</project>
8 changes: 8 additions & 0 deletions src/main/java/de/lemaik/chunkymap/ChunkyMapPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package de.lemaik.chunkymap;

import de.lemaik.chunkymap.rendering.local.ChunkyLogAdapter;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
Expand All @@ -27,12 +28,19 @@
import java.util.logging.Level;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import se.llbit.log.Log;

/**
* The main class.
*/
public class ChunkyMapPlugin extends JavaPlugin {

@Override
public void onLoad() {
Log.setReceiver(new ChunkyLogAdapter(getLogger()), se.llbit.log.Level.ERROR,
se.llbit.log.Level.WARNING, se.llbit.log.Level.INFO);
}

@Override
public void onEnable() {
Plugin dynmap = getServer().getPluginManager().getPlugin("dynmap");
Expand Down
102 changes: 64 additions & 38 deletions src/main/java/de/lemaik/chunkymap/dynmap/ChunkyMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.lemaik.chunkymap.ChunkyMapPlugin;
import de.lemaik.chunkymap.rendering.Renderer;
import de.lemaik.chunkymap.rendering.local.ChunkyRenderer;
import de.lemaik.chunkymap.rendering.rs.RemoteRenderer;
import de.lemaik.chunkymap.util.MinecraftDownloader;
import java.io.File;
import java.io.FileInputStream;
Expand All @@ -14,16 +15,17 @@
import java.util.logging.Level;
import java.util.stream.Collectors;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okio.BufferedSink;
import okio.Okio;
import org.bukkit.Bukkit;
import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapChunk;
import org.dynmap.DynmapCore;
import org.dynmap.DynmapWorld;
import org.dynmap.MapTile;
import org.dynmap.MapType;
import org.dynmap.hdmap.HDMap;
import org.dynmap.hdmap.HDPerspective;
import org.dynmap.hdmap.IsoHDPerspective;
import org.dynmap.utils.TileFlags;
import se.llbit.chunky.renderer.scene.Scene;
Expand All @@ -41,33 +43,52 @@ public class ChunkyMap extends HDMap {
private final Renderer renderer;
private File defaultTexturepackPath;
private File texturepackPath;
private File worldPath;
private final Object worldPathLock = new Object();
private JsonObject templateScene;
private int chunkPadding;
private final int chunkPadding;
private final boolean requeueFailedTiles;

public ChunkyMap(DynmapCore dynmap, ConfigurationNode config) {
super(dynmap, config);
cameraAdapter = new DynmapCameraAdapter((IsoHDPerspective) getPerspective());
renderer = new ChunkyRenderer(
config.getInteger("samplesPerPixel", 100),
config.getBoolean("denoiser/enabled", false),
config.getInteger("denoiser/albedoSamplesPerPixel", 16),
config.getInteger("denoiser/normalSamplesPerPixel", 16),
config.getInteger("chunkyThreads", 2),
Math.min(100, Math.max(0, config.getInteger("chunkyCpuLoad", 100)))
);
if (config.getBoolean("chunkycloud/enabled", false)) {
renderer = new RemoteRenderer(config.getString("chunkycloud/apiKey", ""),
config.getInteger("samplesPerPixel", 100),
config.getString("texturepack", null),
config.getBoolean("chunkycloud/initializeLocally", true));
if (config.getString("chunkycloud/apiKey", "").isEmpty()) {
ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class).getLogger()
.warning("No ChunkyCloud API Key configured.");
}
} else {
renderer = new ChunkyRenderer(
config.getInteger("samplesPerPixel", 100),
config.getBoolean("denoiser/enabled", false),
config.getInteger("denoiser/albedoSamplesPerPixel", 16),
config.getInteger("denoiser/normalSamplesPerPixel", 16),
config.getInteger("chunkyThreads", 2),
Math.min(100, Math.max(0, config.getInteger("chunkyCpuLoad", 100)))
);
}
chunkPadding = config.getInteger("chunkPadding", 0);
requeueFailedTiles = config.getBoolean("requeueFailedTiles", true);

String texturepackVersion = config.getString("texturepackVersion", DEFAULT_TEXTUREPACK_VERSION);
File texturepackPath = new File(
ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class).getDataFolder(),
texturepackVersion + ".jar");
if (!texturepackPath.exists()) {
if (texturepackPath.exists()) {
defaultTexturepackPath = texturepackPath;
} else {
ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class).getLogger()
.info("Downloading additional textures for Minecraft " + texturepackVersion);
try (Response response = MinecraftDownloader.downloadMinecraft(texturepackVersion).get()) {
try (BufferedSink sink = Okio.buffer(Okio.sink(texturepackPath))) {
sink.writeAll(response.body().source());
}
try (
Response response = MinecraftDownloader.downloadMinecraft(texturepackVersion).get();
ResponseBody body = response.body();
BufferedSink sink = Okio.buffer(Okio.sink(texturepackPath))
) {
sink.writeAll(body.source());
defaultTexturepackPath = texturepackPath;
} catch (IOException | ExecutionException | InterruptedException e) {
ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class).getLogger()
Expand All @@ -77,7 +98,7 @@ public ChunkyMap(DynmapCore dynmap, ConfigurationNode config) {
}

if (config.containsKey("texturepack")) {
texturepackPath = Bukkit.getPluginManager().getPlugin("dynmap").getDataFolder().toPath()
this.texturepackPath = Bukkit.getPluginManager().getPlugin("dynmap").getDataFolder().toPath()
.resolve(config.getString("texturepack"))
.toFile();
} else {
Expand All @@ -103,19 +124,11 @@ public ChunkyMap(DynmapCore dynmap, ConfigurationNode config) {
.log(Level.SEVERE, "Could not read the template scene.", e);
}
}

// texturepacks in chunky are static, so only load them once
if (defaultTexturepackPath != null) {
ChunkyRenderer.loadDefaultTexturepack(defaultTexturepackPath);
}
if (texturepackPath != null) {
ChunkyRenderer.loadTexturepack(texturepackPath);
}
}

@Override
public void addMapTiles(List<MapTile> list, DynmapWorld world, int tx, int ty) {
list.add(new ChunkyMapTile(world, getPerspective(), this, tx, ty));
list.add(new ChunkyMapTile(world, getPerspective(), tx, ty, getBoostZoom()));
}

public List<TileFlags.TileCoord> getTileCoords(DynmapWorld world, int x, int y, int z) {
Expand All @@ -129,25 +142,24 @@ public List<TileFlags.TileCoord> getTileCoords(DynmapWorld world, int minx, int

@Override
public MapTile[] getAdjecentTiles(MapTile tile) {
return getAdjecentTilesOfTile(tile, getPerspective());
}

public static MapTile[] getAdjecentTilesOfTile(MapTile tile, HDPerspective perspective) {
ChunkyMapTile t = (ChunkyMapTile) tile;
DynmapWorld w = t.getDynmapWorld();
int x = t.tileOrdinalX();
int y = t.tileOrdinalY();

return new MapTile[]{
new ChunkyMapTile(w, getPerspective(), this, x - 1, y - 1),
new ChunkyMapTile(w, getPerspective(), this, x - 1, y + 1),
new ChunkyMapTile(w, getPerspective(), this, x + 1, y - 1),
new ChunkyMapTile(w, getPerspective(), this, x + 1, y + 1),
new ChunkyMapTile(w, getPerspective(), this, x, y - 1),
new ChunkyMapTile(w, getPerspective(), this, x + 1, y),
new ChunkyMapTile(w, getPerspective(), this, x, y + 1),
new ChunkyMapTile(w, getPerspective(), this, x - 1, y)};
}

@Override
public List<DynmapChunk> getRequiredChunks(MapTile mapTile) {
return getPerspective().getRequiredChunks(mapTile);
new ChunkyMapTile(w, perspective, x - 1, y - 1, t.boostzoom),
new ChunkyMapTile(w, perspective, x - 1, y + 1, t.boostzoom),
new ChunkyMapTile(w, perspective, x + 1, y - 1, t.boostzoom),
new ChunkyMapTile(w, perspective, x + 1, y + 1, t.boostzoom),
new ChunkyMapTile(w, perspective, x, y - 1, t.boostzoom),
new ChunkyMapTile(w, perspective, x + 1, y, t.boostzoom),
new ChunkyMapTile(w, perspective, x, y + 1, t.boostzoom),
new ChunkyMapTile(w, perspective, x - 1, y, t.boostzoom)};
}

@Override
Expand Down Expand Up @@ -187,9 +199,23 @@ int getChunkPadding() {
return chunkPadding;
}

public boolean getRequeueFailedTiles() {
return requeueFailedTiles;
}

void applyTemplateScene(Scene scene) {
if (this.templateScene != null) {
scene.importFromJson(templateScene);
}
}

File getWorldFolder(DynmapWorld world) {
if (worldPath == null) {
// Fixes a ConcurrentModificationException, see https://github.com/leMaik/ChunkyMap/issues/30
synchronized (worldPathLock) {
worldPath = Bukkit.getWorld(world.getRawName()).getWorldFolder();
}
}
return worldPath;
}
}
Loading