Hi there.
First of all I beg you to ignore my bad english. I'm not used to write in such great extends. ^^
My problem is following:
At the moment I try to create Thumbnails of 3DModels. This happens while the program runs, because i need it to happen dynamicly.
My code (see below) runs without errors or warnings, but the saved thumbnail is only a black image.
(The Code is splitted into two methods, the names are self-explaining. )
public void createThumbnail() throws Exception {
if (!(loader.getModel() instanceof Spatial)) {
throw new Exception("The Spatial was not initialized yet. Can't create Thumbnail!");
}
TextureRenderer tRender=DisplaySystem.getDisplaySystem().createTextureRenderer(100, 100, TextureRenderer.Target.Texture2D);
Texture2D rTex=new Texture2D();
tRender.getCamera().setLocation(new Vector3f(0,0,5f));
tRender.setBackgroundColor(ColorRGBA.darkGray);
tRender.setupTexture(rTex);
tRender.render(loader.getModel(), rTex);
saveThumbnail(rTex);
}
public boolean saveThumbnail(Texture2D tex) {
try {
FileOutputStream out = new FileOutputStream(ConstantList.thumbnail_dir + Name + ".jpeg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
BufferedImage image=new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
image.getGraphics().drawImage(ImageUtils.makeAwtImage(tex.getImage()), 0, 0, new Label()); // The Label works as a dummy-imageobserver
JPEGEncodeParam param = JPEGCodec.getDefaultJPEGEncodeParam(image);
encoder.setJPEGEncodeParam(param);
encoder.encode(image);
System.out.println("Thumbnail saved succesfull.");
} catch (Exception e) {
System.out.println(e.getMessage());
return false;
}
return true;
}
The model was load succesfull btw. All used methods work fine... i suppose. I think my problem is something with the jme stuff. It's new for me, so it don't know, how to handel it. I'm working at this problem for some days now and my backup of ideas is running dry...
Has anyone of you oldstagers an idea where my problem is? ( And if so, how to fix it? :P )
Greetings, Kuro Sei