Chapter 10. Creating 3D Text

Away3D includes a number of ways to programmatically create 3D objects. We saw in Chapter 2, Creating and Displaying Primitives, how to create a 3D object from the ground up using the base elements, such as vertices and triangle faces, or by using the primitive 3D object classes.

A relatively recent addition to Away3D is the ability to create a 3D object from a font, which allows us to easily add 3D text into a scene. This ability is provided by an external library called swfvector, which is contained in the wumedia package. More information about the swfvector library can be found at http://code.google.com/p/swfvector/. This library was not developed as part of the Away3D engine, but has been integrated since version 2.4 and 3.4, to enable Away3D to provide a way to create and display text 3D objects within the scene.

Away3D also includes the ability to warp a text 3D object by aligning it to a path made up of both straight and curved sections. This chapter will present a sample application that can warp 3D text, as well as some handy tips on debugging this alignment process.

In this chapter, we will look at:

  • Embedding fonts into an application
  • Creating a text 3D object
  • Applying materials to the 3D text
  • Giving the 3D text some depth
  • Warping the 3D text along a path

Embedding fonts

Creating a text 3D object in Away3D requires a source SWF file with an embedded font. To accommodate this, we will create a very simple application using the Fonts class below. This class embeds a single true-type font called Vera Sans from the Vera.ttf file.

When compiled, the resulting SWF file can then be referenced by our Away3D application, allowing the embedded font file to be accessed.

Tip

When embedding fonts using the Flex 4 SDK, you may need to set the embedAsCFF property to false, like:

[Embed(mimeType="application/x-font", source="Vera.ttf", fontName="Vera Sans", embedAsCFF=false)]

This is due to the new way fonts can be embedded with the latest versions of the Flex SDK. You can find more information on the embedAsCFF property at http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf6320a-7fea.html

package
{
  import flash.display.Sprite;

  public class Fonts extends Sprite
  {
    [Embed(mimeType="application/x-font", source="Vera.ttf", fontName="Vera Sans")] 
    public var VeraSans:Class; 
  }
}

Tip

The font used here is Bitstream Vera, which can be freely distributed, and can be obtained from http://www.gnome.org/fonts/. However, not all fonts can be freely redistributed, so be mindful of the copyright or license restrictions that may be imposed by a particular font.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.179.59