Wednesday, April 16, 2008

How to display text in papervision

I've been looking for a tutorial to display a simple text field within papervision without much success. I finally tumbled on this blog post where it was quite well explained. The example however might be a little long to demonstrate my sole purpose: how to display text in papervision.

So I've decided to put here an even simpler example to make things crystal clear:


// create your text field and set its content.
var t:TextField = new TextField();
t.text = "Hello world!";
// create a BitmapData of your wished width and height
var bitmap:BitmapData = new BitmapData(100,100);
// Fill bmp with the content of your TextField.
//It's as if you took a picture of t.

bitmap.draw(t);
// Create a material with the resulting BitmapData and you can use it on any DisplayObject3D!
var material:BitmapMaterial = new BitmapMaterial(bitmap);
material.smooth = true;
material.doubleSided = true;
var p:Plane = new Plane(material,100,100);
scene.addChild(p);


First observation is that it seems impossible to directly embed a UIComponent within papervision *sigh*. Whatever the UIComponent (Button, TextField, etc), it has to be put somehow in a texture and applied on a DisplayObject3D such as a Plane.

Or at least, I have no knowledge of another way to do it. Does anybody know better? My worry is that it may slow down the frame rate to display text in a texture rather than directly as what it really is: good old plain text.

4 comments:

Mohamed said...

hello
merci pour le petit code c est mieux que rien

Barbara said...

Aha! Seems there is a solution. I'm going to try that, thanks to John!

brandon said...

Hi barbara,

I've been trying to figure this out forever! THANK YOU for the insight. It's good to see you're in the ycombinator gang. Looking forward to other great posts.

brunoimbrizi said...

This could help too:
Text in Papervision3D - Clearing things up | zupko.info