Example usage for javax.media.j3d FontExtrusion FontExtrusion

List of usage examples for javax.media.j3d FontExtrusion FontExtrusion

Introduction

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

Prototype

public FontExtrusion() 

Source Link

Document

Constructs a FontExtrusion object with default parameters.

Usage

From source file:Text3DApp.java

public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    Transform3D t3D = new Transform3D();
    t3D.setTranslation(new Vector3f(0.0f, 0.0f, -3.0f));
    TransformGroup objMove = new TransformGroup(t3D);
    objRoot.addChild(objMove);// w  w w. j a va  2s. com

    // Create the transform group node and initialize it to the
    // identity. Add it to the root of the subgraph.
    TransformGroup objSpin = new TransformGroup();
    objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objMove.addChild(objSpin);

    Appearance textAppear = new Appearance();
    ColoringAttributes textColor = new ColoringAttributes();
    textColor.setColor(1.0f, 0.0f, 0.0f);
    textAppear.setColoringAttributes(textColor);
    textAppear.setMaterial(new Material());

    // Create a simple shape leaf node, add it to the scene graph.
    Font3D font3D = new Font3D(new Font("Helvetica", Font.PLAIN, 1), new FontExtrusion());
    Text3D textGeom = new Text3D(font3D, new String("3DText"));
    textGeom.setAlignment(Text3D.ALIGN_CENTER);
    Shape3D textShape = new Shape3D();
    textShape.setGeometry(textGeom);
    textShape.setAppearance(textAppear);
    objSpin.addChild(textShape);

    // Create a new Behavior object that will perform the desired
    // operation on the specified transform object and add it into
    // the scene graph.
    Alpha rotationAlpha = new Alpha(-1, 10000);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin);

    // a bounding sphere specifies a region a behavior is active
    // create a sphere centered at the origin with radius of 100
    BoundingSphere bounds = new BoundingSphere();
    rotator.setSchedulingBounds(bounds);
    objSpin.addChild(rotator);

    DirectionalLight lightD = new DirectionalLight();
    lightD.setInfluencingBounds(bounds);
    lightD.setDirection(new Vector3f(0.0f, 0.0f, -1.0f));
    lightD.setColor(new Color3f(1.0f, 0.0f, 1.0f));
    objMove.addChild(lightD);

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(bounds);
    objMove.addChild(lightA);

    return objRoot;
}

From source file:PickText3DBounds.java

public BranchGroup createSceneGraph(Canvas3D canvas) {
    Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f);
    Color3f lColor1 = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f lColor2 = new Color3f(0.0f, 1.0f, 0.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);

    Transform3D t;/*from w w  w  .  j a va  2  s. co m*/

    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.4);
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create a bounds for the background and lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Set up the background
    Background bg = new Background(bgColor);
    bg.setApplicationBounds(bounds);
    objScale.addChild(bg);

    Material m = new Material(objColor, eColor, objColor, sColor, 100.0f);
    Appearance a = new Appearance();
    m.setLightingEnable(true);
    a.setMaterial(m);
    Font3D f3d = new Font3D(new Font("TestFont", Font.PLAIN, 1), new FontExtrusion());
    Text3D txt = new Text3D(f3d, new String("TEXT3D"), new Point3f(-2.0f, 0.0f, 0.0f));
    //    txt.setCapability(Geometry.ALLOW_INTERSECT);
    Shape3D s3D = new Shape3D();
    s3D.setGeometry(txt);
    s3D.setAppearance(a);

    // Create a transform group node and initialize it to the
    // identity.  Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime.
    TransformGroup spinTg = new TransformGroup();
    spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    spinTg.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

    spinTg.addChild(s3D);
    objScale.addChild(spinTg);

    // Create the transform group node for the each light and initialize
    // it to the identity.  Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime.  Add them to the root
    // of the subgraph.

    // Create transformations for the positional lights
    t = new Transform3D();
    Vector3d lPos1 = new Vector3d(0.0, 0.0, 2.0);
    t.set(lPos1);
    TransformGroup l1Trans = new TransformGroup(t);
    l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    l1Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
    objScale.addChild(l1Trans);

    t = new Transform3D();
    Vector3d lPos2 = new Vector3d(0.5, 0.8, 2.0);
    t.set(lPos2);
    TransformGroup l2Trans = new TransformGroup(t);
    l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    l2Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

    objScale.addChild(l2Trans);

    // Create Geometry for point lights
    ColoringAttributes caL1 = new ColoringAttributes();
    ColoringAttributes caL2 = new ColoringAttributes();
    caL1.setColor(lColor1);
    caL2.setColor(lColor2);
    Appearance appL1 = new Appearance();
    Appearance appL2 = new Appearance();
    appL1.setColoringAttributes(caL1);
    appL2.setColoringAttributes(caL2);
    l1Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS, 15, appL1));
    l2Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS, 15, appL2));

    // Create lights
    AmbientLight aLgt = new AmbientLight(alColor);

    Light lgt1;
    Light lgt2;

    Point3f lPoint = new Point3f(0.0f, 0.0f, 0.0f);
    Point3f atten = new Point3f(1.0f, 0.0f, 0.0f);
    lgt1 = new PointLight(lColor1, lPoint, atten);
    lgt2 = new PointLight(lColor2, lPoint, atten);

    // Set the influencing bounds
    aLgt.setInfluencingBounds(bounds);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);

    // Add the lights into the scene graph
    objScale.addChild(aLgt);
    l1Trans.addChild(lgt1);
    l2Trans.addChild(lgt2);

    PickRotateBehavior behavior1 = new PickRotateBehavior(objRoot, canvas, bounds);
    behavior1.setMode(PickTool.BOUNDS);
    objRoot.addChild(behavior1);

    PickZoomBehavior behavior2 = new PickZoomBehavior(objRoot, canvas, bounds);
    behavior2.setMode(PickTool.BOUNDS);
    objRoot.addChild(behavior2);

    PickTranslateBehavior behavior3 = new PickTranslateBehavior(objRoot, canvas, bounds);
    behavior3.setMode(PickTool.BOUNDS);
    objRoot.addChild(behavior3);

    // Let Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

