private Material LoadMaterial(Assimp.Material mat) { var material = new Material(); if (mat.HasTextureAmbient) { var texture = LoadTexture(mat.TextureAmbient.FilePath); if (texture != null) { material.AmbientTexture = texture; } } else if (mat.HasColorAmbient) { material.AmbientColor = new Vector4(mat.ColorAmbient.R, mat.ColorAmbient.G, mat.ColorAmbient.B, mat.ColorAmbient.A); } if (mat.HasTextureDiffuse) { var texture = LoadTexture(mat.TextureDiffuse.FilePath); if (texture != null) { material.DiffuseTexture = texture; } } else if (mat.HasColorDiffuse) { material.DiffuseColor = new Vector4(mat.ColorDiffuse.R, mat.ColorDiffuse.G, mat.ColorDiffuse.B, mat.ColorDiffuse.A); } if (mat.HasTextureSpecular) { var texture = LoadTexture(mat.TextureSpecular.FilePath); if (texture != null) { material.SpecularTexture = texture; } } if (mat.HasColorSpecular) { material.SpecularColor = new Vector4(mat.ColorSpecular.R, mat.ColorSpecular.G, mat.ColorSpecular.B, mat.ColorSpecular.A); } return(material); }
private Mesh LoadMesh(Assimp.Mesh mesh, Assimp.Scene scene) { var vertices = new List <Vertex>(); var indices = new List <uint>(); for (var i = 0; i < mesh.Vertices.Count; i++) { var vert = new Vertex { Position = new Vector3(mesh.Vertices[i].X, mesh.Vertices[i].Y, mesh.Vertices[i].Z), Normal = new Vector3(mesh.Normals[i].X, mesh.Normals[i].Y, mesh.Normals[i].Z) }; if (mesh.HasTextureCoords(0)) { var texCoords = new Vector2(mesh.TextureCoordinateChannels[0][i].X, mesh.TextureCoordinateChannels[0][i].Y); vert.TexCoords = texCoords; } else { vert.TexCoords = new Vector2(0.0f); } vertices.Add(vert); } foreach (var face in mesh.Faces) { foreach (var i in face.Indices) { indices.Add((uint)i); } } Material material = null; if (mesh.MaterialIndex >= 0) { material = LoadMaterial(scene.Materials[mesh.MaterialIndex]); } _logger.Info("Loaded mesh: " + mesh.Name); return(new Mesh(vertices, indices, material)); }