当前位置:网站首页>[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】
边栏推荐
- Query word weight, search word weight calculation
- how to come in an investnent bank team
- 大厂裁员潮不断,双非本科出身的我却逆风翻盘挺进阿里
- Summary of some experiences in the process of R & D platform splitting
- Leetcode face T10 (1-9) array, ByteDance interview sharing
- How to solve MySQL master-slave delay problem
- leetcode2312. 卖木头块(困难,周赛)
- [deep learning] Infomap face clustering facecluster
- Pytest testing framework
- 研发中台拆分过程的一些心得总结
猜你喜欢

Medical management system (C language course for freshmen)

LFM signal denoising, time-frequency analysis, filtering

pytest 测试框架

WebGPU(一):基本概念

The basic steps of using information theory to deal with scientific problems are

Cesium dynamic diffusion point effect

What style of Bluetooth headset is easy to use? High quality Bluetooth headset ranking

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

leetcode2309. 兼具大小写的最好英文字母(简单,周赛)

CoordinatorLayout + TabLayout + ViewPager2(里面再嵌套一个RecyclerView),RecyclerView的滑动冲突解决
随机推荐
Deployment practice and problem solving of dash application development environment based on jupyter Lab
LFM信号加噪、时频分析、滤波
[liuyubobobo play with leetcode algorithm interview] [00] Course Overview
Pytest testing framework
leetcode2310. 个位数字为 K 的整数之和(中等,周赛)
Sword finger offer II 031 Least recently used cache
[pit] how to understand "parameter fishing"
剑指 Offer II 031. 最近最少使用缓存
STM32F103——两路PWM控制电机
leetcode2309. 兼具大小写的最好英文字母(简单,周赛)
设置状态栏颜色
超图iServer rest服务之feature查询
Sword finger offer 42 Maximum sum of continuous subarrays
What is the function of the headphone driver
【带你学c带你飞】2day 第8章 指针(练习8.1 密码开锁)
MySQL中一条SQL是怎么执行的
使用开源项目【Banner】实现轮播图效果(带小圆点)
[reading notes] programmer training manual - practical learning is the most effective (project driven)
JS slow animation
es面試題