List of usage examples for javax.media.j3d Material Material
public Material(Color3f ambientColor, Color3f emissiveColor, Color3f diffuseColor, Color3f specularColor, float shininess)
From source file:edu.uci.ics.jung.visualization3d.PluggableRenderContext.java
public PluggableRenderContext() { super();//from w w w .j a va 2 s. com Color3f lightGray = new Color3f(0.7f, 0.7f, 0.7f); Color3f black = new Color3f(0, 0, 0); Color3f white = new Color3f(1, 1, 1); Color3f gray = new Color3f(.2f, .2f, .2f); Color3f red = new Color3f(1, 0, 0); Color3f yellow = new Color3f(0, 1, 1); Material lightGrayMaterial = new Material(lightGray, black, lightGray, white, 100.0f); Material blackMaterial = new Material(lightGray, black, black, lightGray, 10.0f); Material whiteMaterial = new Material(white, white, white, white, 100.0f); Material grayMaterial = new Material(gray, black, gray, gray, 100.0f); Material redMaterial = new Material(red, black, red, red, 100.0f); Material yellowMaterial = new Material(yellow, black, yellow, yellow, 100.0f); final Appearance lightGrayLook = new Appearance(); lightGrayLook.setMaterial(lightGrayMaterial); Appearance blackLook = new Appearance(); blackLook.setMaterial(blackMaterial); Appearance whiteLook = new Appearance(); whiteLook.setMaterial(whiteMaterial); Appearance grayLook = new Appearance(); grayLook.setMaterial(grayMaterial); // grayLook.setCapability(Appearance.ALLOW_MATERIAL_READ); // grayLook.setCapability(Appearance.ALLOW_MATERIAL_WRITE); final Appearance redLook = new Appearance(); redLook.setMaterial(redMaterial); final Appearance yellowLook = new Appearance(); yellowLook.setMaterial(yellowMaterial); final Cylinder cylinder = new Cylinder(1, 1, Cylinder.GENERATE_NORMALS | Cylinder.ENABLE_GEOMETRY_PICKING, 26, 26, lightGrayLook); final Sphere sphere = new Sphere(10, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING, redLook); final Box box = new Box(10, 10, 10, Box.GENERATE_NORMALS | Box.ENABLE_GEOMETRY_PICKING, redLook); this.edgeAppearanceTransformer = new ConstantTransformer(lightGrayLook); this.edgeShapeTransformer = new Transformer<Context<Graph<V, E>, E>, Node>() { public Node transform(Context<Graph<V, E>, E> ec) { LineArray lineArray = new LineArray(2, LineArray.COORDINATES | LineArray.COLOR_3); lineArray.setCoordinates(0, new Point3f[] { new Point3f(0, -.5f, 0), new Point3f(0, .5f, 0) }); lineArray.setColor(0, new Color3f(1, 1, 1)); lineArray.setColor(1, new Color3f(1, 1, 1)); Shape3D shape = new Shape3D(); shape.setGeometry(lineArray); return shape; // return new Cylinder(1, 1, // Cylinder.GENERATE_NORMALS | // Cylinder.ENABLE_GEOMETRY_PICKING, // 26, 26, lightGrayLook); } }; this.vertexAppearanceTransformer = new ConstantTransformer(redLook); this.vertexShapeTransformer = new Transformer<V, Node>() { public Node transform(V arg0) { return new Sphere(10, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING | Sphere.ENABLE_APPEARANCE_MODIFY, redLook); } }; }
From source file:PictureBall.java
public PictureBall() { // Create the universe SimpleUniverse universe = new SimpleUniverse(); // Create a structure to contain objects BranchGroup group = new BranchGroup(); // Set up colors Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f red = new Color3f(0.7f, .15f, .15f); // Set up the texture map TextureLoader loader = new TextureLoader("K:\\3d\\Arizona.jpg", "LUMINANCE", new Container()); Texture texture = loader.getTexture(); texture.setBoundaryModeS(Texture.WRAP); texture.setBoundaryModeT(Texture.WRAP); texture.setBoundaryColor(new Color4f(0.0f, 1.0f, 0.0f, 0.0f)); // Set up the texture attributes //could be REPLACE, BLEND or DECAL instead of MODULATE TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); Appearance ap = new Appearance(); ap.setTexture(texture);/*from www. j av a2 s . co m*/ ap.setTextureAttributes(texAttr); //set up the material ap.setMaterial(new Material(red, black, red, black, 1.0f)); // Create a ball to demonstrate textures int primflags = Primitive.GENERATE_NORMALS + Primitive.GENERATE_TEXTURE_COORDS; Sphere sphere = new Sphere(0.5f, primflags, ap); group.addChild(sphere); // Create lights Color3f light1Color = new Color3f(1f, 1f, 1f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); group.addChild(light1); AmbientLight ambientLight = new AmbientLight(new Color3f(.5f, .5f, .5f)); ambientLight.setInfluencingBounds(bounds); group.addChild(ambientLight); // look towards the ball universe.getViewingPlatform().setNominalViewingTransform(); // add the group of objects to the Universe universe.addBranchGraph(group); }
From source file:PickText3DBounds.java
public BranchGroup createSceneGraph(Canvas3D canvas) { Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f); Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f); Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f); Color3f lColor1 = new Color3f(1.0f, 0.0f, 0.0f); Color3f lColor2 = new Color3f(0.0f, 1.0f, 0.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Transform3D t;/* ww w.j a v a 2 s . co m*/ // 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); objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bounds for the background and lights BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.addChild(bg); Material m = new Material(objColor, eColor, objColor, sColor, 100.0f); Appearance a = new Appearance(); m.setLightingEnable(true); a.setMaterial(m); Font3D f3d = new Font3D(new Font("TestFont", Font.PLAIN, 1), new FontExtrusion()); Text3D txt = new Text3D(f3d, new String("TEXT3D"), new Point3f(-2.0f, 0.0f, 0.0f)); // txt.setCapability(Geometry.ALLOW_INTERSECT); Shape3D s3D = new Shape3D(); s3D.setGeometry(txt); s3D.setAppearance(a); // Create a transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. TransformGroup spinTg = new TransformGroup(); spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); spinTg.setCapability(TransformGroup.ENABLE_PICK_REPORTING); spinTg.addChild(s3D); objScale.addChild(spinTg); // Create the transform group node for the each light and initialize // it to the identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add them to the root // of the subgraph. // Create transformations for the positional lights t = new Transform3D(); Vector3d lPos1 = new Vector3d(0.0, 0.0, 2.0); t.set(lPos1); TransformGroup l1Trans = new TransformGroup(t); l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); l1Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING); objScale.addChild(l1Trans); t = new Transform3D(); Vector3d lPos2 = new Vector3d(0.5, 0.8, 2.0); t.set(lPos2); TransformGroup l2Trans = new TransformGroup(t); l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); l2Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING); objScale.addChild(l2Trans); // Create Geometry for point lights ColoringAttributes caL1 = new ColoringAttributes(); ColoringAttributes caL2 = new ColoringAttributes(); caL1.setColor(lColor1); caL2.setColor(lColor2); Appearance appL1 = new Appearance(); Appearance appL2 = new Appearance(); appL1.setColoringAttributes(caL1); appL2.setColoringAttributes(caL2); l1Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS, 15, appL1)); l2Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS, 15, appL2)); // Create lights AmbientLight aLgt = new AmbientLight(alColor); Light lgt1; Light lgt2; Point3f lPoint = new Point3f(0.0f, 0.0f, 0.0f); Point3f atten = new Point3f(1.0f, 0.0f, 0.0f); lgt1 = new PointLight(lColor1, lPoint, atten); lgt2 = new PointLight(lColor2, lPoint, atten); // Set the influencing bounds aLgt.setInfluencingBounds(bounds); lgt1.setInfluencingBounds(bounds); lgt2.setInfluencingBounds(bounds); // Add the lights into the scene graph objScale.addChild(aLgt); l1Trans.addChild(lgt1); l2Trans.addChild(lgt2); PickRotateBehavior behavior1 = new PickRotateBehavior(objRoot, canvas, bounds); behavior1.setMode(PickTool.BOUNDS); objRoot.addChild(behavior1); PickZoomBehavior behavior2 = new PickZoomBehavior(objRoot, canvas, bounds); behavior2.setMode(PickTool.BOUNDS); objRoot.addChild(behavior2); PickTranslateBehavior behavior3 = new PickTranslateBehavior(objRoot, canvas, bounds); behavior3.setMode(PickTool.BOUNDS); objRoot.addChild(behavior3); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:SimpleMouse.java
/** * Build the content branch for the scene graph * /*from w w w .j a v a 2 s . c o m*/ * @return BranchGroup that is the root of the content */ protected BranchGroup buildContentBranch() { Appearance app = new Appearance(); Color3f ambientColour = new Color3f(1.0f, 0.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, 0.0f, 0.0f); float shininess = 20.0f; app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); Box cube = new Box(2.0f, 2.0f, 2.0f, app); BranchGroup contentBranch = new BranchGroup(); addLights(contentBranch); //Create the transform groups that will be //affected by the mouse utiltities TransformGroup spinGroup = new TransformGroup(); TransformGroup zoomGroup = new TransformGroup(); TransformGroup moveGroup = new TransformGroup(); //Set the capabilities of the groups so that we can //manipulate them spinGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); spinGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); zoomGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); zoomGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); moveGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); moveGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); //Create and use the rotation utility MouseRotate mouseSpin = new MouseRotate(); mouseSpin.setTransformGroup(spinGroup); contentBranch.addChild(mouseSpin); mouseSpin.setSchedulingBounds(bounds); //Create and use the zoom utility MouseZoom mouseSize = new MouseZoom(); mouseSize.setTransformGroup(zoomGroup); contentBranch.addChild(mouseSize); mouseSize.setSchedulingBounds(bounds); //Create and use the translation utility MouseTranslate mouseMove = new MouseTranslate(); mouseMove.setTransformGroup(moveGroup); contentBranch.addChild(mouseMove); mouseMove.setSchedulingBounds(bounds); //Put it all together spinGroup.addChild(cube); moveGroup.addChild(spinGroup); zoomGroup.addChild(moveGroup); contentBranch.addChild(zoomGroup); return contentBranch; }
From source file:Drag.java
/** * Create the scenegraph for this program. *//*from www . j a v a 2 s.co m*/ 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; }
From source file:SimpleSphere.java
protected BranchGroup buildContentBranch() { BranchGroup contentBranch = new BranchGroup(); Transform3D rotateCube = new Transform3D(); rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0)); // rotateCube.set(new AxisAngle4d(1.0,0.0,0.0,Math.PI/2.0)); TransformGroup rotationGroup = new TransformGroup(rotateCube); contentBranch.addChild(rotationGroup); Appearance app = new Appearance(); Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f); Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); float shininess = 20.0f; app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); rotationGroup.addChild(new Sphere(2.0f, Sphere.GENERATE_NORMALS, 120, app)); addLights(contentBranch);/* ww w .j ava 2 s . c o m*/ return contentBranch; }
From source file:PickText3DGeometry.java
public BranchGroup createSceneGraph(Canvas3D canvas) { Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f); Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f); Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f); Color3f lColor1 = new Color3f(1.0f, 0.0f, 0.0f); Color3f lColor2 = new Color3f(0.0f, 1.0f, 0.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Transform3D t;/*from w w w . ja va2s . c o m*/ // 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); objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bounds for the background and lights BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.addChild(bg); Material m = new Material(objColor, eColor, objColor, sColor, 100.0f); Appearance a = new Appearance(); m.setLightingEnable(true); a.setMaterial(m); Font3D f3d = new Font3D(new Font("TestFont", Font.PLAIN, 1), new FontExtrusion()); Text3D text3D = new Text3D(f3d, new String("TEXT3D"), new Point3f(-2.0f, 0.7f, 0.0f)); text3D.setCapability(Geometry.ALLOW_INTERSECT); Shape3D s3D1 = new Shape3D(); s3D1.setGeometry(text3D); s3D1.setAppearance(a); // Create a transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. TransformGroup spinTg1 = new TransformGroup(); spinTg1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); spinTg1.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); spinTg1.setCapability(TransformGroup.ENABLE_PICK_REPORTING); spinTg1.addChild(s3D1); objScale.addChild(spinTg1); Text3D pick = new Text3D(f3d, new String("Pick me"), new Point3f(-2.0f, -0.7f, 0.0f)); pick.setCapability(Geometry.ALLOW_INTERSECT); Shape3D s3D2 = new Shape3D(); s3D2.setGeometry(pick); s3D2.setAppearance(a); // Create a transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. TransformGroup spinTg2 = new TransformGroup(); spinTg2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); spinTg2.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); spinTg2.setCapability(TransformGroup.ENABLE_PICK_REPORTING); spinTg2.addChild(s3D2); objScale.addChild(spinTg2); // Create the transform group node for the each light and initialize // it to the identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add them to the root // of the subgraph. // Create transformations for the positional lights t = new Transform3D(); Vector3d lPos1 = new Vector3d(0.0, 0.0, 2.0); t.set(lPos1); TransformGroup l1Trans = new TransformGroup(t); l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); l1Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING); objScale.addChild(l1Trans); t = new Transform3D(); Vector3d lPos2 = new Vector3d(0.5, 1.2, 2.0); t.set(lPos2); TransformGroup l2Trans = new TransformGroup(t); l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); l2Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING); objScale.addChild(l2Trans); // Create Geometry for point lights ColoringAttributes caL1 = new ColoringAttributes(); ColoringAttributes caL2 = new ColoringAttributes(); caL1.setColor(lColor1); caL2.setColor(lColor2); Appearance appL1 = new Appearance(); Appearance appL2 = new Appearance(); appL1.setColoringAttributes(caL1); appL2.setColoringAttributes(caL2); l1Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING, 15, appL1)); l2Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING, 15, appL2)); // Create lights AmbientLight aLgt = new AmbientLight(alColor); Light lgt1; Light lgt2; Point3f lPoint = new Point3f(0.0f, 0.0f, 0.0f); Point3f atten = new Point3f(1.0f, 0.0f, 0.0f); lgt1 = new PointLight(lColor1, lPoint, atten); lgt2 = new PointLight(lColor2, lPoint, atten); // Set the influencing bounds aLgt.setInfluencingBounds(bounds); lgt1.setInfluencingBounds(bounds); lgt2.setInfluencingBounds(bounds); // Add the lights into the scene graph objScale.addChild(aLgt); l1Trans.addChild(lgt1); l2Trans.addChild(lgt2); PickRotateBehavior behavior1 = new PickRotateBehavior(objRoot, canvas, bounds); behavior1.setMode(PickTool.GEOMETRY); behavior1.setTolerance(0.0f); objRoot.addChild(behavior1); PickZoomBehavior behavior2 = new PickZoomBehavior(objRoot, canvas, bounds); behavior2.setMode(PickTool.GEOMETRY); behavior2.setTolerance(0.0f); objRoot.addChild(behavior2); PickTranslateBehavior behavior3 = new PickTranslateBehavior(objRoot, canvas, bounds); behavior3.setMode(PickTool.GEOMETRY); behavior3.setTolerance(0.0f); objRoot.addChild(behavior3); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
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 ww w . j a v a2 s .c o m 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: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. * /*ww w. j a v a 2s . co m*/ * @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:SimpleDirLight.java
/** * This build the content branch of our scene graph. It creates a transform * group so that the shape is slightly tilted to reveal its 3D shape. * /* w ww. ja v a2 s . c o m*/ * @param shape * Node that represents the geometry for the content * @return BranchGroup that is the root of the content branch */ protected BranchGroup buildContentBranch() { BranchGroup contentBranch = new BranchGroup(); Transform3D rotateCube = new Transform3D(); rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0)); TransformGroup rotationGroup = new TransformGroup(rotateCube); contentBranch.addChild(rotationGroup); //Create a new appearance Appearance app = new Appearance(); //Create the colours for the material Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f); Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); //Define the shininess float shininess = 20.0f; //Set the material of the appearance app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); //Create and add a new sphere using the appearance rotationGroup.addChild(new Sphere(2.0f, Sphere.GENERATE_NORMALS, 120, app)); //Use the addLights function to add the lights to the branch addLights(contentBranch); //Return the root of the content branch return contentBranch; }