use of com.mojang.blaze3d.vertex.VertexFormatElement in project MinecraftForge by MinecraftForge.
the class QuadTransformer method findNormalOffset.
private static int findNormalOffset(VertexFormat fmt) {
int index;
VertexFormatElement element = null;
for (index = 0; index < fmt.getElements().size(); index++) {
VertexFormatElement el = fmt.getElements().get(index);
if (el.getUsage() == VertexFormatElement.Usage.NORMAL) {
element = el;
break;
}
}
if (index == fmt.getElements().size() || element == null)
throw new IllegalStateException("BLOCK format does not have normals?");
if (element.getType() != VertexFormatElement.Type.BYTE)
throw new RuntimeException("Expected NORMAL attribute to have data type BYTE");
if (element.getByteSize() < 3)
throw new RuntimeException("Expected NORMAL attribute to have at least 3 dimensions");
return fmt.getOffset(index);
}
use of com.mojang.blaze3d.vertex.VertexFormatElement in project MinecraftForge by MinecraftForge.
the class LightUtil method generateMapping.
private static int[] generateMapping(VertexFormat from, VertexFormat to) {
int fromCount = from.getElements().size();
int toCount = to.getElements().size();
int[] eMap = new int[fromCount];
for (int e = 0; e < fromCount; e++) {
VertexFormatElement expected = from.getElements().get(e);
int e2;
for (e2 = 0; e2 < toCount; e2++) {
VertexFormatElement current = to.getElements().get(e2);
if (expected.getUsage() == current.getUsage() && expected.getIndex() == current.getIndex()) {
break;
}
}
eMap[e] = e2;
}
return eMap;
}
use of com.mojang.blaze3d.vertex.VertexFormatElement in project MinecraftForge by MinecraftForge.
the class ItemTextureQuadConverter method putVertex.
private static void putVertex(IVertexConsumer consumer, Direction side, float x, float y, float z, float u, float v, int color, int luminosity) {
VertexFormat format = consumer.getVertexFormat();
for (int e = 0; e < format.getElements().size(); e++) {
VertexFormatElement element = format.getElements().get(e);
switch(element.getUsage()) {
case POSITION:
consumer.put(e, x, y, z, 1f);
break;
case COLOR:
// red
float r = ((color >> 16) & 0xFF) / 255f;
// green
float g = ((color >> 8) & 0xFF) / 255f;
// blue
float b = ((color >> 0) & 0xFF) / 255f;
// alpha
float a = ((color >> 24) & 0xFF) / 255f;
consumer.put(e, r, g, b, a);
break;
case NORMAL:
float offX = (float) side.getStepX();
float offY = (float) side.getStepY();
float offZ = (float) side.getStepZ();
consumer.put(e, offX, offY, offZ, 0f);
break;
case UV:
if (element.getIndex() == 0) {
consumer.put(e, u, v, 0f, 1f);
break;
} else if (element.getIndex() == 2) {
consumer.put(e, (luminosity << 4) / 32768.0f, (luminosity << 4) / 32768.0f, 0f, 1f);
break;
}
// else fallthrough to default
default:
consumer.put(e);
break;
}
}
}
Aggregations