public SurfacePolygons LoadItem(string name, object[] loadArgs) { Predicate <Color> isOpaque = null; if (loadArgs != null && loadArgs.Length == 1) { isOpaque = loadArgs[0] as Predicate <Color>; if (isOpaque == null) { if (loadArgs[0] is Color) { Color c = (Color)loadArgs[0]; isOpaque = delegate(Color color) { return(c.ToArgb() != color.ToArgb()); }; } } } if (isOpaque == null) { isOpaque = DefaultIsOpaque; } Surface surface = Cache <Surface> .GetItem(name); Vector2D[][] polygons = VertexHelper.CreateRangeFromBitmap(new SurfaceBitmap(surface, isOpaque)); polygons = VertexHelper.ReduceRange(polygons); Vector2D offset = VertexHelper.GetCentroidOfRange(polygons); polygons = VertexHelper.CenterVertexesRange(polygons); return(new SurfacePolygons(surface, polygons, offset)); }
public Sprite(Surface surface2) { this.surface = surface2; texture = new SurfaceGl(surface, true); texture.WrapS = WrapOption.Clamp; texture.WrapT = WrapOption.Clamp; //texture.MagFilter = MagnificationOption.GL_LINEAR; //texture.MinFilter = MinifyingOption.GL_LINEAR_MIPMAP_LINEAR; int blank = surface.TransparentColor.ToArgb(); bool[,] bitmap = new bool[surface.Width, surface.Height]; Color[,] pixels = surface.GetColors(new System.Drawing.Rectangle(0, 0, surface.Width, surface.Height)); for (int x = 0; x < bitmap.GetLength(0); ++x) { for (int y = 0; y < bitmap.GetLength(1); ++y) { bitmap[x, y] = !(pixels[x, y].A == 0 || pixels[x, y].ToArgb() == blank); } } vertexes = VertexHelper.CreateRangeFromBitmap(bitmap); Console.WriteLine("Before {0}", GetCount); vertexes = VertexHelper.ReduceRange(vertexes, 1); vertexes = VertexHelper.ReduceRange(vertexes, 2); vertexes = VertexHelper.ReduceRange(vertexes, 3); Console.WriteLine("After {0}", GetCount); vertexes = VertexHelper.SubdivideRange(vertexes, 10); Console.WriteLine("Subdivide {0}", GetCount); offset = VertexHelper.GetCentroidOfRange(vertexes); vertexes = VertexHelper.CenterVertexesRange(vertexes); }