Java Programing

February 4, 2007

Figure 14.23 Material colors set as in figure

Filed under: Java 3D Programming — webmaster @ 1:39 am

Figure 14.23 Material colors set as in figure 14.14 and texture image applied using REPLACE mode Refer to the Java 3D API Specification for more details on the texture mapping equations. 14.4.3 Transform A rotational transformation can also be applied to the texture image prior to texture mapping. This is a fairly unusual operation but might prove useful for specialized operations or to implement special effects. The TextureTransformTestexample creates a texture mapped Boxand allows the user to interactively rotate the texture applied to the Boxusing the mouse (figure 14.24). Figure 14.24 Applying a Transform to an applied texture image. TextureTransformTest allows a texture image to be interactively rotated using a MouseRotate behavior. The ColorCube at the lower left of the two frames shows the current rotation Note that only the rotational components of the Transform3Dappear to be used. From TextureTransformTest.java 254

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services

Figure 14.23 Material colors set as in figure

Filed under: Java 3D Programming — webmaster @ 1:39 am

//create a Box with an applied Texture image //and a RotationInterpolator to rotate the box protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); //create the rotation interpolator to rotate the scene RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI*2.0f); rotator.setSchedulingBounds( createApplicationBounds() ); objTrans.addChild(rotator); //create the box final int nScale = 50; Appearance app = new Appearance(); Box box = new Box( nScale, nScale, nScale, Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS, app ); //load the texture image TextureLoader texLoader = new TextureLoader( “texture.gif”, this ); app.setTexture( texLoader.getTexture() ); //set the texture attributes and ensure we can write //to the Transform for the texture attributes m_TextureAttributes = new TextureAttributes(); m_TextureAttributes.setCapability( TextureAttributes.ALLOW_TRANSFORM_WRITE ); app.setTextureAttributes( m_TextureAttributes ); //connect all the elements objTrans.addChild( box ); objRoot.addChild( objTrans ); objRoot.addChild( createRotator() ); return objRoot; } //private TransformGroup createRotator() { //create a ColorCube to illustrate the current rotation TransformGroup transTg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation( new Vector3d( -70, -70, 50 ) ); transTg.setTransform( t3d ); TransformGroup subTg = new TransformGroup(); subTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); subTg.addChild( new ColorCube(10.0) ); //attach a MouseRotate behavior so we can rotate 255

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services

February 3, 2007

texture alpha. The texture is applied to the

Filed under: Java 3D Programming — webmaster @ 7:12 pm

texture alpha. The texture is applied to the surface in proportion to the alpha components of both the texture and the surface. The texture must either be in RGB or RGBA format. MODULATE Color value is the product of the color values of the texture and the surface color. If MODULATE is used with dark textures the surface may end up black. BLEND The color values on the surface are modulated by the color values of the texture and biased by the blend color. REPLACE Color value is simply the texture color. Figure 14.19 Material colors set and no texture image applied Figure 14.20 Material colors set as in figure 14.14 and texture image applied using DECAL mode 252

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

texture alpha. The texture is applied to the

Filed under: Java 3D Programming — webmaster @ 7:12 pm

Figure 14.21 Material colors set as in figure 14.14 and texture image applied using MODULATE mode Figure 14.22 Material colors set as in figure 14.14 and texture image applied using BLEND mode 253

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

February 2, 2007

MinFilter Option Effect FASTEST Equivalent to BASE_LEVEL_POINT NICEST

Filed under: Java 3D Programming — webmaster @ 4:40 am

MinFilter Option Effect FASTEST Equivalent to BASE_LEVEL_POINT NICEST Equivalent to MULTI_LEVEL_LINEAR BASE_LEVEL_POINT Finds nearest texel in the level 0 texture map BASE_LEVEL_LINEAR Performs bilinear interpolation on the four nearest texels in the level 0 texture map MULTI_LEVEL_POINT Selects the nearest texel in the nearest MIPMAP MULTI_LEVEL_LINEAR Performs trilinear interpolation of texels between four texels each from the two nearest MIPMAP levels FASTEST Equivalent to BASE_LEVEL_POINT NICEST Equivalent to BASE_LEVEL_LINEAR BASE_LEVEL_POINT Selects the nearest texel in the level 0 texture map BASE_LEVEL_LINEAR Performs a bilinear interpolation on the four nearest texels in the level 0 texture map Figure 14.14 illustrates how complex blending of the MIPMAP texture images can be achieved. In frame 1 the left-hand face of the cube is dominated by the level 0 texture image, which progressively passes through the 1, 2, and 3 texture images as the size of the surface is reduced through rotation (frames 2 through 4). The blending of multiple texture images obviously requires more work on the part of the graphics API. 248

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

