Skip to content

Commit

Permalink
Merge pull request #12 from booleanbyte/HeightRangeSettings
Browse files Browse the repository at this point in the history
Add height range settings for voxel preview
  • Loading branch information
duplexsystem authored Apr 28, 2024
2 parents 5b004ff + 109abe8 commit f928143
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/main/java/com/dfsek/noise/swing/NoisePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,14 @@ private boolean[][][] getNoiseVals3d(long seed) {
double originZ = this.settingsPanel.getOriginZ();

int sampleRes = this.settingsPanel.getVoxelResolution();
boolean[][][] noiseVals = new boolean[sampleRes][sampleRes][sampleRes];
int sampleYMin = this.settingsPanel.getVoxelBottomY();
int sampleYMax = this.settingsPanel.getVoxelTopY();

boolean[][][] noiseVals = new boolean[sampleRes][sampleYMax - sampleYMin][sampleRes];
for (int x = 0; x < noiseVals.length; x++) {
for (int y = 0; y < noiseVals[x].length; y++) {
for(int z = 0; z < (noiseVals[x][y]).length; z++) {
double n = noiseSeeded.noise(seed, x + originX, y, z + originZ);
double n = noiseSeeded.noise(seed, x + originX, y + sampleYMin, z + originZ);
noiseVals[x][y][z] = n > 0;
}
}
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/com/dfsek/noise/swing/NoiseSettingsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class NoiseSettingsPanel extends JPanel {

// Voxel preview settings
private final JSpinner voxelResolution = new JSpinner(new SpinnerNumberModel(128, 0, Integer.MAX_VALUE, 1));
private final JSpinner voxelBottomY = new JSpinner(new SpinnerNumberModel(-64, Integer.MIN_VALUE, Integer.MAX_VALUE, 1));
private final JSpinner voxelTopY = new JSpinner(new SpinnerNumberModel(319, Integer.MIN_VALUE, Integer.MAX_VALUE, 1));

// Color scale presets
private final ColorScale customColorScalePreset = new ColorScale("Custom", false, (float[][]) null);
Expand Down Expand Up @@ -48,6 +50,11 @@ public NoiseSettingsPanel() {
add(new JLabel("Voxel preview resolution: "));
add(voxelResolution);

add(new JLabel("Voxel preview bottom Y: "));
add(voxelBottomY);
add(new JLabel("Voxel preview top Y: "));
add(voxelTopY);

add(new JLabel("Color scale preset: "));
colorScalePresets.setSelectedItem(ColorScale.GRAYSCALE_NORMALIZED);
add(colorScalePresets);
Expand Down Expand Up @@ -104,7 +111,7 @@ public void actionPerformed(ActionEvent e) {
}
});

SwingUtils.makeCompactGrid(this, 7, 2, 10, 10, 10, 10);
SwingUtils.makeCompactGrid(this, 9, 2, 10, 10, 10, 10);
}

public int getSeed() {
Expand All @@ -131,6 +138,14 @@ public int getVoxelResolution() {
return ((Number) voxelResolution.getValue()).intValue();
}

public int getVoxelBottomY() {
return ((Number) voxelBottomY.getValue()).intValue();
}

public int getVoxelTopY() {
return ((Number) voxelTopY.getValue()).intValue();
}

public ColorScale getColorScale() {
ColorScale selection = (ColorScale) colorScalePresets.getSelectedItem();
if (selection == customColorScalePreset) {
Expand Down

0 comments on commit f928143

Please sign in to comment.