public override void Extrude(float distance) { m_faceSelection.BeginChange(); ProBuilderMesh[] meshes = m_faceSelection.Meshes.OrderBy(m => m == m_faceSelection.LastMesh).ToArray(); foreach (ProBuilderMesh mesh in meshes) { IList <Face> faces = m_faceSelection.GetFaces(mesh).ToArray(); for (int i = 0; i < faces.Count; ++i) { m_faceSelection.Remove(faces[i]); } mesh.Extrude(faces, ExtrudeMethod.FaceNormal, distance); for (int i = 0; i < faces.Count; ++i) { m_faceSelection.Add(mesh, faces[i]); } mesh.ToMesh(); mesh.Refresh(); } m_faceSelection.EndChange(); if (distance != 0.0f) { m_faceSelection.Synchronize( m_faceSelection.GetCenterOfMass(), m_faceSelection.LastPosition + m_faceSelection.LastNormal * distance); } }
public override MeshSelection Select(Camera camera, Rect rect, GameObject[] gameObjects, MeshEditorSelectionMode mode) { MeshSelection selection = new MeshSelection(); m_faceSelection.BeginChange(); Dictionary <ProBuilderMesh, HashSet <Face> > result = PBUtility.PickFaces(camera, rect, gameObjects); if (mode == MeshEditorSelectionMode.Add) { foreach (KeyValuePair <ProBuilderMesh, HashSet <Face> > kvp in result) { ProBuilderMesh mesh = kvp.Key; IList <Face> faces = mesh.faces; IList <int> faceIndices = kvp.Value.Select(f => faces.IndexOf(f)).ToArray(); IList <int> notSelected = faceIndices.Where(f => !m_faceSelection.IsSelected(f)).ToArray(); foreach (int face in notSelected) { m_faceSelection.Add(mesh, face); } selection.SelectedFaces.Add(mesh, notSelected); } } else if (mode == MeshEditorSelectionMode.Substract) { foreach (KeyValuePair <ProBuilderMesh, HashSet <Face> > kvp in result) { ProBuilderMesh mesh = kvp.Key; IList <Face> faces = mesh.faces; IList <int> faceIndices = kvp.Value.Select(f => faces.IndexOf(f)).ToArray(); IList <int> selected = faceIndices.Where(f => m_faceSelection.IsSelected(f)).ToArray(); foreach (int face in selected) { m_faceSelection.Remove(face); } selection.UnselectedFaces.Add(mesh, selected); } } else if (mode == MeshEditorSelectionMode.Difference) { foreach (KeyValuePair <ProBuilderMesh, HashSet <Face> > kvp in result) { ProBuilderMesh mesh = kvp.Key; IList <Face> faces = mesh.faces; IList <int> faceIndices = kvp.Value.Select(f => faces.IndexOf(f)).ToArray(); IList <int> selected = faceIndices.Where(f => m_faceSelection.IsSelected(f)).ToArray(); IList <int> notSelected = faceIndices.Where(f => !m_faceSelection.IsSelected(f)).ToArray(); foreach (int face in selected) { m_faceSelection.Remove(face); } foreach (int face in notSelected) { m_faceSelection.Add(mesh, face); } selection.UnselectedFaces.Add(mesh, selected); selection.SelectedFaces.Add(mesh, notSelected); } } m_faceSelection.EndChange(); if (selection.SelectedFaces.Count == 0 && selection.UnselectedFaces.Count == 0) { selection = null; } return(selection); }
public override MeshSelection Select(Camera camera, Vector3 pointer, bool shift, bool ctrl) { MeshSelection selection = null; MeshAndFace result = PBUtility.PickFace(camera, pointer); if (result.face != null) { if (ctrl) { int submeshIndex = result.face.submeshIndex; IList <Face> faces = result.mesh.faces; List <int> sameMaterialFaces = new List <int>(); bool wasSelected = false; bool wasUnselected = false; m_faceSelection.BeginChange(); for (int i = 0; i < faces.Count; ++i) { Face face = faces[i]; if (face.submeshIndex == submeshIndex) { sameMaterialFaces.Add(i); if (!m_faceSelection.IsSelected(result.mesh, i)) { m_faceSelection.Add(result.mesh, i); wasUnselected = true; } else { wasSelected = true; } } } if (wasSelected && !wasUnselected) { for (int i = 0; i < sameMaterialFaces.Count; ++i) { m_faceSelection.Remove(result.mesh, sameMaterialFaces[i]); } selection = new MeshSelection(); selection.UnselectedFaces.Add(result.mesh, sameMaterialFaces.ToArray()); } else { selection = new MeshSelection(); selection.SelectedFaces.Add(result.mesh, sameMaterialFaces.ToArray()); } m_faceSelection.EndChange(); } else { int faceIndex = result.mesh.faces.IndexOf(result.face); if (m_faceSelection.IsSelected(result.mesh, faceIndex)) { if (shift) { m_faceSelection.Remove(result.mesh, faceIndex); selection = new MeshSelection(); selection.UnselectedFaces.Add(result.mesh, new[] { faceIndex }); } else { //selection = ReadSelection(); selection = null; } } else { if (shift) { selection = new MeshSelection(); } else { selection = ReadSelection(); m_faceSelection.Clear(); } m_faceSelection.Add(result.mesh, faceIndex); selection.SelectedFaces.Add(result.mesh, new[] { faceIndex }); } } } else { if (!shift) { selection = ReadSelection(); if (selection.UnselectedFaces.Count == 0) { selection = null; } m_faceSelection.Clear(); } } return(selection); }