From source file:Text3DLoad.java

public BranchGroup createSceneGraph() {
    float sl = textString.length();
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    // Assuming uniform size chars, set scale to fit string in view
    t3d.setScale(1.2 / sl);// w w w  .  ja va2 s  . co  m
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create the transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add it to the
    // root of the subgraph.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objScale.addChild(objTrans);

    Font3D f3d;
    if (tessellation > 0.0) {
        f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), tessellation, new FontExtrusion());
    } else {
        f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion());
    }
    Text3D txt = new Text3D(f3d, textString, new Point3f(-sl / 2.0f, -1.f, -1.f));
    Shape3D sh = new Shape3D();
    Appearance app = new Appearance();
    Material mm = new Material();
    mm.setLightingEnable(true);
    app.setMaterial(mm);
    sh.setGeometry(txt);
    sh.setAppearance(app);
    objTrans.addChild(sh);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    if (false) {
        Transform3D yAxis = new Transform3D();
        Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

        RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
                (float) Math.PI * 2.0f);
        rotator.setSchedulingBounds(bounds);
        objTrans.addChild(rotator);
    }

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
    Background bgNode = new Background(bgColor);
    bgNode.setApplicationBounds(bounds);
    objRoot.addChild(bgNode);

    // Set up the ambient light
    Color3f ambientColor = new Color3f(0.3f, 0.3f, 0.3f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);

    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
    Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction);
    light2.setInfluencingBounds(bounds);
    objRoot.addChild(light2);

    return objRoot;
}

From source file:PickText3DGeometry.java

