Attached is the version that works and an image showing the output.
I'm not sure I really understand why, but the image size you're producing is not equal to the size of screen otherwise nowt works...
Remember the screen size in on screen mode is the resolution of the screen. For the sake of this experiment I set it to 500x500.
Hope this helps,
Kev
Bj�rn Voigt wrote:
Kevin Glass schrieb:
I tried it and the other, but it does not work, could you run this code on your machine, that I know, that my configuration is OK?
Thank for the time, you are spending for my problem.
Bj�rn
Try changing
test.u = new SimpleUniverse();
to
test.u = new SimpleUniverse(c);
And take out your view lines...
I assume this is the same thing, but its how I got it to work..
Kev
Hi Kevin,
thank you for your fast reply, but it still not work
Looking at the code for model2sprite (http://model2sprite.dev.java.net) three things might be worth trying:
1) Make sure rendering your scene to a normal canvas actually shows something.
This works , I use the HelloUniverse Demo with a cube3d and a normal canvas shows the Image without problems.
2) Try using c.getOffscreenBuffer().getImage() after the rendering instead of relying on you're original image.
This was not successful, but this the same like using the reference of the BufferedImage I used to create the Buffer.
There was Nothing after 100 renderings3) Try causing the scene to render a few times (c.renderOffScreenBuffer(),c.waitForOffScreenRendering()) before using the image, since some behaviors need a few frames to get going.
Shit !!!!!!!!
Homepage!I'm not sure what you're doing with the View.addCanvas3D() thing, its not quite the same as how I did it. If you're interested it might be worth checking out the org/newdawn/model2sprite/OffscreenCanvas3D.java from CVS on the java.net site above.
Kev
Hello Java3d Fans,
I am a Java3d beginner and want to programm an servlet, which create an JPEG of a JAVA3d-Scene.
I wrote a test class using Canvas 3d in offscreen mode, but all I get is an empty Image. What did I wrong? I hope you can help me to fix this ...
Thank you
Here is the program:
[...]
public class Test {
private SimpleUniverse u;
public Test(){}
public BranchGroup createSceneGraph(){ [...] return objRoot; }
public static void main(String[] args) { Test test = new Test(); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D c = new Canvas3D(config,true); Screen3D sOff = c.getScreen3D();
c.getScreen3D().setSize(100,100); c.getScreen3D().setPhysicalScreenWidth( (0.0254/90.0)* 100); c.getScreen3D().setPhysicalScreenHeight((0.0254/90.0)* 100);
BranchGroup scene = test.createSceneGraph(); test.u = new SimpleUniverse();
test.u.getViewingPlatform().setNominalViewingTransform(); test.u.addBranchGraph(scene);
View v = test.u.getViewer().getView(); v.addCanvas3D(c);
BufferedImage bImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGB, bImage);
buffer.setCapability(ImageComponent2D.ALLOW_IMAGE_READ);
c.setOffScreenBuffer(buffer); c.renderOffScreenBuffer(); c.waitForOffScreenRendering();
try { DataOutputStream output = new DataOutputStream(new FileOutputStream("C:\\borstels-offscreen-test.jpg")); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output); encoder.encode(bImage); output.flush(); output.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
Thank you for helping
Bj�rn
--
+++ GMX - Mail, Messaging & more http://www.gmx.net +++ Bitte l�cheln! Fotogalerie online mit GMX ohne eigene
===========================================================================
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".
-- Jose UML - http://www.newdawnsoftware.com/jose Warlock - http://www.cokeandcode.com/warlock
===========================================================================
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".
-- +++ GMX - Mail, Messaging & more http://www.gmx.net +++ Bitte l�cheln! Fotogalerie online mit GMX ohne eigene Homepage!
===========================================================================
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".
-- Jose UML - http://www.newdawnsoftware.com/jose Warlock - http://www.cokeandcode.com/warlock
===========================================================================
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".
===========================================================================
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".
/* * Test.java * * Created on 30 June 2003, 18:40 */
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.Screen3D;
import javax.media.j3d.View;
import javax.media.j3d.ImageComponent2D;
import javax.media.j3d.ImageComponent;
import com.sun.j3d.utils.universe.SimpleUniverse;
import java.awt.GraphicsConfiguration;
import java.awt.image.BufferedImage;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.sun.j3d.utils.geometry.Sphere;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Vector3d;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.GridLayout;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class Test {
private SimpleUniverse u;
public Test(){}
public BranchGroup createSceneGraph() {
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();
// Create the TransformGroup node and initialize it to the
// identity. Enable the TRANSFORM_WRITE capability so that
// our behavior code can modify it at run time. Add it to
// the root of the subgraph.
TransformGroup objTrans = new TransformGroup();
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(objTrans);
// Create a simple Shape3D node; add it to the scene graph.
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);
// Have Java 3D perform optimizations on this scene graph.
objRoot.compile();
return objRoot;
}
public static void main(String[] args) {
int width = 100;
int height = 100;
Test test = new Test();
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
// offscreen
Canvas3D c = new Canvas3D(config,true);
c.getScreen3D().setSize(500,500);
c.getScreen3D().setPhysicalScreenWidth(0.0254/90.0 * 500);
c.getScreen3D().setPhysicalScreenHeight(0.0254/90.0 * 500);
BranchGroup scene = test.createSceneGraph();
test.u = new SimpleUniverse(c);
test.u.addBranchGraph(scene);
test.u.getViewingPlatform().setNominalViewingTransform();
BufferedImage bImage = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
ImageComponent2D buffer = new
ImageComponent2D(ImageComponent.FORMAT_RGB,bImage);
//buffer.setCapability(ImageComponent2D.ALLOW_IMAGE_READ);
System.out.println("Rendering...");
c.setOffScreenBuffer(buffer);
c.renderOffScreenBuffer();
c.waitForOffScreenRendering();
bImage = c.getOffScreenBuffer().getImage();
System.out.println("Saving..");
try {
DataOutputStream output = new DataOutputStream(new
FileOutputStream("test-image.jpg"));
ImageIO.write(bImage,"JPEG",output);
output.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("DONE!");
System.exit(0);
}
}
<<inline: test-image.jpg>>
