In order to use other fonts in Papervision3D, we need to create our own custom Font3D
classes. Although this may sound pretty daunting, it is not hard at all, thanks to a tool by Mathieu Badimon, the developer of Five3D.
In short, downloading the tool and placing in it the correct folder will create a new panel inside the Flash IDE. When the panel is opened, you can choose a font and the tool will generate an ActionScript class file that contains vector data about the font. The following screenshot shows the panel:
Go to http://code.google.com/p/five3d/downloads/list and download the latest release, which was FIVe3D_make_typography_v2.0.zip
at the time of writing.
Inside the ZIP file you will find a SWF and a PDF file. The PDF contains instructions on where to place the SWF and how to create a font file. Read these instructions...
Adding interactivity to 3D vector text and shapes
Adding interactivity to 3D vector objects basically works the same as adding interactivity to any other 3D object. You can use the InteractiveScene3DEvent
similar to what we have done in previous chapters. However, to increase the accuracy you should import VectorShapeHitTest
, which is located in the org.papervision3d.core.render.command
package, and add the following line at the top of your init()
method:
Another aspect worth taking a look at, is adding interactivity to 3D text. If you would try to add an event listener to a Text3D
instance directly, you are out of luck. Adding interactivity is done by adding listeners to the letters of the text. Let's see how that works.
Adding interactivity to 3D text
Again, we will take the Text3DTemplate
as our starting point. We will create a simple example with some 3D text and make it interactive. When the mouse hovers a letter, it will turn...
Drawing vector shapes—lines, circles, and rectangles
The integrated VectorVision library not only lets you create 3D text, it also provides a VectorShape3D
class that allows drawing basic vector shapes such as lines, circles, and rectangles. The shapes are initially drawn in 2D and then projected in 3D space.
Working with vector shapes requires two classes, VectorShapeMaterial
—located in the org.papervision3d.materials.special
package—and VectorShape3D
- located in the org.papervision3d.objects.special
package. To create a vector shape material, use the VectorShapeMaterial
class.
The constructor of this class does not take any parameters.
When you want to draw a shape, you must instantiate VectorShape3D
. The following code draws a line:
Drawing lines with Lines3D
Before VectorVision was integrated, Papervision3D already had a Lines3D
class for drawing 3D lines. Two differences between drawing lines with VectorShape3D
and Lines3D
are:
Whereas VectorShape3D
enables you to easily draw rectangles, circles, and ellipses, Lines3D
does not have built-in methods to do such things.
Lines3D
creates lines with a Vertex3D
as the start and end point, resulting in 3D projection of the vertices that make the line. On the other hand, VectorShape3D
lets you draw a 2D shape, which you then can rotate in order to achieve a 3D perspective.
Let's take a look at how to create straight as well as curved lines with Lines3D
, and how to add interactivity. The following class will serve as a template for the Lines3D
examples to come:
Papervision3D offers a set of easy-to-use classes to draw 3D vector shapes such as simple graphics and text. The classes were originally part of VectorVision, a separate project that was developed to create 3D vector text, but was integrated into Papervision3D.
3D vector graphics can be created similar to how the Flash drawing API works, with methods such as drawCircle()
and lineTo()
. The graphics, such as lines, circles, rectangles, and ellipses are drawn in 2D and can then be rotated to create a 3D illusion.
The 3D text classes allow you to create crisp looking multiline text with alignment, letter spacing, and line spacing. Although Papervision3D has only four built-in fonts, it is possible to create text with other fonts. An external tool has been discussed, which generates font classes, containing vector information about the font you want to use. These classes can easily be incorporated into your Papervision3D project.
You add interactivity to 3D text as well as other 3D vector...