Add() public method

Add vertice to array list of connecting vertices
public Add ( int vert ) : void
vert int
return void
Ejemplo n.º 1
0
        public void Load()
        {
            var data       = File.ReadAllLines(_file);
            var mostLeftX  = float.MinValue;
            var mostRightX = float.MinValue;
            var mostLeftZ  = float.MinValue;
            var mostRightZ = float.MinValue;
            var mostLeftY  = float.MinValue;
            var mostRightY = float.MinValue;

            foreach (var line in data.Where(l => !l.StartsWith("#")))
            {
                if (line.StartsWith("vn"))
                {
                    var blocks = GetBlocks("vn", line);
                    var i      = float.Parse(blocks[0]);
                    var j      = float.Parse(blocks[1]);
                    var k      = float.Parse(blocks[2]);
                    Normals.Add(new Vector3(i, j, k));
                }
                else if (line.StartsWith("vt"))
                {
                    //Texture
                }
                else if (line.StartsWith("v"))
                {
                    var blocks = GetBlocks("v", line);

                    var x = float.Parse(blocks[0]);
                    if (mostLeftX == float.MinValue || x < mostLeftX)
                    {
                        mostLeftX = x;
                    }
                    if (mostRightX == float.MinValue || x > mostRightX)
                    {
                        mostRightX = x;
                    }

                    var y = float.Parse(blocks[1]);
                    if (mostLeftY == float.MinValue || y < mostLeftY)
                    {
                        mostLeftY = y;
                    }
                    if (mostRightY == float.MinValue || y > mostRightY)
                    {
                        mostRightY = y;
                    }

                    var z = float.Parse(blocks[2]);
                    if (mostLeftZ == float.MinValue || z < mostLeftZ)
                    {
                        mostLeftZ = z;
                    }
                    if (mostRightZ == float.MinValue || z > mostRightZ)
                    {
                        mostRightZ = z;
                    }

                    var w = 1.0f;
                    if (blocks.Count > 3)
                    {
                        w = float.Parse(blocks[3]);
                    }
                    Vertice.Add(new VertexTextureNormal
                    {
                        Vertex = new Vector3(x, y, z)
                    });
                }
                else if (line.StartsWith("f"))
                {
                    var points = ReadF(line);
                    for (var i = 0; i < 3; i++)
                    {
                        var point = points[i];
                        //obj data is 1 based
                        Indices.Add(point.vertex - 1);
                        //Skip textures for now
                        Vertice[(int)point.vertex - 1].Normal = Normals[(int)point.normal - 1];
                    }
                    if (points.Count == 4)
                    {
                        for (var i = 0; i < 4; i++)
                        {
                            var point = points[i];
                            //obj data is 1 based
                            Indices.Add(point.vertex - 1);
                            //Skip textures for now
                            Vertice[(int)point.vertex - 1].Normal = Normals[(int)point.normal - 1];

                            if (i == 0)
                            {
                                i++;
                            }
                        }
                    }
                }
            }
            Size = new CubeSize(Math.Abs(mostRightX) - Math.Abs(mostLeftX), Math.Abs(mostRightY) - Math.Abs(mostLeftY), Math.Abs(mostRightZ) - Math.Abs(mostLeftZ));
        }