use of net.minecraftforge.client.model.pipeline.BakedQuadBuilder in project MinecraftForge by MinecraftForge.
the class OBJModel method makeQuad.
private Pair<BakedQuad, Direction> makeQuad(int[][] indices, int tintIndex, Vector4f colorTint, Vector4f ambientColor, TextureAtlasSprite texture, Transformation transform) {
boolean needsNormalRecalculation = false;
for (int[] ints : indices) {
needsNormalRecalculation |= ints.length < 3;
}
Vector3f faceNormal = new Vector3f(0, 0, 0);
if (needsNormalRecalculation) {
Vector3f a = positions.get(indices[0][0]);
Vector3f ab = positions.get(indices[1][0]);
Vector3f ac = positions.get(indices[2][0]);
Vector3f abs = ab.copy();
abs.sub(a);
Vector3f acs = ac.copy();
acs.sub(a);
abs.cross(acs);
abs.normalize();
faceNormal = abs;
}
Vector4f[] pos = new Vector4f[4];
Vector3f[] norm = new Vector3f[4];
BakedQuadBuilder builder = new BakedQuadBuilder(texture);
builder.setQuadTint(tintIndex);
Vec2 uv2 = new Vec2(0, 0);
if (ambientToFullbright) {
int fakeLight = (int) ((ambientColor.x() + ambientColor.y() + ambientColor.z()) * 15 / 3.0f);
uv2 = new Vec2((fakeLight << 4) / 32767.0f, (fakeLight << 4) / 32767.0f);
builder.setApplyDiffuseLighting(fakeLight == 0);
} else {
builder.setApplyDiffuseLighting(diffuseLighting);
}
boolean hasTransform = !transform.isIdentity();
// The incoming transform is referenced on the center of the block, but our coords are referenced on the corner
Transformation transformation = hasTransform ? transform.blockCenterToCorner() : transform;
for (int i = 0; i < 4; i++) {
int[] index = indices[Math.min(i, indices.length - 1)];
Vector3f pos0 = positions.get(index[0]);
Vector4f position = new Vector4f(pos0);
Vec2 texCoord = index.length >= 2 && texCoords.size() > 0 ? texCoords.get(index[1]) : DEFAULT_COORDS[i];
Vector3f norm0 = !needsNormalRecalculation && index.length >= 3 && normals.size() > 0 ? normals.get(index[2]) : faceNormal;
Vector3f normal = norm0;
Vector4f color = index.length >= 4 && colors.size() > 0 ? colors.get(index[3]) : COLOR_WHITE;
if (hasTransform) {
normal = norm0.copy();
transformation.transformPosition(position);
transformation.transformNormal(normal);
}
;
Vector4f tintedColor = new Vector4f(color.x() * colorTint.x(), color.y() * colorTint.y(), color.z() * colorTint.z(), color.w() * colorTint.w());
putVertexData(builder, position, texCoord, normal, tintedColor, uv2, texture);
pos[i] = position;
norm[i] = normal;
}
builder.setQuadOrientation(Direction.getNearest(norm[0].x(), norm[0].y(), norm[0].z()));
Direction cull = null;
if (detectCullableFaces) {
if (// vertex.position.x
Mth.equal(pos[0].x(), 0) && Mth.equal(pos[1].x(), 0) && Mth.equal(pos[2].x(), 0) && Mth.equal(pos[3].x(), 0) && // vertex.normal.x
norm[0].x() < 0) {
cull = Direction.WEST;
} else if (// vertex.position.x
Mth.equal(pos[0].x(), 1) && Mth.equal(pos[1].x(), 1) && Mth.equal(pos[2].x(), 1) && Mth.equal(pos[3].x(), 1) && // vertex.normal.x
norm[0].x() > 0) {
cull = Direction.EAST;
} else if (// vertex.position.z
Mth.equal(pos[0].z(), 0) && Mth.equal(pos[1].z(), 0) && Mth.equal(pos[2].z(), 0) && Mth.equal(pos[3].z(), 0) && // vertex.normal.z
norm[0].z() < 0) {
// can never remember
cull = Direction.NORTH;
} else if (// vertex.position.z
Mth.equal(pos[0].z(), 1) && Mth.equal(pos[1].z(), 1) && Mth.equal(pos[2].z(), 1) && Mth.equal(pos[3].z(), 1) && // vertex.normal.z
norm[0].z() > 0) {
cull = Direction.SOUTH;
} else if (// vertex.position.y
Mth.equal(pos[0].y(), 0) && Mth.equal(pos[1].y(), 0) && Mth.equal(pos[2].y(), 0) && Mth.equal(pos[3].y(), 0) && // vertex.normal.z
norm[0].y() < 0) {
// can never remember
cull = Direction.DOWN;
} else if (// vertex.position.y
Mth.equal(pos[0].y(), 1) && Mth.equal(pos[1].y(), 1) && Mth.equal(pos[2].y(), 1) && Mth.equal(pos[3].y(), 1) && // vertex.normal.y
norm[0].y() > 0) {
cull = Direction.UP;
}
}
return Pair.of(builder.build(), cull);
}
use of net.minecraftforge.client.model.pipeline.BakedQuadBuilder in project MinecraftForge by MinecraftForge.
the class ItemLayerModel method buildQuad.
private static BakedQuad buildQuad(Transformation transform, Direction side, TextureAtlasSprite sprite, int tint, boolean fullbright, float x0, float y0, float z0, float u0, float v0, float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3) {
BakedQuadBuilder builder = new BakedQuadBuilder(sprite);
builder.setQuadTint(tint);
builder.setQuadOrientation(side);
builder.setApplyDiffuseLighting(false);
boolean hasTransform = !transform.isIdentity();
IVertexConsumer consumer = hasTransform ? new TRSRTransformer(builder, transform) : builder;
int uLight, vLight;
uLight = vLight = fullbright ? 15 : 0;
putVertex(consumer, side, x0, y0, z0, u0, v0, uLight, vLight);
putVertex(consumer, side, x1, y1, z1, u1, v1, uLight, vLight);
putVertex(consumer, side, x2, y2, z2, u2, v2, uLight, vLight);
putVertex(consumer, side, x3, y3, z3, u3, v3, uLight, vLight);
return builder.build();
}
use of net.minecraftforge.client.model.pipeline.BakedQuadBuilder in project BluePower by Qmunity.
the class BPMicroblockModel method transform.
private static BakedQuad transform(BakedQuad sizeQuad, TextureAtlasSprite sprite, Direction dir, Block block) {
BakedQuadBuilder builder = new BakedQuadBuilder();
final IVertexConsumer consumer = new VertexTransformer(builder) {
@Override
public void put(int element, float... data) {
VertexFormatElement e = this.getVertexFormat().getElements().get(element);
if (e.getUsage() == VertexFormatElement.Usage.UV && e.getIndex() == 0) {
Vector2f vec = new Vector2f(data[0], data[1]);
float u = (vec.x - sizeQuad.getSprite().getU0()) / (sizeQuad.getSprite().getU1() - sizeQuad.getSprite().getU0()) * 16;
float v = (vec.y - sizeQuad.getSprite().getV0()) / (sizeQuad.getSprite().getV1() - sizeQuad.getSprite().getV0()) * 16;
builder.put(element, sprite.getU(u), sprite.getV(v));
} else if (e.getUsage() == VertexFormatElement.Usage.COLOR) {
int color;
try {
color = Minecraft.getInstance().getBlockColors().getColor(block.defaultBlockState(), null, null, sizeQuad.getTintIndex());
} catch (Exception ex) {
try {
color = Minecraft.getInstance().getBlockColors().getColor(block.defaultBlockState(), null, BlockPos.ZERO, sizeQuad.getTintIndex());
} catch (Exception ex2) {
color = 0;
}
}
int redMask = 0xFF0000, greenMask = 0xFF00, blueMask = 0xFF;
int r = (color & redMask) >> 16;
int g = (color & greenMask) >> 8;
int b = (color & blueMask);
parent.put(element, r / 255F, g / 255F, b / 255F, 1);
} else {
parent.put(element, data);
}
}
};
LightUtil.putBakedQuad(consumer, sizeQuad);
return builder.build();
}
use of net.minecraftforge.client.model.pipeline.BakedQuadBuilder in project BluePower by Qmunity.
the class BPMultipartModel method transform.
private static BakedQuad transform(BakedQuad quad, Pair<Integer, Integer> colorPair, Boolean fullBright) {
BakedQuadBuilder builder = new BakedQuadBuilder();
final IVertexConsumer consumer = new VertexTransformer(builder) {
@Override
public void put(int element, float... data) {
VertexFormatElement e = this.getVertexFormat().getElements().get(element);
if (e.getUsage() == VertexFormatElement.Usage.COLOR) {
int color = quad.getTintIndex() == 2 ? colorPair.getSecond() : colorPair.getFirst();
int redMask = 0xFF0000, greenMask = 0xFF00, blueMask = 0xFF;
int r = (color & redMask) >> 16;
int g = (color & greenMask) >> 8;
int b = (color & blueMask);
parent.put(element, r / 255F, g / 255F, b / 255F, 1);
} else {
parent.put(element, data);
}
}
};
LightUtil.putBakedQuad(consumer, quad);
BakedQuad finalQuad = builder.build();
if (fullBright)
LightUtil.setLightData(finalQuad, 240);
return finalQuad;
}
use of net.minecraftforge.client.model.pipeline.BakedQuadBuilder in project MinecraftForge by MinecraftForge.
the class ItemTextureQuadConverter method putQuad.
private static BakedQuad putQuad(Transformation transform, Direction side, TextureAtlasSprite sprite, int color, int tint, float x1, float y1, float x2, float y2, float z, float u1, float v1, float u2, float v2, int luminosity) {
BakedQuadBuilder builder = new BakedQuadBuilder(sprite);
builder.setQuadTint(tint);
builder.setQuadOrientation(side);
builder.setApplyDiffuseLighting(luminosity == 0);
// only apply the transform if it's not identity
boolean hasTransform = !transform.isIdentity();
IVertexConsumer consumer = hasTransform ? new TRSRTransformer(builder, transform) : builder;
if (side == Direction.SOUTH) {
putVertex(consumer, side, x1, y1, z, u1, v2, color, luminosity);
putVertex(consumer, side, x2, y1, z, u2, v2, color, luminosity);
putVertex(consumer, side, x2, y2, z, u2, v1, color, luminosity);
putVertex(consumer, side, x1, y2, z, u1, v1, color, luminosity);
} else {
putVertex(consumer, side, x1, y1, z, u1, v2, color, luminosity);
putVertex(consumer, side, x1, y2, z, u1, v1, color, luminosity);
putVertex(consumer, side, x2, y2, z, u2, v1, color, luminosity);
putVertex(consumer, side, x2, y1, z, u2, v2, color, luminosity);
}
return builder.build();
}
Aggregations