MinFilter Option Effect FASTEST Equivalent to BASE_LEVEL_POINT NICEST

Filed under: Java 3D Programming — webmaster @ 4:40 am

Figure 14.14 Four frames from the AppearanceTest example illustrate how multiple texture images are blended when the MULTI_LEVEL_LINEAR MinFilter and BASE_LEVEL_LINEAR MagFilter are used In contrast, when the MULTI_LEVEL_POINTmode is used, the texture images are not blended but rather different texture images are chosen for different pixels within the surface, based on the position of the pixel within the surface (figure 14.15). This is the fastest way for the graphics API to support multiple levels of detail texture images. 249

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

February 1, 2007

Creating the appropriate Textureobject, either Texture2Dor Texture3D

Filed under: Java 3D Programming — webmaster @ 8:40 pm

(Adobe) or PaintShop Pro (JASC). In figure 14.13, the AppearanceTestexample uses texture images that are different so that the texture image that was chosen by the graphics API is apparent. Figure 14.13 The seven texture images used in the AppearanceTest example to illustrate Java 3D MIPMAP support 64 x 64 pixels down to 1 x 1 pixels The individual texture images can be assigned to a Textureobject as follows. Note that Texture.MULTI_LEVEL_MIPMAPwas used to activate MIPMAP support. From AppearanceTest.java //Create a texture loader and load the largest image (64×64-pixels) TextureLoader texLoader = new TextureLoader( “texture00.jpg”, m_Component ); //Retrieve the ImageComponent from the TextureLoader ImageComponent2D image = texLoader.getImage(); //Create a MULTI_LEVEL_MIPMAP mode Texture2D object //based on the size of the largest image Texture2D tex2D = new Texture2D( Texture.MULTI_LEVEL_MIPMAP, Texture.RGBA, image.getWidth(), image.getHeight() ); //Now load each of the 7 images and assign to the Texture2D for( int n = 0; n <= 6; n++ ) { texLoader = new TextureLoader( "texture0" + n + ".jpg", m_Component ); tex2D.setImage( n, texLoader.getImage() ); } //assign the Texture2D to the appearance m_Appearance.setTexture( m_Texture ); Once the graphics API has multiple texture images to choose from, it needs some criteria to decide which texture image to display. The graphics API obviously uses the texture image that is easiest to resample to the desired size; however, some more advanced options are also available. These are controlled by the setMinFilterand setMagFiltermethods (table 14.3). Table 14.3 MinFilter and MagFilter 247

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

Creating the appropriate Textureobject, either Texture2Dor Texture3D

Filed under: Java 3D Programming — webmaster @ 8:40 pm

Creating the appropriate Textureobject, either Texture2Dor Texture3D If an ImageComponent2Dor ImageComponent3Dis passed to Texture.setImagedirectly and the TextureLoaderclass is not used, the application developer is responsible for ensuring that the images are a power of 2 (1, 2, 4, 8 ) in both width and height. This is a requirement imposed by the underlying graphics API that is optimized to rescale images of this size. 14.3.4 MIPMAP mode, filter, and multiple texture images One of the common problems of texture mapping is that the texture images become pixilated as resampling enlarges them. The quick fix to this is to ensure that all your texture images are large enough so that they can never become overly magnified. Imagine a cube in your scene with a texture image applied to one face. If the cube s texture image is 64 x 64 pixels and the cube is very close to the viewer, it may end up taking up 300 x 300 pixels on the screen. A texture image that has been magnified by a factor of 5 is obviously not going to look very good regardless of the sophistication of the sampling algorithm employed by the graphics hardware. A solution to this problem would be to assign a 256 x 256 pixel texture image to each face of the cube. However, we are now using 16 times as much texture memory. To complicate matters, most of the time the cube is probably considerably further away from the viewer, and the graphics API will have to work hard to sample the 256 x 256 size image down to an appropriate size based on the cube s distance. What we need, and what MIPMAPs provide, is the ability to specify multiple texture images. The graphics API will select the most appropriate one based on the size of the surface it is trying to render. We pay the penalty of storing multiple texture images which is incidentally very small compared to storing the largest texture image. For example, 64 x 64 = 4096 32 x 32 = 1024 16 x 16 = 256 8 x 8 = 64 4 x 4 = 16 2 x 2 = 4 1 x 1 = 1 The cost of storing the 64 x 64 pixel image is proportional to 4096, while the cost of storing all the other images is proportional to 1365. So using MIPMAPs will improve performance for a very low memory penalty. To use MIPMAPs you must specify all the texture images from your maximum size (which must be a power of 2, right down to the 1 x 1 image). So, if our largest texture image is 64 x 64 pixels, we require seven texture images. Usually, of course, the texture images will be increasingly low resolution images of the same feature. Texture images can be easily preprocessed using the resampling features of a bitmap editor such as PhotoShop 246

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

