예제 #1
0
        private int[] calcEmptySpace(ref ITexture inputTex)
        {
            var   origColors     = inputTex.GetPixelColors(LayerMipmapSlice.Mip0);
            var   expectedColors = new Color[origColors.Length];
            Size3 size           = inputTex.Size;

            int[] ping = new int[origColors.Length];
            int[] pong = new int[origColors.Length];



            for (int i = 0; i < 127; i++)
            {
                foreach (var coord in size)
                {
                    int curIndex = getIndex(coord, size);
                    if (origColors[curIndex].Alpha > 0)
                    {
                        ping[curIndex] = 0;
                    }
                    else
                    {
                        int min = 126;
                        for (int x = -1; x <= 1; x++)
                        {
                            for (int y = -1; y <= 1; y++)
                            {
                                for (int z = -1; z <= 1; z++)
                                {
                                    min = Math.Min(min, getPixelValue(coord + new Size3(x, y, z), size, pong));
                                }
                            }
                        }
                        ping[curIndex] = min + 1;
                    }
                }

                int[] temp = ping;
                ping = pong;
                pong = temp;
            }

            return(pong);
        }
        private int[] CalcValues(ITexture tex)
        {
            var origColors = tex.GetPixelColors(LayerMipmapSlice.Mip0);
            var size       = tex.Size;

            int[] ping = new int[origColors.Length];
            int[] pong = new int[origColors.Length];

            // transfer data into ping
            for (int i = 0; i < origColors.Length; ++i)
            {
                ping[i] = origColors[i].Alpha > 0 ? 0 : 255;
            }

            for (int i = 0; i < 255; ++i)
            {
                foreach (var coord in size)
                {
                    var idx = GetIndex(coord, size);
                    if (ping[idx] == 0)
                    {
                        pong[idx] = 0;
                        continue;
                    }

                    int min = 255;
                    min = Math.Min(min, GetPixelValue(coord - new Size3(1, 0, 0), size, ping));
                    min = Math.Min(min, GetPixelValue(coord + new Size3(1, 0, 0), size, ping));
                    min = Math.Min(min, GetPixelValue(coord - new Size3(0, 1, 0), size, ping));
                    min = Math.Min(min, GetPixelValue(coord + new Size3(0, 1, 0), size, ping));
                    min = Math.Min(min, GetPixelValue(coord - new Size3(0, 0, 1), size, ping));
                    min = Math.Min(min, GetPixelValue(coord + new Size3(0, 0, 1), size, ping));

                    pong[idx] = Math.Min(min + 1, 255);
                }

                int[] temp = ping;
                ping = pong;
                pong = temp;
            }

            return(ping);
        }