use of riskyken.armourersWorkshop.api.common.skin.Rectangle3D in project Armourers-Workshop by RiskyKen.
the class SkinItemRenderHelper method renderSkinAsItem.
public static void renderSkinAsItem(Skin skin, ISkinPointer skinPointer, boolean showSkinPaint, boolean doLodLoading, int targetWidth, int targetHeight) {
if (skin == null) {
return;
}
float blockScale = 16F;
float mcScale = 1F / blockScale;
ArrayList<IRectangle3D> boundsParts = new ArrayList<IRectangle3D>();
ArrayList<IRectangle3D> boundsTextures = new ArrayList<IRectangle3D>();
IRectangle3D boundsTexture = null;
for (int i = 0; i < skin.getPartCount(); i++) {
SkinPart skinPart = skin.getParts().get(i);
if (!(skin.getSkinType() == SkinTypeRegistry.skinBow && i > 0)) {
Rectangle3D bounds = skinPart.getPartBounds();
IPoint3D offset = skinPart.getPartType().getItemRenderOffset();
Rectangle3D rec = new Rectangle3D(bounds.getX() + offset.getX(), bounds.getY() + offset.getY(), bounds.getZ() + offset.getZ(), bounds.getWidth(), bounds.getHeight(), bounds.getDepth());
boundsParts.add(rec);
}
}
if (skin.hasPaintData()) {
ArrayList<ISkinPartType> parts = skin.getSkinType().getSkinParts();
for (int i = 0; i < parts.size(); i++) {
ISkinPartType part = parts.get(i);
if (part instanceof ISkinPartTypeTextured) {
if (part.getItemRenderTextureBounds() != null) {
boundsTextures.add(part.getItemRenderTextureBounds());
}
}
}
}
int minX = 256;
int minY = 256;
int minZ = 256;
int maxX = -256;
int maxY = -256;
int maxZ = -256;
for (int i = 0; i < boundsParts.size(); i++) {
IRectangle3D rec = boundsParts.get(i);
minX = Math.min(minX, rec.getX());
minY = Math.min(minY, rec.getY());
minZ = Math.min(minZ, rec.getZ());
maxX = Math.max(maxX, rec.getWidth() + rec.getX());
maxY = Math.max(maxY, rec.getHeight() + rec.getY());
maxZ = Math.max(maxZ, rec.getDepth() + rec.getZ());
}
for (int i = 0; i < boundsTextures.size(); i++) {
IRectangle3D rec = boundsTextures.get(i);
minX = Math.min(minX, rec.getX());
minY = Math.min(minY, rec.getY());
minZ = Math.min(minZ, rec.getZ());
maxX = Math.max(maxX, rec.getWidth() + rec.getX());
maxY = Math.max(maxY, rec.getHeight() + rec.getY());
maxZ = Math.max(maxZ, rec.getDepth() + rec.getZ());
}
Rectangle3D maxBounds = new Rectangle3D(minX, minY, minZ, maxX - minX, maxY - minY, maxZ - minZ);
GL11.glPushMatrix();
if (debugSpin) {
float angle = (((System.currentTimeMillis() / 10) % 360));
GL11.glRotatef(angle, 0, 1, 0);
}
// Target bounds
if (debugShowTargetBounds) {
drawBounds(new Rectangle3D(-targetWidth / 2, -targetHeight / 2, -targetWidth / 2, targetWidth, targetHeight, targetWidth), 0, 0, 255);
}
int biggerSize = Math.max(maxBounds.getWidth(), maxBounds.getHeight());
biggerSize = Math.max(biggerSize, maxBounds.getDepth());
float newScaleW = (float) targetWidth / Math.max(maxBounds.getWidth(), maxBounds.getDepth());
float newScaleH = (float) targetHeight / maxBounds.getHeight();
float newScale = Math.min(newScaleW, newScaleH);
GL11.glScalef(newScale, newScale, newScale);
// Center the skin
GL11.glTranslated(-(maxBounds.getWidth() / 2F + maxBounds.getX()) * mcScale, 0, 0);
GL11.glTranslated(0, -(maxBounds.getHeight() / 2F + maxBounds.getY()) * mcScale, 0);
GL11.glTranslated(0, 0, -(maxBounds.getDepth() / 2F + maxBounds.getZ()) * mcScale);
renderSkinWithHelper(skin, skinPointer, showSkinPaint, doLodLoading);
if (debugShowFullBounds) {
drawBounds(maxBounds, 255, 255, 0);
}
if (debugShowPartBounds) {
for (int i = 0; i < boundsParts.size(); i++) {
drawBounds(boundsParts.get(i), 255, 0, 0);
}
}
if (debugShowTextureBounds) {
for (int i = 0; i < boundsTextures.size(); i++) {
drawBounds(boundsTextures.get(i), 0, 255, 0);
}
}
GL11.glPopMatrix();
}
use of riskyken.armourersWorkshop.api.common.skin.Rectangle3D in project Armourers-Workshop by RiskyKen.
the class SkinBaker method cullFacesOnEquipmentPart.
public static int[][][] cullFacesOnEquipmentPart(SkinPart skinPart) {
SkinCubeData cubeData = skinPart.getCubeData();
cubeData.setupFaceFlags();
skinPart.getClientSkinPartData().totalCubesInPart = new int[CubeRegistry.INSTANCE.getTotalCubes()];
Rectangle3D pb = skinPart.getPartBounds();
int[][][] cubeArray = new int[pb.getWidth()][pb.getHeight()][pb.getDepth()];
int updates = 0;
for (int i = 0; i < cubeData.getCubeCount(); i++) {
int cubeId = cubeData.getCubeId(i);
byte[] cubeLoc = cubeData.getCubeLocation(i);
skinPart.getClientSkinPartData().totalCubesInPart[cubeId] += 1;
int x = (int) cubeLoc[0] - pb.getX();
int y = (int) cubeLoc[1] - pb.getY();
int z = (int) cubeLoc[2] - pb.getZ();
cubeArray[x][y][z] = i + 1;
if (ConfigHandlerClient.slowModelBaking) {
updates++;
if (updates > 40) {
try {
Thread.sleep(1);
updates = 0;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
ArrayList<CubeLocation> openList = new ArrayList<CubeLocation>();
HashSet<Integer> closedSet = new HashSet<Integer>();
CubeLocation startCube = new CubeLocation(-1, -1, -1);
openList.add(startCube);
closedSet.add(startCube.hashCode());
while (openList.size() > 0) {
CubeLocation cl = openList.get(openList.size() - 1);
openList.remove(openList.size() - 1);
ArrayList<CubeLocation> foundLocations = checkCubesAroundLocation(cubeData, cl, pb, cubeArray);
for (int i = 0; i < foundLocations.size(); i++) {
CubeLocation foundLocation = foundLocations.get(i);
if (!closedSet.contains(foundLocation.hashCode())) {
closedSet.add(foundLocation.hashCode());
if (isCubeInSearchArea(foundLocation, pb)) {
openList.add(foundLocation);
}
}
}
if (ConfigHandlerClient.slowModelBaking) {
updates++;
if (updates > 40) {
try {
Thread.sleep(1);
updates = 0;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
return cubeArray;
}
use of riskyken.armourersWorkshop.api.common.skin.Rectangle3D in project Armourers-Workshop by RiskyKen.
the class TileEntitySkinnable method getBlockBounds.
public static float[] getBlockBounds(Skin skin, int gridX, int gridY, int gridZ, ForgeDirection dir) {
float[] bounds = new float[6];
float scale = 0.0625F;
SkinPart skinPart = skin.getParts().get(0);
gridX = MathHelper.clamp_int(gridX, 0, 2);
gridY = MathHelper.clamp_int(gridY, 0, 2);
gridZ = MathHelper.clamp_int(gridZ, 0, 2);
Rectangle3D rec = skinPart.getBlockBounds(gridX, gridY, gridZ);
switch(dir) {
case NORTH:
// rec = skinPart.getBlockBounds(gridX, gridY, 2 - gridZ);
break;
case EAST:
rec = skinPart.getBlockBounds(2 - gridZ, gridY, gridX);
break;
case SOUTH:
rec = skinPart.getBlockBounds(2 - gridX, gridY, 2 - gridZ);
break;
case WEST:
rec = skinPart.getBlockBounds(gridZ, gridY, 2 - gridX);
break;
default:
break;
}
if (rec != null) {
int x = 8 + rec.getX();
int y = 8 - rec.getHeight() - rec.getY();
int z = 8 - rec.getDepth() - rec.getZ();
bounds[0] = x * scale;
bounds[1] = y * scale;
bounds[2] = z * scale;
bounds[3] = (x + rec.getWidth()) * scale;
bounds[4] = (y + rec.getHeight()) * scale;
bounds[5] = (z + rec.getDepth()) * scale;
bounds = rotateBlockBounds(bounds, dir);
} else {
return null;
}
return bounds;
}
use of riskyken.armourersWorkshop.api.common.skin.Rectangle3D in project Armourers-Workshop by RiskyKen.
the class Skin method getSkinBounds.
@SideOnly(Side.CLIENT)
public Rectangle3D getSkinBounds() {
int x = 0;
int y = 0;
int z = 0;
int width = 1;
int height = 1;
int depth = 1;
for (int i = 0; i < getPartCount(); i++) {
if (!(getSkinType() == SkinTypeRegistry.skinBow && i > 0)) {
SkinPart skinPart = getParts().get(i);
Rectangle3D bounds = skinPart.getPartBounds();
width = Math.max(width, bounds.getWidth());
height = Math.max(height, bounds.getHeight());
depth = Math.max(depth, bounds.getDepth());
x = bounds.getX();
y = bounds.getY();
z = bounds.getZ();
if (hasPaintData()) {
IRectangle3D skinRec = skinPart.getPartType().getGuideSpace();
width = Math.max(width, skinRec.getWidth());
height = Math.max(height, skinRec.getHeight());
depth = Math.max(depth, skinRec.getDepth());
x = Math.max(x, skinRec.getX());
y = Math.max(y, skinRec.getY());
z = Math.max(z, skinRec.getZ());
}
}
}
if (getPartCount() == 0) {
for (int i = 0; i < getSkinType().getSkinParts().size(); i++) {
ISkinPartType part = getSkinType().getSkinParts().get(i);
IRectangle3D skinRec = part.getGuideSpace();
width = Math.max(width, skinRec.getWidth());
height = Math.max(height, skinRec.getHeight());
depth = Math.max(depth, skinRec.getDepth());
x = Math.min(x, skinRec.getX());
y = Math.max(y, skinRec.getY());
z = Math.min(z, skinRec.getZ());
}
}
return new Rectangle3D(x, y, z, width, height, depth);
}
use of riskyken.armourersWorkshop.api.common.skin.Rectangle3D in project Armourers-Workshop by RiskyKen.
the class SkinPart method setupBlockBounds.
private void setupBlockBounds() {
blockGrid = new Rectangle3D[3][3][3];
for (int i = 0; i < cubeData.getCubeCount(); i++) {
byte[] loc = cubeData.getCubeLocation(i);
int x = MathHelper.floor_float((float) (loc[0] + 8) / 16F);
int y = MathHelper.floor_float((float) (loc[1] + 8) / 16F);
int z = MathHelper.floor_float((float) (loc[2] + 8) / 16F);
setupBlockBounds(x, y, z, loc[0] - x * 16, loc[1] - y * 16, loc[2] - z * 16);
}
for (int ix = 0; ix < 3; ix++) {
for (int iy = 0; iy < 3; iy++) {
for (int iz = 0; iz < 3; iz++) {
Rectangle3D rec = blockGrid[ix][iy][iz];
if (rec != null) {
rec.setWidth(rec.getWidth() - rec.getX() + 1);
rec.setHeight(rec.getHeight() - rec.getY() + 1);
rec.setDepth(rec.getDepth() - rec.getZ() + 1);
}
}
}
}
}
Aggregations