mapping but it's normal

This commit is contained in:
2023-08-18 02:51:54 +10:00
parent 14223ddc35
commit a5e0d37e74
5 changed files with 113 additions and 25 deletions

View File

@ -11,10 +11,13 @@ import com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute
import com.badlogic.gdx.graphics.g3d.attributes.IntAttribute
import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight
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.math.*
import com.badlogic.gdx.utils.Array
import com.badlogic.gdx.utils.ScreenUtils
import gay.pizza.CavesOfJolk.Resources.Companion.assetManager
@ -54,23 +57,75 @@ class Game: ApplicationAdapter()
return modelBuilder.createBox(size, size, size, material, attribs.toLong())
}
private fun makeFloor(texture: Texture): Model
private fun makeFloor(): Model
{
val modelBuilder = ModelBuilder()
val material = Material(
ColorAttribute.createDiffuse(XnaColor.BlanchedAlmond.lighten(0.01)),
ColorAttribute.createSpecular(XnaColor.BlanchedAlmond.mix(XnaColor.Black, 0.4f)),
FloatAttribute.createShininess(65.0f),
TextureAttribute.createDiffuse(texture))
val attribs = VertexAttributes.Usage.Position or VertexAttributes.Usage.TextureCoordinates or VertexAttributes.Usage.Normal
val size = 10.0f
return modelBuilder.createRect(
0.0f, 0.0f, 0.0f,
size, 0.0f, 0.0f,
size, 0.0f, -size,
0.0f, 0.0f, -size,
0.0f, 1.0f, 0.0f,
material, attribs.toLong())
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.4f)
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"
material.textures = Array()
material.textures.add(diffuse, normalMap)
model.materials.add(material)
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)
return Model(model, TextureProvider.FileTextureProvider(
Texture.TextureFilter.Nearest,
Texture.TextureFilter.Nearest,
Texture.TextureWrap.Repeat,
Texture.TextureWrap.Repeat,
false))
}
override fun create()
@ -87,7 +142,7 @@ class Game: ApplicationAdapter()
i.set(FloatAttribute.createShininess(30.0f))
cube = makeCube(texJolk)
floor = makeFloor(assetManager.get("cobblestone.png"))
floor = makeFloor()
spriteBatch = SpriteBatch()
@ -107,7 +162,9 @@ class Game: ApplicationAdapter()
CustomIntAttribute.createFogType(CustomIntAttribute.FogTypes.Exp2),
CustomFloatAttribute.createFogDensity(0.1f))
*/
env.add(DirectionalLight().set(XnaColor.White, Vector3(1.0f, -1.0f, -1.0f).nor()))
env.add(DirectionalLight().set(
XnaColor.BlanchedAlmond.lighten(0.01),
Vector3(1.0f, -1.0f, -1.0f).nor()))
val shaderConfig = DefaultShader.Config()
shaderConfig.numDirectionalLights = 1