Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVED]Terrain Texturing  (Read 2532 times)
0 Members and 1 Guest are viewing this topic.
Offline evilion

Junior Newbie





« Posted 2010-04-30 11:45:59 »

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  
//grid is filled with coordinates taken out of a DB
// pts are the points of geometry, taken out of a grid
       for (int i = 0; i < grid.length - 1; i++) {
          for (int j = 0; j < grid[0].length - 1; j++) {
            pts[counter] = grid[i][j]; //top left corner
            counter++;

            pts[counter] = grid[i][j + 1]; //top right corner
            counter++;

            pts[counter] = grid[i + 1][j + 1]; //bottom right corner
            counter++;

            pts[counter] = grid[i + 1][j]; //bottom left corner
            counter++;
       
         }
      }

//geometry stuff
      GeometryInfo gi = new GeometryInfo(GeometryInfo.QUAD_ARRAY);
      gi.setCoordinates(pts);

//making strips
      Stripifier sp = new Stripifier();
      sp.stripify(gi);

//making normals
      NormalGenerator ng = new NormalGenerator();
      ng.setCreaseAngle((float) Math.toRadians(30));
      ng.generateNormals(gi);

//setting appearance
      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);

//setting the texturecoordinates
      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);
     
//loading texture
      TextureLoader texLoad = new TextureLoader("125.tif", null);
      ImageComponent2D textImage = texLoad.getImage();

//setting texture
      Texture2D texture = new Texture2D(Texture2D.BASE_LEVEL, Texture.RGB,
                                        textImage.getWidth(),
                                        textImage.getHeight());
      texture.setImage(0, textImage);

//setting texture attributes
      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);

//adding texture to appearance
      aper.setTextureAttributes(texatt);
      aper.setTexture(texture);

//give geometry and appearance the scene graph
      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  
//set logical texture coordinates
//STEP = 2.0
for (int v = 0; v < textsint; v++) {
         //top left corner
         texts[v] = 0.0f;
         texts[++v] = 0.0f;

         //top right corner
         texts[++v] = 0.0f;
         //texts[++v] = widUnit;
         texts[++v] = (float) STEP;
 
         //bottom right corner
         //texts[++v] = lenUnit;
         texts[++v] = (float) STEP;
         //texts[++v] = widUnit;
         texts[++v] = (float) STEP;

         //bottom left corner
         //texts[++v] = lenUnit;
         texts[++v] = (float) STEP;  
         texts[++v] = 0.0f;
 
      }

//setting texturecoordinates
      gi.setTextureCoordinateParams(1, 2);
      gi.setTextureCoordinates(0, texts);

//setting texture and attributes
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?
Offline evilion

Junior Newbie





« Reply #1 - Posted 2010-05-04 09:26:25 »

Ok I found out how and why

here is my code for it

1  
the code was too big for the post... I attached it


the "heart" of the code are the classes, which i copied from "Pro Java 6 3D Game Development"
My biggest problem in my early code was, that the geometry wasnt created as it should, thats why i never could put one image over the whole map.
hf gl
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (40 views)
2014-12-09 22:41:13

BurntPizza (75 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (113 views)
2014-11-26 15:22:04

toopeicgaming1999 (100 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!