Skip to content

Commit

Permalink
finish backport of TC5 render. buggy but HUGE FPS gain and FMT support
Browse files Browse the repository at this point in the history
  • Loading branch information
EternalBlueFlame committed Nov 24, 2023
1 parent c79f2c6 commit 8b1df63
Show file tree
Hide file tree
Showing 33 changed files with 95 additions and 3,791 deletions.
166 changes: 83 additions & 83 deletions src/main/java/train/client/render/CustomModelRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,90 +7,90 @@
import java.util.ArrayList;

public class CustomModelRenderer extends ModelRendererTurbo {
public CustomModelRenderer(ModelBase m, int i, int j, int w, int h) {
super(m, i, j, w, h);
}

@Override
public ModelRendererTurbo addBox(float f, float f1, float f2, int i, int j, int k) {
addBox(f, f1, f2, i, j, k, 0.0f);
return this;
}

// For some odd reason the boxes seem inside out normally, so it's likely the values are reversed
@Override
public ModelRendererTurbo addBox(float f, float f1, float f2, int i, int j, int k, float f3) {
faces = new ArrayList<>();
float f4 = f + i + f3;
float f5 = f1 + j + f3;
float f6 = f2 + k + f3;
public CustomModelRenderer(ModelBase m, int i, int j, int w, int h) {
super(m,i,j,w,h);
}

@Override
public ModelRendererTurbo addBox(float f, float f1, float f2, int i, int j, int k) {
addBox(f, f1, f2, i, j, k, 0.0f);
return this;
}

//for some odd reason the boxes seem inside out normally, so it's likely the values are reversed
@Override
public ModelRendererTurbo addBox(float f, float f1, float f2, int i, int j, int k, float f3) {
faces = new ArrayList<TexturedPolygon>();
float f4 = f + i +f3;
float f5 = f1 + j +f3;
float f6 = f2 + k +f3;
f -= f3;
f1 -= f3;
f2 -= f3;
TexturedVertex TexturedVertex = new TexturedVertex(f, f1, f2, 0.0F, 0.0F);
TexturedVertex TexturedVertex1 = new TexturedVertex(f4, f1, f2, 0.0F, 8F);
TexturedVertex TexturedVertex2 = new TexturedVertex(f4, f5, f2, 8F, 8F);
TexturedVertex TexturedVertex3 = new TexturedVertex(f, f5, f2, 8F, 0.0F);
TexturedVertex TexturedVertex4 = new TexturedVertex(f, f1, f6, 0.0F, 0.0F);
TexturedVertex TexturedVertex5 = new TexturedVertex(f4, f1, f6, 0.0F, 8F);
TexturedVertex TexturedVertex6 = new TexturedVertex(f4, f5, f6, 8F, 8F);
TexturedVertex TexturedVertex7 = new TexturedVertex(f, f5, f6, 8F, 0.0F);
faces.add(generateFaces(new TexturedVertex[] { TexturedVertex5, TexturedVertex1, TexturedVertex2, TexturedVertex6 }, textureOffsetX + k + i, textureOffsetY + k, textureOffsetX + k + i + k, textureOffsetY + k + j, textureWidth, textureHeight));
faces.add(generateFaces(new TexturedVertex[] { TexturedVertex, TexturedVertex4, TexturedVertex7, TexturedVertex3 }, textureOffsetX, textureOffsetY + k, textureOffsetX + k, textureOffsetY + k + j, textureWidth, textureHeight));
faces.add(generateFaces(new TexturedVertex[] { TexturedVertex5, TexturedVertex4, TexturedVertex, TexturedVertex1 }, textureOffsetX + k, textureOffsetY, textureOffsetX + k + i, textureOffsetY + k, textureWidth, textureHeight));
faces.add(generateFaces(new TexturedVertex[] { TexturedVertex2, TexturedVertex3, TexturedVertex7, TexturedVertex6 }, textureOffsetX + k + i, textureOffsetY, textureOffsetX + k + i + i, textureOffsetY + k, textureWidth, textureHeight));
faces.add(generateFaces(new TexturedVertex[] { TexturedVertex1, TexturedVertex, TexturedVertex3, TexturedVertex2 }, textureOffsetX + k, textureOffsetY + k, textureOffsetX + k + i, textureOffsetY + k + j, textureWidth, textureHeight));
faces.add(generateFaces(new TexturedVertex[] { TexturedVertex4, TexturedVertex5, TexturedVertex6, TexturedVertex7 }, textureOffsetX + k + i + k, textureOffsetY + k, textureOffsetX + k + i + k + i, textureOffsetY + k + j, textureWidth, textureHeight));
return this;
}

private static TexturedPolygon generateFaces(TexturedVertex aPositionTransformVertex[], int i, int j, int k, int l, float textureWidth, float textureHeight) {
aPositionTransformVertex[0] = new TexturedVertex(aPositionTransformVertex[0].vector3F, (float) k / textureWidth - 0.0015625F, (float) j / textureHeight + 0.003125F);
aPositionTransformVertex[1] = new TexturedVertex(aPositionTransformVertex[1].vector3F,(float) i / textureWidth + 0.0015625F, (float) j / textureHeight + 0.003125F);
aPositionTransformVertex[2] = new TexturedVertex(aPositionTransformVertex[2].vector3F,(float) i / textureWidth + 0.0015625F, (float) l / textureHeight - 0.003125F);
aPositionTransformVertex[3] = new TexturedVertex(aPositionTransformVertex[3].vector3F,(float) k / textureWidth - 0.0015625F, (float) l / textureHeight - 0.003125F);
return new TexturedPolygon(aPositionTransformVertex);
}

private static final float degreesF = (float)(180D/Math.PI);

//same as super, but old models have inverse Y rotations and I don't even understand the Z rotation
public void render(float worldScale) {

if(!showModel) {
return;
}
if (rotateAngleX != 0.0F || rotateAngleY != 0.0F || rotateAngleZ != 0.0F) {
GL11.glPushMatrix();
GL11.glTranslatef(rotationPointX * worldScale, rotationPointY * worldScale, rotationPointZ *worldScale);
if (rotateAngleZ != 0.0F) {
GL11.glRotatef(rotateAngleZ * degreesF, 0.0F, 0.0F, 1.0F);
}
if (rotateAngleY != 0.0F) {
GL11.glRotatef(rotateAngleY * degreesF, 0.0F, 1.0F, 0.0F);
}
if (rotateAngleX != 0.0F) {
GL11.glRotatef(rotateAngleX * degreesF, 1.0F, 0.0F, 0.0F);
}
for (TexturedPolygon poly : faces) {
Tessellator.getInstance().drawTexturedVertsWithNormal(poly, worldScale);
}
GL11.glPopMatrix();
}
else if (rotationPointX != 0.0F || rotationPointY != 0.0F || rotationPointZ != 0.0F) {
GL11.glTranslatef(rotationPointX * worldScale, rotationPointY * worldScale, rotationPointZ * worldScale);
for (TexturedPolygon poly : faces) {
Tessellator.getInstance().drawTexturedVertsWithNormal(poly, worldScale);
}
GL11.glTranslatef(-rotationPointX * worldScale, -rotationPointY * worldScale, -rotationPointZ * worldScale);
}
else {
for (TexturedPolygon poly : faces) {
Tessellator.getInstance().drawTexturedVertsWithNormal(poly, worldScale);
}
}
}

f -= f3;
f1 -= f3;
f2 -= f3;

TexturedVertex TexturedVertex = new TexturedVertex(f, f1, f2, 0.0F, 0.0F);
TexturedVertex TexturedVertex1 = new TexturedVertex(f4, f1, f2, 0.0F, 8F);
TexturedVertex TexturedVertex2 = new TexturedVertex(f4, f5, f2, 8F, 8F);
TexturedVertex TexturedVertex3 = new TexturedVertex(f, f5, f2, 8F, 0.0F);
TexturedVertex TexturedVertex4 = new TexturedVertex(f, f1, f6, 0.0F, 0.0F);
TexturedVertex TexturedVertex5 = new TexturedVertex(f4, f1, f6, 0.0F, 8F);
TexturedVertex TexturedVertex6 = new TexturedVertex(f4, f5, f6, 8F, 8F);
TexturedVertex TexturedVertex7 = new TexturedVertex(f, f5, f6, 8F, 0.0F);

faces.add(generateFaces(new TexturedVertex[]{TexturedVertex5, TexturedVertex1, TexturedVertex2, TexturedVertex6}, textureOffsetX + k + i, textureOffsetY + k, textureOffsetX + k + i + k, textureOffsetY + k + j, textureWidth, textureHeight));
faces.add(generateFaces(new TexturedVertex[]{TexturedVertex, TexturedVertex4, TexturedVertex7, TexturedVertex3}, textureOffsetX, textureOffsetY + k, textureOffsetX + k, textureOffsetY + k + j, textureWidth, textureHeight));
faces.add(generateFaces(new TexturedVertex[]{TexturedVertex5, TexturedVertex4, TexturedVertex, TexturedVertex1}, textureOffsetX + k, textureOffsetY, textureOffsetX + k + i, textureOffsetY + k, textureWidth, textureHeight));
faces.add(generateFaces(new TexturedVertex[]{TexturedVertex2, TexturedVertex3, TexturedVertex7, TexturedVertex6}, textureOffsetX + k + i, textureOffsetY, textureOffsetX + k + i + i, textureOffsetY + k, textureWidth, textureHeight));
faces.add(generateFaces(new TexturedVertex[]{TexturedVertex1, TexturedVertex, TexturedVertex3, TexturedVertex2}, textureOffsetX + k, textureOffsetY + k, textureOffsetX + k + i, textureOffsetY + k + j, textureWidth, textureHeight));
faces.add(generateFaces(new TexturedVertex[]{TexturedVertex4, TexturedVertex5, TexturedVertex6, TexturedVertex7}, textureOffsetX + k + i + k, textureOffsetY + k, textureOffsetX + k + i + k + i, textureOffsetY + k + j, textureWidth, textureHeight));
return this;
}

private static TexturedPolygon generateFaces(TexturedVertex aPositionTransformVertex[], int i, int j, int k, int l, float textureWidth, float textureHeight) {
aPositionTransformVertex[0] = new TexturedVertex(aPositionTransformVertex[0].vector3F, (float) k / textureWidth - 0.0015625F, (float) j / textureHeight + 0.003125F);
aPositionTransformVertex[1] = new TexturedVertex(aPositionTransformVertex[1].vector3F, (float) i / textureWidth + 0.0015625F, (float) j / textureHeight + 0.003125F);
aPositionTransformVertex[2] = new TexturedVertex(aPositionTransformVertex[2].vector3F, (float) i / textureWidth + 0.0015625F, (float) l / textureHeight - 0.003125F);
aPositionTransformVertex[3] = new TexturedVertex(aPositionTransformVertex[3].vector3F, (float) k / textureWidth - 0.0015625F, (float) l / textureHeight - 0.003125F);
return new TexturedPolygon(aPositionTransformVertex);
}

private static final float degreesF = (float) (180D / Math.PI);

// Same as super, but old models have inverse Y rotations and I don't even understand the Z rotation
public void render(float worldScale, boolean invertYZ) {
if (!showModel) {
return;
}

if (!compiled) {
compileDisplayList(worldScale);
return;
}

if (rotateAngleX != 0.0F || rotateAngleY != 0.0F || rotateAngleZ != 0.0F) {
GL11.glPushMatrix();
GL11.glTranslatef(rotationPointX * worldScale, rotationPointY * worldScale, rotationPointZ * worldScale);
if (rotateAngleZ != 0.0F) {
GL11.glRotatef(rotateAngleZ * degreesF, 0.0F, 0.0F, 1.0F);
}

if (rotateAngleY != 0.0F) {
GL11.glRotatef(rotateAngleY * degreesF, 0.0F, 1.0F, 0.0F);
}

if (rotateAngleX != 0.0F) {
GL11.glRotatef(rotateAngleX * degreesF, 1.0F, 0.0F, 0.0F);
}

callDisplayList();
GL11.glPopMatrix();
} else if (rotationPointX != 0.0F || rotationPointY != 0.0F || rotationPointZ != 0.0F) {
GL11.glTranslatef(rotationPointX * worldScale, rotationPointY * worldScale, rotationPointZ * worldScale);
callDisplayList();
GL11.glTranslatef(-rotationPointX * worldScale, -rotationPointY * worldScale, -rotationPointZ * worldScale);
} else {
callDisplayList();
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/train/client/render/ItemRenderBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void renderItem(ItemRenderType type, ItemStack stack, Object... data) {

private void renderBook(float left, float up, float right, float rotation, float x, float y, float z, float scale) {
Tessellator tesselator = Tessellator.instance;
tmt.Tessellator.bindTexture(new ResourceLocation(Info.resourceLocation, Info.modelTexPrefix + "book2.png"));
fexcraft.tmt.slim.Tessellator.bindTexture(new ResourceLocation(Info.resourceLocation, Info.modelTexPrefix + "book2.png"));
GL11.glPushMatrix();
GL11.glTranslatef(left, up, right);
GL11.glRotatef(rotation, x, y, z);
Expand All @@ -93,7 +93,7 @@ private void rotateBook(float left, float up, float right, float rotation, float
// down = false;
// }
//System.out.println(w/10);
tmt.Tessellator.bindTexture(new ResourceLocation(Info.resourceLocation, Info.modelTexPrefix + "book2.png"));
fexcraft.tmt.slim.Tessellator.bindTexture(new ResourceLocation(Info.resourceLocation, Info.modelTexPrefix + "book2.png"));
GL11.glPushMatrix();
GL11.glTranslatef(left, up, right);
GL11.glTranslatef(0.5f, 1.f, -0.5f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
}

private void renderGenerator(float f, float g, float h) {
tmt.Tessellator.bindTexture(texture);
fexcraft.tmt.slim.Tessellator.bindTexture(texture);
GL11.glPushMatrix();
GL11.glTranslatef(f, g, h);
GL11.glScalef(0.7F, 0.7F, 0.7F);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/train/client/render/ItemRenderLantern.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void renderLantern(float x, float y, float z, float scale) {
GL11.glTranslatef(x, y, z);
GL11.glScalef(scale, scale, scale);

tmt.Tessellator.bindTexture(texture);
fexcraft.tmt.slim.Tessellator.bindTexture(texture);
float f2 = (float) (0x4f4e4a >> 16 & 255) / 255.0F;
float f3 = (float) (0x4f4e4a >> 8 & 255) / 255.0F;
float f4 = (float) (0x4f4e4a & 255) / 255.0F;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/train/client/render/ItemRenderSignal.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
}

private void renderSignal(float f, float g, float h, float rotation, float scale) {
tmt.Tessellator.bindTexture(texture);
fexcraft.tmt.slim.Tessellator.bindTexture(texture);
GL11.glPushMatrix(); //start
GL11.glTranslatef(f, g, h); //size
GL11.glRotatef(rotation, f, g, h);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/train/client/render/ItemRenderStopper.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
}

private void renderStopper(float f, float g, float h, float rotation) {
tmt.Tessellator.bindTexture(texture);
fexcraft.tmt.slim.Tessellator.bindTexture(texture);
GL11.glPushMatrix(); //start
GL11.glTranslatef(f, g, h); //size
GL11.glRotatef(rotation, f, g, h);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void renderWaterWheel(float x, float y, float z, float scale) {
GL11.glScalef(0.36F, 0.36F, 1F);
GL11.glRotatef(180f, 0f, 1f, 0f);

tmt.Tessellator.bindTexture(texture);
fexcraft.tmt.slim.Tessellator.bindTexture(texture);
float f2 = (float) (0x331D14 >> 16 & 255) / 255.0F;
float f3 = (float) (0x331D14 >> 8 & 255) / 255.0F;
float f4 = (float) (0x331D14 & 255) / 255.0F;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/train/client/render/ItemRenderWindMill.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void renderWindMill(float x, float y, float z, float scale) {
GL11.glTranslatef(x, y, z);
GL11.glScalef(scale, scale, scale);

tmt.Tessellator.bindTexture(new ResourceLocation(Info.resourceLocation, Info.modelTexPrefix + "water_wheel_uv.png"));
fexcraft.tmt.slim.Tessellator.bindTexture(new ResourceLocation(Info.resourceLocation, Info.modelTexPrefix + "water_wheel_uv.png"));
float f2 = (float) (0x331D14 >> 16 & 255) / 255.0F;
float f3 = (float) (0x331D14 >> 8 & 255) / 255.0F;
float f4 = (float) (0x331D14 & 255) / 255.0F;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void render(TileEntity var1, double x, double y, double z) {
GL11.glPushMatrix();

GL11.glTranslated(x, y, z);
tmt.Tessellator.bindTexture(texture);
fexcraft.tmt.slim.Tessellator.bindTexture(texture);

//System.out.println(((TileStopper) var1).getFacing());
GL11.glTranslatef(0.5F, 0.0F, 0.5F);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/train/client/render/RenderStopper.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void render(TileEntity tile, double x, double y, double z) {
GL11.glPushMatrix();

GL11.glTranslated(x, y, z);
tmt.Tessellator.bindTexture(texture);
fexcraft.tmt.slim.Tessellator.bindTexture(texture);

GL11.glTranslatef(0.5F, 0.0F, 0.5F);
modelStopper.render(0.0625F, ((TileStopper) tile).getFacing());
Expand Down
1 change: 1 addition & 0 deletions src/main/java/train/client/render/models/ModelBP4.java
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ public void render(Entity entity, float f, float f1, float f2, float f3, float f

GL11.glTranslatef(3.1f,0f,0);
bogie.render(entity, f, f1, f2, f3, f4, f5);
GL11.glScalef(1f,1f,1f);
GL11.glPopMatrix();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ public void render(Entity entity, float f, float f1, float f2, float f3, float f
GL11.glTranslated(0,-1.4f,-2.6);
GL11.glScaled(0.7,0.9,1);
super.render(entity, f, f1, f2, f3, f4, f5);
setRotationAngles(f, f1, f2, f3, f4, f5, entity);
//setRotationAngles(f, f1, f2, f3, f4, f5, entity);
Left1.render(f5);
Left2.render(f5);
Left3.render(f5);
Expand Down
93 changes: 0 additions & 93 deletions tmt/Angle3D.java

This file was deleted.

Loading

0 comments on commit 8b1df63

Please sign in to comment.