Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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 555 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!
Play the free demo of Revenge of the Titans!
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.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (78 views)
2013-05-17 21:29:12

alaslipknot (89 views)
2013-05-16 21:24:48

gouessej (122 views)
2013-05-16 00:53:38

gouessej (114 views)
2013-05-16 00:17:58

theagentd (126 views)
2013-05-15 15:01:13

theagentd (113 views)
2013-05-15 15:00:54

StreetDoggy (158 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (180 views)
2013-05-12 15:36:09

UnluckyDevil (186 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.112 seconds with 21 queries.