use of net.runelite.cache.models.Vector3f in project runelite by runelite.
the class ModelViewer method drawModel.
private static void drawModel(ModelDefinition md, short[] recolourToFind, short[] recolourToReplace) {
for (int i = 0; i < md.faceCount; ++i) {
if (md.faceRenderTypes != null) {
byte faceRenderType = md.faceRenderTypes[i];
if ((faceRenderType & 2) != 0) {
// what is this?
continue;
}
}
int vertexA = md.faceVertexIndices1[i];
int vertexB = md.faceVertexIndices2[i];
int vertexC = md.faceVertexIndices3[i];
VertexNormal normalVertexA = md.vertexNormals[vertexA];
VertexNormal normalVertexB = md.vertexNormals[vertexB];
VertexNormal normalVertexC = md.vertexNormals[vertexC];
Vector3f nA = normalVertexA.normalize();
Vector3f nB = normalVertexB.normalize();
Vector3f nC = normalVertexC.normalize();
// Invert y
nA.y = -nA.y;
nB.y = -nB.y;
nC.y = -nC.y;
int vertexAx = md.vertexPositionsX[vertexA];
int vertexAy = md.vertexPositionsY[vertexA];
int vertexAz = md.vertexPositionsZ[vertexA];
int vertexBx = md.vertexPositionsX[vertexB];
int vertexBy = md.vertexPositionsY[vertexB];
int vertexBz = md.vertexPositionsZ[vertexB];
int vertexCx = md.vertexPositionsX[vertexC];
int vertexCy = md.vertexPositionsY[vertexC];
int vertexCz = md.vertexPositionsZ[vertexC];
short textureId = md.faceTextures != null ? md.faceTextures[i] : -1;
Color color;
float[] u = null;
float[] v = null;
if (textureId != -1) {
color = Color.WHITE;
Texture texture = getTexture(textureId);
assert texture != null;
if (md.faceTextureUCoordinates == null || md.faceTextureVCoordinates == null) {
md.computeTextureUVCoordinates();
}
u = md.faceTextureUCoordinates[i];
v = md.faceTextureVCoordinates[i];
int glTexture = texture.getOpenglId();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, glTexture);
} else {
short hsb = md.faceColors[i];
// Check recolor
if (recolourToFind != null) {
for (int j = 0; j < recolourToFind.length; ++j) {
if (recolourToFind[j] == hsb) {
hsb = recolourToReplace[j];
}
}
}
int rgb = RS2HSB_to_RGB(hsb);
color = new Color(rgb);
}
// convert to range of 0-1
float rf = (float) color.getRed() / 255f;
float gf = (float) color.getGreen() / 255f;
float bf = (float) color.getBlue() / 255f;
GL11.glBegin(GL11.GL_TRIANGLES);
GL11.glColor3f(rf, gf, bf);
// 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.glNormal3f(nB.x, nB.y, nB.z);
if (textureId != -1) {
GL11.glTexCoord2f(u[1], v[1]);
}
GL11.glVertex3i(vertexBx, -vertexBy, vertexBz);
GL11.glEnd();
if (textureId != -1) {
GL11.glDisable(GL11.GL_TEXTURE_2D);
}
}
}
Aggregations