Utilities created during an attempt at signs

- Cuboids can be inverted across Y and Z
 - TransformStack scaling
 - VecBuffer coloring
This commit is contained in:
Jozufozu 2021-07-17 17:05:49 -07:00
parent b0d317f9a2
commit 04b906d06f
7 changed files with 83 additions and 18 deletions

View file

@ -89,6 +89,14 @@ public class VecBuffer {
return this; return this;
} }
public VecBuffer putColor(int r, int g, int b, int a) {
internal.put((byte) r);
internal.put((byte) g);
internal.put((byte) b);
internal.put((byte) a);
return this;
}
public VecBuffer putVec3(float x, float y, float z) { public VecBuffer putVec3(float x, float y, float z) {
internal.putFloat(x); internal.putFloat(x);
internal.putFloat(y); internal.putFloat(y);

View file

@ -84,6 +84,8 @@ public class PartBuilder {
float posY2; float posY2;
float posZ2; float posZ2;
boolean invertYZ;
final PartBuilder partBuilder; final PartBuilder partBuilder;
CuboidBuilder(PartBuilder partBuilder) { CuboidBuilder(PartBuilder partBuilder) {
@ -123,6 +125,16 @@ public class PartBuilder {
return this; return this;
} }
/**
* Pulls the cuboid "inside out" through the Y and Z axes.
*
* See the {@link com.jozufozu.flywheel.vanilla.SignInstance sign} renderer for the use case.
*/
public CuboidBuilder invertYZ() {
this.invertYZ = true;
return this;
}
public PartBuilder endCuboid() { public PartBuilder endCuboid() {
return partBuilder.addCuboid(this); return partBuilder.addCuboid(this);
} }
@ -137,14 +149,21 @@ public class PartBuilder {
float sizeY = posY2 - posY1; float sizeY = posY2 - posY1;
float sizeZ = posZ2 - posZ1; float sizeZ = posZ2 - posZ1;
Vector3f lll = new Vector3f(posX1 / 16f, posY1 / 16f, posZ1 / 16f); float posX1 = this.posX1 / 16f;
Vector3f hll = new Vector3f(posX2 / 16f, posY1 / 16f, posZ1 / 16f); float posY1 = this.posY1 / 16f;
Vector3f hhl = new Vector3f(posX2 / 16f, posY2 / 16f, posZ1 / 16f); float posZ1 = this.posZ1 / 16f;
Vector3f lhl = new Vector3f(posX1 / 16f, posY2 / 16f, posZ1 / 16f); float posX2 = this.posX2 / 16f;
Vector3f llh = new Vector3f(posX1 / 16f, posY1 / 16f, posZ2 / 16f); float posY2 = this.posY2 / 16f;
Vector3f hlh = new Vector3f(posX2 / 16f, posY1 / 16f, posZ2 / 16f); float posZ2 = this.posZ2 / 16f;
Vector3f hhh = new Vector3f(posX2 / 16f, posY2 / 16f, posZ2 / 16f);
Vector3f lhh = new Vector3f(posX1 / 16f, posY2 / 16f, posZ2 / 16f); Vector3f lll = new Vector3f(posX1, posY1, posZ1);
Vector3f hll = new Vector3f(posX2, posY1, posZ1);
Vector3f hhl = new Vector3f(posX2, posY2, posZ1);
Vector3f lhl = new Vector3f(posX1, posY2, posZ1);
Vector3f llh = new Vector3f(posX1, posY1, posZ2);
Vector3f hlh = new Vector3f(posX2, posY1, posZ2);
Vector3f hhh = new Vector3f(posX2, posY2, posZ2);
Vector3f lhh = new Vector3f(posX1, posY2, posZ2);
float f4 = getU((float)textureOffsetU); float f4 = getU((float)textureOffsetU);
float f5 = getU((float)textureOffsetU + sizeZ); float f5 = getU((float)textureOffsetU + sizeZ);
float f6 = getU((float)textureOffsetU + sizeZ + sizeX); float f6 = getU((float)textureOffsetU + sizeZ + sizeX);
@ -155,6 +174,14 @@ public class PartBuilder {
float f11 = getV((float)textureOffsetV + sizeZ); float f11 = getV((float)textureOffsetV + sizeZ);
float f12 = getV((float)textureOffsetV + sizeZ + sizeY); float f12 = getV((float)textureOffsetV + sizeZ + sizeY);
if (invertYZ) {
quad(buffer, new Vector3f[]{hlh, llh, lll, hll}, f6, f11, f7, f10, Direction.DOWN);
quad(buffer, new Vector3f[]{hhl, lhl, lhh, hhh}, f5, f10, f6, f11, Direction.UP);
quad(buffer, new Vector3f[]{lll, llh, lhh, lhl}, f5, f12, f4, f11, Direction.WEST);
quad(buffer, new Vector3f[]{hll, lll, lhl, hhl}, f9, f12, f8, f11, Direction.NORTH);
quad(buffer, new Vector3f[]{hlh, hll, hhl, hhh}, f8, f12, f6, f11, Direction.EAST);
quad(buffer, new Vector3f[]{llh, hlh, hhh, lhh}, f6, f12, f5, f11, Direction.SOUTH);
} else {
quad(buffer, new Vector3f[]{hlh, llh, lll, hll}, f5, f10, f6, f11, Direction.DOWN); quad(buffer, new Vector3f[]{hlh, llh, lll, hll}, f5, f10, f6, f11, Direction.DOWN);
quad(buffer, new Vector3f[]{hhl, lhl, lhh, hhh}, f6, f11, f7, f10, Direction.UP); quad(buffer, new Vector3f[]{hhl, lhl, lhh, hhh}, f6, f11, f7, f10, Direction.UP);
quad(buffer, new Vector3f[]{lll, llh, lhh, lhl}, f4, f11, f5, f12, Direction.WEST); quad(buffer, new Vector3f[]{lll, llh, lhh, lhl}, f4, f11, f5, f12, Direction.WEST);
@ -162,6 +189,7 @@ public class PartBuilder {
quad(buffer, new Vector3f[]{hlh, hll, hhl, hhh}, f6, f11, f8, f12, Direction.EAST); quad(buffer, new Vector3f[]{hlh, hll, hhl, hhh}, f6, f11, f8, f12, Direction.EAST);
quad(buffer, new Vector3f[]{llh, hlh, hhh, lhh}, f8, f11, f9, f12, Direction.SOUTH); quad(buffer, new Vector3f[]{llh, hlh, hhh, lhh}, f8, f11, f9, f12, Direction.SOUTH);
} }
}
public void quad(VecBuffer buffer, Vector3f[] vertices, float minU, float minV, float maxU, float maxV, Direction dir) { public void quad(VecBuffer buffer, Vector3f[] vertices, float minU, float minV, float maxU, float maxV, Direction dir) {

View file

@ -10,6 +10,20 @@ import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.util.math.vector.Vector3f; import net.minecraft.util.math.vector.Vector3f;
public class RenderUtil { public class RenderUtil {
private static final Matrix4f IDENTITY = new Matrix4f();
static {
IDENTITY.setIdentity();
}
public static Matrix4f getIdentity() {
return IDENTITY;
}
public static Matrix4f copyIdentity() {
return IDENTITY.copy();
}
public static int nextPowerOf2(int a) { public static int nextPowerOf2(int a) {
int h = Integer.highestOneBit(a); int h = Integer.highestOneBit(a);
return (h == a) ? h : (h << 1); return (h == a) ? h : (h << 1);

View file

@ -24,13 +24,21 @@ public class MatrixTransformStack implements TransformStack {
return this; return this;
} }
@Override
public TransformStack scale(float factor) {
internal.scale(factor, factor, factor);
return this;
}
@Override @Override
public TransformStack push() { public TransformStack push() {
internal.pushPose();
return this; return this;
} }
@Override @Override
public TransformStack pop() { public TransformStack pop() {
internal.popPose();
return this; return this;
} }
} }

View file

@ -41,6 +41,11 @@ public class QuaternionTransformStack implements TransformStack {
return this; return this;
} }
@Override
public TransformStack scale(float factor) {
return this;
}
@Override @Override
public TransformStack pop() { public TransformStack pop() {

View file

@ -13,6 +13,8 @@ public interface TransformStack {
TransformStack multiply(Quaternion quaternion); TransformStack multiply(Quaternion quaternion);
TransformStack scale(float factor);
TransformStack push(); TransformStack push();
TransformStack pop(); TransformStack pop();

View file

@ -7,21 +7,21 @@ import net.minecraft.tileentity.TileEntityType;
/** /**
* TODO: * TODO:
* <table> * <table>
* <tr><td>{@link TileEntityType#SHULKER_BOX}</td><td> {@link net.minecraft.client.renderer.tileentity.ShulkerBoxTileEntityRenderer ShulkerBoxTileEntityRenderer}</td></tr>
* <tr><td>{@link TileEntityType#SIGN}</td><td> {@link net.minecraft.client.renderer.tileentity.SignTileEntityRenderer SignTileEntityRenderer}</td></tr> * <tr><td>{@link TileEntityType#SIGN}</td><td> {@link net.minecraft.client.renderer.tileentity.SignTileEntityRenderer SignTileEntityRenderer}</td></tr>
* <tr><td>{@link TileEntityType#MOB_SPAWNER}</td><td> {@link net.minecraft.client.renderer.tileentity.MobSpawnerTileEntityRenderer MobSpawnerTileEntityRenderer}</td></tr>
* <tr><td>{@link TileEntityType#PISTON}</td><td> {@link net.minecraft.client.renderer.tileentity.PistonTileEntityRenderer PistonTileEntityRenderer}</td></tr> * <tr><td>{@link TileEntityType#PISTON}</td><td> {@link net.minecraft.client.renderer.tileentity.PistonTileEntityRenderer PistonTileEntityRenderer}</td></tr>
* <tr><td>{@link TileEntityType#CONDUIT}</td><td> {@link net.minecraft.client.renderer.tileentity.ConduitTileEntityRenderer ConduitTileEntityRenderer}</td></tr>
* <tr><td>{@link TileEntityType#ENCHANTING_TABLE}</td><td> {@link net.minecraft.client.renderer.tileentity.EnchantmentTableTileEntityRenderer EnchantmentTableTileEntityRenderer}</td></tr> * <tr><td>{@link TileEntityType#ENCHANTING_TABLE}</td><td> {@link net.minecraft.client.renderer.tileentity.EnchantmentTableTileEntityRenderer EnchantmentTableTileEntityRenderer}</td></tr>
* <tr><td>{@link TileEntityType#LECTERN}</td><td> {@link net.minecraft.client.renderer.tileentity.LecternTileEntityRenderer LecternTileEntityRenderer}</td></tr> * <tr><td>{@link TileEntityType#LECTERN}</td><td> {@link net.minecraft.client.renderer.tileentity.LecternTileEntityRenderer LecternTileEntityRenderer}</td></tr>
* <tr><td>{@link TileEntityType#MOB_SPAWNER}</td><td> {@link net.minecraft.client.renderer.tileentity.MobSpawnerTileEntityRenderer MobSpawnerTileEntityRenderer}</td></tr>
* <tr><td>^^ Interesting - Major vv</td></tr>
* <tr><td>{@link TileEntityType#END_PORTAL}</td><td> {@link net.minecraft.client.renderer.tileentity.EndPortalTileEntityRenderer EndPortalTileEntityRenderer}</td></tr> * <tr><td>{@link TileEntityType#END_PORTAL}</td><td> {@link net.minecraft.client.renderer.tileentity.EndPortalTileEntityRenderer EndPortalTileEntityRenderer}</td></tr>
* <tr><td>{@link TileEntityType#END_GATEWAY}</td><td> {@link net.minecraft.client.renderer.tileentity.EndGatewayTileEntityRenderer EndGatewayTileEntityRenderer}</td></tr> * <tr><td>{@link TileEntityType#END_GATEWAY}</td><td> {@link net.minecraft.client.renderer.tileentity.EndGatewayTileEntityRenderer EndGatewayTileEntityRenderer}</td></tr>
* <tr><td>{@link TileEntityType#BEACON}</td><td> {@link net.minecraft.client.renderer.tileentity.BeaconTileEntityRenderer BeaconTileEntityRenderer}</td></tr> * <tr><td>{@link TileEntityType#BEACON}</td><td> {@link net.minecraft.client.renderer.tileentity.BeaconTileEntityRenderer BeaconTileEntityRenderer}</td></tr>
* <tr><td>{@link TileEntityType#SKULL}</td><td> {@link net.minecraft.client.renderer.tileentity.SkullTileEntityRenderer SkullTileEntityRenderer}</td></tr> * <tr><td>{@link TileEntityType#SKULL}</td><td> {@link net.minecraft.client.renderer.tileentity.SkullTileEntityRenderer SkullTileEntityRenderer}</td></tr>
* <tr><td>{@link TileEntityType#BANNER}</td><td> {@link net.minecraft.client.renderer.tileentity.BannerTileEntityRenderer BannerTileEntityRenderer}</td></tr> * <tr><td>{@link TileEntityType#BANNER}</td><td> {@link net.minecraft.client.renderer.tileentity.BannerTileEntityRenderer BannerTileEntityRenderer}</td></tr>
* <tr><td>{@link TileEntityType#STRUCTURE_BLOCK}</td><td> {@link net.minecraft.client.renderer.tileentity.StructureTileEntityRenderer StructureTileEntityRenderer}</td></tr> * <tr><td>{@link TileEntityType#STRUCTURE_BLOCK}</td><td> {@link net.minecraft.client.renderer.tileentity.StructureTileEntityRenderer StructureTileEntityRenderer}</td></tr>
* <tr><td>{@link TileEntityType#SHULKER_BOX}</td><td> {@link net.minecraft.client.renderer.tileentity.ShulkerBoxTileEntityRenderer ShulkerBoxTileEntityRenderer}</td></tr>
* <tr><td>{@link TileEntityType#BED}</td><td> {@link net.minecraft.client.renderer.tileentity.BedTileEntityRenderer BedTileEntityRenderer}</td></tr> * <tr><td>{@link TileEntityType#BED}</td><td> {@link net.minecraft.client.renderer.tileentity.BedTileEntityRenderer BedTileEntityRenderer}</td></tr>
* <tr><td>{@link TileEntityType#CONDUIT}</td><td> {@link net.minecraft.client.renderer.tileentity.ConduitTileEntityRenderer ConduitTileEntityRenderer}</td></tr>
* <tr><td>{@link TileEntityType#BELL}</td><td> {@link net.minecraft.client.renderer.tileentity.BellTileEntityRenderer BellTileEntityRenderer}</td></tr>
* <tr><td>{@link TileEntityType#CAMPFIRE}</td><td> {@link net.minecraft.client.renderer.tileentity.CampfireTileEntityRenderer CampfireTileEntityRenderer}</td></tr> * <tr><td>{@link TileEntityType#CAMPFIRE}</td><td> {@link net.minecraft.client.renderer.tileentity.CampfireTileEntityRenderer CampfireTileEntityRenderer}</td></tr>
* </table> * </table>
*/ */