Пример #1
0
        public void Parse(string[] lines)
        {
            foreach (var line in lines)
            {
                if (line == string.Empty)
                {
                    continue;
                }
                var splittedline = line.Split(new char[] { ' ' }, 2);
                switch (splittedline[0])
                {
                case "v":
                    Vertices.Add(StringToPoint(splittedline[1]));
                    break;

                case "vn":
                    Normals.Add(StringToVector(splittedline[1]));
                    break;

                case "g":
                    LastGroupAdded = splittedline[1];
                    Groups.Add(LastGroupAdded, new Group());
                    break;

                case "f":
                    Groups[LastGroupAdded].Add(
                        FanTriangulate(splittedline[1]));
                    break;

                default: IgnoredLines++; break;
                }
            }
        }
Пример #2
0
 public void CreateDefaultNormals()
 {
     while (Normals.Count < Vertices.Count)
     {
         Normals.Add(new Vector3(0, 0, 1));
     }
 }
Пример #3
0
 public void AddVertex(Vector3 pos, Vector3 normal, Vector2 texCoord)
 {
     Vertices.Add(pos);
     Normals.Add(normal);
     TexCoords.Add(texCoord);
     Indices.Add(Indices.Count);
 }
Пример #4
0
 public ObjFaceBuilder Vertex(int v, int?n = null, int?t = null)
 {
     Vertices.Add(v);
     Normals.Add(n ?? -1);
     UVs.Add(t ?? -1);
     return(this);
 }
Пример #5
0
        private void ReadNormal(string[] items)
        {
            var x = double.Parse(items[1]);
            var y = double.Parse(items[2]);
            var z = double.Parse(items[3]);

            Normals.Add(Helper.CreatePoint(x, y, z));
        }
Пример #6
0
        public ObjFileParser()
        {
            // Dummies to get 1-indexed arrays.
            Vertices.Add(Tuple.Point(0, 0, 0));
            Normals.Add(Tuple.Vector(0, 0, 0));

            // Add the default group
            _groups.Add("", new Group());
        }
Пример #7
0
 public void AddVtx(Primitive src, int vtxIdx)
 {
     VertexCount++;
     Matrices.Add(src.Matrices[vtxIdx]);
     Positions.Add(src.Positions[vtxIdx]);
     Normals.Add(src.Normals[vtxIdx]);
     Colors.Add(src.Colors[vtxIdx]);
     TexCoords.Add(src.TexCoords[vtxIdx]);
 }
Пример #8
0
        /// <summary>
        /// Add OBJ model
        /// </summary>
        /// <param name="Path"></param>
        /// <returns></returns>
        public Mesh AddOBJ(string Path)
        {
            FileStream fileStream = new FileStream(Path, FileMode.Open);

            using (StreamReader reader = new StreamReader(fileStream))
            {
                string line;
                Mesh   tmp = new Mesh();

                while ((line = reader.ReadLine()) != null)
                {
                    string[] d = line.Split(" ");

                    //Vertex
                    if (d.Length == 4 && d[0].Equals("v"))
                    {
                        tmp.Positions.Add(new Vector3(float.Parse(d[1], NumberStyles.Any, CultureInfo.InvariantCulture), float.Parse(d[2], NumberStyles.Any, CultureInfo.InvariantCulture), float.Parse(d[3], NumberStyles.Any, CultureInfo.InvariantCulture)));
                    }
                    //UV
                    if (d.Length == 3 && d[0].Equals("vt"))
                    {
                        tmp.UVs.Add(new Vector2(float.Parse(d[1], NumberStyles.Any, CultureInfo.InvariantCulture), float.Parse(d[2], NumberStyles.Any, CultureInfo.InvariantCulture)));
                    }
                    //Normal
                    if (d.Length == 4 && d[0].Equals("vn"))
                    {
                        tmp.Normals.Add(new Vector3(float.Parse(d[1], NumberStyles.Any, CultureInfo.InvariantCulture), float.Parse(d[2], NumberStyles.Any, CultureInfo.InvariantCulture), float.Parse(d[3], NumberStyles.Any, CultureInfo.InvariantCulture)));
                    }
                    //Face
                    if (d.Length == 4 && d[0].Equals("f"))
                    {
                        string[] tri1 = d[1].Split("/");
                        string[] tri2 = d[2].Split("/");
                        string[] tri3 = d[3].Split("/");

                        Positions.Add(tmp.Positions[int.Parse(tri1[0]) - 1]);
                        Positions.Add(tmp.Positions[int.Parse(tri2[0]) - 1]);
                        Positions.Add(tmp.Positions[int.Parse(tri3[0]) - 1]);

                        UVs.Add(tmp.UVs[int.Parse(tri1[1]) - 1]);
                        UVs.Add(tmp.UVs[int.Parse(tri2[1]) - 1]);
                        UVs.Add(tmp.UVs[int.Parse(tri3[1]) - 1]);

                        Normals.Add(tmp.Normals[int.Parse(tri1[2]) - 1]);
                        Normals.Add(tmp.Normals[int.Parse(tri2[2]) - 1]);
                        Normals.Add(tmp.Normals[int.Parse(tri3[2]) - 1]);

                        for (int i = 0; i < 3; i++)
                        {
                            Indices.Add(Indices.Count);
                        }
                    }
                }
            }

            return(this);
        }
