internal void SetTexturesCoincident(IEnumerable <int> vertices) { var lookup = sharedTextureLookup; SharedVertex.SetCoincident(ref lookup, vertices); SetSharedTextures(lookup); }
void GeometryWithPoints(Vector3[] points) { // Wrap in faces Face[] f = new Face[points.Length / 4]; for (int i = 0; i < points.Length; i += 4) { f[i / 4] = new Face(new int[6] { i + 0, i + 1, i + 2, i + 1, i + 3, i + 2 }, 0, AutoUnwrapSettings.tile, 0, -1, -1, false); } Clear(); positions = points; m_Faces = f; m_SharedVertices = SharedVertex.GetSharedVerticesWithPositions(points); InvalidateSharedVertexLookup(); ToMesh(); Refresh(); }
internal void SetSharedTextures(IEnumerable<KeyValuePair<int, int>> indexes) { if (indexes == null) throw new ArgumentNullException("indexes"); m_SharedTextures = SharedVertex.ToSharedVertices(indexes); InvalidateSharedTextureLookup(); }
/// <summary> /// Sets the passed vertices as being considered coincident by the ProBuilderMesh. /// </summary> /// <remarks> /// Note that it is up to the caller to ensure that the passed vertices are indeed sharing a position. /// </remarks> /// <param name="vertices">Returns a list of vertices to be associated as coincident.</param> public void SetVerticesCoincident(IEnumerable <int> vertices) { var lookup = sharedVertexLookup; List <int> coincident = new List <int>(); GetCoincidentVertices(vertices, coincident); SharedVertex.SetCoincident(ref lookup, coincident); SetSharedVertices(lookup); }
/// <summary> /// Copy constructor. /// </summary> /// <param name="sharedVertex">The array to copy.</param> public SharedVertex(SharedVertex sharedVertex) { if (sharedVertex == null) { throw new ArgumentNullException("sharedVertex"); } m_Vertices = new int[sharedVertex.Count]; Array.Copy(sharedVertex.m_Vertices, m_Vertices, m_Vertices.Length); }
internal void AddSharedVertex(SharedVertex vertex) { if (vertex == null) { throw new ArgumentNullException("vertex"); } m_SharedVertices = m_SharedVertices.Add(vertex); InvalidateSharedVertexLookup(); }
static SharedVertex[] ToSharedVertices(List <List <int> > list) { if (list == null) { throw new ArgumentNullException("list"); } SharedVertex[] arr = new SharedVertex[list.Count]; for (int i = 0; i < arr.Length; i++) { arr[i] = new SharedVertex(list[i]); } return(arr); }
/// <summary> /// Clear all mesh attributes and reinitialize with new positions and face collections. /// </summary> /// <param name="vertices">Vertex positions array.</param> /// <param name="faces">Faces array.</param> public void RebuildWithPositionsAndFaces(IEnumerable <Vector3> vertices, IEnumerable <Face> faces) { if (vertices == null) { throw new ArgumentNullException("vertices"); } Clear(); m_Positions = vertices.ToArray(); m_Faces = faces.ToArray(); m_SharedVertices = SharedVertex.GetSharedVerticesWithPositions(m_Positions); InvalidateSharedVertexLookup(); InvalidateSharedTextureLookup(); ToMesh(); Refresh(); }
/// <summary> /// Reset all the attribute arrays on this object. /// </summary> public void Clear() { // various editor tools expect faces & vertices to always be valid. // ideally we'd null everything here, but that would break a lot of existing code. m_Faces = new Face[0]; m_Positions = new Vector3[0]; m_Textures0 = new Vector2[0]; m_Textures2 = null; m_Textures3 = null; m_Tangents = null; m_SharedVertices = new SharedVertex[0]; m_SharedTextures = new SharedVertex[0]; InvalidateSharedVertexLookup(); InvalidateSharedTextureLookup(); m_Colors = null; ClearSelection(); }
/// <summary> /// Create a new array of SharedVertex objects by comparing points in the passed positions collection. /// </summary> /// <example> /// ``` /// <![CDATA[var mesh = gameObject.AdComponent<ProBuilderMesh>();]]> /// mesh.SetPositions(myNewPositions); /// mesh.SetFaces(myNewFaces); /// mesh.SetSharedIndexes(SharedVertex.GetSharedVerticesWithPositions(myNewPositions)); /// ``` /// </example> /// <param name="positions">A collection of Vector3 positions to be tested for equality.</param> /// <returns>A new SharedVertex[] where each SharedIndex is a list of indexes that are sharing the same position.</returns> public static SharedVertex[] GetSharedVerticesWithPositions(IList <Vector3> positions) { if (positions == null) { throw new ArgumentNullException("positions"); } Dictionary <IntVec3, List <int> > sorted = new Dictionary <IntVec3, List <int> >(); for (int i = 0; i < positions.Count; i++) { List <int> ind; if (sorted.TryGetValue(positions[i], out ind)) { ind.Add(i); } else { sorted.Add(new IntVec3(positions[i]), new List <int>() { i }); } } SharedVertex[] share = new SharedVertex[sorted.Count]; int t = 0; foreach (KeyValuePair <IntVec3, List <int> > kvp in sorted) { share[t++] = new SharedVertex(kvp.Value.ToArray()); } return(share); }