skeletal: allow dynamic textures, change some stuff in skeletal system, wip player model

This commit is contained in:
Bixilon 2022-06-06 17:40:49 +02:00
parent f017b1db9f
commit 5379ce921b
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
17 changed files with 258 additions and 22 deletions

View File

@ -48,6 +48,9 @@ import de.bixilon.minosoft.data.registries.particle.data.BlockParticleData
import de.bixilon.minosoft.data.text.ChatColors
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.data.text.RGBColor
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.entity.models.DummyModel
import de.bixilon.minosoft.gui.rendering.entity.models.EntityModel
import de.bixilon.minosoft.gui.rendering.input.camera.EntityPositionInfo
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.advanced.block.BlockDustParticle
import de.bixilon.minosoft.gui.rendering.util.VecUtil.empty
@ -139,6 +142,9 @@ abstract class Entity(
protected var lastTickTime = -1L
open var model: EntityModel<out Entity>? = null
// fluids stuff
val fluidHeights: MutableMap<ResourceLocation, Float> = synchronizedMapOf()
var submergedFluid: Fluid? = null
@ -594,6 +600,8 @@ abstract class Entity(
open fun onAttack(attacker: Entity) = true
open fun createModel(renderWindow: RenderWindow): EntityModel<*>? = DummyModel(renderWindow, this)
companion object {
private val FLAGS_DATA = EntityDataField("ENTITY_FLAGS")

View File

@ -32,6 +32,9 @@ import de.bixilon.minosoft.data.registries.items.armor.DyeableArmorItem
import de.bixilon.minosoft.data.text.ChatColors
import de.bixilon.minosoft.data.text.RGBColor
import de.bixilon.minosoft.data.world.World
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.entity.models.EntityModel
import de.bixilon.minosoft.gui.rendering.entity.models.minecraft.player.PlayerModel
import de.bixilon.minosoft.gui.rendering.util.VecUtil.clamp
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.EMPTY
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
@ -117,7 +120,18 @@ abstract class PlayerEntity(
return ChatColors.RED
}
override fun createModel(renderWindow: RenderWindow): EntityModel<PlayerEntity>? {
return PlayerModel(renderWindow, this)
}
companion object {
private val ABSORPTION_HEARTS_DATA = EntityDataField("PLAYER_ABSORPTION_HEARTS")
private val SCORE_DATA = EntityDataField("PLAYER_SCORE")
private val SKIN_PARTS_DATA = EntityDataField("PLAYER_SKIN_PARTS_FLAGS")
private val MAIN_ARM_DATA = EntityDataField("PLAYER_SKIN_MAIN_HAND")
private val LEFT_SHOULDER_DATA_DATA = EntityDataField("PLAYER_LEFT_SHOULDER_DATA")
private val RIGHT_SHOULDER_DATA_DATA = EntityDataField("PLAYER_RIGHT_SHOULDER_DATA")
private val LAST_DEATH_POSITION_DATA = EntityDataField("PLAYER_LAST_DEATH_POSITION")
private val DIMENSIONS: Map<Poses, Vec2> = mapOf(
Poses.STANDING to Vec2(0.6f, 1.8f),
Poses.SLEEPING to Vec2(0.2f, 0.2f),
@ -127,12 +141,5 @@ abstract class PlayerEntity(
Poses.SNEAKING to Vec2(0.6f, 1.5f), // ToDo: This changed at some time
Poses.DYING to Vec2(0.2f, 0.2f),
)
private val ABSORPTION_HEARTS_DATA = EntityDataField("PLAYER_ABSORPTION_HEARTS")
private val SCORE_DATA = EntityDataField("PLAYER_SCORE")
private val SKIN_PARTS_DATA = EntityDataField("PLAYER_SKIN_PARTS_FLAGS")
private val MAIN_ARM_DATA = EntityDataField("PLAYER_SKIN_MAIN_HAND")
private val LEFT_SHOULDER_DATA_DATA = EntityDataField("PLAYER_LEFT_SHOULDER_DATA")
private val RIGHT_SHOULDER_DATA_DATA = EntityDataField("PLAYER_RIGHT_SHOULDER_DATA")
private val LAST_DEATH_POSITION_DATA = EntityDataField("PLAYER_LAST_DEATH_POSITION")
}
}

View File

@ -0,0 +1,63 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.gui.rendering.entity
import de.bixilon.kutil.latch.CountUpAndDownLatch
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.renderer.Renderer
import de.bixilon.minosoft.gui.rendering.renderer.RendererBuilder
import de.bixilon.minosoft.gui.rendering.system.base.RenderSystem
import de.bixilon.minosoft.gui.rendering.system.base.phases.OpaqueDrawable
import de.bixilon.minosoft.gui.rendering.system.base.phases.SkipAll
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
class EntityRenderer(
val connection: PlayConnection,
override val renderWindow: RenderWindow,
) : Renderer, OpaqueDrawable, SkipAll {
override val renderSystem: RenderSystem = renderWindow.renderSystem
val profile = connection.profiles.entity.hitbox
private val visibilityGraph = renderWindow.camera.visibilityGraph
override val skipAll: Boolean
get() = false
override fun init(latch: CountUpAndDownLatch) {
}
override fun setupOpaque() {
renderWindow.renderSystem.reset(faceCulling = false)
}
override fun drawOpaque() {
connection.world.entities.lock.acquire()
for (entity in connection.world.entities) {
if (entity.model == null) {
entity.model = entity.createModel(renderWindow)
}
entity.model?.draw()
}
connection.world.entities.lock.release()
}
companion object : RendererBuilder<EntityRenderer> {
override val RESOURCE_LOCATION = ResourceLocation("minosoft:entity")
override fun build(connection: PlayConnection, renderWindow: RenderWindow): EntityRenderer {
return EntityRenderer(connection, renderWindow)
}
}
}

View File

@ -0,0 +1,20 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.gui.rendering.entity.models
import de.bixilon.minosoft.data.entities.entities.Entity
import de.bixilon.minosoft.gui.rendering.RenderWindow
@Deprecated("TODO")
class DummyModel(renderWindow: RenderWindow, entity: Entity) : EntityModel<Entity>(renderWindow, entity)

View File

@ -0,0 +1,27 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.gui.rendering.entity.models
import de.bixilon.minosoft.data.entities.entities.Entity
import de.bixilon.minosoft.gui.rendering.RenderWindow
abstract class EntityModel<E : Entity>(
val renderWindow: RenderWindow,
val entity: E,
) {
open fun draw() {
println("Drawing entity: $entity")
}
}

View File

@ -0,0 +1,29 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.gui.rendering.entity.models
import de.bixilon.minosoft.data.entities.entities.Entity
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.skeletal.baked.BakedSkeletalModel
import de.bixilon.minosoft.gui.rendering.skeletal.instance.SkeletalInstance
abstract class SkeletalEntityModel<E : Entity>(renderWindow: RenderWindow, entity: E) : EntityModel<E>(renderWindow, entity) {
abstract val model: BakedSkeletalModel
abstract val instance: SkeletalInstance
override fun draw() {
instance.draw()
}
}

View File

@ -0,0 +1,38 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.gui.rendering.entity.models.minecraft.player
import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.entity.models.SkeletalEntityModel
import de.bixilon.minosoft.gui.rendering.models.ModelLoader.Companion.bbModel
import de.bixilon.minosoft.gui.rendering.skeletal.baked.BakedSkeletalModel
import de.bixilon.minosoft.gui.rendering.skeletal.instance.SkeletalInstance
import de.bixilon.minosoft.util.KUtil.toResourceLocation
class PlayerModel(renderWindow: RenderWindow, player: PlayerEntity) : SkeletalEntityModel<PlayerEntity>(renderWindow, player) {
override val model: BakedSkeletalModel = renderWindow.modelLoader.entities.loadModel(
"minecraft:entities/player/steve".toResourceLocation(),
"minecraft:entities/player/steve".toResourceLocation().bbModel(),
mutableMapOf(0 to renderWindow.textureManager.steveTexture),
)
init {
model.loadMesh(renderWindow)
}
override val instance: SkeletalInstance = SkeletalInstance(renderWindow, Vec3i(), model)
}

View File

@ -20,6 +20,7 @@ import de.bixilon.minosoft.config.profile.ConnectionProfiles
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.entity.EntityHitboxRenderer
import de.bixilon.minosoft.gui.rendering.entity.EntityRenderer
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
import de.bixilon.minosoft.gui.rendering.sky.SkyRenderer
@ -148,6 +149,7 @@ class RendererManager(
if (!profiles.particle.skipLoading) {
register(ParticleRenderer)
}
register(EntityRenderer)
register(EntityHitboxRenderer)
register(ChunkBorderRenderer)
register(WorldBorderRenderer)

View File

@ -33,6 +33,7 @@ class SkeletalManager(
fun postInit() {
shader.defines["TRANSFORMS"] = TRANSFORMS
shader.loadAnimated()
renderWindow.textureManager.dynamicTextures.use(shader)
shader["uSkeletalBuffer"] = uniformBuffer
shader.setUInt("uLight", 0xFF)
renderWindow.lightMap.use(shader)

View File

@ -16,21 +16,21 @@ package de.bixilon.minosoft.gui.rendering.skeletal
import de.bixilon.kotlinglm.vec2.Vec2
import de.bixilon.kotlinglm.vec3.Vec3
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
import de.bixilon.minosoft.gui.rendering.system.base.texture.ShaderTexture
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
class SkeletalMesh(renderWindow: RenderWindow, initialCacheSize: Int) : Mesh(renderWindow, EntitiesMeshStruct, initialCacheSize = initialCacheSize) {
fun addVertex(position: FloatArray, uv: Vec2, transform: Int, texture: AbstractTexture) {
val transformedUV = texture.renderData.transformUV(uv)
fun addVertex(position: FloatArray, uv: Vec2, transform: Int, texture: ShaderTexture) {
val transformedUV = texture.transformUV(uv)
data.add(position[0])
data.add(position[1])
data.add(position[2])
data.add(transformedUV.x)
data.add(transformedUV.y)
data.add(Float.fromBits(transform))
data.add(Float.fromBits(texture.renderData.shaderTextureId))
data.add(Float.fromBits(texture.shaderId))
}

View File

@ -23,7 +23,7 @@ import de.bixilon.minosoft.gui.rendering.models.unbaked.element.UnbakedElement
import de.bixilon.minosoft.gui.rendering.skeletal.SkeletalMesh
import de.bixilon.minosoft.gui.rendering.skeletal.model.SkeletalModel
import de.bixilon.minosoft.gui.rendering.skeletal.model.outliner.SkeletalOutliner
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
import de.bixilon.minosoft.gui.rendering.system.base.texture.ShaderTexture
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.rotateAssign
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
@ -31,7 +31,7 @@ import java.util.*
class BakedSkeletalModel(
val model: SkeletalModel,
val textures: Int2ObjectOpenHashMap<AbstractTexture>,
val textures: Int2ObjectOpenHashMap<ShaderTexture>,
) {
lateinit var mesh: SkeletalMesh

View File

@ -22,7 +22,7 @@ import de.bixilon.minosoft.gui.rendering.skeletal.model.meta.SkeletalMeta
import de.bixilon.minosoft.gui.rendering.skeletal.model.outliner.SkeletalOutliner
import de.bixilon.minosoft.gui.rendering.skeletal.model.resolution.SkeletalResolution
import de.bixilon.minosoft.gui.rendering.skeletal.model.textures.SkeletalTexture
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
import de.bixilon.minosoft.gui.rendering.system.base.texture.ShaderTexture
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.EMPTY
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
@ -38,8 +38,8 @@ data class SkeletalModel(
val animations: List<SkeletalAnimation> = emptyList(),
) {
fun bake(renderWindow: RenderWindow, textureOverride: MutableMap<Int, AbstractTexture>): BakedSkeletalModel {
val textures: Int2ObjectOpenHashMap<AbstractTexture> = Int2ObjectOpenHashMap()
fun bake(renderWindow: RenderWindow, textureOverride: MutableMap<Int, ShaderTexture>): BakedSkeletalModel {
val textures: Int2ObjectOpenHashMap<ShaderTexture> = Int2ObjectOpenHashMap()
for (entry in this.textures) {
val override = textureOverride[entry.id]
if (override != null) {

View File

@ -0,0 +1,22 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.gui.rendering.system.base.texture
import de.bixilon.kotlinglm.vec2.Vec2
interface ShaderTexture : ShaderIdentifiable {
fun transformUV(end: Vec2?): Vec2
fun transformUV(end: FloatArray?): FloatArray
}

View File

@ -13,11 +13,11 @@
package de.bixilon.minosoft.gui.rendering.system.base.texture.dynamic
import de.bixilon.minosoft.gui.rendering.system.base.texture.ShaderIdentifiable
import de.bixilon.minosoft.gui.rendering.system.base.texture.ShaderTexture
import java.util.*
import java.util.concurrent.atomic.AtomicInteger
interface DynamicTexture : ShaderIdentifiable {
interface DynamicTexture : ShaderTexture {
val uuid: UUID
val usages: AtomicInteger

View File

@ -17,14 +17,14 @@ import de.bixilon.kotlinglm.vec2.Vec2
import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.minosoft.assets.AssetsManager
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.gui.rendering.system.base.texture.ShaderIdentifiable
import de.bixilon.minosoft.gui.rendering.system.base.texture.ShaderTexture
import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureStates
import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureTransparencies
import de.bixilon.minosoft.gui.rendering.system.opengl.texture.OpenGLTextureUtil
import de.bixilon.minosoft.gui.rendering.textures.properties.ImageProperties
import java.nio.ByteBuffer
interface AbstractTexture : ShaderIdentifiable {
interface AbstractTexture : ShaderTexture {
val resourceLocation: ResourceLocation
var textureArrayUV: Vec2
@ -55,4 +55,13 @@ interface AbstractTexture : ShaderIdentifiable {
return OpenGLTextureUtil.generateMipMaps(data, size)
}
override fun transformUV(end: FloatArray?): FloatArray {
return renderData.transformUV(end)
}
override fun transformUV(end: Vec2?): Vec2 {
return renderData.transformUV(end)
}
}

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.gui.rendering.system.opengl.texture.dynamic
import de.bixilon.kotlinglm.vec2.Vec2
import de.bixilon.minosoft.gui.rendering.system.base.texture.dynamic.DynamicTexture
import de.bixilon.minosoft.gui.rendering.system.base.texture.dynamic.DynamicTextureState
import java.nio.ByteBuffer
@ -43,4 +44,13 @@ class OpenGLDynamicTexture(
override fun toString(): String {
return uuid.toString()
}
override fun transformUV(end: Vec2?): Vec2 {
return end ?: Vec2(1.0f)
}
override fun transformUV(end: FloatArray?): FloatArray {
return end ?: floatArrayOf(1.0f, 1.0f)
}
}

View File

@ -18,7 +18,7 @@ import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.skeletal.baked.BakedSkeletalModel
import de.bixilon.minosoft.gui.rendering.skeletal.model.SkeletalModel
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
import de.bixilon.minosoft.gui.rendering.system.base.texture.ShaderTexture
class EntityModels(val renderWindow: RenderWindow) {
private val unbakedModels: MutableMap<ResourceLocation, SkeletalModel> = mutableMapOf()
@ -30,7 +30,7 @@ class EntityModels(val renderWindow: RenderWindow) {
}
@Synchronized
fun loadModel(name: ResourceLocation, path: ResourceLocation, textureOverride: MutableMap<Int, AbstractTexture> = mutableMapOf()): BakedSkeletalModel {
fun loadModel(name: ResourceLocation, path: ResourceLocation, textureOverride: MutableMap<Int, ShaderTexture> = mutableMapOf()): BakedSkeletalModel {
return skeletal.getOrPut(name) { loadUnbakedModel(path).bake(renderWindow, textureOverride) }
}