Search in sources :

Example 6 with ObjectDefinition

use of net.runelite.cache.definitions.ObjectDefinition in project runelite by runelite.

the class ModelViewer method getObject.

private static ObjectDefinition getObject(int id) {
    ObjectDefinition object = objects[id];
    if (object != null) {
        return object;
    }
    try (FileInputStream fin = new FileInputStream("objects/" + id + ".json")) {
        object = new Gson().fromJson(new InputStreamReader(fin), ObjectDefinition.class);
        objects[id] = object;
        return object;
    } catch (IOException ex) {
        logger.warn(null, ex);
        return null;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Gson(com.google.gson.Gson) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 7 with ObjectDefinition

use of net.runelite.cache.definitions.ObjectDefinition 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();
}
Also used : Color(java.awt.Color) Arrays(java.util.Arrays) Location(net.runelite.cache.region.Location) Options(org.apache.commons.cli.Options) GL_TEXTURE_WRAP_T(org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_T) LoggerFactory(org.slf4j.LoggerFactory) GL_TEXTURE_WRAP_S(org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_S) HashMap(java.util.HashMap) Vector3f(net.runelite.cache.models.Vector3f) GL_NEAREST(org.lwjgl.opengl.GL11.GL_NEAREST) GL_TEXTURE_2D(org.lwjgl.opengl.GL11.GL_TEXTURE_2D) ByteBuffer(java.nio.ByteBuffer) Position(net.runelite.cache.region.Position) ArrayList(java.util.ArrayList) DefaultParser(org.apache.commons.cli.DefaultParser) Gson(com.google.gson.Gson) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) CommandLine(org.apache.commons.cli.CommandLine) Region(net.runelite.cache.region.Region) OverlayDefinition(net.runelite.cache.definitions.OverlayDefinition) GL11(org.lwjgl.opengl.GL11) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) TextureDefinition(net.runelite.cache.definitions.TextureDefinition) VertexNormal(net.runelite.cache.models.VertexNormal) Display(org.lwjgl.opengl.Display) Logger(org.slf4j.Logger) BufferedImage(java.awt.image.BufferedImage) CommandLineParser(org.apache.commons.cli.CommandLineParser) UnderlayDefinition(net.runelite.cache.definitions.UnderlayDefinition) GL_TEXTURE_MIN_FILTER(org.lwjgl.opengl.GL11.GL_TEXTURE_MIN_FILTER) LocationsLoader(net.runelite.cache.definitions.loaders.LocationsLoader) IOUtils(org.apache.commons.compress.utils.IOUtils) IOException(java.io.IOException) LocationsDefinition(net.runelite.cache.definitions.LocationsDefinition) FileInputStream(java.io.FileInputStream) InputStreamReader(java.io.InputStreamReader) FileNotFoundException(java.io.FileNotFoundException) MapDefinition(net.runelite.cache.definitions.MapDefinition) List(java.util.List) KitDefinition(net.runelite.cache.definitions.KitDefinition) DisplayMode(org.lwjgl.opengl.DisplayMode) GL_TEXTURE_MAG_FILTER(org.lwjgl.opengl.GL11.GL_TEXTURE_MAG_FILTER) NpcDefinition(net.runelite.cache.definitions.NpcDefinition) GL_CLAMP_TO_EDGE(org.lwjgl.opengl.GL12.GL_CLAMP_TO_EDGE) GL11.glTexParameteri(org.lwjgl.opengl.GL11.glTexParameteri) MapLoader(net.runelite.cache.definitions.loaders.MapLoader) ModelDefinition(net.runelite.cache.definitions.ModelDefinition) Options(org.apache.commons.cli.Options) NpcDefinition(net.runelite.cache.definitions.NpcDefinition) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) MapDefinition(net.runelite.cache.definitions.MapDefinition) KitDefinition(net.runelite.cache.definitions.KitDefinition) CommandLineParser(org.apache.commons.cli.CommandLineParser) LocationsDefinition(net.runelite.cache.definitions.LocationsDefinition) DefaultParser(org.apache.commons.cli.DefaultParser) InputStreamReader(java.io.InputStreamReader) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) LocationsLoader(net.runelite.cache.definitions.loaders.LocationsLoader) FileInputStream(java.io.FileInputStream) DisplayMode(org.lwjgl.opengl.DisplayMode) CommandLine(org.apache.commons.cli.CommandLine) MapLoader(net.runelite.cache.definitions.loaders.MapLoader) ModelDefinition(net.runelite.cache.definitions.ModelDefinition) Region(net.runelite.cache.region.Region)