public BranchGroup createSceneGraph(Canvas3D canvas) {
    Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f);
    Color3f lColor1 = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f lColor2 = new Color3f(0.0f, 1.0f, 0.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);

    Transform3D t;//  w w w  .j a  v  a 2s. com

    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.4);
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create a bounds for the background and lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Set up the background
    Background bg = new Background(bgColor);
    bg.setApplicationBounds(bounds);
    objScale.addChild(bg);

    Material m = new Material(objColor, eColor, objColor, sColor, 100.0f);
    Appearance a = new Appearance();
    m.setLightingEnable(true);
    a.setMaterial(m);
    Font3D f3d = new Font3D(new Font("TestFont", Font.PLAIN, 1), new FontExtrusion());

    Text3D text3D = new Text3D(f3d, new String("TEXT3D"), new Point3f(-2.0f, 0.7f, 0.0f));
    text3D.setCapability(Geometry.ALLOW_INTERSECT);
    Shape3D s3D1 = new Shape3D();
    s3D1.setGeometry(text3D);
    s3D1.setAppearance(a);

    // Create a transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime.
    TransformGroup spinTg1 = new TransformGroup();
    spinTg1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    spinTg1.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    spinTg1.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

    spinTg1.addChild(s3D1);
    objScale.addChild(spinTg1);

    Text3D pick = new Text3D(f3d, new String("Pick me"), new Point3f(-2.0f, -0.7f, 0.0f));
    pick.setCapability(Geometry.ALLOW_INTERSECT);
    Shape3D s3D2 = new Shape3D();
    s3D2.setGeometry(pick);
    s3D2.setAppearance(a);

    // Create a transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime.
    TransformGroup spinTg2 = new TransformGroup();
    spinTg2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    spinTg2.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    spinTg2.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

    spinTg2.addChild(s3D2);
    objScale.addChild(spinTg2);

    // Create the transform group node for the each light and initialize
    // it to the identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add them to the root
    // of the subgraph.

    // Create transformations for the positional lights
    t = new Transform3D();
    Vector3d lPos1 = new Vector3d(0.0, 0.0, 2.0);
    t.set(lPos1);
    TransformGroup l1Trans = new TransformGroup(t);
    l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    l1Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
    objScale.addChild(l1Trans);

    t = new Transform3D();
    Vector3d lPos2 = new Vector3d(0.5, 1.2, 2.0);
    t.set(lPos2);
    TransformGroup l2Trans = new TransformGroup(t);
    l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    l2Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
    objScale.addChild(l2Trans);

    // Create Geometry for point lights
    ColoringAttributes caL1 = new ColoringAttributes();
    ColoringAttributes caL2 = new ColoringAttributes();
    caL1.setColor(lColor1);
    caL2.setColor(lColor2);
    Appearance appL1 = new Appearance();
    Appearance appL2 = new Appearance();
    appL1.setColoringAttributes(caL1);
    appL2.setColoringAttributes(caL2);
    l1Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING, 15, appL1));
    l2Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING, 15, appL2));

    // Create lights
    AmbientLight aLgt = new AmbientLight(alColor);

    Light lgt1;
    Light lgt2;

    Point3f lPoint = new Point3f(0.0f, 0.0f, 0.0f);
    Point3f atten = new Point3f(1.0f, 0.0f, 0.0f);
    lgt1 = new PointLight(lColor1, lPoint, atten);
    lgt2 = new PointLight(lColor2, lPoint, atten);

    // Set the influencing bounds
    aLgt.setInfluencingBounds(bounds);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);

    // Add the lights into the scene graph
    objScale.addChild(aLgt);
    l1Trans.addChild(lgt1);
    l2Trans.addChild(lgt2);

    PickRotateBehavior behavior1 = new PickRotateBehavior(objRoot, canvas, bounds);
    behavior1.setMode(PickTool.GEOMETRY);
    behavior1.setTolerance(0.0f);
    objRoot.addChild(behavior1);

    PickZoomBehavior behavior2 = new PickZoomBehavior(objRoot, canvas, bounds);
    behavior2.setMode(PickTool.GEOMETRY);
    behavior2.setTolerance(0.0f);
    objRoot.addChild(behavior2);

    PickTranslateBehavior behavior3 = new PickTranslateBehavior(objRoot, canvas, bounds);
    behavior3.setMode(PickTool.GEOMETRY);
    behavior3.setTolerance(0.0f);
    objRoot.addChild(behavior3);

    // Let Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

From source file:BillboardTest.java

private TransformGroup createBillboard(String szText, Point3f locationPoint, int nMode, Point3f billboardPoint,
        BoundingSphere bounds) {// ww  w  . j a  va  2 s .c o  m
    TransformGroup subTg = new TransformGroup();
    subTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    Font3D f3d = new Font3D(new Font("SansSerif", Font.PLAIN, 10), new FontExtrusion());
    Text3D label3D = new Text3D(f3d, szText, locationPoint);

    Appearance app = new Appearance();

    Color3f black = new Color3f(0.1f, 0.1f, 0.1f);
    Color3f objColor = new Color3f(0.2f, 0.2f, 0.2f);

    app.setMaterial(new Material(objColor, black, objColor, black, 90.0f));
    Shape3D sh = new Shape3D(label3D, app);

    subTg.addChild(sh);

    Billboard billboard = new Billboard(subTg, nMode, billboardPoint);
    billboard.setSchedulingBounds(bounds);
    subTg.addChild(billboard);

    return subTg;
}

