コード例 #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);
        }
コード例 #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);
        }
コード例 #3
0
ファイル: StlWriter.cs プロジェクト: ixmilia/stl
 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)));
 }
コード例 #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)));
 }
コード例 #5
0
ファイル: StlWriter.cs プロジェクト: IxMilia/Stl
 private static string NormalToString(StlNormal normal)
 {
     return string.Format("{0} {1} {2}", normal.X.ToString(FloatFormat), normal.Y.ToString(FloatFormat), normal.Z.ToString(FloatFormat));
 }
コード例 #6
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;
        }
コード例 #7
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;
        }