Skip to content

Commit

Permalink
Work with meshes
Browse files Browse the repository at this point in the history
  • Loading branch information
miyucomics committed Jul 9, 2024
1 parent ab1a31b commit 031519b
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 28 deletions.
50 changes: 28 additions & 22 deletions src/main/java/miyucomics/hexical/casting/patterns/OpReweave.kt
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
package miyucomics.hexical.casting.patterns

import at.petrak.hexcasting.api.misc.MediaConstants
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellAction
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getVec3
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.iota.Vec3Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapBadEntity
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
import at.petrak.hexcasting.api.spell.mishaps.MishapLocationTooFarAway
import miyucomics.hexical.entities.MeshEntity
import net.minecraft.util.math.MathHelper
import net.minecraft.util.math.Vec2f
import net.minecraft.util.math.Vec3d

class OpReweave : SpellAction {
override val argc = 1
override val argc = 2
override fun execute(args: List<Iota>, ctx: CastingContext): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val headOffset = args.getVec3(0, argc)
val xAxis = ctx.caster.rotationVector
val upPitch = (-ctx.caster.pitch + 90) * (Math.PI.toFloat() / 180)
val yaw = -ctx.caster.headYaw * (Math.PI.toFloat() / 180)
val h = MathHelper.cos(yaw).toDouble()
val j = MathHelper.cos(upPitch).toDouble()
val yAxis = Vec3d(MathHelper.sin(yaw).toDouble() * j, MathHelper.sin(upPitch).toDouble(), h * j)
val zAxis = xAxis.crossProduct(yAxis).normalize()
val offset = Vec3d.ZERO
.add(xAxis.multiply(headOffset.x))
.add(yAxis.multiply(headOffset.y))
.add(zAxis.multiply(headOffset.z))
if (offset.length() > 128)
throw MishapLocationTooFarAway(ctx.caster.eyePos.add(offset))
return Triple(Spell(ctx.caster.eyePos.add(offset)), MediaConstants.SHARD_UNIT * 2, listOf())
val mesh = args.getEntity(0, argc)
if (mesh !is MeshEntity)
throw MishapBadEntity.of(mesh, "mesh")

val design = args.getList(1, argc)
if (design.size() > 32)
throw MishapInvalidIota.of(args[1], 1, "mesh_vector_list")
val shape = mutableListOf<Vec3d>()
for (point in design) {
if (point.type != Vec3Iota.TYPE)
throw MishapInvalidIota.of(args[1], 1, "mesh_vector_list")
else {
val vector = (point as Vec3Iota).vec3
if (vector.length() > 32)
throw MishapInvalidIota.of(args[1], 1, "mesh_vector_list")
shape.add(vector)
}
}
return Triple(Spell(mesh, shape), MediaConstants.DUST_UNIT, listOf())
}

private data class Spell(val position: Vec3d) : RenderedSpell {
private data class Spell(val mesh: MeshEntity, val shape: List<Vec3d>) : RenderedSpell {
override fun cast(ctx: CastingContext) {
ctx.caster.teleport(position.x, position.y, position.z)
mesh.setShape(shape)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class OpSpecklikeProperty(val mode: Int) : ConstMediaAction {
0 -> {
val position = args.getVec3(1, argc)
ctx.assertVecInRange(position)
specklike.setPosition(position)
specklike.setPosition(position.subtract(0.0, specklike.standingEyeHeight.toDouble(), 0.0))
}
1 -> specklike.lookAt(EntityAnchorArgumentType.EntityAnchor.FEET, specklike.pos.add(args.getVec3(1, argc)))
2 -> (specklike as Specklike).setRoll(args.getDoubleBetween(1, 0.0, 1.0, argc).toFloat() * 360)
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/miyucomics/hexical/entities/MeshRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package miyucomics.hexical.entities

import com.mojang.blaze3d.systems.RenderSystem
import miyucomics.hexical.utils.RenderUtils
import net.minecraft.client.MinecraftClient
import net.minecraft.client.render.Frustum
import net.minecraft.client.render.GameRenderer
import net.minecraft.client.render.VertexConsumerProvider
Expand All @@ -20,16 +21,18 @@ class MeshRenderer(ctx: EntityRendererFactory.Context) : EntityRenderer<MeshEnti
RenderSystem.enableDepthTest()
matrices.push()

val pos = MinecraftClient.getInstance().player!!.pos
if (entity!!.yaw != 0.0f)
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-entity.yaw))
if (entity.pitch != 0.0f)
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(entity.pitch))
if (entity.clientRoll != 0.0f)
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(entity.clientRoll))
matrices.scale(entity.clientSize, entity.clientSize, entity.clientSize)
matrices.scale(entity!!.clientSize, entity.clientSize, entity.clientSize)
matrices.translate(entity.x - pos.x, entity.y - pos.y, entity.z - pos.z)

