Skip to content

Commit

Permalink
Model viewer improvements - supports RS2 and some RSHD textures
Browse files Browse the repository at this point in the history
  • Loading branch information
lequietriot committed Dec 12, 2022
1 parent 02a1e9c commit 795a87f
Show file tree
Hide file tree
Showing 21 changed files with 1,678 additions and 164 deletions.
2 changes: 1 addition & 1 deletion Old-School-RuneScape-Cache-Tools.iml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="true">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/resources" type="java-resource" />
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ Made with IntelliJ IDEA using Java 1.8 SDK with various libraries including Java
* Cache Explorer: Not able to dump/export all files of single archive - only the first file is exported?
* Cache Explorer: Some caches may not load correctly
* Data Decoders: SoundFont conversion - may not be perfect
* Model Viewer: Does not work on RS2 yet
* Model Viewer: May not work on Mac computers, a workaround would be running the project directly through IntelliJ IDEA.
* Model Viewer: Textures do not work in RS2 caches
* Model Viewer: Textures may not load in all RSHD caches
* Model Viewer: May not work on Mac computers, a workaround would be running the project or jar directly through IntelliJ IDEA.

## That's all for now. Enjoy!
Binary file not shown.
1 change: 0 additions & 1 deletion src/java/com/application/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,6 @@ private void loadCache(File cache) {
}
}


this.revalidate();
}

