1using System.Collections;
2using System.Collections.Generic;
5using NaughtyAttributes;
9[RequireComponent(typeof(MeshFilter))]
10[RequireComponent(typeof(MeshCollider))]
15 private List<Vector3> m_Vertices;
23 m_MiniCubePrefab = GameObject.Find(
"ModelEditorRoot").transform.Find(
"Store").transform.Find(
"Vertex Editor").GetComponent<
VertexEditor>();
25 GameObject.Find(
"Store")?.SetActive(
false);
27 m_Mesh = GetComponent<MeshFilter>().mesh;
30 m_Vertices = GetMeshVertices();
31 GenerateVerticesEditorObjects();
39 public void SetVertex(List<int> vertexIndex, Vector3 position)
41 for (
int i = 0; i < vertexIndex.Count; i++)
42 m_Vertices[vertexIndex[i]] = position;
46 m_Mesh.vertices = m_Vertices.ToArray();
47 m_Mesh.RecalculateNormals();
50 private List<Vector3> GetMeshVertices()
52 return m_Mesh.vertices.ToList();
56 private void GenerateVerticesEditorObjects()
63 if (m_Mesh.vertices.Length < 1)
67 List<VertexEditor> vertexEditors =
new List<VertexEditor>();
71 vertexEditors[0].transform.localPosition = m_Vertices[0];
72 vertexEditors[0].AddVertexIndex(0);
74 for (
int i = 1; i < m_Vertices.Count; i++)
76 int index = GetVertexPositionIndex(m_Vertices[i], vertexEditors);
80 vertexEditors[index].AddVertexIndex(i);
86 int last = vertexEditors.Count - 1;
87 vertexEditors[last].transform.localPosition = m_Vertices[i];
88 vertexEditors[last].AddVertexIndex(i);
99 private int GetVertexPositionIndex(Vector3 vertexPosition, List<VertexEditor> list)
101 for (
int i = 0; i < list.Count; i++)
102 if (list[i].transform.localPosition == vertexPosition)
109 private void ExportFBX()
110 {var allVE = FindObjectsOfType<VertexEditor>();
111 foreach (var ve
in allVE)
113 ve.gameObject.SetActive(
false);
116 foreach (var ve
in allVE)
118 ve.gameObject.SetActive(
true);
124 var allVE = FindObjectsOfType<VertexEditor>();
125 foreach (var ve
in allVE)
127 ve.gameObject.SetActive(
false);
130 foreach (var ve
in allVE)
132 ve.gameObject.SetActive(
true);
UnityEngine.UI.Button Button
VertexEditor m_MiniCubePrefab
void SetVertex(List< int > vertexIndex, Vector3 position)
After moving a VertexEditor, it should change all vertices position
static ModelEditorLogicManager instance
void SetVertex(List< int > vertexIndex, Vector3 position)
static bool ExportGameObjToFBX(GameObject gameObj, string newPath, bool copyMaterials=false, bool copyTextures=false)
static string ExportGameObjToFBXString(GameObject gameObj)