Jump to content

  • Log In with Google      Sign In   
  • Create Account


Getting textures to tile on a mesh the same way regardless of the size or shape of the mesh


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Casey Hardman   Crossbones+   -  Reputation: 2145

Like
0Likes
Like

Posted 05 November 2013 - 04:12 AM

Hey guys,

 

I'm having some trouble...

 

I'm using Unity and about to get into testing out the level design for the 3D game I'm making.  I've got some test textures that I made (poorly) and I'm confused on how to get them to show up the same way regardless of the mesh they're placed on.

 

I already sought help on the matter by asking on the Unity Answers website some time ago.  I explained the dilemma there and I put an image up to help demonstrate it.  Here's a link there.  Just so you know, the answer below my question there isn't really relevant to this thread.

 

I kind of fixed the issue with the help of the community and some of my own hacky coding.

 

What I did was code up a way to make a new material (which, in Unity, is a texture, kind of) and set its tiling based on the distance the material has to be 'stretched across'.  If the mesh is 25 units wide and 8 units tall, then it sets the X tiling to 25 and the Y tiling to 8.  Since the goal was to try and make a way to tile a texture by game units instead of "how many times it's placed on the mesh", I added a variable called 'gameUnitsPerTile' and set the X and Y tiling to X distance / gameUnitsPerTile and Y distance / gameUnitsPerTile, respectively.

 

The thought was, the material tiles across the whole mesh X/Y tiling times.  So if the tiling is 4x4, then it draws the image 4 times along the X axis and 4 times along the Y axis.  If the tiling values were set to the actual 'length' of the mesh, then it'd be tiling it once across the whole mesh.  That way, as long as your gameUnitsPerTile value was the same for each mesh, you could have the texture showing the same way on each mesh.

 

It actually worked pretty well, but I still feel like I'm doing it wrong, and I'm not totally confident my method is very optimized (having a different material for each wall) or will work in every situation I'll need it to.  I'm probably just severely mixed up about how UVs and texture tiling works.  I feel like this is a lot harder than it should be.

 

Anyway, thanks for reading this far, and I hope it makes sense.  If I've failed to explain something properly, please tell me what it is and I'll try to fix it.  Any help would be appreciated.



Sponsor:

#2 meeshoo   Members   -  Reputation: 508

Like
1Likes
Like

Posted 05 November 2013 - 10:20 AM

Well, when i started my first game in Unity, i didn't watch any tutorials, I just read docs when I needed and start working. I ended up with many things that were not supposed to be done as I did, but then it worked and who cares.

 

If it works and has no performance impact (i.e. you are doing it when the level is loading or something, not every frame), then just get over it.

 

Sometimes there is no proper way to do a thing, and the goal is to make a game, not write perfect code.



#3 Hawkblood   Members   -  Reputation: 712

Like
0Likes
Like

Posted 06 November 2013 - 05:43 PM

Are you changing the size of the mesh often?

 

Is the mesh a plane?

 

I haven't used Unity before, so I'm not sure if this will work:

 

If you are using a plane, simply make a 2x2 vertex plane and set the UV coordinates according to the size of the plane:

If you want each whole number unit to be a "tile", then you simply apply the U and V with respect to X and Z (or Y).



#4 Kian   Members   -  Reputation: 235

Like
0Likes
Like

Posted 07 November 2013 - 02:28 PM

I'm curious, why are you doing this at run time? Do you expect your meshes to change?



#5 Casey Hardman   Crossbones+   -  Reputation: 2145

Like
0Likes
Like

Posted 15 November 2013 - 08:44 PM

Sorry for the late reply!

 

 

Are you changing the size of the mesh often?

 

Is the mesh a plane?

 

I haven't used Unity before, so I'm not sure if this will work:

 

If you are using a plane, simply make a 2x2 vertex plane and set the UV coordinates according to the size of the plane:

If you want each whole number unit to be a "tile", then you simply apply the U and V with respect to X and Z (or Y).

 

I'm not really using a plane; I can get it to work on planes, because they're simple enough shapes, but actual level geometry, like a whole wall that winds around into itself, is another story.

 

I'm curious, why are you doing this at run time? Do you expect your meshes to change?

 

I'm not anymore.  I was at one point, just to test if the method worked, but I've since made it happen in the editor.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS