Simple Shape Extruder using FP10 Drawing API

Tuesday, March 10th, 2009

My SoTexty 3d Text Effect demo uses a Class I wrote a which takes a polygon in the form of a Vector of Points, and extrudes it into a 3dMesh of sorts.

Click the image for a demo:

The colors are random, as is the outline of the shapes... Refresh if the result doesn't please your aesthetics ;)

Here's the snippet that uses the class:

Actionscript:
  1. protected function testExtrude():void{
  2.     var points:Vector.<Point>=createCircularPath(new Point(300,300),200,250,50);
  3.     var negative_shape_points:Vector.<Point>=createCircularPath(new Point(300,300),90,190,40);
  4.     var points2:Vector.<Point>=createCircularPath(new Point(550,550),80,20,20);
  5.     var points3:Vector.<Point>=createCircularPath(new Point(300,650),80,20,20);
  6.     var points4:Vector.<Point>=createCircularPath(new Point(650,300),80,20,20);
  7.     _extruded=SimpleShapeExtruderDrawAPI.createExtrudedShapeFromPoints(100,
  8.                                                                 Vector.<Vector.<Point>>([points,points2,points3,points4]),
  9.                                                                 Vector.<Vector.<Point>>([negative_shape_points]),
  10.                                                                 Math.random()*0xFFFFFF,0xFF000000+Math.random()*0xFFFFFF
  11.                                                                 );
  12.     _extruded.adjustCenter(300,300);
  13.     _extruded.x=300;
  14.     _extruded.y=300;
  15.     addChild(_extruded);
  16.     addEventListener(Event.ENTER_FRAME,rotateExtruded);
  17. }

Instead of Triangulating the shape, I used a "shortcut" which I learned a while back from Den Ivanov. The Mesh contains a "front" and a "back" which are a triangle pair, who use the "original" shape as their material:

The large red square with the diagonal represents the "front", the "back" is identical. A curiosity about this screenshot is that the "filled triangles" are z-sorted correctly, however, there are some issues with the outlines. Meh.

The code accepts a Vector of Positive and Negative "shapes", which are rendered into a BitmapData and used as a "Material" by the 3DMesh. Here is a screenshot of what the "rendered" material looks like:

The filled box on the right is the "material" used by the extruded sides.

Notice the white space surrounding the shape. An annoying issue I ran into was that the "front" and the "back" had unwanted artifacts when using a "1 to 1" ratio "material". The UV mapping would go from 0 to 50% horizontally, and 0 to 100% vertically. For some reason, the edges (when rotated) would render an arbitrary "line" on any of the four sides.

The solution was to add white space, and grab the material using "less precise" percentages, which unfortunately results in some "spaces" on the edges of the "shape" material and the extruded side triangles. Another Meh.

It's not perfect, but I figured the code might be fun to play with...

Download the flex project here

(requires Flex SDK 3.2 or higher)

I’ll be talking Text Effects at FITC Amsterdam 2009

Thursday, October 30th, 2008

I got an email earlier this week from Shawn Pucknell Confirming that I'd been accepted as a speaker for FITC Amsterdam this year, but I didn't really believe it until I saw my pretty face on the website.

I spoke about Text Effects with AS3 at MultiMania when AS3 was still relatively new. This time around, I will be taking my Text Effects arsenal further with the possibilities provided by flashplayer10. I've got a TON of ideas, I guess the challenge will be to fit it all into one cohesive presentation. I can guarantee that it's gonna be cool though, I've been planning V2 of the Text Effects presentation for a long time now :)

More info : Speaker profile and Presentation Write up

Can't wait! See you there!

The Flash Bar!

Thursday, October 30th, 2008

I must have walked past this a few hundred times without noticing it. Indeed, 'tis not an exuberant establishment, but all the same, this morning I was astonished to find myself face to face:
with :pirate: THE FLASH BAR :pirate: :

picture of the facade of flash bar in brussels

I'm sure the old geezer at the door wrote parts of the core flashplayer, and is asking the hesitant youth to recite some obscure low level code in exchange for admission into the bar...

Screw the Old Ship, The Flash bar :buttrock: IS HOTT :buttrock:

This epicenter of awesomeness is yours to experience just off Place Stephanie in Brussels :

View Larger Map

