This is the crux of the code. I'm using Krypton for light effects but I'm having some issues getting the two to behave - the 'tiles' in the image below are created from a Texture2D, using an Earclip Decompressor to work out a poly and convert it to fixtures.
Works really well, and I was hoping it'd be relatively simple to grab the list of Vertices it produces during that process and use them to create a 'ShadowHull' for each tile, which is what Krypton uses to block out light sources.
It's sort of working, but I'm getting some weird behaviour, as seen in the image.
My light source is hidden by certain parts of the poly, and not others.
Also, no debug ShadowHull debug is being drawn, even though the light's reacting to one. Doing some simple tests, I think that's because Debug only draws ShadowHulls when the vertices it gets fed are clockwise. I'm not sure, but I think
the verts I'm getting from the Farseer Earclip aren't. I don't think they're counter-clockwise either, because otherwise a simple reverse() of the list should draw a ShadowHull, right?
So I'm left thinking that my Verts are ordered left-to-right.. or something. I'm not sure.
Any advice? Here's some code for what's happening:
public List<Vertices> getVertsFromTexture(String sTexture, Vector2 vSize)
//load texture that represents the body
Texture2D polygonTexture = getTextureFromSpriteSheet(spriteSheet, sTexture);
//Create an array to hold the data from the texture
uint data = new uint[polygonTexture.Width * polygonTexture.Height];
//Transfer the texture data to the array
//Find the vertices that makes up the outline of the shape in the texture
Vertices verts = PolygonTools.CreatePolygon(data, polygonTexture.Width, polygonTexture.Height, false);
//Since it is a concave polygon, we need to partition it into several smaller convex polygons
List<Vertices> _list = EarclipDecomposer.ConvexPartition(verts);
I'm then creating my ShadowHulls based on that _list, as discussed:
for (int i = 0; i < _list.Count; i++)
Vector2 polygon = _list[i].ToArray();
if (polygon != null && polygon.Length >= 3)
var _hull = ShadowHull.CreateConvex(ref polygon);
_hull.Position = vPosition;
_hull.Angle = fAngle;
I'm hoping I'm just doing something really stupid here... any idea what that might be?
(some of this a crosspost from Krypton ;)