From source file:OrientedPtTest.java

public BranchGroup createSceneGraph() {

    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    TransformGroup objScale = new TransformGroup();
    Transform3D textMat = new Transform3D();
    // Assuming uniform size chars, set scale to fit string in view
    textMat.setScale(1.2 / sl);//w w w . j  a  v a 2s  .com
    objScale.setTransform(textMat);

    // Create the transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add it to the
    // root of the subgraph.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objRoot.addChild(objTrans);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    Appearance apText = new Appearance();
    Material m = new Material();
    m.setLightingEnable(true);
    apText.setMaterial(m);

    Appearance apEarth = new Appearance();
    Material mm = new Material();
    mm.setLightingEnable(true);
    apEarth.setMaterial(mm);

    Appearance apStone = new Appearance();
    apStone.setMaterial(mm);

    // create 3D text
    Font3D f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion());
    Point3f textPt = new Point3f(-sl / 2.0f, 3.0f, 0.0f);
    Text3D txt = new Text3D(f3d, textString, textPt);
    OrientedShape3D textShape = new OrientedShape3D();
    textShape.setGeometry(txt);
    textShape.setAppearance(apText);

    textShape.setAlignmentMode(OrientedShape3D.ROTATE_ABOUT_POINT);
    // text is centered around 0, 3, 0. Make it rotate around 0,5,0
    Point3f rotationPt = new Point3f(0.0f, 5.0f, 0.0f);
    textShape.setRotationPoint(rotationPt);
    objScale.addChild(textShape);

    // also add a small Sphere at the rotation point to
    // show that we are rotating around the right point
    Sphere sphere = new Sphere(0.2f);
    TransformGroup sphereGroup = new TransformGroup();
    Transform3D sphereXform = new Transform3D();
    sphereXform.set(new Vector3f(rotationPt));
    sphereGroup.setTransform(sphereXform);
    sphereGroup.addChild(sphere);
    objScale.addChild(sphereGroup);

    // Create a simple shape leaf node, add it to the scene graph.

    Transform3D cubeMat = new Transform3D();
    TransformGroup cubeTrans = new TransformGroup(cubeMat);
    cubeMat.set(new Vector3d(0.9, 0.0, -1.0));
    cubeTrans.setTransform(cubeMat);
    cubeTrans.addChild(new ColorCube(0.3));
    objTrans.addChild(cubeTrans);

    TextureLoader stoneTex = new TextureLoader(stoneImage, new String("RGB"), this);
    if (stoneTex != null)
        apStone.setTexture(stoneTex.getTexture());

    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.REPLACE);
    apStone.setTextureAttributes(texAttr);

    Transform3D coneMat = new Transform3D();
    TransformGroup coneTrans = new TransformGroup(coneMat);
    coneMat.set(new Vector3d(0.0, 0.0, 0.0));
    coneTrans.setTransform(coneMat);
    coneTrans.addChild(new Cone(.2f, 0.8f, Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, apStone));
    objTrans.addChild(coneTrans);

    TextureLoader earthTex = new TextureLoader(earthImage, new String("RGB"), this);
    if (earthTex != null)
        apEarth.setTexture(earthTex.getTexture());
    apEarth.setTextureAttributes(texAttr);

    Transform3D cylinderMat = new Transform3D();
    TransformGroup cylinderTrans = new TransformGroup(cylinderMat);
    cylinderMat.set(new Vector3d(-0.9, 0.5, -1.0));
    cylinderTrans.setTransform(cylinderMat);
    cylinderTrans.addChild(
            new Cylinder(.35f, 2.0f, Cylinder.GENERATE_NORMALS | Cylinder.GENERATE_TEXTURE_COORDS, apEarth));
    objTrans.addChild(cylinderTrans);

    objTrans.addChild(objScale);

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
    Background bgNode = new Background(bgColor);
    bgNode.setApplicationBounds(bounds);
    objRoot.addChild(bgNode);

    // Set up the ambient light
    Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);

    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
    Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction);
    light2.setInfluencingBounds(bounds);
    objRoot.addChild(light2);

    apText.setMaterial(mm);

    // Have Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

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);/*from ww  w  .  j av a  2  s .c  o  m*/

    // 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;
}

From source file:OrientedTest.java

