Merge pull request #29 from Avanatiker/feature/renderer · lambda-client/lambda@fe4eb3b · GitHub
Skip to content

Commit fe4eb3b

Browse files
committed
Merge pull request #29 from Avanatiker/feature/renderer
[1.20.x, 1.21.x] 3d Renderer
1 parent 4eb6aec commit fe4eb3b

18 files changed

Lines changed: 321 additions & 256 deletions

File tree

common/src/main/kotlin/com/lambda/event/events/RenderEvent.kt

Lines changed: 6 additions & 6 deletions

common/src/main/kotlin/com/lambda/graphics/RenderMain.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import com.lambda.graphics.gl.GlStateUtils.setupGL
77
import com.lambda.graphics.gl.Matrices
88
import com.lambda.graphics.gl.Matrices.resetMatrix
99
import com.lambda.graphics.gl.Matrices.translate
10-
import com.lambda.graphics.renderer.esp.global.BlockESPRenderer
11-
import com.lambda.graphics.renderer.esp.global.EntityESPRenderer
10+
import com.lambda.graphics.renderer.esp.global.StaticESP
11+
import com.lambda.graphics.renderer.esp.global.DynamicESP
1212
import com.lambda.module.modules.client.GuiSettings
1313
import com.lambda.util.math.Vec2d
1414
import com.mojang.blaze3d.systems.RenderSystem.getProjectionMatrix
@@ -42,8 +42,8 @@ object RenderMain {
4242

4343
setupGL {
4444
RenderEvent.World().post()
45-
BlockESPRenderer.render()
46-
EntityESPRenderer.render()
45+
StaticESP.render()
46+
DynamicESP.render()
4747
}
4848
}
4949

common/src/main/kotlin/com/lambda/graphics/renderer/esp/ChunkedESP.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import com.lambda.event.events.WorldEvent
66
import com.lambda.event.listener.SafeListener.Companion.concurrentListener
77
import com.lambda.event.listener.SafeListener.Companion.listener
88
import com.lambda.graphics.buffer.vao.vertex.BufferUsage
9+
import com.lambda.graphics.renderer.esp.impl.ESPRenderer
10+
import com.lambda.graphics.renderer.esp.impl.StaticESPRenderer
911
import com.lambda.module.modules.client.RenderSettings
1012
import com.lambda.threading.awaitMainThread
1113
import net.minecraft.util.math.ChunkPos
@@ -16,7 +18,7 @@ import java.util.concurrent.ConcurrentLinkedDeque
1618