Expand Down
4 changes: 2 additions & 2 deletions src/java/modelviewer/controllers/ModelController.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public void updateModel(CacheLibrary cacheLibrary, int selectedIndex, int select
if (AppConstants.cacheType.equals("RuneScape 2")) {
ModelLoader modelLoader = new ModelLoader();
ModelDefinition model;
if (selectedIndex == 7) {
if (selectedIndex == 1) {
model = modelLoader.load(0, Objects.requireNonNull(cacheLibrary.data(selectedIndex, selectedArchive, selectedFile)));
} else {
model = modelLoader.load(0, Objects.requireNonNull(cacheLibrary.data(7, 1, 0)));
model = modelLoader.load(0, Objects.requireNonNull(cacheLibrary.data(1, 1, 0)));
}
if (model != null) {
try {
Expand Down
39 changes: 39 additions & 0 deletions src/java/modelviewer/scene/RSMeshGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.runelite.cache.definitions.SpriteDefinition;
import net.runelite.cache.definitions.loaders.SpriteLoader;
import net.runelite.cache.fs.Store;
import rshd.TextureLoaderHD;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
Expand All @@ -32,6 +33,7 @@ public class RSMeshGroup {
public final float MODEL_SCALE = 0.03f;

private TextureManager textureManager;
private TextureLoaderHD textureLoaderHD;

public RSMeshGroup(ModelDefinition model) {
this.model = model;
Expand All @@ -40,12 +42,18 @@ public RSMeshGroup(ModelDefinition model) {
private Image texture;

public void buildMeshes() throws IOException {
if (AppConstants.cacheType.equals("RuneScape 2")) {

}
if (AppConstants.cacheType.equals("Old School RuneScape")) {
Store store = new Store(new File(GUI.cacheLibrary.getPath()));
store.load();
textureManager = new TextureManager(store);
textureManager.load();
}
if (AppConstants.cacheType.equals("RuneScape High Definition")) {
textureLoaderHD = new TextureLoaderHD();
}
model.computeTextureUVCoordinates();
for (int face = 0; face < model.faceCount; face++) {
TriangleMesh mesh = new TriangleMesh();
Expand Down Expand Up @@ -81,6 +89,13 @@ public void buildMeshes() throws IOException {
if (model.faceTextures != null && model.faceTextures[face] != -1 && AppConstants.cacheType.equals("Old School RuneScape")) {
texture = exportToImage(textureManager.findTexture(model.faceTextures[face]).getFileIds()[0]);
mat.setDiffuseMap(texture);
mat.setDiffuseColor(ColorUtils.rs2HSLToColor(model.faceColors[face], model.faceTransparencies == null ? 0 : model.faceTransparencies[face]));
view.setMaterial(mat);
}
if (model.faceTextures != null && model.faceTextures[face] != -1 && AppConstants.cacheType.equals("RuneScape High Definition")) {
texture = exportToImageHD(model.faceTextures[face]);
mat.setDiffuseMap(texture);
mat.setDiffuseColor(ColorUtils.rs2HSLToColor(model.faceColors[face], 0));//model.faceTransparencies == null ? 0 : model.faceTransparencies[face]));
view.setMaterial(mat);
}
else {
Expand All @@ -94,6 +109,7 @@ public void buildMeshes() throws IOException {
}
}


private void initListeners(MeshView view) {
view.setOnMouseClicked(event -> {
paint(view);
Expand Down Expand Up @@ -127,4 +143,27 @@ public Image exportToImage(int spriteID) throws IOException
ImageIO.write(image, "png", byteArrayOutputStream);
return new Image(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
}

public Image exportToImageHD(int id) {
byte[] data = GUI.cacheLibrary.data(9, id, 0);
if (data != null) {
if (data[1] == "P".getBytes()[0]) {
return new Image(new ByteArrayInputStream(data));
}
}
/*
try {
ImageIndexLoader imageIndexLoader = new ImageIndexLoader(GUI.cacheLibrary.index(26), GUI.cacheLibrary.index(9), GUI.cacheLibrary.index(8));
int[] pixels = imageIndexLoader.renderMaterialPixelsI(id, 256, 256);
BufferedImage bi = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);
bi.setRGB(0, 0, 256, 256, pixels, 0, 256);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ImageIO.write(bi, "png", byteArrayOutputStream);
return new Image(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
} catch (IOException e) {
e.printStackTrace();
}
*/
return null;
}
}
143 changes: 0 additions & 143 deletions src/java/net/runelite/cache/loaders/ImageIndexLoader.java

This file was deleted.

13 changes: 0 additions & 13 deletions src/java/net/runelite/cache/loaders/ImageLoader.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/java/net/runelite/cache/managers/TextureManagerHD.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.displee.cache.CacheLibrary;
import com.displee.cache.index.Index;
import com.displee.cache.index.archive.Archive;
import net.runelite.cache.loaders.ImageIndexLoader;
import rshd.ImageIndexLoader;
import net.runelite.cache.definitions.TextureDefinition;
import net.runelite.cache.definitions.TextureDetails;
import net.runelite.cache.providers.TextureProvider;
Expand Down
50 changes: 50 additions & 0 deletions src/java/rshd/Class308.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package rshd;

import osrs.Node;

public class Class308 {

public boolean aBool3619;
int[][][] anIntArrayArrayArray3614;
LinkedNodeList aClass473_3612 = new LinkedNodeList();
int anInt3617;
int anInt3616 = -1;
int anInt3611;
Node[] aNode_Sub16Array3615;
int anInt3613;

Class308(int i_1, int i_2, int i_3) {
anInt3611 = i_2;
anInt3613 = i_1;
anIntArrayArrayArray3614 = new int[anInt3613][3][i_3];
}

void clear() {
for (int i_2 = 0; i_2 < anInt3613; i_2++) {
anIntArrayArrayArray3614[i_2][0] = null;
anIntArrayArrayArray3614[i_2][1] = null;
anIntArrayArrayArray3614[i_2][2] = null;
anIntArrayArrayArray3614[i_2] = null;
}
anIntArrayArrayArray3614 = null;
aClass473_3612.clear();
aClass473_3612 = null;
}

public int[][] method5463(int i_1) {
if (anInt3611 == anInt3613) {
aBool3619 = true;
return anIntArrayArrayArray3614[i_1];
}
if (anInt3613 != 1) {
Node class282_sub16_3 = aNode_Sub16Array3615[i_1];
aClass473_3612.insertFront(class282_sub16_3);
return anIntArrayArrayArray3614[(int) class282_sub16_3.key];
} else {
aBool3619 = anInt3616 != i_1;
anInt3616 = i_1;
return anIntArrayArrayArray3614[0];
}
}

}
33 changes: 33 additions & 0 deletions src/java/rshd/Class316.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package rshd;

import osrs.NodeHashTable;

public class Class316 {

public static int[] anIntArray3677;
public static int[] anIntArray3675;
public static int[] anIntArray3672;
public static int anInt3669;
public static int anInt3670;
public static int anInt3678;
public static int[] anIntArray3668;
public static int anInt3673;
public static int anInt3671;
static NodeHashTable aClass223_3679 = new NodeHashTable(16);

public static void method5586() {
if (anIntArray3677 == null || anIntArray3675 == null) {
anIntArray3677 = new int[256];
anIntArray3675 = new int[256];
for (int i_1 = 0; i_1 < 256; i_1++) {
double d_2 = 6.283185307179586D * (i_1 / 255.0D);
anIntArray3677[i_1] = (int) (Math.sin(d_2) * 4096.0D);
anIntArray3675[i_1] = (int) (Math.cos(d_2) * 4096.0D);
}
}
}

Class316() throws Throwable {
throw new Error();
}
}
Loading

0 comments on commit 795a87f

Please sign in to comment.