OrbitBehavior and Text3D strange thing happens

Hi all,

putting it briefly:
a) i have put some Text3D objects along the z axis
b) when going past the origin Text3D objects disappear, Cylinders in front of Text3D go on being rendered
this is the code,
the red cylinder is at the origin

quite confused…


import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.image.*;
import com.sun.j3d.utils.behaviors.vp.*;
import java.awt.*;
import java.awt.Font;
import javax.swing.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class Text3DTest
{
public Text3DTest()
{
    BranchGroup group = new BranchGroup();
    Color3f green     = new Color3f(0.0f, 1.0f, 0.0f);
    Color3f white     = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f red       = new Color3f(0.7f, .15f, .15f);
    Color3f black     = new Color3f(0.0f, 0.0f, 0.0f);
   
    Vector3f direction    = new Vector3f(4.0f,-7.0f, -12.0f);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),300.0);


    AmbientLight ambientLightNode = new AmbientLight(white);
    ambientLightNode.setInfluencingBounds(bounds);
    group.addChild(ambientLightNode);

    Transform3D rot = new Transform3D();
    rot.setIdentity();
    rot.rotZ(Math.toRadians(90));
    TransformGroup tg = new TransformGroup(rot);
    Appearance ap     = new Appearance();
    ap.setMaterial(new Material(red, black, red, white, 1.0f));
    Cylinder RedAxis = new Cylinder(0.01f, 1000.0f, ap);
    tg.addChild(RedAxis); 
    group.addChild(tg);



    BranchGroup text1 = Text3DTest.text("alpha", new Point3f(-5.0f, 0.0f, 15.0f));
    BranchGroup text2 = Text3DTest.text("bravo", new Point3f(-5.0f, 0.0f, 0.0f));
    BranchGroup text3 = Text3DTest.text("charlie", new Point3f(-5.0f, 0.0f, -15.0f));
    group.addChild(text1);
    group.addChild(text2);
    group.addChild(text3);

    BranchGroup text10 = Text3DTest.text("alpha", new Point3f(-5.0f, 5.0f, 15.0f));
    BranchGroup text20 = Text3DTest.text("bravo", new Point3f(-5.0f, 5.0f, 0.0f));
    BranchGroup text30 = Text3DTest.text("charlie", new Point3f(-5.0f, 5.0f, -15.0f));
    group.addChild(text10);
    group.addChild(text20);
    group.addChild(text30);

    BranchGroup text101 = Text3DTest.text("alpha", new Point3f(-5.0f, -5.0f, 15.0f));
    BranchGroup text201 = Text3DTest.text("bravo", new Point3f(-5.0f, -5.0f, 0.0f));
    BranchGroup text301 = Text3DTest.text("charlie", new Point3f(-5.0f, -5.0f, -15.0f));
    group.addChild(text101);
    group.addChild(text201);
    group.addChild(text301);

    BranchGroup cylinder1 = Text3DTest.cylinder(green, 0.0f, 0.0f, 10.0f);
    BranchGroup cylinder2 = Text3DTest.cylinder(red, 0.0f, 0.0f, 0.0f);
    BranchGroup cylinder3 = Text3DTest.cylinder(white, 0.0f, 0.0f, -10.0f);
    group.addChild(cylinder1);     
    group.addChild(cylinder2);
    group.addChild(cylinder3); 

    JFrame f = new JFrame();
    GraphicsConfiguration gc = SimpleUniverse.getPreferredConfiguration();
    Canvas3D canvas = new Canvas3D(gc);
    f.add(new JPanel().add("Center",canvas));

    SimpleUniverse universe = new SimpleUniverse(canvas);
    OrbitBehavior orbit =  new OrbitBehavior(canvas, OrbitBehavior.REVERSE_ALL);
    orbit.setSchedulingBounds(bounds);
    ViewingPlatform vp = universe.getViewingPlatform();
    vp.setViewPlatformBehavior(orbit);
    vp = universe.getViewingPlatform();
    vp.getViewPlatform().setActivationRadius(1000.0f);
    TransformGroup steerTG = vp.getViewPlatformTransform();
    Transform3D t3d = new Transform3D( );
    steerTG.getTransform( t3d );
    Point3d viewerInitPos = new Point3d(0, 0, -20);
    Point3d viewerLooksAt = new Point3d(0, 0, 0);
    Vector3d upDirection  = new Vector3d(0,1,0);
    t3d.lookAt( viewerInitPos, viewerLooksAt, upDirection);
    t3d.invert();
    steerTG.setTransform(t3d);


    universe.addBranchGraph(group);

    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.setPreferredSize(new Dimension(600,600));
    f.pack();
    f.setVisible(true);
}
private static BranchGroup text(String text, Point3f pos)
{
    BranchGroup textBG = new BranchGroup();
    Font3D font3d = new Font3D(new Font("Helvetica", Font.PLAIN, 2), new FontExtrusion());
    Text3D textGeom = new Text3D(font3d, text, pos);
    Shape3D textShape = new Shape3D(textGeom);

    Color3f red       = new Color3f(0.7f, .15f, .15f);
    Color3f black     = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white     = new Color3f(1.0f, 1.0f, 1.0f);
    Appearance redAp = new Appearance();
    redAp.setMaterial(new Material(red, black, red, white, 1.0f));
    textShape.setAppearance(redAp);
    textBG.addChild(textShape);
    return textBG;
}
private static BranchGroup cylinder(Color3f color, float x, float y, float z)
{
    Color3f blue      = new Color3f(0.0f, 0.0f, 1.0f);
    Color3f white     = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f red       = new Color3f(0.7f, .15f, .15f);
    Color3f black     = new Color3f(0.0f, 0.0f, 0.0f);

    BranchGroup bg = new BranchGroup();
    Appearance ap2 = new Appearance();
    ap2.setMaterial(new Material(color, black, color, white, 1.0f));

    Cylinder cylinder = new Cylinder(0.5f, 1.0f, ap2);
    Transform3D transform = new Transform3D();
    Vector3f vector = new Vector3f(x, y, z);
    transform.set(vector);
    TransformGroup tg = new TransformGroup(transform);
    tg.addChild(cylinder);
    bg.addChild(tg);
    return bg;
}
public static void main(String[] args )
{
    new Text3DTest();
}
}







Not sure if I understand what the problem is. I tried to run the code, and did not see any code. My only suggestion is to use an infinite bounds. Make the radius Double.POSITIVE_INFINITY. That will sort out any scoping issues. What you are seeing can also be the objects being ciipped by the back clip plane. You could try increasing it.