use of net.runelite.cache.definitions.providers.ModelProvider 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);
}
use of net.runelite.cache.definitions.providers.ModelProvider 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());
}
Aggregations