Search in sources :

Example 1 with Vector3f

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

the class QuadViewImpl method copyPos.

@Override
public Vector3f copyPos(int vertexIndex, Vector3f target) {
    if (target == null) {
        target = new Vector3f();
    }
    final int index = vertexStart() + vertexIndex * 7;
    target.set(Float.intBitsToFloat(data[index]), Float.intBitsToFloat(data[index + 1]), Float.intBitsToFloat(data[index + 2]));
    return target;
}
Also used : Vector3f(net.minecraft.client.util.math.Vector3f)

Example 2 with Vector3f

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

the class QuadViewImpl method copyNormal.

@Override
public Vector3f copyNormal(int vertexIndex, Vector3f target) {
    if (hasNormal(vertexIndex)) {
        if (target == null) {
            target = new Vector3f();
        }
        final int normal = data[vertexStart() + VANILLA_STRIDE + vertexIndex];
        target.set(NormalHelper.getPackedNormalComponent(normal, 0), NormalHelper.getPackedNormalComponent(normal, 1), NormalHelper.getPackedNormalComponent(normal, 2));
        return target;
    } else {
        return null;
    }
}
Also used : Vector3f(net.minecraft.client.util.math.Vector3f)

Example 3 with Vector3f

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

the class ModelHelper method makeTransform.

/**
 * The vanilla model transformation logic is closely coupled with model deserialization.
 * That does little good for modded model loaders and procedurally generated models.
 * This convenient construction method applies the same scaling factors used for vanilla models.
 * This means you can use values from a vanilla JSON file as inputs to this method.
 */
private static Transformation makeTransform(float rotationX, float rotationY, float rotationZ, float translationX, float translationY, float translationZ, float scaleX, float scaleY, float scaleZ) {
    Vector3f translation = new Vector3f(translationX, translationY, translationZ);
    translation.scale(0.0625f);
    translation.clamp(-5.0F, 5.0F);
    return new Transformation(new Vector3f(rotationX, rotationY, rotationZ), translation, new Vector3f(scaleX, scaleY, scaleZ));
}
Also used : Transformation(net.minecraft.client.render.model.json.Transformation) ModelTransformation(net.minecraft.client.render.model.json.ModelTransformation) Vector3f(net.minecraft.client.util.math.Vector3f)

Example 4 with Vector3f

use of net.minecraft.client.util.math.Vector3f in project sodium-fabric by CaffeineMC.

the class ChunkGraph method init.