Example 8 with ObjectDefinition

use of net.runelite.cache.definitions.ObjectDefinition in project runelite by runelite.

the class CacheController method getObject.

@RequestMapping("object/{objectId}")
public ObjectDefinition getObject(@PathVariable int objectId) throws IOException {
    ArchiveEntry archiveEntry = findConfig(ConfigType.OBJECT);
    ArchiveFiles archiveFiles = cacheService.getArchiveFiles(archiveEntry);
    if (archiveFiles == null) {
        throw new NotFoundException();
    }
    FSFile file = archiveFiles.findFile(objectId);
    if (file == null) {
        throw new NotFoundException();
    }
    ObjectDefinition objectdef = new ObjectLoader().load(objectId, file.getContents());
    return objectdef;
}
Also used : ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) NotFoundException(net.runelite.http.service.util.exception.NotFoundException) ArchiveEntry(net.runelite.http.service.cache.beans.ArchiveEntry) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) ObjectLoader(net.runelite.cache.definitions.loaders.ObjectLoader) FSFile(net.runelite.cache.fs.FSFile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with ObjectDefinition

use of net.runelite.cache.definitions.ObjectDefinition in project runelite by runelite.

the class MapImageDumper method drawMapIcons.

private void drawMapIcons(Graphics2D graphics, Region region, int z, int drawBaseX, int drawBaseY) {
    for (Location location : region.getLocations()) {
        int localZ = location.getPosition().getZ();
        if (z != 0 && localZ != z) {
            // draw all icons on z=0
            continue;
        }
        ObjectDefinition od = findObject(location.getId());
        assert od != null;
        int localX = location.getPosition().getX() - region.getBaseX();
        int localY = location.getPosition().getY() - region.getBaseY();
        int drawX = drawBaseX + localX;
        int drawY = drawBaseY + (Region.Y - 1 - localY);
        if (od.getMapAreaId() != -1) {
            AreaDefinition area = areas.getArea(od.getMapAreaId());
            assert area != null;
            int spriteId = area.spriteId;
            SpriteDefinition sprite = sprites.findSprite(spriteId, 0);
            assert sprite != null;
            BufferedImage iconImage = sprites.getSpriteImage(sprite);
            graphics.drawImage(iconImage, drawX * MAP_SCALE, drawY * MAP_SCALE, null);
        }
    }
}
Also used : AreaDefinition(net.runelite.cache.definitions.AreaDefinition) SpriteDefinition(net.runelite.cache.definitions.SpriteDefinition) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) BufferedImage(java.awt.image.BufferedImage) Location(net.runelite.cache.region.Location)

Example 10 with ObjectDefinition

use of net.runelite.cache.definitions.ObjectDefinition in project runelite by runelite.

the class ObjectManager method dump.

public void dump(File out) throws IOException {
    out.mkdirs();
    for (ObjectDefinition def : objects.values()) {
        ObjectExporter exporter = new ObjectExporter(def);
        File targ = new File(out, def.getId() + ".json");
        exporter.exportTo(targ);
    }
}
Also used : ObjectExporter(net.runelite.cache.definitions.exporters.ObjectExporter) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) File(java.io.File) FSFile(net.runelite.cache.fs.FSFile)

Aggregations

ObjectDefinition (net.runelite.cache.definitions.ObjectDefinition)10 FSFile (net.runelite.cache.fs.FSFile)4 Location (net.runelite.cache.region.Location)4 BufferedImage (java.awt.image.BufferedImage)3 Gson (com.google.gson.Gson)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 ModelDefinition (net.runelite.cache.definitions.ModelDefinition)2 ObjectLoader (net.runelite.cache.definitions.loaders.ObjectLoader)2 ArchiveFiles (net.runelite.cache.fs.ArchiveFiles)2 Position (net.runelite.cache.region.Position)2 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 Image (java.awt.Image)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1