List of usage examples for javax.media.j3d Appearance setMaterial
public void setMaterial(Material material)
From source file:ScenegraphTest.java
private void addHead(Group parentGroup) { // add a cylinder for the Neck TransformGroup tgNeck = addLimb(parentGroup, "Neck", 0.05, 0.2, 0.0, 0.0); Appearance app = new Appearance(); Color3f black = new Color3f(0.4f, 0.2f, 0.1f); Color3f objColor = new Color3f(1, 0.8f, 0.6f); app.setMaterial(new Material(objColor, black, objColor, black, 90.0f)); // position a Sphere for the head itself Sphere headSphere = new Sphere((float) 0.12, Primitive.GENERATE_NORMALS, app); tgNeck.addChild(headSphere);/*w w w.ja va2s. c om*/ }
From source file:SimpleTextureGen.java
/** * This defines the appearance for the shape using a texture. It uses a * TextureLoader to load the texture image from an external file and a * TexCoordGeneration to define the texture coordinates. * //www . j av a 2s . c om * @return Appearance that uses a texture. */ protected Appearance DefineAppearance() { //This is used to automatically define the texture coordinates. //The coordinates are generated in object coordinates, but by //commented out the line with 'OBJECT_LINEAR' and uncommenting //the line 'EYE_LINEAR' the program will use eye coordinates. TexCoordGeneration textCoorder = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR, //TexCoordGeneration.EYE_LINEAR, TexCoordGeneration.TEXTURE_COORDINATE_2); //Load the texture from the external image file TextureLoader textLoad = new TextureLoader("housebrick.jpg", this); //Access the image from the loaded texture ImageComponent2D textImage = textLoad.getImage(); //Create a two dimensional texture Texture2D texture = new Texture2D(Texture2D.BASE_LEVEL, Texture.RGB, textImage.getWidth(), textImage.getHeight()); //Set the texture from the image loaded texture.setImage(0, textImage); //Create the appearance that will use the texture Appearance app = new Appearance(); app.setTexture(texture); //Pass the coordinate generator to the appearance app.setTexCoordGeneration(textCoorder); //Define how the texture will be mapped onto the surface //by creating the appropriate texture attributes TextureAttributes textAttr = new TextureAttributes(); textAttr.setTextureMode(TextureAttributes.REPLACE); app.setTextureAttributes(textAttr); app.setMaterial(new Material()); return app; }
From source file:SimpleKeyNav.java
/** * Build the content branch for the scene graph * /*from w w w . j a v a2 s .c om*/ * @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:ScenegraphTest.java
TransformGroup createLimb(double radius, double length) { // because the cylinder is centered at 0,0,0 // we need to shift the cylinder so that the bottom of // the cylinder is at 0,0,0 and the top is at 0, length, 0 TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(0, length / 2, 0)); tg.setTransform(t3d);/*from w w w . j a v a2s . c om*/ Appearance app = new Appearance(); Color3f black = new Color3f(0.4f, 0.2f, 0.1f); Color3f objColor = new Color3f(1, 0.8f, 0.6f); app.setMaterial(new Material(objColor, black, objColor, black, 90.0f)); Cylinder cylinder = new Cylinder((float) radius, (float) length, Primitive.GENERATE_NORMALS, app); tg.addChild(cylinder); return tg; }
From source file:SimpleTest.java
public BranchGroup createSceneGraph() { // create a parent BranchGroup node for the Sphere BranchGroup bg = new BranchGroup(); // create an Appearance for the Sphere. // The Appearance object controls various rendering // options for the Sphere geometry. Appearance app = new Appearance(); // assign a Material to the Appearance. For the Sphere // to respond to the light in the scene it must have a Material. // Assign some colors to the Material and a shininess setting // that controls how reflective the surface is to lighting. Color3f objColor = new Color3f(0.8f, 0.2f, 1.0f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); // create a Sphere with a radius of 0.1 // and associate the Appearance that we described. // the option GENERATE_NORMALS is required to ensure that the // Sphere responds correctly to lighting. Sphere sphere = new Sphere(0.1f, Primitive.GENERATE_NORMALS, app); // add the sphere to the BranchGroup to wire // it into the scene. bg.addChild(sphere);//from w w w .j a va 2 s. c o m return bg; }
From source file:AlternateAppearanceScopeTest.java
BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); // Create influencing bounds worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent Transform3D t = new Transform3D(); // move the object upwards t.set(new Vector3f(0.0f, 0.1f, 0.0f)); // Shrink the object t.setScale(0.8);//from w ww. j a v a2s . c om TransformGroup trans = new TransformGroup(t); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); otherApp = new Appearance(); altMat = new Material(); altMat.setCapability(Material.ALLOW_COMPONENT_WRITE); altMat.setDiffuseColor(new Color3f(0.0f, 1.0f, 0.0f)); otherApp.setMaterial(altMat); altApp = new AlternateAppearance(); altApp.setAppearance(otherApp); altApp.setCapability(AlternateAppearance.ALLOW_SCOPE_WRITE); altApp.setCapability(AlternateAppearance.ALLOW_SCOPE_READ); altApp.setInfluencingBounds(worldBounds); objRoot.addChild(altApp); // Build foreground geometry into two groups. We'll // create three directional lights below, one each with // scope to cover the first geometry group only, the // second geometry group only, or both geometry groups. Appearance app1 = new Appearance(); mat1 = new Material(); mat1.setCapability(Material.ALLOW_COMPONENT_WRITE); mat1.setDiffuseColor(new Color3f(1.0f, 0.0f, 0.0f)); app1.setMaterial(mat1); content1 = new SphereGroup(0.05f, // radius of spheres 0.4f, // x spacing 0.2f, // y spacing 3, // number of spheres in X 5, // number of spheres in Y app1, // appearance true); // alt app override = true trans.addChild(content1); shapes1 = ((SphereGroup) content1).getShapes(); content2 = new SphereGroup(0.05f, // radius of spheres .4f, // x spacing 0.2f, // y spacing 2, // number of spheres in X 5, // number of spheres in Y app1, // appearance true); // alt app override = true trans.addChild(content2); shapes2 = ((SphereGroup) content2).getShapes(); // Add lights DirectionalLight light1 = null; light1 = new DirectionalLight(); light1.setEnable(true); light1.setColor(new Color3f(0.2f, 0.2f, 0.2f)); light1.setDirection(new Vector3f(1.0f, 0.0f, -1.0f)); light1.setInfluencingBounds(worldBounds); objRoot.addChild(light1); DirectionalLight light2 = new DirectionalLight(); light2.setEnable(true); light2.setColor(new Color3f(0.2f, 0.2f, 0.2f)); light2.setDirection(new Vector3f(-1.0f, 0.0f, 1.0f)); light2.setInfluencingBounds(worldBounds); objRoot.addChild(light2); // Add an ambient light to dimly illuminate the rest of // the shapes in the scene to help illustrate that the // directional lights are being scoped... otherwise it looks // like we're just removing shapes from the scene AmbientLight ambient = new AmbientLight(); ambient.setEnable(true); ambient.setColor(new Color3f(1.0f, 1.0f, 1.0f)); ambient.setInfluencingBounds(worldBounds); objRoot.addChild(ambient); objRoot.addChild(trans); return objRoot; }
From source file:ConicWorld.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); idx = idx % 5;/*from w w w . j ava 2s . com*/ switch (idx) { // Lit solid case 0: { // 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; } // Lit solid, no specular case 1: { // Set up the material properties Color3f objColor = new Color3f(0.0f, 0.8f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); break; } // Lit solid, specular only case 2: { // Set up the material properties Color3f objColor = new Color3f(0.0f, 0.8f, 0.8f); app.setMaterial(new Material(black, black, objColor, white, 80.0f)); break; } // Texture mapped, lit solid case 3: { // Set up the texture map TextureLoader tex = new TextureLoader(texImage, this); app.setTexture(tex.getTexture()); // Set up the material properties app.setMaterial(new Material(white, black, white, black, 1.0f)); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); app.setTextureAttributes(texAttr); break; } // Another lit solid with a different color case 4: { // Set up the material properties Color3f objColor = new Color3f(1.0f, 1.0f, 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:MixedTest.java
public void renderField(int fieldDesc) { super.renderField(fieldDesc); GraphicsContext3D g = getGraphicsContext3D(); // first time initialization if (m_nRender == 0) { // set the start time m_StartTime = System.currentTimeMillis(); // add a light to the graphics context DirectionalLight light = new DirectionalLight(); light.setEnable(true);/*ww w.j a va2 s .co m*/ g.addLight((Light) light); // create the material for the points Appearance a = new Appearance(); Material mat = new Material(); mat.setLightingEnable(true); mat.setAmbientColor(0.5f, 1.0f, 1.0f); a.setMaterial(mat); a.setColoringAttributes(new ColoringAttributes(1.0f, 0.5f, 0.5f, ColoringAttributes.NICEST)); // enlarge the points a.setPointAttributes(new PointAttributes(4, true)); // make the appearance current in the graphics context g.setAppearance(a); } // set the current transformation for the graphics context g.setModelTransform(m_t3d); // finally render the PointArray g.draw(m_PointArray); // calculate and display the Frames Per Second for the // Immediate Mode rendering of the PointArray m_nRender++; if ((m_nRender % m_kReportInterval) == 0) { float fps = (float) 1000.0f / ((System.currentTimeMillis() - m_StartTime) / (float) m_kReportInterval); System.out.println("FPS:\t" + fps); m_StartTime = System.currentTimeMillis(); } }
From source file:PickWorld.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); Color3f gray = new Color3f(0.4f, 0.4f, 0.4f); idx = idx % 5;/* www . j a va 2s . c om*/ switch (idx) { // Lit solid case 0: { // Set up the material properties Color3f objColor = new Color3f(0.0f, 0.8f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); break; } // Lit solid, specular only case 1: { // Set up the material properties Color3f objColor = new Color3f(0.0f, 0.4f, 0.2f); app.setMaterial(new Material(black, black, objColor, white, 80.0f)); break; } case 2: { // Set up the texture map TextureLoader tex = new TextureLoader("apimage.jpg", this); app.setTexture(tex.getTexture()); // Set up the material properties app.setMaterial(new Material(gray, black, gray, white, 1.0f)); break; } // Texture mapped, lit solid case 3: { // Set up the texture map TextureLoader tex = new TextureLoader("earth.jpg", this); app.setTexture(tex.getTexture()); // Set up the material properties app.setMaterial(new Material(gray, black, gray, white, 1.0f)); break; } // Another lit solid with a different color case 4: { // Set up the material properties Color3f objColor = new Color3f(1.0f, 1.0f, 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:SwingTest.java
/** * Create a BranchGroup that contains a Sphere. The user data for the * BranchGroup is set so the BranchGroup can be identified. *///from w ww . j a va2s.com protected BranchGroup createSphere() { BranchGroup bg = new BranchGroup(); bg.setCapability(BranchGroup.ALLOW_DETACH); Appearance app = new Appearance(); Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); bg.addChild(new com.sun.j3d.utils.geometry.Sphere(1, app)); bg.setUserData("Sphere"); return bg; }