예제 #1
0
        private void TransformPoints(Glyph fromGlyph, VectorTransform transform)
        {
            if (HoleSorted && !fromGlyph.WasHoleSorted)
            {
                // We must sort all components:
                fromGlyph.HoleSort();
            }

            VectorPoint current = fromGlyph.FirstPathNode;

            while (current != null)
            {
                // Create a new one:
                VectorPoint newPoint = current.Copy();

                // Apply transformed pos:
                newPoint.Transform(transform);

                // Add it:
                AddPathNode(newPoint);

                current = current.Next;

                if (current == null)
                {
                    // Last one - ensure it's closed:
                    newPoint.IsClose = true;
                }
            }
        }
예제 #2
0
        public static List <string> WriteSTLOfShells(TelescopeSegment segment, Vector3 minOffset)
        {
            List <string> stlNames = new List <string>();

            foreach (TelescopeShell shell in segment.shells)
            {
                string stl = "stls/" + shell.name + ".stl";
                using (StreamWriter file = new StreamWriter("scad/" + stl))
                {
                    VectorTransform ShellTransform = (v =>
                                                      shell.transform.rotation * v + shell.transform.position - minOffset);

                    List <string> shellLines = FacetsOfMesh(shell.mesh, ShellTransform);

                    file.WriteLine("solid " + shell.name);
                    foreach (string line in shellLines)
                    {
                        file.WriteLine(line);
                    }
                    file.WriteLine("endsolid");
                }
                stlNames.Add(stl);
            }
            return(stlNames);
        }
예제 #3
0
        public static List <string> STLOfMesh(Mesh m)
        {
            Bounds          b = m.bounds;
            VectorTransform f = (v => v - b.min);

            return(STLOfMesh(m, f));
        }
예제 #4
0
        public static List <string> STLOfMesh(Mesh m, VectorTransform f)
        {
            List <string> facets = FacetsOfMesh(m, f);

            facets.Insert(0, "solid " + m.name);
            facets.Add("endsolid");

            return(facets);
        }
예제 #5
0
 public void AddComponent(VectorTransform component)
 {
     if (FirstComponent == null)
     {
         // Set as only one:
         FirstComponent = LastComponent = component;
     }
     else
     {
         // Push to the end:
         LastComponent = LastComponent.Next = component;
     }
 }
예제 #6
0
 private void UpdateVectorTransform()
 {
     VectorTransform.Series.Clear();
     VectorTransform.Series.Add(XOneFormSeries());
     VectorTransform.Series.Add(YOneFormSeries());
     foreach (var line in _model.VectorCoordinates())
     {
         VectorTransform.Series.Add(line);
     }
     VectorTransform.Series.Add(VectorSeries(true));
     VectorTransform.Series.Add(XAxis());
     VectorTransform.Series.Add(YAxis());
     VectorTransform.InvalidatePlot(true);
 }
예제 #7
0
        static List <string> FacetsOfMesh(Mesh m, VectorTransform f)
        {
            List <string> lines = new List <string>();

            int numTriangles = m.triangles.Length / 3;

            for (int i = 0; i < numTriangles; i++)
            {
                // Unity has clockwise winding order; STL takes CCW, so reverse
                int i1 = m.triangles[3 * i + 0];
                int i2 = m.triangles[3 * i + 1];
                int i3 = m.triangles[3 * i + 2];

                Vector3 p1 = f(m.vertices[i1]);
                Vector3 p2 = f(m.vertices[i2]);
                Vector3 p3 = f(m.vertices[i3]);

                CheckPositiveOctant(p1);
                CheckPositiveOctant(p2);
                CheckPositiveOctant(p3);

                Vector3 e1          = p2 - p1;
                Vector3 e2          = p3 - p1;
                Vector3 crossNormal = Vector3.Cross(e2.normalized, e1.normalized);

                /*
                 * Vector3 vertAverageNormal = m.normals[i1] + m.normals[i2] + m.normals[i3];
                 * vertAverageNormal.Normalize();
                 * float dot = Vector3.Dot(crossNormal, vertAverageNormal);
                 * if (dot < 0)
                 * {
                 *  throw new System.Exception("cross normal doesn't match vertex normals: " + dot);
                 * }
                 */

                StringOfVector sov = (v => v.x + " " + v.y + " " + v.z);

                lines.Add("  facet normal " + sov(-crossNormal));
                lines.Add("    outer loop");
                lines.Add("      vertex " + sov(p1));
                lines.Add("      vertex " + sov(p2));
                lines.Add("      vertex " + sov(p3));
                lines.Add("    endloop");
                lines.Add("  endfacet");
            }

            return(lines);
        }
예제 #8
0
        public override void LoadFully(Glyph[] glyphs)
        {
            VectorTransform current = FirstComponent;

            while (current != null)
            {
                Glyph componentGlyph = glyphs[current.Index];

                if (componentGlyph != null)
                {
                    // Transform the points of the component glyph into this one:
                    TransformPoints(componentGlyph, current);
                }

                current = current.Next;
            }
        }
