Charles Petzold



3D Text Animation (dot xaml)

July 6, 2006
In NY, NY for a Liberty game

I like graphics programming involving text, and I've enjoyed animating those graphics, and in the future I'd like to extend this unhealthy obsession into the 3D realm, of which this program is a simple example.

Hello3D.xaml

In 3D programming, you're not actually displaying a TextBlock object. Anything you display has to be a GeometryModel3D object with a Geometry property set to a MeshGeometry3D object, which defines an object in three dimensions as a collection of triangles that share vertices and sides. You can then define a Material object based on a Brush to color the sides of this object. That brush can be a VisualBrush, of course, which can be based on a TextBlock. And that's how you get text into the 3D scene.

Just two triangles comprise the square object created in this particular program. The TextureCoordinates property of MeshGeometry3D defines how the 2D coordinates of the material brush correspond to the 3D coordinates of the object. Because this particular object is a flat square, assigning the same Material object to the Material and BackMaterial properties of GeometryModel3D cause the text to appear normally on the front of the object and in reverse on the back.

Then all you need to do is attach the object to the side of a popsicle stick like a flag, give it a little flick with your finger, and off it goes.