Moin Leute,
ich bin gearde dabei zu versuchen ein PDF dokument mittels PDFRenderer auf EINE seite eines Würfels zu bekommen, scheitere aber dabei. Vieleicht könnt ihr mich auf Fehler hinweisen oder verbesserungsvorschläge geben.
vielen dank für die hilfe im voraus.
Gruß
Patrick
ich bin gearde dabei zu versuchen ein PDF dokument mittels PDFRenderer auf EINE seite eines Würfels zu bekommen, scheitere aber dabei. Vieleicht könnt ihr mich auf Fehler hinweisen oder verbesserungsvorschläge geben.
Code:
package eigeneTests;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.behaviors.vp.*;
import javax.swing.JFrame;
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;
public class Universe3D extends JFrame{
Canvas3D myCanvas3D;
public Universe3D(int hight, int width) throws IOException{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myCanvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
SimpleUniverse simpUniv = new SimpleUniverse(myCanvas3D);
simpUniv.getViewingPlatform().setNominalViewingTransform();
createSceneGraph(simpUniv);
addLight(simpUniv);
OrbitBehavior ob = new OrbitBehavior(myCanvas3D);
ob.setSchedulingBounds(new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE));
simpUniv.getViewingPlatform().setViewPlatformBehavior(ob);
setTitle("Eine kleine Animation");
setSize(hight,width);
getContentPane().add("Center", myCanvas3D);
setVisible(true);
}
public void createSceneGraph(SimpleUniverse su) throws IOException{
String filename = "plan.pdf";
File pdf = new File(filename);
RandomAccessFile raf = new RandomAccessFile(pdf, "r");
FileChannel channel = raf.getChannel();
ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
PDFFile pdffile = new PDFFile(buf);
PDFPage page = pdffile.getPage(50);
BufferedImage bi = (BufferedImage) page.getImage((int)page.getWidth(), (int)page.getHeight(), null, null);
//Eine Appearance, um die Plattform Rot zu faerben
Appearance whiteApp = new Appearance();
setToMyDefaultAppearance(whiteApp,new Color3f(0.8f,0.0f,0.0f));
//Halbe Seitenlaenge des Wuerfels, der die Plattform darstellt.
float platformSize = 0.5f;
//Erzeugung der Plattform als Wuerfel
Box platform = new Box(platformSize,platformSize,platformSize,Box.GENERATE_TEXTURE_COORDS |
Box.GENERATE_NORMALS | Box.ENABLE_APPEARANCE_MODIFY, null);
// textur anlegen
Texture2D anteriorTexture = (Texture2D) new TextureLoader(bi, this).getTexture();
anteriorTexture.setEnable(true);
// textur auf box bringen
Shape3D anteriorShape = platform.getShape(Box.FRONT);
Appearance anteriorAppearance = anteriorShape.getAppearance();
anteriorShape.setAppearance(anteriorAppearance);
anteriorAppearance.setColoringAttributes(new
ColoringAttributes(new Color3f(1,0,0), ColoringAttributes.NICEST));
anteriorAppearance.setTexture(anteriorTexture);
//Die Transformationsgruppe der Plattform
TransformGroup tgPlatform = new TransformGroup();
tgPlatform.addChild(platform);
BranchGroup theScene = new BranchGroup();
theScene.addChild(tgPlatform);
//Die folgenden drei Zeilen erzeugen einen weißen Hintergrund.
Background bg = new Background(new Color3f(1.0f,1.0f,1.0f));
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE);
bg.setApplicationBounds(bounds);
theScene.addChild(bg);
theScene.compile();
//Hinzufuegen der Szene
su.addBranchGraph(theScene);
}
public void addLight(SimpleUniverse su){
BranchGroup bgLight = new BranchGroup();
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
Color3f lightColour1 = new Color3f(1.0f,1.0f,1.0f);
Vector3f lightDir1 = new Vector3f(-1.0f,0.0f,-0.5f);
DirectionalLight light1 = new DirectionalLight(lightColour1, lightDir1);
light1.setInfluencingBounds(bounds);
bgLight.addChild(light1);
su.addBranchGraph(bgLight);
}
public static void setToMyDefaultAppearance(Appearance app, Color3f col){
app.setMaterial(new Material(col,col,col,col,120.0f));
}
public static void main(String[] args) throws IOException {
int hight = 800;
int width = 600;
new Universe3D(hight, width);
}
}
vielen dank für die hilfe im voraus.
Gruß
Patrick