当前位置:网站首页>[question 008: what is UV in unity?]
[question 008: what is UV in unity?]
2022-07-02 02:22:00 【valaki】
Video Explanation
Unity Chinese vs UV The understanding of the
One 、 What is? UV
UV What is it? ?UV In fact, it is another definition of texture coordinate axis ;
For example, we usually say Transform Coordinates of , That is to say Transform Specific position in Cartesian coordinate system , The visual representation of the location is (x,y,z); So usually when we talk about the coordinates of objects , The subconscious mind will think (x,y,z);
Why do textures have coordinates ?
For example, this picture below :
From this picture we can view its information , Know this picture size How much is the , What's the size , When was it created , But we don't care about the coordinates of this picture , Because we don't use its coordinates at this time , But it does exist .
When we put the above texture on a Quad When it's up there , You need to use the coordinates of the texture : Look at the following effect :
Above is the picture Unity The effect of operation , Among them is 5 The two are equal in size Quad, But they use the same texture to get different results ; This is because every Quad Of the texture obtained UV The coordinate ranges are different , Lead to Quad The rendering results are different ;
Two 、 The example analysis
UV The meaning of coordinates lies in a mapping relationship with object coordinates ;
For example, the texture size in the above figure is 512x512, We can't use 512*512 This size to map , If we are mapping to objects of the same size , They are 1 Yes 1 The relationship between , That is, the coordinates and texture of each object UV The coordinate points correspond to ; Otherwise, the mapping process is very troublesome ;
So what are object coordinates ?
Look at one below Quad Pictures of the :
The object in the above figure Pivot and Center All in the center , In wireframe mode, you can see that the object has 4 vertices ,2 Triangles ; To put all or part of a texture completely in this quad It shows correctly , It needs to be used uv coordinate , The following steps are required :
- To find the Quad Rendering of triangles , Is it counterclockwise or clockwise ; You will get a picture of the front or the back
- To find the Quad Of 4 individual UV The order of coordinates , That is to confirm uv[0]、uv[1]、uv[2]、uv[3] And vertex coordinates vertext[0]、vertext[1]、vertext[2]、vertext[3] Correspondence of , Only the correct correspondence can get the correct result ; You can use it here UV Any reasonable range of coordinates 4 individual uv Coordinate points to correspond to vertex coordinates , In this way, some or all of the texture can be rendered to quad On ;
- uv The value range of coordinates will be converted to 0-1 Between ; such as 512 The size picture range will be changed to :uv(0/512,0/512)-(512/512,512/512) Value range of , Convert according to image size ;
- Finally, reset the object UV Coordinates are OK ;
UV Is another name for texture coordinates ,UV The coordinates are xy coordinate , It is only for the convenience of describing the differences in the process that this statement is made ; So deal with uv Coordinates deal with Cartesian coordinates ; You can think of a texture as the first quadrant in a Cartesian coordinate system , In the lower left corner (0,0) coordinate , The maximum value range of the first quadrant of this coordinate is 0-1 Between ;
The mapping between texture and object is the mapping relationship between texture coordinates and object coordinates , The correct mapping of texture coordinates can get the correct appearance of the object .
3、 ... and 、 Source code
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class ValakiShowUvPartDemos : MonoBehaviour
{
enum ShowUVPartType
{
None=0,
LeftTop,
LeftBottom,
Center,
RightTop,
RightBottom
};
List<Vector2> uvs;
Vector2[] backUv;
Mesh mesh;
[SerializeField] ShowUVPartType showUVPartType;
[SerializeField] bool isPlayRandomUvPart;
ShowUVPartType currentUvPartType = ShowUVPartType.None;
private void Awake()
{
mesh = GetComponent<MeshFilter>().mesh;
uvs = mesh.uv.ToList();
backUv = mesh.uv;
}
float totalTime;
private void LateUpdate()
{
if (isPlayRandomUvPart)
{
totalTime += Time.deltaTime;
if(totalTime >= 0.7f)
{
totalTime = 0;
int random = Random.Range(1, 6);
showUVPartType = (ShowUVPartType)random;
}
}
if (currentUvPartType != showUVPartType)
{
currentUvPartType = showUVPartType;
switch (showUVPartType)
{
case ShowUVPartType.Center:
mesh.SetUVs(0, backUv);
break;
case ShowUVPartType.LeftBottom:
ShowLeftBottomUvPart();
break;
case ShowUVPartType.LeftTop:
ShowLeftTopUvPart();
break;
case ShowUVPartType.RightBottom:
ShowRightBottomUvPart();
break;
case ShowUVPartType.RightTop:
ShowRightTopUvPart();
break;
}
}
}
void ShowLeftTopUvPart()
{
// Left - The lower right - Top left - The upper right
uvs[0] = new Vector2(0, 0.75f);
uvs[1] = new Vector2(0.25f, 0.75f);
uvs[2] = new Vector2(0, 1);
uvs[3] = new Vector2(0.25f, 1);
mesh.SetUVs(0, uvs);
}
void ShowRightTopUvPart()
{
uvs[0] = new Vector2(0.75f, 0.75f);
uvs[1] = new Vector2(1, 0.75f);
uvs[2] = new Vector2(0.75f, 1);
uvs[3] = new Vector2(1, 1);
mesh.SetUVs(0, uvs);
}
void ShowLeftBottomUvPart()
{
uvs[0] = new Vector2(0, 0);
uvs[1] = new Vector2(0.25f, 0);
uvs[2] = new Vector2(0, 0.25f);
uvs[3] = new Vector2(0.25f, 0.25f);
mesh.SetUVs(0, uvs);
}
void ShowRightBottomUvPart()
{
uvs[0] = new Vector2(0.75f, 0);
uvs[1] = new Vector2(1, 0);
uvs[2] = new Vector2(0.75f, 0.25f);
uvs[3] = new Vector2(1, 0.25f);
mesh.SetUVs(0, uvs);
}
}
Conclusion :
Don't ask me how many grades , I'm just a jerk 【valaki】
边栏推荐
- [reading notes] programmer training manual - practical learning is the most effective (project driven)
- Word search applet design report based on cloud development +ppt+ project source code + demonstration video
- [C #] use regular verification content
- Email picture attachment
- pytest 测试框架
- Quality means doing it right when no one is looking
- The wave of layoffs in big factories continues, but I, who was born in both non undergraduate schools, turned against the wind and entered Alibaba
- leetcode2305. 公平分发饼干(中等,周赛,状压dp)
- LeetCode刷题(十)——顺序刷题46至50
- Open那啥的搭建文档
猜你喜欢
The basic steps of using information theory to deal with scientific problems are
CSDN article underlined, font color changed, picture centered, 1 second to understand
【毕业季】研究生学长分享怎样让本科更有意义
Types of exhibition items available in the multimedia interactive exhibition hall
leetcode2311. Longest binary subsequence less than or equal to K (medium, weekly)
Build a modern data architecture on the cloud with Amazon AppFlow, Amazon lake formation and Amazon redshift
AR增强现实可应用的场景
Which kind of sports headphones is easier to use? The most recommended sports headphones
leetcode2312. Selling wood blocks (difficult, weekly race)
【带你学c带你飞】2day 第8章 指针(练习8.1 密码开锁)
随机推荐
What is the MySQL column to row function
【带你学c带你飞】2day 第8章 指针(练习8.1 密码开锁)
Divorce for 3 years to discover the undivided joint property, or
Pytest testing framework
CVPR 2022 | 大连理工提出自校准照明框架,用于现实场景的微光图像增强
Questions d'entrevue
剑指 Offer 42. 连续子数组的最大和
Software testing learning notes - network knowledge
leetcode2310. 个位数字为 K 的整数之和(中等,周赛)
Sword finger offer 47 Maximum value of gifts
2022低压电工考试题模拟考试题库模拟考试平台操作
AR增强现实可应用的场景
Sword finger offer 31 Stack push in and pop-up sequence
leetcode2310. The one digit number is the sum of integers of K (medium, weekly)
leetcode2312. 卖木头块(困难,周赛)
MySQL主从延迟问题怎么解决
Summary of some experiences in the process of R & D platform splitting
Sword finger offer 29 Print matrix clockwise
Infix expression to suffix expression (computer) code
Which kind of sports headphones is easier to use? The most recommended sports headphones