OctreeDebugRenderer .java

net.minecraft.client.renderer.debug.OctreeDebugRenderer (class): members: frustum, emitGizmos, minecraft. imports: Octree, GizmoStyle, MutableInt, Gizmos.

net.minecraft.client.renderer.debugclass58 linesclient2.1 KB

Implements

API Surface (1)

void emitGizmos(final double camX, final double camY, final double camZ, final DebugValueAccess debugValues, final Frustum frustum, final float partialTicks)

Fields & Constants (2)

minecraft
frustum

Full Source

OctreeDebugRenderer.java58 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer.debug;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.client.Minecraft;
6
import net.minecraft.client.renderer.Octree;
7
import net.minecraft.client.renderer.culling.Frustum;
8
import net.minecraft.gizmos.GizmoStyle;
9
import net.minecraft.gizmos.Gizmos;
10
import net.minecraft.gizmos.TextGizmo.Style;
11
import net.minecraft.util.ARGB;
12
import net.minecraft.util.Mth;
13
import net.minecraft.util.debug.DebugValueAccess;
14
import net.minecraft.world.phys.AABB;
15
import org.apache.commons.lang3.mutable.MutableInt;
16
17
@Environment(EnvType.CLIENT)
18
public class OctreeDebugRenderer implements DebugRenderer.SimpleDebugRenderer {
19
	private final Minecraft minecraft;
20
21
	public OctreeDebugRenderer(final Minecraft minecraft) {
22
		this.minecraft = minecraft;
23
	}
24
25
	@Override
26
	public void emitGizmos(
27
		final double camX, final double camY, final double camZ, final DebugValueAccess debugValues, final Frustum frustum, final float partialTicks
28
	) {
29
		Octree octree = this.minecraft.levelRenderer.sectionOcclusionGraph().getOctree();
30
		MutableInt count = new MutableInt(0);
31
		octree.visitNodes((node, fullyVisible, depth, isClose) -> this.renderNode(node, depth, fullyVisible, count, isClose), frustum, 32);
32
	}
33
34
	private void renderNode(final Octree.Node node, final int depth, final boolean fullyVisible, final MutableInt count, final boolean isClose) {
35
		AABB aabb = node.getAABB();
36
		double xSize = aabb.getXsize();
37
		long size = Math.round(xSize / 16.0);
38
		if (size == 1L) {
39
			count.add(1);
40
			int color = isClose ? -16711936 : -1;
41
			Gizmos.billboardText(String.valueOf(count.intValue()), aabb.getCenter(), Style.forColorAndCentered(color).withScale(4.8F));
42
		}
43
44
		long colorNum = size + 5L;
45
		Gizmos.cuboid(
46
			aabb.deflate(0.1 * depth),
47
			GizmoStyle.stroke(
48
				ARGB.colorFromFloat(fullyVisible ? 0.4F : 1.0F, getColorComponent(colorNum, 0.3F), getColorComponent(colorNum, 0.8F), getColorComponent(colorNum, 0.5F))
49
			)
50
		);
51
	}
52
53
	private static float getColorComponent(final long size, final float multiplier) {
54
		float minColor = 0.1F;
55
		return Mth.frac(multiplier * (float)size) * 0.9F + 0.1F;
56
	}
57
}
58

Decompiled Minecraft 26.3 source of OctreeDebugRenderer (net/minecraft/client/renderer/debug/OctreeDebugRenderer.java) with Mojang official mappings, stored verbatim on the site.