forked from MagicBane/Server
Pixel data loaded from TARGA files
This commit is contained in:
@@ -40,7 +40,7 @@ public class HeightMap {
|
||||
|
||||
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.
|
||||
public static float SCALEVALUE = 1.0f / 255;
|
||||
@@ -310,7 +310,7 @@ public class HeightMap {
|
||||
|
||||
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/"))) {
|
||||
filePathStream.forEach(filePath -> {
|
||||
@@ -320,7 +320,24 @@ public class HeightMap {
|
||||
|
||||
try {
|
||||
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) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user