-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now we have: - limited number of `Echo`s -- they should be ideally only one per Id, for now it is one per one scan; in the future, the label might be also stored there - `BlockEcho` is an `Echo` with a position and ping time. - _(new)_ `EchoState` is a `BlockEcho`, with information, which sides and edges are visible - _(new)_ `EchoNugget` is a clump of all touching echoes of the same id - `BlockEchoes` is a container for all known `BlockEcho`es and now a container of all known `EchoNugget`s fixes: #22 closes: #23
- Loading branch information
Showing
35 changed files
with
1,616 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
fabric/any/src/main/java/com/midnightbits/scanner/fabric/Mesh.java
This file was deleted.
Oops, something went wrong.
179 changes: 0 additions & 179 deletions
179
fabric/any/src/main/java/com/midnightbits/scanner/fabric/Pixel.java
This file was deleted.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
fabric/any/src/main/java/com/midnightbits/scanner/fabric/Pixels.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright (c) 2024 Marcin Zdun | ||
// This code is licensed under MIT license (see LICENSE for details) | ||
|
||
package com.midnightbits.scanner.fabric; | ||
|
||
import java.util.List; | ||
|
||
import com.midnightbits.scanner.sonar.EchoNugget; | ||
import com.midnightbits.scanner.sonar.graphics.*; | ||
import net.minecraft.client.render.*; | ||
import net.minecraft.util.math.Box; | ||
import org.joml.Matrix4f; | ||
|
||
import com.mojang.blaze3d.platform.GlStateManager; | ||
import com.mojang.blaze3d.systems.RenderSystem; | ||
|
||
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; | ||
|
||
public class Pixels { | ||
|
||
private record GlProgramVertexConsumer(VertexConsumer buffer) implements GlProgramConsumer { | ||
@Override | ||
public void vertexColor(Matrix4f matrix, float x, float y, float z, int argb32) { | ||
buffer.vertex(matrix, x, y, z).color(argb32); | ||
} | ||
} | ||
|
||
public static void renderLevel(WorldRenderContext context, List<EchoNugget> nuggets, List<Shimmers> shimmers) { | ||
final var frustum = context.frustum(); | ||
if (frustum == null) { | ||
return; | ||
} | ||
|
||
final var contextMatrices = context.matrixStack(); | ||
if (contextMatrices == null) { | ||
return; | ||
} | ||
|
||
final var matrices = new MatrixStack(contextMatrices.peek().getPositionMatrix()); | ||
|
||
final var camera = context.camera(); | ||
final var cameraPos = camera.getPos().toVector3f(); | ||
|
||
final var frustumFilter = new FrustumFilter() { | ||
@Override | ||
public boolean contains(EchoState.AABB bounds) { | ||
return frustum.isVisible( | ||
new Box(bounds.minX(), bounds.minY(), bounds.minZ(), | ||
bounds.maxX(), bounds.maxY(), bounds.maxZ())); | ||
} | ||
}; | ||
|
||
final var allShimmers = EchoNugget.group(Shimmers.toEchoStates(shimmers, .5)); | ||
|
||
final var visibleNuggets = EchoNugget.filterVisible(nuggets, frustumFilter); | ||
final var visibleShimmers = EchoNugget.filterVisible(allShimmers, frustumFilter); | ||
|
||
if (visibleNuggets.isEmpty() && visibleShimmers.isEmpty()) { | ||
return; | ||
} | ||
|
||
RenderSystem.disableDepthTest(); | ||
RenderSystem.enableBlend(); | ||
RenderSystem.blendFunc( | ||
GlStateManager.SrcFactor.SRC_ALPHA, | ||
GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA); | ||
RenderSystem.setShader(GameRenderer::getPositionColorProgram); | ||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); | ||
|
||
final var tessellator = Tessellator.getInstance(); | ||
{ | ||
final var buffer = tessellator.begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR); | ||
final var glProgram = new GlProgramVertexConsumer(buffer); | ||
|
||
for (final var nugget : visibleShimmers) { | ||
nugget.draw(glProgram, matrices, cameraPos); | ||
} | ||
|
||
for (final var nugget: visibleNuggets) { | ||
nugget.draw(glProgram, matrices, cameraPos); | ||
} | ||
|
||
final var builtBuffer = buffer.endNullable(); | ||
if (builtBuffer != null) | ||
BufferRenderer.drawWithGlobalProgram(builtBuffer); | ||
} | ||
|
||
{ | ||
final var buffer = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR); | ||
final var glProgram = new GlProgramVertexConsumer(buffer); | ||
|
||
for (final var nugget: visibleNuggets) { | ||
nugget.sketch(glProgram, matrices, cameraPos); | ||
} | ||
|
||
final var builtBuffer = buffer.endNullable(); | ||
if (builtBuffer != null) | ||
BufferRenderer.drawWithGlobalProgram(builtBuffer); | ||
} | ||
|
||
RenderSystem.enableDepthTest(); | ||
} | ||
} |
Oops, something went wrong.