List of usage examples for javax.media.j3d Material Material
public Material()
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 . com*/ 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:ExLinearFog.java
public ColumnScene(Component observer) { BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Add a few lights AmbientLight ambient = new AmbientLight(); ambient.setEnable(true);//from w ww. j a va2 s .c o m ambient.setColor(new Color3f(0.2f, 0.2f, 0.2f)); ambient.setInfluencingBounds(worldBounds); addChild(ambient); DirectionalLight dir1 = new DirectionalLight(); dir1.setEnable(true); dir1.setColor(new Color3f(1.0f, 1.0f, 1.0f)); dir1.setDirection(new Vector3f(0.8f, -0.35f, 0.5f)); dir1.setInfluencingBounds(worldBounds); addChild(dir1); DirectionalLight dir2 = new DirectionalLight(); dir2.setEnable(true); dir2.setColor(new Color3f(0.75f, 0.75f, 1.0f)); dir2.setDirection(new Vector3f(-0.7f, -0.35f, -0.5f)); dir2.setInfluencingBounds(worldBounds); addChild(dir2); // Load textures TextureLoader texLoader = new TextureLoader("grass06.jpg", observer); Texture grassTex = texLoader.getTexture(); if (grassTex == null) System.err.println("Cannot load grass06.jpg texture"); else { grassTex.setBoundaryModeS(Texture.WRAP); grassTex.setBoundaryModeT(Texture.WRAP); grassTex.setMinFilter(Texture.NICEST); grassTex.setMagFilter(Texture.NICEST); grassTex.setMipMapMode(Texture.BASE_LEVEL); grassTex.setEnable(true); } texLoader = new TextureLoader("marble10.jpg", observer); Texture walkTex = texLoader.getTexture(); if (walkTex == null) System.err.println("Cannot load marble10.jpg texture"); else { walkTex.setBoundaryModeS(Texture.WRAP); walkTex.setBoundaryModeT(Texture.WRAP); walkTex.setMinFilter(Texture.NICEST); walkTex.setMagFilter(Texture.NICEST); walkTex.setMipMapMode(Texture.BASE_LEVEL); walkTex.setEnable(true); } texLoader = new TextureLoader("granite07rev.jpg", observer); columnTex = texLoader.getTexture(); if (columnTex == null) System.err.println("Cannot load granite07rev.jpg texture"); else { columnTex.setBoundaryModeS(Texture.WRAP); columnTex.setBoundaryModeT(Texture.WRAP); columnTex.setMinFilter(Texture.NICEST); columnTex.setMagFilter(Texture.NICEST); columnTex.setMipMapMode(Texture.BASE_LEVEL); columnTex.setEnable(true); } // // Build the ground // +-----+---+-----+ // | | | | // | G | W | G | // | | | | // +-----+---+-----+ // // where "G" is grass, and "W" is a walkway between columns // Vector3f trans = new Vector3f(); Transform3D tr = new Transform3D(); TransformGroup tg; // Walkway appearance Appearance walkApp = new Appearance(); Material walkMat = new Material(); walkMat.setAmbientColor(0.5f, 0.5f, 0.5f); walkMat.setDiffuseColor(1.0f, 1.0f, 1.0f); walkMat.setSpecularColor(0.0f, 0.0f, 0.0f); walkApp.setMaterial(walkMat); TextureAttributes walkTexAtt = new TextureAttributes(); walkTexAtt.setTextureMode(TextureAttributes.MODULATE); walkTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST); tr.setIdentity(); tr.setScale(new Vector3d(1.0, 6.0, 1.0)); walkTexAtt.setTextureTransform(tr); walkApp.setTextureAttributes(walkTexAtt); if (walkTex != null) walkApp.setTexture(walkTex); // Grass appearance Appearance grassApp = new Appearance(); Material grassMat = new Material(); grassMat.setAmbientColor(0.5f, 0.5f, 0.5f); grassMat.setDiffuseColor(1.0f, 1.0f, 1.0f); grassMat.setSpecularColor(0.0f, 0.0f, 0.0f); grassApp.setMaterial(grassMat); TextureAttributes grassTexAtt = new TextureAttributes(); grassTexAtt.setTextureMode(TextureAttributes.MODULATE); grassTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST); tr.setIdentity(); tr.setScale(new Vector3d(2.0, 8.0, 1.0)); grassTexAtt.setTextureTransform(tr); grassApp.setTextureAttributes(grassTexAtt); if (grassTex != null) grassApp.setTexture(grassTex); // Left grass trans.set(-LawnWidth / 2.0f - WalkwayWidth / 2.0f, -1.6f, 0.0f); tr.set(trans); tg = new TransformGroup(tr); ElevationGrid grass1 = new ElevationGrid(2, // X dimension 2, // Z dimension LawnWidth, // X spacing LawnDepth, // Z spacing grassApp); // appearance tg.addChild(grass1); addChild(tg); // Right grass trans.set(LawnWidth / 2.0f + WalkwayWidth / 2.0f, -1.6f, 0.0f); tr.set(trans); tg = new TransformGroup(tr); ElevationGrid grass2 = new ElevationGrid(2, // X dimension 2, // Z dimension LawnWidth, // X spacing LawnDepth, // Z spacing grassApp); // appearance tg.addChild(grass2); addChild(tg); // Walkway trans.set(0.0f, -1.6f, 0.0f); tr.set(trans); tg = new TransformGroup(tr); ElevationGrid walk = new ElevationGrid(2, // X dimension 2, // Z dimension WalkwayWidth, // X spacing WalkwayDepth, // Z spacing walkApp); // appearance tg.addChild(walk); addChild(tg); // // Build several columns on the floor // SharedGroup column = buildSharedColumn(); Group columns = buildColumns(column); addChild(columns); }
From source file:AppearanceTest.java
protected NodeComponent createComponent() { return (NodeComponent) new Material(); }
From source file:ExSpotLight.java
public SphereGroup(float radius, float xSpacing, float ySpacing, int xCount, int yCount, Appearance app) { 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);//from 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; 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; } y += ySpacing; } }