Assign UV in the model and use spriteBake

This commit is contained in:
quat1024 2023-07-02 05:15:28 -04:00
parent b257241b5e
commit 0c4a7f1ed8
2 changed files with 23 additions and 80 deletions

View File

@ -23,22 +23,27 @@ public class SlopeBaseMesh {
qu.tag(TAG_SLOPE) qu.tag(TAG_SLOPE)
.pos(0, 0f, 0f, 0f).pos(1, 0f, 1f, 1f).pos(2, 1f, 1f, 1f).pos(3, 1f, 0f, 0f) .pos(0, 0f, 0f, 0f).pos(1, 0f, 1f, 1f).pos(2, 1f, 1f, 1f).pos(3, 1f, 0f, 0f)
.color(-1, -1, -1, -1) .color(-1, -1, -1, -1)
.uv(0, 1f, 1f).uv(1, 1f, 0f).uv(2, 0f, 0f).uv(3, 0f, 1f)
.emit() .emit()
.tag(TAG_LEFT) .tag(TAG_LEFT)
.pos(0, 1f, 0f, 0f).pos(1, 1f, 1f, 1f).pos(2, 1f, 0f, 1f).pos(3, 1f, 0f, 1f) .pos(0, 1f, 0f, 0f).pos(1, 1f, 1f, 1f).pos(2, 1f, 0f, 1f).pos(3, 1f, 0f, 1f)
.color(-1, -1, -1, -1) .color(-1, -1, -1, -1)
.uv(0, 1f, 0f).uv(1, 0f, 0f).uv(2, 0f, 1f).uv(3, 1f, 1f)
.emit() .emit()
.tag(TAG_RIGHT) .tag(TAG_RIGHT)
.pos(0, 0f, 0f, 0f).pos(1, 0f, 0f, 0f).pos(2, 0f, 0f, 1f).pos(3, 0f, 1f, 1f) .pos(0, 0f, 0f, 0f).pos(1, 0f, 0f, 0f).pos(2, 0f, 0f, 1f).pos(3, 0f, 1f, 1f)
.color(-1, -1, -1, -1) .color(-1, -1, -1, -1)
.uv(0, 0f, 0f).uv(1, 0f, 1f).uv(2, 1f, 1f).uv(3, 1f, 0f)
.emit() .emit()
.tag(TAG_BACK) .tag(TAG_BACK)
.pos(0, 0f, 0f, 1f).pos(1, 1f, 0f, 1f).pos(2, 1f, 1f, 1f).pos(3, 0f, 1f, 1f) .pos(0, 0f, 0f, 1f).pos(1, 1f, 0f, 1f).pos(2, 1f, 1f, 1f).pos(3, 0f, 1f, 1f)
.color(-1, -1, -1, -1) .color(-1, -1, -1, -1)
.uv(0, 0f, 1f).uv(1, 1f, 1f).uv(2, 1f, 0f).uv(3, 0f, 0f)
.emit() .emit()
.tag(TAG_BOTTOM) .tag(TAG_BOTTOM)
.pos(0, 0f, 0f, 0f).pos(1, 1f, 0f, 0f).pos(2, 1f, 0f, 1f).pos(3, 0f, 0f, 1f) .pos(0, 0f, 0f, 0f).pos(1, 1f, 0f, 0f).pos(2, 1f, 0f, 1f).pos(3, 0f, 0f, 1f)
.color(-1, -1, -1, -1) .color(-1, -1, -1, -1)
.uv(0, 0f, 1f).uv(1, 1f, 1f).uv(2, 1f, 0f).uv(3, 0f, 0f)
.emit(); .emit();
return builder.build(); return builder.build();
} }

View File

