3D experiments with Flash Player 10 and AS3Dmod

Demos: [ 1 ] [ 2 ] [ 3 ] [ 4 ] Flash Player 10 required (obviously)
Flash Player 10 has been around for a few months now. As most of you know, it brings some native 3D support. It’s not as robust as Papervision3D or Away3D, and in fact was not designed to compete with those engines. Rather than that, it contains classes that perform 3D calculations and allows basic 3D manipulation of display objects.
The last months I focused on catching up with 3D math. I ordered a book called “3D Math Primer”, which explains in detail all the vector and matrix operations involved in 3D graphics. Even though the examples are in C++ I recommend this book to anyone doing 3D in Flash. The authors made a great effort to explain the subject with clarity. It worked pretty well for me and I understand the math behind 3D much better now.
Both Papervision3D and Away3D were created so that we don’t have to deal directly with 3D calculations. If you are working on a project that involves non-trivial 3D and has a deadline, it’s better to choose one of those engines instead of “pure Flash Player 10″.
However, if you just want to do some casual experiments and learn something on the way, FP10 is great. It offers a small number of tools, focused around Vector3D and a Matrix3D classes. These classes offer low level functionality, so to use them one needs to understand what’s going on under the hood. This is a great way to learn!
Then I had this idea to port AS3Dmod to Flash Player 10 and try to run the modifiers on objects created using FP10 3D classes. It turns out it was not so difficult. Instead of rendering textured 3D objects I just render a single pixel for each vertex. Thanks to this I get a relatively good performance even with as much as 8000 vertices. I found that a modifier applied to such a large amount of vertices, gives interesting visual effects. I even wrote a very simple Wavefront OBJ importer, and I could import the 3d pants model from one of my previous posts to render them in Flash Player 10.
All my previous demos with AS3Dmod involved pretty small amount of vertices – most often no more than 500-600. At this level the performance of the modifiers was not a problem. But with 8000 vertices the modifiers start to have an big impact on the frame rate. A Perlin modifier alone takes 4-5 FPS, which is quite a lot and it got me worried. I believe code optimizations are in order. An interesting solution could be to implement the modifiers as a Pixel Bender kernels. Anyway, I need to do some more research…
In the AS3Dmod SVN you’ll find the FP10 branch. The main difference between this version and the trunk is that it uses FP10 built-in Vector3D and Matrix3D classes as well as Vectors instead of Arrays. The sources for all experiments mentioned above, including a simple AS3Dmod plugin for FP10, are available here.



Thanks for sharing, this is great for effects built without 3D engines.
Great experiments Bartek!
i get an error on demo 1,2 and 4 then nothing happens :\
ArgumentError: Error #2015: Invalid BitmapData.
at flash.display::BitmapData()
at com.everydayflash.cart.core::AbstractSketch/onAdded()
fp 10 r22 debug, firefox 3, osx 10.5
1 and 3 are really pretty!
Just some feedback:
I can’t see anything on a Mac Pro / Firefox 3 / Flash player 10
It works well on the same machine but with Safari.
Did you see FP10-demos from Alternativa team?
http://blog.alternativaplatform.com/en/2009/02/21/alternativa3d-7-in-progress/
They achieved over 21000 vertices model with good FPS (last demo).
Skeletal animation is also interesting – there are no gaps between bones.
@Andrea @Piergiorgio Niero Thanks, it seems there is a weird bug with stage.stageWidth not being available after the ADDED_TO_STAGE event. I’m looking into that.
@Niaz Aliev Yes, I’ve seen them – Alternativa3D team does amazing stuff, its always inspiring!
not locking bcanvas you are why? maybe you could gain those 4 fps back :)
@makc bitmapData.lock is overrated :) it only gave me +1fps improvement
[...] hogy az eredeti sokkal jobban nézett ki, de ez csak 1260 [...]
All except #2 gives me this error:
ArgumentError: Error #2015: Invalid BitmapData.
at flash.display::BitmapData()
at com.everydayflash.cart.core::AbstractSketch/onAdded()
Any ideas?
J
@Jensa exactly, this was already noticed by others and I am getting this error too, although not every time. Seems that stage width & height is not always available inside the onAdded event. Unfortunately I didn’t find any rule for this, so I still don’t know the nature of the bug. My code is very straightforward as you can see, so I don’t see where I can go wrong… I will investigate.
are the sourcecodes available?
sorry, found it ;)
[...] seeing these experiments over at everyday flash, I felt compelled to make something using the fp10 version of [...]
Hi, I’ve made an audio visualisation based on your 3rd example, the pixel tunnel.
Find it here:
http://blog.madebypi.co.uk/2009/03/30/flashplayer-10-audio-fun/
[...] everydayflash.com [...]
hi! i can’t seem to find source files for example 4.. could anybody help me out? thanks!
One suggestion on the bloat Mod..
Change
public function set r (v:Number):void { _r = Math.max (0, v); }
to just
public function set r (v:Number):void { _r = v; }
The r method works much like the force methods in the other mods. So for instance, if you apply it to a plane and bloat the direction in the Z direction, you can oscillate (both + and -) the bloat effect much like in your example FLA.
It would also allow for the inverse of the effect on a primitive, which looks more like a contraction… The only issue being if you go too far, you invert the mesh, creating an inside out possible mess.
btw… I added all these mods to VizualPV3D, and they work great. bravo… they really add much more in the 3d melting pot.
I am dealing with the frame rate speed stuff too.
Its obviously that Perlin Noise effect calculates thousands of pixels each frame and that is why it is so slow.
Looking forward to your next researches ;)
Have fun !!!