public STGenericMaterial CreateGenericMaterial(Material material) { STGenericMaterial mat = new STGenericMaterial(); mat.Text = material.Name; foreach (var slot in material.GetAllMaterialTextures()) { textures.Add(CreateGenericTexture(slot.FilePath)); } TextureSlot tex; if (material.GetMaterialTexture(TextureType.Diffuse, 0, out tex)) { mat.TextureMaps.Add(CreateTextureSlot(tex, TextureType.Diffuse)); } if (material.GetMaterialTexture(TextureType.Normals, 1, out tex)) { mat.TextureMaps.Add(CreateTextureSlot(tex, TextureType.Normals)); } if (material.GetMaterialTexture(TextureType.Specular, 1, out tex)) { mat.TextureMaps.Add(CreateTextureSlot(tex, TextureType.Specular)); } return(mat); }
private static void SaveMesh(StringBuilder writer, STGenericObject mesh, STGenericMaterial mat, int VertexCount) { writer.AppendLine($"o {mesh.Text}"); writer.AppendLine($"g {mesh.Text}"); foreach (var v in mesh.vertices) { writer.AppendLine($"v {v.pos.X} {v.pos.Y} {v.pos.Z}"); writer.AppendLine($"vn {v.nrm.X} {v.nrm.Y} {v.nrm.Z}"); writer.AppendLine($"vt {v.uv0.X} {v.uv0.Y}"); } if (mat != null) { writer.AppendLine($"usemtl {mat.Text}"); } for (int i = 0; i < mesh.faces.Count; i++) { int[] indices = new int[3] { mesh.faces[i++], mesh.faces[i++], mesh.faces[i] }; writer.AppendLine($"f {indices[0] + VertexCount}/{indices[0] + VertexCount}/{indices[0] + VertexCount}" + $" {indices[1] + VertexCount}/{indices[1] + VertexCount}/{indices[1] + VertexCount}" + $" {indices[2] + VertexCount}/{indices[2] + VertexCount}/{indices[2] + VertexCount}"); } VertexCount += mesh.vertices.Count; }
public STGenericMaterial CreateGenericMaterial(Material material) { STGenericMaterial mat = new STGenericMaterial(); mat.Text = material.Name; TextureSlot tex; if (material.GetMaterialTexture(TextureType.Diffuse, 0, out tex)) mat.TextureMaps.Add(CreateTextureSlot(tex, TextureType.Diffuse)); if (material.GetMaterialTexture(TextureType.Normals, 1, out tex)) mat.TextureMaps.Add(CreateTextureSlot(tex, TextureType.Normals)); if (material.GetMaterialTexture(TextureType.Specular, 1, out tex)) mat.TextureMaps.Add(CreateTextureSlot(tex, TextureType.Specular)); return mat; }