fix pixlyzer model offsetting

This commit is contained in:
Moritz Zwerger 2023-08-01 16:16:44 +02:00
parent 4044e9a0ba
commit 0000f39be9
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 26 additions and 6 deletions

View File

@ -56,5 +56,17 @@ class ElementRotationTest {
baked.assertFace(Directions.UP, floatArrayOf(0.5f, 1.0f, -0.2f, 1.2f, 1.0f, 0.5f, 0.5f, 1.0f, 1.2f, -0.2f, 1.0f, 0.5f), rbgy, 1.0f)
}
fun `rotate grass around origin 45 degree on the y axis and rescale`() {
val from = Vec3(0.8, 0, 8) / 16
val to = Vec3(15.2, 16, 8) / 16
val model = SingleBlockStateApply(BlockModel(elements = listOf(ModelElement(from, to, faces = createFaces(), rotation = ElementRotation(origin = Vec3(0.5f), axis = Axes.Y, angle = 45.0f, rescale = true))), textures = mapOf("test" to minecraft("block/test").texture())))
val baked = model.bake(createTextureManager("block/test"))!!
baked.assertFace(Directions.NORTH, floatArrayOf(0.05f, 0.0f, 0.95f, 0.95f, 0.0f, 0.05f, 0.95f, 1.0f, 0.05f, 0.05f, 1.0f, 0.95f))
}
// TODO: a,z axis
}

View File

@ -101,7 +101,7 @@ class TargetHandler(
return null
}
var shape = state.block.getOutlineShape(camera.connection, state) ?: return null
state.block.nullCast<RandomOffsetBlock>()?.offsetBlock(blockPosition)?.let { shape += it }
state.block.nullCast<RandomOffsetBlock>()?.offsetShape(blockPosition)?.let { shape += it }
shape += blockPosition

View File

@ -104,11 +104,16 @@ open class PixLyzerBlock(
return identifier.toString()
}
override fun offsetBlock(position: Vec3i): Vec3 {
override fun offsetShape(position: Vec3i): Vec3 {
val offset = randomOffset ?: return Vec3.EMPTY
return super.offsetBlock(position) + if (offset == RandomOffsetTypes.XZ) NULL_OFFSET_XZ else NULL_OFFSET_XYZ // this corrects wrong pixlyzer data
return super.offsetShape(position) + if (offset == RandomOffsetTypes.XZ) NULL_OFFSET_XZ else NULL_OFFSET_XYZ // this corrects wrong pixlyzer data
}
override fun offsetModel(position: Vec3i): Vec3 {
return super.offsetShape(position)
}
companion object : ResourceLocationCodec<Block>, PixLyzerBlockFactory<Block>, MultiClassFactory<Block> {
private val NULL_OFFSET_XYZ = Vec3i(0, 0, 0).getWorldOffset(RandomOffsetTypes.XYZ)
private val NULL_OFFSET_XZ = Vec3i(0, 0, 0).getWorldOffset(RandomOffsetTypes.XZ)

View File

@ -22,8 +22,10 @@ interface RandomOffsetBlock {
val randomOffset: RandomOffsetTypes? // TODO: make non nullable
fun offsetBlock(position: Vec3i): Vec3 {
fun offsetShape(position: Vec3i): Vec3 {
val offset = this.randomOffset ?: return Vec3.EMPTY
return position.getWorldOffset(offset)
}
fun offsetModel(position: Vec3i): Vec3 = offsetShape(position)
}

View File

@ -124,7 +124,7 @@ class BlockOutlineRenderer(
val blockOffset = target.blockPosition.toVec3d
if (target.state.block is RandomOffsetBlock) {
blockOffset += target.state.block.offsetBlock(target.blockPosition)
blockOffset += target.state.block.offsetShape(target.blockPosition)
}

View File

@ -139,12 +139,13 @@ class SolidSectionMesher(
var offset: Vec3? = null
if (state.block is RandomOffsetBlock) {
offset = state.block.offsetBlock(position)
offset = state.block.offsetModel(position)
floatOffset[0] += offset.x
floatOffset[1] += offset.y
floatOffset[2] += offset.z
}
val tints = tints.getAverageBlockTint(chunk, neighbourChunks, state, x, y, z)
var rendered = model.render(position, floatOffset, mesh, random, state, neighbourBlocks, light, tints)