public BranchGroup createSceneGraph() {

    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    TransformGroup objScale = new TransformGroup();
    Transform3D textMat = new Transform3D();
    // Assuming uniform size chars, set scale to fit string in view
    textMat.setScale(1.2 / sl);//from w ww . j av  a 2s  . c om
    objScale.setTransform(textMat);

    // Create the transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add it to the
    // root of the subgraph.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objRoot.addChild(objTrans);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    Appearance apText = new Appearance();
    Material m = new Material();
    m.setLightingEnable(true);
    apText.setMaterial(m);

    Appearance apEarth = new Appearance();
    Material mm = new Material();
    mm.setLightingEnable(true);
    apEarth.setMaterial(mm);

    Appearance apStone = new Appearance();
    apStone.setMaterial(mm);

    // create 3D text
    Font3D f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion());
    Text3D txt = new Text3D(f3d, textString, new Point3f(-sl / 2.0f, 3.0f, 0.0f));
    OrientedShape3D textShape = new OrientedShape3D();
    textShape.setGeometry(txt);
    textShape.setAppearance(apText);
    textShape.setAlignmentAxis(0.0f, 1.0f, 0.0f);
    objScale.addChild(textShape);

    // Create a simple shape leaf node, add it to the scene graph.

    Transform3D cubeMat = new Transform3D();
    TransformGroup cubeTrans = new TransformGroup(cubeMat);
    cubeMat.set(new Vector3d(0.9, 0.0, -1.0));
    cubeTrans.setTransform(cubeMat);
    cubeTrans.addChild(new ColorCube(0.3));
    objTrans.addChild(cubeTrans);

    TextureLoader stoneTex = new TextureLoader(stoneImage, new String("RGB"), this);
    if (stoneTex != null)
        apStone.setTexture(stoneTex.getTexture());

    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.MODULATE);
    apStone.setTextureAttributes(texAttr);

    Transform3D coneMat = new Transform3D();
    TransformGroup coneTrans = new TransformGroup(coneMat);
    coneMat.set(new Vector3d(0.0, 0.0, 0.0));
    coneTrans.setTransform(coneMat);
    coneTrans.addChild(new Cone(.2f, 0.8f, Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, apStone));
    objTrans.addChild(coneTrans);

    TextureLoader earthTex = new TextureLoader(earthImage, new String("RGB"), this);
    if (earthTex != null)
        apEarth.setTexture(earthTex.getTexture());

    apEarth.setTextureAttributes(texAttr);

    Transform3D cylinderMat = new Transform3D();
    TransformGroup cylinderTrans = new TransformGroup(cylinderMat);
    cylinderMat.set(new Vector3d(-0.9, 0.5, -1.0));
    cylinderTrans.setTransform(cylinderMat);
    cylinderTrans.addChild(
            new Cylinder(.35f, 2.0f, Cylinder.GENERATE_NORMALS | Cylinder.GENERATE_TEXTURE_COORDS, apEarth));
    objTrans.addChild(cylinderTrans);

    objTrans.addChild(objScale);

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
    Background bgNode = new Background(bgColor);
    bgNode.setApplicationBounds(bounds);
    objRoot.addChild(bgNode);

    // Set up the ambient light
    Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);

    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
    Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction);
    light2.setInfluencingBounds(bounds);
    objRoot.addChild(light2);

    apText.setMaterial(mm);

    // Have Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

From source file:PointTest.java

private BranchGroup createPoints(final int nPointSize, final int nNumPoints, boolean bAliased) {
    BranchGroup bg = new BranchGroup();

    String szText = new String();
    szText += (nNumPoints + "X, Size:" + nPointSize + ", aliased: " + bAliased);

    Font3D f3d = new Font3D(new Font("SansSerif", Font.PLAIN, 1), new FontExtrusion());
    Text3D label3D = new Text3D(f3d, szText, new Point3f(-5, 0, 0));
    Shape3D sh = new Shape3D(label3D);

    bg.addChild(sh);//from w  ww .  ja  v  a 2s  .  c om

    PointArray pointArray = new PointArray(nNumPoints * nNumPoints,
            GeometryArray.COORDINATES | GeometryArray.COLOR_3);

    // create the PointArray that we will be rendering
    int nPoint = 0;
    final double factor = 1.0 / nNumPoints;

    for (int n = 0; n < nNumPoints; n++) {
        for (int i = 0; i < nNumPoints; i++) {
            Point3f point = new Point3f(n - nNumPoints / 2, i - nNumPoints / 2, 0.0f);
            pointArray.setCoordinate(nPoint, point);
            pointArray.setColor(nPoint++, new Color3f(0.5f, (float) (n * factor), (float) (i * factor)));
        }
    }

    // create the material for the points
    Appearance pointApp = new Appearance();

    // enlarge the points
    pointApp.setPointAttributes(new PointAttributes(nPointSize, bAliased));

    Shape3D pointShape = new Shape3D(pointArray, pointApp);

    bg.addChild(pointShape);
    return bg;
}

