public MediumMeshStripe Merge(MediumMeshStripe stripe) { _bottomLeft = new Int2(_bottomLeft.X, stripe._bottomLeft.Y); _bottomRight = new Int2(_bottomRight.X, stripe._bottomRight.Y); NeedToCoverBottom = stripe.NeedToCoverBottom; return(this); }
private void PrepareData(Sprite sprite) { for (int y = _yMax - 1; y >= _yMin; y--) { for (int x = _xMin; x < _xMax; x++) { if (sprite.texture.GetPixel(x, y).a > 0.0f) { var stripe = new MediumMeshStripe(_size, new Int2(x, y)); if (!stripe.NeedToCoverTop && (y + 1 >= _yMax || sprite.texture.GetPixel(x, y + 1).a <= 0.0f)) { stripe.NeedToCoverTop = true; } if (!stripe.NeedToCoverBottom && (y - 1 <= _yMin || sprite.texture.GetPixel(x, y - 1).a <= 0.0f)) { stripe.NeedToCoverBottom = true; } x++; while (sprite.texture.GetPixel(x, y).a > 0.0f && x < _xMax) { stripe.SetEnd(new Int2(x, y)); if (!stripe.NeedToCoverTop && sprite.texture.GetPixel(x, y + 1).a <= 0.0f) { stripe.NeedToCoverTop = true; } if (!stripe.NeedToCoverBottom && sprite.texture.GetPixel(x, y - 1).a <= 0.0f) { stripe.NeedToCoverBottom = true; } x++; } var merged = false; for (int i = 0; i < _stripes.Count; i++) { if (_stripes[i].MergeableToTheBottom(stripe)) { _stripes[i] = _stripes[i].Merge(stripe); merged = true; break; } } if (!merged) { _stripes.Add(stripe); } } } } }
public bool MergeableToTheBottom(MediumMeshStripe stripe) { return(_bottomLeft.X == stripe._bottomLeft.X && _bottomRight.X == stripe._bottomRight.X && _bottomLeft.Y - stripe._topLeft.Y == 1); }