List of usage examples for javax.media.j3d Texture RGB
int RGB
To view the source code for javax.media.j3d Texture RGB.
Click Source Link
From source file:MultiTextureTest.java
public Texture createLightMap() { int width = 128; int height = 128; BufferedImage bimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); int[] rgbArray = new int[width * height]; int index, index2; int rgbInc = 256 / (width / 2 - 20); int rgbValue = 0; int k = width / 2 - 5; int i, j, rgb; rgb = 0xff;/* w w w.j av a2s . c o m*/ rgbValue = rgb | (rgb << 8) | (rgb << 16) | (rgb << 24); for (i = width / 2 - 1, j = 0; j < 10; j++, i--) { rgbArray[i] = rgbValue; } for (; i > 8; i--, rgb -= rgbInc) { rgbValue = rgb | (rgb << 8) | (rgb << 16) | (rgb << 24); rgbArray[i] = rgbValue; } for (; i >= 0; i--) { rgbArray[i] = rgbValue; } for (i = 0; i < width / 2; i++) { rgbValue = rgbArray[i]; index = i; index2 = (width - i - 1); for (j = 0; j < height; j++) { rgbArray[index] = rgbArray[index2] = rgbValue; index += width; index2 += width; } } bimage.setRGB(0, 0, width, height, rgbArray, 0, width); ImageComponent2D grayImage = new ImageComponent2D(ImageComponent.FORMAT_RGB, bimage); lightTex = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, width, height); lightTex.setImage(0, grayImage); return lightTex; }
From source file:SimpleTexture.java
/** * This defines the appearance with a texture. The texture is loaded from an * external file.// w ww . j ava 2 s.c om * * @return Appearance that uses the texture. */ protected Appearance DefineAppearance() { //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); //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: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. * /*from w ww.ja va 2 s. com*/ * @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:TextureTest.java
protected Shape3D createTextureGeometry(String szFile, boolean bWireframe) { // load all the texture data from the file and create the geometry // coordinates TextureGeometryInfo texInfo = createTextureCoordinates(szFile); if (texInfo == null) { System.err.println("Could not load texture info for file:" + szFile); return null; }// w w w. j a va 2 s . com // print some stats on the loaded file System.out.println("Loaded File: " + szFile); System.out.println(" Texture image: " + texInfo.m_szImage); System.out.println(" Texture coordinates: " + texInfo.m_TexCoordArray.length); // create an Appearance and assign a Material Appearance app = new Appearance(); PolygonAttributes polyAttribs = null; // create the PolygonAttributes and attach to the Appearance, // note that we use CULL_NONE so that the "rear" side of the geometry // is visible with the applied texture image if (bWireframe == false) polyAttribs = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0); else polyAttribs = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0); app.setPolygonAttributes(polyAttribs); // load the texture image and assign to the appearance TextureLoader texLoader = new TextureLoader(texInfo.m_szImage, Texture.RGB, this); Texture tex = texLoader.getTexture(); app.setTexture(tex); // create a GeometryInfo for the QuadArray that was populated. GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY); gi.setCoordinates(texInfo.m_CoordArray); gi.setTextureCoordinates(texInfo.m_TexCoordArray); // use the triangulator utility to triangulate the polygon int[] stripCountArray = { texInfo.m_CoordArray.length }; int[] countourCountArray = { stripCountArray.length }; gi.setContourCounts(countourCountArray); gi.setStripCounts(stripCountArray); Triangulator triangulator = new Triangulator(); triangulator.triangulate(gi); // generate normal vectors for the triangles, not // strictly necessary as we are not lighting the scene // but generally useful NormalGenerator normalGenerator = new NormalGenerator(); normalGenerator.generateNormals(gi); // wrap the GeometryArray in a Shape3D and assign appearance return new Shape3D(gi.getGeometryArray(), app); }
From source file:TexCoordTest.java
void createAppearance(double yMaxHeight) { // create an Appearance and assign a Material m_Appearance = new Appearance(); m_Appearance.setCapability(Appearance.ALLOW_TEXGEN_WRITE); Color3f black = new Color3f(0, 0.2f, 0); Color3f objColor = new Color3f(0.1f, 0.7f, 0.2f); m_Appearance.setMaterial(new Material(objColor, black, objColor, black, 0.8f)); // load the texture image TextureLoader texLoader = new TextureLoader("stripes.gif", Texture.RGB, this); // clamp the coordinates in the S dimension, that way they // will not wrap when the calculated texture coordinate falls outside // the range 0 to 1. When the texture coordinate is outside this range // no texture coordinate will be used Texture tex = texLoader.getTexture(); tex.setBoundaryModeS(Texture.CLAMP); // assign the texute image to the appearance m_Appearance.setTexture(tex);/*from w w w . j av a2s . c o m*/ // create the TexCoordGeneration object. // we are only using 1D texture coordinates (S) - texture coordinates // are calculated from a vertex's distance from the Y = 0 plane // the 4th parameter to the Vector4f is the distance in *texture // coordinates* // that we shift the texture coordinates by (i.e. Y = 0 corresponds to S // = 0.5) TexCoordGeneration texGen = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR, TexCoordGeneration.TEXTURE_COORDINATE_2, new Vector4f(0, (float) (1.0 / (2 * yMaxHeight)), 0, 0.5f), new Vector4f(0, 0, 0, 0), new Vector4f(0, 0, 0, 0)); // create our "non-live" TexCoordGeneration object so we // can update the "genMode" parameter after we go live. m_TexGen = (TexCoordGeneration) texGen.cloneNodeComponent(true); // assign the TexCoordGeneration to the Appearance m_Appearance.setTexCoordGeneration(texGen); // we just glue the texture image to the surface, we are not // blending or modulating the texture image based on material // attributes. You can experiment with MODULATE or BLEND. TextureAttributes texAttribs = new TextureAttributes(); texAttribs.setTextureMode(TextureAttributes.DECAL); m_Appearance.setTextureAttributes(texAttribs); }
From source file:J3dSwingFrame.java
/** * Set the texture on our goemetry/* www .j av a 2 s. c om*/ * <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(); }