Text was always a problem I had with Papervision3D. I had to map a bitmap texture on a plane to create a 3D text effect. The results always came out less than satisfactory. So in exploring recent releases of Papervision3D for a new project we picked up, http://www.spychresearch.com, I discovered a Text3D class that had been ported over to Papervision3D over a year ago! What a delightful discovery. The class comes from another 3D flash api, http://five3d.mathieu-badimon.com/.
The text3D class is very easy to implement. Here’s a sample of the code I used:
package {
import flash.events.*
import fonts.*;
import org.papervision3d.view.BasicView;
import org.papervision3d.typography.Font3D;
import org.papervision3d.materials.special.Letter3DMaterial;
public class FloatingText extends BasicView {
private var floatingText:Text3D;
private var floatingTextMat:Letter3DMaterial
public function FloatingText():void {
initText();
startRendering();
}
private function initText():void {
var DINfont:Font3D = new DINmedium();
floatingTextMat = new Letter3DMaterial();
floatingTextMat.fillColor = 0xFFFFFF;
floatingTextMat.doubleSided = true;
floatingText = createText("We don't call it market research,\nmore like peer therapy.", DINfont, floatingTextMat);
scene.addChild(floatingText);
}
private function createText(message:String, font:Font3D, material:Letter3DMaterial):Text3D {
var t:Text3D;
t = new Text3D(message, font, material);
return t;
}
override protected function onRenderTick(e:Event = null):void {
super.onRenderTick(e);
floatingText.yaw(0.5);
}
}
}
And the result:
How do I create the font file?
Creating the vector font needs some workaround. First use the “Make a new typography file v2.0″ tool from FIVe3D.
The generated font will need some tweaking to work in Papervision3D.
1. Correct the package path
2. import org.papervision3d.typography.Font3D
3. And make sure the font extends Font3D
2. Add the following functions to the top:
override public function get motifs():Object
{
if(!__initialized)initialize();
return __motifs;
}
override public function get widths():Object
{
if(!__initialized)initialize();
return __widths;
}
override public function get height():Number
{
if(!__initialized)initialize();
return __heights;
}
The before:
package five3D.typography {
public class DINmedium {
static public var __motifs:Object = {};
static public var __widths:Object = {};
static public var __heights:Number = 170;
static public var __initialized:Boolean = false;
static public function initialize():void {
initializeMotifsUppercase();
initializeMotifsLowercase();
initializeMotifsNumbers();
initializeMotifsPunctuation();
initializeWidthsUppercase();
initializeWidthsLowercase();
initializeWidthsNumbers();
initializeWidthsPunctuation();
__initialized = true;
}
The after:
package fonts {
import org.papervision3d.typography.Font3D;
public class DINmedium extends Font3D{
static public var __motifs:Object = {};
static public var __widths:Object = {};
static public var __heights:Number = 121;
static public var __initialized:Boolean = false;
static public function initialize():void {
initializeMotifsUppercase();
initializeMotifsLowercase();
initializeMotifsNumbers();
initializeMotifsPunctuation();
initializeWidthsUppercase();
initializeWidthsLowercase();
initializeWidthsNumbers();
initializeWidthsPunctuation();
__initialized = true;
}
////////////////////////////////////////////
override public function get motifs():Object
{
if(!__initialized)initialize();
return __motifs;
}
override public function get widths():Object
{
if(!__initialized)initialize();
return __widths;
}
override public function get height():Number
{
if(!__initialized)initialize();
return __heights;
}
////////////////////////////////////////////
Source:floatingText.zip










