// Attention: p needs to be 2D (X/Y-Plane)
        void applyUV(Vector3[] vts, ref Vector2[] uvArray, int index, int count, CGMaterialSettings mat, Bounds bounds)
        {
            float u, v;
            float w = bounds.size.x;
            float h = bounds.size.y;

            float mx = bounds.min.x;
            float my = bounds.min.y;

            float fx = mat.UVScale.x;
            float fy = mat.UVScale.y;

            switch (mat.KeepAspect)
            {
            case CGKeepAspectMode.ScaleU:
                float sw = w * mat.UVScale.x;
                float sh = h * mat.UVScale.y;
                fx *= sw / sh;
                break;

            case CGKeepAspectMode.ScaleV:
                float sw1 = w * mat.UVScale.x;
                float sh1 = h * mat.UVScale.y;
                fy *= sh1 / sw1;
                break;
            }

            if (mat.UVRotation != 0)
            {
                float uvRotRad = (mat.UVRotation) * Mathf.Deg2Rad;
                float sn = Mathf.Sin(uvRotRad);
                float cs = Mathf.Cos(uvRotRad);
                float ox, oy;
                float fx2 = fx * 0.5f;
                float fy2 = fy * 0.5f;
                for (int i = 0; i < count; i++)
                {
                    u  = (vts[i].x - mx) / w * fx;
                    v  = (vts[i].y - my) / h * fy;
                    ox = u - fx2;
                    oy = v - fy2;
                    u  = (cs * ox - sn * oy + fx2) + mat.UVOffset.x;
                    v  = (sn * ox + cs * oy + fy2) + mat.UVOffset.y;

                    uvArray[i + index] = (mat.SwapUV) ? new Vector2(v, u) : new Vector2(u, v);
                }
            }
            else
            {
                for (int i = 0; i < count; i++)
                {
                    u = mat.UVOffset.x + (vts[i].x - mx) / w * fx;
                    v = mat.UVOffset.y + (vts[i].y - my) / h * fy;
                    uvArray[i + index] = (mat.SwapUV) ? new Vector2(v, u) : new Vector2(u, v);
                }
            }
        }
 public override void Reset()
 {
     base.Reset();
     StartCap                = CGYesNoAuto.Auto;
     EndCap                  = CGYesNoAuto.Auto;
     ReverseTriOrder         = false;
     GenerateUV              = true;
     m_StartMaterialSettings = new CGMaterialSettings();
     m_EndMaterialSettings   = new CGMaterialSettings();
 }
Example #3
0
        // Attention: p needs to be 2D (X/Y-Plane)
        void applyUV(Vector3[] vts, ref Vector2[] uvArray, int index, int count, Bounds bounds, CGMaterialSettings mat)
        {
            float u, v;
            float w = bounds.size.x;
            float h = bounds.size.y;

            float mx = bounds.min.x;
            float my = bounds.min.y;

            float fx = mat.UVScale.x;
            float fy = mat.UVScale.y;

            switch (mat.KeepAspect)
            {
                case CGKeepAspectMode.ScaleU:
                    float sw = w * mat.UVScale.x;
                    float sh = h * mat.UVScale.y;
                    fx *= sw / sh;
                    break;
                case CGKeepAspectMode.ScaleV:
                    float sw1 = w * mat.UVScale.x;
                    float sh1 = h * mat.UVScale.y;
                    fy *= sh1 / sw1;
                    break;
            }

            if (mat.UVRotation != 0)
            {
                float uvRotRad = (mat.UVRotation) * Mathf.Deg2Rad;
                float sn = Mathf.Sin(uvRotRad);
                float cs = Mathf.Cos(uvRotRad);
                float ox, oy;
                float fx2 = fx * 0.5f;
                float fy2 = fy * 0.5f;
                for (int i = 0; i < count; i++)
                {
                    u = (vts[i].x - mx) / w * fx;
                    v = (vts[i].y - my) / h * fy;
                    ox = u - fx2;
                    oy = v - fy2;
                    u = (cs * ox - sn * oy + fx2) + mat.UVOffset.x;
                    v = (sn * ox + cs * oy + fy2) + mat.UVOffset.y;

                    uvArray[i + index] = (mat.SwapUV) ? new Vector2(v, u) : new Vector2(u, v);

                }
            }
            else
            {
                for (int i = 0; i < count; i++)
                {
                    u = mat.UVOffset.x + (vts[i].x - mx) / w * fx;
                    v = mat.UVOffset.y + (vts[i].y - my) / h * fy;
                    uvArray[i + index] = (mat.SwapUV) ? new Vector2(v, u) : new Vector2(u, v);
                }
            }



        }
Example #4
0
 public override void Reset()
 {
     base.Reset();
     StartCap = CGYesNoAuto.Auto;
     EndCap = CGYesNoAuto.Auto;
     ReverseTriOrder = false;
     GenerateUV = true;
     m_StartMaterialSettings = new CGMaterialSettings();
     m_EndMaterialSettings = new CGMaterialSettings();
 }