use of net.minecraft.client.renderer.vertex.VertexFormat in project ImmersiveEngineering by BluSunrize.
the class BakedModelTransformer method transform.
private static BakedQuad transform(BakedQuad quad, IVertexTransformer transformer, Function<VertexFormat, VertexFormat> formatRemapper) {
VertexFormat format = quad.getFormat();
VertexFormat newFormat = formatRemapper.apply(format);
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(newFormat);
if (quad.hasTintIndex())
builder.setQuadTint(quad.getTintIndex());
builder.setQuadOrientation(quad.getFace());
LightUtil.putBakedQuad(builder, quad);
UnpackedBakedQuad unpackedQuad = builder.build();
try {
float[][][] unpackedData = getUnpackedData(unpackedQuad);
int count = newFormat.getElementCount();
for (int v = 0; v < 4; v++) {
for (int e = 0; e < count; e++) {
VertexFormatElement element = newFormat.getElement(e);
unpackedData[v][e] = transformer.transform(quad, element.getType(), element.getUsage(), unpackedData[v][e]);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return unpackedQuad;
}
use of net.minecraft.client.renderer.vertex.VertexFormat in project MinecraftForge by MinecraftForge.
the class LightUtil method putBakedQuad.
public static void putBakedQuad(IVertexConsumer consumer, BakedQuad quad) {
consumer.setTexture(quad.getSprite());
consumer.setQuadOrientation(quad.getFace());
if (quad.hasTintIndex()) {
consumer.setQuadTint(quad.getTintIndex());
}
consumer.setApplyDiffuseLighting(quad.shouldApplyDiffuseLighting());
//int[] eMap = mapFormats(consumer.getVertexFormat(), DefaultVertexFormats.ITEM);
float[] data = new float[4];
VertexFormat formatFrom = consumer.getVertexFormat();
VertexFormat formatTo = quad.getFormat();
int countFrom = formatFrom.getElementCount();
int countTo = formatTo.getElementCount();
int[] eMap = formatMaps.getUnchecked(Pair.of(formatFrom, formatTo));
for (int v = 0; v < 4; v++) {
for (int e = 0; e < countFrom; e++) {
if (eMap[e] != countTo) {
unpack(quad.getVertexData(), data, quad.getFormat(), v, eMap[e]);
consumer.put(e, data);
} else {
consumer.put(e);
}
}
}
}
use of net.minecraft.client.renderer.vertex.VertexFormat in project MinecraftForge by MinecraftForge.
the class VertexLighterFlat method getVertexFormat.
private static VertexFormat getVertexFormat(IVertexConsumer parent) {
VertexFormat format = parent.getVertexFormat();
if (format.hasNormal())
return format;
format = new VertexFormat(format);
format.addElement(new VertexFormatElement(0, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.NORMAL, 4));
return format;
}
use of net.minecraft.client.renderer.vertex.VertexFormat in project MinecraftForge by MinecraftForge.
the class ForgeHooksClient method putQuadColor.
public static void putQuadColor(VertexBuffer renderer, BakedQuad quad, int color) {
float cb = color & 0xFF;
float cg = (color >>> 8) & 0xFF;
float cr = (color >>> 16) & 0xFF;
float ca = (color >>> 24) & 0xFF;
VertexFormat format = quad.getFormat();
int size = format.getIntegerSize();
// assumes that color is aligned
int offset = format.getColorOffset() / 4;
for (int i = 0; i < 4; i++) {
int vc = quad.getVertexData()[offset + size * i];
float vcr = vc & 0xFF;
float vcg = (vc >>> 8) & 0xFF;
float vcb = (vc >>> 16) & 0xFF;
float vca = (vc >>> 24) & 0xFF;
int ncr = Math.min(0xFF, (int) (cr * vcr / 0xFF));
int ncg = Math.min(0xFF, (int) (cg * vcg / 0xFF));
int ncb = Math.min(0xFF, (int) (cb * vcb / 0xFF));
int nca = Math.min(0xFF, (int) (ca * vca / 0xFF));
renderer.putColorRGBA(renderer.getColorIndex(4 - i), ncr, ncg, ncb, nca);
}
}
use of net.minecraft.client.renderer.vertex.VertexFormat in project ImmersiveEngineering by BluSunrize.
the class ClientUtils method renderModelTESR.
public static void renderModelTESR(List<BakedQuad> quads, VertexBuffer renderer, int brightness) {
int l1 = (brightness >> 0x10) & 0xFFFF;
int l2 = brightness & 0xFFFF;
for (BakedQuad quad : quads) {
int[] vData = quad.getVertexData();
VertexFormat format = quad.getFormat();
int size = format.getIntegerSize();
int uv = format.getUvOffsetById(0) / 4;
for (int i = 0; i < 4; ++i) {
renderer.pos(Float.intBitsToFloat(vData[size * i]), Float.intBitsToFloat(vData[size * i + 1]), Float.intBitsToFloat(vData[size * i + 2])).color(255, 255, 255, 255).tex(Float.intBitsToFloat(vData[size * i + uv]), Float.intBitsToFloat(vData[size * i + uv + 1])).lightmap(l1, l2).endVertex();
}
}
}
Aggregations