Пример #9
0
        public void AddPlane(Microsoft.Xna.Framework.Vector3 intersection, Microsoft.Xna.Framework.Vector3 normal)
        {
            Vector <float> p = Vector <float> .Build.Dense(new float[] { intersection.X, intersection.Y, intersection.Z });

            Vector <float> n = Vector <float> .Build.Dense(new float[] { normal.X, normal.Y, normal.Z });

            Intersections.Add(p);
            Normals.Add(n);
            qef.Add(intersection, normal);
        }
Пример #10
0
        /// <summary>
        /// Добавление грани куба.
        /// </summary>
        /// <param name="center">
        /// Центр Куба.
        /// </param>
        /// <param name="normal">
        /// Вектор нормали для грани.
        /// </param>
        /// <param name="up">
        /// Вектор вверх для грани.
        /// </param>
        /// <param name="dist">
        /// Расстояние от центра куба до грани.
        /// </param>
        /// <param name="width">
        /// Ширина грани.
        /// </param>
        /// <param name="height">
        /// Высота грани.
        /// </param>
        void AddCubeFace(Vector3 center, Vector3 normal, Vector3 up, float dist, float width, float height)
        {
            var right = Vector3.Cross(normal, up);
            var n     = normal * dist / 2;

            up    *= height / 2;
            right *= width / 2;
            var p1 = center + n - up - right;
            var p2 = center + n - up + right;
            var p3 = center + n + up + right;
            var p4 = center + n + up - right;

            int i0 = Positions.Count;

            Positions.Add(p1);
            Positions.Add(p2);
            Positions.Add(p3);
            Positions.Add(p4);
            if (Normals != null)
            {
                Normals.Add(normal);
                Normals.Add(normal);
                Normals.Add(normal);
                Normals.Add(normal);
            }

            Indices.Add(i0 + 2);
            Indices.Add(i0 + 1);
            Indices.Add(i0 + 0);
            Indices.Add(i0 + 0);
            Indices.Add(i0 + 3);
            Indices.Add(i0 + 2);

            // добавление граней
            var face = new Face();

            face.Indices.Add(i0 + 2);
            face.Indices.Add(i0 + 1);
            face.Indices.Add(i0 + 0);
            face.Indices.Add(i0 + 0);
            face.Indices.Add(i0 + 3);
            face.Indices.Add(i0 + 2);

            Faces.Add(face);

            // добавление ребер к граням
            var edge = new Edge();

            AddLine(edge, i0 + 0, i0 + 1);
            AddLine(edge, i0 + 1, i0 + 2);
            AddLine(edge, i0 + 2, i0 + 3);
            AddLine(edge, i0 + 3, i0 + 0);
            //AddLine(edge, i0 + 2, i0 + 1);
            face.Edges.Add(edge);
        }
