Search in sources :

Example 1 with Vec3i

use of net.minecraft.util.maths.Vec3i in project StationAPI by ModificationStation.

the class StationTessellator method quad.

@Override
default void quad(MatrixStack.Entry matrixEntry, BakedQuad quad, float[] brightnesses, float red, float green, float blue, int[] lights, int overlay, boolean useQuadColorData) {
    float[] fs = new float[] { brightnesses[0], brightnesses[1], brightnesses[2], brightnesses[3] };
    int[] is = new int[] { lights[0], lights[1], lights[2], lights[3] };
    int[] js = quad.getVertexData();
    Vec3i vec3i = quad.getFace().vector;
    Vector3f vec3f = new Vector3f(vec3i.x, vec3i.y, vec3i.z);
    Matrix4f matrix4f = matrixEntry.getModel();
    vec3f.transform(matrixEntry.getNormal());
    int j = js.length / 8;
    ByteBuffer byteBuffer = BUFFER;
    IntBuffer intBuffer = byteBuffer.asIntBuffer();
    for (int k = 0; k < j; ++k) {
        float q;
        float p;
        float o;
        float n;
        float m;
        intBuffer.clear();
        intBuffer.put(js, k * 8, 8);
        float f = byteBuffer.getFloat(0);
        float g = byteBuffer.getFloat(4);
        float h = byteBuffer.getFloat(8);
        if (useQuadColorData) {
            float l = (float) (byteBuffer.get(20) & 0xFF) / 255.0f;
            m = (float) (byteBuffer.get(21) & 0xFF) / 255.0f;
            n = (float) (byteBuffer.get(22) & 0xFF) / 255.0f;
            o = l * fs[k] * red;
            p = m * fs[k] * green;
            q = n * fs[k] * blue;
        } else {
            o = fs[k] * red;
            p = fs[k] * green;
            q = fs[k] * blue;
        }
        int r = is[k];
        m = byteBuffer.getFloat(12);
        n = byteBuffer.getFloat(16);
        Vector4f vector4f = new Vector4f(f, g, h, 1.0f);
        vector4f.transform(matrix4f);
        this.vertex(vector4f.getX(), vector4f.getY(), vector4f.getZ(), o, p, q, 1.0f, m, n, overlay, r, vec3f.getX(), vec3f.getY(), vec3f.getZ());
    }
}
Also used : Vec3i(net.minecraft.util.maths.Vec3i) Matrix4f(net.modificationstation.stationapi.api.util.math.Matrix4f) Vector4f(net.modificationstation.stationapi.api.util.math.Vector4f) Vector3f(net.modificationstation.stationapi.api.util.math.Vector3f)

Example 2 with Vec3i

use of net.minecraft.util.maths.Vec3i in project StationAPI by ModificationStation.

the class VertexConsumer method quad.

default void quad(MatrixStack.Entry matrixEntry, BakedQuad quad, float[] brightnesses, float red, float green, float blue, int[] lights, int overlay, boolean useQuadColorData) {
    float[] fs = new float[] { brightnesses[0], brightnesses[1], brightnesses[2], brightnesses[3] };
    int[] is = new int[] { lights[0], lights[1], lights[2], lights[3] };
    int[] js = quad.getVertexData();
    Vec3i vec3i = quad.getFace().vector;
    Vector3f vec3f = new Vector3f(vec3i.x, vec3i.y, vec3i.z);
    Matrix4f matrix4f = matrixEntry.getModel();
    vec3f.transform(matrixEntry.getNormal());
    int j = js.length / 8;
    ByteBuffer byteBuffer = BUFFER;
    IntBuffer intBuffer = byteBuffer.asIntBuffer();
    for (int k = 0; k < j; ++k) {
        float q;
        float p;
        float o;
        float n;
        float m;
        intBuffer.clear();
        intBuffer.put(js, k * 8, 8);
        float f = byteBuffer.getFloat(0);
        float g = byteBuffer.getFloat(4);
        float h = byteBuffer.getFloat(8);
        if (useQuadColorData) {
            float l = (float) (byteBuffer.get(12) & 0xFF) / 255.0f;
            m = (float) (byteBuffer.get(13) & 0xFF) / 255.0f;
            n = (float) (byteBuffer.get(14) & 0xFF) / 255.0f;
            o = l * fs[k] * red;
            p = m * fs[k] * green;
            q = n * fs[k] * blue;
        } else {
            o = fs[k] * red;
            p = fs[k] * green;
            q = fs[k] * blue;
        }
        int r = is[k];
        m = byteBuffer.getFloat(16);
        n = byteBuffer.getFloat(20);
        Vector4f vector4f = new Vector4f(f, g, h, 1.0f);
        vector4f.transform(matrix4f);
        this.vertex(vector4f.getX(), vector4f.getY(), vector4f.getZ(), o, p, q, 1.0f, m, n, overlay, r, vec3f.getX(), vec3f.getY(), vec3f.getZ());
    }
}
Also used : Vec3i(net.minecraft.util.maths.Vec3i) Matrix4f(net.modificationstation.stationapi.api.util.math.Matrix4f) Vector4f(net.modificationstation.stationapi.api.util.math.Vector4f) Vector3f(net.modificationstation.stationapi.api.util.math.Vector3f)

Example 3 with Vec3i

use of net.minecraft.util.maths.Vec3i in project StationAPI by ModificationStation.

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(@NotNull Vector3f saveTo, QuadView q) {
    final Direction nominalFace = q.nominalFace();
    if (GeometryHelper.isQuadParallelToFace(nominalFace, q)) {
        Vec3i vec = nominalFace.vector;
        saveTo.set(vec.x, vec.y, vec.z);
        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);
}
Also used : Vec3i(net.minecraft.util.maths.Vec3i) Direction(net.modificationstation.stationapi.api.util.math.Direction)

Aggregations

Vec3i (net.minecraft.util.maths.Vec3i)3 Matrix4f (net.modificationstation.stationapi.api.util.math.Matrix4f)2 Vector3f (net.modificationstation.stationapi.api.util.math.Vector3f)2 Vector4f (net.modificationstation.stationapi.api.util.math.Vector4f)2 Direction (net.modificationstation.stationapi.api.util.math.Direction)1