public void hide () { offscreenGroup.removeChild(bg); onscreenGroup.removeChild(bg); }
public void hide () { offscreenGroup.removeChild(bg); onscreenGroup.removeChild(bg); }
private static void render3D () { rootGroup.addChild(offscreenGroup); if (clear3D) { clear3D = false; rootGroup.removeChild(onscreenGroup); onscreenGroup = offscreenGroup; } else { Enumeration children = offscreenGroup.getAllChildren(); while(children.hasMoreElements()) { Node child = (Node)children.nextElement(); offscreenGroup.removeChild(child); onscreenGroup.addChild(child); } } offscreenGroup = createBranchGroup(); //System.out.println("off = " + offscreenGroup.numChildren()); //System.out.println("on = " + onscreenGroup.numChildren()); rootGroup.removeChild(offscreenGroup); //StdOut.println("showed once = true"); } /* ***************************************************************
private static void render3D () { rootGroup.addChild(offscreenGroup); if (clear3D) { clear3D = false; rootGroup.removeChild(onscreenGroup); onscreenGroup = offscreenGroup; } else { Enumeration children = offscreenGroup.getAllChildren(); while(children.hasMoreElements()) { Node child = (Node)children.nextElement(); offscreenGroup.removeChild(child); onscreenGroup.addChild(child); } } offscreenGroup = createBranchGroup(); //System.out.println("off = " + offscreenGroup.numChildren()); //System.out.println("on = " + onscreenGroup.numChildren()); rootGroup.removeChild(offscreenGroup); //StdOut.println("showed once = true"); } /* ***************************************************************
/** * Combines any number of shapes into one shape and returns it. */ public static Shape combine (Shape... shapes) { BranchGroup combinedGroup = createBranchGroup(); TransformGroup combinedTransform = new TransformGroup(); for (int i = 0; i < shapes.length; i++) { BranchGroup bg = shapes[i].bg; TransformGroup tg = shapes[i].tg; offscreenGroup.removeChild(bg); onscreenGroup.removeChild(bg); bg.removeChild(tg); combinedTransform.addChild(shapes[i].tg); } combinedGroup.addChild(combinedTransform); offscreenGroup.addChild(combinedGroup); return new Shape(combinedGroup, combinedTransform); }
/** * Combines any number of shapes into one shape and returns it. */ public static Shape combine (Shape... shapes) { BranchGroup combinedGroup = createBranchGroup(); TransformGroup combinedTransform = new TransformGroup(); for (int i = 0; i < shapes.length; i++) { BranchGroup bg = shapes[i].bg; TransformGroup tg = shapes[i].tg; offscreenGroup.removeChild(bg); onscreenGroup.removeChild(bg); bg.removeChild(tg); combinedTransform.addChild(shapes[i].tg); } combinedGroup.addChild(combinedTransform); offscreenGroup.addChild(combinedGroup); return new Shape(combinedGroup, combinedTransform); }
/** * Sets the background image to the given filename, scaled to fit the window. * * @param imageURL The filename for the background image. */ public static void setBackground (String imageURL) { rootGroup.removeChild(bgGroup); bgGroup.removeChild(background); background = createBackground(); BufferedImage bi = null; try { bi = ImageIO.read(new File(imageURL)); } catch (IOException ioe) {ioe.printStackTrace(); } if (bi == null) { try { ImageIO.read(new URL(imageURL)); } catch (Exception e) { e.printStackTrace(); } } ImageComponent2D imageComp = new ImageComponent2D(ImageComponent.FORMAT_RGB, bi); background.setImage(imageComp); background.setImageScaleMode(Background.SCALE_FIT_ALL); bgGroup.addChild(background); rootGroup.addChild(bgGroup); }
/** * Sets the background image to the given filename, scaled to fit the window. * * @param imageURL The filename for the background image. */ public static void setBackground (String imageURL) { rootGroup.removeChild(bgGroup); bgGroup.removeChild(background); background = createBackground(); BufferedImage bi = null; try { bi = ImageIO.read(new File(imageURL)); } catch (IOException ioe) {ioe.printStackTrace(); } if (bi == null) { try { ImageIO.read(new URL(imageURL)); } catch (Exception e) { e.printStackTrace(); } } ImageComponent2D imageComp = new ImageComponent2D(ImageComponent.FORMAT_RGB, bi); background.setImage(imageComp); background.setImageScaleMode(Background.SCALE_FIT_ALL); bgGroup.addChild(background); rootGroup.addChild(bgGroup); }
/** * Sets the background color to the given color. * * @param color The color to set the background as. */ public static void setBackground (Color color) { if (!color.equals(bgColor)) { bgColor = color; rootGroup.removeChild(bgGroup); bgGroup.removeChild(background); background = createBackground(); background.setColor(new Color3f(bgColor)); bgGroup.addChild(background); rootGroup.addChild(bgGroup); } }
/** * Sets the background color to the given color. * * @param color The color to set the background as. */ public static void setBackground (Color color) { if (!color.equals(bgColor)) { bgColor = color; rootGroup.removeChild(bgGroup); bgGroup.removeChild(background); background = createBackground(); background.setColor(new Color3f(bgColor)); bgGroup.addChild(background); rootGroup.addChild(bgGroup); } }
/** * Sets the background to the given image file. The file gets * wrapped around as a spherical skybox. * * @param imageURL The background image to use. */ public static void setBackgroundSphere (String imageURL) { Sphere sphere = new Sphere(1.1f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_NORMALS_INWARD | Sphere.GENERATE_TEXTURE_COORDS, numDivisions); Appearance ap = sphere.getAppearance(); Texture texture = createTexture(imageURL); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.REPLACE); ap.setTexture(texture); ap.setTextureAttributes(texAttr); sphere.setAppearance(ap); BranchGroup backGeoBranch = createBranchGroup(); backGeoBranch.addChild(sphere); rootGroup.removeChild(bgGroup); bgGroup.removeChild(background); background = createBackground(); background.setGeometry(backGeoBranch); bgGroup.addChild(background); rootGroup.addChild(bgGroup); }
/** * Sets the background to the given image file. The file gets * wrapped around as a spherical skybox. * * @param imageURL The background image to use. */ public static void setBackgroundSphere (String imageURL) { Sphere sphere = new Sphere(1.1f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_NORMALS_INWARD | Sphere.GENERATE_TEXTURE_COORDS, numDivisions); Appearance ap = sphere.getAppearance(); Texture texture = createTexture(imageURL); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.REPLACE); ap.setTexture(texture); ap.setTextureAttributes(texAttr); sphere.setAppearance(ap); BranchGroup backGeoBranch = createBranchGroup(); backGeoBranch.addChild(sphere); rootGroup.removeChild(bgGroup); bgGroup.removeChild(background); background = createBackground(); background.setGeometry(backGeoBranch); bgGroup.addChild(background); rootGroup.addChild(bgGroup); }