Search in sources :

Example 21 with Vector3f

use of net.minecraft.client.util.math.Vector3f in project fabric by FabricMC.

the class AoCalculator method irregularFace.

private void irregularFace(MutableQuadViewImpl quad) {
    final Vector3f faceNorm = quad.faceNormal();
    Vector3f normal;
    final float[] w = this.w;
    final float[] aoResult = this.ao;
    final int[] lightResult = this.light;
    for (int i = 0; i < 4; i++) {
        normal = quad.hasNormal(i) ? quad.copyNormal(i, vertexNormal) : faceNorm;
        float ao = 0, sky = 0, block = 0, maxAo = 0;
        int maxSky = 0, maxBlock = 0;
        final float x = normal.getX();
        if (!MathHelper.equalsApproximate(0f, x)) {
            final Direction face = x > 0 ? Direction.EAST : Direction.WEST;
            final AoFaceData fd = gatherInsetFace(quad, i, face);
            AoFace.get(face).weightFunc.apply(quad, i, w);
            final float n = x * x;
            final float a = fd.weigtedAo(w);
            final int s = fd.weigtedSkyLight(w);
            final int b = fd.weigtedBlockLight(w);
            ao += n * a;
            sky += n * s;
            block += n * b;
            maxAo = a;
            maxSky = s;
            maxBlock = b;
        }
        final float y = normal.getY();
        if (!MathHelper.equalsApproximate(0f, y)) {
            final Direction face = y > 0 ? Direction.UP : Direction.DOWN;
            final AoFaceData fd = gatherInsetFace(quad, i, face);
            AoFace.get(face).weightFunc.apply(quad, i, w);
            final float n = y * y;
            final float a = fd.weigtedAo(w);
            final int s = fd.weigtedSkyLight(w);
            final int b = fd.weigtedBlockLight(w);
            ao += n * a;
            sky += n * s;
            block += n * b;
            maxAo = Math.max(maxAo, a);
            maxSky = Math.max(maxSky, s);
            maxBlock = Math.max(maxBlock, b);
        }
        final float z = normal.getZ();
        if (!MathHelper.equalsApproximate(0f, z)) {
            final Direction face = z > 0 ? Direction.SOUTH : Direction.NORTH;
            final AoFaceData fd = gatherInsetFace(quad, i, face);
            AoFace.get(face).weightFunc.apply(quad, i, w);
            final float n = z * z;
            final float a = fd.weigtedAo(w);
            final int s = fd.weigtedSkyLight(w);
            final int b = fd.weigtedBlockLight(w);
            ao += n * a;
            sky += n * s;
            block += n * b;
            maxAo = Math.max(maxAo, a);
            maxSky = Math.max(maxSky, s);
            maxBlock = Math.max(maxBlock, b);
        }
        aoResult[i] = (ao + maxAo) * 0.5f;
        lightResult[i] = (((int) ((sky + maxSky) * 0.5f) & 0xF0) << 16) | ((int) ((block + maxBlock) * 0.5f) & 0xF0);
    }
}
Also used : Vector3f(net.minecraft.client.util.math.Vector3f) Direction(net.minecraft.util.math.Direction)

Example 22 with Vector3f

use of net.minecraft.client.util.math.Vector3f in project Biome-Makeover by Lemonszz.

the class BMBoatRender method render.

public void render(BMBoatEntity boatEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i) {
    matrixStack.push();
    matrixStack.translate(0.0D, 0.375D, 0.0D);
    matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(180.0F - f));
    float h = (float) boatEntity.getDamageWobbleTicks() - g;
    float j = boatEntity.getDamageWobbleStrength() - g;
    if (j < 0.0F) {
        j = 0.0F;
    }
    if (h > 0.0F) {
        matrixStack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(MathHelper.sin(h) * h * j / 10.0F * (float) boatEntity.getDamageWobbleSide()));
    }
    float k = boatEntity.interpolateBubbleWobble(g);
    if (!MathHelper.approximatelyEquals(k, 0.0F)) {
        matrixStack.multiply(new Quaternion(new Vector3f(1.0F, 0.0F, 1.0F), boatEntity.interpolateBubbleWobble(g), true));
    }
    matrixStack.scale(-1.0F, -1.0F, 1.0F);
    matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(90.0F));
    this.model.setAngles(boatEntity, g, 0.0F, -0.1F, 0.0F, 0.0F);
    VertexConsumer vertexConsumer = vertexConsumerProvider.getBuffer(this.model.getLayer(this.getTexture(boatEntity)));
    this.model.render(matrixStack, vertexConsumer, i, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F, 1.0F, 1.0F);
    VertexConsumer vertexConsumer2 = vertexConsumerProvider.getBuffer(RenderLayer.getWaterMask());
    this.model.getBottom().render(matrixStack, vertexConsumer2, i, OverlayTexture.DEFAULT_UV);
    matrixStack.pop();
    super.render(boatEntity, f, g, matrixStack, vertexConsumerProvider, i);
}
Also used : Quaternion(net.minecraft.util.math.Quaternion) Vector3f(net.minecraft.client.util.math.Vector3f) VertexConsumer(net.minecraft.client.render.VertexConsumer)