private boolean init(BlockPos blockPos, Camera camera, Vec3d cameraPos, Frustum frustum, int frame, boolean spectator) {
    MinecraftClient client = MinecraftClient.getInstance();
    ObjectArrayFIFOQueue<ChunkGraphNode<T>> queue = this.iterationQueue;
    boolean cull = client.chunkCullingEnabled;
    ChunkGraphNode<T> node = this.getOrCreateNode(blockPos);
    if (node != null) {
        node.reset();
        // Player is within bounds and inside a node
        Set<Direction> openFaces = this.getOpenChunkFaces(blockPos);
        if (openFaces.size() == 1) {
            Vector3f vector3f = camera.getHorizontalPlane();
            Direction direction = Direction.getFacing(vector3f.getX(), vector3f.getY(), vector3f.getZ()).getOpposite();
            openFaces.remove(direction);
        }
        if (openFaces.isEmpty() && !spectator) {
            this.visibleNodes.add(node);
        } else {
            if (spectator && this.world.getBlockState(blockPos).isFullOpaque(this.world, blockPos)) {
                cull = false;
            }
            node.setRebuildFrame(frame);
            queue.enqueue(node);
        }
    } else {
        // Player is out-of-bounds
        int y = blockPos.getY() > 0 ? 248 : 8;
        int x = MathHelper.floor(cameraPos.x / 16.0D) * 16;
        int z = MathHelper.floor(cameraPos.z / 16.0D) * 16;
        List<ChunkGraphNode<T>> list = Lists.newArrayList();
        for (int x2 = -this.renderDistance; x2 <= this.renderDistance; ++x2) {
            for (int z2 = -this.renderDistance; z2 <= this.renderDistance; ++z2) {
                ChunkGraphNode<T> chunk = this.getOrCreateNode(new BlockPos(x + (x2 << 4) + 8, y, z + (z2 << 4) + 8));
                if (chunk == null) {
                    continue;
                }
                if (frustum.isVisible(chunk.getBoundingBox())) {
                    chunk.setRebuildFrame(frame);
                    chunk.reset();
                    list.add(chunk);
                }
            }
        }
        list.sort(Comparator.comparingDouble(o -> blockPos.getSquaredDistance(o.chunk.getOrigin().add(8, 8, 8))));
        for (ChunkGraphNode<T> n : list) {
            queue.enqueue(n);
        }
    }
    return cull;
}
Also used : ChunkOcclusionDataBuilder(net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder) SodiumGameOptions(me.jellysquid.mods.sodium.client.gui.SodiumGameOptions) SodiumClientMod(me.jellysquid.mods.sodium.client.SodiumClientMod) net.minecraft.util.math(net.minecraft.util.math) World(net.minecraft.world.World) ObjectArrayList(it.unimi.dsi.fastutil.objects.ObjectArrayList) Set(java.util.Set) ChunkSection(net.minecraft.world.chunk.ChunkSection) DirectionUtil(me.jellysquid.mods.sodium.common.util.DirectionUtil) WorldChunk(net.minecraft.world.chunk.WorldChunk) List(java.util.List) Lists(com.google.common.collect.Lists) Frustum(net.minecraft.client.render.Frustum) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) Vector3f(net.minecraft.client.util.math.Vector3f) ObjectArrayFIFOQueue(it.unimi.dsi.fastutil.objects.ObjectArrayFIFOQueue) MinecraftClient(net.minecraft.client.MinecraftClient) BlockState(net.minecraft.block.BlockState) Comparator(java.util.Comparator) ObjectList(it.unimi.dsi.fastutil.objects.ObjectList) EnumSet(java.util.EnumSet) Camera(net.minecraft.client.render.Camera) MinecraftClient(net.minecraft.client.MinecraftClient) Vector3f(net.minecraft.client.util.math.Vector3f)

Example 5 with Vector3f

use of net.minecraft.client.util.math.Vector3f in project canvas by vram-guild.

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 = ao;
    final int[] lightResult = light;
    // TODO: currently no way to handle 3d interpolation shader-side
    quad.blockLight = null;
    quad.skyLight = null;
    quad.aoShade = null;
    for (int i = 0; i < 4; i++) {
        normal = quad.hasNormal(i) ? quad.copyNormal(i, vertexNormal) : faceNorm;
        float ao = 0, sky = 0, block = 0;
        int maxSky = 0, maxBlock = 0;
        float maxAo = 0;
        final float x = normal.getX();
        if (!MathHelper.approximatelyEquals(0f, x)) {
            final int face = x > 0 ? EAST : WEST;
            // PERF: really need to cache these
            final AoFaceCalc fd = blendedInsetData(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.approximatelyEquals(0f, y)) {
            final int face = y > 0 ? UP : DOWN;
            final AoFaceCalc fd = blendedInsetData(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(a, maxAo);
            maxSky = Math.max(s, maxSky);
            maxBlock = Math.max(b, maxBlock);
        }
        final float z = normal.getZ();
        if (!MathHelper.approximatelyEquals(0f, z)) {
            final int face = z > 0 ? SOUTH : NORTH;
            final AoFaceCalc fd = blendedInsetData(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(a, maxAo);
            maxSky = Math.max(s, maxSky);
            maxBlock = Math.max(b, maxBlock);
        }
        aoResult[i] = (ao + maxAo) * (0.5f * DIVIDE_BY_255);
        lightResult[i] = (((int) ((sky + maxSky) * 0.5f) & 0xFF) << 16) | ((int) ((block + maxBlock) * 0.5f) & 0xFF);
    }
}
Also used : Vector3f(net.minecraft.client.util.math.Vector3f)

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