public void SelectVertices(Func <Vector2, float> canSelect, bool selectClosest, bool clearSelection) { m_editor.Undo.BeginRecord(); for (int index = 0; index < m_selection.Count; ++index) { ManualUVSelection selection = m_selection[index]; ManualUVSelection oldSelection = new ManualUVSelection(selection); if (clearSelection) { selection.Clear(); } PBMesh mesh = selection.Mesh; Vector2[] uvs = mesh.Textures; float minDistance = float.PositiveInfinity; int closestIndex = -1; for (int i = 0; i < uvs.Length; ++i) { float distance = canSelect(uvs[i]); if (selectClosest) { if (distance < minDistance) { closestIndex = i; minDistance = distance; } } else { if (distance <= 0) { if (!selection.Vertices.Contains(i)) { selection.Vertices.Add(i); } } } } if (closestIndex >= 0) { if (!selection.Vertices.Contains(closestIndex)) { selection.Vertices.Add(closestIndex); } } RecordSelection(index, oldSelection, new ManualUVSelection(selection)); if (SelectionChanged != null) { SelectionChanged(selection); } } m_editor.Undo.EndRecord(); }
private void Select(MeshSelection meshSelection) { for (int index = 0; index < m_selection.Count; ++index) { ManualUVSelection selection = m_selection[index]; ManualUVSelection oldSelection = new ManualUVSelection(selection); selection.Clear(); if (meshSelection.HasVertices) { foreach (int i in meshSelection.GetIndices(selection.Mesh)) { selection.Vertices.Add(i); } } else if (meshSelection.HasEdges) { foreach (int i in meshSelection.GetEdges(selection.Mesh)) { selection.Edges.Add(i); } } else if (meshSelection.HasFaces) { foreach (int i in meshSelection.GetFaces(selection.Mesh)) { selection.Faces.Add(i); } } if (SelectionChanged != null) { SelectionChanged(selection); } } }
public void SelectFaces(Func <Vector2, float> canSelect, bool selectClosest, bool clearSelection) { m_editor.Undo.BeginRecord(); for (int index = 0; index < m_selection.Count; ++index) { ManualUVSelection selection = m_selection[index]; ManualUVSelection oldSelection = new ManualUVSelection(selection); if (clearSelection) { selection.Clear(); } PBMesh mesh = selection.Mesh; Vector2[] meshUV = mesh.Textures; PBFace[] meshFaces = mesh.Faces; float minDistance = float.PositiveInfinity; int closestIndex = -1; for (int i = 0; i < meshFaces.Length; ++i) { PBFace face = meshFaces[i]; Vector2 uv = meshUV[face.Indexes[0]]; for (int j = 1; j < face.Indexes.Length; ++j) { uv += meshUV[face.Indexes[j]]; } uv /= face.Indexes.Length; float distance = canSelect(uv); if (selectClosest) { if (distance < minDistance) { closestIndex = i; minDistance = distance; } } else { if (distance <= 0) { if (!selection.Faces.Contains(i)) { selection.Faces.Add(i); } } } } if (closestIndex >= 0) { if (!selection.Faces.Contains(closestIndex)) { selection.Faces.Add(closestIndex); } } RecordSelection(index, oldSelection, new ManualUVSelection(selection)); if (SelectionChanged != null) { SelectionChanged(selection); } } m_editor.Undo.EndRecord(); }