Пример #1
0
        private TriMesh openBinary(string fileName)
        {
            UInt32 triCountBin = 0;
            var    triangles   = new TriMesh();

            try
            {
                if (fileName != null && fileName != "" & System.IO.File.Exists(fileName))
                {
                    using (System.IO.BinaryReader br = new System.IO.BinaryReader(System.IO.File.Open(fileName, System.IO.FileMode.Open)))
                    {
                        br.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
                        char[] header   = new char[80];
                        UInt32 triIndex = 0;
                        header      = br.ReadChars(80);
                        triCountBin = br.ReadUInt32();

                        while (triIndex < triCountBin && br.BaseStream.Position < br.BaseStream.Length)
                        {
                            double  n1   = br.ReadSingle();
                            double  n2   = br.ReadSingle();
                            double  n3   = br.ReadSingle();
                            double  v1x  = br.ReadSingle();
                            double  v1y  = br.ReadSingle();
                            double  v1z  = br.ReadSingle();
                            double  v2x  = br.ReadSingle();
                            double  v2y  = br.ReadSingle();
                            double  v2z  = br.ReadSingle();
                            double  v3x  = br.ReadSingle();
                            double  v3y  = br.ReadSingle();
                            double  v3z  = br.ReadSingle();
                            UInt16  attr = br.ReadUInt16();
                            Vector3 norm = new Vector3(n1, n2, n3);
                            Vector3 p1   = new Vector3(v1x, v1y, v1z);
                            Vector3 p2   = new Vector3(v2x, v2y, v2z);
                            Vector3 p3   = new Vector3(v3x, v3y, v3z);
                            triangles.Add(new Triangle(p1, p2, p3, triIndex));
                            triIndex++;
                        }
                    }
                }
                return(triangles);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
0
        private TriMesh openAscii(string fileName)
        {
            var file    = openTextFile(fileName);
            var triMesh = new TriMesh();

            try
            {
                UInt32 triIndex = 0;
                for (int i = 0; i < file.Count; i++)
                {
                    if (file[i].Contains("normal"))
                    {
                        triMesh.Add(new Triangle(parseVertex(file[i + 2]), parseVertex(file[i + 3]), parseVertex(file[i + 4]), parseVector(file[i]), triIndex));
                        triIndex++;
                    }
                }
                int triCount = triMesh.Count;
                return(triMesh);
            }
            catch (Exception)
            {
                throw;
            }
        }