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

Use y-clipping settings from the map view when creating a new scene or loading chunks from it #1770

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
8 changes: 3 additions & 5 deletions chunky/src/java/se/llbit/chunky/renderer/scene/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -3073,17 +3073,15 @@ public Collection<ChunkPosition> getChunks() {
}

/**
* Clears the reset reason and returns the previous reason.
* Get the reset reason.
* @return the current reset reason
*/
public synchronized ResetReason getResetReason() {
public ResetReason getResetReason() {
return resetReason;
}

public void setResetReason(ResetReason resetReason) {
if (this.resetReason != ResetReason.SCENE_LOADED) {
this.resetReason = resetReason;
}
this.resetReason = resetReason;
}

public void importMaterials() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,14 @@ public void saveScene(SceneIOProvider ioContext, Scene scene) throws Interrupted

@Override public void loadFreshChunks(World world, Collection<ChunkPosition> chunksToLoad) {
synchronized (scene) {
int yClipMin = scene.getYClipMin();
int yClipMax = scene.getYClipMax();
scene.clear();
scene.loadChunks(taskTracker, world, chunksToLoad);
scene.resetScene(null, context.getChunky().getSceneFactory());
scene.setYClipMin(yClipMin);
scene.setYClipMax(yClipMax);
context.setSceneDirectory(new File(context.getChunky().options.sceneDir, scene.name));
scene.loadChunks(taskTracker, world, chunksToLoad);
scene.refresh();
scene.setResetReason(ResetReason.SCENE_LOADED);
scene.setRenderMode(RenderMode.PREVIEW);
Expand All @@ -253,19 +257,19 @@ public void saveScene(SceneIOProvider ioContext, Scene scene) throws Interrupted
if (prevChunkCount == 0) {
scene.moveCameraToCenter();
}
scene.refresh();
scene.setResetReason(ResetReason.SCENE_LOADED);
scene.setRenderMode(RenderMode.PREVIEW);
scene.refresh();
}
onChunksLoaded.run();
}

@Override public void reloadChunks() {
synchronized (scene) {
scene.reloadChunks(taskTracker);
scene.refresh();
scene.setResetReason(ResetReason.SCENE_LOADED);
scene.setRenderMode(RenderMode.PREVIEW);
scene.refresh();
}
onChunksLoaded.run();
}
Expand Down
14 changes: 10 additions & 4 deletions chunky/src/java/se/llbit/chunky/ui/ChunkMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,22 @@ public ChunkMap(WorldMapLoader loader, ChunkyFxController controller,
newScene.setGraphic(new ImageView(Icon.sky.fxImage()));
newScene.setOnAction(event -> {
SceneManager sceneManager = controller.getRenderController().getSceneManager();
sceneManager
.loadFreshChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelection());
sceneManager.getSceneProvider().withEditSceneProtected(scene -> {
scene.setYClipMin(mapView.getYMin());
scene.setYClipMax(mapView.getYMax());
});
sceneManager.loadFreshChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelection());
});
newScene.setDisable(chunkSelection.isEmpty());

MenuItem loadSelection = new MenuItem("Load selected chunks");
loadSelection.setOnAction(event -> {
SceneManager sceneManager = controller.getRenderController().getSceneManager();
sceneManager
.loadChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelection());
sceneManager.getSceneProvider().withEditSceneProtected(scene -> {
scene.setYClipMin(mapView.getYMin());
scene.setYClipMax(mapView.getYMax());
});
sceneManager.loadChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelection());
});
loadSelection.setDisable(chunkSelection.isEmpty());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ public GeneralTab() throws IOException {
canvasSizeInput.setSize(scene.canvasConfig.getCropWidth(), scene.canvasConfig.getCropHeight());
}

@Override
public void onChunksLoaded() {
yMin.set(scene.getYClipMin());
yMax.set(scene.getYClipMax());
}

@Override public String getTabTitle() {
return "Scene";
}
Expand Down