Пример #11
0
        public void Generate()
        {
            Float3 center = new();
            Float3 vertex = new();
            Float3 normal = new();

            // generate vertices, normals and uvs
            for (int j = 0; j <= radialSegments; j++)
            {
                for (int i = 0; i <= tubularSegments; i++)
                {
                    double u = (double)i / tubularSegments * arc;
                    double v = (double)j / radialSegments * Math.PI * 2;

                    // vertex
                    vertex.X = (float)((radius + tube * Math.Cos(v)) * Math.Cos(u));
                    vertex.Y = (float)((radius + tube * Math.Cos(v)) * Math.Sin(u));
                    vertex.Z = (float)(tube * Math.Sin(v));

                    Positions.Add(vertex);

                    // normal
                    center.X = (float)(radius * Math.Cos(u));
                    center.Y = (float)(radius * Math.Sin(u));
                    normal   = vertex - center;

                    Normals.Add(normal.Normalize);

                    // uv
                    TextureCoordinates.Add(new((float)i / tubularSegments, (float)j / radialSegments, 0.0f));
                }
            }

            for (int j = 1; j <= radialSegments; j++)
            {
                for (int i = 1; i <= tubularSegments; i++)
                {
                    // indices
                    int a = (tubularSegments + 1) * j + i - 1;
                    int b = (tubularSegments + 1) * (j - 1) + i - 1;
                    int c = (tubularSegments + 1) * (j - 1) + i;
                    int d = (tubularSegments + 1) * j + i;

                    // faces
                    Indices.Add(d);
                    Indices.Add(b);
                    Indices.Add(a);

                    Indices.Add(d);
                    Indices.Add(c);
                    Indices.Add(b);
                }
            }
        }
Пример #12
0
        /// <summary>
        /// 当前实体数据变成两倍,使单面实体变成双面实体。
        /// </summary>
        public void MakeDoubleSided()
        {
            ((List <XYZ>)Points).Capacity  = Points.Count * 2;
            ((List <XYZ>)Normals).Capacity = this.Normals.Count * 2;
            ((List <UV>)Uvs).Capacity      = this.Uvs.Count * 2;
            ((List <int>)Indices).Capacity = this.Indices.Count * 2;
            int count = Points.Count;

            for (int i = 0; i < count; i++)
            {
                Points.Add(Points[i]);
            }
            int count2 = Normals.Count;

            for (int j = 0; j < count2; j++)
            {
                Normals.Add(Normals[j]);
            }
            int count3 = Uvs.Count;

            for (int k = 0; k < count3; k++)
            {
                Uvs.Add(Uvs[k]);
            }
            for (int l = 0; l < count2; l++)
            {
                Normals[l].Negate();
            }
            int count4 = Indices.Count;

            for (int m = 0; m < count4; m++)
            {
                Indices.Add(Indices[m]);
            }
            int value = 0;

            for (int n = 0; n < count4; n++)
            {
                int num = n % 3;
                if (num != 1)
                {
                    if (num == 2)
                    {
                        Indices[n] = value;
                    }
                }
                else
                {
                    value      = Indices[n];
                    Indices[n] = Indices[n + 1];
                }
            }
        }
Пример #13
0
        public override void Update()
        {
            //Clear
            Positions.Clear();
            Indices.Clear();
            Normals.Clear();

            if (points.Count % 2 != 0)
            {
                throw new InvalidOperationException("The number of points should be even.");
            }
            var p10   = p1 - p0;
            var axisY = Vector3.Cross(axisX, p10);

            axisY.Normalize();
            axisX.Normalize();
            int index0 = Positions.Count;

            for (int i = 0; i < points.Count; i++)
            {
                var p = points[i];
                var d = (axisX * p.X) + (axisY * p.Y);
                Positions.Add(p0 + d);
                Positions.Add(p1 + d);

                if (Normals != null)
                {
                    d.Normalize();
                    Normals.Add(d);
                    Normals.Add(d);
                }
            }

            int n = points.Count - 1;

            for (int i = 0; i < n; i++)
            {
                int i0 = index0 + (i * 2);
                int i1 = i0 + 1;
                int i2 = i0 + 3;
                int i3 = i0 + 2;

                Indices.Add(i0);
                Indices.Add(i1);
                Indices.Add(i2);

                Indices.Add(i2);
                Indices.Add(i3);
                Indices.Add(i0);
            }
        }
