Skip to content

Commit

Permalink
Apply single color textures without a restart by making Texture.useAv…
Browse files Browse the repository at this point in the history
…erageColor static.
  • Loading branch information
leMaik committed Jun 3, 2024
1 parent fdffd82 commit 224e827
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public int[] getData() {
}
@Override
public float[] getColor(int x, int y) {
if(empty.usesAverageColor())
if(useAverageColor)
return empty.getAvgColorFlat();
float[] result = new float[4];
boolean shouldOverlay = bookPresentAt(x, y);
Expand Down
17 changes: 7 additions & 10 deletions chunky/src/java/se/llbit/chunky/resources/Texture.java
Original file line number Diff line number Diff line change
Expand Up @@ -1479,12 +1479,13 @@ public class Texture {

public static final Texture armorStand = new Texture();

protected static boolean useAverageColor = PersistentSettings.getSingleColorTextures();

@NotNull protected BitmapImage image;
protected int width;
protected int height;
protected int avgColor;
private float[] avgColorLinear;
private boolean usesAverageColor = false;
private float[] avgColorFlat;

private Image fxImage = null;
Expand All @@ -1499,14 +1500,6 @@ public Texture(String resourceName) {

public Texture(BitmapImage img) {
setTexture(img);
useAverageColor(PersistentSettings.getSingleColorTextures());
}

public void useAverageColor(boolean enable) {
usesAverageColor = enable;
}
public boolean usesAverageColor() {
return usesAverageColor;
}

public void setTexture(Texture texture) {
Expand Down Expand Up @@ -1583,7 +1576,7 @@ public float[] getColor(double u, double v) {
* @return color
*/
public float[] getColor(int x, int y) {
if(usesAverageColor)
if(useAverageColor)
return avgColorFlat;
float[] result = new float[4];
ColorUtil.getRGBAComponentsGammaCorrected(image.data[width*y + x], result);
Expand Down Expand Up @@ -1686,4 +1679,8 @@ public int[] getData() {
public BitmapImage getBitmap() {
return image;
}

public static void setUseAverageColor(boolean useAverageColor) {
Texture.useAverageColor = useAverageColor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import se.llbit.chunky.renderer.RenderController;
import se.llbit.chunky.renderer.scene.Scene;
import se.llbit.chunky.renderer.scene.SceneManager;
import se.llbit.chunky.resources.Texture;
import se.llbit.chunky.ui.IntegerAdjuster;
import se.llbit.chunky.ui.controller.RenderControlsFxController;
import se.llbit.chunky.ui.dialogs.ResourcePackChooser;
Expand Down Expand Up @@ -87,6 +88,7 @@ public void initialize(URL location, ResourceBundle resources) {
singleColorBtn.selectedProperty().addListener((observable, oldValue, newValue) -> {
Scene scene = sceneManager.getScene();
PersistentSettings.setSingleColorTextures(newValue);
Texture.setUseAverageColor(newValue);
scene.refresh();
scene.rebuildBvh();
});
Expand Down

0 comments on commit 224e827

Please sign in to comment.