List of usage examples for javax.media.j3d Background Background
public Background(BranchGroup branch)
From source file:ViewProj.java
public void init() { setLayout(new BorderLayout()); nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(3);//from w ww .j a va 2 s. c o m GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); JPanel canvasPanel = new JPanel(); GridBagLayout gridbag = new GridBagLayout(); canvasPanel.setLayout(gridbag); canvas = new Canvas3D(config); canvas.setSize(400, 400); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridx = 0; constraints.gridy = 0; constraints.gridwidth = 2; constraints.gridheight = 2; constraints.insets = new Insets(5, 5, 5, 5); constraints.fill = GridBagConstraints.BOTH; gridbag.setConstraints(canvas, constraints); canvasPanel.add(canvas); constraints.fill = GridBagConstraints.REMAINDER; constraints.gridwidth = 1; constraints.gridheight = 1; constraints.gridx = 2; constraints.gridy = 0; urCanvas = new Canvas3D(config); urCanvas.setSize(200, 200); gridbag.setConstraints(urCanvas, constraints); canvasPanel.add(urCanvas); constraints.gridx = 2; constraints.gridy = 1; lrCanvas = new Canvas3D(config); lrCanvas.setSize(200, 200); gridbag.setConstraints(lrCanvas, constraints); canvasPanel.add(lrCanvas); add(canvasPanel, BorderLayout.NORTH); SimpleUniverse u = new SimpleUniverse(canvas); urUniverse = new SimpleUniverse(urCanvas); lrUniverse = new SimpleUniverse(lrCanvas); if (isApplication) { offScreenCanvas = new OffScreenCanvas3D(config, true); // set the size of the off-screen canvas based on a scale // of the on-screen size Screen3D sOn = canvas.getScreen3D(); Screen3D sOff = offScreenCanvas.getScreen3D(); Dimension dim = sOn.getSize(); dim.width *= offScreenScale; dim.height *= offScreenScale; sOff.setSize(dim); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * offScreenScale); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * offScreenScale); // attach the offscreen canvas to the view u.getViewer().getView().addCanvas3D(offScreenCanvas); urOffScreenCanvas = new OffScreenCanvas3D(config, true); // set the size of the off-screen canvas based on a scale // of the on-screen size sOn = urCanvas.getScreen3D(); sOff = urOffScreenCanvas.getScreen3D(); dim = sOn.getSize(); dim.width *= urOffScreenScale; dim.height *= urOffScreenScale; sOff.setSize(dim); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * urOffScreenScale); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * urOffScreenScale); // attach the offscreen canvas to the view urUniverse.getViewer().getView().addCanvas3D(urOffScreenCanvas); lrOffScreenCanvas = new OffScreenCanvas3D(config, true); // set the size of the off-screen canvas based on a scale // of the on-screen size sOn = lrCanvas.getScreen3D(); sOff = lrOffScreenCanvas.getScreen3D(); dim = sOn.getSize(); dim.width *= lrOffScreenScale; dim.height *= lrOffScreenScale; sOff.setSize(dim); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * lrOffScreenScale); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * lrOffScreenScale); // attach the offscreen canvas to the view lrUniverse.getViewer().getView().addCanvas3D(lrOffScreenCanvas); } // Create a simple scene and attach it to the virtual universe BranchGroup scene = createSceneGraph(); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. viewingPlatform = u.getViewingPlatform(); viewingPlatform.setNominalViewingTransform(); view = u.getViewer().getView(); view.setFrontClipPolicy(View.VIRTUAL_EYE); view.setBackClipPolicy(View.VIRTUAL_EYE); view.setFrontClipDistance(frontClipDist); view.setBackClipDistance(backClipDist); u.addBranchGraph(scene); // init the clipGridPts arrays for (int i = 0; i < maxClipGridPts; i++) { clipGridPtsVW[i] = new Point3f(); clipGridPtsProj[i] = new Point3f(); } // init the circlePts arrays for (int i = 0; i < numCirclePts; i++) { circlePtsVW[i] = new Point3f(); circlePtsProj[i] = new Point3f(); } // setup the ur canvas urScene = createVWorldViewSG(); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. urUniverse.getViewingPlatform().setNominalViewingTransform(); View urView = urUniverse.getViewer().getView(); urView.setProjectionPolicy(View.PARALLEL_PROJECTION); urUniverse.addBranchGraph(urScene); // set up the background on a separate BG so that it can stay there // when we replace the scene SG Background urBgWhite = new Background(white); urBgWhite.setApplicationBounds(infiniteBounds); BranchGroup urBackBG = new BranchGroup(); urBackBG.addChild(urBgWhite); urUniverse.addBranchGraph(urBackBG); // setup the lr canvas lrScene = createProjViewSG(); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. lrUniverse.getViewingPlatform().setNominalViewingTransform(); View lrView = lrUniverse.getViewer().getView(); lrView.setProjectionPolicy(View.PARALLEL_PROJECTION); lrUniverse.addBranchGraph(lrScene); // set up the background on a separate BG so that it can stay there // when we replace the scene SG Background lrBgWhite = new Background(white); lrBgWhite.setApplicationBounds(infiniteBounds); BranchGroup lrBackBG = new BranchGroup(); lrBackBG.addChild(lrBgWhite); lrUniverse.addBranchGraph(lrBackBG); // set up the sliders JPanel guiPanel = new JPanel(); guiPanel.setLayout(new GridLayout(0, 2)); FloatLabelJSlider dynamicSlider = new FloatLabelJSlider("Dynamic Offset", 0.1f, 0.0f, 2.0f, dynamicOffset); dynamicSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { dynamicOffset = e.getValue(); solidPa.setPolygonOffsetFactor(dynamicOffset); } }); guiPanel.add(dynamicSlider); LogFloatLabelJSlider staticSlider = new LogFloatLabelJSlider("Static Offset", 0.1f, 10000.0f, staticOffset); staticSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { staticOffset = e.getValue(); solidPa.setPolygonOffset(staticOffset); } }); guiPanel.add(staticSlider); // These are declared final here so they can be changed by the // listener routines below. LogFloatLabelJSlider frontClipSlider = new LogFloatLabelJSlider("Front Clip Distance", 0.001f, 10.0f, frontClipDist); final LogFloatLabelJSlider backClipSlider = new LogFloatLabelJSlider("Back Clip Distance", 1.0f, 10000.0f, backClipDist); final LogFloatLabelJSlider backClipRatioSlider = new LogFloatLabelJSlider("Back Clip Ratio", 1.0f, 10000.0f, backClipRatio); frontClipSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { frontClipDist = e.getValue(); view.setFrontClipDistance(frontClipDist); backClipRatio = backClipDist / frontClipDist; backClipRatioSlider.setValue(backClipRatio); updateViewWindows(); } }); guiPanel.add(frontClipSlider); backClipSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { backClipDist = e.getValue(); backClipRatio = backClipDist / frontClipDist; backClipRatioSlider.setValue(backClipRatio); view.setBackClipDistance(backClipDist); updateViewWindows(); } }); guiPanel.add(backClipSlider); backClipRatioSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { backClipRatio = e.getValue(); backClipDist = backClipRatio * frontClipDist; backClipSlider.setValue(backClipDist); updateViewWindows(); } }); guiPanel.add(backClipRatioSlider); FloatLabelJSlider innerSphereSlider = new FloatLabelJSlider("Inner Sphere Scale", 0.001f, 0.90f, 1.0f, innerScale); innerSphereSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { innerScale = e.getValue(); updateInnerScale(); } }); guiPanel.add(innerSphereSlider); JButton mainSnap = new JButton(snapImageString); mainSnap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Point loc = canvas.getLocationOnScreen(); offScreenCanvas.setOffScreenLocation(loc); Dimension dim = canvas.getSize(); dim.width *= offScreenScale; dim.height *= offScreenScale; nf.setMinimumIntegerDigits(3); offScreenCanvas.snapImageFile(outFileBase + nf.format(outFileSeq++), dim.width, dim.height); nf.setMinimumIntegerDigits(0); } }); guiPanel.add(mainSnap); JButton urSnap = new JButton(urSnapImageString); urSnap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Snap UR"); Point loc = urCanvas.getLocationOnScreen(); urOffScreenCanvas.setOffScreenLocation(loc); Dimension dim = urCanvas.getSize(); dim.width *= urOffScreenScale; dim.height *= urOffScreenScale; nf.setMinimumIntegerDigits(3); urOffScreenCanvas.snapImageFile(urOutFileBase + nf.format(urOutFileSeq++), dim.width, dim.height); nf.setMinimumIntegerDigits(0); } }); guiPanel.add(urSnap); JButton lrSnap = new JButton(lrSnapImageString); lrSnap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Snap LR"); Point loc = lrCanvas.getLocationOnScreen(); lrOffScreenCanvas.setOffScreenLocation(loc); Dimension dim = lrCanvas.getSize(); dim.width *= lrOffScreenScale; dim.height *= lrOffScreenScale; nf.setMinimumIntegerDigits(3); lrOffScreenCanvas.snapImageFile(lrOutFileBase + nf.format(lrOutFileSeq++), dim.width, dim.height); nf.setMinimumIntegerDigits(0); } }); guiPanel.add(lrSnap); add(guiPanel, BorderLayout.SOUTH); }
From source file:AppearanceExplorer.java
BackgroundTool(String codeBaseString) { bgSwitch = new Switch(Switch.CHILD_NONE); bgSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); // set up the dark grey BG color node Background bgDarkGrey = new Background(darkGrey); bgDarkGrey.setApplicationBounds(infiniteBounds); bgSwitch.addChild(bgDarkGrey);/* w w w . ja v a2s . co m*/ // set up the grey BG color node Background bgGrey = new Background(grey); bgGrey.setApplicationBounds(infiniteBounds); bgSwitch.addChild(bgGrey); // set up the light grey BG color node Background bgLightGrey = new Background(lightGrey); bgLightGrey.setApplicationBounds(infiniteBounds); bgSwitch.addChild(bgLightGrey); // set up the white BG color node Background bgWhite = new Background(white); bgWhite.setApplicationBounds(infiniteBounds); bgSwitch.addChild(bgWhite); // set up the blue BG color node Background bgBlue = new Background(skyBlue); bgBlue.setApplicationBounds(infiniteBounds); bgSwitch.addChild(bgBlue); // set up the image java.net.URL bgImageURL = null; try { bgImageURL = new java.net.URL(codeBaseString + "bg.jpg"); } catch (java.net.MalformedURLException ex) { System.out.println(ex.getMessage()); System.exit(1); } if (bgImageURL == null) { // application, try file URL try { bgImageURL = new java.net.URL("file:./bg.jpg"); } catch (java.net.MalformedURLException ex) { System.out.println(ex.getMessage()); System.exit(1); } } TextureLoader bgTexture = new TextureLoader(bgImageURL, null); // Create a background with the static image Background bgImage = new Background(bgTexture.getImage()); bgImage.setApplicationBounds(infiniteBounds); bgSwitch.addChild(bgImage); // create a background with the image mapped onto a sphere which // will enclose the world Background bgGeo = new Background(); bgGeo.setApplicationBounds(infiniteBounds); BranchGroup bgGeoBG = new BranchGroup(); Appearance bgGeoApp = new Appearance(); bgGeoApp.setTexture(bgTexture.getTexture()); Sphere sphereObj = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_NORMALS_INWARD | Sphere.GENERATE_TEXTURE_COORDS, 45, bgGeoApp); bgGeoBG.addChild(sphereObj); bgGeo.setGeometry(bgGeoBG); bgSwitch.addChild(bgGeo); // Create the chooser GUI String[] bgNames = { "No Background (Black)", "Dark Grey", "Grey", "Light Grey", "White", "Blue", "Sky Image", "Sky Geometry", }; int[] bgValues = { Switch.CHILD_NONE, 0, 1, 2, 3, 4, 5, 6 }; bgChooser = new IntChooser("Background:", bgNames, bgValues, 0); bgChooser.addIntListener(new IntListener() { public void intChanged(IntEvent event) { int value = event.getValue(); bgSwitch.setWhichChild(value); } }); bgChooser.setValue(Switch.CHILD_NONE); }