Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java 3D > Stretched terra...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 764 of 817
Post > Topic >>

Stretched terrain texture and glare

by Miss Elaine Eos <Misc@[EMAIL PROTECTED] > Jun 28, 2007 at 05:49 AM

I'm using an IndexedTriangleStripArray for my terrain mesh.  I give it a 
textured appearance, via the code, below.  The problem is that the 
texture isn't laid out in nice "tiled" pattern, like I might hope.  
Instead, it's rather badly warped & stretched, as shown here:

<http://www.manyfriends.com/Misc/j3d/>

In addition, when I face toward the light, there's a rather undesirable 
glare on my terrain.  I used NormalGenerator.generateNormals(), so I'm 
pretty sure those are right...

Can anyone offer some hints about what I can do to correct both of these?

Thanks!

   --- Code snippets ---

// Create the terrain.  A T3DTerrainMesh is just a simple 
IndexedTriangleStripArray.
 T3DTerrainSection terrain        = new T3DTerrainMesh(...);
 terrain.setAppearance (textureAppearance(getBufferedImage ("grass"), 
terrain.createAppearance ()));

/**
   Return an Appearance, defined to lay out a texture referenced by 
resName,
   across a SceneObject.
   @[EMAIL PROTECTED]
 textureImageBuf  The image containing the texture.
   @[EMAIL PROTECTED]
 start   An initial Appearance object to modify (or null.)
   @[EMAIL PROTECTED]
 tAttr   TextureAttributes to use (or null for defaults.)
   @[EMAIL PROTECTED]
  An Appearance, updated with the texture image.
*/
public   static   Appearance  textureAppearance (BufferedImage 
textureImageBuf, Appearance start, TextureAttributes tAttr)
{
   Appearance        textureAppear  = (start == null) ? new Appearance() 
: start;

   if (textureImageBuf == null)
   {
      throw new Error ("Null texture image");
   }
   else
   {
      if (tAttr == null)
      {
         tAttr = new TextureAttributes();
         tAttr.setTextureMode (TextureAttributes.MODULATE);
      }

      TexCoordGeneration   tcg      = new TexCoordGeneration 
(TexCoordGeneration.OBJECT_LINEAR,
                                           
TexCoordGeneration.TEXTURE_COORDINATE_2);
      textureAppear.setTexCoordGeneration (tcg);

      ImageComponent2D  image    = new ImageComponent2D 
(ImageComponent2D.FORMAT_RGBA, textureImageBuf);
      Texture2D         texture     = new Texture2D (Texture.BASE_LEVEL, 
Texture.RGBA,
                                    image.getWidth(), image.getHeight());
      texture.setImage (0, image);
      texture.setEnable (true);

      texture.setMagFilter (Texture.BASE_LEVEL_LINEAR);
      texture.setMinFilter (Texture.BASE_LEVEL_LINEAR);
      
      textureAppear.setTexture (texture);
      textureAppear.setTextureAttributes (tAttr);
   }
   textureAppear.setMaterial (new Material());

   return textureAppear;
}


// This is from T3dTerrainMesh, a supposedly "flat" material:
protected   Appearance  createAppearance()
{
   Color3f           ambient     = new Color3f (0, 0, 0);
   Color3f           diffuse     = new Color3f (1f, 1f, 1f);
   Color3f           specular = new Color3f (0.5f, 0.5f, 0.5f);
   Color3f           emit     = new Color3f (0, 0, 0);
   float          shininess   = 0;

   Appearance        app      = new Appearance();
   Material       mat      = new Material (ambient, emit, diffuse, 
specular, shininess);     

   app.setMaterial (mat);
   
   return (app);
}

-- 
Please take off your pants or I won't read your e-mail.
I will not, no matter how "good" the deal, patronise any business which
sends
unsolicited commercial e-mail or that advertises in discussion newsgroups.




 1 Posts in Topic:
Stretched terrain texture and glare
Miss Elaine Eos <Misc@  2007-06-28 05:49:06 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun May 11 19:08:41 CDT 2008.