x


How to move UV's of a mesh so you can have two textures in one file

Hi,

I'd like to move the a mesh's uv.x value += 512 so it displays a different version of the objects skin that sits inside the same texture.

I've seen this:

mesh.Clear(); mesh.vertices = newVertices; mesh.uv = newUV; mesh.triangles = newTriangles;

Which seems to stretch or shrink the skin.

The end goal to is to only move certains vertices so I have some of the skin coming from one side of the texture and some of it from the other side.

Anyone know what I'm talking about?

more ▼

asked Mar 17 '10 at 05:58 AM

David O'Donoghue gravatar image

David O'Donoghue
61 4 4 9

As a general note: 512 sounds like you are talking about a shift of 512 pixels. However, uv's are always given in a resolution-independent, normalized space. So if your texture is 1024x1024, a 512 pixel shift would be uv.x+=0.5

Oct 04 '10 at 10:21 AM Wolfram
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

1) Have you consider trying to achieve the effect by manipulating a material rather then animating a mesh's uvs?

Materials with texture have a tiling xy AND an offset xy.

I would highly recommend experimenting with the material in the editor before writing your script to automate it.

You will need to adjust the tiling to get the new skin to work. This will have the effect of stretching or shrinking the skin until you get it right. Next, manipulate the offset x or y. This will slide the entire texture map across the surface of your object.

Once you understand how get control over that, then write the script that manipulates the material.

2) It is difficult to understand your question without seeing it. Can you post an concept image that describes the look you are going for?

more ▼

answered Mar 17 '10 at 06:28 AM

lowbloodsugar gravatar image

lowbloodsugar
433 9 11 16

Here's an example. The first picture is the original undamaged texture, the second is a texture that shows the entire object damaged and the third represents only 1 face of the object damaged.

[url=http://i.imagehost.org/view/0319/test2][img]http://i.imagehost.org/t/0319/test2.jpg[/img][/url]

Apr 20 '10 at 03:35 AM David O'Donoghue

I wouldn't advise doing this since it will create a new instance of the material thus another draw call

Jan 14 at 06:40 PM Next Beat Games
(comments are locked)
10|3000 characters needed characters left

Offsetting only a few triangle's worth of UV's is going to be needlessly complicated.. However, if you wish to offset the entire UV set of an object, i wrote this..

var xOffset = 0.0;
var yOffset = 0.0;

function Start()
{

    // Build the uvs 
    var uvs : Vector2[] = new Vector2[(GetComponent(MeshFilter) as MeshFilter).mesh.vertices.Length]; 
    uvs = (GetComponent(MeshFilter) as MeshFilter).mesh.uv; // Take the existing UVs 


    for (var i = 0 ; i < uvs.Length; i++) uvs[i] = Vector2 (uvs[i].x + xOffset, uvs[i].y + yOffset); // Offset all the UV's 

   // Apply the modded UV's 
    (GetComponent(MeshFilter) as MeshFilter).mesh.uv = uvs; 

    // Blow this shiz away 
    Destroy(this);
}
more ▼

answered Sep 03 '10 at 05:12 AM

jtbentley gravatar image

jtbentley
579 3 4 16

This helped me tremendously after hours of searching and not finding what I needed.. Thanks!

Jul 13 '12 at 10:59 AM cynicalwanderer

thanks for this code, i tried to paste it to a simple instantiation and it runs ok but the UV's of all the clone objects are still the same.

Sep 07 '12 at 12:29 PM ZoomDomain
(comments are locked)
10|3000 characters needed characters left

Don't know how old this is, but I wrote a script that let's you slide UVs in the editor visually while still batching. It's a little buggy, but it works :)

Link: http://ethanredd.tumblr.com/post/35949640385/simple-free-uvslider-i-wrote

more ▼

answered Nov 18 '12 at 01:15 PM

theRaddRedd gravatar image

theRaddRedd
1 1 2 2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x238

asked: Mar 17 '10 at 05:58 AM

Seen: 4633 times

Last Updated: Jan 14 at 06:40 PM