|
|
@ -103,31 +103,38 @@ public enum MapLoader { |
|
|
|
if (Files.isRegularFile(filePath)) { |
|
|
|
if (Files.isRegularFile(filePath)) { |
|
|
|
File imageFile = filePath.toFile(); |
|
|
|
File imageFile = filePath.toFile(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BufferedImage heightmapImage; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
BufferedImage heightmapImage = ImageIO.read(imageFile); |
|
|
|
heightmapImage = ImageIO.read(imageFile); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Generate pixel data for this heightmap. RPG channels are all the same
|
|
|
|
int fileName = Integer.parseInt(imageFile.getName().substring(0, imageFile.getName().lastIndexOf("."))); |
|
|
|
// in this greyscale TGA heightmap. We will choose red.
|
|
|
|
boolean singleBandRaster = heightmapImage.getRaster().getNumBands() == 1; |
|
|
|
|
|
|
|
int color; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Generate pixel data for this heightmap.
|
|
|
|
|
|
|
|
|
|
|
|
short[][] colorData = new short[heightmapImage.getWidth()][heightmapImage.getHeight()]; |
|
|
|
short[][] colorData = new short[heightmapImage.getWidth()][heightmapImage.getHeight()]; |
|
|
|
|
|
|
|
|
|
|
|
for (int y = 0; y < heightmapImage.getHeight(); y++) |
|
|
|
for (int y = 0; y < heightmapImage.getHeight(); y++) |
|
|
|
for (int x = 0; x < heightmapImage.getWidth(); x++) { |
|
|
|
for (int x = 0; x < heightmapImage.getWidth(); x++) { |
|
|
|
|
|
|
|
|
|
|
|
Color color = new Color(heightmapImage.getRGB(x, y)); |
|
|
|
if (singleBandRaster) |
|
|
|
colorData[x][y] = (short) color.getRed(); |
|
|
|
color = heightmapImage.getRaster().getSample(x, y, 0); |
|
|
|
} |
|
|
|
else |
|
|
|
|
|
|
|
color = new Color(heightmapImage.getRGB(x, y)).getRed(); |
|
|
|
|
|
|
|
|
|
|
|
// Insert color data into lookup table
|
|
|
|
colorData[x][y] = (short) color; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int heightMapID = Integer.parseInt(imageFile.getName().substring(0, imageFile.getName().lastIndexOf("."))); |
|
|
|
// Add pixel for this TGA image into the collection
|
|
|
|
Terrain._heightmap_pixel_cache.put(heightMapID, colorData); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
Terrain._heightmap_pixel_cache.put(fileName, colorData); |
|
|
|
Logger.error(e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); // Try with resources block
|
|
|
|
}); // Try with resources block
|
|
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|