Пример #1
0
        private static int ColourPixels(ref Color[] cols, IBrush brush, Vector2[] triangleUVs, Vector3[] triangleVerts, Transform modelTransform, Rect uvRect, Rect bigUVRect, int texWidth, int texHeight)
        {
            int pixels = 0;

            int xOffset = Mathf.FloorToInt((uvRect.xMin - bigUVRect.xMin) * texWidth);
            int yOffset = Mathf.FloorToInt((uvRect.yMin - bigUVRect.yMin) * texHeight);
            int width   = Mathf.FloorToInt(uvRect.width * texWidth);
            int height  = Mathf.FloorToInt(uvRect.height * texHeight);

            int colsStride = Mathf.FloorToInt(bigUVRect.width * texWidth);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    int i = (y + yOffset) * colsStride + x + xOffset;

                    Vector2 texPos = new Vector2(uvRect.xMin + (float)x / texWidth, uvRect.yMin + (float)y / texHeight);

                    Vector3 bary = GetBarycentricCoordFromUV(texPos, triangleUVs, triangleVerts);
                    float   baryMag = bary.magnitude;
                    float   min = -0.1f, max = 1.1f, maxMag = 1.1f;
                    if (!(bary.x < min || bary.y < min || bary.z < min || bary.x > max || bary.y > max || bary.z > max || baryMag > maxMag))
                    {
                        Vector3 modelPosOfUV = bary.x * triangleVerts[0] + bary.y * triangleVerts[1] + bary.z * triangleVerts[2];
                        Vector3 worldPosOfUV = modelTransform.TransformPoint(modelPosOfUV);
                        if (brush.IsInsideBrushStroke(worldPosOfUV))
                        {
                            cols[i] = brush.Colour;
                            pixels++;
                        }
                    }
                }
            }
            return(pixels);
        }