Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
 private static void EnsureCorrectNormal(StlTriangle triangle)
 {
     triangle.Normal = triangle.GetValidNormal();
 }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
0
 private static void EnsureCorrectNormal(StlTriangle triangle)
 {
     triangle.Normal = triangle.GetValidNormal();
 }