## Easy Papervision3D skybox tutorial and source

PDF

Adding a skybox in Papervision3D is extremely easy. I couldn’t find a whole lot of examples/tutorials about skyboxes in Papervision3D, but I managed to find a skybox tutorial source and learned how to do it. The tutorial I got the initial source from is actually about adding stars using particle fields, but I just used the skybox part of it (and used the textures).

I decided to clean it up and make a nice class out of it. I’ve used the trunk of the papervision code repository, revision 851, but since it’s very basic stuff I doubt it’ll break with future versions.

See the line material.doubleSided = true;? That’s needed since we’re inside the cube that is the skybox. Since normally you can only see objects from the outside we’re setting the double-sidedness of the skybox. Perhaps a better solution is to flip the faces of the skybox and leave out the double-sidedness all together:

To use the Skybox class, here’s an example:

Here are the steps you need:

• define a bunch of textures in the top of your classes by embedding them and pass these classes to the Skybox constructor.
• pass in a size for your skybox: I’ve used Number.MAX_VALUE so the skybox won’t move or pixelate while I move through it with the camera.
• pass in a quality value: this can be any number actually, I just found 4, 6 and 8 to work nicely. These numbers determine how many segments are used in each of the faces of the skybox to avoid texture distortion and awkward transitions from one texture into another.

For my own convenience I’ve made a NebulaSkybox which simply encapsulates all the embedded images for the nebula sky:

Tags:
• #### Morten Legarth

About the doubleSided as you mentioned it might not be the best way. The Cube primitive actually does have a built in feature for flipping the faces.

The Cube constructor’s 8th param defines which faces are “inside”, pass Cube.ALL to it to flip all faces.

• #### Benny Bottema Post author

Indeed! Thanks for pointing that out…

• #### Rutger

Hiya,

I keep getting a:

TypeError: Error #1007: Instantiation attempted on a non-constructor.
at org.codemonkey.papervision3d::Skybox/org.codemonkey.papervision3d:Skybox::generateMaterials()
at org.codemonkey.papervision3d::Skybox\$iinit()
at org.codemonkey.tutorial.skyboxtutorial::SkyboxTutorial/org.codemonkey.tutorial.skyboxtutorial:SkyboxTutorial::initScene()
at org.codemonkey.tutorial.skyboxtutorial::SkyboxTutorial\$iinit()

Any idea what it could be?
Cheers

• #### Benny Bottema Post author

Are you using the right pv3d version (revision)? It should be revision 851 from the trunk of their code repository. If you’re having trouble getting the right version, I’ll be happy to help.

• #### David Peers

Thanks, this blog helped me somewhat in narrowing down some issues with the latest release candidate, Why do they always leave out vital documentation when they release a new version? It may be minor to them but not to me. I’m sure we’re not alone.