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;
}
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;
}
}
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));
}
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;
}
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);
}
}
Aggregations