Closed IonSwitz closed 10 years ago
To try out the new addVertexInConvexShape method, try:
var maxNum:Number = 1000.0;
for ( var i:int = maxNum-1; i >= 0; i-- )
{
var lerp:Number = Number(i) / maxNum;
var px:Number = 200 + 500 * Math.cos(Math.PI * 2 * lerp);
var py:Number = 200 + 500 * Math.sin(Math.PI * 2 * lerp);
fill.addVertexInConvexShape(px, py, 0xFFFF00);
// fill.addVertex(px, py, 0xFFFF00);
}
Toggle between addVertex and addVertexInConvexShape to notice the differences.
Like the new "addVertexInConvexShape()". That'll become quite handy in the near future. Thanks mate!
Thank you. In its current state, I believe the benefits will only be useful ( or even work at all) when you make one convex shape per fill. So if you have two circles of the ones I made above, I would suggest putting it into two separate Fills, not one Fill with multiple areas, so to speak.
It's still not a super fast method, the triangulate method still uses a bit of CPU, but it is a lot better without the convertToSimple code path. I haven't tried this for a lot of shapes, so please play with it, when you have the time.
It might be unusable in practical cases, I have very few of those, unfortunately, merely my own "fake" tests :)
A much faster alternative to Fill.addVertexInConvexShape would be the 'TriangleFan' primitive. This primtive assumes your shape has a single vertex at 0,0 - then each subsequent vertex forms a 'shell' surrounding it.
@jonathanrpace
I have now checked in three separate fixes in one big check in, and I want to apologize for not keeping the check ins separate.
The three things are:
1 - Adding the ability to call validateNow() when preparing shapes, to prepare the geometry, so not all calculations have to be made during render() 2 - Adding a faster addVertex-variant to Fill: addVertexInConvexShape works like addVertex, but allows a user to bypass the very expensive convertToSimple method when the user knows that the Fill is well ordered and convex. 3 - Cleaning up the brand new drawPath and drawGraphicsData APIs, moving them all to the GraphicsEx class. The reasoning behind this is that they require a bunch of Flash class imports, for functionality that is not always desired, so to keep the imports lean, I've added them to the GraphicsEx class.
Now, I am normally not this disorganized, and I am really sorry for this mess, but I hope the code is usable and reasonable.