Example usage for javax.media.j3d Canvas3D Canvas3D

List of usage examples for javax.media.j3d Canvas3D Canvas3D

Introduction

In this page you can find the example usage for javax.media.j3d Canvas3D Canvas3D.

Prototype

public Canvas3D(GraphicsConfiguration graphicsConfiguration) 

Source Link

Document

Constructs and initializes a new Canvas3D object that Java 3D can render into.

Usage

From source file:HelloWorld.java

public static void main(String[] args) {
    Frame frame = new Frame();
    frame.setSize(640, 480);/*  w  ww . ja  va2 s  . c o  m*/
    frame.setLayout(new BorderLayout());

    Canvas3D canvas = new Canvas3D(null);
    frame.add("Center", canvas);

    SimpleUniverse univ = new SimpleUniverse(canvas);
    univ.getViewingPlatform().setNominalViewingTransform();

    BranchGroup scene = createSceneGraph();
    scene.compile();
    univ.addBranchGraph(scene);

    frame.show();
}

From source file:QueryProperties.java

public static void main(String[] args) {
    VirtualUniverse vu = new VirtualUniverse();
    Map vuMap = vu.getProperties();

    System.out.println("version = " + vuMap.get("j3d.version"));
    System.out.println("vendor = " + vuMap.get("j3d.vendor"));
    System.out.println("specification.version = " + vuMap.get("j3d.specification.version"));
    System.out.println("specification.vendor = " + vuMap.get("j3d.specification.vendor"));
    System.out.println("renderer = " + vuMap.get("j3d.renderer") + "\n");

    GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();

    /*//from   ww  w.ja  va2 s . com
     * We need to set this to force choosing a pixel format that support the
     * canvas.
     */
    template.setStereo(template.PREFERRED);
    template.setSceneAntialiasing(template.PREFERRED);

    GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
            .getBestConfiguration(template);

    Map c3dMap = new Canvas3D(config).queryProperties();

    System.out.println("Renderer version = " + c3dMap.get("native.version"));
    System.out.println("doubleBufferAvailable = " + c3dMap.get("doubleBufferAvailable"));
    System.out.println("stereoAvailable = " + c3dMap.get("stereoAvailable"));
    System.out.println("sceneAntialiasingAvailable = " + c3dMap.get("sceneAntialiasingAvailable"));
    System.out.println("sceneAntialiasingNumPasses = " + c3dMap.get("sceneAntialiasingNumPasses"));
    System.out.println("textureColorTableSize = " + c3dMap.get("textureColorTableSize"));
    System.out.println("textureEnvCombineAvailable = " + c3dMap.get("textureEnvCombineAvailable"));
    System.out.println("textureCombineDot3Available = " + c3dMap.get("textureCombineDot3Available"));
    System.out.println("textureCombineSubtractAvailable = " + c3dMap.get("textureCombineSubtractAvailable"));
    System.out.println("texture3DAvailable = " + c3dMap.get("texture3DAvailable"));
    System.out.println("textureCubeMapAvailable = " + c3dMap.get("textureCubeMapAvailable"));
    System.out.println("textureSharpenAvailable = " + c3dMap.get("textureSharpenAvailable"));
    System.out.println("textureDetailAvailable = " + c3dMap.get("textureDetailAvailable"));
    System.out.println("textureFilter4Available = " + c3dMap.get("textureFilter4Available"));
    System.out
            .println("textureAnisotropicFilterDegreeMax = " + c3dMap.get("textureAnisotropicFilterDegreeMax"));
    System.out.println("textureBoundaryWidthMax = " + c3dMap.get("textureBoundaryWidthMax"));
    System.out.println("textureWidthMax = " + c3dMap.get("textureWidthMax"));
    System.out.println("textureHeightMax = " + c3dMap.get("textureHeightMax"));
    System.out.println("textureLodOffsetAvailable = " + c3dMap.get("textureLodOffsetAvailable"));
    System.out.println("textureLodRangeAvailable = " + c3dMap.get("textureLodRangeAvailable"));
    System.out.println("textureUnitStateMax = " + c3dMap.get("textureUnitStateMax"));
    System.out.println(
            "compressedGeometry.majorVersionNumber = " + c3dMap.get("compressedGeometry.majorVersionNumber"));
    System.out.println(
            "compressedGeometry.minorVersionNumber = " + c3dMap.get("compressedGeometry.minorVersionNumber"));
    System.out.println("compressedGeometry.minorMinorVersionNumber = "
            + c3dMap.get("compressedGeometry.minorMinorVersionNumber"));

    System.exit(0);
}

From source file:Rotation.java

public void init() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    canvas3D = new Canvas3D(config);
    add("Center", canvas3D);
    BranchGroup szene = macheSzene();//from   w w w .j a  v a 2  s . c  o m
    szene.compile();
    universe = new SimpleUniverse(canvas3D);
    universe.getViewingPlatform().setNominalViewingTransform();
    universe.addBranchGraph(szene);
}

From source file:CanvasDemo.java

public CanvasDemo() {

    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    Canvas3D canvas = new Canvas3D(config);
    add("North", new Label("This is the top"));
    add("Center", canvas);
    add("South", new Label("This is the bottom"));
    BranchGroup contents = new BranchGroup();
    contents.addChild(new ColorCube(0.3));
    SimpleUniverse universe = new SimpleUniverse(canvas);
    universe.getViewingPlatform().setNominalViewingTransform();
    universe.addBranchGraph(contents);/*ww w .  j a va 2s  .c  o m*/
}

From source file:HelloJava3Da.java

public HelloJava3Da() {
    setLayout(new BorderLayout());
    Canvas3D canvas3D = new Canvas3D(null);
    add("Center", canvas3D);

    BranchGroup scene = createSceneGraph();

    // SimpleUniverse is a Convenience Utility class
    SimpleUniverse simpleU = new SimpleUniverse(canvas3D);

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    simpleU.getViewingPlatform().setNominalViewingTransform();

    simpleU.addBranchGraph(scene);//from   w w  w  .  j a  va 2  s .c  o m
}

From source file:BooksDemo.java

public BooksDemo() {
    super("AmazonPick");

    JButton cover1 = UIHelper.createButton("", "cover1_small_button", true);
    cover1.addActionListener(new CoverSwitcher("cover1"));
    JButton cover2 = UIHelper.createButton("", "cover2_small_button", true);
    cover2.addActionListener(new CoverSwitcher("cover2"));
    JButton cover3 = UIHelper.createButton("", "cover3_small_button", true);
    cover3.addActionListener(new CoverSwitcher("cover3"));

    JPanel buttons = new JPanel();
    buttons.add(cover1);//from   www . j  av a  2  s  .c  o m
    buttons.add(cover2);
    buttons.add(cover3);
    buttons.setOpaque(false);

    c3d = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
    c3d.setSize(CANVAS3D_WIDTH, CANVAS3D_HEIGHT);

    xpanel.add(c3d);
    xpanel.setOpaque(false);

    this.setContentPane(new GradientPanel());
    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add(xpanel, BorderLayout.CENTER);
    this.getContentPane().add(buttons, BorderLayout.SOUTH);
    this.pack();
    this.setResizable(false);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    UIHelper.centerOnScreen(this);
}

From source file:BasicConstruct.java

/**
 * Perform the essential setups for the Java3D
 *//*from w  ww.  java  2s  .c o  m*/
protected void initial_setup() {
    // A JFrame is a Container -- something that can hold
    // other things, e.g a button, a textfield, etc..
    // however, for a container to hold something, you need
    // to specify the layout of the storage. For our
    // example, we would like to use a BorderLayout.
    // The next line does just this:
    getContentPane().setLayout(new BorderLayout());

    // The next step is to setup graphics configuration
    // for Java3D. Since different machines/OS have differnt
    // configuration for displaying stuff, therefore, for
    // java3D to work, it is important to obtain the correct
    // graphics configuration first.
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    // Since we are doing stuff via java3D -- meaning we
    // cannot write pixels directly to the screen, we need
    // to construct a "canvas" for java3D to "paint". And
    // this "canvas" will be constructed with the graphics
    // information we just obtained.
    Canvas3D canvas3D = new Canvas3D(config);

    // And we need to add the "canvas to the centre of our
    // window..
    getContentPane().add("Center", canvas3D);

    // Creates the universe
    simpleU = new SimpleUniverse(canvas3D);

    // First create the BranchGroup object
    rootBranchGroup = new BranchGroup();
}

From source file:HelloJava3Dbalt.java

public HelloJava3Dbalt() {
    setLayout(new BorderLayout());
    Canvas3D canvas3D = new Canvas3D(null);
    add("Center", canvas3D);

    BranchGroup scene = createSceneGraph();

    // SimpleUniverse is a Convenience Utility class
    SimpleUniverse simpleU = new SimpleUniverse(canvas3D);

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    simpleU.getViewingPlatform().setNominalViewingTransform();

    simpleU.addBranchGraph(scene);//from   w w  w.j a v  a  2s. c  om
}

From source file:HelloJava3Db.java

public HelloJava3Db() {
    setLayout(new BorderLayout());
    Canvas3D canvas3D = new Canvas3D(null);
    add("Center", canvas3D);

    BranchGroup scene = createSceneGraph();

    // SimpleUniverse is a Convenience Utility class
    SimpleUniverse simpleU = new SimpleUniverse(canvas3D);

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    simpleU.getViewingPlatform().setNominalViewingTransform();

    simpleU.addBranchGraph(scene);/*from  w w w . ja  va 2s  .co  m*/
}

From source file:mytrack.SimpleModelView.java

/**
 * Defines basic properties of the canvas. 
 *///from  w  w w.j a  va  2 s  .  c  om
private void configureCanvas() {
    canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
    canvas.setDoubleBufferEnable(true);
    getContentPane().add(canvas, BorderLayout.CENTER);
}