Пример #1
0
        public void ProcessFace(string line, Mesh mesh)
        {
            var tokens = line.Remove(0, 2).Split(' ');

            Face face = new Face();

            foreach (var token in tokens)
            {
                FaceItem item = new FaceItem();

                string[] items = token.Split('/');

                switch (items.Length)
                {
                    case 1:
                        if (!string.IsNullOrWhiteSpace(items[0])) item.Vertex = uint.Parse(items[0], Style, Info);
                        break;
                    case 2:
                        if (!string.IsNullOrWhiteSpace(items[0])) item.Vertex = uint.Parse(items[0], Style, Info);
                        if (!string.IsNullOrWhiteSpace(items[1])) item.Texture = uint.Parse(items[1], Style, Info);
                        break;
                    case 3:
                        if (!string.IsNullOrWhiteSpace(items[0])) item.Vertex = uint.Parse(items[0], Style, Info);
                        if (!string.IsNullOrWhiteSpace(items[1])) item.Texture = uint.Parse(items[1], Style, Info);
                        if (!string.IsNullOrWhiteSpace(items[2])) item.Normal = uint.Parse(items[2], Style, Info);
                        break;
                }
                face.Items.Add(item);
            }

            mesh.SubMeshes.Last().Faces.Add(face);
        }
Пример #2
0
        public void ProcessVertex(string line, Mesh mesh)
        {
            if (!mesh.SubMeshes.Any())
                mesh.SubMeshes.Add(new SubMesh());

            var tokens = line.Split(' ');
            if (tokens.Length != 4) return;

            Vector3 vertex = new Vector3
            {
                X = float.Parse(tokens[1], Style, Info),
                Y = float.Parse(tokens[2], Style, Info),
                Z = float.Parse(tokens[3], Style, Info)
            };

            mesh.SubMeshes.Last().Vertices.Add(vertex);

            //	Bounds
            if (vertex.X < mesh.MinVertex.X) mesh.MinVertex.X = vertex.X;
            if (vertex.Y < mesh.MinVertex.Y) mesh.MinVertex.Y = vertex.Y;
            if (vertex.Z < mesh.MinVertex.Z) mesh.MinVertex.Z = vertex.Z;

            if (vertex.X > mesh.MaxVertex.X) mesh.MaxVertex.X = vertex.X;
            if (vertex.Y > mesh.MaxVertex.Y) mesh.MaxVertex.Y = vertex.Y;
            if (vertex.Z > mesh.MaxVertex.Z) mesh.MaxVertex.Z = vertex.Z;
        }
Пример #3
0
        public void ThrowsWhenProcessIdIsNotDefined()
        {
            string unknownProcessId = _fixture.Create<string>();
            Mesh mesh = new Mesh();

            ParsingService service = new ParsingService();

            Assert.That(() => service.ProcessLine(unknownProcessId, mesh), Throws.InvalidOperationException);
        }
Пример #4
0
        public Mesh LoadMesh(string path)
        {
            var mesh = new Mesh();

            IEnumerable<string> lines = _fileLoader.LoadFile(path);

            foreach (string line in lines)
            {
                _parsingService.ProcessLine(line, mesh);
            }

            return mesh;
        }
Пример #5
0
        public void ReturnWhenLineIsEmpty(string line)
        {
            Mesh mesh = new Mesh();

            ParsingService service = new ParsingService();
            service.ProcessLine(line, mesh);
            
            Mesh emptyMesh = new Mesh();
            Assert.That(mesh.MinVertex, Is.EqualTo(emptyMesh.MinVertex));
            Assert.That(mesh.MaxVertex, Is.EqualTo(emptyMesh.MaxVertex));
            Assert.That(mesh.Filename, Is.Null);
            Assert.That(mesh.SubMeshes, Is.Empty);
        }
Пример #6
0
        public void ProcessTextCoord(string line, Mesh mesh)
        {
            var tokens = line.Split(' ');
            if (tokens.Length != 3) return;

            Vector3 texture = new Vector3
            {
                X = float.Parse(tokens[1], Style, Info),
                Y = float.Parse(tokens[2], Style, Info)
            };

            mesh.SubMeshes.Last().Textures.Add(texture);
        }
Пример #7
0
        public void ProcessNormal(string line, Mesh mesh)
        {
            var tokens = line.Split(' ');
            if (tokens.Length != 4) return;

            Vector3 normal = new Vector3
            {
                X = float.Parse(tokens[1], Style, Info),
                Y = float.Parse(tokens[2], Style, Info),
                Z = float.Parse(tokens[3], Style, Info)
            };

            mesh.SubMeshes.Last().Normals.Add(normal);
        }
Пример #8
0
        public void ProcessLine(string line, Mesh mesh)
        {
            //	comment
            if (string.IsNullOrWhiteSpace(line) || line.StartsWith("#")) return;

            string action = line.Split(' ').FirstOrDefault();
            if (action != null && ProcessDictionary.ContainsKey(action))
            {
                ProcessDictionary[action].Invoke(line, mesh);
            }
            else
            {
                throw new InvalidOperationException($"Cannot find a correct process for line {line}");
            }
        }
Пример #9
0
 public void ProcessObject(string line, Mesh mesh)
 {
     mesh.SubMeshes.Add(new SubMesh());
 }