Example #1
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);
        }
Example #2
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);
        }
Example #3
0
 private static string NormalToString(StlNormal normal)
 {
     return(string.Format("{0} {1} {2}",
                          normal.X.ToString(FloatFormat, CultureInfo.InvariantCulture),
                          normal.Y.ToString(FloatFormat, CultureInfo.InvariantCulture),
                          normal.Z.ToString(FloatFormat, CultureInfo.InvariantCulture)));
 }
Example #4
0
 private static string NormalToString(StlNormal normal)
 {
     return(string.Format("{0} {1} {2}", normal.X.ToString(FloatFormat), normal.Y.ToString(FloatFormat), normal.Z.ToString(FloatFormat)));
 }
Example #5
0
 private static string NormalToString(StlNormal normal)
 {
     return string.Format("{0} {1} {2}", normal.X.ToString(FloatFormat), normal.Y.ToString(FloatFormat), normal.Z.ToString(FloatFormat));
 }
Example #6
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;
        }
Example #7
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;
        }