Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (780)
Games in Android Showcase (233)
games submitted by our members
Games in WIP (856)
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  
  Texture Nightmare  (Read 1582 times)
0 Members and 1 Guest are viewing this topic.
Offline Markus_me

Junior Newbie

Java games rock!

« Posted 2005-02-02 13:14:23 »


I am moderately new to Java3D and have like most other people delved into the world of terrain generation. My problem lies with texture mapping my generated terrain. I have been through the many tutorials on offer via Sun and Java world and can tile textures fairly ok, but what I want to do is drape a single texture over the whole terrain like a blanket which for some reason I can not do.

The size of the world I am trying to texture ranges from
-64 to 64 on the x and z axis and the y axis varies from 0 to 10. Therefore obviously I want the bottom left of the world to correlate with the bottom left of the loaded texture, the bottom right to the bottom right of the texture and so on. Is it possible to stretch a texture in this way and if so how? I would be most grateful if you could help as I have been trying to do this for a very long time and now beginning to get a little frustrated.
Offline Mike Jacobs

Junior Devvie

« Reply #1 - Posted 2005-02-02 20:25:43 »

In order to drape a single texture over your landscape you need a texture attributes on the appearance, a square terrain, and texture coordinates on the geometry.  

It sounds like the nature of the problem you are having has to do with texture coordinates.  Texture coordinates are u,v pairs that start at (0,0) at the lower left corner and go to (1,1) at the upper right corner of the texture/terrain.  Because your terrain varies between (x,z) = (-64,-64) to (+64, +64), the texture coordinates should be u = (x+64)/128, and v = (z+64/128 ).  Be sure the values are floats or doubles.

The confusing part can be how the texture coordinates relate to the vertices in the geometry.  For example, if your terrain is 2 by 2 squares using a QuadArray then there are 16 vertices that need to have texture coordinates.  Four vertices (at the center) all share the same texture coordinate values.  As the number of quads grow, so does the overlapped vertices.

If your texture is draped but looks upside down, consider using the yUp parameter on the ImageComponent2D.


Special Effects for Java 3D games:
Offline Markus_me

Junior Newbie

Java games rock!

« Reply #2 - Posted 2005-02-03 13:32:39 »

Thanks Mike!

I kinda think (?  Smiley ) I know what you're getting at, but I'm not sure how to work it in (been trying all morning) so I will post some code and if you can give me some pointers I would be most grateful.

BoundingBox boundBox = new BoundingBox(shape.getBounds());
         System.out.println("BOUNDING BOX = " + boundBox);
         Point3d lower = new Point3d();
         Point3d upper = new Point3d();
              float width = (float)(upper.x - lower.x);
         float height = (float)(upper.y - lower.y);
               float depth = (float)(upper.z - lower.z);
                 RenderingAttributes ra = new RenderingAttributes();
         PolygonAttributes pa = new PolygonAttributes();

         TextureLoader texLoader = new TextureLoader( image,null );
                 texture = (Texture2D) texLoader.getTexture();
          TextureAttributes ta = new TextureAttributes();
     Transform3D trans = new Transform3D( );
     trans.setScale( 1.0 );
     ta.setTextureTransform( trans );
     // Setup the automatic texture coordinate generation

     Vector4f planeS = new Vector4f( (float)(1.0/width), 0.0f, 0.0f, (float)(-lower.x/width));
     Vector4f planeT = new Vector4f( 0.0f, (float)(1.0/height), 0.0f, (float)(-lower.y/height));  
     TexCoordGeneration texCoord = new TexCoordGeneration(
        TexCoordGeneration.TEXTURE_COORDINATE_2, TexCoordGeneration.OBJECT_LINEAR, planeS, planeT);
                 Material material = new Material();

     Appearance a = new Appearance();
     // set up

I hope thats clear
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mike Jacobs

Junior Devvie

« Reply #3 - Posted 2005-02-04 12:02:41 »

My post had to do with generating your own texture coordinates rather than using the TexCoordGeneration class.  I have not used the TexCoordGeneration but I do have a few observations.  

Because the texture is a 2D texture, I believe you can use the default S and T plane coefficients.  Your sample code appears to be setting the Q coefficient which appears to be part of 4D textures, not 2D textures.

Color RGB values range from 0 to 1, but the emissive color is set to 5,5,5.

There is no need to set the texture transform and scale in the manner shown because those are defaulted for you.

Hope that helps.


Special Effects for Java 3D games:
Pages: [1]
  ignore  |  Print  

hadezbladez (728 views)
2018-11-16 13:46:03

hadezbladez (363 views)
2018-11-16 13:41:33

hadezbladez (715 views)
2018-11-16 13:35:35

hadezbladez (179 views)
2018-11-16 13:32:03

EgonOlsen (2375 views)
2018-06-10 19:43:48

EgonOlsen (2528 views)
2018-06-10 19:43:44

EgonOlsen (1466 views)
2018-06-10 19:43:20

DesertCoockie (2132 views)
2018-05-13 18:23:11

nelsongames (1928 views)
2018-04-24 18:15:36

nelsongames (2601 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 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‑
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!