• 大小: 10KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-05
  • 语言: C#
  • 标签: C#  STL  

资源简介

提取STL的面片信息,包括三角面片的法向量和三个顶点

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {

        public class Point
        {
            public Point(double _x = 0 double _y = 0 double _z = 0)
            {
                x = _x;
                y = _y;
                z = _z;
            }
            public double x { get; set; }
            public double y { get; set; }
            public double z { get; set; }
        }

        public static void SimpleSaveTxt(List points )
        {
            string mFileFullname = @“D:\data.txt“;

            System.IO.StreamWriter mStreamWriter = new System.IO.StreamWriter(mFileFullname false System.Text.Encoding.UTF8);


            Console.WriteLine(“Length:“ + points.Count);

            for (int i = 0; i < points.Count; i++)
            {
                mStreamWriter.WriteLine(points[i].x + “ “ + points[i].y + “ “ + points[i].z);
            }

            mStreamWriter.Close();
            mStreamWriter.Dispose();
            mStreamWriter = null;
        }

        public static List FloatReadBinary(List points string filename)
        {
            int count = 0;

            using (BinaryReader reader = new BinaryReader(File.OpenRead(filename)))
            {
                reader.ReadBytes(80);
                uint facecount = reader.ReadUInt32();

                Console.WriteLine(“FaceCount:“ + facecount);

                for (int i = 0; i < facecount; i++)
                {
                    for (int m = 0; m < 4; m++)
                    {
                        float[] fs = new float[3];

                        for (int j = 0; j < 3; j++)
                        {
                            float x = reader.ReadSingle();
                            fs[j] = x;
                            Console.Write(“DD:“ + x + “ “);    
                        }
                        points.Add(new Point(fs[0] fs[1] fs[2]));
                        count++;
                        Console.WriteLine(“Count:“ + count);
                    }
                    Console.WriteLine();
                    UInt16 attribute = reader.ReadUInt16();
                    Console.WriteLine(“Arribute:“ + attribute);

                  //  Console.ReadKey();
                }
            }

            return points;
        }

        static void Main(string[] args)
        {

            string s = “06.stl“;
            List points = new List();

            points = FloatReadBinary(points s);

            SimpleSaveTxt(points);
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      45284  2011-08-07 17:34  06.stl

     文件       2740  2015-07-01 18:07  Program.cs

----------- ---------  ---------- -----  ----

                48024                    2


评论

共有 条评论