modelviewer: fix most of rotation logic
Also add alpha support
This commit is contained in:
@@ -24,57 +24,12 @@
|
||||
*/
|
||||
package net.runelite.modelviewer;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
public class LocationKey
|
||||
{
|
||||
private final int id;
|
||||
private final int type;
|
||||
private final int orientation;
|
||||
|
||||
public LocationKey(int id, int type, int orientation)
|
||||
{
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.orientation = orientation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int hash = 5;
|
||||
hash = 97 * hash + this.id;
|
||||
hash = 97 * hash + this.type;
|
||||
hash = 97 * hash + this.orientation;
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
final LocationKey other = (LocationKey) obj;
|
||||
if (this.id != other.id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.type != other.type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.orientation != other.orientation)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,9 +46,11 @@ public class ModelManager
|
||||
{
|
||||
LocationKey key;
|
||||
|
||||
int rot = location.getOrientation();
|
||||
|
||||
if (location != null)
|
||||
{
|
||||
key = new LocationKey(id, location.getType(), location.getOrientation());
|
||||
key = new LocationKey(id, location.getType(), rot);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -70,7 +72,8 @@ public class ModelManager
|
||||
|
||||
if (object != null && location != null)
|
||||
{
|
||||
rotate(md, object, location);
|
||||
rotate(md, object, location, rot);
|
||||
md.computeNormals();
|
||||
}
|
||||
|
||||
models.put(key, md);
|
||||
@@ -84,13 +87,13 @@ public class ModelManager
|
||||
}
|
||||
|
||||
// this logic is from method3697 in 140
|
||||
private static void rotate(ModelDefinition md, ObjectDefinition object, Location location)
|
||||
private static void rotate(ModelDefinition md, ObjectDefinition object, Location location, int rot)
|
||||
{
|
||||
if (object.getObjectTypes() == null)
|
||||
{
|
||||
boolean isRotate = object.isRotated();
|
||||
|
||||
if (location.getType() == 2 && location.getOrientation() > 3)
|
||||
if (location.getType() == 2 && rot > 3)
|
||||
{
|
||||
isRotate = !isRotate;
|
||||
}
|
||||
@@ -102,7 +105,7 @@ public class ModelManager
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean isRotate = object.isRotated() ^ location.getOrientation() > 3;
|
||||
boolean isRotate = object.isRotated() ^ rot > 3;
|
||||
|
||||
if (isRotate)
|
||||
{
|
||||
@@ -110,7 +113,7 @@ public class ModelManager
|
||||
}
|
||||
}
|
||||
|
||||
switch (location.getOrientation())
|
||||
switch (rot & 3)
|
||||
{
|
||||
case 1:
|
||||
md.rotate1();
|
||||
|
||||
@@ -225,6 +225,10 @@ public class ModelViewer
|
||||
|
||||
GL11.glCullFace(GL11.GL_BACK);
|
||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
long last = 0;
|
||||
|
||||
Camera camera = new Camera();
|
||||
@@ -297,6 +301,11 @@ public class ModelViewer
|
||||
nB.y = -nB.y;
|
||||
nC.y = -nC.y;
|
||||
|
||||
// and z
|
||||
nA.z = -nA.z;
|
||||
nB.z = -nB.z;
|
||||
nC.z = -nC.z;
|
||||
|
||||
int vertexAx = md.vertexPositionsX[vertexA];
|
||||
int vertexAy = md.vertexPositionsY[vertexA];
|
||||
int vertexAz = md.vertexPositionsZ[vertexA];
|
||||
@@ -310,6 +319,12 @@ public class ModelViewer
|
||||
int vertexCz = md.vertexPositionsZ[vertexC];
|
||||
|
||||
short textureId = md.faceTextures != null ? md.faceTextures[i] : -1;
|
||||
int alpha = md.faceAlphas != null ? (md.faceAlphas[i] & 0xFF) : 255;
|
||||
if (alpha == 0)
|
||||
{
|
||||
alpha = 255;
|
||||
}
|
||||
|
||||
Color color;
|
||||
|
||||
float[] u = null;
|
||||
@@ -359,34 +374,32 @@ public class ModelViewer
|
||||
float rf = (float) color.getRed() / 255f;
|
||||
float gf = (float) color.getGreen() / 255f;
|
||||
float bf = (float) color.getBlue() / 255f;
|
||||
float af = (float) alpha / 255f;
|
||||
|
||||
GL11.glBegin(GL11.GL_TRIANGLES);
|
||||
|
||||
GL11.glColor3f(rf, gf, bf);
|
||||
GL11.glColor4f(rf, gf, bf, af);
|
||||
|
||||
// With GL11.GL_CCW we have to draw A -> C -> B when
|
||||
// inverting y instead of A -> B -> C, or else with cull
|
||||
// face will cull the wrong side
|
||||
GL11.glNormal3f(nA.x, nA.y, nA.z);
|
||||
if (textureId != -1)
|
||||
{
|
||||
GL11.glTexCoord2f(u[0], v[0]);
|
||||
}
|
||||
GL11.glVertex3i(vertexAx, -vertexAy, vertexAz);
|
||||
|
||||
GL11.glNormal3f(nC.x, nC.y, nC.z);
|
||||
if (textureId != -1)
|
||||
{
|
||||
GL11.glTexCoord2f(u[2], v[2]);
|
||||
}
|
||||
GL11.glVertex3i(vertexCx, -vertexCy, vertexCz);
|
||||
GL11.glVertex3i(vertexAx, -vertexAy, -vertexAz);
|
||||
|
||||
GL11.glNormal3f(nB.x, nB.y, nB.z);
|
||||
if (textureId != -1)
|
||||
{
|
||||
GL11.glTexCoord2f(u[1], v[1]);
|
||||
}
|
||||
GL11.glVertex3i(vertexBx, -vertexBy, vertexBz);
|
||||
GL11.glVertex3i(vertexBx, -vertexBy, -vertexBz);
|
||||
|
||||
GL11.glNormal3f(nC.x, nC.y, nC.z);
|
||||
if (textureId != -1)
|
||||
{
|
||||
GL11.glTexCoord2f(u[2], v[2]);
|
||||
}
|
||||
GL11.glVertex3i(vertexCx, -vertexCy, -vertexCz);
|
||||
|
||||
GL11.glEnd();
|
||||
|
||||
@@ -556,15 +569,19 @@ public class ModelViewer
|
||||
int height = -region.getTileHeight(objectPos.getZ(), regionX, regionY) / HEIGHT_MOD;
|
||||
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
|
||||
// TILE_SCALE/2 to draw the object from the center of the tile it is on
|
||||
GL11.glTranslatef(regionX * TILE_SCALE + (TILE_SCALE / 2), height, -regionY * TILE_SCALE - (TILE_SCALE / 2));
|
||||
GL11.glTranslatef(regionX * TILE_SCALE + (TILE_SCALE / 2), height * (location.getPosition().getZ() + 1), -regionY * TILE_SCALE - (TILE_SCALE / 2));
|
||||
|
||||
for (int i = 0; i < object.getObjectModels().length; ++i)
|
||||
{
|
||||
if (object.getObjectTypes() != null && object.getObjectTypes()[i] != location.getType())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ModelDefinition md = ModelManager.getModel(object.getObjectModels()[i], object, location);
|
||||
|
||||
if (object.getObjectTypes() != null && object.getObjectTypes()[i] != location.getType())
|
||||
if (md == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -572,7 +589,7 @@ public class ModelViewer
|
||||
drawModel(md, object.getRecolorToFind(), object.getRecolorToReplace());
|
||||
}
|
||||
|
||||
GL11.glTranslatef(-regionX * TILE_SCALE - (TILE_SCALE / 2), -height, regionY * TILE_SCALE + (TILE_SCALE / 2));
|
||||
GL11.glTranslatef(-regionX * TILE_SCALE - (TILE_SCALE / 2), -(height * (location.getPosition().getZ() + 1)), regionY * TILE_SCALE + (TILE_SCALE / 2));
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user