Пример #14
0
        private void AddNormal(string[] parts)
        {
            // Normals
            if (parts.Length >= 4)
            {
                var x = double.Parse(parts[1]);
                var y = double.Parse(parts[2]);
                var z = double.Parse(parts[3]);

                var vector = new Vector(x, y, z);

                Normals.Add(vector);
            }
        }
Пример #15
0
        protected void SetBox(float hw, float hh)
        {
            internalVertices.Clear();
            Normals.Clear();
            internalVertices.Add(new Vec2(-hw, -hh));
            internalVertices.Add(new Vec2(hw, -hh));
            internalVertices.Add(new Vec2(hw, hh));
            internalVertices.Add(new Vec2(-hw, hh));

            Normals.Add(new Vec2(0.0f, -1.0f));
            Normals.Add(new Vec2(1.0f, 0.0f));
            Normals.Add(new Vec2(0.0f, 1.0f));
            Normals.Add(new Vec2(-1.0f, 0.0f));
            Initialize();
        }
Пример #16
0
        public bool AddNormal(String rawData)
        {
            string[] parts = rawData.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (parts.Length != 3)
            {
                return(false);
            }
            double x, y, z;

            if (!Double.TryParse(parts[0], out x) || !Double.TryParse(parts[1], out y) || !Double.TryParse(parts[2], out z))
            {
                return(false);
            }
            Normals.Add(new DSVector(x, y, z));
            return(true);
        }
Пример #17
0
        public void CalculateNormals()
        {
            Normals.Clear();

            Microsoft.Xna.Framework.Graphics.VertexPositionNormalTexture[] vp = new Microsoft.Xna.Framework.Graphics.VertexPositionNormalTexture[46];
            Game3DPlatformer.Instance.BaseCube.Meshes[0].MeshParts[0].VertexBuffer.GetData(vp);

            for (int i = 0; i < Indices.Count; i += 3)
            {
                Normals.Add(-Vector3.Cross(Vertices[Indices[i + 1]] - Vertices[Indices[i]], Vertices[Indices[i + 2]] - Vertices[Indices[i + 1]]));
                Normals.Add(-Vector3.Cross(Vertices[Indices[i + 1]] - Vertices[Indices[i]], Vertices[Indices[i + 2]] - Vertices[Indices[i + 1]]));

                Normals[Normals.Count - 2].Normalize();
                Normals[Normals.Count - 1].Normalize();
            }
        }
Пример #18
0
        private void InternalParse(string content)
        {
            var currentGroup = _groups[""];
            var lines        = content.Replace("\r\n", "\n").Split("\n");

            foreach (var line in lines)
            {
                var lineType = GetLineType(line);
                switch (lineType)
                {
                case LineType.Vertice:
                    Vertices.Add(ParseVertice(line));
                    break;

                case LineType.Triangle:
                    currentGroup.AddChild(ParseTriangle(line));
                    break;

                case LineType.SmoothTriangle:
                    currentGroup.AddChild(ParseSmoothTriangle(line));
                    break;

                case LineType.Polygon:
                    currentGroup.AddChilds(ParseTriangles(line));
                    break;

                case LineType.SmoothPolygon:
                    currentGroup.AddChilds(ParseSmoothTriangles(line));
                    break;

                case LineType.GroupName:
                    currentGroup = new Group();
                    var groupName = ParseGroupName(line);
                    _groups.Add(groupName, currentGroup);
                    break;

                case LineType.VertexNormal:
                    Normals.Add(ParseVertexNormal(line));
                    break;

                default:
                    NumberIgnoredLines++;
                    break;
                }
                ;
            }
        }
