2

I'm currently working at my student project. One part of it is to render loaded .OBJ file in stereoscopic view (truly stereoscope, not red/blue shadows). I was able to load .OBJ file and render it in two views: for left and right eye, but I'm stuck with render it on double buffers. Here is how it look like:

Penguin-screenshot

And here is the code:

public class ObjStereoscope extends JFrame{

Canvas3D c1 = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
Canvas3D c2 = new Canvas3D(SimpleUniverse.getPreferredConfiguration());

private SimpleUniverse u = null;
private BranchGroup scene = null;
private JPanel mainPanel = null;

public ObjStereoscope() {
    super();
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice device = env.getDefaultScreenDevice();
    init(device);
}

public void init(GraphicsDevice dev) {

    this.setUndecorated(true);
    //this.setIgnoreRepaint(true);

    try {
        dev.setFullScreenWindow(this);
    } finally {
        dev.setFullScreenWindow(null);
    }

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    mainPanel = new JPanel();
    mainPanel.setLayout(new FlowLayout());
    this.setLayout(new FlowLayout());
    this.add(mainPanel);

    setExtendedState(this.getExtendedState() | JFrame.MAXIMIZED_BOTH);

    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    c1.setSize(500, 500);
    c1.setMonoscopicViewPolicy(View.LEFT_EYE_VIEW);
    mainPanel.add(c1);
    c2.setSize(500, 500);
    c2.setMonoscopicViewPolicy(View.RIGHT_EYE_VIEW);
    mainPanel.add(c2);
    mainPanel.repaint();

    scene = makeScene();
    u = new SimpleUniverse(c1);

    View view0 = u.getViewer().getView();
    View view = new View();
    PhysicalBody myBod = view0.getPhysicalBody();
    myBod.setLeftEyePosition(new Point3d(-.006, 0.0, 0.0)); // default
                                                            // is(-0.033,
                                                            // 0.0, 0.0)
    myBod.setRightEyePosition(new Point3d(+.006, 0.0, 0.0));
    view.setPhysicalBody(myBod);
    view.setPhysicalEnvironment(view0.getPhysicalEnvironment());
    view.attachViewPlatform(u.getViewingPlatform().getViewPlatform());
    view.addCanvas3D(c2);

    view.repaint();

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    u.getViewingPlatform().setNominalViewingTransform();
    u.addBranchGraph(scene);

}

private BranchGroup makeScene() {
    BranchGroup branchGroup = new BranchGroup();

    Transform3D rotation1 = new Transform3D();
    Transform3D ratation2 = new Transform3D();
    rotation1.rotX(Math.PI / 4.0d);
    ratation2.rotY(Math.PI / 5.0d);
    rotation1.mul(ratation2);

    TransformGroup objTrans = new TransformGroup(rotation1);
    objTrans.setCapability(17); // 17
    objTrans.setCapability(18); // 18
    ObjectFile file = new ObjectFile(ObjectFile.RESIZE);
    Scene scene = null;

    try {
        scene = file.load(ClassLoader.getSystemResource("penguin.obj"));
    } catch (FileNotFoundException e) {
        System.err.println(e);
    } catch (ParsingErrorException e) {
        System.err.println(e);
    } catch (IncorrectFormatException e) {
        System.err.println(e);
    } catch (Exception e) {
        System.err.println(e);
    }
    objTrans.addChild(scene.getSceneGroup());

    DirectionalLight d_Licht = new DirectionalLight(new Color3f(0.7f, 1.5f, 0.3f), new Vector3f(1.0f, -10.0f, 1.0f));
    d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), 100.0d));
    objTrans.addChild(d_Licht);

    BoundingSphere bounds = new BoundingSphere();
    MouseRotate spin = new MouseRotate();
    spin.setTransformGroup(objTrans);
    spin.setSchedulingBounds(bounds);

    branchGroup.addChild(spin);
    branchGroup.addChild(objTrans);

    return branchGroup;
}

public static void main(String[] args) {
    new ObjStereoscope();

    }

}

And my questions are:

1) Is that possible to make it stereo rendered with multiple buffers in Java3D? If yes, how?

2) Do I need some extra hardware to implement it in stereo? I need just implement it, app will be presented on stereoscope projector with active glasses. This example works ok on my computer:

MultiBufferTest.java

3) Thank you in advance for any help. I would be very grateful.

  • It should work with Java 3D 1.6, please rather ask your question on the official Java 3D forum: http://forum.jogamp.org/java3d-f3728156.html – gouessej Sep 04 '14 at 14:01

0 Answers0