@ -64,112 +64,50 @@ public class SlopeQuadTransformFactory implements TemplateQuadTransformFactory {
else globalTint = 0xFFFFFF; else globalTint = 0xFFFFFF;
} }
return new Transformer(dir, appearance, material, globalTint); return new Transformer(appearance, material, globalTint);
} }
@Override @Override
public @NotNull RenderContext.QuadTransform itemTransformer(ItemStack stack, Supplier<Random> randomSupplier) { public @NotNull RenderContext.QuadTransform itemTransformer(ItemStack stack, Supplier<Random> randomSupplier) {
return new Transformer(Direction.EAST, tam.getDefaultAppearance(), r.materialFinder().clear().find(), 0xFFFFFF); return new Transformer(tam.getDefaultAppearance(), r.materialFinder().clear().find(), 0xFFFFFF);
} }
private static record Transformer(Direction dir, TemplateAppearance appearance, RenderMaterial material, int color) implements RenderContext.QuadTransform { private static record Transformer(TemplateAppearance appearance, RenderMaterial material, int color) implements RenderContext.QuadTransform {
@Override @Override
public boolean transform(MutableQuadView quad) { public boolean transform(MutableQuadView quad) {
quad.material(material); quad.material(material);
Sprite sprite = null;
//TODO: this newly-simplified direction passing in hasColor is almost certainly incorrect
switch(quad.tag()) { switch(quad.tag()) {
case SlopeBaseMesh.TAG_SLOPE -> { case SlopeBaseMesh.TAG_SLOPE -> {
if(appearance.hasColor(Direction.UP)) quad.color(color, color, color, color); if(appearance.hasColor(Direction.UP)) quad.color(color, color, color, color);
paintSlope(quad, appearance.getSprite(Direction.UP)); sprite = appearance.getSprite(Direction.UP);
} }
case SlopeBaseMesh.TAG_LEFT -> { case SlopeBaseMesh.TAG_LEFT -> {
final Direction leftDir = this.dir.rotateYCounterclockwise(); if(appearance.hasColor(Direction.EAST)) quad.color(color, color, color, color);
if(appearance.hasColor(leftDir)) quad.color(color, color, color, color); sprite = appearance.getSprite(Direction.EAST);
paintLeftSide(quad, appearance.getSprite(leftDir));
} }
case SlopeBaseMesh.TAG_RIGHT -> { case SlopeBaseMesh.TAG_RIGHT -> {
final Direction rightDir = this.dir.rotateYClockwise(); if(appearance.hasColor(Direction.WEST)) quad.color(color, color, color, color);
if(appearance.hasColor(rightDir)) quad.color(color, color, color, color); sprite = appearance.getSprite(Direction.WEST);
paintRightSide(quad, appearance.getSprite(rightDir));
} }
case SlopeBaseMesh.TAG_BACK -> { case SlopeBaseMesh.TAG_BACK -> {
if(appearance.hasColor(dir)) quad.color(color, color, color, color); if(appearance.hasColor(Direction.SOUTH)) quad.color(color, color, color, color);
paintBack(quad, appearance.getSprite(dir)); sprite = appearance.getSprite(Direction.SOUTH);
} }
case SlopeBaseMesh.TAG_BOTTOM -> { case SlopeBaseMesh.TAG_BOTTOM -> {
if(appearance.hasColor(Direction.DOWN)) quad.color(color, color, color, color); if(appearance.hasColor(Direction.DOWN)) quad.color(color, color, color, color);
paintBottom(quad, appearance.getSprite(Direction.DOWN)); sprite = appearance.getSprite(Direction.DOWN);
} }
} }
if(sprite == null) return false; //remove this quad
quad.spriteBake(sprite, MutableQuadView.BAKE_NORMALIZED);
return true; return true;
} }
private void paintSlope(MutableQuadView quad, Sprite sprite) {
switch(dir) {
case NORTH -> quad.uv(0, sprite.getMinU(), sprite.getMinV())
.uv(1, sprite.getMinU(), sprite.getMaxV())
.uv(2, sprite.getMaxU(), sprite.getMaxV())
.uv(3, sprite.getMaxU(), sprite.getMinV());
case SOUTH -> quad.uv(0, sprite.getMaxU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMinV())
.uv(2, sprite.getMinU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMaxV());
case EAST -> quad.uv(0, sprite.getMinU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMaxV())
.uv(2, sprite.getMaxU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMinV());
case WEST -> quad.uv(0, sprite.getMaxU(), sprite.getMinV())
.uv(1, sprite.getMinU(), sprite.getMinV())
.uv(2, sprite.getMinU(), sprite.getMaxV())
.uv(3, sprite.getMaxU(), sprite.getMaxV());
}
}
private void paintLeftSide(MutableQuadView quad, Sprite sprite) {
switch(dir) {
case NORTH, EAST, WEST -> quad.uv(0, sprite.getMinU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMaxV())
.uv(2, sprite.getMaxU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMinV());
case SOUTH -> quad.uv(0, sprite.getMaxU(), sprite.getMinV())
.uv(1, sprite.getMinU(), sprite.getMinV())
.uv(2, sprite.getMinU(), sprite.getMaxV())
.uv(3, sprite.getMaxU(), sprite.getMaxV());
}
}
private void paintRightSide(MutableQuadView quad, Sprite sprite) {
switch(dir) {
case NORTH, WEST -> quad.uv(0, sprite.getMaxU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMinV())
.uv(2, sprite.getMinU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMaxV());
case SOUTH, EAST -> quad.uv(0, sprite.getMinU(), sprite.getMinV())
.uv(1, sprite.getMinU(), sprite.getMaxV())
.uv(2, sprite.getMaxU(), sprite.getMaxV())
.uv(3, sprite.getMaxU(), sprite.getMinV());
}
}
private void paintBack(MutableQuadView quad, Sprite sprite) {
switch(dir) {
case NORTH, EAST -> quad.uv(0, sprite.getMaxU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMinV())
.uv(2, sprite.getMinU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMaxV());
case SOUTH, WEST -> quad.uv(0, sprite.getMinU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMaxV())
.uv(2, sprite.getMaxU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMinV());
}
}
private void paintBottom(MutableQuadView quad, Sprite sprite) {
quad.uv(0, sprite.getMinU(), sprite.getMaxV())
.uv(1, sprite.getMaxU(), sprite.getMaxV())
.uv(2, sprite.getMaxU(), sprite.getMinV())
.uv(3, sprite.getMinU(), sprite.getMinV());
}
} }
} }