Ejemplo n.º 1
0
        public virtual void PaintToTexture2D(PlaytimePainter pntr, BrushConfig br, StrokeVector st)
        {
            Vector2 delta_uv = st.uvTo - st.uvFrom;

            if (delta_uv.magnitude > (0.2f + st.avgBrushSpeed * 3))
            {
                delta_uv = Vector2.zero;                                                     // This is made to avoid glitch strokes on seams
            }
            else
            {
                st.avgBrushSpeed = (st.avgBrushSpeed + delta_uv.magnitude) / 2;
            }


            float alpha = Mathf.Clamp01(br.speed * (Application.isPlaying ? Time.deltaTime : 0.1f));


            bool worldSpace = pntr.NeedsGrid();

            var id = pntr.ImgData;

            float uvDist    = (delta_uv.magnitude * id.width * 8 / br.Size(false));
            float worldDist = st.Delta_WorldPos.magnitude;

            float steps = (int)Mathf.Max(1, worldSpace ? worldDist : uvDist);

            delta_uv /= steps;
            Vector3 deltaPos = st.Delta_WorldPos / steps;

            st.uvFrom  += delta_uv;
            st.posFrom += deltaPos;


            Blit_Functions.PaintTexture2DMethod pluginBlit = null;

            if (pluginBlit == null && tex2DPaintPlugins != null)
            {
                foreach (Blit_Functions.PaintTexture2DMethod p in tex2DPaintPlugins.GetInvocationList())
                {
                    if (p(st, alpha, id, br, pntr))
                    {
                        pluginBlit = p;
                        break;
                    }
                }
            }

            if (pluginBlit == null)
            {
                pluginBlit = Blit_Functions.Paint;
                pluginBlit(st, alpha, id, br, pntr);
            }


            for (float i = 1; i < steps; i++)
            {
                st.uvFrom  += delta_uv;
                st.posFrom += deltaPos;
                pluginBlit(st, alpha, id, br, pntr);
            }



            pntr.AfterStroke(st);
        }