/// <param name="celAlphaMasks">Fill with masks created from Cels</param> /// <param name="allMasks">Fill with all created masks</param> public void RegenerateAlphaMask() { masks.TryRemoveBaseFallBack(); // <- it is about to be regenerated // If this frame has a single sprite-containing Cel, generate it directly if (firstLayer != null && firstLayer.next == null) { Mask mask = new Mask { data = firstLayer.spriteRef.ResolveRequire().GetAlphaMask(), isGeneratedAlphaMask = true, }; masks.Add(new TagSet(), mask); } else // ... Otherwise, try to create a mask merged from the frame's layers { List <MaskData> layerMasks = new List <MaskData>(); foreach (var cel in layers) { MaskData maskData = cel.spriteRef.ResolveRequire().GetAlphaMask(); if (maskData.Width != 0 && maskData.Height != 0) { layerMasks.Add(maskData); } } Rectangle maxBounds = Rectangle.Empty; foreach (var maskData in layerMasks) { maxBounds = RectangleExtensions.UnionIgnoreEmpty(maxBounds, maskData.Bounds); } Mask mask = new Mask() { isGeneratedAlphaMask = true }; mask.data = new MaskData(maxBounds); foreach (var layerMask in layerMasks) { Debug.Assert(!Asserts.enabled || mask.data.Bounds.Contains(layerMask.Bounds)); mask.data.SetBitwiseOrFrom(layerMask); } masks.Add(new TagSet(), mask); } }