List of usage examples for javax.media.j3d Appearance setMaterial
public void setMaterial(Material material)
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);/*w w w . j a va2s .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:edu.uci.ics.jung.visualization3d.PluggableRenderContext.java
public PluggableRenderContext() { super();//from www . j av a 2 s .co m 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:Licht.java
/** * Wurfeldarstellung/*from w w w. j ava2 s . c o m*/ * * @return Appearance */ private Appearance makeAppearance() { Appearance a = new Appearance(); Material mat = new Material(); mat.setShininess(50.0f); mat.setDiffuseColor(new Color3f(1.0f, 0.0f, 0.0f)); mat.setSpecularColor(new Color3f(0.0f, 0.0f, 0.0f)); a.setMaterial(mat); return a; }
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);/*w w w . j a va 2 s .c o 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:LitSphereApp.java
Appearance createAppearance() { Appearance appear = new Appearance(); Material material = new Material(); // material.setDiffuseColor(0.0f, 0.0f, 1.0f); material.setShininess(50.0f);/*ww w . jav a2 s . co m*/ // make modifications to default material properties appear.setMaterial(material); // ColoringAttributes colorAtt = new ColoringAttributes(); // colorAtt.setShadeModel(ColoringAttributes.SHADE_FLAT); // appear.setColoringAttributes(colorAtt); return appear; }
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 w ww. ja v a 2s . 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: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;//w w w.j av a 2s . c om // 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:BasicConstruct.java
/** * Adds a box to the universe//from www .j a v a 2s .co m * * @param x * The x dimension of the box * @param y * The y dimension of the box * @param z * The z dimension of the box */ public void addBox(float x, float y, float z, Color3f diffuse, Color3f spec) { // Add a box with the given dimension // First setup an appearance for the box Appearance app = new Appearance(); Material mat = new Material(); mat.setDiffuseColor(diffuse); mat.setSpecularColor(spec); mat.setShininess(5.0f); app.setMaterial(mat); Box box = new Box(x, y, z, app); // Create a TransformGroup and make it the parent of the box TransformGroup tg = new TransformGroup(); tg.addChild(box); // Then add it to the rootBranchGroup rootBranchGroup.addChild(tg); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); MouseRotate myMouseRotate = new MouseRotate(); myMouseRotate.setTransformGroup(tg); myMouseRotate.setSchedulingBounds(new BoundingSphere()); rootBranchGroup.addChild(myMouseRotate); MouseTranslate myMouseTranslate = new MouseTranslate(); myMouseTranslate.setTransformGroup(tg); myMouseTranslate.setSchedulingBounds(new BoundingSphere()); rootBranchGroup.addChild(myMouseTranslate); MouseZoom myMouseZoom = new MouseZoom(); myMouseZoom.setTransformGroup(tg); myMouseZoom.setSchedulingBounds(new BoundingSphere()); rootBranchGroup.addChild(myMouseZoom); }
From source file:Text3DApp.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); Transform3D t3D = new Transform3D(); t3D.setTranslation(new Vector3f(0.0f, 0.0f, -3.0f)); TransformGroup objMove = new TransformGroup(t3D); objRoot.addChild(objMove);// w w w . j a v a2 s .co m // Create the transform group node and initialize it to the // identity. Add it to the root of the subgraph. TransformGroup objSpin = new TransformGroup(); objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objMove.addChild(objSpin); Appearance textAppear = new Appearance(); ColoringAttributes textColor = new ColoringAttributes(); textColor.setColor(1.0f, 0.0f, 0.0f); textAppear.setColoringAttributes(textColor); textAppear.setMaterial(new Material()); // Create a simple shape leaf node, add it to the scene graph. Font3D font3D = new Font3D(new Font("Helvetica", Font.PLAIN, 1), new FontExtrusion()); Text3D textGeom = new Text3D(font3D, new String("3DText")); textGeom.setAlignment(Text3D.ALIGN_CENTER); Shape3D textShape = new Shape3D(); textShape.setGeometry(textGeom); textShape.setAppearance(textAppear); objSpin.addChild(textShape); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. Alpha rotationAlpha = new Alpha(-1, 10000); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin); // a bounding sphere specifies a region a behavior is active // create a sphere centered at the origin with radius of 100 BoundingSphere bounds = new BoundingSphere(); rotator.setSchedulingBounds(bounds); objSpin.addChild(rotator); DirectionalLight lightD = new DirectionalLight(); lightD.setInfluencingBounds(bounds); lightD.setDirection(new Vector3f(0.0f, 0.0f, -1.0f)); lightD.setColor(new Color3f(1.0f, 0.0f, 1.0f)); objMove.addChild(lightD); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(bounds); objMove.addChild(lightA); 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); // create a sphere and put it into a shared group Sphere sphere = new Sphere(0.5f, appearance); SharedGroup sphereSG = new SharedGroup(); sphereSG.addChild(sphere);/* www . ja v a 2 s . co m*/ // 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); } } }