コード例 #1
0
 public StripedPathSet(SvgParser.SvgPath path, StripeFieldConfig stripeFieldConfig, SCSvgFileData _svgFileData)
 {
     this.stripeFieldConfig = stripeFieldConfig;
     this._svgFileData      = _svgFileData;
     diamondCalculator      = new DiamondCalculator(stripeFieldConfig);
     dbugSettings           = UnityEngine.Object.FindObjectOfType <DbugSettings>();
     setup(path);
 }
コード例 #2
0
ファイル: SVGCrosshatch.cs プロジェクト: melsov/SVGCrosshatch
    private void lineRenderPath(SvgParser.SvgPath path)
    {
        SCPathDisplay display = Instantiate(pathDisplayPrefab); // go.AddComponent<SCPathDisplay>();

        display.color            = testColor;
        display.transform.parent = transform;
        display.display(path);
    }
コード例 #3
0
 public static IEnumerable <Vector2f> GetPoints(SvgParser.SvgPath path, bool appendFirstPointIfClosed = true)
 {
     for (int i = 0; i < path.npts; ++i)
     {
         yield return(PointAt(path, i));
     }
     if (appendFirstPointIfClosed && path.closed)
     {
         yield return(PointAt(path, 0));
     }
 }
コード例 #4
0
 public PathData(SvgParser.SvgPath path, bool isYAxisInverted = true)
 {
     this.path            = path;
     this.isYAxisInverted = isYAxisInverted;
     addPathPoints(path);
     if (pathPoints.Count < 2)
     {
         throw new Exception("Not sure I can work with this path. (fewer than 2 points)");
     }
     setup();
 }
コード例 #5
0
 public void updatePath(SvgParser.SvgPath path)
 {
     if (path._class != null && storage.ContainsKey(path._class))
     {
         path.updateWith(storage[path._class]);
     }
     else
     {
         Debug.Log("no class: " + path._class);
     }
 }
コード例 #6
0
        private void addRotatedCopies(SvgParser.SvgPath it, int copyOffset = 0)
        {
            PathData pdata = new PathData(it, _svgFileData.isYAxisInverted);

            int      iters   = dbugSettings.numVariations;
            float    ang     = Mathf.PI / 2f / iters;
            Vector2f cOffset = new Vector2f(0f, iters / dbugSettings.variationColumns * copyOffset);

            for (int i = 0; i < iters; ++i)
            {
                paths.Add(rotateAndShift(pdata, ang * i, cOffset + new Vector2f(i % (dbugSettings.variationColumns), i / (dbugSettings.variationColumns))));
            }
        }
コード例 #7
0
        // clockwise detection: https://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-points-are-in-clockwise-order

        private void addPathPoints(SvgParser.SvgPath path)
        {
            pathPoints = new List <Vector2f>(path.npts);
            float    shoeLaceSum = 0f;
            Vector2f v, vNext;

            for (int i = 0; i < path.npts; ++i)
            {
                v            = PathToVector.PointAt(path, i);
                vNext        = PathToVector.PointAt(path, (i + 1) % path.npts);
                shoeLaceSum += (vNext.x - v.x) * (vNext.y + v.y);
                pathPoints.Add(v);
                average += v;
            }
            area = Math.Abs(shoeLaceSum) / 2f;
            isClockwiseOrdered = (shoeLaceSum > 0f) != isYAxisInverted;
            average           /= path.npts;
        }
コード例 #8
0
        private void setup(SvgParser.SvgPath path)
        {
            //setupFields(path);
            paths = new List <SvgParser.SvgPath>();

            for (var it = path; it != null; it = it.next)
            {
                //rotated copies
                if (dbugSettings.makeVariations)
                {
                    addRotatedCopies(it);
                    if (dbugSettings.reverseClockwiseOrderCopies)
                    {
                        addRotatedCopies(it.ReversedPointsClone(), 1);
                    }
                    break; // only use the first path
                }

                paths.Add(it);
            }
        }
コード例 #9
0
ファイル: SVGCrosshatch.cs プロジェクト: melsov/SVGCrosshatch
    void CreateGenerator()
    {
        SVGViewBox viewBox = SCCSSParser.ParseViewBox(svgFullPath);
        CSSLookup  lookup  = SCCSSParser.Parse(svgFullPath);

        SvgParser.SvgPath plist = getSvgPath(svgFullPath);

        for (var it = plist; it != null; it = it.next)
        {
            lookup.updatePath(it);
        }

        SCSvgFileData _svgFileData = new SCSvgFileData()
        {
            isYAxisInverted = yAxisInverted
        };
        StripeFieldConfig stripeFieldConfig = FindObjectOfType <StripeFieldConfig>();
        StripedPathSet    stripedPathSet    = new StripedPathSet(plist, stripeFieldConfig, _svgFileData);

        //
        // Configure generator
        //
        if (generatorType == GeneratorType.Crosshatch)
        {
            var crosshatchGenerator = new SCCrosshatchGenerator(machineConfig, new HatchConfig(), _svgFileData, viewBox, _generatorConfig);
            crosshatchGenerator.UsePathSet(stripedPathSet);
            generator = crosshatchGenerator;
        }
        else if (generatorType == GeneratorType.Triangles)
        {
            var pixelTree = bitMapPointGenerator.getPixelTriTree();
            //if (ShouldMeshPixelTree)
            //    pixelTreeDebugDisplay.GetComponent<MeshFilter>().mesh = pixelTree.getMesh();

            var pointSetGenerator = new SCTriangleCrosshatchGenerator(
                machineConfig,
                _generatorConfig,
                pixelTree,
                bitMapPointGenerator);

            generator = pointSetGenerator;
        }
        else
        {
            SCTSPCrosshatchGenerator tspGenerator;
            if (useBitMapPointGenerator)
            {
                tspGenerator = new SCTSPCrosshatchGenerator(machineConfig, bitMapPointGenerator.inputImageBox, _generatorConfig);
                tspGenerator.SetTSPPointSets(bitMapPointGenerator.getPoints());

                tspGenerator.BaseFileName = Path.GetFileNameWithoutExtension(bitMapPointGenerator.bmapName);
            }
            else
            {
                List <Vector2f> points;
                tspGenerator = new SCTSPCrosshatchGenerator(machineConfig, viewBox, _generatorConfig);
                points       = stripedPathSet.AllPathsToPoints();
                tspGenerator.AddPoints(points);
            }

            generator = tspGenerator;
        }
    }
コード例 #10
0
 public static List <Vector2f> GetPointList(SvgParser.SvgPath path, bool appendFirstPointIfClosed = true)
 {
     return(Enumerable.ToList(GetPoints(path, appendFirstPointIfClosed)));
 }
コード例 #11
0
        //public static CPoint2D CPointAt(SvgParser.SvgPath path, int i) {
        //    return new CPoint2D(path.pts[i * 2], path.pts[i * 2 + 1]);
        //}

        public static int PointCount(SvgParser.SvgPath path)
        {
            return(path.npts + (path.closed ? 1 : 0));
        }
コード例 #12
0
 public static Vector2f PointAt(SvgParser.SvgPath path, int i)
 {
     return(new Vector2f(path.pts[i * 2], path.pts[i * 2 + 1]));
 }
コード例 #13
0
 public void display(SvgParser.SvgPath path)
 {
     displayPoints(PathToVector.GetPointList(path));
 }