Friday, June 5, 2009

Flash Player 10 Drawing API






Introduction

Flash Player 10 expands greatly on the drawing API in ActionScript, more so than any other version of the Flash Player since the initial introduction of the drawing API in Flash Player 6. New features include:

  • Support for Pixel Bender (Hydra) filters
  • Use of vectors (typed arrays) for improved throughput and use of memory
  • Support for non-zero winding rules
  • An API for drawing triangles with support for 3D perspective rendering
  • Drawing API data objects
Though the older APIs still exist, and to much of an extent work with the newer APIs, these new enhancements mostly render those old APIs obsolete. This is especially the case with the IGraphicsData objects which serve as data representations of all the available APIs.

New Graphics Methods

Drawing APIs are located within the Graphics class. Display objects which support the drawing APIs contain a Graphicsinstance from which these APIs are called. As of Flash Player 9, these APIs include:

  • beginBitmapFill()
  • beginFill()
  • beginGradientFill()
  • clear()
  • curveTo()
  • drawCircle()
  • drawEllipse()
  • drawRect()
  • drawRoundRect()
  • endFill()
  • lineGradientStyle()
  • lineStyle()
  • lineTo()
  • moveTo()

These remain active and unchanged. Flash Player 10 introduces the following new Graphics APIs:

  • beginShaderFill()
  • drawGraphicsData()
  • drawPath()
  • drawTriangles()
  • lineBitmapStyle()
  • lineShaderStyle()

Of the new APIs, lineBitmapStyle sticks out a little as it fills a hole in the older API set for strokes.

The beginShaderFill and lineShaderStyle APIs are similar, but these utilize a new feature in Flash Player 10, support for Pixel Bender (code named Hydra) filters.

UV mapping is a method for texturing objects. It relies on two values, a U horizontal (x) and a V vertical (y). Rather than being based on pixel values, they're based on percentages, where 0 U and 0 V is the top left of an image and 1 U and 1 V is the bottom right.

Vectors of a triangle can be given UV coordinates to associate themselves with the respective locations on an image.


  • Point A UV: (.25, .33)
  • Point B UV: (.25, .66)
  • Point C UV: (1, .66)

As the triangle is transformed in space, the image is mapped to the triangle based on those coordinates.



You can imagine how well this approach will work with 3D models drawn in Flash. No longer will complicated matrix calculations be required to transform a bitmap to a pseudo-3D plane. Now UV values can be set once and work consistently throughout the lifetime of a model.

Conclusion

With all of the new drawing API features in Flash Player 10, it might take a while to get caught up. Having 3D (or 2.5D) support is a big one, and the drawing API has been updated to be a part of that - a part outside of the DisplayObjectintegration (not covered here).

Other drawing API features challenge you to rethink how you draw images dynamically in Flash Player. WithIGraphicsData objects, you now have a standardized data format for maintaining and reusing dynamic drawings whose usage is completely different from that of the older APIs. Existing systems may need to be ported, but the benefit may be well worth it.

One thing is for sure, with 3D, Pixel Bender integration, and the other enhancements, it's certainly an exciting time for Flash Player on the visual front. I'm excited to see how these features will be used to create totally new and compelling content.

If you want to know more about this,use the following link.

http://www.senocular.com/flash/tutorials/flash10drawingapi/

If you want to get it,use the following link.

http://get.adobe.com/flashplayer/?promoid=DXLUJ

No comments:

Post a Comment