party refactors in the house tonight

This commit is contained in:
2023-08-19 05:46:29 +10:00
parent 81064b497f
commit a6d6277070
5 changed files with 72 additions and 70 deletions

View File

@ -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()