Esempio n. 1
0
                private static int[] GetColorMapUV(float temp, float rain, int pixel_range = 0, bool rich = false, float warmer = 0.0f, float wetter = 0.0f)
                {
                    int[]  uv = new[] { 0, 0 };
                    double uv_x = 0.0f, uv_y = 0.0f;

                    if (temp > 1)
                    {
                        temp = 1;
                    }
                    if (temp < 0)
                    {
                        temp = 0;
                    }
                    if (rain > 1)
                    {
                        rain = 1;
                    }
                    if (rain < 0)
                    {
                        rain = 0;
                    }
                    bool rangeEroor = true;

                    while (rangeEroor)
                    {
                        if (!Program.smooth)
                        {
                            var theta = StaticRandom.NextDouble() * 360;
                            var d     = StaticRandom.NextDouble() * pixel_range - pixel_range / 2;
                            uv_x = temp + (warmer / 256f) + (d / 256f) * Math.Cos(theta * Math.PI / 360); uv_y = temp * rain + (wetter / 256f) + (d / 256f) * Math.Sin(theta * Math.PI / 360);
                        }
                        else
                        {
                            uv_x = temp + (warmer / 256f); uv_y = temp * rain + (wetter / 256f);
                        }
                        if (uv_x >= 1)
                        {
                            uv_x = 1;
                        }
                        if (uv_x <= 0)
                        {
                            uv_x = 0;
                        }
                        if (uv_y >= 1)
                        {
                            uv_y = 1;
                        }
                        if (uv_y <= 0)
                        {
                            uv_y = 0;
                        }
                        if (uv_x >= uv_y)
                        {
                            rangeEroor = false;
                        }
                    }

                    if (!rich)
                    {
                        uv_x = 1 - uv_x;
                        uv_y = 1 - uv_y;
                    }
                    uv[0] = (int)Math.Floor(uv_x * 16);
                    uv[1] = (int)Math.Floor(uv_y * 16);
                    return(uv);
                }
Esempio n. 2
0
                private int[] GetUV(BlockInfo _info, string directoryPath)
                {
                    var uv   = new int[] { 0, 0 };
                    var t    = GetTexture(_info);
                    var path = "";

                    if (Program.version >= 1.13)
                    {
                        var m = t.Path.ToList();
                        m.RemoveAt(5);
                        path = String.Join(null, m.ToArray());
                    }
                    if (t.Params != null && t.Params.Contains("ColorMap")) //ColorMap
                    {
                        var pars = t.Params.Split(' ');
                        if (pars.Length != 5 && pars[0] != "ColorMap")
                        {
                            uv = GetColorMapUV(Program.temp, Program.rain, 0, false, 0);
                        }
                        else
                        {
                            uv = GetColorMapUV(Program.temp, Program.rain, int.Parse(pars[1]), bool.Parse(pars[2]), float.Parse(pars[3]), float.Parse(pars[4]));
                        }
                    }
                    else //Default
                    {
                        bool textureError = true;
                        if (Program.smooth)
                        {
                            try
                            {
                                Bitmap compare = new Bitmap(directoryPath + "\\textures\\" + path.Replace("/", "\\") + ".png");
                                for (int mh = 0; mh < compare.Size.Height; mh++)
                                {
                                    for (int mw = 0; mw < compare.Size.Width; mw++)
                                    {
                                        if (compare.GetPixel(mh, mw).A > 8)
                                        {
                                            uv[0] = mh; uv[1] = mw; break;
                                        }
                                    }
                                    if (uv[0] > 0 && uv[1] > 0)
                                    {
                                        break;
                                    }
                                }
                            }
                            catch
                            {
                                Current.Error("Texture: " + t.Path + ".png Not Found", false);
                            }
                        }
                        else
                        {
                            while (textureError)
                            {
                                uv[0] = (int)Math.Floor(StaticRandom.NextDouble() * 16);
                                uv[1] = (int)Math.Floor(StaticRandom.NextDouble() * 16);
                                try
                                {
                                    Bitmap compare = new Bitmap(System.Windows.Forms.Application.StartupPath + "\\textures\\" + path.Replace("/", "\\") + ".png");
                                    textureError = (compare.GetPixel((int)uv[0], (int)uv[1]).A <= 8);
                                }
                                catch
                                {
                                    Current.Error("Texture: " + t.Path + ".png Not Found", false);
                                }
                            }
                        }
                    }
                    return(uv);
                }