public void Optimise() { Rectangle extents = heightmapData.FindTrimBounds(DefaultHeight); if (heightmapData.Bounds != extents) { heightmapData = heightmapData.CopyWithNewBounds(extents, DefaultHeight); } }
/// <summary>Convert color data to a trimmed 1-bit mask</summary> public static MaskData CreateMask(this Data2D <Color> data, Color color, bool inverse = false) { Rectangle trimBounds = data.FindTrimBounds(color, inverse); // TODO: Avoid this copy... Data2D <Color> trimData = data.CopyWithNewBounds(trimBounds); MaskData mask = new MaskData(trimData.Bounds); for (int y = trimData.StartY; y < trimData.EndY; y++) { for (int x = trimData.StartX; x < trimData.EndX; x++) { mask[x, y] = ((trimData[x, y] == color) != inverse); } } return(mask); }
// TODO: This is disabled at the moment, because it will probably make authoring difficult... // (Also it's less of a big deal than physics heightmaps) public void OptimiseForShadowReceiver() { if (heightmapData.Data == null) { return; // <- nothing to optimise } Debug.Assert(heightmapData.Data.Length > 0); // <- Data2D should be enforcing this condition // See if we have a heightmap filled with just a single value: byte startValue = heightmapData.Data[0]; for (int i = 0; i < heightmapData.Data.Length; i++) { if (heightmapData.Data[i] != startValue) { goto hasMoreThanOneValue; } } // Convert to fixed-height: DefaultHeight = startValue; heightmapData = new Data2D <byte>(); return; hasMoreThanOneValue: Rectangle extents = heightmapData.FindTrimBoundsForShadowReceiver(); // Assert that we're shrinking (because if we expand, then we're adding in wrong data, due to DefaultHeight) Debug.Assert(extents.Left >= heightmapData.Bounds.Left); Debug.Assert(extents.Right <= heightmapData.Bounds.Right); Debug.Assert(extents.Top >= heightmapData.Bounds.Top); Debug.Assert(extents.Bottom <= heightmapData.Bounds.Bottom); if (heightmapData.Bounds != extents) { heightmapData = heightmapData.CopyWithNewBounds(extents, DefaultHeight); } }