Monday, January 7, 2008

Technical: Text3D/Font3D in Java3D

Upon advancing into the API (Java3D 1.4.0), we discovered a short and easy way to create 3D text from a text string. Initially we thought of having to draw out these 3D text in 3DStudio Max and export it as a compatible format which can be rendered onto screen by Java3D. Now we can save the trouble.

By importing 2 objects. Namely the 
- javax.media.j3d.Text3D
- javax.media.j3d.Font3D

Text3D generates the 3D text by accepting 2 arguments, a Font3D object and a string.

/**  Begin of sample code  */

Font3D arial = new Font3D(

new Font("Arial", Font.PLAIN, 1),

new FontExtrusion());


Text3D text = new Text3D(arial, "3DText");

/**  End of sample code  */


As you can see, arial is my Font3D object here. It describes the font style of the text string, such as the font family (Arial in this case), style (Italic, bold, etc.), and point size. The size of the resulting characters will be equal to the point size. Lastly, the extrusion creates the depth in the Z axis. 


No comments: