• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by David O'Donoghue · Mar 17, 2010 at 05:58 AM · uv

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Wolfram · Oct 04, 2010 at 10:21 AM 0
Share

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by jtbentley · Sep 03, 2010 at 05:12 AM

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);

}

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image chmodseven · Jul 13, 2012 at 10:59 AM 0
Share

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

avatar image MountDoomTeam · Sep 07, 2012 at 12:29 PM 0
Share

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.

avatar image
0

Answer by lowbloodsugar · Mar 17, 2010 at 06:28 AM

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?

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image David O'Donoghue · Apr 20, 2010 at 03:35 AM 0
Share

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]

avatar image David O'Donoghue · Apr 20, 2010 at 03:36 AM 0
Share

http://i.imagehost.org/0319/test2.jpg

avatar image Next Beat Games · Jan 14, 2013 at 06:40 PM 0
Share

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

avatar image
0

Answer by theRaddRedd · Nov 18, 2012 at 01:15 PM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Assigning UV Map to model at runtime 0 Answers

Playing UV-Animation on a Plane, without particle system? 1 Answer

How do I Rotate a Skybox's Material 4 Answers

Difference between TRANSFORM_TEX and MultiplyUV 0 Answers

Updating UV in imported mesh without having to re-material 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges