mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 17:37:58 -04:00
fix pixlyzer model offsetting
This commit is contained in:
parent
4044e9a0ba
commit
0000f39be9
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user