Пример #19
0
        public void CalculateNormals()
        {
            Normals.Clear();

            var tempNormals = new List <VertexNormalAverageHelper>();

            for (int i = 0; i < Positions.Count; i++)
            {
                tempNormals.Add(new VertexNormalAverageHelper());
            }

            foreach (var submesh in Submeshes)
            {
                foreach (var poly in submesh.Value.Polygons)
                {
                    var p0 = Positions[poly.Indices[0]];
                    var p1 = Positions[poly.Indices[1]];
                    var p2 = Positions[poly.Indices[2]];

                    var v1     = p0 - p2;
                    var v2     = p1 - p2;
                    var normal = Vector3.Cross(v1, v2);

                    tempNormals[poly.Indices[0]].Normal += normal;
                    tempNormals[poly.Indices[0]].NumVertices++;

                    tempNormals[poly.Indices[1]].Normal += normal;
                    tempNormals[poly.Indices[1]].NumVertices++;

                    tempNormals[poly.Indices[2]].Normal += normal;
                    tempNormals[poly.Indices[2]].NumVertices++;

                    if (poly.Shape == IOPolygonShape.Quad)
                    {
                        tempNormals[poly.Indices[3]].Normal += normal;
                        tempNormals[poly.Indices[3]].NumVertices++;
                    }
                }
            }

            for (int i = 0; i < tempNormals.Count; i++)
            {
                var normal = tempNormals[i].Normal / Math.Max(1, tempNormals[i].NumVertices);
                normal = Vector3.Normalize(normal);
                Normals.Add(normal);
            }
        }
Пример #20
0
        protected override void Parse(string keyword, string data)
        {
            switch (keyword.ToLower())
            {
            case "v":
                Vertices.Add(ParseVertex(data));
                break;

            case "vp":
                throw new NotImplementedException();
                break;

            case "vn":
                Normals.Add(ParseNormal(data));
                break;

            case "vt":
                TextureVertices.Add(ParseTextureVertex(data));
                break;

            case "g":

                break;

            case "f":
                Faces.Add(ParseFace(data));
                break;

            case "usemtl":
                Materials.Add(_currentMaterial = LoadedMaterials.First(m => m.Name == data));
                break;

            case "mtllib":
                using (var stream = FileSource.Get(data))
                {
                    MaterialFiles.Add(new MATFile(stream, FileSource));
                }
                break;

            default:
                throw new Exception(keyword);
                break;
                //
            }
        }
Пример #21
0
        public void SetTriangle(TriangleData triangle)
        {
            Triangles.Add(triangle.T0);
            Triangles.Add(triangle.T1);
            Triangles.Add(triangle.T2);

            Vertices.Add(triangle.V0);
            Vertices.Add(triangle.V1);
            Vertices.Add(triangle.V2);

            Normals.Add(triangle.N0);
            Normals.Add(triangle.N1);
            Normals.Add(triangle.N2);

            Uvs.Add(triangle.Uv0);
            Uvs.Add(triangle.Uv1);
            Uvs.Add(triangle.Uv2);
        }
Пример #22
0
        public virtual void Deserialize(Stream stream)
        {
            using (var r = stream.ToBinaryReader(true))
            {
                var count = r.ReadInt32();
                for (var i = 0; i < count; i++)
                {
                    Vertices.Add(new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()));
                }

                count = r.ReadInt32();
                for (var i = 0; i < count; i++)
                {
                    Faces.Add(new Vector3(r.ReadInt16(), r.ReadInt16(), r.ReadInt16()));
                }

                count = r.ReadInt32();
                for (var i = 0; i < count; i++)
                {
                    Normals.Add(new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()));
                }

                count = r.ReadInt32();
                for (var i = 0; i < count; i++)
                {
                    UV.Add(new Vector2(r.ReadSingle(), r.ReadSingle()));
                }

                if (ModelChunk.TextureData.Unk2 == 1)
                {
                    for (var i = 0; i < count; i++)
                    {
                        UV2.Add(new Vector2(r.ReadSingle(), r.ReadSingle()));
                    }
                }

                count = r.ReadInt32();
                for (var i = 0; i < count; i++)
                {
                    Unk.Add(new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()));
                }
            }
        }
