Skip to content

Commit a7bfd25

Browse files
authored
Merge pull request #29 from Avanatiker/feature/renderer
[1.20.x, 1.21.x] 3d Renderer
2 parents 20ed407 + 7a6229c commit a7bfd25

File tree

18 files changed

+321
-256
lines changed

18 files changed

+321
-256
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ import com.lambda.Lambda.mc
44
import com.lambda.event.Event
55
import com.lambda.event.callback.Cancellable
66
import com.lambda.event.callback.ICancellable
7-
import com.lambda.graphics.renderer.esp.global.BlockESPRenderer
8-
import com.lambda.graphics.renderer.esp.global.EntityESPRenderer
7+
import com.lambda.graphics.renderer.esp.global.StaticESP
8+
import com.lambda.graphics.renderer.esp.global.DynamicESP
99
import com.lambda.util.math.Vec2d
1010

1111
abstract class RenderEvent : Event {
1212
class World : RenderEvent()
1313

14-
class BlockESP : RenderEvent() {
15-
val renderer = BlockESPRenderer
14+
class StaticESP : RenderEvent() {
15+
val renderer = StaticESP
1616
}
1717

18-
class EntityESP : RenderEvent() {
19-
val renderer = EntityESPRenderer
18+
class DynamicESP : RenderEvent() {
19+
val renderer = DynamicESP
2020
}
2121

2222
abstract class GUI(val scale: Double) : RenderEvent() {

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
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
package com.lambda.graphics.renderer.esp.global
1+
package com.lambda.graphics.renderer.esp.builders
22

33
import com.lambda.graphics.renderer.esp.DirectionMask
44
import com.lambda.graphics.renderer.esp.DirectionMask.hasDirection
5-
import com.lambda.graphics.renderer.esp.ESPRenderer
5+
import com.lambda.graphics.renderer.esp.impl.ESPRenderer
6+
import com.lambda.graphics.renderer.esp.impl.StaticESPRenderer
67
import com.lambda.util.primitives.extension.max
78
import com.lambda.util.primitives.extension.min
89
import net.minecraft.util.math.Box
910
import java.awt.Color
1011

11-
fun ESPRenderer.build(
12+
fun StaticESPRenderer.build(
1213
box: Box,
1314
filledColor: Color,
1415
outlineColor: Color,
@@ -19,20 +20,20 @@ fun ESPRenderer.build(
1920
buildOutline(box, outlineColor, sides, outlineMode)
2021
}
2122

22-
fun ESPRenderer.buildFilled(
23+
fun StaticESPRenderer.buildFilled(
2324
box: Box,
2425
color: Color,
2526
sides: Int = DirectionMask.ALL
2627
) = buildFilled(box, color, color, sides)
2728

28-
fun ESPRenderer.buildOutline(
29+
fun StaticESPRenderer.buildOutline(
2930
box: Box,
3031
color: Color,
3132
sides: Int = DirectionMask.ALL,
3233
outlineMode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.OR
3334
) = buildOutline(box, color, color, sides, outlineMode)
3435

35-
fun ESPRenderer.buildFilled(
36+
fun StaticESPRenderer.buildFilled(
3637
box: Box,
3738
colorBottom: Color,
3839
colorTop: Color = colorBottom,
@@ -42,7 +43,6 @@ fun ESPRenderer.buildFilled(
4243
val pos2 = box.max
4344

4445
grow(8)
45-
updateFaces = true
4646

4747
val blb by vertex(faceVertices, pos1.x, pos1.y, pos1.z, colorBottom)
4848
val blf by vertex(faceVertices, pos1.x, pos1.y, pos2.z, colorBottom)
@@ -59,9 +59,11 @@ fun ESPRenderer.buildFilled(
5959
if (sides.hasDirection(DirectionMask.DOWN)) putQuad(blb, brb, brf, blf)
6060
if (sides.hasDirection(DirectionMask.SOUTH)) putQuad(blf, brf, trf, tlf)
6161
if (sides.hasDirection(DirectionMask.NORTH)) putQuad(blb, tlb, trb, brb)
62+
63+
updateFaces = true
6264
}
6365

64-
fun ESPRenderer.buildOutline(
66+
fun StaticESPRenderer.buildOutline(
6567
box: Box,
6668
colorBottom: Color,
6769
colorTop: Color = colorBottom,
@@ -72,7 +74,6 @@ fun ESPRenderer.buildOutline(
7274
val pos2 = box.max
7375

7476
grow(8)
75-
updateOutlines = true
7677

7778
val blb by vertex(outlineVertices, pos1.x, pos1.y, pos1.z, colorBottom)
7879
val blf by vertex(outlineVertices, pos1.x, pos1.y, pos2.z, colorBottom)
@@ -104,4 +105,6 @@ fun ESPRenderer.buildOutline(
104105
if (outlineMode.check(hasNorth, hasEast)) putLine(trb, brb)
105106
if (outlineMode.check(hasEast, hasSouth)) putLine(trf, brf)
106107
if (outlineMode.check(hasSouth, hasWest)) putLine(tlf, blf)
108+
109+
updateOutlines = true
107110
}

0 commit comments

Comments
 (0)