Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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 754 times)
0 Members and 1 Guest are viewing this topic.
Offline Markus_me

Junior Newbie




Java games rock!


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

Hi

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 Member





« Reply #1 - Posted 2005-02-02 21: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.

Mike  

Special Effects for Java 3D games: http://www.indietechnologies.com
Offline Markus_me

Junior Newbie




Java games rock!


« Reply #2 - Posted 2005-02-03 14: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();
         boundBox.getLower(lower);
         boundBox.getUpper(upper);
   
              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();
             ra.setDepthBufferEnable(true);
         ra.setIgnoreVertexColors(true);
   
         PolygonAttributes pa = new PolygonAttributes();
             pa.setCullFace(PolygonAttributes.CULL_NONE);
         pa.setPolygonMode(pa.POLYGON_FILL);
         
         

   
         TextureLoader texLoader = new TextureLoader( image,null );
                 texture = (Texture2D) texLoader.getTexture();
                 texture.setEnable(true);
   
          TextureAttributes ta = new TextureAttributes();
     ta.setTextureMode(ta.MODULATE);
     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();
     material.setLightingEnable(true);

     material.setEmissiveColor(5,5,5);
           
     Appearance a = new Appearance();
             a.setRenderingAttributes(ra);
             a.setPolygonAttributes(pa);
     a.setTexture(texture);
     a.setTextureAttributes(ta);
     a.setMaterial(material);
     a.setTexCoordGeneration(texCoord);
             
     // set up
     shape.setAppearance(a);

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

Junior Member





« Reply #3 - Posted 2005-02-04 13: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.

Mike

Special Effects for Java 3D games: http://www.indietechnologies.com
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.

Riven (18 views)
2014-07-29 18:09:19

Riven (13 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (31 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (41 views)
2014-07-23 21:16:32

Riven (28 views)
2014-07-23 21:07:15

Riven (29 views)
2014-07-23 20:56:16

ctomni231 (60 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!