Browse Source

Pixel data loaded from TARGA files

magicbox-1.5.2
MagicBot 1 year ago
parent
commit
9714393538
  1. 23
      src/engine/InterestManagement/HeightMap.java

23
src/engine/InterestManagement/HeightMap.java

@ -40,7 +40,7 @@ public class HeightMap {
public static final HashMap<Integer, HeightMap> heightmapByLoadNum = new HashMap<>(); public static final HashMap<Integer, HeightMap> heightmapByLoadNum = new HashMap<>();
public static final HashMap<Integer, byte[][]> _pixelData = new HashMap<>(); public static final HashMap<String, int[][]> _pixelData = new HashMap<>();
// Heightmap data for all zones. // Heightmap data for all zones.
public static float SCALEVALUE = 1.0f / 255; public static float SCALEVALUE = 1.0f / 255;
@ -310,7 +310,7 @@ public class HeightMap {
Logger.info(HeightMap.heightmapByLoadNum.size() + " Heightmaps cached."); Logger.info(HeightMap.heightmapByLoadNum.size() + " Heightmaps cached.");
// Load pixel data // Load pixel data for heightmaps
try (Stream<Path> filePathStream = Files.walk(Paths.get(ConfigManager.DEFAULT_DATA_DIR + "heightmaps/TARGA/"))) { try (Stream<Path> filePathStream = Files.walk(Paths.get(ConfigManager.DEFAULT_DATA_DIR + "heightmaps/TARGA/"))) {
filePathStream.forEach(filePath -> { filePathStream.forEach(filePath -> {
@ -320,7 +320,24 @@ public class HeightMap {
try { try {
BufferedImage heightmapImage = ImageIO.read(imageFile); BufferedImage heightmapImage = ImageIO.read(imageFile);
int width = heightmapImage.getWidth();
// Generate pixel for this heightmap. RPG channels are all the same
// in this greyscale TGA heightmap. We will choose red.
int[][] colorData = new int[heightmapImage.getWidth()][heightmapImage.getHeight()];
for (int y = 0; y < heightmapImage.getHeight(); y++) {
for (int x = 0; x < heightmapImage.getWidth(); x++) {
Color color = new Color(heightmapImage.getRGB(x, y));
colorData[x][y] = color.getRed();
}
}
// Insert color data into lookup table
_pixelData.put(imageFile.getName().substring(0, imageFile.getName().lastIndexOf(".")), colorData);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

Loading…
Cancel
Save