List of usage examples for javax.media.j3d Switch CHILD_ALL
int CHILD_ALL
To view the source code for javax.media.j3d Switch CHILD_ALL.
Click Source Link
From source file:SwitchTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); double labelScale = 20; // flip this boolean to either display all // the child nodes or to just display the 3, 6 and 7th. final boolean bDisplayAll = false; // create the Switch Node int nMode = Switch.CHILD_ALL; if (bDisplayAll == false) nMode = Switch.CHILD_MASK;//from ww w .j av a2s . c o m Switch switchGroup = new Switch(nMode); switchGroup.setCapability(Switch.ALLOW_SWITCH_WRITE); switchGroup.addChild(createLabel("Child Node 1", labelScale)); switchGroup.addChild(createLabel("Child Node 2", labelScale)); switchGroup.addChild(createLabel("Child Node 3", labelScale)); switchGroup.addChild(createLabel("Child Node 4", labelScale)); switchGroup.addChild(createLabel("Child Node 5", labelScale)); switchGroup.addChild(createLabel("Child Node 6", labelScale)); switchGroup.addChild(createLabel("Child Node 7", labelScale)); if (bDisplayAll == false) { java.util.BitSet visibleNodes = new java.util.BitSet(switchGroup.numChildren()); // make the third, sixth and seventh nodes visible visibleNodes.set(2); visibleNodes.set(5); visibleNodes.set(6); switchGroup.setChildMask(visibleNodes); } // finally add the Switch Node objRoot.addChild(switchGroup); return objRoot; }
From source file:LightBug.java
void setupSpheres() { // create a Switch for the spheres, allow switch changes spheresSwitch = new Switch(Switch.CHILD_ALL); spheresSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); // Set up an appearance to make the Sphere with red ambient, // black emmissive, red diffuse and white specular coloring Material material = new Material(red, black, red, white, 64); Appearance appearance = new Appearance(); appearance.setMaterial(material);/*from w ww .j a va2s . c om*/ // create a sphere and put it into a shared group Sphere sphere = new Sphere(0.5f, appearance); SharedGroup sphereSG = new SharedGroup(); sphereSG.addChild(sphere); // create a grid of spheres in the z=0 plane // each has a TransformGroup to position the sphere which contains // a link to the shared group for the sphere for (int y = -2; y <= 2; y++) { for (int x = -2; x <= 2; x++) { TransformGroup tg = new TransformGroup(); tmpVector.set(x * 1.2f, y * 1.2f, 0.0f); tmpTrans.set(tmpVector); tg.setTransform(tmpTrans); tg.addChild(new Link(sphereSG)); spheresSwitch.addChild(tg); } } }
From source file:EnvironmentExplorer.java
void setupSpheres() { // create a Switch for the spheres, allow switch changes spheresSwitch = new Switch(Switch.CHILD_ALL); spheresSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); // Set up an appearance to make the Sphere with objColor ambient, // black emmissive, objColor diffuse and white specular coloring Material material = new Material(objColor, black, objColor, white, 32); Appearance appearance = new Appearance(); appearance.setMaterial(material);/*from ww w . j a va 2s .c o m*/ // create a sphere and put it into a shared group Sphere sphere = new Sphere(0.5f, appearance); SharedGroup sphereSG = new SharedGroup(); sphereSG.addChild(sphere); // create a grid of spheres in the z=0 plane // each has a TransformGroup to position the sphere which contains // a link to the shared group for the sphere for (int y = -2; y <= 2; y++) { for (int x = -2; x <= 2; x++) { TransformGroup tg = new TransformGroup(); tmpVector.set(x * 1.2f, y * 1.2f, -0.1f); tmpTrans.set(tmpVector); tg.setTransform(tmpTrans); tg.addChild(new Link(sphereSG)); spheresSwitch.addChild(tg); } } }
From source file:ffx.potential.MolecularAssembly.java
/** * The MolecularAssembly BranchGroup has two TransformGroups between it and * the "base" node where geometry is attached. If the point between the two * transformations is where user rotation occurs. For example, if rotating * about the center of mass of the system, the RotToCOM transformation will * be an identity transformation (ie. none). If rotation is about some atom * or group of atoms within the system, then the RotToCOM transformation * will be a translation from that point to the COM. * * @param zero boolean//www . ja va 2 s.c om * @return BranchGroup */ public BranchGroup createScene(boolean zero) { originToRotT3D = new Transform3D(); originToRotV3D = new Vector3d(); originToRot = new TransformGroup(originToRotT3D); branchGroup = new BranchGroup(); rotToCOM = new TransformGroup(); rotToCOMT3D = new Transform3D(); rotToCOMV3D = new Vector3d(); // Set capabilities needed for picking and moving the MolecularAssembly branchGroup.setCapability(BranchGroup.ALLOW_DETACH); originToRot.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); originToRot.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); originToRot.setCapability(TransformGroup.ENABLE_PICK_REPORTING); rotToCOM.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); rotToCOM.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); // Put the MolecularAssembly in the middle of the scene if (zero) { originToRotV3D.set(0.0, 0.0, 0.0); originToRotT3D.set(originToRotV3D); originToRot.setTransform(originToRotT3D); } wire = renderWire(); switchGroup = new Switch(Switch.CHILD_NONE); switchGroup.setCapability(Switch.ALLOW_SWITCH_WRITE); base = new BranchGroup(); base.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND); base.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE); childNodes = new BranchGroup(); childNodes.setCapability(BranchGroup.ALLOW_DETACH); childNodes.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND); childNodes.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE); switchGroup.addChild(base); if (wire != null) { base.addChild(wire); } vrml = loadVRML(); if (vrml != null) { vrmlTG = new TransformGroup(); vrmlTd = new Transform3D(); vrmlTG.setTransform(vrmlTd); vrmlTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); vrmlTG.addChild(vrml); switchGroup.addChild(vrmlTG); setView(RendererCache.ViewModel.INVISIBLE, null); } switchGroup.setWhichChild(Switch.CHILD_ALL); rotToCOM.addChild(switchGroup); originToRot.addChild(rotToCOM); branchGroup.addChild(originToRot); branchGroup.compile(); return branchGroup; }
From source file:TransformExplorer.java
JPanel configPanel() { JPanel panel = new JPanel(); panel.setLayout(new GridLayout(0, 1)); panel.add(new JLabel("Display annotation:")); // create the check boxes rotAxisCheckBox = new JCheckBox(rotAxisString); rotAxisCheckBox.setSelected(showRotAxis); rotAxisCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object source = e.getSource(); showRotAxis = ((JCheckBox) source).isSelected(); if (showRotAxis) { rotAxis.setWhichChild(Switch.CHILD_ALL); } else { rotAxis.setWhichChild(Switch.CHILD_NONE); }/*from www . j a v a2 s. c o m*/ } }); panel.add(rotAxisCheckBox); coordSysCheckBox = new JCheckBox(coordSysString); coordSysCheckBox.setSelected(showCoordSys); coordSysCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object source = e.getSource(); showCoordSys = ((JCheckBox) source).isSelected(); if (showCoordSys) { coordSys.setWhichChild(Switch.CHILD_ALL); } else { coordSys.setWhichChild(Switch.CHILD_NONE); } } }); panel.add(coordSysCheckBox); if (isApplication) { JButton snapButton = new JButton(snapImageString); snapButton.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); nf.setMaximumFractionDigits(0); offScreenCanvas.snapImageFile(outFileBase + nf.format(outFileSeq++), dim.width, dim.height); nf.setMinimumIntegerDigits(0); } }); panel.add(snapButton); } return panel; }
From source file:EnvironmentExplorer.java
JPanel configPanel() { JPanel panel = new JPanel(); panel.setLayout(new GridLayout(1, 0)); String[] dataTypeValues = { "Spheres", "Grid", }; IntChooser dataTypeChooser = new IntChooser("Data:", dataTypeValues); dataTypeChooser.addIntListener(new IntListener() { public void intChanged(IntEvent event) { int value = event.getValue(); switch (value) { case 0: spheresSwitch.setWhichChild(Switch.CHILD_ALL); gridSwitch.setWhichChild(Switch.CHILD_NONE); break; case 1: gridSwitch.setWhichChild(Switch.CHILD_ALL); spheresSwitch.setWhichChild(Switch.CHILD_NONE); break; }// ww w . j ava2 s.c o m } }); panel.add(dataTypeChooser); if (isApplication) { JButton snapButton = new JButton("Snap Image"); snapButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Point loc = canvas.getLocationOnScreen(); offScreenCanvas.setOffScreenLocation(loc); Dimension dim = canvas.getSize(); dim.width *= OFF_SCREEN_SCALE; dim.height *= OFF_SCREEN_SCALE; nf.setMinimumIntegerDigits(3); offScreenCanvas.snapImageFile(outFileBase + nf.format(outFileSeq++), dim.width, dim.height); nf.setMinimumIntegerDigits(0); } }); panel.add(snapButton); } return panel; }
From source file:TransformExplorer.java
CoordSys(float axisLength) { super(Switch.CHILD_ALL); float coordSysLength = axisLength; float labelOffset = axisLength / 20.0f; float axisRadius = axisLength / 500.0f; float arrowRadius = axisLength / 125.0f; float arrowHeight = axisLength / 50.0f; float tickRadius = axisLength / 125.0f; float tickHeight = axisLength / 250.0f; // Set the Switch to allow changes setCapability(Switch.ALLOW_SWITCH_READ); setCapability(Switch.ALLOW_SWITCH_WRITE); // Set up an appearance to make the Axis have // grey ambient, black emmissive, grey diffuse and grey specular // coloring.// ww w . j a v a 2 s. c o m //Material material = new Material(grey, black, grey, white, 64); Material material = new Material(white, black, white, white, 64); Appearance appearance = new Appearance(); appearance.setMaterial(material); // Create a shared group to hold one axis of the coord sys SharedGroup coordAxisSG = new SharedGroup(); // create a cylinder for the central line of the axis Cylinder cylinder = new Cylinder(axisRadius, coordSysLength, appearance); // cylinder goes from -coordSysLength/2 to coordSysLength in y coordAxisSG.addChild(cylinder); // create the shared arrowhead Cone arrowHead = new Cone(arrowRadius, arrowHeight, appearance); SharedGroup arrowHeadSG = new SharedGroup(); arrowHeadSG.addChild(arrowHead); // Create a TransformGroup to move the arrowhead to the top of the // axis // The arrowhead goes from -arrowHeight/2 to arrowHeight/2 in y. // Put it at the top of the axis, coordSysLength / 2 tmpVector.set(0.0f, coordSysLength / 2 + arrowHeight / 2, 0.0f); tmpTrans.set(tmpVector); TransformGroup topTG = new TransformGroup(); topTG.setTransform(tmpTrans); topTG.addChild(new Link(arrowHeadSG)); coordAxisSG.addChild(topTG); // create the minus arrowhead // Create a TransformGroup to turn the cone upside down: // Rotate 180 degrees around Z axis tmpAxisAngle.set(0.0f, 0.0f, 1.0f, (float) Math.toRadians(180)); tmpTrans.set(tmpAxisAngle); // Put the arrowhead at the bottom of the axis tmpVector.set(0.0f, -coordSysLength / 2 - arrowHeight / 2, 0.0f); tmpTrans.setTranslation(tmpVector); TransformGroup bottomTG = new TransformGroup(); bottomTG.setTransform(tmpTrans); bottomTG.addChild(new Link(arrowHeadSG)); coordAxisSG.addChild(bottomTG); // Now add "ticks" at 1, 2, 3, etc. // create a shared group for the tick Cylinder tick = new Cylinder(tickRadius, tickHeight, appearance); SharedGroup tickSG = new SharedGroup(); tickSG.addChild(tick); // transform each instance and add it to the coord axis group int maxTick = (int) (coordSysLength / 2); int minTick = -maxTick; for (int i = minTick; i <= maxTick; i++) { if (i == 0) continue; // no tick at 0 // use a TransformGroup to offset to the tick location TransformGroup tickTG = new TransformGroup(); tmpVector.set(0.0f, (float) i, 0.0f); tmpTrans.set(tmpVector); tickTG.setTransform(tmpTrans); // then link to an instance of the Tick shared group tickTG.addChild(new Link(tickSG)); // add the TransformGroup to the coord axis coordAxisSG.addChild(tickTG); } // add a Link to the axis SharedGroup to the coordSys addChild(new Link(coordAxisSG)); // Y axis // Create TransformGroups for the X and Z axes TransformGroup xAxisTG = new TransformGroup(); // rotate 90 degrees around Z axis tmpAxisAngle.set(0.0f, 0.0f, 1.0f, (float) Math.toRadians(90)); tmpTrans.set(tmpAxisAngle); xAxisTG.setTransform(tmpTrans); xAxisTG.addChild(new Link(coordAxisSG)); addChild(xAxisTG); // X axis TransformGroup zAxisTG = new TransformGroup(); // rotate 90 degrees around X axis tmpAxisAngle.set(1.0f, 0.0f, 0.0f, (float) Math.toRadians(90)); tmpTrans.set(tmpAxisAngle); zAxisTG.setTransform(tmpTrans); zAxisTG.addChild(new Link(coordAxisSG)); addChild(zAxisTG); // Z axis // Add the labels. First we need a Font3D for the Text3Ds // select the default font, plain style, 0.5 tall. Use null for // the extrusion so we get "flat" text since we will be putting it // into an oriented Shape3D Font3D f3d = new Font3D(new Font("Default", Font.PLAIN, 1), null); // set up the +X label Text3D plusXText = new Text3D(f3d, "+X", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT); // orient around the local origin OrientedShape3D plusXTextShape = new OrientedShape3D(plusXText, appearance, OrientedShape3D.ROTATE_ABOUT_POINT, origin); // transform to scale down to 0.15 in height, locate at end of axis TransformGroup plusXTG = new TransformGroup(); tmpVector.set(coordSysLength / 2 + labelOffset, 0.0f, 0.0f); tmpTrans.set(0.15f, tmpVector); plusXTG.setTransform(tmpTrans); plusXTG.addChild(plusXTextShape); addChild(plusXTG); // set up the -X label Text3D minusXText = new Text3D(f3d, "-X", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT); // orient around the local origin OrientedShape3D minusXTextShape = new OrientedShape3D(minusXText, appearance, OrientedShape3D.ROTATE_ABOUT_POINT, origin); // transform to scale down to 0.15 in height, locate at end of axis TransformGroup minusXTG = new TransformGroup(); tmpVector.set(-coordSysLength / 2 - labelOffset, 0.0f, 0.0f); tmpTrans.set(0.15f, tmpVector); minusXTG.setTransform(tmpTrans); minusXTG.addChild(minusXTextShape); addChild(minusXTG); // set up the +Y label Text3D plusYText = new Text3D(f3d, "+Y", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT); // orient around the local origin OrientedShape3D plusYTextShape = new OrientedShape3D(plusYText, appearance, OrientedShape3D.ROTATE_ABOUT_POINT, origin); // transform to scale down to 0.15 in height, locate at end of axis TransformGroup plusYTG = new TransformGroup(); tmpVector.set(0.0f, coordSysLength / 2 + labelOffset, 0.0f); tmpTrans.set(0.15f, tmpVector); plusYTG.setTransform(tmpTrans); plusYTG.addChild(plusYTextShape); addChild(plusYTG); // set up the -Y label Text3D minusYText = new Text3D(f3d, "-Y", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT); // orient around the local origin OrientedShape3D minusYTextShape = new OrientedShape3D(minusYText, appearance, OrientedShape3D.ROTATE_ABOUT_POINT, origin); // transform to scale down to 0.15 in height, locate at end of axis TransformGroup minusYTG = new TransformGroup(); tmpVector.set(0.0f, -coordSysLength / 2 - labelOffset, 0.0f); tmpTrans.set(0.15f, tmpVector); minusYTG.setTransform(tmpTrans); minusYTG.addChild(minusYTextShape); addChild(minusYTG); // set up the +Z label Text3D plusZText = new Text3D(f3d, "+Z", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT); // orient around the local origin OrientedShape3D plusZTextShape = new OrientedShape3D(plusZText, appearance, OrientedShape3D.ROTATE_ABOUT_POINT, origin); // transform to scale down to 0.15 in height, locate at end of axis TransformGroup plusZTG = new TransformGroup(); tmpVector.set(0.0f, 0.0f, coordSysLength / 2 + labelOffset); tmpTrans.set(0.15f, tmpVector); plusZTG.setTransform(tmpTrans); plusZTG.addChild(plusZTextShape); addChild(plusZTG); // set up the -Z label Text3D minusZText = new Text3D(f3d, "-Z", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT); // orient around the local origin OrientedShape3D minusZTextShape = new OrientedShape3D(minusZText, appearance, OrientedShape3D.ROTATE_ABOUT_POINT, origin); // transform to scale down to 0.15 in height, locate at end of axis TransformGroup minusZTG = new TransformGroup(); tmpVector.set(0.0f, 0.0f, -coordSysLength / 2 - labelOffset); tmpTrans.set(0.15f, tmpVector); minusZTG.setTransform(tmpTrans); minusZTG.addChild(minusZTextShape); addChild(minusZTG); }
From source file:ffx.potential.MolecularAssembly.java
/** * {@inheritDoc}//from w ww . jav a 2 s . c o m */ @Override public void setView(RendererCache.ViewModel newViewModel, List<BranchGroup> newShapes) { // Just Detach the whole system branch group if (newViewModel == RendererCache.ViewModel.DESTROY) { if (switchGroup != null) { switchGroup.setWhichChild(Switch.CHILD_NONE); } visible = false; } else if (newViewModel == RendererCache.ViewModel.SHOWVRML) { switchGroup.setWhichChild(Switch.CHILD_ALL); } else if (newViewModel == RendererCache.ViewModel.HIDEVRML) { switchGroup.setWhichChild(0); } else { setWireWidth(RendererCache.bondwidth); if (newViewModel == RendererCache.ViewModel.DETAIL && childNodes.isLive()) { childNodes.detach(); } /** * We'll collect new Scenegraph Shapes in our newShapeNode This is * to avoid the case where setView is called from the root node and * all new shapes for every MolecularAssembly would then be put into * the same ArrayList. */ super.setView(newViewModel, myNewShapes); ArrayList<ROLS> moleculeList = getList(Molecule.class, new ArrayList<ROLS>()); for (ROLS m : moleculeList) { m.setView(newViewModel, myNewShapes); } for (MSNode m : molecules.getChildList()) { m.setView(newViewModel, myNewShapes); } for (MSNode m : water.getChildList()) { m.setView(newViewModel, myNewShapes); } for (MSNode m : ions.getChildList()) { m.setView(newViewModel, myNewShapes); } if (newViewModel == RendererCache.ViewModel.INVISIBLE) { switchGroup.setWhichChild(0); } if (newViewModel == RendererCache.ViewModel.DETAIL) { childNodes.compile(); base.addChild(childNodes); } } }