Hey guys
I need your help
I am a begginer in Java3D and i read quite a lot Tutorials and tried some stuff to make.
Now i made a terrain out of a coordinates, which are in a DB. All works fine but i just cant get the texture over the whole terrain.
The texture is a real map.
This is my code snippet in which i set the geometry and the texture
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| for (int i = 0; i < grid.length - 1; i++) { for (int j = 0; j < grid[0].length - 1; j++) { pts[counter] = grid[i][j]; counter++;
pts[counter] = grid[i][j + 1]; counter++;
pts[counter] = grid[i + 1][j + 1]; counter++;
pts[counter] = grid[i + 1][j]; counter++; } }
GeometryInfo gi = new GeometryInfo(GeometryInfo.QUAD_ARRAY); gi.setCoordinates(pts);
Stripifier sp = new Stripifier(); sp.stripify(gi);
NormalGenerator ng = new NormalGenerator(); ng.setCreaseAngle((float) Math.toRadians(30)); ng.generateNormals(gi);
Appearance aper = new Appearance(); Material Mser = new Material(); Mser.setShininess(0.01f); Mser.setEmissiveColor(0.0f, 0.0f, 0.0f); Mser.setAmbientColor(0.1f, 0.1f, 0.1f); aper.setMaterial(Mser);
Vector4f planeS = new Vector4f((float)1.0/1800,0.0f, 0.0f, 0.0f); Vector4f planeT = new Vector4f(0.0f, 0.0f, (float)1.0/1800, 0.0f); TexCoordGeneration tcg = new TexCoordGeneration( TexCoordGeneration.OBJECT_LINEAR, TexCoordGeneration.TEXTURE_COORDINATE_2, planeS, planeT); aper.setTexCoordGeneration(tcg); TextureLoader texLoad = new TextureLoader("125.tif", null); ImageComponent2D textImage = texLoad.getImage();
Texture2D texture = new Texture2D(Texture2D.BASE_LEVEL, Texture.RGB, textImage.getWidth(), textImage.getHeight()); texture.setImage(0, textImage);
texture.setMinFilter(Texture.NICEST); texture.setMagFilter(Texture.NICEST); texture.setEnable(true);
TextureAttributes texatt = new TextureAttributes( TextureAttributes.DECAL, new Transform3D(), new Color4f(1.0f, 1.0f, 1.0f, 1.0f), TextureAttributes.NICEST);
aper.setTextureAttributes(texatt); aper.setTexture(texture);
this.setGeometry(gi.getGeometryArray()); this.setAppearance(aper); |
before I used the TexCoordGeneration I had this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| for (int v = 0; v < textsint; v++) { texts[v] = 0.0f; texts[++v] = 0.0f;
texts[++v] = 0.0f; texts[++v] = (float) STEP; texts[++v] = (float) STEP; texts[++v] = (float) STEP;
texts[++v] = (float) STEP; texts[++v] = 0.0f; }
gi.setTextureCoordinateParams(1, 2); gi.setTextureCoordinates(0, texts);
try { TextureLoader Texget = new TextureLoader(new java.net.URL(texture), null); Texture2D ourTex = (Texture2D) Texget.getTexture(); TextureAttributes texatt = new TextureAttributes( TextureAttributes.BLEND, new Transform3D(), new Color4f(1.0f, 1.0f, 1.0f, 1.0f), TextureAttributes.NICEST); aper.setTextureAttributes(texatt); aper.setTexture(ourTex); } catch (java.net.MalformedURLException e) { System.err.println("error loading textures"); e.printStackTrace(); } |
Now I got two questions
#1: How can I set the texturecoordinates, so one image covers the whole terrain?
#2: In TexCoordGeneration has planeS and T (and R, Q) and i searched in the internet for the meaning of the 4 parameters, which i can set... Vector4f planeS = new Vector4f(1.0f, 0.0f, 0.0f, 0.0f); Can someone tell me exactly for what does those 4 numbers stand?
-----EDIT:-----
k I found out what the first 3 parameters exactly do... x (length), y (height), z(width), w (wtf?)
-----------------
Here is a pic of my current situation:

The problem:

The texture is wrapped exactly 4 times on the terrain but it shouldnt be wrapped at all. And is think because of the wrap the texture flips, but I dont care about that now.
Can anyone please help me?