List of usage examples for javax.media.j3d TransformGroup ALLOW_TRANSFORM_READ
int ALLOW_TRANSFORM_READ
To view the source code for javax.media.j3d TransformGroup ALLOW_TRANSFORM_READ.
Click Source Link
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//from w w w .jav a 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:LightTest.java
public Group createGeometry() { m_DirectionTransformGroup = new TransformGroup(); m_DirectionTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); m_DirectionTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // create appearance and material for the Cone Appearance app = new Appearance(); // create the Primitive and add to the parent BranchGroup m_Cone = new Cone(0.5f, 2, Primitive.ENABLE_APPEARANCE_MODIFY | Primitive.GENERATE_NORMALS, app); m_DirectionTransformGroup.addChild(m_Cone); Group superGroup = super.createGeometry(); superGroup.addChild(m_DirectionTransformGroup); return superGroup; }
From source file:GearTest.java
public BranchGroup createGearBox(int toothCount) { Transform3D tempTransform = new Transform3D(); // Create the root of the branch graph BranchGroup branchRoot = createBranchEnvironment(); // Create a Transformgroup to scale all objects so they // appear in the scene. TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(0.4);//ww w. j av a 2 s . c om objScale.setTransform(t3d); branchRoot.addChild(objScale); // Create an Appearance. Appearance look = new Appearance(); Color3f objColor = new Color3f(0.5f, 0.5f, 0.6f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); look.setMaterial(new Material(objColor, black, objColor, white, 100.0f)); // Create the transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup gearboxTrans = new TransformGroup(); gearboxTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); gearboxTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objScale.addChild(gearboxTrans); // Create a bounds for the mouse behavior methods BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Define the shaft base information int shaftCount = 4; int secondsPerRevolution = 8000; // Create the Shaft(s) Shaft shafts[] = new Shaft[shaftCount]; TransformGroup shaftTGs[] = new TransformGroup[shaftCount]; Alpha shaftAlphas[] = new Alpha[shaftCount]; RotationInterpolator shaftRotors[] = new RotationInterpolator[shaftCount]; Transform3D shaftAxis[] = new Transform3D[shaftCount]; // Note: the following arrays we're incorporated to make changing // the gearbox easier. float shaftRatios[] = new float[shaftCount]; shaftRatios[0] = 1.0f; shaftRatios[1] = 0.5f; shaftRatios[2] = 0.75f; shaftRatios[3] = 5.0f; float shaftRadius[] = new float[shaftCount]; shaftRadius[0] = 0.2f; shaftRadius[1] = 0.2f; shaftRadius[2] = 0.2f; shaftRadius[3] = 0.2f; float shaftLength[] = new float[shaftCount]; shaftLength[0] = 1.8f; shaftLength[1] = 0.8f; shaftLength[2] = 0.8f; shaftLength[3] = 0.8f; float shaftDirection[] = new float[shaftCount]; shaftDirection[0] = 1.0f; shaftDirection[1] = -1.0f; shaftDirection[2] = 1.0f; shaftDirection[3] = -1.0f; Vector3d shaftPlacement[] = new Vector3d[shaftCount]; shaftPlacement[0] = new Vector3d(-0.75, -0.9, 0.0); shaftPlacement[1] = new Vector3d(0.75, -0.9, 0.0); shaftPlacement[2] = new Vector3d(0.75, 0.35, 0.0); shaftPlacement[3] = new Vector3d(-0.75, 0.60, -0.7); // Create the shafts. for (int i = 0; i < shaftCount; i++) { shafts[i] = new Shaft(shaftRadius[i], shaftLength[i], 25, look); } // Create a transform group node for placing each shaft for (int i = 0; i < shaftCount; i++) { shaftTGs[i] = new TransformGroup(); gearboxTrans.addChild(shaftTGs[i]); shaftTGs[i].getTransform(tempTransform); tempTransform.setTranslation(shaftPlacement[i]); shaftTGs[i].setTransform(tempTransform); shaftTGs[i].addChild(shafts[i]); } // Add rotation interpolators to rotate the shaft in the appropriate // direction and at the appropriate rate for (int i = 0; i < shaftCount; i++) { shaftAlphas[i] = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, (long) (secondsPerRevolution * shaftRatios[i]), 0, 0, 0, 0, 0); shaftAxis[i] = new Transform3D(); shaftAxis[i].rotX(Math.PI / 2.0); shaftRotors[i] = new RotationInterpolator(shaftAlphas[i], shafts[i], shaftAxis[i], 0.0f, shaftDirection[i] * (float) Math.PI * 2.0f); shaftRotors[i].setSchedulingBounds(bounds); shaftTGs[i].addChild(shaftRotors[i]); } // Define the gear base information. Again, these arrays exist to // make the process of changing the GearBox via an editor faster int gearCount = 5; float valleyToCircularPitchRatio = .15f; float pitchCircleRadius = 1.0f; float addendum = 0.05f; float dedendum = 0.05f; float gearThickness = 0.3f; float toothTipThickness = 0.27f; // Create an array of gears and their associated information SpurGear gears[] = new SpurGear[gearCount]; TransformGroup gearTGs[] = new TransformGroup[gearCount]; int gearShaft[] = new int[gearCount]; gearShaft[0] = 0; gearShaft[1] = 1; gearShaft[2] = 2; gearShaft[3] = 0; gearShaft[4] = 3; float ratio[] = new float[gearCount]; ratio[0] = 1.0f; ratio[1] = 0.5f; ratio[2] = 0.75f; ratio[3] = 0.25f; ratio[4] = 1.25f; Vector3d placement[] = new Vector3d[gearCount]; placement[0] = new Vector3d(0.0, 0.0, 0.0); placement[1] = new Vector3d(0.0, 0.0, 0.0); placement[2] = new Vector3d(0.0, 0.0, 0.0); placement[3] = new Vector3d(0.0, 0.0, -0.7); placement[4] = new Vector3d(0.0, 0.0, 0.0); // Create the gears. for (int i = 0; i < gearCount; i++) { gears[i] = new SpurGearThinBody(((int) ((float) toothCount * ratio[i])), pitchCircleRadius * ratio[i], shaftRadius[0], addendum, dedendum, gearThickness, toothTipThickness, valleyToCircularPitchRatio, look); } // Create a transform group node for arranging the gears on a shaft // and attach the gear to its associated shaft for (int i = 0; i < gearCount; i++) { gearTGs[i] = new TransformGroup(); gearTGs[i].getTransform(tempTransform); tempTransform .rotZ((shaftDirection[gearShaft[i]] == -1.0) ? gears[i].getCircularPitchAngle() / -2.0f : 0.0f); tempTransform.setTranslation(placement[i]); gearTGs[i].setTransform(tempTransform); gearTGs[i].addChild(gears[i]); shafts[gearShaft[i]].addChild(gearTGs[i]); } // Have Java 3D perform optimizations on this scene graph. branchRoot.compile(); return branchRoot; }
From source file:LightTest.java
public Group createGeometry() { m_TransformGroup = new TransformGroup(); m_TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); m_TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // create appearance and material for the Cone Appearance app = new Appearance(); // create the Primitive and add to the parent BranchGroup m_Cone = new Cone(1, 10, Primitive.ENABLE_APPEARANCE_MODIFY | Primitive.GENERATE_NORMALS, app); m_TransformGroup.addChild(m_Cone);//w w w . j a va 2 s . co m Group superGroup = super.createGeometry(); superGroup.addChild(m_TransformGroup); return superGroup; }
From source file:Demo3D.java
/** * Create the subgraph #31 and prepare the TransformGroup node trGr31 for * the tetrahedron's picking.//from ww w . j a v a2s .co m * * @return javax.media.j3d.TransformGroup trGr31_2 - the root of the * subgraph #31 */ public TransformGroup mySubGraph31() { // Create a Transform3D node to execute the desired "static translation" // of the tetrahedron ===> start position. transl = new Transform3D(); vectransl = new Vector3d(0.0, -2.0, 0.0); // translation transl.set(vectransl); // Create the TransformGroup node trGr31, attach into it the "static // translation" instance and prepare it for the picking. trGr31 = new TransformGroup(transl); trGr31.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); trGr31.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); trGr31.setCapability(TransformGroup.ENABLE_PICK_REPORTING); // Attach myObject (Shape3D leaf) to the TransformGroup node trGr31. trGr31.addChild(myObject); // Return the final version of the TransformGroup node trGr31. return trGr31; }
From source file:FourByFour.java
/** * Create the scenegraph for the 3D view. *//*www . jav a 2 s . c o m*/ public BranchGroup createScene3D() { // Define colors Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f red = new Color3f(0.80f, 0.20f, 0.2f); Color3f ambient = new Color3f(0.25f, 0.25f, 0.25f); Color3f diffuse = new Color3f(0.7f, 0.7f, 0.7f); Color3f specular = new Color3f(0.9f, 0.9f, 0.9f); Color3f ambientRed = new Color3f(0.2f, 0.05f, 0.0f); Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); // Create the branch group BranchGroup branchGroup = new BranchGroup(); // Create the bounding leaf node BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0); BoundingLeaf boundingLeaf = new BoundingLeaf(bounds); branchGroup.addChild(boundingLeaf); // Create the background Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); branchGroup.addChild(bg); // Create the ambient light AmbientLight ambLight = new AmbientLight(white); ambLight.setInfluencingBounds(bounds); branchGroup.addChild(ambLight); // Create the directional light Vector3f dir = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight dirLight = new DirectionalLight(white, dir); dirLight.setInfluencingBounds(bounds); branchGroup.addChild(dirLight); // Create the pole appearance Material poleMaterial = new Material(ambient, black, diffuse, specular, 110.f); poleMaterial.setLightingEnable(true); Appearance poleAppearance = new Appearance(); poleAppearance.setMaterial(poleMaterial); // Create the transform group node TransformGroup transformGroup = new TransformGroup(); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); branchGroup.addChild(transformGroup); // Create the poles Poles poles = new Poles(poleAppearance); transformGroup.addChild(poles.getChild()); // Add the position markers to the transform group transformGroup.addChild(positions.getChild()); // Let the positions object know about the transform group positions.setTransformGroup(transformGroup); // Create the mouse pick and drag behavior node PickDragBehavior behavior = new PickDragBehavior(canvas2D, canvas3D, positions, branchGroup, transformGroup); behavior.setSchedulingBounds(bounds); transformGroup.addChild(behavior); return branchGroup; }
From source file:TransformExplorer.java
RotAxis(float axisLength) { super(Switch.CHILD_NONE); setCapability(Switch.ALLOW_SWITCH_READ); setCapability(Switch.ALLOW_SWITCH_WRITE); // set up the proportions for the arrow float axisRadius = axisLength / 120.0f; float arrowRadius = axisLength / 50.0f; float arrowHeight = axisLength / 30.0f; // create the TransformGroup which will be used to orient the axis axisTG = new TransformGroup(); axisTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); axisTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); addChild(axisTG);/* w w w. ja v a 2 s .c om*/ // Set up an appearance to make the Axis have // blue ambient, black emmissive, blue diffuse and white specular // coloring. Material material = new Material(blue, black, blue, white, 64); Appearance appearance = new Appearance(); appearance.setMaterial(material); // create a cylinder for the central line of the axis Cylinder cylinder = new Cylinder(axisRadius, axisLength, appearance); // cylinder goes from -length/2 to length/2 in y axisTG.addChild(cylinder); // create a SharedGroup for the arrowHead Cone arrowHead = new Cone(arrowRadius, arrowHeight, appearance); SharedGroup arrowHeadSG = new SharedGroup(); arrowHeadSG.addChild(arrowHead); // Create a TransformGroup to move the cone to the top of the // cylinder tmpVector.set(0.0f, axisLength / 2 + arrowHeight / 2, 0.0f); tmpTrans.set(tmpVector); TransformGroup topTG = new TransformGroup(); topTG.setTransform(tmpTrans); topTG.addChild(new Link(arrowHeadSG)); axisTG.addChild(topTG); // create the bottom of the arrow // Create a TransformGroup to move the cone to the bottom of the // axis so that its pushes into the bottom of the cylinder tmpVector.set(0.0f, -(axisLength / 2), 0.0f); tmpTrans.set(tmpVector); TransformGroup bottomTG = new TransformGroup(); bottomTG.setTransform(tmpTrans); bottomTG.addChild(new Link(arrowHeadSG)); axisTG.addChild(bottomTG); updateAxisTransform(); }