Since there is no "flash scene" to speak of in Brussels, I propose a monthly "Flash Geek Drinkers Club" meeting. Who's in?

Trying out fp10 3d features partII : Z sorting, truly simple shader, nested perspective

Wednesday, October 22nd, 2008

Continuing on with the basics, heres a few more tests. Just to clarify from last time, all of this is achieved using only the x,y,z, rotationX, rotationY and rotationZ properties of plain old Sprites. This is what I find so awesome about the new flashplayer10 as3 features.

Sure, the performance and rendering capabilites are no match for what developers have at their hands in games consoles etc. (this is nothing new or surprising). What I'm really digging is that anyone with a basic understanding of display object programming in as3 can jump into doing fairly cool 3d. Just grab your bag of flash tricks and take them to another dimension (har har ;) ). Seriously, everything works more or less exactly as I wanted / expected, and is a real pleasure to code. Reminds me of of the enthusiasm when I was learning to program with flash5 and 6. :thumbsup:

Anyway. Moving on, z-Sorting :.

screenshot of cube with simple z sorting

There is this ROCKING little method:

[Sprite].transform.getRelativeMatrix3D(parent).position.z;

Here's what it does:

  • In the case of the cube. I created a parent Sprite, called "cube".
  • In it, I created 6 nested Sprites with a square graphic. I moved, and rotated these into positions which constitute a cube.
  • Rotating the parent "cube" (with rotationX,Y and Z) results in what you see in "3) CubeTest".
  • To sort these sides, all I need to do is run the afore mentioned function, which returns the current z position of the nested clips.
  • With this knowledge, it just takes a simple loop to sort the display list. See an example here.

Simple shading:


screenshot of cube with simple z sorting and simple shading

Using that same Z value which I used to sort out the sides of the square, I just added a dark layer on top of each "side button". On every render, I set its trasparency equal to a proportionate value of Z and the maximum and minimum z (possible for the sides of the rotated cube). It's not phong or gouraud shading, but it'll fool the novice :) Again, a real "flash" feeling.

Same thing but with a bitmap material (read simple sprite).


screenshot of cube with simple z sorting, simple shading using bitmap materials

Nested Perspective:

No rocket science here either, just curious how changing the z of a nested clip would act out...


screenshot of nested perspective menu test

With a little more work, I think something like the Vaio10 menu could be achieved. Same goes for the cube menu above and the Pioneer Kuro Project menu.

As a matter of fact, I can think of several popular papervision menus which can be reproduced using very basic flashplayer 10 AS3 features. I'm guessing this is more than welcome news to the more "designer flashers" as opposed to the "programmer flashers" (who also get their share of new FP10 features, which I'll be exploring in upcoming posts). All good :)

As promised, here are the sources. This is a Flex project, in order to work with it (at the time of writing), just follow these simple steps:

  1. Download a nightly build of the Flex3 sdk (or gumbo) dating later than May. (more details)
  2. Copy the sdk into your flexbuilder sdks folder and create a Flexbuilder project, adjusting the preferences so that the compiler targets flashplayer10 and the new sdk. It's dead easy, see details here.

Again, here is the link to the test app

I would love to hear/see of anyone that decides to use this "test set up". Enjoy!

Trying out flash player 10 3d features

Thursday, October 16th, 2008

Nascom was kind enough to let me spend some work hours investigating the new features of flash player 10. Naturally the first step was to check out the 3d features. I built a quick "testing" environment. Each test is pretty self explanatory, but if that's not enough, I included some notes attached to each experiment in the flex app. Behold the first 3 tests (but install player 10 first)...

Be sure to drag the vanishing point...

basic flash player 10 3d behaviour

The frame rate is not bad, even with a ton of shapes:

basic flash player 10 3d performance test

Creating a cube... lookout papervision ;)

flash player 10 3d cube test with color materia

Ok, so the cube was not so impressive due to the "layered" nature of flash player10 3d. I'm convinced that through the "hackish" nature of the flash community, there will soon be enough "clever" implementations that will be small in filesize, but will fool the eye. Remember, these cubes can be created and tweened on the timeline... Here's a slightly more convincing "wireframe" version :


flash player 10 3d cube test with wireframe material

try out the flash player 10 3d test runner

More tests coming soon. I'll be posting the code as well.