public void GenerateTextSmoothAngle() { var mesh = new An8Mesh(); mesh.SmoothAngleThreshold = 2.0f; var text = mesh.GenerateText(); string expected = @"mesh { name { """" } smoothangle { 2.000000 } materiallist { } points { } normals { } edges { } texcoords { } faces { } } "; Assert.Equal( expected.Replace("\r\n", "\n"), text.Replace("\r\n", "\n")); }
public void ParseNormalsAndTexCoords() { var mesh = new An8Mesh(); mesh.Parse( @" faces { 3 7 4 5 ( ( 10 11 12 ) ( 13 14 15 ) ( 16 17 18 ) ) } "); var face = mesh.Faces[0]; Assert.True(face.IsBackShown); Assert.True(face.HasNormalIndexes); Assert.True(face.HasTexCoordIndexes); Assert.Equal(3, face.PointIndexes.Length); Assert.Equal(3, face.NormalIndexes.Length); Assert.Equal(3, face.TexCoordIndexes.Length); Assert.Equal(4, face.MaterialIndex); Assert.Equal(5, face.FlatNormalIndex); Assert.Equal(10, face.PointIndexes[0]); Assert.Equal(11, face.NormalIndexes[0]); Assert.Equal(12, face.TexCoordIndexes[0]); Assert.Equal(13, face.PointIndexes[1]); Assert.Equal(14, face.NormalIndexes[1]); Assert.Equal(15, face.TexCoordIndexes[1]); Assert.Equal(16, face.PointIndexes[2]); Assert.Equal(17, face.NormalIndexes[2]); Assert.Equal(18, face.TexCoordIndexes[2]); }
public void GenerateTextMaterialList() { var mesh = new An8Mesh(); mesh.MaterialList.Add("abc"); var text = mesh.GenerateText(); string expected = @"mesh { name { """" } smoothangle { 0.000000 } materiallist { materialname { ""abc"" } } points { } normals { } edges { } texcoords { } faces { } } "; Assert.Equal( expected.Replace("\r\n", "\n"), text.Replace("\r\n", "\n")); }
public void ParsePoints() { var mesh = new An8Mesh(); mesh.Parse( @" faces { 3 0 4 5 ( ( 10 ) ( 13 ) ( 16 ) ) } "); var face = mesh.Faces[0]; Assert.False(face.IsBackShown); Assert.False(face.HasNormalIndexes); Assert.False(face.HasTexCoordIndexes); Assert.Equal(3, face.PointIndexes.Length); Assert.Null(face.NormalIndexes); Assert.Null(face.TexCoordIndexes); Assert.Equal(4, face.MaterialIndex); Assert.Equal(5, face.FlatNormalIndex); Assert.Equal(10, face.PointIndexes[0]); Assert.Equal(13, face.PointIndexes[1]); Assert.Equal(16, face.PointIndexes[2]); }
public void GenerateTextTexCoords() { var mesh = new An8Mesh(); mesh.TexCoords.Add(new An8TexCoord { U = 2.0f, V = 3.0f }); var text = mesh.GenerateText(); string expected = @"mesh { name { """" } smoothangle { 0.000000 } materiallist { } points { } normals { } edges { } texcoords { ( 2.000000 3.000000 ) } faces { } } "; Assert.Equal( expected.Replace("\r\n", "\n"), text.Replace("\r\n", "\n")); }
public void GenerateTextFaces() { var mesh = new An8Mesh(); mesh.Faces.Add(new An8Face()); var text = mesh.GenerateText(); string expected = @"mesh { name { """" } smoothangle { 0.000000 } materiallist { } points { } normals { } edges { } texcoords { } faces { 0 0 0 0 ( ) } } "; Assert.Equal( expected.Replace("\r\n", "\n"), text.Replace("\r\n", "\n")); }
public void ParseEmpty() { var mesh = new An8Mesh(); mesh.Parse( @" "); }
public void ParseOther() { var mesh = new An8Mesh(); mesh.Parse( @" other { } "); }
public void ParseMaterial() { var mesh = new An8Mesh(); mesh.Parse( @" material { } "); Assert.NotNull(mesh.Material); }
public void ParseSmoothAngle() { var mesh = new An8Mesh(); mesh.Parse( @" smoothangle { 2.0 } "); Assert.Equal(2.0f, mesh.SmoothAngleThreshold); }
public void ParseEmpty() { var mesh = new An8Mesh(); mesh.Parse( @" faces { 0 0 0 0 ( ) } "); var face = mesh.Faces[0]; }
public void NewMesh() { var mesh = new An8Mesh(); Assert.Null(mesh.Material); Assert.Equal(0.0f, mesh.SmoothAngleThreshold); Assert.NotNull(mesh.MaterialList); Assert.NotNull(mesh.Points); Assert.NotNull(mesh.Normals); Assert.NotNull(mesh.Edges); Assert.NotNull(mesh.TexCoords); Assert.NotNull(mesh.Faces); }
public void ParseFaces() { var mesh = new An8Mesh(); mesh.Parse( @" faces { 0 0 0 0 ( ) } "); Assert.Equal(1, mesh.Faces.Count); }
public void ParseMaterialListClear() { var mesh = new An8Mesh(); mesh.MaterialList.Add(null); mesh.Parse( @" materiallist { } "); Assert.Equal(0, mesh.MaterialList.Count); }
public void ParseMaterialList() { var mesh = new An8Mesh(); mesh.Parse( @" materiallist { materialname { ""abc"" } } "); Assert.Equal(1, mesh.MaterialList.Count); Assert.Equal("abc", mesh.MaterialList[0]); }
public void ParsePointsClear() { var mesh = new An8Mesh(); mesh.Points.Add(new An8Point()); mesh.Parse( @" points { } "); Assert.Equal(0, mesh.Points.Count); }
public void ParseNormalsClear() { var mesh = new An8Mesh(); mesh.Normals.Add(new An8Point()); mesh.Parse( @" normals { } "); Assert.Equal(0, mesh.Normals.Count); }
public void ParseFacesClear() { var mesh = new An8Mesh(); mesh.Faces.Add(new An8Face()); mesh.Parse( @" faces { } "); Assert.Equal(0, mesh.Faces.Count); }
public void ParseTexCoordsClear() { var mesh = new An8Mesh(); mesh.TexCoords.Add(new An8TexCoord()); mesh.Parse( @" texcoords { } "); Assert.Equal(0, mesh.TexCoords.Count); }
public void ParseEdgesClear() { var mesh = new An8Mesh(); mesh.Edges.Add(new An8Edge()); mesh.Parse( @" edges { } "); Assert.Equal(0, mesh.Edges.Count); }
public void ParseTexCoords() { var mesh = new An8Mesh(); mesh.Parse( @" texcoords { ( 2.0 3.0 ) } "); Assert.Equal(1, mesh.TexCoords.Count); Assert.Equal(2.0f, mesh.TexCoords[0].U); Assert.Equal(3.0f, mesh.TexCoords[0].V); }
public void ParsePoints() { var mesh = new An8Mesh(); mesh.Parse( @" points { ( 2.0 3.0 4.0 ) } "); Assert.Equal(1, mesh.Points.Count); Assert.Equal(2.0f, mesh.Points[0].X); Assert.Equal(3.0f, mesh.Points[0].Y); Assert.Equal(4.0f, mesh.Points[0].Z); }
public void ParseNormals() { var mesh = new An8Mesh(); mesh.Parse( @" normals { ( 2.0 3.0 4.0 ) } "); Assert.Equal(1, mesh.Normals.Count); Assert.Equal(2.0f, mesh.Normals[0].X); Assert.Equal(3.0f, mesh.Normals[0].Y); Assert.Equal(4.0f, mesh.Normals[0].Z); }
public void GenerateTextNormalsAndTexCoords() { var face = new An8Face(); face.IsBackShown = true; face.MaterialIndex = 4; face.FlatNormalIndex = 5; face.PointIndexes = new int[] { 10, 13, 16 }; face.NormalIndexes = new int[] { 11, 14, 17 }; face.TexCoordIndexes = new int[] { 12, 15, 18 }; var mesh = new An8Mesh(); mesh.Faces.Add(face); var text = mesh.GenerateText(); string expected = @"mesh { name { """" } smoothangle { 0.000000 } materiallist { } points { } normals { } edges { } texcoords { } faces { 3 7 4 5 ( ( 10 11 12 ) ( 13 14 15 ) ( 16 17 18 ) ) } } "; Assert.Equal( expected.Replace("\r\n", "\n"), text.Replace("\r\n", "\n")); }
public void ParseEdges() { var mesh = new An8Mesh(); mesh.Parse( @" edges { ( 2 3 ) ( 4 5 6 ) } "); Assert.Equal(2, mesh.Edges.Count); Assert.Equal(2, mesh.Edges[0].Index1); Assert.Equal(3, mesh.Edges[0].Index2); Assert.False(mesh.Edges[0].Sharpness.HasValue); Assert.Equal(4, mesh.Edges[1].Index1); Assert.Equal(5, mesh.Edges[1].Index2); Assert.True(mesh.Edges[1].Sharpness.HasValue); Assert.Equal(6, mesh.Edges[1].Sharpness.Value); }
public void GenerateTextPoints() { var face = new An8Face(); face.MaterialIndex = 4; face.FlatNormalIndex = 5; face.PointIndexes = new int[] { 10, 13, 16 }; var mesh = new An8Mesh(); mesh.Faces.Add(face); var text = mesh.GenerateText(); string expected = @"mesh { name { """" } smoothangle { 0.000000 } materiallist { } points { } normals { } edges { } texcoords { } faces { 3 0 4 5 ( ( 10 ) ( 13 ) ( 16 ) ) } } "; Assert.Equal( expected.Replace("\r\n", "\n"), text.Replace("\r\n", "\n")); }
public void GenerateTextEdges() { var mesh = new An8Mesh(); mesh.Edges.Add(new An8Edge { Index1 = 2, Index2 = 3 }); mesh.Edges.Add(new An8Edge { Index1 = 4, Index2 = 5, Sharpness = 6 }); var text = mesh.GenerateText(); string expected = @"mesh { name { """" } smoothangle { 0.000000 } materiallist { } points { } normals { } edges { ( 2 3 ) ( 4 5 6 ) } texcoords { } faces { } } "; Assert.Equal( expected.Replace("\r\n", "\n"), text.Replace("\r\n", "\n")); }
public static void OptToAn8(OptFile opt, string an8Path, bool scale) { if (opt == null) { throw new ArgumentNullException("opt"); } string an8Directory = Path.GetDirectoryName(an8Path); string an8Name = Path.GetFileNameWithoutExtension(an8Path); foreach (var texture in opt.Textures.Values) { texture.Save(Path.Combine(an8Directory, string.Concat(texture.Name, ".png"))); } var distances = opt.Meshes .SelectMany(t => t.Lods) .Select(t => t.Distance) .Distinct() .OrderByDescending(t => t) .ToArray(); for (int distance = 0; distance < distances.Length; distance++) { var an8 = new An8File(); foreach (var texture in opt.Textures.Values) { var an8Texture = new An8Texture(); an8Texture.Name = texture.Name; an8Texture.Files.Add(string.Concat(texture.Name, ".png")); an8.Textures.Add(an8Texture); var an8Material = new An8Material(); an8Material.Name = texture.Name; an8Material.FrontSurface = new An8Surface(); an8Material.FrontSurface.Diffuse = new An8MaterialColor { TextureName = texture.Name, TextureParams = new An8TextureParams { AlphaMode = texture.HasAlpha ? An8AlphaMode.Final : An8AlphaMode.None, BlendMode = An8BlendMode.Darken } }; an8.Materials.Add(an8Material); } var an8Object = new An8Object(); an8Object.Name = Path.GetFileNameWithoutExtension(opt.FileName); an8.Objects.Add(an8Object); int objectsIndex = 0; foreach (var mesh in opt.Meshes) { var lod = mesh.Lods.FirstOrDefault(t => t.Distance <= distances[distance]); if (lod == null) { continue; } var an8Mesh = new An8Mesh(); an8Mesh.Name = string.Format(CultureInfo.InvariantCulture, "{0}.{1:D3}", mesh.Descriptor.MeshType, objectsIndex); an8Object.Components.Add(an8Mesh); objectsIndex++; foreach (var texture in mesh.Lods .SelectMany(t => t.FaceGroups) .SelectMany(t => t.Textures) .Distinct()) { an8Mesh.MaterialList.Add(texture); } if (scale) { foreach (var v in mesh.Vertices) { an8Mesh.Points.Add(new An8Point { X = v.X * OptFile.ScaleFactor, Y = v.Z * OptFile.ScaleFactor, Z = v.Y * OptFile.ScaleFactor }); } } else { foreach (var v in mesh.Vertices) { an8Mesh.Points.Add(new An8Point { X = v.X, Y = v.Z, Z = v.Y }); } } foreach (var v in mesh.TextureCoordinates) { an8Mesh.TexCoords.Add(new An8TexCoord { U = v.U, V = -v.V }); } foreach (var v in mesh.VertexNormals) { an8Mesh.Normals.Add(new An8Point { X = v.X, Y = v.Z, Z = v.Y }); } int verticesIndex = 0; int verticesTexIndex = 0; int verticesNormalIndex = 0; foreach (var faceGroup in lod.FaceGroups) { int materialIndex = 0; if (faceGroup.Textures.Count > 0) { materialIndex = an8Mesh.MaterialList.IndexOf(faceGroup.Textures[0]); } foreach (var face in faceGroup.Faces) { if (face.VerticesIndex.D < 0) { var an8Face = new An8Face { MaterialIndex = materialIndex, FlatNormalIndex = -1 }; an8Face.PointIndexes = new int[] { verticesIndex + face.VerticesIndex.A, verticesIndex + face.VerticesIndex.B, verticesIndex + face.VerticesIndex.C }; an8Face.TexCoordIndexes = new int[] { verticesTexIndex + face.TextureCoordinatesIndex.A, verticesTexIndex + face.TextureCoordinatesIndex.B, verticesTexIndex + face.TextureCoordinatesIndex.C }; an8Face.NormalIndexes = new int[] { verticesNormalIndex + face.VertexNormalsIndex.A, verticesNormalIndex + face.VertexNormalsIndex.B, verticesNormalIndex + face.VertexNormalsIndex.C }; an8Mesh.Faces.Add(an8Face); } else { var an8Face = new An8Face { MaterialIndex = materialIndex, FlatNormalIndex = -1 }; an8Face.PointIndexes = new int[] { verticesIndex + face.VerticesIndex.A, verticesIndex + face.VerticesIndex.B, verticesIndex + face.VerticesIndex.C, verticesIndex + face.VerticesIndex.D }; an8Face.TexCoordIndexes = new int[] { verticesTexIndex + face.TextureCoordinatesIndex.A, verticesTexIndex + face.TextureCoordinatesIndex.B, verticesTexIndex + face.TextureCoordinatesIndex.C, verticesTexIndex + face.TextureCoordinatesIndex.D }; an8Face.NormalIndexes = new int[] { verticesNormalIndex + face.VertexNormalsIndex.A, verticesNormalIndex + face.VertexNormalsIndex.B, verticesNormalIndex + face.VertexNormalsIndex.C, verticesNormalIndex + face.VertexNormalsIndex.D }; an8Mesh.Faces.Add(an8Face); } } } verticesIndex += mesh.Vertices.Count; verticesTexIndex += mesh.TextureCoordinates.Count; verticesNormalIndex += mesh.VertexNormals.Count; } an8.Save(Path.Combine(an8Directory, string.Format(CultureInfo.InvariantCulture, "{0}_{1}.an8", an8Name, distance))); } }