use of net.minecraft.util.math.Direction in project fabric by FabricMC.
the class TerrainFallbackConsumer method accept.
@Override
public void accept(BakedModel model) {
final Supplier<Random> random = blockInfo.randomSupplier;
final Value defaultMaterial = blockInfo.defaultAo && model.useAmbientOcclusion() ? MATERIAL_SHADED : MATERIAL_FLAT;
final BlockState blockState = blockInfo.blockState;
for (int i = 0; i < 6; i++) {
Direction face = ModelHelper.faceFromIndex(i);
List<BakedQuad> quads = model.getQuads(blockState, face, random.get());
final int count = quads.size();
if (count != 0 && blockInfo.shouldDrawFace(face)) {
for (int j = 0; j < count; j++) {
BakedQuad q = quads.get(j);
renderQuad(q, face, defaultMaterial);
}
}
}
List<BakedQuad> quads = model.getQuads(blockState, null, random.get());
final int count = quads.size();
if (count != 0) {
for (int j = 0; j < count; j++) {
BakedQuad q = quads.get(j);
renderQuad(q, null, defaultMaterial);
}
}
}
use of net.minecraft.util.math.Direction in project fabric by FabricMC.
the class AoCalculator method vanillaPartialFace.
private void vanillaPartialFace(QuadViewImpl quad, boolean isOnLightFace) {
final Direction lightFace = quad.lightFace();
AoFaceData faceData = computeFace(lightFace, isOnLightFace);
final WeightFunction wFunc = AoFace.get(lightFace).weightFunc;
final float[] w = this.w;
for (int i = 0; i < 4; i++) {
wFunc.apply(quad, i, w);
light[i] = faceData.weightedCombinedLight(w);
ao[i] = faceData.weigtedAo(w);
}
}
use of net.minecraft.util.math.Direction in project fabric by FabricMC.
the class AoCalculator method blendedPartialFace.
private void blendedPartialFace(QuadViewImpl quad) {
final Direction lightFace = quad.lightFace();
AoFaceData faceData = blendedInsetFace(quad, 0, lightFace);
final WeightFunction wFunc = AoFace.get(lightFace).weightFunc;
for (int i = 0; i < 4; i++) {
wFunc.apply(quad, i, w);
light[i] = faceData.weightedCombinedLight(w);
ao[i] = faceData.weigtedAo(w);
}
}
use of net.minecraft.util.math.Direction in project fabric by FabricMC.
the class GeometryHelper method computeShapeFlags.
/**
* Analyzes the quad and returns a value with some combination
* of {@link #AXIS_ALIGNED_FLAG}, {@link #LIGHT_FACE_FLAG} and {@link #CUBIC_FLAG}.
* Intended use is to optimize lighting when the geometry is regular.
* Expects convex quads with all points co-planar.
*/
public static int computeShapeFlags(QuadView quad) {
Direction lightFace = quad.lightFace();
int bits = 0;
if (isQuadParallelToFace(lightFace, quad)) {
bits |= AXIS_ALIGNED_FLAG;
if (isParallelQuadOnFace(lightFace, quad)) {
bits |= LIGHT_FACE_FLAG;
}
}
if (isQuadCubic(lightFace, quad)) {
bits |= CUBIC_FLAG;
}
return bits;
}
use of net.minecraft.util.math.Direction in project fabric by FabricMC.
the class NormalHelper method computeFaceNormal.
/**
* Computes the face normal of the given quad and saves it in the provided non-null vector.
* If {@link QuadView#nominalFace()} is set will optimize by confirming quad is parallel to that
* face and, if so, use the standard normal for that face direction.<p>
*
* Will work with triangles also. Assumes counter-clockwise winding order, which is the norm.
* Expects convex quads with all points co-planar.
*/
public static void computeFaceNormal(Vector3f saveTo, QuadView q) {
final Direction nominalFace = q.nominalFace();
if (GeometryHelper.isQuadParallelToFace(nominalFace, q)) {
Vec3i vec = nominalFace.getVector();
saveTo.set(vec.getX(), vec.getY(), vec.getZ());
return;
}
final float x0 = q.x(0);
final float y0 = q.y(0);
final float z0 = q.z(0);
final float x1 = q.x(1);
final float y1 = q.y(1);
final float z1 = q.z(1);
final float x2 = q.x(2);
final float y2 = q.y(2);
final float z2 = q.z(2);
final float x3 = q.x(3);
final float y3 = q.y(3);
final float z3 = q.z(3);
final float dx0 = x2 - x0;
final float dy0 = y2 - y0;
final float dz0 = z2 - z0;
final float dx1 = x3 - x1;
final float dy1 = y3 - y1;
final float dz1 = z3 - z1;
float normX = dy0 * dz1 - dz0 * dy1;
float normY = dz0 * dx1 - dx0 * dz1;
float normZ = dx0 * dy1 - dy0 * dx1;
float l = (float) Math.sqrt(normX * normX + normY * normY + normZ * normZ);
if (l != 0) {
normX /= l;
normY /= l;
normZ /= l;
}
saveTo.set(normX, normY, normZ);
}
Aggregations