List of usage examples for javax.media.j3d Texture BASE_LEVEL
int BASE_LEVEL
To view the source code for javax.media.j3d Texture BASE_LEVEL.
Click Source Link
From source file:J3dSwingFrame.java
/** * Set the texture on our goemetry// w w w . ja va2s . com * <P> * Always specified as a URL so that we may fetch it from anywhere. * * @param url * The url to the image. */ public void setTexture(URL url) { Toolkit tk = Toolkit.getDefaultToolkit(); Image src_img = tk.createImage(url); BufferedImage buf_img = null; if (!(src_img instanceof BufferedImage)) { // create a component anonymous inner class to give us the image // observer we need to get the width and height of the source image. Component obs = new Component() { }; int width = src_img.getWidth(obs); int height = src_img.getHeight(obs); // construct the buffered image from the source data. buf_img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics g = buf_img.getGraphics(); g.drawImage(src_img, 0, 0, null); g.dispose(); } else buf_img = (BufferedImage) src_img; src_img.flush(); ImageComponent img_comp = new ImageComponent2D(ImageComponent.FORMAT_RGB, buf_img); texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, img_comp.getWidth(), img_comp.getHeight()); appearance.setTexture(texture); buf_img.flush(); }
From source file:AppearanceExplorer.java
void setupAppearance() { appearance = new Appearance(); // ColoringAttributes coloringColor = new Color3f(red); coloringAttr = new ColoringAttributes(coloringColor, coloringShadeModel); coloringAttr.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE); coloringAttr.setCapability(ColoringAttributes.ALLOW_SHADE_MODEL_WRITE); appearance.setColoringAttributes(coloringAttr); // set up the editor coloringAttrEditor = new ColoringAttributesEditor(coloringAttr); // PointAttributes pointAttr = new PointAttributes(pointSize, pointAAEnable); pointAttr.setCapability(PointAttributes.ALLOW_SIZE_WRITE); pointAttr.setCapability(PointAttributes.ALLOW_ANTIALIASING_WRITE); appearance.setPointAttributes(pointAttr); // set up the editor pointAttrEditor = new PointAttributesEditor(pointAttr); // LineAttributes lineAttr = new LineAttributes(lineWidth, linePattern, lineAAEnable); lineAttr.setCapability(LineAttributes.ALLOW_WIDTH_WRITE); lineAttr.setCapability(LineAttributes.ALLOW_PATTERN_WRITE); lineAttr.setCapability(LineAttributes.ALLOW_ANTIALIASING_WRITE); appearance.setLineAttributes(lineAttr); // set up the editor lineAttrEditor = new LineAttributesEditor(lineAttr); // PolygonAttributes polygonAttr = new PolygonAttributes(polygonMode, polygonCull, 0.0f); polygonAttr.setPolygonOffset(polygonOffsetBias); polygonAttr.setPolygonOffsetFactor(polygonOffsetFactor); polygonAttr.setCapability(PolygonAttributes.ALLOW_MODE_WRITE); polygonAttr.setCapability(PolygonAttributes.ALLOW_CULL_FACE_WRITE); polygonAttr.setCapability(PolygonAttributes.ALLOW_OFFSET_WRITE); appearance.setPolygonAttributes(polygonAttr); // set up the editor polygonAttrEditor = new PolygonAttributesEditor(polygonAttr); // Rendering attributes renderAttr = new RenderingAttributes(renderDepthBuffer, renderDepthBufferWrite, 0.0f, RenderingAttributes.ALWAYS, renderVisible, renderIgnoreVertexColor, renderRasterOpEnable, renderRasterOp);//from ww w .j av a 2s. c o m renderAttr.setCapability(RenderingAttributes.ALLOW_IGNORE_VERTEX_COLORS_WRITE); renderAttr.setCapability(RenderingAttributes.ALLOW_VISIBLE_WRITE); renderAttr.setCapability(RenderingAttributes.ALLOW_RASTER_OP_WRITE); renderAttr.setCapability(RenderingAttributes.ALLOW_ALPHA_TEST_FUNCTION_WRITE); renderAttr.setCapability(RenderingAttributes.ALLOW_ALPHA_TEST_VALUE_WRITE); appearance.setRenderingAttributes(renderAttr); appearance.setCapability(Appearance.ALLOW_RENDERING_ATTRIBUTES_WRITE); // set up the editor renderAttrEditor = new RenderingAttributesEditor(renderAttr); // TransparencyAttributes transpAttr = new TransparencyAttributes(transpMode, transpValue); transpAttr.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE); transpAttr.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE); transpAttr.setCapability(TransparencyAttributes.ALLOW_BLEND_FUNCTION_WRITE); appearance.setTransparencyAttributes(transpAttr); // set up the editor transpAttrEditor = new TransparencyAttributesEditor(transpAttr); // Material material = new Material(red, black, red, white, 20.f); material.setLightingEnable(false); material.setCapability(Material.ALLOW_COMPONENT_WRITE); appearance.setMaterial(material); // material presets String[] materialNames = { "Red", "White", "Red Ambient", "Red Diffuse", "Grey Emissive", "White Specular", "Aluminium", "Blue Plastic", "Copper", "Gold", "Red Alloy", "Black Onyx" }; Material[] materialPresets = new Material[materialNames.length]; materialPresets[0] = new Material(red, black, red, white, 20.0f); materialPresets[1] = new Material(white, black, white, white, 20.0f); materialPresets[2] = new Material(red, black, black, black, 20.0f); materialPresets[3] = new Material(black, black, red, black, 20.0f); materialPresets[4] = new Material(black, grey, black, black, 20.0f); materialPresets[5] = new Material(black, black, black, white, 20.0f); Color3f alum = new Color3f(0.37f, 0.37f, 0.37f); Color3f alumSpec = new Color3f(0.89f, 0.89f, 0.89f); materialPresets[6] = new Material(alum, black, alum, alumSpec, 17); Color3f bluePlastic = new Color3f(0.20f, 0.20f, 0.70f); Color3f bluePlasticSpec = new Color3f(0.85f, 0.85f, 0.85f); materialPresets[7] = new Material(bluePlastic, black, bluePlastic, bluePlasticSpec, 22); Color3f copper = new Color3f(0.30f, 0.10f, 0.00f); ; Color3f copperSpec = new Color3f(0.75f, 0.30f, 0.00f); materialPresets[8] = new Material(copper, black, copper, copperSpec, 10); Color3f gold = new Color3f(0.49f, 0.34f, 0.00f); Color3f goldSpec = new Color3f(0.89f, 0.79f, 0.00f); materialPresets[9] = new Material(gold, black, gold, goldSpec, 15); Color3f redAlloy = new Color3f(0.34f, 0.00f, 0.34f); Color3f redAlloySpec = new Color3f(0.84f, 0.00f, 0.00f); materialPresets[10] = new Material(redAlloy, black, redAlloy, redAlloySpec, 15); Color3f blackOnyxSpec = new Color3f(0.72f, 0.72f, 0.72f); materialPresets[11] = new Material(black, black, black, blackOnyxSpec, 23); // set up the editor materialEditor = new MaterialPresetEditor(material, materialNames, materialPresets); // Texture2D // set the values to the defaults texEnable = false; texMipMapMode = Texture.BASE_LEVEL; texBoundaryModeS = Texture.WRAP; texBoundaryModeT = Texture.WRAP; texMinFilter = Texture.BASE_LEVEL_POINT; texMagFilter = Texture.BASE_LEVEL_POINT; texBoundaryColor = new Color4f(0.0f, 0.0f, 0.0f, 0.0f); // set up the image choices String[] texImageNames = { "Earth", "Fish", }; String[] texImageFileNames = { "earth.jpg", "fish1.gif", }; int texImageFileIndex = 0; // set up the appearance to allow the texture to be changed appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE); // set up the editor (this will create the initial Texture2D and // assign it to the appearance) texture2DEditor = new Texture2DEditor(appearance, codeBaseString, texImageNames, texImageFileNames, texImageFileIndex, texEnable, texBoundaryModeS, texBoundaryModeT, texMinFilter, texMagFilter, texMipMapMode, texBoundaryColor); // TextureAttributes texMode = TextureAttributes.REPLACE; texBlendColor = new Color4f(1.0f, 1.0f, 1.0f, 1.0f); texTransform = new Transform3D(); texPerspCorrect = TextureAttributes.NICEST; textureAttr = new TextureAttributes(texMode, texTransform, texBlendColor, texPerspCorrect); // set the capabilities to allow run time changes textureAttr.setCapability(TextureAttributes.ALLOW_MODE_WRITE); textureAttr.setCapability(TextureAttributes.ALLOW_BLEND_COLOR_WRITE); textureAttr.setCapability(TextureAttributes.ALLOW_TRANSFORM_WRITE); // connect it to the appearance appearance.setTextureAttributes(textureAttr); // setup the editor textureAttrEditor = new TextureAttributesEditor(textureAttr); // set up the tex coordinate generation texGenEnable = false; texGenMode = TexCoordGeneration.OBJECT_LINEAR; texGenPlaneS = new Vector4f(1.0f, 0.0f, 0.0f, 0.0f); texGenPlaneT = new Vector4f(0.0f, 1.0f, 0.0f, 0.0f); // set the appearance so that we can replace the tex gen when live appearance.setCapability(Appearance.ALLOW_TEXGEN_WRITE); // setup the editor texGenEditor = new TexCoordGenerationEditor(appearance, texGenEnable, texGenMode, texGenPlaneS, texGenPlaneT); }
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);/*ww w . ja va2s . 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:ExTexture.java
private Texture2D loadTexture(String filename) { // Load the texture image file if (debug)//w ww . j av a2 s. c o m System.err.println("Loading texture '" + filename + "'"); TextureLoader texLoader = new TextureLoader(filename, this); // If the image is NULL, something went wrong ImageComponent2D ic = texLoader.getImage(); if (ic == null) { System.err.println("Cannot load texture '" + filename + "'"); return null; } // Configure a Texture2D with the image Texture2D t = (Texture2D) texLoader.getTexture(); int mode = ((Integer) boundaries[currentBoundary].value).intValue(); t.setBoundaryModeS(mode); t.setBoundaryModeT(mode); Color3f color = (Color3f) colors[currentColor].value; t.setBoundaryColor(color.x, color.y, color.z, 0.0f); int filter = ((Integer) filters[currentFilter].value).intValue(); t.setMagFilter(filter); t.setMinFilter(filter); t.setMipMapMode(Texture.BASE_LEVEL); // Turn it on and allow future changes t.setEnable(true); t.setCapability(Texture.ALLOW_ENABLE_WRITE); return t; }
From source file:AppearanceTest.java
public void onBASE_LEVEL() { getTexture().setMipMapMode(Texture.BASE_LEVEL); assignToAppearance(); }
From source file:AppearanceExplorer.java
public Texture2DEditor(Appearance app, String codeBaseString, String[] texImageNames, String[] texImageFileNames, int texImageIndex, boolean texEnable, int texBoundaryModeS, int texBoundaryModeT, int texMinFilter, int texMagFilter, int texMipMapMode, Color4f texBoundaryColor) { super(BoxLayout.Y_AXIS); this.appearance = app; // TODO: make deep copies? this.imageNames = texImageNames; this.imageFileNames = texImageFileNames; this.imageIndex = texImageIndex; this.imageFile = texImageFileNames[texImageIndex]; this.codeBaseString = codeBaseString; this.enable = texEnable; this.mipMapMode = texMipMapMode; this.boundaryModeS = texBoundaryModeS; this.boundaryModeT = texBoundaryModeT; this.minFilter = texMinFilter; this.magFilter = texMagFilter; this.boundaryColor.set(texBoundaryColor); // set up the initial texture setTexture();/*ww w .j a v a 2 s . com*/ JCheckBox texEnableCheckBox = new JCheckBox("Enable Texture"); texEnableCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { enable = ((JCheckBox) e.getSource()).isSelected(); // workaround for bug // should just be able to // texture.setEnable(texEnable); // instead we have to: setTexture(); } }); // add the checkbox to the panel add(new LeftAlignComponent(texEnableCheckBox)); IntChooser imgChooser = new IntChooser("Image:", imageNames); imgChooser.setValue(imageIndex); imgChooser.addIntListener(new IntListener() { public void intChanged(IntEvent event) { imageIndex = event.getValue(); imageFile = imageFileNames[imageIndex]; setTexture(); } }); add(imgChooser); // texture boundaries String[] boundaryNames = { "WRAP", "CLAMP", }; int[] boundaryValues = { Texture.WRAP, Texture.CLAMP, }; // texture boundary S IntChooser bndSChooser = new IntChooser("Boundary S Mode:", boundaryNames, boundaryValues); bndSChooser.setValue(texBoundaryModeS); bndSChooser.addIntListener(new IntListener() { public void intChanged(IntEvent event) { int value = event.getValue(); boundaryModeS = value; setTexture(); } }); add(bndSChooser); // texture boundary T IntChooser bndTChooser = new IntChooser("Boundary T Mode:", boundaryNames, boundaryValues); bndTChooser.setValue(texBoundaryModeT); bndTChooser.addIntListener(new IntListener() { public void intChanged(IntEvent event) { int value = event.getValue(); boundaryModeT = value; setTexture(); } }); add(bndTChooser); // texture min filter String[] minFiltNames = { "FASTEST", "NICEST", "BASE_LEVEL_POINT", "BASE_LEVEL_LINEAR", "MULTI_LEVEL_POINT", "MULTI_LEVEL_LINEAR", }; int[] minFiltValues = { Texture.FASTEST, Texture.NICEST, Texture.BASE_LEVEL_POINT, Texture.BASE_LEVEL_LINEAR, Texture.MULTI_LEVEL_POINT, Texture.MULTI_LEVEL_LINEAR, }; // min filter IntChooser minFiltChooser = new IntChooser("Min Filter:", minFiltNames, minFiltValues); minFiltChooser.setValue(minFilter); minFiltChooser.addIntListener(new IntListener() { public void intChanged(IntEvent event) { int value = event.getValue(); minFilter = value; setTexture(); } }); add(minFiltChooser); // texture mag filter String[] magFiltNames = { "FASTEST", "NICEST", "BASE_LEVEL_POINT", "BASE_LEVEL_LINEAR", }; int[] magFiltValues = { Texture.FASTEST, Texture.NICEST, Texture.BASE_LEVEL_POINT, Texture.BASE_LEVEL_LINEAR, }; // mag filter IntChooser magFiltChooser = new IntChooser("Mag Filter:", magFiltNames, magFiltValues); magFiltChooser.setValue(magFilter); magFiltChooser.addIntListener(new IntListener() { public void intChanged(IntEvent event) { int value = event.getValue(); magFilter = value; setTexture(); } }); add(magFiltChooser); // texture mipmap mode String[] mipMapNames = { "BASE_LEVEL", "MULTI_LEVEL_MIPMAP", }; int[] mipMapValues = { Texture.BASE_LEVEL, Texture.MULTI_LEVEL_MIPMAP, }; // mipMap mode IntChooser mipMapChooser = new IntChooser("MipMap Mode:", mipMapNames, mipMapValues); mipMapChooser.setValue(mipMapMode); mipMapChooser.addIntListener(new IntListener() { public void intChanged(IntEvent event) { int value = event.getValue(); mipMapMode = value; setTexture(); } }); add(mipMapChooser); Color4fEditor boundaryColorEditor = new Color4fEditor("Boundary Color", boundaryColor); boundaryColorEditor.addColor4fListener(new Color4fListener() { public void colorChanged(Color4fEvent event) { event.getValue(boundaryColor); setTexture(); } }); add(boundaryColorEditor); }
From source file:AppearanceExplorer.java
void setTexture() { // set up the image using the TextureLoader java.net.URL imageURL = null; try {//from w w w .j a v a 2s . c o m imageURL = new java.net.URL(codeBaseString + imageFile); } catch (Exception e) { System.err.println("Exception: " + e); System.exit(1); } int flags; if (mipMapMode == Texture.BASE_LEVEL) { flags = 0; } else { flags = TextureLoader.GENERATE_MIPMAP; } texLoader = new TextureLoader(imageURL, new String("RGBA"), flags, this); // We could create texture from image // // Get the image from the loader. We need an image which // has power of two dimensions, so we'll get the unscaled image, // figure out what the scaled size should be and then get a scale // image //ImageComponent2D unscaledImage = texLoader.getImage(); //int width = unscaledImage.getWidth(); //int height = unscaledImage.getWidth(); // // scaled values are next power of two greater than or equal to // value //texWidth = powerOfTwo(width); //texHeight = powerOfTwo(height); // // rescale the image if necessary //ImageComponent2D texImage; //if ((texWidth == width) && (texHeight == height)) { // texImage = unscaledImage; //} else { // texImage = texLoader.getScaledImage(texWidth, texHeight); //} //texFormat = Texture.RGB; //texture = new Texture2D(texMipMapMode, texFormat, texWidth, // texHeight); //texture.setImage(0, texImage); // instead we'll just get get the texture from loader texture = (Texture2D) texLoader.getTexture(); texture.setBoundaryColor(boundaryColor); texture.setBoundaryModeS(boundaryModeS); texture.setBoundaryModeT(boundaryModeT); texture.setEnable(enable); texture.setMinFilter(minFilter); texture.setMagFilter(magFilter); // Set the capabilities to enable the changable attrs texture.setCapability(Texture.ALLOW_ENABLE_WRITE); texture.setCapability(Texture.ALLOW_IMAGE_WRITE); // connect the new texture to the appearance appearance.setTexture(texture); }