Search in sources :

Example 1 with ModelLoader

use of net.runelite.cache.definitions.loaders.ModelLoader in project runelite by runelite.

the class ObjExporterTest method testExport.

@Test
@Ignore
public void testExport() throws Exception {
    try (Store store = new Store(StoreLocation.LOCATION)) {
        store.load();
        TextureManager tm = new TextureManager(store);
        tm.load();
        ModelLoader loader = new ModelLoader();
        ModelDefinition model = loader.load(9638, Files.readAllBytes(new File("D:\\rs\\07\\cache\\models\\9638.model").toPath()));
        ObjExporter exporter = new ObjExporter(tm, model);
        try (PrintWriter objWriter = new PrintWriter(new FileWriter(new File("D:\\rs\\07\\temp\\9638.obj")));
            PrintWriter mtlWriter = new PrintWriter(new FileWriter(new File("D:\\rs\\07\\temp\\9638.mtl")))) {
            exporter.export(objWriter, mtlWriter);
        }
    }
}
Also used : TextureManager(net.runelite.cache.TextureManager) ModelLoader(net.runelite.cache.definitions.loaders.ModelLoader) FileWriter(java.io.FileWriter) ModelDefinition(net.runelite.cache.definitions.ModelDefinition) Store(net.runelite.cache.fs.Store) File(java.io.File) PrintWriter(java.io.PrintWriter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with ModelLoader

use of net.runelite.cache.definitions.loaders.ModelLoader in project runelite by runelite.

the class ItemSpriteFactoryTest method test.

@Test
@Ignore
public void test() throws IOException {
    File base = StoreLocation.LOCATION, outDir = folder.newFolder();
    int count = 0;
    try (Store store = new Store(base)) {
        store.load();
        ItemManager itemManager = new ItemManager(store);
        itemManager.load();
        ModelProvider modelProvider = new ModelProvider() {

            @Override
            public ModelDefinition provide(int modelId) throws IOException {
                Index models = store.getIndex(IndexType.MODELS);
                Archive archive = models.getArchive(modelId);
                byte[] data = archive.decompress(store.getStorage().loadArchive(archive));
                ModelDefinition inventoryModel = new ModelLoader().load(modelId, data);
                return inventoryModel;
            }
        };
        SpriteManager spriteManager = new SpriteManager(store);
        spriteManager.load();
        TextureManager textureManager = new TextureManager(store);
        textureManager.load();
        for (ItemDefinition itemDef : itemManager.getItems()) {
            if (itemDef.name == null || itemDef.name.equalsIgnoreCase("null")) {
                continue;
            }
            try {
                BufferedImage sprite = ItemSpriteFactory.createSprite(itemManager, modelProvider, spriteManager, textureManager, itemDef.id, 1, 1, 3153952, false);
                File out = new File(outDir, itemDef.id + ".png");
                BufferedImage img = sprite;
                ImageIO.write(img, "PNG", out);
                ++count;
            } catch (Exception ex) {
                log.warn("error dumping item {}", itemDef.id, ex);
            }
        }
    }
    log.info("Dumped {} item images to {}", count, outDir);
}
Also used : Archive(net.runelite.cache.fs.Archive) ItemManager(net.runelite.cache.ItemManager) ModelProvider(net.runelite.cache.definitions.providers.ModelProvider) ItemDefinition(net.runelite.cache.definitions.ItemDefinition) Store(net.runelite.cache.fs.Store) Index(net.runelite.cache.fs.Index) SpriteManager(net.runelite.cache.SpriteManager) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) ModelLoader(net.runelite.cache.definitions.loaders.ModelLoader) TextureManager(net.runelite.cache.TextureManager) ModelDefinition(net.runelite.cache.definitions.ModelDefinition) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with ModelLoader

use of net.runelite.cache.definitions.loaders.ModelLoader in project runelite by runelite.

the class CacheController method getItemImage.

