Unity3d 努力将偏移图像纹理应用于统一立方体基本体的所有边

Unity3d 努力将偏移图像纹理应用于统一立方体基本体的所有边,unity3d,textures,texture2d,Unity3d,Textures,Texture2d,我有一个统一的纹理包含四个不同的缝合在一起的图像(见下文) 我的目标是获取图像的绿色“左下”部分,并使用网格UV将其作为纹理统一应用于立方体基本体的所有面。问题是我没有完全掌握顶点是如何排列的,所以我正在努力使纹理正确匹配 如果您查看下面的代码,变量bottomLeft、bottomRight、topLeft和toplright对应于我的图像纹理的绿色“BOTTOM-LEFT”部分。只需将提供的图像拖动到Unity中的多维数据集上,并将此脚本添加到Start()中,就可以轻松地测试这一点 到目

我有一个统一的纹理包含四个不同的缝合在一起的图像(见下文)

我的目标是获取图像的绿色“左下”部分,并使用网格UV将其作为纹理统一应用于立方体基本体的所有面。问题是我没有完全掌握顶点是如何排列的,所以我正在努力使纹理正确匹配

如果您查看下面的代码,变量bottomLeft、bottomRight、topLeft和toplright对应于我的图像纹理的绿色“BOTTOM-LEFT”部分。只需将提供的图像拖动到Unity中的多维数据集上,并将此脚本添加到Start()中,就可以轻松地测试这一点

到目前为止,我已经设法找出了立方体的“正面”、“顶部”和“背面”…但是“底部”和“左侧”由于某种原因旋转了90度…而“右侧”是完全错误的。我不知道哪些UV对应于什么,所以我只是猜测尝试重新排列UV[xx]

void Start()
{    
    Mesh mesh = GetComponent<MeshFilter>().mesh;         
    Vector2[] UVs = new Vector2[mesh.vertices.Length];

    Vector2 bottomLeft = new Vector2(0.0f, 0.0f);
    Vector2 bottomRight = new Vector2(0.5f, 0.0f);
    Vector2 topLeft = new Vector2(0.0f, 0.5f);
    Vector2 topRight = new Vector2(0.5f, 0.5f);

    /* Working */

    // front
    UVs[0] = bottomLeft;        
    UVs[1] = bottomRight;       
    UVs[2] = topLeft;           
    UVs[3] = topRight;          

    // top
    UVs[8] = bottomLeft;        
    UVs[9] = bottomRight;       
    UVs[4] = topLeft;           
    UVs[5] = topRight;          

    // back
    UVs[10] = bottomLeft;        
    UVs[11] = bottomRight;      
    UVs[6] = topLeft;           
    UVs[7] = topRight;          


    /* Kinda Working */

    // bottom
    UVs[13] = bottomLeft;        
    UVs[12] = bottomRight;       
    UVs[14] = topLeft;           
    UVs[15] = topRight;          

    // left
    UVs[18] = bottomLeft;        
    UVs[16] = bottomRight;      
    UVs[17] = topLeft;           
    UVs[19] = topRight;          

    /* Not Working */

    // right
    UVs[21] = bottomLeft;        
    UVs[20] = bottomRight;       
    UVs[22] = topLeft;           
    UVs[23] = topRight;          

    mesh.uv = UVs;
}
void Start()
{    
网格网格=GetComponent().Mesh;
Vector2[]UVs=新的Vector2[mesh.vertices.Length];
Vector2 bottomLeft=新的Vector2(0.0f,0.0f);
Vector2 bottomRight=新的Vector2(0.5f,0.0f);
向量2左上=新向量2(0.0f,0.5f);
Vector2 topRight=新Vector2(0.5f,0.5f);
/*工作*/
//正面
UVs[0]=左下角;
UVs[1]=右下角;
UVs[2]=左上角;
UVs[3]=右上角;
//顶
UVs[8]=左下角;
UVs[9]=右下角;
UVs[4]=左上角;
UVs[5]=右上角;
//背
UVs[10]=左下角;
UVs[11]=右下角;
UVs[6]=左上角;
UVs[7]=右上角;
/*还不错*/
//底部
UVs[13]=左下角;
UVs[12]=右下角;
UVs[14]=左上角;
UVs[15]=右上角;
//左
UVs[18]=左下角;
UVs[16]=右下角;
UVs[17]=左上角;
UVs[19]=右上角;
/*不起作用*/
//对
UVs[21]=左下角;
UVs[20]=右下角;
UVs[22]=左上角;
UVs[23]=右上角;
网格uv=uv;
}
欢迎提供任何指导,因为我不知道从哪里开始尝试匹配构成立方体的每个三角形上的每个点。

明白了

    // front side of cube
    UVs[0] = bottomLeft;        
    UVs[1] = bottomRight;       
    UVs[2] = topLeft;           
    UVs[3] = topRight;          

    // top side of cube
    UVs[4] = topLeft;           
    UVs[5] = topRight;          
    UVs[8] = bottomLeft;       // note here it's UVs 8 and 9 for 'top'
    UVs[9] = bottomRight;         

    // back side of cube
    UVs[6] = bottomRight;      // and UVs 6 and 7 are actually part of 'back'
    UVs[7] = bottomLeft;         
    UVs[10] = topRight;          
    UVs[11] = topLeft;              

    // bottom side of cube
    UVs[12] = bottomLeft;        
    UVs[13] = topLeft;           
    UVs[14] = topRight;          
    UVs[15] = bottomRight;       

    // left side of cube
    UVs[16] = bottomLeft;        
    UVs[17] = topLeft;           
    UVs[18] = topRight;          
    UVs[19] = bottomRight;       
    
    // right side of cube
    UVs[20] = bottomLeft;        
    UVs[21] = topLeft;           
    UVs[22] = topRight;          
    UVs[23] = bottomRight;