Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect uv calculations due to BlockBench 4.9 #129

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class BlockBenchModel {

private static final String VERSION = "4.5";
private static final String VERSION = "4.9";

private final JsonObject root = new JsonObject();
private final ArrayList<Cube> elements = new ArrayList<>();
Expand All @@ -36,13 +36,17 @@ public void setResolution(int w, int h) {
}

// returns the image id
public int addImage(String name, String source) {
public int addImage(String name, String source, int width, int height) {
int id = textures.size();

JsonObject texture = new JsonObject();
texture.addProperty("name", name);
texture.addProperty("id", String.valueOf(id));
texture.addProperty("source", "data:image/png;base64," + source);
texture.addProperty("width", width);
texture.addProperty("height", height);
texture.addProperty("uv_width", width);
texture.addProperty("uv_height", height);
textures.add(texture);

return id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public static class Texture {
String name;
String relative_path;
String source;
Float width, height;
Float uv_width, uv_height;
}

// -- elements -- //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,14 @@ private void parseTextures(Path avatar, Path sourceFile, String folders, String
int id = textureIndex.indexOf(name) + textureOffset;

//fix texture size for more speed
int[] imageSize = getTextureSize(source);
float[] fixedSize = new float[]{(float) imageSize[0] / resolution.width, (float) imageSize[1] / resolution.height};
float[] fixedSize;
if (texture.width != null) {
fixedSize = new float[]{(float) texture.width / texture.uv_width, (float) texture.height / texture.uv_height};
}
else {
int[] imageSize = getTextureSize(source);
fixedSize = new float[]{(float) imageSize[0] / resolution.width, (float) imageSize[1] / resolution.height};
}

//add the texture on the map
textureMap.put(name, new TextureData(id, fixedSize));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ private byte[] buildModel() {
BlockBenchModel model = new BlockBenchModel("free");

//textures
int playerTex = hasPlayer ? model.addImage("Skin", slim ? playerTextureSlim : playerTexture) : -1;
int capeTex = hasCapeOrElytra ? model.addImage("Cape", capeTexture) : -1;
int playerTex = hasPlayer ? model.addImage("Skin", slim ? playerTextureSlim : playerTexture, 64, 64) : -1;
int capeTex = hasCapeOrElytra ? model.addImage("Cape", capeTexture, 64, 32) : -1;

//resolution
if (hasPlayer)
Expand Down