暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VertexDictionary.cs 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using Unity.Collections;
  4. internal struct VertexDictionary
  5. {
  6. static Dictionary<Vector3, int> m_VertexDictionary = new Dictionary<Vector3, int>();
  7. public NativeArray<int> GetIndexRemap(NativeArray<Vector3> vertices, NativeArray<int> indices)
  8. {
  9. // Create a mapping to unique vertices
  10. NativeArray<int> vertexMapping = new NativeArray<int>(vertices.Length, Allocator.Temp);
  11. m_VertexDictionary.Clear();
  12. m_VertexDictionary.EnsureCapacity(vertices.Length);
  13. for (int i = 0; i < vertices.Length; i++)
  14. {
  15. Vector3 vertex = vertices[i];
  16. if (!m_VertexDictionary.ContainsKey(vertex))
  17. {
  18. vertexMapping[i] = i;
  19. m_VertexDictionary.Add(vertex, i);
  20. }
  21. else
  22. {
  23. vertexMapping[i] = m_VertexDictionary[vertex];
  24. }
  25. }
  26. NativeArray<int> remappedIndices = new NativeArray<int>(indices.Length, Allocator.Temp);
  27. for (int i = 0; i < indices.Length; i++)
  28. {
  29. remappedIndices[i] = vertexMapping[indices[i]];
  30. }
  31. return remappedIndices;
  32. }
  33. }