Re: Java3D stereo
Posted by bjoern on Sep 03, 2013; 8:10pm
URL: https://forum.jogamp.org/Java3D-stereo-tp4029914p4029977.html
Hi Harvey, Hi Julien, and Hi Jody,
first of all, thanks a lot to you - Julien and Harvey - for starting saving Java 3D! We are also using Java 3D for our CELLmicrocosmos project, and as these are quite large software projects running since several years (area: Bioinformatics & Visualization), we were quite unhappy about the situation of J3D. Still, it runs on many machines, but as you said, on Mac OS X it is already a huge problem.
So we are happy that you started porting J3D to JOGL. I made a few tests with our major projects MembraneEditor and CellExplorer, and both work very fine with your j3d-1.6.0-pre8. I did it by using Eclipse, importing Jogamp as a separate project, binding it e.g. to the CellExplorer project via the Build Path and then I just substituted the standard J3D jars (j3dcore/j3dutil/vecmath). Moreover, I use the ancient j3d-org-geom-core.jar. I just left it in the Build Path, and still it seems to work.
However, I did only some first tests, to I may add small bugs later.
But, here the topic of jodyv is Stereo, and this is also a major topic of our projects. And yes, we have the same problem as Jody, stereo does not work.
To help you to evaluate this problem, I just coded some small example how the standard stereo method of Java3D works (I stole Jody's cone ;-) . It is even more easy than the one of Jody, as it does not use immediate mode and this means, the this Jody's example is closer to OpenGL. I use only Java 3D coding now.
Here is the source code:
----------------------------------------------------------------------------------------------------------------
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import javax.media.j3d.Appearance;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.GraphicsConfigTemplate3D;
import javax.media.j3d.Material;
import javax.media.j3d.PointLight;
import javax.swing.JFrame;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;
import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
import com.sun.j3d.utils.geometry.Cone;
import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.universe.SimpleUniverse;
/**
* Simple Java 3D Stereoscopy test example.
*
* There are two ways to activate stereoscopy here:
* 1. Use the code block _STEREO_CANVAS_ and the last code block in
* StereoTestJava3DStandard()
* 2. Deactivate the code blocks mentioned in 1. and activate the line
* SimpleUniverse universe = new SimpleUniverse(); and start the
* program with the VM argument -Dj3d.stereo=PREFERRED
*
* You need some professional 3D equipment such as NVIDIA Quadro (FX) or
* ATI/ASUS FireGL, compatible monitors and to activate the stereoscopic
* capabilities in the graphics driver preferences.
*
* @author bjoern
*/
public class StereoTestJava3DStandard {
public StereoTestJava3DStandard() {
BranchGroup rootBG = new BranchGroup();
BoundingSphere universeBounds = new BoundingSphere(new Point3d(0.0,
0.0, 0.0), 100000.0);
// add directional light (for front of object)
Color3f lightColor = new Color3f(1, 1, 1);
Vector3f lightDir = new Vector3f(0, 0, -1);
DirectionalLight dirLight = new DirectionalLight(true, lightColor,
lightDir);
rootBG.addChild(dirLight);
dirLight.setInfluencingBounds(universeBounds);
// add point light (for bottom of object)
PointLight pointLight = new PointLight(true, new Color3f(1, 1, 1),
new Point3f(0, -1, 0), new Point3f(1, 1, 1));
pointLight.setInfluencingBounds(universeBounds);
rootBG.addChild(pointLight);
// add colored cone
Appearance redApp = new Appearance();
Color3f ambientColor = new Color3f(0, 0, 0);
Color3f emissiveColor = new Color3f(0, 0, 0);
Color3f diffuseColor = new Color3f(1, 0, 0);
Color3f specularColor = new Color3f(1, 1, 1);
redApp.setMaterial(new Material(ambientColor, emissiveColor,
diffuseColor, specularColor, 5));
Cone cone = new Cone(0.4f, 0.6f, Primitive.GENERATE_NORMALS, 64, 64,
redApp);
rootBG.addChild(cone);
// create stereo canvas and universe (-> _STEREO_CANVAS_)
GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
template.setStereo(GraphicsConfigTemplate3D.PREFERRED);
template.setSceneAntialiasing(GraphicsConfigTemplate3D.PREFERRED);
GraphicsConfiguration config = GraphicsEnvironment
.getLocalGraphicsEnvironment().getDefaultScreenDevice()
.getBestConfiguration(template);
Canvas3D stereoCanvas = new Canvas3D(config);
SimpleUniverse universe = new SimpleUniverse(stereoCanvas);
// create standard canvas and universe (used only without
// _STEREO_CANVAS_)
// activate 3D stereoscopy with VM argument:
// -Dj3d.stereo=PREFERRED
// SimpleUniverse universe = new SimpleUniverse();
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(rootBG);
// attach orbit behavior for mouse navigation
OrbitBehavior orbit = new OrbitBehavior(universe.getCanvas(),
OrbitBehavior.REVERSE_ALL);
orbit.setSchedulingBounds(universeBounds);
universe.getViewingPlatform().setViewPlatformBehavior(orbit);
// create the window and add the 3D canvas (used only with
// _STEREO_CANVAS_)
JFrame frame = new JFrame();
frame.setSize(new Dimension(200, 200));
frame.setMinimumSize(new Dimension(200, 200));
frame.add(stereoCanvas);
frame.setVisible(true);
}
public static void main(String[] args) {
// start the program
new StereoTestJava3DStandard();
}
}
----------------------------------------------------------------------------------------------------------------
So, if I use this example with standard Java 3D libraries on my computer (incl. PNY/NVIDIA Quadro 4000 + Planar StereoMirror Monitor), the cone is rendered for the left and the right eye. And now - this should be interesting also for Jody - if I use your libraries, then neither the left nor the right perspective is rendered. Exceptionally the centered perspective is rendered (cyclopean perspective). In other words, stereo is completely ignored.
By the way, these are the files found in my build path:
gluegen-rt-natives-windows-i586.jar
j3dcore.jar
j3dutils.jar
joal-natives-windows-i586.jar
jocl-natives-windows-i586.jar
jogl-all-natives-windows-amd64.jar
jogl-all-noawt.jar
jogl-awt.jar
vecmath.jar
You can run the example above in two ways. If you just copy it this way, then it will try to start stereoscopy mode, if it is available by the hardware. The other way is, to use just a completely regular canvas (see the comment in the source code) and use then the VM argument :
-Dj3d.stereo=PREFERRED
This was the standard way how I used all these years the stereo method.
I just tested it now on Windows 7 (64 bit). Of course, I also tested Jody's example. With the old libraries, I see one cone for each eye. With the JOGL J3D libraries, I see only - oh - a black background. I think, this is the case, because Jody's pipeline addresses explicitely the left and right eye.
So, maybe it is really easy for Harvey to fix this problem by just adding some swith, but it might also be a little bit complicated. For example, in J3D you can easily manipulate the eye distance in a stereo environment with this method:
----------------------------------------------------------------------------------------------------------------
public void setEyeDistance(double d) {
Canvas3D canvas = universe.getCanvas();
if (canvas == null)
return;
double lx = -d/2;
Point3d left = new Point3d();
canvas.getView().getPhysicalBody().getLeftEyePosition(left);
left.setX(lx);
double rx = d/2;
Point3d right= new Point3d();
canvas.getView().getPhysicalBody().getRightEyePosition(right);
right.setX(rx);
canvas.setLeftManualEyeInImagePlate(left);
canvas.setRightManualEyeInImagePlate(right);
canvas.getView().getPhysicalBody().setLeftEyePosition(left);
canvas.getView().getPhysicalBody().setRightEyePosition(right);
}
----------------------------------------------------------------------------------------------------------------
So if you - Harvey - already were coding in this area, maybe it runs already, if you attach a small swith. But if you did not work with this PhysicalBody methods, it might be even more work.
So if there are more questions and I can help in this issue, please let me know.
However, thanks a lot for your great work!!!
Björn