1719
class ChunkedESP private constructor(
1820
owner: Any,
19-
private val update: ESPRenderer.(WorldView, Int, Int, Int) -> Unit
21+
private val update: StaticESPRenderer.(WorldView, Int, Int, Int) -> Unit
2022
) {
2123
private val rendererMap = ConcurrentHashMap<Long, EspChunk>()
2224
private val WorldChunk.renderer get() = rendererMap.getOrPut(pos.toLong()) {
@@ -76,7 +78,7 @@ class ChunkedESP private constructor(
7678

7779
companion object {
7880
fun Any.newChunkedESP(
79-
update: ESPRenderer.(WorldView, Int, Int, Int) -> Unit
81+
update: StaticESPRenderer.(WorldView, Int, Int, Int) -> Unit
8082
) = ChunkedESP(this, update)
8183
}
8284

@@ -101,7 +103,7 @@ class ChunkedESP private constructor(
101103

102104
suspend fun rebuild() {
103105
val newRenderer = awaitMainThread {
104-
ESPRenderer(BufferUsage.STATIC)
106+
StaticESPRenderer(BufferUsage.STATIC)
105107
}
106108

107109
iterateChunk { x, y, z ->
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.lambda.graphics.renderer.esp
2+
3+
import com.lambda.util.math.VecUtils.minus
4+
import com.lambda.util.math.VecUtils.plus
5+
import com.lambda.util.primitives.extension.max
6+
import com.lambda.util.primitives.extension.min
7+
import com.lambda.util.primitives.extension.prevPos
8+
import net.minecraft.entity.Entity
9+
import net.minecraft.util.math.Box
10+
11+
class DynamicAABB {
12+
private var prev: Box? = null
13+
private var curr: Box? = null
14+
15+
fun update(box: Box) {
16+
prev = curr
17+
curr = box
18+
19+
if (prev == null) {
20+
prev = box
21+
}
22+
}
23+
24+
fun reset() {
25+
prev = null
26+
curr = null
27+
}
28+
29+
fun getBoxPair(): Pair<Box, Box>? {
30+
prev?.let { previous ->
31+
curr?.let { current ->
32+
return previous to current
33+
}
34+
}
35+
36+
return null
37+
}
38+
39+
companion object {
40+
val Entity.dynamicBox get() = DynamicAABB().apply {
41+
val box = boundingBox
42+
43+
val delta = prevPos - pos
44+
val prevBox = Box(box.min + delta, box.max + delta)
45+
46+
update(prevBox)
47+
update(box)
48+
}
49+
}
50+
}

common/src/main/kotlin/com/lambda/graphics/renderer/esp/ESPRenderer.kt

Lines changed: 0 additions & 71 deletions
This file was deleted.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.lambda.graphics.renderer.esp.builders
2+
3+
import com.lambda.graphics.renderer.esp.DirectionMask
4+
import com.lambda.graphics.renderer.esp.DirectionMask.hasDirection
5+
import com.lambda.graphics.renderer.esp.DynamicAABB
6+
import com.lambda.graphics.renderer.esp.impl.DynamicESPRenderer
7+
import com.lambda.util.primitives.extension.max
8+
import com.lambda.util.primitives.extension.min
9+
import java.awt.Color
10+
11+
fun DynamicESPRenderer.build(
12+
box: DynamicAABB,
13+
filledColor: Color,
14+
outlineColor: Color,
15+
sides: Int = DirectionMask.ALL,
16+
outlineMode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.OR
17+
) {
18+
buildFilled(box, filledColor, sides)
19+
buildOutline(box, outlineColor, sides, outlineMode)
20+
}
21+
22+
fun DynamicESPRenderer.buildFilled(
23+
box: DynamicAABB,
24+
color: Color,
25+
sides: Int = DirectionMask.ALL
26+
) = faces.use {
27+
val boxes = box.getBoxPair() ?: return@use
28+
29+
val pos11 = boxes.first.min
30+
val pos12 = boxes.first.max
31+
val pos21 = boxes.second.min
32+
val pos22 = boxes.second.max
33+
34+
grow(8)
35+
36+
val blb by lazy { vec3(pos11.x, pos11.y, pos11.z).vec3(pos21.x, pos21.y, pos21.z).color(color).end() }
37+
val blf by lazy { vec3(pos11.x, pos11.y, pos12.z).vec3(pos21.x, pos21.y, pos22.z).color(color).end() }
38+
val brb by lazy { vec3(pos12.x, pos11.y, pos11.z).vec3(pos22.x, pos21.y, pos21.z).color(color).end() }
39+
val brf by lazy { vec3(pos12.x, pos11.y, pos12.z).vec3(pos22.x, pos21.y, pos22.z).color(color).end() }
40+
val tlb by lazy { vec3(pos11.x, pos12.y, pos11.z).vec3(pos21.x, pos22.y, pos21.z).color(color).end() }
41+
val tlf by lazy { vec3(pos11.x, pos12.y, pos12.z).vec3(pos21.x, pos22.y, pos22.z).color(color).end() }
42+
val trb by lazy { vec3(pos12.x, pos12.y, pos11.z).vec3(pos22.x, pos22.y, pos21.z).color(color).end() }
43+
val trf by lazy { vec3(pos12.x, pos12.y, pos12.z).vec3(pos22.x, pos22.y, pos22.z).color(color).end() }
44+
45+
if (sides.hasDirection(DirectionMask.EAST)) putQuad(brb, trb, trf, brf)
46+
if (sides.hasDirection(DirectionMask.WEST)) putQuad(blb, blf, tlf, tlb)
47+
if (sides.hasDirection(DirectionMask.UP)) putQuad(tlb, tlf, trf, trb)
48+
if (sides.hasDirection(DirectionMask.DOWN)) putQuad(blb, brb, brf, blf)
49+
if (sides.hasDirection(DirectionMask.SOUTH)) putQuad(blf, brf, trf, tlf)
50+
if (sides.hasDirection(DirectionMask.NORTH)) putQuad(blb, tlb, trb, brb)
51+
}
52+
53+
fun DynamicESPRenderer.buildOutline(
54+
box: DynamicAABB,
55+
color: Color,
56+
sides: Int = DirectionMask.ALL,
57+
outlineMode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.OR
58+
) = outlines.use {
59+
val boxes = box.getBoxPair() ?: return@use
60+
61+
val pos11 = boxes.first.min
62+
val pos12 = boxes.first.max
63+
val pos21 = boxes.second.min
64+
val pos22 = boxes.second.max
65+
66+
grow(8)
67+
68+
val blb by lazy { vec3(pos11.x, pos11.y, pos11.z).vec3(pos21.x, pos21.y, pos21.z).color(color).end() }
69+
val blf by lazy { vec3(pos11.x, pos11.y, pos12.z).vec3(pos21.x, pos21.y, pos22.z).color(color).end() }
70+
val brb by lazy { vec3(pos12.x, pos11.y, pos11.z).vec3(pos22.x, pos21.y, pos21.z).color(color).end() }
71+
val brf by lazy { vec3(pos12.x, pos11.y, pos12.z).vec3(pos22.x, pos21.y, pos22.z).color(color).end() }
72+
val tlb by lazy { vec3(pos11.x, pos12.y, pos11.z).vec3(pos21.x, pos22.y, pos21.z).color(color).end() }
73+
val tlf by lazy { vec3(pos11.x, pos12.y, pos12.z).vec3(pos21.x, pos22.y, pos22.z).color(color).end() }
74+
val trb by lazy { vec3(pos12.x, pos12.y, pos11.z).vec3(pos22.x, pos22.y, pos21.z).color(color).end() }
75+
val trf by lazy { vec3(pos12.x, pos12.y, pos12.z).vec3(pos22.x, pos22.y, pos22.z).color(color).end() }
76+
77+
val hasEast = sides.hasDirection(DirectionMask.EAST)
78+
val hasWest = sides.hasDirection(DirectionMask.WEST)
79+
val hasUp = sides.hasDirection(DirectionMask.UP)
80+
val hasDown = sides.hasDirection(DirectionMask.DOWN)
81+
val hasSouth = sides.hasDirection(DirectionMask.SOUTH)
82+
val hasNorth = sides.hasDirection(DirectionMask.NORTH)
83+
84+
if (outlineMode.check(hasUp, hasNorth)) putLine(tlb, trb)
85+
if (outlineMode.check(hasUp, hasSouth)) putLine(tlf, trf)
86+
if (outlineMode.check(hasUp, hasWest)) putLine(tlb, tlf)
87+
if (outlineMode.check(hasUp, hasEast)) putLine(trf, trb)
88+
89+
if (outlineMode.check(hasDown, hasNorth)) putLine(blb, brb)
90+
if (outlineMode.check(hasDown, hasSouth)) putLine(blf, brf)
91+
if (outlineMode.check(hasDown, hasWest)) putLine(blb, blf)
92+
if (outlineMode.check(hasDown, hasEast)) putLine(brb, brf)
93+
94+
if (outlineMode.check(hasWest, hasNorth)) putLine(tlb, blb)
95+
if (outlineMode.check(hasNorth, hasEast)) putLine(trb, brb)
96+
if (outlineMode.check(hasEast, hasSouth)) putLine(trf, brf)
97+
if (outlineMode.check(hasSouth, hasWest)) putLine(tlf, blf)
98+
}

common/src/main/kotlin/com/lambda/graphics/renderer/esp/global/ESPBuilders.kt renamed to common/src/main/kotlin/com/lambda/graphics/renderer/esp/builders/StaticESPBuilders.kt

Lines changed: 12 additions & 9 deletions

0 commit comments

Comments
 (0)