DrawTriangles picnic

Having another look at the powerful drawTriangles method while playing with my shiny new CS5 reminded me that a while ago I was planning to do a full-blown cloth-like effect utilizing this little vintage experiment.
However, with the introduction of native 3D and numerous drawing API enhancements into Flash it is now possible to do this in a lot less less cumbersome fashion than before.

Consequently, please take a look at this wholesome virtual picnic tablecloth:

The real star of the show here is the drawTriangles method, which is rendering 800 textured triangles based on vertex, index and UV information supplied by Vectors (the grid fades in and out to show the mesh structure).
The wavy movement as well as the dark/light patches are achieved with a continuously redrawn perlinNoise map: it functions as sort of a height-map for the vertices, and it's also scaled and blended with the texture to generate the dark/light areas corresponding to the height information.

One obvious way to improve the performance of this experiment would be to use fixed-size Vectors instead of dynamically changing ones.
I actually started off with that approach, but ran into mysterious problems trying to fill the Vectors with the correct data, and never quite managed to get the UV information come back the right way.
I have some theories regarding possible causes, but I eventually decided to move on for now and figure this problem out another day. ;)

And now the (hopefully sufficiently commented) source:

One Response to DrawTriangles picnic

Leave Your Mark

Recent Posts