Starfield for Papervision3D
Some PV3D sessions at Flash on the Beach inspired me to play with Papervision3D again and I sort of went for the “space” theme. And there’s certainly no space without stars!
There are several options how to approach this, for example, you can distribute a thousands of tiny 3d objects randomly in the space, you can use the built-in particle field - all these approaches will give you good results, but at the expense of valuable CPU resources. Alternative to real star particles is to use something called “skybox”. Sky box is simply a giant cube with all 6 sides textured with camera placed inside of this box.
Now, if you want to build starfield skybox manually, you have to go through several steps, you need to find appropriate 6 images with stars that can be seamlessly stitched together , import these images, set them as individual BitmapMaterials, make them double sided, add them to MaterialList, build a cube with that material, determine the right mesh subdivision amount and size and finally add the cube to scene.
Starfield component reduces all of the above to one line : scene.addChild(new Starfield());
That will give you a default Starfield, but there are several options that you can pass via constructor to configure your starfield..
Starfield(nuStars, size,contentWidth,contentHeight)
nuStars - number of the stars to be visible per cube side
size - width/height/depth of the cube
contentWidth - width of the texture bitmap used on every side of the cube
contentHeight - height of the texture bitmap used on every side of the cube
With this approach you can have easily 10 000 – 100 000 stars in your scene without a noticeable CPU decrease. Also, no need to look for images from Hubble telescope as the texture is code generated.
Though it’s quite important to correctly configure camera’s field of view and zoom to get the correct “feel” of the space. Otherwise you will end up with too much perspective distortion which will give away the trick. Also don’t forget that Skybox is just a backdrop to your starwars scene, not the main actor, so even if it feels slightly “fake” on its own, with the other scene elements, firing lasers and exploding spaceships … it will do!
Check out the demo and right click to view/download the source.
Posted in AS3, papervision



February 18th, 2009 at 10:25 pm
hey dude, how are you?
so. i just would like to ask if i can use this in my new portfolio. if you see my one, you will see just a html version that what i planning to do with it.
please, answer me as soon as you can.
sorry about my bad english. =D
February 18th, 2009 at 11:34 pm
Hi Julio,
of course, no problem feel free to use it.
June 6th, 2009 at 5:19 pm
[...] on them to activate/deactivate). Incidentally, the stars seen in the first two examples come from Slavomír Durej. Nice little quick and easy class to give your PV3D projects a spacy [...]
November 23rd, 2009 at 11:31 am
Why not use large Sphere instead of Box?
You would than have just one bitmap material instead of six in you component so maybe save some memory.
November 23rd, 2009 at 2:26 pm
fra:
in theory you’re right,
however,
the issue with 3D in flash is normaly not the memory but CPU consumption..
The sphere has much more polygons, even a simplest one so it’s going to be heavier on performance.
As well as , there’s a lot more distortion and warping when texture needs to be wrapped around a spherical object.