assigned texture coordinates. I suggest you experiment with

Filed under: Java 3D Programming — webmaster @ 12:24 pm

assigned texture coordinates. I suggest you experiment with the TexCoordTestexample, edit the texture images, and change the mapping planes until you are comfortable with the techniques and have an intuitive feel for the mathematics behind the texture coordinate generation options. 14.2 3D texture coordinates The previous section included some hand waving on the subject of 3D texture coordinates. The 3D texture coordinates are fairly unusual and are at present supported by Java 3D only on the Solaris platform. Instead of a 2D texture image being applied to a surface, a 3D object can appear to have been carved from a 3D texture. Some textures are inherently 3D and are easiest to specify procedurally (such as the grain in wood). Using a 3D texture image defines a color (potentially with an alpha value) for each x,y,z location. Texels, instead of being 2D squares, are now 3D cubes within the three dimensions of the texture image (s,t,r). For example, if a 2D wood grain texture were applied to the faces of a cube, the grain lines would not match up at the edges of the faces of the cube. By using a 3D texture image, the grain lines will appear to run through the cube in a realistic manner. Similarly, in a 3D visualization application, such as MRI scanning, a 3D texture image might be used to represent the color of each voxel within a volume rendering. This might be used as a cheat to create a relatively coarse voxel resolution and apply a high-resolution 3D texture image to trade off accuracy against interactive performance. 14.3 Texture and multiple levels of detail java.lang.Object | +–javax.media.j3d.SceneGraphObject | +–javax.media.j3d.NodeComponent | +–javax.media.j3d.Texture Capability Bits (OpenGL Reference: glTexImage2D, glTexParameter): BOUNDARY_COLOR ENABLE FILTER IMAGE MIPMAP_MODE Textureis an abstract class and hence cannot be instantiated. The two derived classes Texture2Dor Texture3D(used with 2D or 3D texture coordinates respectively) should be instantiated instead. Texture-derived objects are usually not created directly but are returned by the getTexturemethod of the TextureLoaderutility class. See section 14.3.3 for more details. 14.3.1 Boundary color 244

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services

assigned texture coordinates. I suggest you experiment with

Filed under: Java 3D Programming — webmaster @ 12:24 pm

Figure 14.12 Boundary color set to black. The boundary was only visible when the boundary mode for s and t was set to CLAMP and the MinFilter was set to NICEST 14.3.2 Boundary mode Setting the boundary mode to Texture.WRAPallows texture coordinates greater than 1 to be used. The texture image will be repeated (tiled) along each axis (s, t, or r) that has the WRAPboundary mode. If CLAMP is used, texture coordinates outside the 0 to 1 range will be ignored. See figure 14.12 for an example of how CLAMPand MinFiltercan be used. Note that the texture image can be flipped in each axis by using the WRAPattribute and a texture coordinate of 1. 14.3.3 Setting the image Setting the image within the Textureobject is achieved using the setImagemethod. The TextureLoaderutility class is usually used to create the Texturewith an image applied: From TextureTest.java //Create TextureLoader and initialize it with an image file name //and a mode TextureLoader texLoader = new TextureLoader( texInfo.m_szImage, Texture.RGB, this ); //Extract a Texture object from the loader Texture tex = texLoader.getTexture(); //Assign the Texture to the Appearance Appearance app = new Appearance(); app.setTexture( tex ); The advantages of using the TextureLoader class are: Loading the image from disk (JPEG or GIF) Rescaling the image so that it is a power of 2, that is, width and height. 245

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services

« Previous PageNext Page »

Powered by Java Web Hosting