Skip to content

Commit

Permalink
Fix texture mapping for floating point cube sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
mchorse committed Sep 10, 2021
1 parent 5c42dcf commit 152eef7
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions src/main/java/mchorse/chameleon/lib/data/model/ModelCube.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ public class ModelCube
public void setupBoxUV(Vector2f boxUV, boolean mirror)
{
/* North */
float tMinX = boxUV.x + this.size.z;
float tMinY = boxUV.y + this.size.z;
float tMaxX = tMinX + this.size.x;
float tMaxY = tMinY + this.size.y;
float w = (float) Math.floor(this.size.x);
float h = (float) Math.floor(this.size.y);
float d = (float) Math.floor(this.size.z);
float tMinX = boxUV.x + d;
float tMinY = boxUV.y + d;
float tMaxX = tMinX + w;
float tMaxY = tMinY + h;

if (mirror)
{
Expand All @@ -42,16 +45,16 @@ public void setupBoxUV(Vector2f boxUV, boolean mirror)

/* East */
tMinX = boxUV.x;
tMinY = boxUV.y + this.size.z;
tMaxX = tMinX + this.size.z;
tMaxY = tMinY + this.size.y;
tMinY = boxUV.y + d;
tMaxX = tMinX + d;
tMaxY = tMinY + h;

if (mirror)
{
tMinX = boxUV.x + this.size.z + this.size.x;
tMinY = boxUV.y + this.size.z;
tMaxX = tMinX + this.size.z;
tMaxY = tMinY + this.size.y;
tMinX = boxUV.x + d + w;
tMinY = boxUV.y + d;
tMaxX = tMinX + d;
tMaxY = tMinY + h;

float tmp = tMinX;

Expand All @@ -62,10 +65,10 @@ public void setupBoxUV(Vector2f boxUV, boolean mirror)
this.east = ModelUV.from(tMinX, tMinY, tMaxX, tMaxY);

/* South */
tMinX = boxUV.x + this.size.z * 2 + this.size.x;
tMinY = boxUV.y + this.size.z;
tMaxX = tMinX + this.size.x;
tMaxY = tMinY + this.size.y;
tMinX = boxUV.x + d * 2 + w;
tMinY = boxUV.y + d;
tMaxX = tMinX + w;
tMaxY = tMinY + h;

if (mirror)
{
Expand All @@ -78,17 +81,17 @@ public void setupBoxUV(Vector2f boxUV, boolean mirror)
this.south = ModelUV.from(tMinX, tMinY, tMaxX, tMaxY);

/* West */
tMinX = boxUV.x + this.size.z + this.size.x;
tMinY = boxUV.y + this.size.z;
tMaxX = tMinX + this.size.z;
tMaxY = tMinY + this.size.y;
tMinX = boxUV.x + d + w;
tMinY = boxUV.y + d;
tMaxX = tMinX + d;
tMaxY = tMinY + h;

if (mirror)
{
tMinX = boxUV.x;
tMinY = boxUV.y + this.size.z;
tMaxX = tMinX + this.size.z;
tMaxY = tMinY + this.size.y;
tMinY = boxUV.y + d;
tMaxX = tMinX + d;
tMaxY = tMinY + h;

float tmp = tMinX;

Expand All @@ -99,10 +102,10 @@ public void setupBoxUV(Vector2f boxUV, boolean mirror)
this.west = ModelUV.from(tMinX, tMinY, tMaxX, tMaxY);

/* Up */
tMinX = boxUV.x + this.size.z;
tMinX = boxUV.x + d;
tMinY = boxUV.y;
tMaxX = tMinX + this.size.x;
tMaxY = tMinY + this.size.z;
tMaxX = tMinX + w;
tMaxY = tMinY + d;

if (mirror)
{
Expand All @@ -115,9 +118,9 @@ public void setupBoxUV(Vector2f boxUV, boolean mirror)
this.up = ModelUV.from(tMinX, tMinY, tMaxX, tMaxY);

/* Down */
tMinX = boxUV.x + this.size.z + this.size.x;
tMinY = boxUV.y + this.size.z;
tMaxX = tMinX + this.size.x;
tMinX = boxUV.x + d + w;
tMinY = boxUV.y + d;
tMaxX = tMinX + w;
tMaxY = boxUV.y;

if (mirror)
Expand Down

0 comments on commit 152eef7

Please sign in to comment.