protected override void ReadFromImpl(object obj) { base.ReadFromImpl(obj); PBFace uo = (PBFace)obj; Indexes = uo.Indexes; SubmeshIndex = uo.SubmeshIndex; TextureGroup = uo.TextureGroup; IsManualUV = uo.IsManualUV; }
protected override object WriteToImpl(object obj) { obj = base.WriteToImpl(obj); PBFace uo = (PBFace)obj; uo.Indexes = Indexes; uo.SubmeshIndex = SubmeshIndex; uo.TextureGroup = TextureGroup; uo.IsManualUV = IsManualUV; return(uo); }
private void GetIndexes() { if (m_tool.Mode == ProBuilderToolMode.Vertex) { m_indexes = m_selection.Select(s => s.Vertices.ToArray()).ToArray(); } else if (m_tool.Mode == ProBuilderToolMode.Face) { m_indexes = m_selection.Select(s => { HashSet <int> indexes = new HashSet <int>(); PBFace[] faces = s.Mesh.Faces; foreach (int faceIndex in s.Faces) { PBFace face = faces[faceIndex]; for (int i = 0; i < face.Indexes.Length; ++i) { if (!indexes.Contains(face.Indexes[i])) { indexes.Add(face.Indexes[i]); } } } return(indexes.ToArray()); }).ToArray(); } else { m_indexes = m_selection.Select(s => { HashSet <int> indexes = new HashSet <int>(); PBEdge[] edges = s.Mesh.Edges; foreach (int edgeIndex in s.Edges) { PBEdge edge = edges[edgeIndex]; if (!indexes.Contains(edge.A)) { indexes.Add(edge.A); } if (!indexes.Contains(edge.B)) { indexes.Add(edge.B); } } return(indexes.ToArray()); }).ToArray(); } }
public void RefreshPivotPoint() { Vector2 pivotPosition = Vector2.zero; int count = 0; switch (m_tool.Mode) { case ProBuilderToolMode.Vertex: foreach (ManualUVSelection selection in m_selection) { PBMesh mesh = selection.Mesh; Vector2[] uvs = mesh.Textures; foreach (int index in selection.Vertices) { count++; if (count == 1) { pivotPosition = uvs[index]; } else { pivotPosition *= (count - 1) / (float)count; pivotPosition += uvs[index] / count; } } } break; case ProBuilderToolMode.Face: foreach (ManualUVSelection selection in m_selection) { PBMesh mesh = selection.Mesh; Vector2[] uvs = mesh.Textures; PBFace[] faces = mesh.Faces; foreach (int index in selection.Faces) { PBFace face = faces[index]; int[] faceIndexes = face.Indexes; Vector2 faceUV = uvs[faceIndexes[0]]; for (int i = 1; i < faceIndexes.Length; ++i) { faceUV += uvs[faceIndexes[i]]; } faceUV /= faceIndexes.Length; count++; if (count == 1) { pivotPosition = faceUV; } else { pivotPosition *= (count - 1) / (float)count; pivotPosition += faceUV / count; } } } break; default: foreach (ManualUVSelection selection in m_selection) { PBMesh mesh = selection.Mesh; Vector2[] uvs = mesh.Textures; PBEdge[] edges = mesh.Edges; foreach (int index in selection.Edges) { PBEdge edge = edges[index]; Vector2 edgeUV = (uvs[edge.A] + uvs[edge.B]) * 0.5f; count++; if (count == 1) { pivotPosition = edgeUV; } else { pivotPosition *= (count - 1) / (float)count; pivotPosition += edgeUV / count; } } } break; } pivotPosition *= ManualUVRenderer.Scale; m_pivotPoint.position = new Vector3(pivotPosition.x, pivotPosition.y, -1); m_pivotPoint.rotation = Quaternion.identity; m_pivotPoint.localScale = Vector3.one; m_prevPivotPoint = m_pivotPoint.position; if (count == 0) { m_pivotPointSelection.Select(null, null); } else { m_pivotPointSelection.Select(m_pivotPoint.gameObject, new[] { m_pivotPoint.gameObject }); } }
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(); }