Пример #1
0
        public static void Silhouette(Spline[] splines, MatrixWorld strokeMatrix, MatrixWorld dstMatrix)
        /// Fills all pixels within closed spline with 1, and all outer pixels with 0
        /// Pixels directly in the spline are filled with 0.5
        /// Requires the matrix with line stroked. StrokeMatrix and DstMatrix could be the same
        {
            DebugGizmos.Clear("Slhuette");

            if (strokeMatrix != dstMatrix)
            {
                dstMatrix.Fill(strokeMatrix);
            }
            //and then using dst matrix only

            CoordRect rect = dstMatrix.rect;
            Coord     min = rect.Min; Coord max = rect.Max;

            for (int x = min.x; x < max.x; x++)
            {
                for (int z = min.z; z < max.z; z++)
                {
                    int pos = (z - rect.offset.z) * rect.size.x + x - rect.offset.x;

                    if (dstMatrix.arr[pos] < 0.01f)                             //free from stroke and fill
                    {
                        Vector2D pixelPos = (Vector2D)dstMatrix.PixelToWorld(x, z);

                        bool handness = Spline.Handness(splines, pixelPos) >= 0;

                        DebugGizmos.DrawDot("Slhuette", (Vector3)pixelPos, 6, color: handness ? Color.red : Color.green, additive: true);

                        dstMatrix.PaintBucket(new Coord(x, z), handness ? 0.75f : 0.25f);
                    }
                }
            }
        }