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 void GroupFaces(MeshSelection selection) { SetTextureGroup(selection); }
public void UngroupFaces(MeshSelection selection) { SetTextureGroup(selection, -1); }
public virtual void ApplySelection(MeshSelection selection) { }
public virtual void RollbackSelection(MeshSelection 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); }
public override MeshSelection Select(Camera camera, Vector3 pointer, bool shift) { MeshSelection selection = null; MeshAndFace result = PBUtility.PickFace(camera, pointer); if (result.face != null) { if (m_faceSelection.IsSelected(result.face)) { if (shift) { m_faceSelection.Remove(result.face); selection = new MeshSelection(); selection.UnselectedFaces.Add(result.mesh, new[] { result.face }); } else { selection = ReadSelection(); //if(selection.SelectedFaces.Count > 1) //{ // selection.UnselectedFaces[result.mesh] = selection.UnselectedFaces[result.mesh].Where(f => f != result.face).ToArray(); // selection.SelectedFaces.Add(result.mesh, new[] { result.face }); // m_faceSelection.Clear(); // m_faceSelection.Add(result.mesh, result.face); //} //else { selection = null; } } } else { if (shift) { selection = new MeshSelection(); } else { selection = ReadSelection(); m_faceSelection.Clear(); } m_faceSelection.Add(result.mesh, result.face); selection.SelectedFaces.Add(result.mesh, new[] { result.face }); } } else { if (!shift) { selection = ReadSelection(); if (selection.UnselectedFaces.Count == 0) { selection = null; } m_faceSelection.Clear(); } } return(selection); }
public override MeshSelection Select(Camera camera, Vector3 pointer, bool shift, bool ctrl, bool depthTest) { MeshSelection selection = null; GameObject pickedObject = PBUtility.PickObject(camera, pointer); float result = PBUtility.PickEdge(camera, pointer, 20, pickedObject, m_edgeSelection.Meshes, depthTest, ref m_selection); if (result != Mathf.Infinity) { if (m_edgeSelection.IsSelected(m_selection.mesh, m_selection.edge)) { if (shift) { m_edgeSelection.FindCoincidentEdges(m_selection.mesh); IList <Edge> edges = m_edgeSelection.GetCoincidentEdges(new[] { m_selection.edge }); m_edgeSelection.Remove(m_selection.mesh, edges); selection = new MeshSelection(); selection.UnselectedEdges.Add(m_selection.mesh.gameObject, edges); } else { m_edgeSelection.FindCoincidentEdges(m_selection.mesh); IList <Edge> edges = m_edgeSelection.GetCoincidentEdges(new[] { m_selection.edge }); selection = ReadSelection(); selection.UnselectedEdges[m_selection.mesh.gameObject] = selection.UnselectedEdges[m_selection.mesh.gameObject].Where(e => e != m_selection.edge).ToArray(); selection.SelectedEdges.Add(m_selection.mesh.gameObject, edges); m_edgeSelection.Clear(); m_edgeSelection.Add(m_selection.mesh, edges); } } else { if (shift) { selection = new MeshSelection(); } else { selection = ReadSelection(); m_edgeSelection.Clear(); } m_edgeSelection.FindCoincidentEdges(m_selection.mesh); IList <Edge> edges = m_edgeSelection.GetCoincidentEdges(new[] { m_selection.edge }); m_edgeSelection.Add(m_selection.mesh, edges); selection.SelectedEdges.Add(m_selection.mesh.gameObject, edges); } } else { if (!shift) { selection = ReadSelection(); if (selection.UnselectedEdges.Count == 0) { selection = null; } m_edgeSelection.Clear(); } } return(selection); }
public virtual void SetSelection(MeshSelection selection) { }
public void Merge(MeshSelection selection, bool partial) { if (HasFaces) { if (selection.HasEdges) { selection.EdgesToFaces(false, partial); } else if (selection.HasVertices) { selection.VerticesToFaces(false, partial); } foreach (KeyValuePair <ProBuilderMesh, IList <int> > kvp in selection.SelectedFaces) { ProBuilderMesh mesh = kvp.Key; IList <int> faces = kvp.Value; if (!SelectedFaces.ContainsKey(mesh)) { SelectedFaces.Add(mesh, faces); } else { IList <int> existingFaces = SelectedFaces[mesh].ToList(); MergeLists(faces, existingFaces); SelectedFaces[mesh] = existingFaces; } } foreach (KeyValuePair <ProBuilderMesh, IList <int> > kvp in selection.UnselectedFaces) { ProBuilderMesh mesh = kvp.Key; IList <int> faces = kvp.Value; if (!UnselectedFaces.ContainsKey(mesh)) { UnselectedFaces.Add(mesh, faces); } else { IList <int> existingFaces = UnselectedFaces[mesh].ToList(); MergeLists(faces, existingFaces); UnselectedFaces[mesh] = existingFaces; } } } else if (HasEdges) { if (selection.HasFaces) { selection.FacesToEdges(false); } else if (selection.HasVertices) { selection.VerticesToEdges(false, partial); } foreach (KeyValuePair <ProBuilderMesh, IList <Edge> > kvp in selection.SelectedEdges) { ProBuilderMesh mesh = kvp.Key; IList <Edge> edges = kvp.Value; if (!SelectedEdges.ContainsKey(mesh)) { SelectedEdges.Add(mesh, edges); } else { IList <Edge> existingEdges = SelectedEdges[mesh].ToList(); MergeLists(edges, existingEdges); SelectedEdges[mesh] = existingEdges; } } foreach (KeyValuePair <ProBuilderMesh, IList <Edge> > kvp in selection.UnselectedEdges) { ProBuilderMesh mesh = kvp.Key; IList <Edge> edges = kvp.Value; if (!UnselectedEdges.ContainsKey(mesh)) { UnselectedEdges.Add(mesh, edges); } else { IList <Edge> existingEdges = UnselectedEdges[mesh].ToList(); MergeLists(edges, existingEdges); UnselectedEdges[mesh] = existingEdges; } } } else if (HasVertices) { if (selection.HasFaces) { selection.FacesToVertices(false); } else if (selection.HasEdges) { selection.EdgesToVertices(false); } foreach (KeyValuePair <ProBuilderMesh, IList <int> > kvp in selection.SelectedIndices) { ProBuilderMesh mesh = kvp.Key; IList <int> indexes = kvp.Value; if (!SelectedIndices.ContainsKey(mesh)) { SelectedIndices.Add(mesh, indexes); } else { IList <int> existingIndexes = SelectedIndices[mesh].ToList(); MergeLists(indexes, existingIndexes); SelectedIndices[mesh] = existingIndexes; } } foreach (KeyValuePair <ProBuilderMesh, IList <int> > kvp in selection.SelectedIndices) { ProBuilderMesh mesh = kvp.Key; IList <int> indexes = kvp.Value; if (!UnselectedIndices.ContainsKey(mesh)) { UnselectedIndices.Add(mesh, indexes); } else { IList <int> existingIndexes = UnselectedIndices[mesh].ToList(); MergeLists(indexes, existingIndexes); UnselectedIndices[mesh] = existingIndexes; } } } }
public virtual void BeginDrag(MeshSelection selection, Vector3 initialPosition, Quaternion initialRotation) { Selection = selection; if (Selection.HasEdges) { Selection.EdgesToFaces(false, false); } if (Selection.HasVertices) { Selection.VerticesToFaces(false, false); } InitialPosition = initialPosition; InitialRotation = initialRotation; Matrix = Matrix4x4.TRS(InitialPosition, InitialRotation, Vector3.one); MatrixInv = Matrix.inverse; List <ProBuilderMesh> allMeshes = new List <ProBuilderMesh>(); List <Vector2[]> allOrigins = new List <Vector2[]>(); List <Vector2[]> allFaceCenters = new List <Vector2[]>(); List <PBAutoUVConversion.UVTransform[]> allUVTransforms = new List <PBAutoUVConversion.UVTransform[]>(); List <bool[]> allIsManualUv = new List <bool[]>(); List <int[]> allIndexes = new List <int[]>(); HashSet <int> indexes = new HashSet <int>(); List <Vector2> origins = new List <Vector2>(); List <Vector2> faceCenters = new List <Vector2>(); List <PBAutoUVConversion.UVTransform> uvTransforms = new List <PBAutoUVConversion.UVTransform>(); List <bool> isManualUv = new List <bool>(); List <Face> faces = new List <Face>(); foreach (KeyValuePair <ProBuilderMesh, IList <int> > kvp in Selection.SelectedFaces) { ProBuilderMesh mesh = kvp.Key; mesh.GetFaces(kvp.Value, faces); IList <Vector2> textures = mesh.textures; for (int f = 0; f < faces.Count; ++f) { Face face = faces[f]; IList <int> faceIndexes = face.indexes; for (int i = 0; i < faceIndexes.Count; ++i) { int faceIndex = faceIndexes[i]; if (!indexes.Contains(faceIndex)) { indexes.Add(faceIndex); origins.Add(textures[faceIndex]); faceCenters.Add(GetCenterOfMass(textures, face)); PBAutoUVConversion.UVTransform transform = PBAutoUVConversion.GetUVTransform(mesh, face); if (!face.manualUV) { Vector2 scale = transform.scale; scale.x = -scale.x; transform.scale = scale; } uvTransforms.Add(transform); } } isManualUv.Add(face.manualUV); face.manualUV = true; } allIndexes.Add(indexes.ToArray()); allOrigins.Add(origins.ToArray()); allFaceCenters.Add(faceCenters.ToArray()); allUVTransforms.Add(uvTransforms.ToArray()); allIsManualUv.Add(isManualUv.ToArray()); allMeshes.Add(mesh); indexes.Clear(); origins.Clear(); faceCenters.Clear(); uvTransforms.Clear(); isManualUv.Clear(); faces.Clear(); } Indexes = allIndexes.ToArray(); Origins = allOrigins.ToArray(); FaceCenters = allFaceCenters.ToArray(); UVTransforms = allUVTransforms.ToArray(); IsManualUv = allIsManualUv.ToArray(); Meshes = allMeshes.ToArray(); }
public static void ClearGroup(PBMesh pbMesh, MeshSelection selection) { SetGroup(pbMesh, selection, smoothingGroupNone); }