private GameMesh processMesh(Mesh mesh, Scene s) { List<GameVertex> vertices = new List<GameVertex>(); List<uint> indices = new List<uint>(); List<GameTexture> textures = new List<GameTexture>(); this.Log("Converting Imported Mesh File Structure to Game Engine Structure", DebugChannel.Log, 6); this.Log("Copying Vertex Data...", DebugChannel.Log, 5); for (int i = 0; i < mesh.VertexCount; i++) { Vector3D vert = mesh.Vertices[i]; Vector3D norm = mesh.Normals[i]; Vector3D tan = mesh.HasTangentBasis ? mesh.Tangents[i] : new Vector3D(0); Vector3D bit = mesh.HasTangentBasis ? mesh.BiTangents[i] : new Vector3D(0); Vector3D uv = mesh.HasTextureCoords(0) ? mesh.TextureCoordinateChannels[0][i] : new Vector3D(0); GameVertex v = new GameVertex() { Position = new Vector3(vert.X, vert.Y, vert.Z), Normal = new Vector3(norm.X, norm.Y, norm.Z), UV = new Vector2(uv.X, uv.Y), Bitangent = new Vector3(bit.X, bit.Y, bit.Z), Tangent = new Vector3(tan.X, tan.Y, tan.Z) }; vertices.Add(v); } this.Log("Calculating Indices...", DebugChannel.Log, 5); for (int i = 0; i < mesh.FaceCount; i++) { Face f = mesh.Faces[i]; indices.AddRange(f.Indices.Select(x => (uint)x)); } Material m = s.Materials[mesh.MaterialIndex]; this.Log("Loading Baked Material: " + m.Name, DebugChannel.Log, 5); textures.AddRange(loadMaterialTextures(m, TextureType.Diffuse, "texture_diffuse")); textures.AddRange(loadMaterialTextures(m, TextureType.Specular, "texture_specular")); textures.AddRange(loadMaterialTextures(m, TextureType.Normals, "texture_normal")); textures.AddRange(loadMaterialTextures(m, TextureType.Height, "texture_height")); return new GameMesh(vertices, indices, textures); }
public static GameMesh CreateCube() { List <GameVertex> ret = new List <GameVertex>() { new GameVertex() { Position = new Vector3(-1.0f, -1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(-1.0f, -1.0f, 1.0f) }, new GameVertex() { Position = new Vector3(-1.0f, 1.0f, 1.0f) }, new GameVertex() { Position = new Vector3(1.0f, 1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(-1.0f, -1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(-1.0f, 1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(1.0f, -1.0f, 1.0f) }, new GameVertex() { Position = new Vector3(-1.0f, -1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(1.0f, -1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(1.0f, 1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(1.0f, -1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(-1.0f, -1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(-1.0f, -1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(-1.0f, 1.0f, 1.0f) }, new GameVertex() { Position = new Vector3(-1.0f, 1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(1.0f, -1.0f, 1.0f) }, new GameVertex() { Position = new Vector3(-1.0f, -1.0f, 1.0f) }, new GameVertex() { Position = new Vector3(-1.0f, -1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(-1.0f, 1.0f, 1.0f) }, new GameVertex() { Position = new Vector3(-1.0f, -1.0f, 1.0f) }, new GameVertex() { Position = new Vector3(1.0f, -1.0f, 1.0f) }, new GameVertex() { Position = new Vector3(1.0f, 1.0f, 1.0f) }, new GameVertex() { Position = new Vector3(1.0f, -1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(1.0f, 1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(1.0f, -1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(1.0f, 1.0f, 1.0f) }, new GameVertex() { Position = new Vector3(1.0f, -1.0f, 1.0f) }, new GameVertex() { Position = new Vector3(1.0f, 1.0f, 1.0f) }, new GameVertex() { Position = new Vector3(1.0f, 1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(-1.0f, 1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(1.0f, 1.0f, 1.0f) }, new GameVertex() { Position = new Vector3(-1.0f, 1.0f, -1.0f) }, new GameVertex() { Position = new Vector3(-1.0f, 1.0f, 1.0f) }, new GameVertex() { Position = new Vector3(1.0f, 1.0f, 1.0f) }, new GameVertex() { Position = new Vector3(-1.0f, 1.0f, 1.0f) }, new GameVertex() { Position = new Vector3(1.0f, -1.0f, 1.0f) } }; List <uint> ind = new List <uint>(); for (int i = 0; i < ret.Count; i++) { GameVertex v = ret[i]; v.Position += Vector3.UnitZ * -1; ret[i] = v; ind.Add((uint)i); } GameMesh gm = new GameMesh(ret, ind, new List <GameTexture>()); ret.Log($"Creating Cube Mesh", DebugChannel.Log, 8); return(gm); }