Пример #23
0
        private void ReadNormal(char[] contents)
        {
            var normal = Tuple.Vector(0, 0, 0);

            for (int i = 0; i < 3; ++i)
            {
                Token token = GetNextToken(contents);
                if (token.Type == TokenType.Number)
                {
                    normal[i] = float.Parse(token.Value);
                }
                else
                {
                    throw new FormatException($"{token.Value} is not a Number");
                }
            }

            Normals.Add(normal);
        }
Пример #24
0
    public void AddTriangleToMesh(Vector3[] triangleVertices, Vector3[] normals, Vector2[] uvs)
    {
        for (int i = 0; i < 3; i++)
        {
            Vector3 vertex = triangleVertices[i];

            /*this.Vertices.Add (vertex);
             *          this.Normals.Add (normals [i]);
             *          this.UVs.Add (uvs [i]);
             * this.Triangles.Add(this.Vertices.Count - 1);*/

            if (!Vertices.Contains(vertex))
            {
                Vertices.Add(vertex);
                Normals.Add(normals[i]);
                UVs.Add(uvs[i]);
                Triangles.Add(Vertices.Count - 1);
            }
            else
            {
                int[] indicesForVertex = IndexOfAllOccurences(Vertices, vertex);
                bool  itAlreadyExisted = false;
                foreach (int vertexIndex in indicesForVertex)
                {
                    if (Normals[vertexIndex] == normals[i] && UVs[vertexIndex] == uvs[i])
                    {
                        Triangles.Add(vertexIndex);
                        itAlreadyExisted = true;
                        break;
                    }
                }

                if (!itAlreadyExisted)
                {
                    Vertices.Add(vertex);
                    Normals.Add(normals[i]);
                    UVs.Add(uvs[i]);
                    Triangles.Add(Vertices.Count - 1);
                }
            }
        }
    }
Пример #25
0
        public void AddNormals(IEnumerable <string> vertices)
        {
            var tmpVertex = vertices.ToArray();

            try
            {
                if (tmpVertex.Length != 3)
                {
                    throw new ArgumentException();
                }
                var vert3 = VertexParser.Parse(tmpVertex[0], tmpVertex[1], tmpVertex[2]);
                Normals.Add(vert3);
            }
            catch
            {
                _normalsDamaged.Add(Normals.Count, string.Join(" ", vertices));
                //Console.WriteLine(String.Join(" ", vertexes));
                Normals.Add(Vector3.Zero);
            }
        }
Пример #26
0
        public void Add(Vector3 p, Vector3 n)
        {
            Intersections.Add(p);
            Normals.Add(n);

            /*ata.M11 += n.X * n.X;
             * ata.M12 += n.X * n.Y;
             * ata.M13 += 0; //x * z
             * ata.M21 += n.Y * n.Y;
             * ata.M22 += 0; //y * z
             * ata.M23 += 0; //z * z
             *
             * float dot = n.X * p.X + n.Y * p.Y;
             * atb.X += dot * n.X;
             * atb.Y += dot * n.Y;
             *
             * btb += dot * dot;*/

            mass_point += p;
        }
Пример #27
0
        public void Generate()
        {
            // A cube has six faces, each one pointing in a different direction.
            Float3[] normals =
            {
                new Float3(0,   0,  1),
                new Float3(0,   0, -1),
                new Float3(1,   0,  0),
                new Float3(-1,  0,  0),
                new Float3(0,   1,  0),
                new Float3(0,  -1,  0),
            };

            // Create each face in turn.
            foreach (Float3 normal in normals)
            {
                // Get two vectors perpendicular to the face normal and to each other.
                Float3 side1 = new Float3(normal.Y, normal.Z, normal.X);
                Float3 side2 = normal.Cross(side1);

                // Six indices (two triangles) per face.
                Indices.Add(Positions.Count + 0);
                Indices.Add(Positions.Count + 1);
                Indices.Add(Positions.Count + 2);

                Indices.Add(Positions.Count + 0);
                Indices.Add(Positions.Count + 2);
                Indices.Add(Positions.Count + 3);

                // Four vertices per face.
                Positions.Add((normal - side1 - side2) * _size / 2);
                Positions.Add((normal - side1 + side2) * _size / 2);
                Positions.Add((normal + side1 + side2) * _size / 2);
                Positions.Add((normal + side1 - side2) * _size / 2);

                Normals.Add(normal);
                Normals.Add(normal);
                Normals.Add(normal);
                Normals.Add(normal);
            }
        }