Example 23 with Vector3f

use of net.minecraft.client.util.math.Vector3f in project LittleMaidModelLoader-Fabric by SistrScarlet.

the class SmoothModelPart2 method renderSmoothCuboids.

private void renderSmoothCuboids(MatrixStack.Entry defaultEntry, MatrixStack.Entry parentEntry, VertexConsumer vertexConsumer, int light, int overlay, float red, float green, float blue, float alpha) {
    Matrix4f defaultPosMat = defaultEntry.getModel();
    Matrix3f defaultNormal = defaultEntry.getNormal();
    Matrix4f parentPosMat = parentEntry.getModel();
    Matrix3f parentNormal = parentEntry.getNormal();
    ObjectList<Cuboid> cuboids = ((ModelPartAccessor) this).getCuboids();
    for (Cuboid cuboid : cuboids) {
        Quad[] quads = ((CuboidAccessor) cuboid).getQuads();
        // ここで値取ってこれと一致する頂点をーの方がいいかもね
        int indexQ = 0;
        for (Quad quad : quads) {
            Direction quadDirection = getQuadDirection(indexQ++);
            Vector3f defaultNormalVec = quad.direction.copy();
            defaultNormalVec.transform(defaultNormal);
            Vector3f smoothNormalVec = quad.direction.copy();
            smoothNormalVec.transform(parentNormal);
            int indexV = 0;
            for (Vertex vertex : quad.vertices) {
                Vector4f posVec = new Vector4f(vertex.pos.getX() / 16.0F, vertex.pos.getY() / 16.0F, vertex.pos.getZ() / 16.0F, 1.0F);
                if (shouldFollowParent(indexV++, quadDirection, direction)) {
                    posVec.transform(parentPosMat);
                    vertexConsumer.vertex(posVec.getX(), posVec.getY(), posVec.getZ(), red, green, blue, alpha, vertex.u, vertex.v, overlay, light, smoothNormalVec.getX(), smoothNormalVec.getY(), smoothNormalVec.getZ());
                } else {
                    posVec.transform(defaultPosMat);
                    vertexConsumer.vertex(posVec.getX(), posVec.getY(), posVec.getZ(), red, green, blue, alpha, vertex.u, vertex.v, overlay, light, defaultNormalVec.getX(), defaultNormalVec.getY(), defaultNormalVec.getZ());
                }
            }
        }
    }
}
Also used : ModelPartAccessor(net.sistr.littlemaidmodelloader.client.util.ModelPartAccessor) Direction(net.minecraft.util.math.Direction) Matrix4f(net.minecraft.util.math.Matrix4f) Vector4f(net.minecraft.client.util.math.Vector4f) Matrix3f(net.minecraft.util.math.Matrix3f) Vector3f(net.minecraft.client.util.math.Vector3f) CuboidAccessor(net.sistr.littlemaidmodelloader.client.util.CuboidAccessor)

Aggregations

Vector3f (net.minecraft.client.util.math.Vector3f)23 Direction (net.minecraft.util.math.Direction)4 BlockState (net.minecraft.block.BlockState)3 ChunkOcclusionDataBuilder (net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder)3 Vector4f (net.minecraft.client.util.math.Vector4f)3 BlockPos (net.minecraft.util.math.BlockPos)3 Matrix3f (net.minecraft.util.math.Matrix3f)3 Matrix4f (net.minecraft.util.math.Matrix4f)3 ChunkMeshBuilder (me.jellysquid.mods.sodium.client.render.mesh.ChunkMeshBuilder)2 Block (net.minecraft.block.Block)2 BlockEntity (net.minecraft.block.entity.BlockEntity)2 BufferBuilder (net.minecraft.client.render.BufferBuilder)2 RenderLayer (net.minecraft.client.render.RenderLayer)2 VertexConsumer (net.minecraft.client.render.VertexConsumer)2 FluidState (net.minecraft.fluid.FluidState)2 Quaternion (net.minecraft.util.math.Quaternion)2 CuboidAccessor (net.sistr.littlemaidmodelloader.client.util.CuboidAccessor)2 ModelPartAccessor (net.sistr.littlemaidmodelloader.client.util.ModelPartAccessor)2 Lists (com.google.common.collect.Lists)1 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)1