From a6d62770709aa35f2d415546f476a338c472bda0 Mon Sep 17 00:00:00 2001 From: a dinosaur Date: Sat, 19 Aug 2023 05:46:29 +1000 Subject: [PATCH] party refactors in the house tonight --- src/main/kotlin/Colin.kt | 5 +- src/main/kotlin/Game.kt | 117 ++++++++++++++------------------ src/main/kotlin/Resources.kt | 12 ++++ src/main/kotlin/Util.kt | 8 +++ src/main/resources/suzanne.g3db | Bin 293213 -> 293213 bytes 5 files changed, 72 insertions(+), 70 deletions(-) diff --git a/src/main/kotlin/Colin.kt b/src/main/kotlin/Colin.kt index 3d7d0b9..2a0d3bd 100644 --- a/src/main/kotlin/Colin.kt +++ b/src/main/kotlin/Colin.kt @@ -40,10 +40,7 @@ class Colin private fun updateCamera() { cam.position.set(Vector3(pos.x, 1.0f, pos.y)) - val forward = Vector3(0.0f, 0.0f, -1.0f) - val up = Vector3(0.0f, 1.0f, 0.0f) - val right = Vector3(1.0f, 0.0f, 0.0f) - cam.direction.set(forward.rotateRad(right, offsAngle.y).rotateRad(up, offsAngle.x + angle)) + cam.direction.set(Util.forward.rotateRad(Util.right, offsAngle.y).rotateRad(Util.up, offsAngle.x + angle)) cam.update() } diff --git a/src/main/kotlin/Game.kt b/src/main/kotlin/Game.kt index 1215812..9265021 100644 --- a/src/main/kotlin/Game.kt +++ b/src/main/kotlin/Game.kt @@ -13,7 +13,7 @@ import com.badlogic.gdx.graphics.g3d.model.data.* import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder import com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor -import com.badlogic.gdx.graphics.g3d.utils.TextureProvider +import com.badlogic.gdx.graphics.g3d.utils.TextureProvider.AssetTextureProvider import com.badlogic.gdx.math.* import com.badlogic.gdx.utils.Array import com.badlogic.gdx.utils.ScreenUtils @@ -58,76 +58,61 @@ class Game: ApplicationAdapter() private fun makeFloor(): Model { - val model = ModelData() - - val mesh = ModelMesh() - mesh.id = "floormodel" - mesh.attributes = arrayOf( - VertexAttribute.Position(), - VertexAttribute.Normal(), - VertexAttribute.Tangent(), - VertexAttribute.Binormal(), - VertexAttribute.TexCoords(0)) - val normal = Vector3(0.0f, 1.0f, 0.0f) - val tangent = Vector3(1.0f, 0.0f, 0.0f) - val bitangent = Vector3(0.0f, 0.0f, -1.0f) - val vertex = { pos: Vector3, tex: Vector2, norm: Vector3, tan: Vector3, bitan: Vector3 -> floatArrayOf( - pos.x, pos.y, pos.z, - norm.x, norm.y, norm.z, - tan.x, tan.y, tan.z, - bitan.x, bitan.y, bitan.z, - tex.x, tex.y - )} val size = 16.0f val texs = 4.0f - mesh.vertices = - vertex(Vector3(0.0f, 0.0f, 0.0f), Vector2(0.0f, texs), normal, tangent, bitangent) + - vertex(Vector3(size, 0.0f, 0.0f), Vector2(texs, texs), normal, tangent, bitangent) + - vertex(Vector3(0.0f, 0.0f, -size), Vector2(0.0f, 0.0f), normal, tangent, bitangent) + - vertex(Vector3(size, 0.0f, -size), Vector2(texs, 0.0f), normal, tangent, bitangent) - val part = ModelMeshPart() - part.id = "floormesh" - part.primitiveType = GL20.GL_TRIANGLES - part.indices = shortArrayOf( - 0, 1, 2, - 3, 2, 1) - mesh.parts = arrayOf(part) - model.addMesh(mesh) - val material = ModelMaterial() - material.id = "floormat" - material.diffuse = XnaColor.White - material.specular = XnaColor.BlanchedAlmond.mix(XnaColor.Black, 0.12f) - material.shininess = 65.0f - val diffuse = ModelTexture() - diffuse.usage = ModelTexture.USAGE_DIFFUSE - diffuse.fileName = "cobblestone.png" - val normalMap = ModelTexture() - normalMap.usage = ModelTexture.USAGE_NORMAL - normalMap.fileName = "cobblestone_normal.png" - val specular = ModelTexture() - specular.usage = ModelTexture.USAGE_SPECULAR - specular.fileName = "cobblestone_specular.png" - material.textures = Array() - material.textures.add(diffuse, normalMap, specular) - model.materials.add(material) + val vertex = { pos: Vector3, tex: Vector2 -> + val normal = Util.up + val tangent = Util.right + val bitangent = Util.forward + floatArrayOf( + pos.x, pos.y, pos.z, + normal.x, normal.y, normal.z, tangent.x, tangent.y, tangent.z, bitangent.x, bitangent.y, bitangent.z, + tex.x, tex.y) + } - val node = ModelNode() - node.id = "floornode" - node.scale = Vector3(1.0f, 1.0f, 1.0f) - node.rotation = Quaternion() - val nodePart = ModelNodePart() - nodePart.meshPartId = "floormesh" - nodePart.materialId = "floormat" - node.parts = arrayOf(nodePart) - model.nodes.add(node) + val modelTexture = { modelTextureUsage: Int, textureFilename: String -> ModelTexture().apply { + usage = modelTextureUsage + fileName = textureFilename + }} - return Model(model, TextureProvider.FileTextureProvider( - Texture.TextureFilter.Nearest, - Texture.TextureFilter.Nearest, - Texture.TextureWrap.Repeat, - Texture.TextureWrap.Repeat, - false)) + return Model(ModelData().apply { + addMesh(ModelMesh().apply { + id = "floormodel" + attributes = arrayOf(VertexAttribute.Position(), VertexAttribute.Normal(), VertexAttribute.Tangent(), VertexAttribute.Binormal(), VertexAttribute.TexCoords(0)) + vertices = + vertex(Vector3(0.0f, 0.0f, 0.0f), Vector2(0.0f, texs)) + + vertex(Vector3(size, 0.0f, 0.0f), Vector2(texs, texs)) + + vertex(Vector3(0.0f, 0.0f, -size), Vector2(0.0f, 0.0f)) + + vertex(Vector3(size, 0.0f, -size), Vector2(texs, 0.0f)) + parts = arrayOf(ModelMeshPart().apply { + id = "floormesh" + primitiveType = GL20.GL_TRIANGLES + indices = shortArrayOf( + 0, 1, 2, + 3, 2, 1) + }) + }) + materials.add(ModelMaterial().apply { + id = "floormat" + diffuse = XnaColor.White + specular = XnaColor.BlanchedAlmond.mix(XnaColor.Black, 0.12f) + shininess = 65.0f + textures = Array() + textures.add( + modelTexture(ModelTexture.USAGE_DIFFUSE, "cobblestone.png"), + modelTexture(ModelTexture.USAGE_NORMAL, "cobblestone_normal.png"), + modelTexture(ModelTexture.USAGE_SPECULAR, "cobblestone_specular.png")) + }) + nodes.add(ModelNode().apply { + id = "floornode" + scale = Util.one + parts = arrayOf(ModelNodePart().apply { + meshPartId = "floormesh" + materialId = "floormat" + }) + }) + }, AssetTextureProvider(assetManager)) } override fun create() diff --git a/src/main/kotlin/Resources.kt b/src/main/kotlin/Resources.kt index 236063d..d2b82ac 100644 --- a/src/main/kotlin/Resources.kt +++ b/src/main/kotlin/Resources.kt @@ -1,6 +1,7 @@ package gay.pizza.CavesOfJolk import com.badlogic.gdx.assets.AssetManager +import com.badlogic.gdx.assets.loaders.TextureLoader import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver import com.badlogic.gdx.audio.Sound import com.badlogic.gdx.graphics.Texture @@ -30,6 +31,14 @@ class Resources private constructor() assetManager.setLoader(BitmapFont::class.java, ".ttf", FreetypeFontLoader(resolver)) } + val linearMipped = TextureLoader.TextureParameter().apply { + minFilter = Texture.TextureFilter.MipMapLinearLinear + magFilter = Texture.TextureFilter.Linear + wrapU = Texture.TextureWrap.Repeat + wrapV = Texture.TextureWrap.Repeat + genMipMaps = true + } + fun loadAssets() { assetManager.load("colin.png", Texture::class.java) @@ -37,6 +46,9 @@ class Resources private constructor() assetManager.loadFont("Comic Sans MS.ttf", 20) assetManager.load("suzanne.g3db", Model::class.java) assetManager.load("nut.wav", Sound::class.java) + assetManager.load("cobblestone.png", Texture::class.java, linearMipped) + assetManager.load("cobblestone_normal.png", Texture::class.java, linearMipped) + assetManager.load("cobblestone_specular.png", Texture::class.java, linearMipped) } } diff --git a/src/main/kotlin/Util.kt b/src/main/kotlin/Util.kt index 8cc9c43..2f4588f 100644 --- a/src/main/kotlin/Util.kt +++ b/src/main/kotlin/Util.kt @@ -5,8 +5,10 @@ import com.badlogic.gdx.graphics.g3d.Attribute import com.badlogic.gdx.graphics.g3d.Attributes import com.badlogic.gdx.math.MathUtils import com.badlogic.gdx.math.Vector2 +import com.badlogic.gdx.math.Vector3 import ktx.math.div import ktx.math.times +import ktx.math.unaryMinus import org.hsluv.HUSLColorConverter import kotlin.math.pow @@ -43,6 +45,12 @@ class Util ((abgr8888 and 0xFF00u) shr 8).toFloat() / 255.0f, ((abgr8888 and 0xFF0000u) shr 16).toFloat() / 255.0f, ((abgr8888 and 0xFF000000u) shr 24).toFloat() / 255.0f) + + val zero get() = Vector3.Zero + val one get() = Vector3(1.0f, 1.0f, 1.0f) + val forward get() = -Vector3.Z + val right get() = Vector3.X + val up get() = Vector3.Y } } diff --git a/src/main/resources/suzanne.g3db b/src/main/resources/suzanne.g3db index a29221d54d0da3b327bfb960a6a710e01ca1d701..1e39e51130dfd770bfe2b92125d1394d58444037 100644 GIT binary patch delta 1724 zcmZ9Mdr%Ws6vo*E5d=ZSprlF=7$I0d5EwAYZbd{zK#ILE;}?Dq@&BoAjUU-22xvJ4APM>Lub$nvLvvL zZEoNa=V`&V8omWv-n>DVX7E;y0hyO=1iN~s6l~aecX0Xs-e7%YJs@Sz-$A&S-VH9N z+0}T$z=tVzLM&Xn0&0WyG`Paj^U!1#AI9BVoDzS?q_86Z1O&xMef zUx1Shu46&eI;}DMa-Ngdafmjyf%Jd7IS>x=O)!1e=>XH6ruh*2J^d4$)*)MW<=0w9 zrCW9XXL&fdl_eLzdN>||#@k~JG>&Ey$b-NjUCwXE<-v4&>k^Pr@rxk%4Wdfg2A`ta z2}a$d2Oi2mh-v*YK@Ox20k=GO3rNa|i4ZoG?tv+=X&1=ht0~~J4EuDY4{8-o5VIOX z=$T;UnLFwoYumKg^;DG2*WSN9u`Z6}XI zI1pS7^$#z`gG4Ph>UWN2Qkk8+tv6F4Q&?P^e_8XGAhZ%>O#+ z`v_!aQ4)lf{k>3szuN%P5c3e+l1G(#mnbInKgy)TASBnQ3N}#Z;&MF<^W17EsD=w?WK2$wK(!t_kclTYHdo@g{I{ zYYy-Urx}h>&>^i3xd(1x><6&hx2J&J_mT&>s1KsKnt$Z$&oE1*OcL+j!Zb=0|4w|* z>1z-Z-08U1NIj`sEmjZ*MBnCn&oPu6OB)$Mj|T3gkz>LKQ5!ksPHjZu1NK9JBR}*f zrk#^b2b*3v65>*Os^^sa;SeXzSMWAYk`NokSg<-*Gs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