use of net.runelite.cache.region.Region in project runelite by runelite.
the class MapImageDumper method drawMap.
private void drawMap(BufferedImage image, int z) {
for (Region region : regionLoader.getRegions()) {
int baseX = region.getBaseX();
int baseY = region.getBaseY();
// to pixel X
int drawBaseX = baseX - regionLoader.getLowestX().getBaseX();
// to pixel Y. top most y is 0, but the top most
// region has the greatest y, so invert
int drawBaseY = regionLoader.getHighestY().getBaseY() - baseY;
drawMap(image, drawBaseX, drawBaseY, z, region);
}
}
use of net.runelite.cache.region.Region in project runelite by runelite.
the class MapImageDumperTest method dumpRegions.
@Test
@Ignore
public void dumpRegions() throws Exception {
File base = StoreLocation.LOCATION, outDir = folder.newFolder();
try (Store store = new Store(base)) {
store.load();
RegionLoader regionLoader = new RegionLoader(store);
regionLoader.loadRegions();
MapImageDumper dumper = new MapImageDumper(store);
dumper.load();
int z = 0;
for (Region region : regionLoader.getRegions()) {
File imageFile = new File(outDir, "img-" + z + "-" + region.getRegionID() + ".png");
BufferedImage image = dumper.drawRegion(region, z);
ImageIO.write(image, "png", imageFile);
}
}
}
use of net.runelite.cache.region.Region in project runelite by runelite.
the class ModelViewer method main.
public static void main(String[] args) throws Exception {
Options options = new Options();
options.addOption(null, "npcdir", true, "npc directory");
options.addOption(null, "mapdir", true, "maps directory");
options.addOption(null, "objectdir", true, "objects directory");
options.addOption(null, "npc", true, "npc to render");
options.addOption(null, "object", true, "object to render");
options.addOption(null, "model", true, "model to render");
options.addOption(null, "map", true, "map region to render");
options.addOption(null, "kits", true, "kits to render");
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);
String npcdir = cmd.getOptionValue("npcdir");
String mapdir = cmd.getOptionValue("mapdir");
String objectdir = cmd.getOptionValue("objectdir");
NpcDefinition npcdef = null;
ObjectDefinition objdef = null;
List<ModelDefinition> models = new ArrayList<>();
Region region = null;
if (cmd.hasOption("model")) {
// render model
String model = cmd.getOptionValue("model");
ModelDefinition md = ModelManager.getModel(Integer.parseInt(model), null, null);
models.add(md);
}
if (cmd.hasOption("npc")) {
String npc = cmd.getOptionValue("npc");
try (FileInputStream fin = new FileInputStream(npcdir + "/" + npc + ".json")) {
npcdef = new Gson().fromJson(new InputStreamReader(fin), NpcDefinition.class);
}
for (int model : npcdef.models) {
ModelDefinition md = ModelManager.getModel(model, null, null);
models.add(md);
}
}
if (cmd.hasOption("object")) {
String obj = cmd.getOptionValue("object");
try (FileInputStream fin = new FileInputStream(objectdir + "/" + obj + ".json")) {
objdef = new Gson().fromJson(new InputStreamReader(fin), ObjectDefinition.class);
}
for (int model : objdef.getObjectModels()) {
ModelDefinition md = ModelManager.getModel(model, null, null);
models.add(md);
}
}
if (cmd.hasOption("map")) {
String map = cmd.getOptionValue("map");
String[] s = map.split(",");
int x = Integer.parseInt(s[0]), y = Integer.parseInt(s[1]);
region = new Region(x, y);
MapLoader mapLoader = new MapLoader();
LocationsLoader locationsLoader = new LocationsLoader();
try (FileInputStream fin = new FileInputStream(mapdir + "/m" + x + "_" + y + ".dat")) {
byte[] b = IOUtils.toByteArray(fin);
MapDefinition mapDef = mapLoader.load(x, y, b);
region.loadTerrain(mapDef);
}
try (FileInputStream fin = new FileInputStream(mapdir + "/l" + x + "_" + y + ".dat")) {
byte[] b = IOUtils.toByteArray(fin);
LocationsDefinition locDef = locationsLoader.load(x, y, b);
region.loadLocations(locDef);
} catch (FileNotFoundException ex) {
logger.info("No landscape file for {},{}", x, y);
}
loadUnderlays();
loadOverlays();
}
if (cmd.hasOption("kits")) {
String kits = cmd.getOptionValue("kits");
Integer[] kitIds = Arrays.stream(kits.split(",")).map(s -> Integer.parseInt(s)).toArray(Integer[]::new);
for (int kitId : kitIds) {
KitDefinition kit = KitManager.getKit(kitId);
for (int model : kit.modelIds) {
ModelDefinition md = ModelManager.getModel(model, null, null);
models.add(md);
}
}
}
Display.setDisplayMode(new DisplayMode(800, 600));
Display.setTitle("Model Viewer");
Display.setInitialBackground((float) Color.gray.getRed() / 255f, (float) Color.gray.getGreen() / 255f, (float) Color.gray.getBlue() / 255f);
Display.create();
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
double aspect = 1;
// near should be chosen as far into the scene as possible
double near = 1;
double far = 10000;
// 1 gives you a 90° field of view. It's tan(fov_angle)/2.
double fov = 1;
GL11.glFrustum(-aspect * near * fov, aspect * near * fov, -fov, fov, near, far);
GL11.glPopMatrix();
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glCullFace(GL11.GL_BACK);
GL11.glEnable(GL11.GL_CULL_FACE);
long last = 0;
Camera camera = new Camera();
while (!Display.isCloseRequested()) {
// Clear the screen and depth buffer
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
for (ModelDefinition def : models) {
short[] recolourToFind = null, recolourToReplace = null;
if (npcdef != null) {
recolourToFind = npcdef.recolorToFind;
recolourToReplace = npcdef.recolorToReplace;
}
if (objdef != null) {
recolourToFind = objdef.getRecolorToFind();
recolourToReplace = objdef.getRecolorToReplace();
}
drawModel(def, recolourToFind, recolourToReplace);
}
drawRegion(region);
Display.update();
// fps
Display.sync(50);
long delta = System.currentTimeMillis() - last;
last = System.currentTimeMillis();
camera.acceptInput(delta);
camera.apply();
}
Display.destroy();
}
use of net.runelite.cache.region.Region in project runelite by runelite.
the class HeightMapDumper method draw.
private void draw(BufferedImage image, int z) {
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
for (Region region : regionLoader.getRegions()) {
int baseX = region.getBaseX();
int baseY = region.getBaseY();
// to pixel X
int drawBaseX = baseX - regionLoader.getLowestX().getBaseX();
// to pixel Y. top most y is 0, but the top most
// region has the greatest y, so invert
int drawBaseY = regionLoader.getHighestY().getBaseY() - baseY;
for (int x = 0; x < Region.X; ++x) {
int drawX = drawBaseX + x;
for (int y = 0; y < Region.Y; ++y) {
int drawY = drawBaseY + (Region.Y - 1 - y);
int height = region.getTileHeight(z, x, y);
if (height > max) {
max = height;
}
if (height < min) {
min = height;
}
int rgb = toColor(height);
drawMapSquare(image, drawX, drawY, rgb);
}
}
}
System.out.println("max " + max);
System.out.println("min " + min);
}
use of net.runelite.cache.region.Region in project runelite by runelite.
the class MapImageDumper method drawMap.
private void drawMap(int[][] pixels, Region region, int z) {
int baseX = region.getBaseX();
int baseY = region.getBaseY();
int len = Region.X + BLEND * 2;
int[] hues = new int[len];
int[] sats = new int[len];
int[] light = new int[len];
int[] mul = new int[len];
int[] num = new int[len];
boolean hasLeftRegion = regionLoader.findRegionForWorldCoordinates(baseX - 1, baseY) != null;
boolean hasRightRegion = regionLoader.findRegionForWorldCoordinates(baseX + Region.X, baseY) != null;
boolean hasUpRegion = regionLoader.findRegionForWorldCoordinates(baseX, baseY + Region.Y) != null;
boolean hasDownRegion = regionLoader.findRegionForWorldCoordinates(baseX, baseY - 1) != null;
for (int xi = (hasLeftRegion ? -BLEND * 2 : -BLEND); xi < Region.X + (hasRightRegion ? BLEND * 2 : BLEND); ++xi) {
for (int yi = (hasDownRegion ? -BLEND : 0); yi < Region.Y + (hasUpRegion ? BLEND : 0); ++yi) {
int xr = xi + BLEND;
if (xr >= (hasLeftRegion ? -BLEND : 0) && xr < Region.X + (hasRightRegion ? BLEND : 0)) {
Region r = regionLoader.findRegionForWorldCoordinates(baseX + xr, baseY + yi);
if (r != null) {
int underlayId = r.getUnderlayId(z, convert(xr), convert(yi));
if (underlayId > 0) {
UnderlayDefinition underlay = findUnderlay(underlayId - 1);
hues[yi + BLEND] += underlay.getHue();
sats[yi + BLEND] += underlay.getSaturation();
light[yi + BLEND] += underlay.getLightness();
mul[yi + BLEND] += underlay.getHueMultiplier();
num[yi + BLEND]++;
}
}
}
int xl = xi - BLEND;
if (xl >= (hasLeftRegion ? -BLEND : 0) && xl < Region.X + (hasRightRegion ? BLEND : 0)) {
Region r = regionLoader.findRegionForWorldCoordinates(baseX + xl, baseY + yi);
if (r != null) {
int underlayId = r.getUnderlayId(z, convert(xl), convert(yi));
if (underlayId > 0) {
UnderlayDefinition underlay = findUnderlay(underlayId - 1);
hues[yi + BLEND] -= underlay.getHue();
sats[yi + BLEND] -= underlay.getSaturation();
light[yi + BLEND] -= underlay.getLightness();
mul[yi + BLEND] -= underlay.getHueMultiplier();
num[yi + BLEND]--;
}
}
}
}
if (xi >= 0 && xi < Region.X) {
int runningHues = 0;
int runningSat = 0;
int runningLight = 0;
int runningMultiplier = 0;
int runningNumber = 0;
for (int yi = (hasDownRegion ? -BLEND * 2 : -BLEND); yi < Region.Y + (hasUpRegion ? BLEND * 2 : BLEND); ++yi) {
int yu = yi + BLEND;
if (yu >= (hasDownRegion ? -BLEND : 0) && yu < Region.Y + (hasUpRegion ? BLEND : 0)) {
runningHues += hues[yu + BLEND];
runningSat += sats[yu + BLEND];
runningLight += light[yu + BLEND];
runningMultiplier += mul[yu + BLEND];
runningNumber += num[yu + BLEND];
}
int yd = yi - BLEND;
if (yd >= (hasDownRegion ? -BLEND : 0) && yd < Region.Y + (hasUpRegion ? BLEND : 0)) {
runningHues -= hues[yd + BLEND];
runningSat -= sats[yd + BLEND];
runningLight -= light[yd + BLEND];
runningMultiplier -= mul[yd + BLEND];
runningNumber -= num[yd + BLEND];
}
if (yi >= 0 && yi < Region.Y) {
Region r = regionLoader.findRegionForWorldCoordinates(baseX + xi, baseY + yi);
if (r != null) {
int underlayId = r.getUnderlayId(z, convert(xi), convert(yi));
int overlayId = r.getOverlayId(z, convert(xi), convert(yi));
if (underlayId > 0 || overlayId > 0) {
int underlayHsl = -1;
if (underlayId > 0) {
int avgHue = runningHues * 256 / runningMultiplier;
int avgSat = runningSat / runningNumber;
int avgLight = runningLight / runningNumber;
if (avgLight < 0) {
avgLight = 0;
} else if (avgLight > 255) {
avgLight = 255;
}
underlayHsl = packHsl(avgHue, avgSat, avgLight);
}
int underlayRgb = 0;
if (underlayHsl != -1) {
int var0 = method1792(underlayHsl, 96);
underlayRgb = colorPalette[var0];
}
int shape, rotation;
Integer overlayRgb = null;
if (overlayId == 0) {
shape = rotation = 0;
} else {
shape = r.getOverlayPath(z, convert(xi), convert(yi)) + 1;
rotation = r.getOverlayRotation(z, convert(xi), convert(yi));
OverlayDefinition overlayDefinition = findOverlay(overlayId - 1);
int overlayTexture = overlayDefinition.getTexture();
int rgb;
if (overlayTexture >= 0) {
rgb = rsTextureProvider.getAverageTextureRGB(overlayTexture);
} else if (overlayDefinition.getRgbColor() == 0xFF_00FF) {
rgb = -2;
} else {
// randomness added here
int overlayHsl = packHsl(overlayDefinition.getHue(), overlayDefinition.getSaturation(), overlayDefinition.getLightness());
rgb = overlayHsl;
}
overlayRgb = 0;
if (rgb != -2) {
int var0 = adjustHSLListness0(rgb, 96);
overlayRgb = colorPalette[var0];
}
if (overlayDefinition.getSecondaryRgbColor() != -1) {
int hue = overlayDefinition.getOtherHue();
int sat = overlayDefinition.getOtherSaturation();
int olight = overlayDefinition.getOtherLightness();
rgb = packHsl(hue, sat, olight);
int var0 = adjustHSLListness0(rgb, 96);
overlayRgb = colorPalette[var0];
}
}
if (shape == 0) {
int drawX = xi;
int drawY = Region.Y - 1 - yi;
if (underlayRgb != 0) {
drawMapSquare(pixels, drawX, drawY, underlayRgb);
}
} else if (shape == 1) {
int drawX = xi;
int drawY = Region.Y - 1 - yi;
drawMapSquare(pixels, drawX, drawY, overlayRgb);
} else {
int drawX = xi * MAP_SCALE;
int drawY = (Region.Y - 1 - yi) * MAP_SCALE;
int[] tileShapes = TILE_SHAPE_2D[shape];
int[] tileRotations = TILE_ROTATION_2D[rotation];
if (underlayRgb != 0) {
int rotIdx = 0;
for (int i = 0; i < Region.Z; ++i) {
int p1 = tileShapes[tileRotations[rotIdx++]] == 0 ? underlayRgb : overlayRgb;
int p2 = tileShapes[tileRotations[rotIdx++]] == 0 ? underlayRgb : overlayRgb;
int p3 = tileShapes[tileRotations[rotIdx++]] == 0 ? underlayRgb : overlayRgb;
int p4 = tileShapes[tileRotations[rotIdx++]] == 0 ? underlayRgb : overlayRgb;
pixels[drawX + 0][drawY + i] = p1;
pixels[drawX + 1][drawY + i] = p2;
pixels[drawX + 2][drawY + i] = p3;
pixels[drawX + 3][drawY + i] = p4;
}
} else {
int rotIdx = 0;
for (int i = 0; i < Region.Z; ++i) {
int p1 = tileShapes[tileRotations[rotIdx++]];
int p2 = tileShapes[tileRotations[rotIdx++]];
int p3 = tileShapes[tileRotations[rotIdx++]];
int p4 = tileShapes[tileRotations[rotIdx++]];
if (p1 != 0) {
pixels[drawX + 0][drawY + i] = overlayRgb;
}
if (p2 != 0) {
pixels[drawX + 1][drawY + i] = overlayRgb;
}
if (p3 != 0) {
pixels[drawX + 2][drawY + i] = overlayRgb;
}
if (p4 != 0) {
pixels[drawX + 3][drawY + i] = overlayRgb;
}
}
}
}
}
}
}
}
}
}
}
Aggregations