Пример #28
0
        public ushort CreateFreshSubMesh(ushort vertsToReserve, ushort trisToReserve)
        {
            // create custom List<> implementation with NativeArray that supports growth without assignment!
            SubMesh subMesh = new SubMesh((ushort)Verts.Count, (ushort)Tris.Count, vertsToReserve, trisToReserve);

            lastVert += vertsToReserve;
            lastTri  += trisToReserve;
            SubMeshes.Add(subMesh);
            for (int i = 0; i < vertsToReserve; i++)
            {
                Verts.Add(Vector3.zero); // this is multiple assignment! BAD!
                Normals.Add(Vector3.up);
                TextureUVs.Add(Vector2.zero);
                SubmaterialUVs.Add(Vector2.zero);
            }
            for (int i = 0; i < trisToReserve; i++)
            {
                Tris.Add(0); // more evil multiple assignment!
            }
            return((ushort)(SubMeshes.Count + SubMeshBaseIdx - 1));
        }
Пример #29
0
        public bool Parse(Section section)
        {
            var reader = new BinaryReader(new MemoryStream(section.Data));

            while (reader.ReadByte() == 0x11)
            {
            }

            reader.BaseStream.Position -= 1;

            var desc = section.ParentSection.GetSection(SectionHeaders.MeshDescription).Decode <MeshDescription>();

            while (Positions.Count < desc.VerticesCount)
            {
                var posX = reader.ReadSingle();
                var posY = reader.ReadSingle();
                var posZ = reader.ReadSingle();

                var normalX = reader.ReadSingle();
                var normalY = reader.ReadSingle();
                var normalZ = reader.ReadSingle();

                var unknown = reader.ReadSingle();

                var texCoordX = reader.ReadSingle();
                var texCoordY = reader.ReadSingle();

                Positions.Add(new Vector3f(posX, posY, posZ));
                Normals.Add(new Vector3f(normalX, normalY, normalZ));
                TexCoordinates.Add(new Vector2f(texCoordX, texCoordY));
                Unknown.Add(unknown);
            }

            Console.WriteLine("End Position : " + reader.BaseStream.Position + " out of " + reader.BaseStream.Length);

            return(true);
        }
Пример #30
0
        /// <summary>
        /// Добавление сферы.
        /// </summary>
        /// <param name="с">
        /// Центр сферы.
        /// </param>
        /// <param name="Radius">
        /// Радиус сферы.
        /// </param>
        /// <param name="thetaDiv">
        /// The number of divisions around the ellipsoid.
        /// </param>
        /// <param name="phiDiv">
        /// The number of divisions from top to bottom of the ellipsoid.
        /// </param>
        public override void Update()
        {
            //Очитска
            Positions.Clear();
            Indices.Clear();
            Normals.Clear();

            var c = new Vector3(1, 1, 1);
            int thetaDiv = 32; int phiDiv = 32;
            int index0 = this.Positions.Count;
            var dt     = 2 * Math.PI / thetaDiv;
            var dp     = Math.PI / phiDiv;

            for (int pi = 0; pi <= phiDiv; pi++)
            {
                var phi = pi * dp;

                for (int ti = 0; ti <= thetaDiv; ti++)
                {
                    var theta = ti * dt;
                    var x     = Math.Cos(theta) * Math.Sin(phi);
                    var y     = Math.Sin(theta) * Math.Sin(phi);
                    var z     = Math.Cos(phi);

                    var p = new Vector3((float)(c.X + (Radius * x)), (float)(c.Y + (Radius * y)), (float)(c.Z + (Radius * z)));
                    Positions.Add(new Vector3(p.X, p.Y, p.Z));

                    if (Normals != null)
                    {
                        var n = new Vector3((float)x, (float)y, (float)z);
                        Normals.Add(n);
                    }
                }
            }

            this.AddIndices(index0, phiDiv + 1, thetaDiv + 1, true);
        }