Hello everybody.
Didn’t find a solution searching here or in google. Perhaps someone can forward me to some hints or help me out a little bit. I’m just starting off with Java3D. Normal display and manipulation of my universe works fine, but now I’m getting into tricky parts…
My overall goal is to display java3D-objects above an image or video, where the 3d stuff is occluded by real-life-objects out of the (video)image. Of course I don’t get the 3d-info out of my image, but I rather have a prepared mask for occlusion or representative 3d-models for that (which I don’t want to draw but only use for occlusion).
Unfortunatelly I didn’t find out how it would be possible to use 3d-models only for filling the z-Buffer, but not the display… (java3D seems to be TOO high-level for that).
Any idea?
My other plan is to grab the canvas3D-image as a BufferedImage, do an AND-operation with my mask-image and underlay the result with the background-image. This works fine for the first frame, but (and here I get to the point) if I have any Behaviours in my world changing positions for example the Canvas3D does not update itself… and my grabbed image of the 3D-world is always the first one…
Functions like renderOffScreenBuffer() or startRenderer() don’t seem to change a thing…
Any advice how to still get a 3D-world in a Canvas3D to run, which is NOT displayed directly (only drawn offscreen)?
Here some sourcecode:
public class Something extends Frame implements KeyListener
{
BufferedImage bImage;
...
setLayout(new FlowLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
// initialise canvas OFFSCREEN (flag = true)
canvas3D = new Canvas3D(config, true);
canvas3D.getScreen3D().setSize(350, 350);
canvas3D.getScreen3D().setPhysicalScreenWidth(0.254 / 90.0 * xsize);
canvas3D.getScreen3D().setPhysicalScreenHeight(0.254 / 90.0 * ysize);
...
// creates some objects and Behaviours which don't need user interaction
BranchGroup scene = createSceneGraph();
SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
simpleU.getViewingPlatform().setNominalViewingTransform();
simpleU.addBranchGraph(scene);
...
bImage = new BufferedImage(350, 350, BufferedImage.TYPE_4BYTE_ABGR);
ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA, bImage);
canvas3D.setOffScreenBuffer(buffer);
canvas3D.renderOffScreenBuffer();
canvas3D.waitForOffScreenRendering();
bImage = canvas3D.getOffScreenBuffer().getImage();
// I add the buffered image to some panel, afterwards I see the first frame of the world in it
// ImagePanel extend Canvas
ImagePanel panel = new ImagePanel(bImage);
add(panel);
...
// after this I can see the Canvas in my Frame displaying the BufferedImage-copy of the 3dworld... but only the first frame
// I defined a keyListener to my Frame which triggers this:
public void update3DView()
{
canvas3D.startRenderer();
canvas3D.renderOffScreenBuffer();
canvas3D.waitForOffScreenRendering();
bImage = canvas3D.getOffScreenBuffer().getImage();
// whatever I try it does not trigger an update
panel.repaint();
canvas3D.repaint();
repaint();
}
Well. That’s it so far.
Don’t know where the error could lie…
some missing calls for the canvas3D/theUniverse, some missing AWT update, … hmm.
If I use the same universe created by createSceneGraph() with an onscreen Canvas3D all animation is triggered perfectly.
Thanks in advance,
cu,
Konterfei.