@RequestMapping(path = "item/{itemId}/image", produces = "image/png")
public ResponseEntity<byte[]> getItemImage(@PathVariable int itemId, @RequestParam(defaultValue = "1") int quantity, @RequestParam(defaultValue = "1") int border, @RequestParam(defaultValue = "3153952") int shadowColor) throws IOException {
    final CacheEntry cache = cacheService.findMostRecent();
    ItemProvider itemProvider = new ItemProvider() {

        @Override
        public ItemDefinition provide(int itemId) {
            try {
                return getItem(itemId);
            } catch (IOException ex) {
                log.warn(null, ex);
                return null;
            }
        }
    };
    ModelProvider modelProvider = new ModelProvider() {

        @Override
        public ModelDefinition provide(int modelId) throws IOException {
            IndexEntry indexEntry = cacheService.findIndexForCache(cache, IndexType.MODELS.getNumber());
            ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, modelId);
            byte[] archiveData = Container.decompress(cacheService.getArchive(archiveEntry), null).data;
            return new ModelLoader().load(modelId, archiveData);
        }
    };
    SpriteProvider spriteProvider = new SpriteProvider() {

        @Override
        public SpriteDefinition provide(int spriteId, int frameId) {
            try {
                IndexEntry indexEntry = cacheService.findIndexForCache(cache, IndexType.SPRITES.getNumber());
                ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, spriteId);
                byte[] archiveData = Container.decompress(cacheService.getArchive(archiveEntry), null).data;
                SpriteDefinition[] defs = new SpriteLoader().load(spriteId, archiveData);
                return defs[frameId];
            } catch (Exception ex) {
                log.warn(null, ex);
                return null;
            }
        }
    };
    TextureProvider textureProvider2 = new TextureProvider() {

        @Override
        public TextureDefinition[] provide() {
            try {
                IndexEntry indexEntry = cacheService.findIndexForCache(cache, IndexType.TEXTURES.getNumber());
                ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, 0);
                ArchiveFiles archiveFiles = cacheService.getArchiveFiles(archiveEntry);
                TextureLoader loader = new TextureLoader();
                TextureDefinition[] defs = new TextureDefinition[archiveFiles.getFiles().size()];
                int i = 0;
                for (FSFile file : archiveFiles.getFiles()) {
                    TextureDefinition def = loader.load(file.getFileId(), file.getContents());
                    defs[i++] = def;
                }
                return defs;
            } catch (Exception ex) {
                log.warn(null, ex);
                return null;
            }
        }
    };
    BufferedImage itemImage = ItemSpriteFactory.createSprite(itemProvider, modelProvider, spriteProvider, textureProvider2, itemId, quantity, border, shadowColor, false);
    ByteArrayOutputStream bao = new ByteArrayOutputStream();
    ImageIO.write(itemImage, "png", bao);
    return ResponseEntity.ok(bao.toByteArray());
}
Also used : ItemProvider(net.runelite.cache.definitions.providers.ItemProvider) TextureLoader(net.runelite.cache.definitions.loaders.TextureLoader) ModelProvider(net.runelite.cache.definitions.providers.ModelProvider) SpriteDefinition(net.runelite.cache.definitions.SpriteDefinition) IndexEntry(net.runelite.http.service.cache.beans.IndexEntry) ArchiveEntry(net.runelite.http.service.cache.beans.ArchiveEntry) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CacheEntry(net.runelite.http.service.cache.beans.CacheEntry) TextureProvider(net.runelite.cache.definitions.providers.TextureProvider) IOException(java.io.IOException) NotFoundException(net.runelite.http.service.util.exception.NotFoundException) BufferedImage(java.awt.image.BufferedImage) FSFile(net.runelite.cache.fs.FSFile) ModelLoader(net.runelite.cache.definitions.loaders.ModelLoader) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) TextureDefinition(net.runelite.cache.definitions.TextureDefinition) SpriteLoader(net.runelite.cache.definitions.loaders.SpriteLoader) SpriteProvider(net.runelite.cache.definitions.providers.SpriteProvider) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ModelLoader

use of net.runelite.cache.definitions.loaders.ModelLoader in project runelite by runelite.

the class ModelDumperTest method test.

@Test
public void test() throws IOException {
    File modelDir = folder.newFolder("models");
    int count = 0;
    try (Store store = new Store(StoreLocation.LOCATION)) {
        store.load();
        Storage storage = store.getStorage();
        Index index = store.getIndex(IndexType.MODELS);
        for (Archive archive : index.getArchives()) {
            byte[] contents = archive.decompress(storage.loadArchive(archive));
            ModelLoader loader = new ModelLoader();
            loader.load(archive.getArchiveId(), contents);
            Files.write(contents, new File(modelDir, archive.getArchiveId() + ".model"));
            ++count;
        }
    }
    logger.info("Dumped {} models to {}", count, modelDir);
}
Also used : ModelLoader(net.runelite.cache.definitions.loaders.ModelLoader) Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) Store(net.runelite.cache.fs.Store) Index(net.runelite.cache.fs.Index) File(java.io.File) Test(org.junit.Test)

Example 5 with ModelLoader

use of net.runelite.cache.definitions.loaders.ModelLoader in project runelite by runelite.

the class ModelManager method getModel.

public static ModelDefinition getModel(int id, ObjectDefinition object, Location location) {
    LocationKey key;
    if (location != null) {
        key = new LocationKey(id, location.getType(), location.getOrientation());
    } else {
        key = new LocationKey(id, -1, -1);
    }
    ModelDefinition md = models.get(key);
    if (md != null) {
        return md;
    }
    try {
        byte[] b = Files.readAllBytes(new File("models/" + id + ".model").toPath());
        ModelLoader loader = new ModelLoader();
        md = loader.load(id, b);
        if (object != null && location != null) {
            rotate(md, object, location);
        }
        models.put(key, md);
        return md;
    } catch (IOException ex) {
        logger.warn(null, ex);
        return null;
    }
}
Also used : ModelLoader(net.runelite.cache.definitions.loaders.ModelLoader) ModelDefinition(net.runelite.cache.definitions.ModelDefinition) IOException(java.io.IOException) File(java.io.File)

Aggregations

ModelLoader (net.runelite.cache.definitions.loaders.ModelLoader)5 File (java.io.File)4 IOException (java.io.IOException)3 ModelDefinition (net.runelite.cache.definitions.ModelDefinition)3 Store (net.runelite.cache.fs.Store)3 Test (org.junit.Test)3 BufferedImage (java.awt.image.BufferedImage)2 TextureManager (net.runelite.cache.TextureManager)2 ModelProvider (net.runelite.cache.definitions.providers.ModelProvider)2 Archive (net.runelite.cache.fs.Archive)2 Index (net.runelite.cache.fs.Index)2 Ignore (org.junit.Ignore)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 ItemManager (net.runelite.cache.ItemManager)1 SpriteManager (net.runelite.cache.SpriteManager)1 ItemDefinition (net.runelite.cache.definitions.ItemDefinition)1 SpriteDefinition (net.runelite.cache.definitions.SpriteDefinition)1 TextureDefinition (net.runelite.cache.definitions.TextureDefinition)1