RenderSystem.disableCull()
RenderUtils.sentinelLike(matrices, entity.clientVertices, entity.clientThickness * 0.05f, entity.clientPigment)
RenderUtils.sentinelLike(matrices, entity.clientVertices, 5f, entity.clientPigment)
RenderSystem.enableCull()

matrices.pop()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/miyucomics/hexical/entities/SpeckEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SpeckEntity(entityType: EntityType<SpeckEntity?>?, world: World?) : Entity
super.tick()
}

override fun getEyeHeight(pose: EntityPose, dimensions: EntityDimensions) = 0f
override fun getEyeHeight(pose: EntityPose, dimensions: EntityDimensions) = 0.5f

override fun initDataTracker() {
dataTracker.startTracking(displayDataTracker, NbtCompound())
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/miyucomics/hexical/registry/HexicalEvents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking
import net.minecraft.client.MinecraftClient

object HexicalEvents {
private val MEDIA_SICKNESS_SHADER = ShaderEffectManager.getInstance().manage(HexicalMain.id("shaders/post/media_vision.json"))
private val NIGHT_VISION_SHADER = ShaderEffectManager.getInstance().manage(HexicalMain.id("shaders/post/night_vision.json"))

@JvmStatic
fun init() {
Expand Down Expand Up @@ -55,7 +55,7 @@ object HexicalEvents {
ShaderEffectRenderCallback.EVENT.register(ShaderEffectRenderCallback { tickDelta: Float ->
val player = MinecraftClient.getInstance().player ?: return@ShaderEffectRenderCallback
if (player.hasStatusEffect(HexicalStatusEffects.MEDIA_VISION_STATUS_EFFECT))
MEDIA_SICKNESS_SHADER.render(tickDelta)
NIGHT_VISION_SHADER.render(tickDelta)
})
}
}
2 changes: 2 additions & 0 deletions src/main/java/miyucomics/hexical/registry/HexicalPatterns.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ object HexicalPatterns {
register("conjure_hexburst", "edeqaawaa", HexDir.SOUTH_WEST, OpConjureHexburst())
register("conjure_hextito", "edeaddadd", HexDir.SOUTH_WEST, OpConjureHextito())

register("shape_mesh", "dwaqawd", HexDir.SOUTH_EAST, OpReweave())

register("conjure_speck", "ade", HexDir.SOUTH_WEST, OpConjureSpeck())
register("iota_speck", "adeeaqa", HexDir.SOUTH_WEST, OpIotaSpeck())
register("kill_specklike", "adeaqde", HexDir.SOUTH_WEST, OpKillSpecklike())
Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/assets/hexical/shaders/post/night_vision.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"targets": [
"swap"
],
"passes": [
{
"name": "hexical:night_vision",
"intarget": "minecraft:main",
"outtarget": "swap"
}, {
"name": "blit",
"intarget": "swap",
"outtarget": "minecraft:main"
}
]
}
13 changes: 13 additions & 0 deletions src/main/resources/assets/hexical/shaders/program/night_vision.fsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#version 150

uniform sampler2D DiffuseSampler;

in vec2 texCoord;
out vec4 fragColor;

void main() {
vec3 color = texture(DiffuseSampler, texCoord).rgb;
color *= 3.;
color = mix(vec3(dot(color, vec3(.5))), color, .5);
fragColor = vec4(color, 1.0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"blend": {
"func": "add",
"srcrgb": "srcalpha",
"dstrgb": "1-srcalpha"
},
"vertex": "sobel",
"fragment": "hexical:night_vision",
"attributes": ["Position"],
"samplers": [
{
"name": "DiffuseSampler"
}
],
"uniforms": [
{
"name": "ProjMat",
"type": "matrix4x4",
"count": 16,
"values": [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
}, {
"name": "OutSize",
"type": "float",
"count": 2,
"values": [1.0, 1.0]
}
]
}

0 comments on commit 031519b

Please sign in to comment.