Below you will find a simple conversion of HelloUniverse to render to
an offscreen canvas.  It works well except for the fact that paint()
always shows the same face-on view of the colored cube.  Why would the
interpolator not run just as if it was an on-screen canvas?

---------------------------------

import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.image.BufferedImage;

import javax.media.j3d.*;
import javax.swing.JComponent;
import javax.vecmath.Point3d;

import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class ThreeDPreview extends JComponent {

        private final SimpleUniverse universe;

        private final Canvas3D canvas;

        public ThreeDPreview() {

                GraphicsConfiguration config = SimpleUniverse
                                .getPreferredConfiguration();
                canvas = new Canvas3D(config, true);
                universe = new SimpleUniverse(canvas);

                BufferedImage bufferedImage = new BufferedImage(300, 300,
                                BufferedImage.TYPE_INT_RGB);
                ImageComponent2D imageComponent = new ImageComponent2D(
                                ImageComponent.FORMAT_RGBA, bufferedImage);
                canvas.setOffScreenBuffer(imageComponent);
                canvas.setOffScreenLocation(0, 0);

                Screen3D screen = canvas.getScreen3D();
                screen.setSize(1600, 1600);
                screen.setPhysicalScreenWidth(0.5d);
                screen.setPhysicalScreenHeight(0.5d);

                BranchGroup scene = createSceneGraph();
                universe.addBranchGraph(scene);

                universe.getViewingPlatform().setNominalViewingTransform();
        }

        public void paint(Graphics g) {
                canvas.renderOffScreenBuffer();
                canvas.waitForOffScreenRendering();
                g.drawImage(canvas.getOffScreenBuffer().getImage(), 0, 0, this);
        }

        public BranchGroup createSceneGraph() {
                BranchGroup objRoot = new BranchGroup();

                TransformGroup objTrans = new TransformGroup();
                objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
                objRoot.addChild(objTrans);

                objTrans.addChild(new ColorCube(0.4));

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

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

                objRoot.compile();
                return objRoot;
        }

}

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to