已解决
Unity-UV展开工具
来自网友在路上 182882提问 提问时间:2023-11-03 16:44:04阅读次数: 82
最佳答案 问答题库828位专家为你答疑解惑
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;public class unfold : EditorWindow
{[MenuItem("Gq_Tools/展开")]public static void ShowWin(){EditorWindow.CreateInstance<unfold>().Show();}private void OnGUI(){GUILayout.Space(10);GUILayout.BeginHorizontal("box");GUILayout.Space(10);if (GUILayout.Button("Planar-X 展开"))//UI上画一个按钮{//MonoBehaviour.print("do");Unfold0("X");}if (GUILayout.Button("Planar-Y 展开"))//UI上画一个按钮{//MonoBehaviour.print("do");Unfold0("Y");}if (GUILayout.Button("Planar-Z 展开"))//UI上画一个按钮{//MonoBehaviour.print("do");Unfold0("Z");}GUILayout.EndHorizontal();GUILayout.Space(10);GUILayout.BeginHorizontal("box");if (GUILayout.Button("立方展开"))//UI上画一个按钮{//MonoBehaviour.print("do");Unfold1();}GUILayout.EndHorizontal();GUILayout.Space(10);GUILayout.BeginHorizontal("box");if (GUILayout.Button("通过光图UV展开"))//UI上画一个按钮 {//MonoBehaviour.print("do");Unfold2();}GUILayout.EndHorizontal();}//Planar Unfoldvoid Unfold0(string inStr){var objs = Selection.objects;if (inStr == "X"){foreach (var obj in objs)//for每个选中的物体{var go = obj as GameObject;Mesh mesh = go.GetComponent<MeshFilter>().sharedMesh;Vector3[] vertices = mesh.vertices;Vector2[] uvs = new Vector2[vertices.Length];//Planar Unfoldfor (int i = 0; i < uvs.Length; i++){uvs[i] = new Vector2(vertices[i].y, vertices[i].z);}mesh.uv = uvs;}}if (inStr == "Y"){foreach (var obj in objs)//for每个选中的物体 {var go = obj as GameObject;Mesh mesh = go.GetComponent<MeshFilter>().sharedMesh;Vector3[] vertices = mesh.vertices;Vector2[] uvs = new Vector2[vertices.Length];//Planar Unfoldfor (int i = 0; i < uvs.Length; i++){uvs[i] = new Vector2(vertices[i].x, vertices[i].z);}mesh.uv = uvs;}}if (inStr == "Z"){foreach (var obj in objs)//for每个选中的物体{var go = obj as GameObject;Mesh mesh = go.GetComponent<MeshFilter>().sharedMesh;Vector3[] vertices = mesh.vertices;Vector2[] uvs = new Vector2[vertices.Length];//Planar Unfoldfor (int i = 0; i < uvs.Length; i++){uvs[i] = new Vector2(vertices[i].x, vertices[i].y);}mesh.uv = uvs;}}}//Cubic Unfoldvoid Unfold1(){var objs = Selection.objects;foreach (var obj in objs)//for每个选中的物体 {var go = obj as GameObject;Mesh mesh = go.GetComponent<MeshFilter>().sharedMesh;Vector3[] vertices = mesh.vertices;Vector2[] uvs = new Vector2[vertices.Length];Vector3[] normals = mesh.normals;//Cubic Unfoldfor (int i = 0; i < normals.Length; i++){//X-Planeif (Mathf.Abs(normals[i].x) > Mathf.Abs(normals[i].y) && Mathf.Abs(normals[i].x) > Mathf.Abs(normals[i].z)){uvs[i] = new Vector2(vertices[i].y, vertices[i].z);}//Y-Planeif (Mathf.Abs(normals[i].y) > Mathf.Abs(normals[i].x) && Mathf.Abs(normals[i].y) > Mathf.Abs(normals[i].z)){uvs[i] = new Vector2(vertices[i].x, vertices[i].z);}//Z-Planeif (Mathf.Abs(normals[i].z) > Mathf.Abs(normals[i].x) && Mathf.Abs(normals[i].z) > Mathf.Abs(normals[i].y)){uvs[i] = new Vector2(vertices[i].x, vertices[i].y);}}mesh.uv = uvs; }}//use lightmap UV void Unfold2(){var objs = Selection.objects;foreach (var obj in objs)//对于每个选中的物体 // {var go = obj as GameObject;Mesh mesh = go.GetComponent<MeshFilter>().sharedMesh;mesh.uv = mesh.uv2;}}
}
查看全文
99%的人还看了
相似问题
- Untiy 使用RotateAround()方法实现物体围绕某个点或者某个物体旋转
- 【OpenCV】计算视频的光流并跟踪物体calcOpticalFlowPyrLK
- 双十一“静悄悄”?VR购物拉满沉浸式购物体验
- 【Unity ShaderGraph】| 物体靠近时局部溶解,根据坐标控制溶解的位置【文末送书】
- 最新Cocos Creator 3.x 如何动态修改3D物体的透明度
- unity 从UI上拖出3D物体,(2D转3D)
- DirectX3D 虚拟现实项目 三维物体的光照及着色(五个不同着色效果的旋转茶壶)
- Azure 机器学习 - 使用 AutoML 和 Python 训练物体检测模型
- 【UE】从UI中拖拽生成物体
- RK3588平台开发系列讲解(项目篇)基于yolov5的物体识别
猜你感兴趣
版权申明
本文"Unity-UV展开工具":http://eshow365.cn/6-31204-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!