List of usage examples for javax.media.j3d Appearance Appearance
public Appearance()
From source file:SimpleKeyNav.java
/** * Build the content branch for the scene graph * /* w ww . ja va 2s . co m*/ * @return BranchGroup that is the root of the content */ protected BranchGroup buildContentBranch() { //Create the appearance an appearance for the two cubes Appearance app1 = new Appearance(); Appearance app2 = new Appearance(); Color3f ambientColour1 = new Color3f(1.0f, 0.0f, 0.0f); Color3f ambientColour2 = new Color3f(1.0f, 1.0f, 0.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour1 = new Color3f(1.0f, 0.0f, 0.0f); Color3f diffuseColour2 = new Color3f(1.0f, 1.0f, 0.0f); float shininess = 20.0f; app1.setMaterial(new Material(ambientColour1, emissiveColour, diffuseColour1, specularColour, shininess)); app2.setMaterial(new Material(ambientColour2, emissiveColour, diffuseColour2, specularColour, shininess)); //Make two cubes Box leftCube = new Box(1.0f, 1.0f, 1.0f, app1); Box rightCube = new Box(1.0f, 1.0f, 1.0f, app2); BranchGroup contentBranch = new BranchGroup(); addLights(contentBranch); //Put it all together Transform3D leftGroupXfm = new Transform3D(); leftGroupXfm.set(new Vector3d(-1.5, 0.0, 0.0)); TransformGroup leftGroup = new TransformGroup(leftGroupXfm); Transform3D rightGroupXfm = new Transform3D(); rightGroupXfm.set(new Vector3d(1.5, 0.0, 0.0)); TransformGroup rightGroup = new TransformGroup(rightGroupXfm); leftGroup.addChild(leftCube); rightGroup.addChild(rightCube); contentBranch.addChild(leftGroup); contentBranch.addChild(rightGroup); return contentBranch; }
From source file:MultiView.java
public BranchGroup createSceneBranchGroup() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); //Make the scene graph try {// ww w . j a v a2s.c om TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans); // Create appearance object for textured cube Appearance app = new Appearance(); Texture tex = new TextureLoader("Dog.jpg", this).getTexture(); app.setTexture(tex); // Create a simple shape leaf node, add it to the scene graph. Box textureCube = new Box(2, 3, 4, Box.GENERATE_TEXTURE_COORDS, app); objTrans.addChild(textureCube); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. 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, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator); } catch (RuntimeException e) { System.out.println("MultiView.createSceneBranchGroup:" + e.getMessage()); System.exit(-1); } return objRoot; }
From source file:SimpleLOD.java
/** * Build the content branch for the scene graph This creates three * cylinders, each with a different resolution. These are then used with a * LOD node to implement a crude level of detail. * //from ww w.ja v a2 s. c om * @return BranchGroup that is the root of the content */ protected BranchGroup buildContentBranch() { //Create the appearance Appearance app = new Appearance(); Color3f ambientColour = new Color3f(1.0f, 1.0f, 0.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour = new Color3f(1.0f, 1.0f, 0.0f); float shininess = 20.0f; app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); //Make the switch node that is to used with the LOD //and make it writable Switch LODswitch = new Switch(); LODswitch.setCapability(Switch.ALLOW_SWITCH_WRITE); //Add the three cylinders LODswitch.addChild(new Cylinder(1.0f, 1.0f, Cylinder.GENERATE_NORMALS, 10, 10, app)); LODswitch.addChild(new Cylinder(1.0f, 1.0f, Cylinder.GENERATE_NORMALS, 5, 5, app)); LODswitch.addChild(new Cylinder(1.0f, 1.0f, Cylinder.GENERATE_NORMALS, 3, 3, app)); //Define the distances for the LOD float[] LODdistances = { 5.0f, 10.0f, 15.0f }; DistanceLOD myLOD = new DistanceLOD(LODdistances, new Point3f(0.0f, 0.0f, 0.0f)); myLOD.setSchedulingBounds(bounds); //Add the switch to the LOD myLOD.addSwitch(LODswitch); BranchGroup contentBranch = new BranchGroup(); contentBranch.addChild(myLOD); addLights(contentBranch); contentBranch.addChild(LODswitch); return contentBranch; }
From source file:RedGreenGriffin.java
public BranchGroup createSceneGraph(int i) { System.out.println("Creating scene for: " + URLString); // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); try {/*from w ww. j av a 2s. com*/ Transform3D myTransform3D = new Transform3D(); myTransform3D.setTranslation(new Vector3f(+0.0f, -0.15f, -3.6f)); TransformGroup objTrans = new TransformGroup(myTransform3D); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D t = new Transform3D(); TransformGroup tg = new TransformGroup(t); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.addChild(tg); URL url = new URL(URLString); ObjectFile f = new ObjectFile(); f.setFlags(ObjectFile.RESIZE | ObjectFile.TRIANGULATE | ObjectFile.STRIPIFY); System.out.println("About to load"); Scene s = f.load(url); Transform3D myTrans = new Transform3D(); myTrans.setTranslation(new Vector3f(eyeOffset, -eyeOffset, 0F)); TransformGroup mytg = new TransformGroup(myTrans); //mytg.addChild(s.getSceneGroup()); tg.addChild(mytg); Transform3D myTrans2 = new Transform3D(); myTrans2.setTranslation(new Vector3f(-eyeOffset, +eyeOffset, 0F)); TransformGroup mytg2 = new TransformGroup(myTrans2); //mytg2.addChild(s.getSceneGroup()); Hashtable table = s.getNamedObjects(); for (Enumeration e = table.keys(); e.hasMoreElements();) { Object key = e.nextElement(); System.out.println(key); Object obj = table.get(key); System.out.println(obj.getClass().getName()); Shape3D shape = (Shape3D) obj; //shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); Appearance ap = new Appearance(); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f red = new Color3f(0.7f, .0f, .15f); Color3f green = new Color3f(0f, .7f, .15f); ap.setMaterial(new Material(green, black, green, black, 1.0f)); Appearance ap2 = new Appearance(); ap2.setMaterial(new Material(red, black, red, black, 1.0f)); float transparencyValue = 0.5f; TransparencyAttributes t_attr = new TransparencyAttributes(TransparencyAttributes.BLENDED, transparencyValue, TransparencyAttributes.BLEND_SRC_ALPHA, TransparencyAttributes.BLEND_ONE); ap2.setTransparencyAttributes(t_attr); ap2.setRenderingAttributes(new RenderingAttributes()); ap.setTransparencyAttributes(t_attr); ap.setRenderingAttributes(new RenderingAttributes()); // bg.addChild(ap); shape.setAppearance(ap); mytg2.addChild(new Shape3D(shape.getGeometry(), ap2)); mytg.addChild(new Shape3D(shape.getGeometry(), ap)); } tg.addChild(mytg2); System.out.println("Finished Loading"); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Color3f light1Color = new Color3f(.9f, 0.9f, 0.9f); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objTrans.addChild(light1); // Set up the ambient light Color3f ambientColor = new Color3f(1.0f, .4f, 0.3f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objTrans.addChild(ambientLightNode); MouseRotate behavior = new MouseRotate(); behavior.setTransformGroup(tg); objTrans.addChild(behavior); // Create the translate behavior node MouseTranslate behavior3 = new MouseTranslate(); behavior3.setTransformGroup(tg); objTrans.addChild(behavior3); behavior3.setSchedulingBounds(bounds); KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(tg); keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0)); objTrans.addChild(keyNavBeh); behavior.setSchedulingBounds(bounds); objRoot.addChild(objTrans); } catch (Throwable t) { System.out.println("Error: " + t); } return objRoot; }
From source file:TextureTransformTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.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); // create the rotation interpolator to rotate the scene RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(createApplicationBounds()); objTrans.addChild(rotator);// w w w.j av a 2 s.c o m // create the box final int nScale = 50; Appearance app = new Appearance(); Box box = new Box(nScale, nScale, nScale, Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS, app); // load the texture image TextureLoader texLoader = new TextureLoader("texture.gif", this); app.setTexture(texLoader.getTexture()); // set the texture attributes and ensure we // can write to the Transform for the texture attributes m_TextureAttributes = new TextureAttributes(); m_TextureAttributes.setCapability(TextureAttributes.ALLOW_TRANSFORM_WRITE); app.setTextureAttributes(m_TextureAttributes); // connect all the elements objTrans.addChild(box); objRoot.addChild(objTrans); objRoot.addChild(createRotator()); return objRoot; }
From source file:ModelClipTest.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // 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 w w w . j a v a 2 s . co m*/ objScale.setTransform(t3d); objRoot.addChild(objScale); // This Transformgroup is used by the mouse manipulators to // move the CYlinder. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objScale.addChild(objTrans); //Create Model Clip ModelClip mc = new ModelClip(); boolean enables[] = { false, false, false, false, false, false }; Vector4d eqn1 = new Vector4d(0.0, 1.0, 0.0, 0.0); Vector4d eqn2 = new Vector4d(1.0, 1.0, 0.0, 0.0); mc.setEnables(enables); mc.setPlane(1, eqn1); mc.setPlane(2, eqn2); mc.setEnable(1, true); mc.setEnable(2, true); mc.setInfluencingBounds(bounds); objTrans.addChild(mc); //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(1.0f, 2.0f, ap); objTrans.addChild(CylinderObj); // 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); //Shine it with two colored lights. 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); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2); lgt1.setInfluencingBounds(bounds); lgt2.setInfluencingBounds(bounds); objScale.addChild(lgt1); objScale.addChild(lgt2); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:AppearanceTest.java
private Appearance createAppearance(int idx) { Appearance app = new Appearance(); // Globally used colors Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); switch (idx) { // Unlit solid case 0: {/*www . jav a 2 s . com*/ // Set up the coloring properties Color3f objColor = new Color3f(1.0f, 0.2f, 0.4f); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(objColor); app.setColoringAttributes(ca); break; } // Unlit wire frame case 1: { // Set up the coloring properties Color3f objColor = new Color3f(0.5f, 0.0f, 0.2f); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(objColor); app.setColoringAttributes(ca); // Set up the polygon attributes PolygonAttributes pa = new PolygonAttributes(); pa.setPolygonMode(pa.POLYGON_LINE); pa.setCullFace(pa.CULL_NONE); app.setPolygonAttributes(pa); break; } // Unlit points case 2: { // Set up the coloring properties Color3f objColor = new Color3f(0.2f, 0.2f, 1.0f); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(objColor); app.setColoringAttributes(ca); // Set up the polygon attributes PolygonAttributes pa = new PolygonAttributes(); pa.setPolygonMode(pa.POLYGON_POINT); pa.setCullFace(pa.CULL_NONE); app.setPolygonAttributes(pa); // Set up point attributes PointAttributes pta = new PointAttributes(); pta.setPointSize(5.0f); app.setPointAttributes(pta); break; } // Lit solid case 3: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); break; } // Texture mapped, lit solid case 4: { // Set up the texture map TextureLoader tex = new TextureLoader(texImage, this); app.setTexture(tex.getTexture()); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); app.setTextureAttributes(texAttr); // Set up the material properties app.setMaterial(new Material(white, black, white, black, 1.0f)); break; } // Transparent, lit solid case 5: { // Set up the transparency properties TransparencyAttributes ta = new TransparencyAttributes(); ta.setTransparencyMode(ta.BLENDED); ta.setTransparency(0.6f); app.setTransparencyAttributes(ta); // Set up the polygon attributes PolygonAttributes pa = new PolygonAttributes(); pa.setCullFace(pa.CULL_NONE); app.setPolygonAttributes(pa); // Set up the material properties Color3f objColor = new Color3f(0.7f, 0.8f, 1.0f); app.setMaterial(new Material(objColor, black, objColor, black, 1.0f)); break; } // Lit solid, no specular case 6: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); break; } // Lit solid, specular only case 7: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); app.setMaterial(new Material(black, black, black, white, 80.0f)); break; } // Another lit solid with a different color case 8: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.8f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); break; } default: { ColoringAttributes ca = new ColoringAttributes(); ca.setColor(new Color3f(0.0f, 1.0f, 0.0f)); app.setColoringAttributes(ca); } } return app; }
From source file:InterpolatorTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); // create a root TG in case we need to scale the scene TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // create the Appearance for the Shape3D Appearance app = new Appearance(); // create a Material, modified by the ColorInterpolator Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Material mat = new Material(objColor, black, objColor, black, 80.0f); mat.setCapability(Material.ALLOW_COMPONENT_WRITE); app.setMaterial(mat);/* w ww. j av a 2s. c o m*/ // create a TransparencyAttributes, modified by the // TransparencyInterpolator TransparencyAttributes transparency = new TransparencyAttributes(); transparency.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE); transparency.setTransparencyMode(TransparencyAttributes.NICEST); app.setTransparencyAttributes(transparency); // create a Switch Node and set capabilities Switch switchNode = new Switch(); switchNode.setCapability(Switch.ALLOW_SWITCH_WRITE); // create a Alpha object for the Interpolators Alpha alpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 500, 100, 5000, 2000, 1000, 5000, 2000, 500); // add each BG and Interpolator as a child of the Switch Node TransformGroup tg = createSharedGroup(app); switchNode.addChild(createBranchGroup(tg, new ColorInterpolator(alpha, app.getMaterial()))); tg = createSharedGroup(app); switchNode.addChild(createBranchGroup(tg, new PositionInterpolator(alpha, tg))); tg = createSharedGroup(app); switchNode.addChild(createBranchGroup(tg, new RotationInterpolator(alpha, tg))); tg = createSharedGroup(app); switchNode.addChild(createBranchGroup(tg, new ScaleInterpolator(alpha, tg))); tg = createSharedGroup(app); switchNode.addChild(createBranchGroup(tg, new TransparencyInterpolator(alpha, app.getTransparencyAttributes(), 0, 0.8f))); // define the data for the RotPosScalePathInterpolator float[] knots = { 0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.6f, 0.8f, 0.9f, 1.0f }; float[] scales = { 0.2f, 0.5f, 0.8f, 2.3f, 5.4f, 0.6f, 0.4f, 0.2f, 0.1f }; Quat4f[] quats = new Quat4f[9]; Point3f[] positions = new Point3f[9]; quats[0] = new Quat4f(0.3f, 1.0f, 1.0f, 0.0f); quats[1] = new Quat4f(1.0f, 0.0f, 0.0f, 0.3f); quats[2] = new Quat4f(0.2f, 1.0f, 0.0f, 0.0f); quats[3] = new Quat4f(0.0f, 0.2f, 1.0f, 0.0f); quats[4] = new Quat4f(1.0f, 0.0f, 0.4f, 0.0f); quats[5] = new Quat4f(0.0f, 1.0f, 1.0f, 0.2f); quats[6] = new Quat4f(0.3f, 0.3f, 0.0f, 0.0f); quats[7] = new Quat4f(1.0f, 0.0f, 1.0f, 1.0f); quats[8] = quats[0]; positions[0] = new Point3f(0.0f, 0.0f, -1.0f); positions[1] = new Point3f(1.0f, -2.0f, -2.0f); positions[2] = new Point3f(-2.0f, 2.0f, -3.0f); positions[3] = new Point3f(1.0f, 1.0f, -4.0f); positions[4] = new Point3f(-4.0f, -2.0f, -5.0f); positions[5] = new Point3f(2.0f, 0.3f, -6.0f); positions[6] = new Point3f(-4.0f, 0.5f, -7.0f); positions[7] = new Point3f(0.0f, -1.5f, -4.0f); positions[8] = positions[0]; tg = createSharedGroup(app); // create the Interpolator RotPosScalePathInterpolator rotPosScalePathInterplator = new RotPosScalePathInterpolator(alpha, tg, new Transform3D(), knots, quats, positions, scales); // add a BG for the Interpolator switchNode.addChild(createBranchGroup(tg, rotPosScalePathInterplator)); // create a RandomAlpha object to control a SwitchInterpolator // to set the Switches active child node randomly RandomAlpha randomAlpha = new RandomAlpha(); // create the interpolator SwitchValueInterpolator switchInterpolator = new SwitchValueInterpolator(randomAlpha, switchNode); switchInterpolator.setSchedulingBounds(getApplicationBounds()); // connect the scenegraph objTrans.addChild(switchNode); objTrans.addChild(switchInterpolator); // Set up the global lights Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(getApplicationBounds()); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(getApplicationBounds()); // add the lights objRoot.addChild(aLgt); objRoot.addChild(lgt1); // connect objRoot.addChild(objTrans); return objRoot; }
From source file:SimpleBillboard.java
/** * Build the content branch for the scene graph. This creates two cubes and * uses a billboard node to keep one face of one of the cubes facing the * viewer.//from ww w . ja v a 2 s. c om * * @return BranchGroup that is the root of the content */ protected BranchGroup buildContentBranch() { //Create the appearance Appearance app = new Appearance(); Color3f ambientColour = new Color3f(1.0f, 1.0f, 0.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour = new Color3f(1.0f, 1.0f, 0.0f); float shininess = 20.0f; app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); //Make the cubes Box leftCube = new Box(1.0f, 1.0f, 1.0f, app); ColorCube rightCube = new ColorCube(); //Create the transformgroup used for the billboard TransformGroup billBoardGroup = new TransformGroup(); //Set the access rights to the group billBoardGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); //Add the cube to the group billBoardGroup.addChild(rightCube); //Create and activate the billboard Billboard myBillboard = new Billboard(billBoardGroup, Billboard.ROTATE_ABOUT_AXIS, new Vector3f(0.0f, 1.0f, 0.0f)); myBillboard.setSchedulingBounds(bounds); BranchGroup contentBranch = new BranchGroup(); contentBranch.addChild(myBillboard); addLights(contentBranch); //Position the cubes TransformGroup bothGroup = new TransformGroup(); Transform3D leftGroupXfm = new Transform3D(); leftGroupXfm.set(new Vector3d(-1.5, 0.0, 0.0)); TransformGroup leftGroup = new TransformGroup(leftGroupXfm); Transform3D rightGroupXfm = new Transform3D(); rightGroupXfm.set(new Vector3d(1.5, 0.0, 0.0)); TransformGroup rightGroup = new TransformGroup(rightGroupXfm); //Put it all together bothGroup.addChild(leftGroup); leftGroup.addChild(leftCube); bothGroup.addChild(rightGroup); rightGroup.addChild(billBoardGroup); contentBranch.addChild(bothGroup); return contentBranch; }
From source file:Drag.java
/** * Create the scenegraph for this program. *//* www . j a va2 s . com*/ public BranchGroup createSceneGraph() { // 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 ambientRed = new Color3f(0.2f, 0.05f, 0.0f); Color3f ambient = new Color3f(0.2f, 0.2f, 0.2f); Color3f diffuse = new Color3f(0.7f, 0.7f, 0.7f); Color3f specular = new Color3f(0.7f, 0.7f, 0.7f); Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); // Create the branch group BranchGroup branchGroup = 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); objScale.setTransform(t3d); branchGroup.addChild(objScale); // Create the bounding leaf node BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); BoundingLeaf boundingLeaf = new BoundingLeaf(bounds); objScale.addChild(boundingLeaf); // Set up the background Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.addChild(bg); // Create the ambient light AmbientLight ambLight = new AmbientLight(white); ambLight.setInfluencingBounds(bounds); objScale.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); objScale.addChild(dirLight); // Create the red appearance node Material redMaterial = new Material(ambientRed, black, red, specular, 75.0f); redMaterial.setLightingEnable(true); Appearance redAppearance = new Appearance(); redAppearance.setMaterial(redMaterial); // Create the white appearance node Material whiteMaterial = new Material(ambient, black, diffuse, specular, 75.0f); whiteMaterial.setLightingEnable(true); Appearance whiteAppearance = new Appearance(); whiteAppearance.setMaterial(whiteMaterial); // Create the transform node TransformGroup transformGroup = new TransformGroup(); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); transformGroup.addChild(new Cube(redAppearance).getChild()); // transformGroup.addChild(new Corners(whiteAppearance).getChild()); objScale.addChild(transformGroup); // Create the drag behavior node MouseRotate behavior = new MouseRotate(); behavior.setTransformGroup(transformGroup); transformGroup.addChild(behavior); behavior.setSchedulingBounds(bounds); // Create the zoom behavior node MouseZoom behavior2 = new MouseZoom(); behavior2.setTransformGroup(transformGroup); transformGroup.addChild(behavior2); behavior2.setSchedulingBounds(bounds); // Create the zoom behavior node MouseTranslate behavior3 = new MouseTranslate(); behavior3.setTransformGroup(transformGroup); transformGroup.addChild(behavior3); behavior3.setSchedulingBounds(bounds); // Let Java 3D perform optimizations on this scene graph. branchGroup.compile(); return branchGroup; }