当前位置:网站首页>[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】
边栏推荐
- 2022 Q2 - 提昇技能的技巧總結
- es面試題
- how to add one row in the dataframe?
- Sword finger offer 42 Maximum sum of continuous subarrays
- What is the function of the headphone driver
- Redis环境搭建和使用的方法
- How to batch add background and transition effects to videos?
- 【OpenCV】-5种图像滤波的综合示例
- Ar Augmented Reality applicable scenarios
- Leetcode face T10 (1-9) array, ByteDance interview sharing
猜你喜欢
![[technology development -21]: rapid overview of the application and development of network and communication technology -1- Internet Network Technology](/img/2d/299fa5c76416f74bd1a693c433dd09.png)
[technology development -21]: rapid overview of the application and development of network and communication technology -1- Internet Network Technology

Cesium dynamic diffusion point effect
![[liuyubobobo play with leetcode algorithm interview] [00] Course Overview](/img/1c/c8cab92c74b6658c3ef608c5255f1f.png)
[liuyubobobo play with leetcode algorithm interview] [00] Course Overview

How to solve MySQL master-slave delay problem

How does MySQL solve the problem of not releasing space after deleting a large amount of data
![[learn C and fly] 2day Chapter 8 pointer (practice 8.1 password unlocking)](/img/2e/8fe55393ccca6663d98c0b3dd9a146.png)
[learn C and fly] 2day Chapter 8 pointer (practice 8.1 password unlocking)

Comparative analysis of MVC, MVP and MVVM, source code analysis

研发中台拆分过程的一些心得总结

WebGPU(一):基本概念

Redis环境搭建和使用的方法
随机推荐
Regular expression learning notes
Vsocde has cli every time it is opened js
剑指 Offer 29. 顺时针打印矩阵
As a software testing engineer, will you choose the bank post? Laolao bank test post
essay structure
Opencascade7.6 compilation
JVM interview
Medical management system (C language course for freshmen)
Data analysis on the disaster of Titanic
What are the necessary things for students to start school? Ranking list of Bluetooth headsets with good sound quality
How to build and use redis environment
研发中台拆分过程的一些心得总结
CSDN article underlined, font color changed, picture centered, 1 second to understand
Deep learning: a solution to over fitting in deep neural networks
Which kind of sports headphones is easier to use? The most recommended sports headphones
Comparative analysis of MVC, MVP and MVVM, source code analysis
If you want to rewind the video picture, what simple methods can you use?
实现一个自定义布局的扫码功能
超图iServer rest服务之feature查询
MySQL operates the database through the CMD command line, and the image cannot be found during the real machine debugging of fluent