示例#1
0
        public void GenerateTextEmpty()
        {
            var face = new An8Face();

            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 {
    0 0 0 0 ( )
  }
}
";

            Assert.Equal(
                expected.Replace("\r\n", "\n"),
                text.Replace("\r\n", "\n"));
        }
示例#2
0
        public void NewFace()
        {
            var face = new An8Face();

            Assert.False(face.IsBackShown);
            Assert.Equal(0, face.MaterialIndex);
            Assert.Equal(0, face.FlatNormalIndex);
            Assert.Null(face.PointIndexes);
            Assert.Null(face.NormalIndexes);
            Assert.False(face.HasNormalIndexes);
            Assert.Null(face.TexCoordIndexes);
            Assert.False(face.HasTexCoordIndexes);
        }
示例#3
0
        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"));
        }
示例#4
0
        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"));
        }
示例#5
0
        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)));
            }
        }
示例#6
0
        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)));
            }
        }