From source file:edu.uci.ics.jung.visualization3d.VisualizationViewer.java

public void setGraphLayout(Layout<V, E> inLayout) {

    //      this.layout = inLayout;
    this.graph = inLayout.getGraph();
    BranchGroup branch = new BranchGroup();
    LayoutEventBroadcaster<V, E> elayout = new LayoutEventBroadcaster<V, E>(inLayout);
    this.layout = elayout;
    for (V v : graph.getVertices()) {
        VertexGroup<V> vg = new VertexGroup<V>(v, renderContext.getVertexShapeTransformer().transform(v));
        vg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        vg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        vertexMap.put(v, vg);//from  ww  w.j av  a2  s .co m
        branch.addChild(vg);
        String label = renderContext.getVertexStringer().transform(v);
        if (label != null) {
            String fontName = "Serif";
            Font3D f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion());
            Text3D txt = new Text3D(f3d, label, new Point3f(2f, 2f, 0));
            OrientedShape3D textShape = new OrientedShape3D();
            textShape.setGeometry(txt);
            textShape.setAppearance(grayLook);
            //            textShape.setAlignmentAxis( 0.0f, 1.0f, 0.0f);
            textShape.setAlignmentMode(OrientedShape3D.ROTATE_ABOUT_POINT);
            textShape.setRotationPoint(new Point3f());
            //            objScale.addChild( textShape );
            //            BranchGroup bg = new BranchGroup();
            //            bg.addChild(textShape);
            //            branch.addChild(bg);

            //            Text2D text = new Text2D(label+" more text here", new Color3f(0,0,0),"Serif",50,Font.BOLD);
            Transform3D tt = new Transform3D();
            //            tt.setTranslation(new Vector3f(100,100,100));
            tt.setScale(5);
            TransformGroup tg = new TransformGroup(tt);
            //            textShape.setGeometry(text);
            tg.addChild(textShape);
            BranchGroup bg = new BranchGroup();
            bg.addChild(tg);
            //            branch.addChild(bg);
            vg.getLabelNode().addChild(bg);

        }

    }
    System.err.println("vertexMap = " + vertexMap);

    for (E edge : graph.getEdges()) {
        EdgeGroup<E> eg = new EdgeGroup<E>(edge, renderContext.getEdgeShapeTransformer()
                .transform(Context.<Graph<V, E>, E>getInstance(graph, edge)));
        eg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        eg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        edgeMap.put(edge, eg);
        branch.addChild(eg);
    }

    //      System.err.println("branch is "+branch);
    //      for(int i=0; i<branch.numChildren(); i++) {
    //         System.err.println("branch child ["+i+"] is "+branch.getChild(i));
    //      }

    objTrans.addChild(branch);
    elayout.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            for (V v : vertexMap.keySet()) {
                Point3f p = VisualizationViewer.this.layout.transform(v);
                Vector3f pv = new Vector3f(p.getX(), p.getY(), p.getZ());
                Transform3D tx = new Transform3D();
                tx.setTranslation(pv);
                vertexMap.get(v).setTransform(tx);
            }

            for (E edge : graph.getEdges()) {
                Pair<V> endpoints = graph.getEndpoints(edge);
                V start = endpoints.getFirst();
                V end = endpoints.getSecond();
                EdgeGroup eg = edgeMap.get(edge);
                eg.setEndpoints(layout.transform(start), layout.transform(end));
            }
        }
    });

    elayout.setSize(new BoundingSphere(new Point3d(), 200));
    elayout.initialize();
    VisRunner runner = new VisRunner((IterativeContext) elayout);
    runner.relax();

    //      for(int i=0; i<objTrans.numChildren(); i++) {
    //         System.err.println("objTrans child ["+i+"] is "+objTrans.getChild(i));
    //      }

}