cleanup isometric head

This commit is contained in:
Lee 2024-04-11 08:08:57 +01:00
parent d9e6becebb
commit 9acb7c259a
4 changed files with 15 additions and 28 deletions

@ -115,7 +115,7 @@ public class Skin {
/** /**
* The skin part renderer for the part. * The skin part renderer for the part.
*/ */
private final SkinRenderer skinRenderer; private final SkinRenderer renderer;
/** /**
* Gets the name of the part. * Gets the name of the part.
@ -151,7 +151,7 @@ public class Skin {
HEAD(8, 8, 8, 8, null), HEAD(8, 8, 8, 8, null),
HEAD_TOP(8, 0, 8, 8, null), HEAD_TOP(8, 0, 8, 8, null),
HEAD_FRONT(8, 8, 8, 8, null), HEAD_FRONT(8, 8, 8, 8, null),
HEAD_RIGHT(0, 8, 8, 8, null), HEAD_LEFT(0, 8, 8, 8, null),
BODY(20, 20, 8, 12, null), BODY(20, 20, 8, 12, null),
BODY_BACK(20, 36, 8, 12, null), BODY_BACK(20, 36, 8, 12, null),
@ -169,7 +169,6 @@ public class Skin {
*/ */
HEAD_OVERLAY_TOP(40, 0, 8, 8, null), HEAD_OVERLAY_TOP(40, 0, 8, 8, null),
HEAD_OVERLAY_FRONT(40, 8, 8, 8, null), HEAD_OVERLAY_FRONT(40, 8, 8, 8, null),
HEAD_OVERLAY_RIGHT(32, 8, 8, 8, null),
HEAD_OVERLAY_LEFT(48, 8, 8, 8, null), HEAD_OVERLAY_LEFT(48, 8, 8, 8, null),
BODY_OVERLAY_FRONT(20, 36, 8, 12, null), BODY_OVERLAY_FRONT(20, 36, 8, 12, null),

@ -139,7 +139,7 @@ public class PlayerService {
} }
long before = System.currentTimeMillis(); long before = System.currentTimeMillis();
byte[] skinPartBytes = part.getSkinRenderer().renderPart(player.getSkin(), part.getName(), renderOverlay, size); byte[] skinPartBytes = part.getRenderer().renderPart(player.getSkin(), part.getName(), renderOverlay, size);
log.info("Took {}ms to render skin part {} for player: {}", System.currentTimeMillis() - before, part.getName(), player.getUniqueId()); log.info("Took {}ms to render skin part {} for player: {}", System.currentTimeMillis() - before, part.getName(), player.getUniqueId());
CachedPlayerSkinPart skinPart = new CachedPlayerSkinPart( CachedPlayerSkinPart skinPart = new CachedPlayerSkinPart(
key, key,

@ -7,7 +7,6 @@ import lombok.Getter;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import java.awt.*; import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@Getter @Log4j2 @Getter @Log4j2

@ -1,6 +1,5 @@
package cc.fascinated.service.skin.impl; package cc.fascinated.service.skin.impl;
import cc.fascinated.common.ImageUtils;
import cc.fascinated.model.player.Skin; import cc.fascinated.model.player.Skin;
import cc.fascinated.service.skin.SkinRenderer; import cc.fascinated.service.skin.SkinRenderer;
import lombok.Getter; import lombok.Getter;
@ -19,16 +18,15 @@ public class IsometricHeadRenderer extends SkinRenderer {
/** /**
* The head transforms * The head transforms
*/ */
private static final AffineTransform HEAD_TRANSFORM = new AffineTransform(1d, -SKEW_A, 1, SKEW_A, 0, 0); private static final AffineTransform HEAD_TOP_TRANSFORM = new AffineTransform(1D, -SKEW_A, 1, SKEW_A, 0, 0);
private static final AffineTransform FRONT_TRANSFORM = new AffineTransform(1d, -SKEW_A, 0d, SKEW_B, 0d, SKEW_A); private static final AffineTransform FACE_TRANSFORM = new AffineTransform(1D, -SKEW_A, 0D, SKEW_B, 0d, SKEW_A);
private static final AffineTransform RIGHT_TRANSFORM = new AffineTransform(1d, SKEW_A, 0d, SKEW_B, 0d, 0d); private static final AffineTransform HEAD_LEFT_TRANSFORM = new AffineTransform(1D, SKEW_A, 0D, SKEW_B, 0D, 0D);
@Override @Override
public byte[] renderPart(Skin skin, String partName, boolean renderOverlay, int size) { public byte[] renderPart(Skin skin, String partName, boolean renderOverlay, int size) {
double scale = (size / 8d) / 2.5; double scale = (size / 8d) / 2.5;
log.info("Getting {} part bytes for {} with size {} and scale {}", partName, skin.getUrl(), size, scale); log.info("Getting {} part bytes for {} with size {} and scale {}", partName, skin.getUrl(), size, scale);
double x, y, z; // The x, y, and z positions
double zOffset = scale * 3.5d; double zOffset = scale * 3.5d;
double xOffset = scale * 2d; double xOffset = scale * 2d;
BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
@ -37,32 +35,23 @@ public class IsometricHeadRenderer extends SkinRenderer {
// Get all the required head parts // Get all the required head parts
BufferedImage headTop = this.getSkinPart(skin, Skin.PartPosition.HEAD_TOP, scale); BufferedImage headTop = this.getSkinPart(skin, Skin.PartPosition.HEAD_TOP, scale);
BufferedImage headFront = this.getSkinPart(skin, Skin.PartPosition.HEAD_FRONT, scale); BufferedImage headFront = this.getSkinPart(skin, Skin.PartPosition.HEAD_FRONT, scale);
BufferedImage headRight = this.getSkinPart(skin, Skin.PartPosition.HEAD_RIGHT, scale); BufferedImage headLeft = this.getSkinPart(skin, Skin.PartPosition.HEAD_LEFT, scale);
if (renderOverlay) { // Render the skin layers if (renderOverlay) { // Render the skin layers
applyOverlay(headTop, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_TOP, scale)); applyOverlay(headTop, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_TOP, scale));
applyOverlay(headFront, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_FRONT, scale)); applyOverlay(headFront, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_FRONT, scale));
applyOverlay(headRight, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_RIGHT, scale)); applyOverlay(headLeft, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_LEFT, scale));
} }
// Draw the top of the head // Draw the top of the left
x = xOffset; drawPart(graphics, headTop, HEAD_TOP_TRANSFORM, -0.5 - zOffset, xOffset + zOffset, headTop.getWidth(), headTop.getHeight() + 2);
y = -0.5;
z = zOffset;
// The head is offset by 2 pixels for whatever reason
drawPart(graphics, headTop, HEAD_TRANSFORM, y - z, x + z, headTop.getWidth(), headTop.getHeight() + 2);
// Draw the front of the head // Draw the face of the head
x = xOffset + 8 * scale; double x = xOffset + 8 * scale;
y = 0; drawPart(graphics, headFront, FACE_TRANSFORM, x, x + zOffset - 0.5, headFront.getWidth(), headFront.getHeight());
z = zOffset - 0.5;
drawPart(graphics, headFront, FRONT_TRANSFORM, y + x, x + z, headFront.getWidth(), headFront.getHeight());
// Draw the right side of the head // Draw the left side of the head
x = xOffset; drawPart(graphics, headLeft, HEAD_LEFT_TRANSFORM, xOffset + 1, zOffset - 0.5, headLeft.getWidth(), headLeft.getHeight());
y = 0;
z = zOffset;
drawPart(graphics, headRight, RIGHT_TRANSFORM, x + y + 1, z - y - 0.5, headRight.getWidth(), headRight.getHeight());
return super.getBytes(outputImage, skin, partName); return super.getBytes(outputImage, skin, partName);
} }