Example usage for javax.media.j3d Text3D setFont3D

List of usage examples for javax.media.j3d Text3D setFont3D

Introduction

In this page you can find the example usage for javax.media.j3d Text3D setFont3D.

Prototype

public void setFont3D(Font3D font3d) 

Source Link

Document

Sets the Font3D object used by this Text3D NodeComponent object.

Usage

From source file:ExText.java

public void checkboxChanged(CheckboxMenu menu, int check) {
    if (menu == fontMenu) {
        // Change the 2D font used to build a 3D font
        currentFont = check;/* w ww.  j  av  a2s  .  c  o  m*/
        String fontName = (String) fonts[currentFont].name;
        Font font = (Font) fonts[currentFont].value;
        Font3D font3d = new Font3D(font, extrusion);

        Text3D tex = new Text3D();
        tex.setFont3D(font3d);
        tex.setString(fontName);
        tex.setAlignment(Text3D.ALIGN_CENTER);

        scene.removeChild(0);
        shape.setGeometry(tex);
        scene.addChild(textGroup);

        if (debug)
            System.err.println("Font set to " + fontName);
        return;
    }

    // Handle all other checkboxes
    super.checkboxChanged(menu, check);
}

From source file:ExText.java

public Group buildScene() {
    // Get the current font attributes
    Font font = (Font) fonts[currentFont].value;
    String textString = (String) fonts[currentFont].name;

    // Turn on the example headlight
    setHeadlightEnable(true);/*w  ww .j a  v  a2s. c  om*/

    // Build the scene group
    scene = new Group();
    scene.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    scene.setCapability(Group.ALLOW_CHILDREN_WRITE);

    // Build a branch group to hold the text shape
    // (this allows us to remove the text shape later,
    // change it, then put it back, all under menu control)
    textGroup = new BranchGroup();
    textGroup.setCapability(BranchGroup.ALLOW_DETACH);
    scene.addChild(textGroup);

    // BEGIN EXAMPLE TOPIC
    // Create a font extrusion with a default extrusion shape
    extrusion = new FontExtrusion();

    // Define a 3D font with a default extrusion path
    Font3D font3d = new Font3D(font, extrusion);

    // Build 3D text geometry using the 3D font
    Text3D tex = new Text3D();
    tex.setFont3D(font3d);
    tex.setString(textString);
    tex.setAlignment(Text3D.ALIGN_CENTER);

    // Define a generic shaded appearance
    Appearance app = new Appearance();
    Material mat = new Material();
    mat.setLightingEnable(true);
    app.setMaterial(mat);

    // Assemble geometry and appearance into a shape
    // and add it to the scene
    shape = new Shape3D(tex, app);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    textGroup.addChild(shape);
    // END EXAMPLE TOPIC

    return scene;
}