List of usage examples for javax.media.j3d TransformGroup addChild
public void addChild(Node child)
From source file:AlternateAppearanceScopeTest.java
public SphereGroup(float radius, float xSpacing, float ySpacing, int xCount, int yCount, Appearance app, boolean overrideflag) { if (app == null) { app = new Appearance(); Material material = new Material(); material.setDiffuseColor(new Color3f(0.8f, 0.8f, 0.8f)); material.setSpecularColor(new Color3f(0.0f, 0.0f, 0.0f)); material.setShininess(0.0f);/*w w w . ja va 2 s .co m*/ app.setMaterial(material); } double xStart = -xSpacing * (double) (xCount - 1) / 2.0; double yStart = -ySpacing * (double) (yCount - 1) / 2.0; Sphere sphere = null; TransformGroup trans = null; Transform3D t3d = new Transform3D(); Vector3d vec = new Vector3d(); double x, y = yStart, z = 0.0; shapes = new Shape3D[xCount * yCount]; for (int i = 0; i < yCount; i++) { x = xStart; for (int j = 0; j < xCount; j++) { vec.set(x, y, z); t3d.setTranslation(vec); trans = new TransformGroup(t3d); addChild(trans); sphere = new Sphere(radius, // sphere radius Primitive.GENERATE_NORMALS, // generate normals 16, // 16 divisions radially app); // it's appearance trans.addChild(sphere); x += xSpacing; shapes[numShapes] = sphere.getShape(); if (overrideflag) shapes[numShapes].setCapability(Shape3D.ALLOW_APPEARANCE_OVERRIDE_WRITE); numShapes++; } y += ySpacing; } }
From source file:ModelClipTest2.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // 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);//from ww w . ja v a 2 s . c o m objScale.setTransform(t3d); objRoot.addChild(objScale); // Create lights BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); //Shine it with two colored lights. Color3f lColor0 = new Color3f(1.0f, 1.0f, 1.0f); Color3f lColor1 = new Color3f(0.5f, 0.0f, 0.5f); Color3f lColor2 = new Color3f(0.7f, 0.7f, 0.0f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, 1.0f); Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f); AmbientLight lgt0 = new AmbientLight(true, lColor2); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2); lgt0.setInfluencingBounds(bounds); lgt1.setInfluencingBounds(bounds); lgt2.setInfluencingBounds(bounds); objScale.addChild(lgt0); objScale.addChild(lgt1); objScale.addChild(lgt2); // Create a Transformgroup for the geometry TransformGroup objRot = new TransformGroup(); Transform3D t3d1 = new Transform3D(); AxisAngle4f rot1 = new AxisAngle4f(0.0f, 1.0f, 0.0f, 45.0f); t3d1.setRotation(rot1); objRot.setTransform(t3d1); objScale.addChild(objRot); //Create a cylinder PolygonAttributes attr = new PolygonAttributes(); attr.setCullFace(PolygonAttributes.CULL_NONE); Appearance ap = new Appearance(); Material mat = new Material(); mat.setLightingEnable(true); ap.setMaterial(mat); ap.setPolygonAttributes(attr); Cylinder CylinderObj = new Cylinder(0.5f, 2.2f, ap); objRot.addChild(CylinderObj); //Create a box Box BoxObj = new Box(0.8f, 0.8f, 0.8f, ap); objRot.addChild(BoxObj); // This Transformgroup is used by the mouse manipulators to // move the model clip planes. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRot.addChild(objTrans); // Create the rotate behavior node MouseRotate behavior = new MouseRotate(objTrans); objTrans.addChild(behavior); behavior.setSchedulingBounds(bounds); // Create the zoom behavior node MouseZoom behavior2 = new MouseZoom(objTrans); objTrans.addChild(behavior2); behavior2.setSchedulingBounds(bounds); //Create Model Clip ModelClip mc = new ModelClip(); boolean enables[] = { false, false, false, false, false, false }; Vector4d eqn = new Vector4d(0.0, 1.0, 1.0, 0.0); mc.setEnables(enables); mc.setPlane(1, eqn); mc.setEnable(1, true); mc.setInfluencingBounds(bounds); objTrans.addChild(mc); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:ScenegraphTest.java
private TransformGroup addLimb(Group parentGroup, String szName, double radius, double length, double rotMin, double rotMax) { // create the rotator TransformGroup tgJoint = new TransformGroup(); tgJoint.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); tgJoint.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // add a rotator if necessary if (rotMin != rotMax) { Transform3D xAxis = new Transform3D(); xAxis.rotX(Math.PI / 2.0); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, tgJoint, xAxis, (float) rotMin, (float) rotMax); rotator.setSchedulingBounds(createApplicationBounds()); tgJoint.addChild(rotator); }/* w w w .java2s . c o m*/ // create a cylinder using length and radius tgJoint.addChild(createLimb(radius, length)); // create the joint (the *next* TG should // be offset by the length of this limb) TransformGroup tgOffset = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(0, length, 0)); tgOffset.setTransform(t3d); tgJoint.addChild(tgOffset); parentGroup.addChild(tgJoint); // return the offset TG, so any child TG's will be added // in the correct position. return tgOffset; }
From source file:CustomAlphaTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); ColorCube cube = new ColorCube(2); objTrans.addChild(cube); FileAlpha fileAlpha = null;// w ww.j a v a 2s .com try { fileAlpha = new FileAlpha(new URL(getWorkingDirectory(), "values.xls"), this); } catch (Exception e) { e.toString(); } PositionInterpolator posInterpolator = new PositionInterpolator(fileAlpha, objTrans, new Transform3D(), -6, 6); posInterpolator.setSchedulingBounds(getApplicationBounds()); objTrans.addChild(posInterpolator); objRoot.addChild(objTrans); return objRoot; }
From source file:NodesTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); double labelScale = 20; // create the top level Switch Node // we will use the Switch Node to switch the // other Nodes on and off. // 1: Switch/*from w w w . ja va 2 s. c o m*/ Switch switchGroup = new Switch(); switchGroup.setCapability(Switch.ALLOW_SWITCH_WRITE); switchGroup.addChild(createLabel("1. Switch Label", labelScale)); // 2: BranchGroup BranchGroup branchGroup = new BranchGroup(); branchGroup.addChild(createLabel("2. BranchGroup", labelScale)); switchGroup.addChild(branchGroup); // 3: OrderedGroup, OrderedGroup orderedGroup = new OrderedGroup(); orderedGroup.addChild(createLabel("3. OrderedGroup", labelScale)); orderedGroup.addChild(createLabel("Child 1", labelScale)); orderedGroup.addChild(createLabel("Child 2", labelScale)); switchGroup.addChild(orderedGroup); // 4: SharedGroup, SharedGroup sharedGroup1 = new SharedGroup(); sharedGroup1.addChild(createLabel("4. Shared Group 1", labelScale)); switchGroup.addChild(new Link(sharedGroup1)); // 5: Primitive, BranchGroup primitiveGroup = new BranchGroup(); primitiveGroup.addChild(createLabel("5. Primitive", labelScale)); primitiveGroup.addChild(new Sphere(2)); switchGroup.addChild(primitiveGroup); // 6: TransformGroup TransformGroup transformGroup = new TransformGroup(); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, transformGroup, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(createApplicationBounds()); transformGroup.addChild(rotator); transformGroup.addChild(new ColorCube(2)); transformGroup.addChild(createLabel("6. TransformGroup", labelScale)); switchGroup.addChild(transformGroup); // 7: add another copy of the shared group switchGroup.addChild(new Link(sharedGroup1)); // create a SwitchValueInterpolator to // cycle through the child nodes in the Switch Node Alpha switchAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 10000, 0, 0, 0, 0, 0); SwitchValueInterpolator switchInterpolator = new SwitchValueInterpolator(switchAlpha, switchGroup); switchInterpolator.setSchedulingBounds(createApplicationBounds()); switchInterpolator.setEnable(true); // WARNING: do not add the SwitchValueInterpolator to the Switch Node! objRoot.addChild(switchInterpolator); // finally add the Switch Node objRoot.addChild(switchGroup); return objRoot; }
From source file:AvatarTest.java
ViewerAvatar createAvatar() { ViewerAvatar va = new ViewerAvatar(); TransformGroup tg = new TransformGroup(); Car car = new Car(this, tg, ComplexObject.GEOMETRY | ComplexObject.TEXTURE | ComplexObject.COLLISION | ComplexObject.COLLISION_SOUND); car.createObject(new Appearance(), new Vector3d(0, -0.3, -0.3), new Vector3d(0.3, 0.3, 1), "platform.jpg", null, "collide.wav"); tg.addChild(car); va.addChild(tg);/*from w w w.j ava 2 s . com*/ return va; }
From source file:PickCollisionTest.java
protected void addCube(BranchGroup bg, double x, double y, double z, double sx, double sy, double sz, String name, boolean wireframe) { // create four ColorCube objects TransformGroup cubeTg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(x, y, z)); t3d.setScale(new Vector3d(sx, sy, sz)); cubeTg.setTransform(t3d);/*from w w w . j a v a2s .c om*/ ColorCube cube = new ColorCube(1.0); // we have to make the front face wireframe // or we can't see inside the box! if (wireframe) { Appearance app = new Appearance(); app.setPolygonAttributes( new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0)); cube.setAppearance(app); } cubeTg.addChild(cube); recursiveSetUserData(cubeTg, name); bg.addChild(cubeTg); }
From source file:Human1.java
BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a TransformGroup to scale the scene down by 3.5x // TODO: move view platform instead of scene using orbit behavior TransformGroup objScale = new TransformGroup(); Transform3D scaleTrans = new Transform3D(); scaleTrans.set(1 / 3.5f); // scale down by 3.5x objScale.setTransform(scaleTrans);//from ww w . j a v a 2 s . c om objRoot.addChild(objScale); // Create a TransformGroup and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // the mouse behaviors code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objScale.addChild(objTrans); // Add the primitives to the scene createHuman(); // the human objTrans.addChild(Human_body); BoundingSphere bounds = new BoundingSphere(new Point3d(), 100.0); Background bg = new Background(new Color3f(1.0f, 1.0f, 1.0f)); bg.setApplicationBounds(bounds); objTrans.addChild(bg); // set up the mouse rotation behavior MouseRotate mr = new MouseRotate(); mr.setTransformGroup(objTrans); mr.setSchedulingBounds(bounds); mr.setFactor(0.007); objTrans.addChild(mr); // Set up the ambient light Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objRoot.addChild(ambientLightNode); // Set up the directional lights Color3f light1Color = new Color3f(1.0f, 1.0f, 1.0f); Vector3f light1Direction = new Vector3f(0.0f, -0.2f, -1.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objRoot.addChild(light1); return objRoot; }
From source file:HiResCoordTest.java
protected BranchGroup createSceneBranchGroupEarth() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D yAxis = new Transform3D(); yAxis.rotZ(0.2);/*from w w w .ja v a 2 s. c om*/ Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), m_TranslateSunZ); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator); Transform3D t3d = new Transform3D(); t3d.setScale(m_EarthRadius); objTrans.addChild(createPlanet("Earth", new Color3f(0, 0.1f, 1), t3d, "earth.jpg")); objRoot.addChild(objTrans); return objRoot; }
From source file:HiResCoordTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); Transform3D t3dTilt = new Transform3D(); t3dTilt.rotX(0.3);//from w w w .j av a 2 s . c o m TransformGroup objTrans = new TransformGroup(t3dTilt); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); TransformGroup objTransPlanets = new TransformGroup(); objTransPlanets.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTransPlanets, yAxis, 0.0f, (float) Math.PI * 2.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), m_TranslateSunZ); rotator.setSchedulingBounds(bounds); objTransPlanets.addChild(rotator); // create the sun TransformGroup sunTg = createSun(); // create Earth Transform3D t3dEarth = new Transform3D(); t3dEarth.setScale(m_EarthRadius); t3dEarth.setTranslation(new Vector3d(m_EarthOrbit, 0, 0)); objTransPlanets.addChild(createPlanet("Earth", new Color3f(0, 0.1f, 1.0f), t3dEarth, null)); // create Mars Transform3D t3dMars = new Transform3D(); t3dMars.setTranslation( new Vector3d(Math.sin(Math.PI * 1.5) * m_MarsOrbit, 0, Math.cos(Math.PI * 0.5) * m_MarsOrbit)); t3dMars.setScale(m_MarsRadius); objTransPlanets.addChild(createPlanet("Mars", new Color3f(1, 0, 0), t3dMars, null)); // create Mercury Transform3D t3dMercury = new Transform3D(); t3dMercury.setTranslation( new Vector3d(Math.sin(Math.PI) * m_MercuryOrbit, 0, Math.cos(Math.PI) * m_MercuryOrbit)); t3dMercury.setScale(m_MercuryRadius); objTransPlanets.addChild(createPlanet("Mercury", new Color3f(0.5f, 0.5f, 0.5f), t3dMercury, null)); sunTg.addChild(objTransPlanets); objTrans.addChild(sunTg); objRoot.addChild(objTrans); return objRoot; }