Skip to main content

How to not stretch the texture.

5 replies [Last post]
sproketboy
Offline
Joined: 2006-08-07

Hi All,

In my game I have a setting for wall height when creating walls. When I make the walls higher the texture image I use gets stretched and blurry. I would rather if the image didn't stretch and instead repeated itself. Any ideas how to do that?
I've tried setting TextureAttributes as MODULATE, DECAL, BLEND, REPLACE, or COMBINE and it doesn't seem to make a difference.

tia

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vmironov
Offline
Joined: 2010-11-08

I have the same problem. I am developing some 3D editor project. All graphic objects in my project are created from primitives (like Box) and they have size 1
And i using for resize a scale - some thing like this:
Transform3D t = new Transform3D();
t.setScale(size.getVector3d())
But problem, that texture is also scaled but I need have it tiled. I am solved this by set texture coordinates
TexCoordGeneration tcg = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR,
TexCoordGeneration.TEXTURE_COORDINATE_2,
new Vector4f(widthScale, 0, 0, 0), new Vector4f(0, heightScale, 0, 0));
scaleAp.setTexCoordGeneration(tcg);
but it not effectively and requare much memory, becouse apperance every time new.
How is properly make realization of resizing 3D objects with Java 3D? Thanks.

sproketboy
Offline
Joined: 2006-08-07

I found something here:
http://www.mail-archive.com/java3d-interest@sun.com/msg01220.html
Let me know if that works for you.

Don Casteel

You need to change the values of the texture coordinates to linearly represent
their position.

In other words if you raise the position of a point from 1.0 to 2.0 your texture
coordinate's Y value needs to change as well.

The texture will repeat every 1.0 units, so if a square polygon spans 3.0 X
3.0 units of texture space it will have 3 rows and 3 columns of tiling

I hope this helps

Don Casteel 

Freelance Portfolio   Deviant Art Home
Deviant Art Gallery
Project Home 

________________________________
From: "java3d-interest@javadesktop.org"
To: interest@java3d.dev.java.net
Sent: Fri, October 29, 2010 6:17:19 PM
Subject: How to not stretch the texture.

Hi All,

In my game I have a setting for wall height when creating walls. When I make the
walls higher the texture image I use gets stretched and blurry. I would rather
if the image didn't stretch and instead repeated itself.  Any ideas how to do
that?
I've tried setting TextureAttributes as MODULATE, DECAL, BLEND, REPLACE, or
COMBINE and it doesn't seem to make a difference.

tia
[Message sent by forum member 'sproketboy']

http://forums.java.net/jive/thread.jspa?messageID=486511

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

[att1.html]

sproketboy
Offline
Joined: 2006-08-07

Thanks. That puts me in the right direction.

I create the object like this:

Primitive wall = new Box(THICKNESS, height, RADIUS, flags, wallApp, texHeight);

I'm assuming that the Box constructor's last param (called numTexUnit) is the correct way.

But I still see the texture stretch... :(

The int texHeight is 1 or 2 or 3.

Don Casteel

First, I have not used Java3D in a long time, so my comments are generalized to
how to accomplish what you need in "most" 3D engines.

It looks like you are trying to animate your box by re-creating a new box of a
different size for each frame. This is going to be very inefficient, so I
reccommend you create the mesh programatically.
I can't remember if the texture coordinates are exposed in J3D's primitives, but
if they aren't you will need to create your box as a mesh anyway.

I very much doubt Java3D has automated functionallity to keep the texture from
distorting as you move vertices around, (most engines do not)
I'm afraid you will have to modify the texture coordinates manually in whatever
loop your using to move your vertices.

In the loop where you move each vertex, simply set the texture coordinate to the
same values. (choosing the correct 2 of the 3 XYZ components for the vertex
position) 

So if the face is an XY plane:

_vertex.X += 0.1;
>_vertex.Y += 0.1;
>_vertex.Z += 0.1;
>texturCoord.X = _vertex.X * scalefactor;  // scalefactor is just a preset
>variable to size the texture to the face
>texturCoord.Y = _vertex.Y * scalefactor;
If the face is an YZ plane:
_vertex.X += 0.1;
>_vertex.Y += 0.1;
>_vertex.Z += 0.1;
>texturCoord.X = _vertex.Y * scalefactor;  // scalefactor is just a preset
>variable to size the texture to the face
>texturCoord.Y = _vertex.Z * scalefactor;

Don Casteel 

Freelance Portfolio   Deviant Art Home
Deviant Art Gallery
Project Home 

________________________________
From: "java3d-interest@javadesktop.org"
To: interest@java3d.dev.java.net
Sent: Sat, October 30, 2010 7:12:02 AM
Subject: Re: How to not stretch the texture.

Thanks. That puts me in the right direction.

I create the object like this:

Primitive wall = new Box(THICKNESS, height, RADIUS, flags, wallApp, texHeight);

I'm assuming that the Box constructor's last param (called numTexUnit) is the
correct way.

But I still see the texture stretch... :(

The int texHeight is 1 or 2 or 3.
[Message sent by forum member 'sproketboy']

http://forums.java.net/jive/thread.jspa?messageID=486524

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

[att1.html]