예제 #1
0
        public List <StlTriangle> ReadTriangles()
        {
            var triangles = new List <StlTriangle>();

            if (isAscii)
            {
                var t = ReadTriangle();
                while (t != null)
                {
                    EnsureCorrectNormal(t);
                    triangles.Add(t);
                    t = ReadTriangle();
                }
            }
            else
            {
                for (uint i = 0; i < triangleCount; i++)
                {
                    // normal should equal (v3-v2)x(v1-v1)
                    var normal = new StlNormal(ReadFloatBinary(), ReadFloatBinary(), ReadFloatBinary());
                    var v1     = ReadVertexBinary();
                    var v2     = ReadVertexBinary();
                    var v3     = ReadVertexBinary();
                    binReader.ReadUInt16(); // attribute byte count; garbage value
                    var t = new StlTriangle(normal, v1, v2, v3);
                    EnsureCorrectNormal(t);
                    triangles.Add(t);
                }
            }

            return(triangles);
        }
예제 #2
0
        private StlTriangle ReadTriangle()
        {
            StlTriangle triangle = null;

            if (isAscii)
            {
                switch (PeekToken())
                {
                case "facet":
                    AdvanceToken();
                    SwallowToken("normal");
                    var normal = new StlNormal(ConsumeNumberToken(), ConsumeNumberToken(), ConsumeNumberToken());
                    SwallowToken("outer");
                    SwallowToken("loop");
                    SwallowToken("vertex");
                    var v1 = ConsumeVertexToken();
                    SwallowToken("vertex");
                    var v2 = ConsumeVertexToken();
                    SwallowToken("vertex");
                    var v3 = ConsumeVertexToken();
                    SwallowToken("endloop");
                    SwallowToken("endfacet");
                    triangle = new StlTriangle(normal, v1, v2, v3);
                    break;

                case "endsolid":
                    return(null);

                default:
                    throw new StlReadException("Unexpected token " + PeekToken());
                }
            }

            return(triangle);
        }
예제 #3
0
 private static void EnsureCorrectNormal(StlTriangle triangle)
 {
     triangle.Normal = triangle.GetValidNormal();
 }
예제 #4
0
파일: StlReader.cs 프로젝트: IxMilia/Stl
        public List<StlTriangle> ReadTriangles()
        {
            var triangles = new List<StlTriangle>();
            if (isAscii)
            {
                var t = ReadTriangle();
                while (t != null)
                {
                    EnsureCorrectNormal(t);
                    triangles.Add(t);
                    t = ReadTriangle();
                }
            }
            else
            {
                for (uint i = 0; i < triangleCount; i++)
                {
                    // normal should equal (v3-v2)x(v1-v1)
                    var normal = new StlNormal(ReadFloatBinary(), ReadFloatBinary(), ReadFloatBinary());
                    var v1 = ReadVertexBinary();
                    var v2 = ReadVertexBinary();
                    var v3 = ReadVertexBinary();
                    binReader.ReadUInt16(); // attribute byte count; garbage value
                    var t = new StlTriangle(normal, v1, v2, v3);
                    EnsureCorrectNormal(t);
                    triangles.Add(t);
                }
            }

            return triangles;
        }
예제 #5
0
파일: StlReader.cs 프로젝트: IxMilia/Stl
        private StlTriangle ReadTriangle()
        {
            StlTriangle triangle = null;
            if (isAscii)
            {
                switch (PeekToken())
                {
                    case "facet":
                        AdvanceToken();
                        SwallowToken("normal");
                        var normal = new StlNormal(ConsumeNumberToken(), ConsumeNumberToken(), ConsumeNumberToken());
                        SwallowToken("outer");
                        SwallowToken("loop");
                        SwallowToken("vertex");
                        var v1 = ConsumeVertexToken();
                        SwallowToken("vertex");
                        var v2 = ConsumeVertexToken();
                        SwallowToken("vertex");
                        var v3 = ConsumeVertexToken();
                        SwallowToken("endloop");
                        SwallowToken("endfacet");
                        triangle = new StlTriangle(normal, v1, v2, v3);
                        break;
                    case "endsolid":
                        return null;
                    default:
                        throw new StlReadException("Unexpected token " + PeekToken());
                }
            }

            return triangle;
        }
예제 #6
0
파일: StlReader.cs 프로젝트: IxMilia/Stl
 private static void EnsureCorrectNormal(StlTriangle triangle)
 {
     triangle.Normal = triangle.GetValidNormal();
 }