Improve generation of normals for vanilla models (#4313)

This commit is contained in:
Ben Staddon authored and LexManos committed 2017-09-06 14:31:46 -07:00
1 parent cb8cace92d
commit 0dd386b74c
1 file changed
+22 -8
@@ -575,24 +575,38 @@ public class ForgeHooksClient
*/
public static void fillNormal(int[] faceData, EnumFacing facing)
{
Vector3f v1 = new Vector3f(faceData[3 * 7 + 0], faceData[3 * 7 + 1], faceData[3 * 7 + 2]);
Vector3f t = new Vector3f(faceData[1 * 7 + 0], faceData[1 * 7 + 1], faceData[1 * 7 + 2]);
Vector3f v2 = new Vector3f(faceData[2 * 7 + 0], faceData[2 * 7 + 1], faceData[2 * 7 + 2]);
Vector3f v1 = getVertexPos(faceData, 3);
Vector3f t = getVertexPos(faceData, 1);
Vector3f v2 = getVertexPos(faceData, 2);
v1.sub(t);
t.set(faceData[0 * 7 + 0], faceData[0 * 7 + 1], faceData[0 * 7 + 2]);
t.set(getVertexPos(faceData, 0));
v2.sub(t);
v1.cross(v2, v1);
v1.normalize();
int x = ((byte)(v1.x * 127)) & 0xFF;
int y = ((byte)(v1.y * 127)) & 0xFF;
int z = ((byte)(v1.z * 127)) & 0xFF;
int x = ((byte) Math.round(v1.x * 127)) & 0xFF;
int y = ((byte) Math.round(v1.y * 127)) & 0xFF;
int z = ((byte) Math.round(v1.z * 127)) & 0xFF;
int normal = x | (y << 0x08) | (z << 0x10);
for(int i = 0; i < 4; i++)
{
faceData[i * 7 + 6] = x | (y << 0x08) | (z << 0x10);
faceData[i * 7 + 6] = normal;
}
}
private static Vector3f getVertexPos(int[] data, int vertex)
{
int idx = vertex * 7;
float x = Float.intBitsToFloat(data[idx]);
float y = Float.intBitsToFloat(data[idx + 1]);
float z = Float.intBitsToFloat(data[idx + 2]);
return new Vector3f(x, y, z);
}
@SuppressWarnings("deprecation")
public static Optional<TRSRTransformation> applyTransform(net.minecraft.client.renderer.block.model.ItemTransformVec3f transform, Optional<? extends IModelPart> part)
{