예제 #9
0
        public override void LoadNow()
        {
            // Clear:
            FirstPathNode  = null;
            LatestPathNode = null;
            PathNodeCount  = 0;

            Glyph[] glyphs = Font.ParserGlyphs;

            VectorTransform current = FirstComponent;

            while (current != null)
            {
                Glyph componentGlyph = glyphs[current.Index];

                if (componentGlyph != null)
                {
                    if (componentGlyph.RequiresLoad)
                    {
                        // Load it:
                        componentGlyph.LoadNow();
                    }
                }

                if (componentGlyph.WasHoleSorted)
                {
                    // Sort all of them.
                    HoleSorted = true;
                }

                current = current.Next;
            }

            // Load fully:
            LoadFully(glyphs);

            // Reduce the amount of unloaded glyphs:
            Font.UnloadedGlyphs--;

            if (Font.UnloadedGlyphs <= 0)
            {
                // Let the font know that every glyph is now loaded:
                Font.AllGlyphsLoaded();
            }
        }
예제 #10
0
        private void TransformPoints(Glyph fromGlyph, VectorTransform transform)
        {
            VectorPoint current = fromGlyph.FirstPathNode;

            while (current != null)
            {
                // Create a new one:
                VectorPoint newPoint = current.Copy();

                // Apply transformed pos:
                newPoint.Transform(transform);

                // Add it:
                AddPathNode(newPoint);

                current = current.Next;
            }
        }
예제 #11
0
        public static void WriteSTLOfSegment(TelescopeSegment segment, Vector3 minOffset, string filename)
        {
            Debug.Log("Write STL to " + filename);

            List <string> allLines = new List <string>();

            allLines.Add("solid " + segment.name);

            foreach (TelescopeShell shell in segment.shells)
            {
                VectorTransform ShellTransform = (v =>
                                                  shell.transform.rotation * v + shell.transform.position - minOffset);

                List <string> shellLines = FacetsOfMesh(shell.mesh, ShellTransform);
                allLines.AddRange(shellLines);
            }

            allLines.Add("endsolid");
            File.WriteAllLines(filename, allLines.ToArray());
        }
예제 #12
0
        public static Glyph ParseGlyph(FontParser parser, FontFace font, float range)
        {
            // How many contours has it got?
            int contourCount = parser.ReadInt16();

            // Skip bounds - we don't trust these too much, so we'll figure them out ourselves:
            parser.Position += 8;

            if (contourCount > 0)
            {
                // This glyph is not a composite.

                // Create the glyph:
                Glyph glyph = new Glyph(font);

                if (Fonts.Preload)
                {
                    LoadGlyph(glyph, contourCount, parser, range);
                }
                else
                {
                    // Increase unloaded count:
                    font.UnloadedGlyphs++;

                    // Add position info:
                    glyph.AddPathNode(new LoadMetaPoint(parser.Position, contourCount));
                }

                return(glyph);
            }
            else if (contourCount == 0)
            {
                // Empty glyph e.g. space. Create the glyph:
                Glyph glyph = new Glyph(font);

                return(glyph);
            }

            CompositeGlyph compGlyph = new CompositeGlyph(font);

            bool moreComponents = true;

            while (moreComponents)
            {
                ushort cFlags     = parser.ReadUInt16();
                ushort glyphIndex = parser.ReadUInt16();

                VectorTransform component = new VectorTransform(glyphIndex);

                if ((cFlags & 1) > 0)
                {
                    // The arguments are words
                    component.Dx = (float)parser.ReadInt16() / range;
                    component.Dy = (float)parser.ReadInt16() / range;
                }
                else
                {
                    // The arguments are bytes
                    component.Dx = (float)parser.ReadByte() / range;
                    component.Dy = (float)parser.ReadByte() / range;
                }

                if ((cFlags & 8) > 0)
                {
                    // We have one scale
                    component.XScale = component.YScale = parser.ReadF2Dot14();
                }
                else if ((cFlags & 64) > 0)
                {
                    // We have an X / Y scale
                    component.XScale = parser.ReadF2Dot14();
                    component.YScale = parser.ReadF2Dot14();
                }
                else if ((cFlags & 128) > 0)
                {
                    // We have a 2x2 transformation
                    component.XScale  = parser.ReadF2Dot14();
                    component.Scale01 = parser.ReadF2Dot14();
                    component.Scale10 = parser.ReadF2Dot14();
                    component.YScale  = parser.ReadF2Dot14();
                }

                // Push the component to the end:
                compGlyph.AddComponent(component);

                moreComponents = ((cFlags & 32) == 32);
            }

            return(compGlyph);
        }
예제 #13
0
        public static void WriteSTLOfMesh(Mesh m, string s, VectorTransform f)
        {
            List <string> lines = STLOfMesh(m, f);

            File.WriteAllLines(s, lines.ToArray());
        }