message: spatial: Minor refactoring
  Switch loops to be based on triangle count and add a few comments.
diff: @@ -49,6 +49,7 @@ static void computeOrder(unsigned int* result, const float* vertex_positions_dat
  float scale = extent == 0 ? 0.f : 1.f / extent;
  + // generate Morton order based on the position inside a unit cube
  for (size_t i = 0; i < vertex_count; ++i)
  {
  const float* v = vertex_positions_data + i * vertex_stride_float;
  @@ -61,11 +62,11 @@ static void computeOrder(unsigned int* result, const float* vertex_positions_dat
  }
  }
  -// TODO: is it faster to use [3][1024]?
  static void computeHistogram(unsigned int (&hist)[1024][3], const unsigned int* data, size_t count)
  {
  memset(hist, 0, sizeof(hist));
  + // compute 3 10-bit histograms in parallel
  for (size_t i = 0; i < count; ++i)
  {
  unsigned int id = data[i];
  @@ -77,6 +78,7 @@ static void computeHistogram(unsigned int (&hist)[1024][3], const unsigned int*
  unsigned int sumx = 0, sumy = 0, sumz = 0;
  + // replace histogram data with prefix histogram sums in-place
  for (int i = 0; i < 1024; ++i)
  {
  unsigned int hx = hist[i][0], hy = hist[i][1], hz = hist[i][2];
  @@ -147,28 +149,27 @@ void meshopt_spatialSortTriangles(unsigned int* destination, const unsigned int*
  (void)vertex_count;
  - meshopt_Allocator allocator;
  + size_t face_count = index_count / 3;
  + size_t vertex_stride_float = vertex_positions_stride / sizeof(float);
  - float* centroids = allocator.allocate<float>(index_count);
  + meshopt_Allocator allocator;
  - size_t vertex_stride_float = vertex_positions_stride / sizeof(float);
  + float* centroids = allocator.allocate<float>(face_count * 3);
  - for (size_t i = 0; i < index_count; i += 3)
  + for (size_t i = 0; i < face_count; ++i)
  {
  - unsigned int a = indices[i + 0], b = indices[i + 1], c = indices[i + 2];
  + unsigned int a = indices[i * 3 + 0], b = indices[i * 3 + 1], c = indices[i * 3 + 2];
  assert(a < vertex_count && b < vertex_count && c < vertex_count);
  const float* va = vertex_positions + a * vertex_stride_float;
  const float* vb = vertex_positions + b * vertex_stride_float;
  const float* vc = vertex_positions + c * vertex_stride_float;
  - centroids[i + 0] = (va[0] + vb[0] + vc[0]) / 3.f;
  - centroids[i + 1] = (va[1] + vb[1] + vc[1]) / 3.f;
  - centroids[i + 2] = (va[2] + vb[2] + vc[2]) / 3.f;
  + centroids[i * 3 + 0] = (va[0] + vb[0] + vc[0]) / 3.f;
  + centroids[i * 3 + 1] = (va[1] + vb[1] + vc[1]) / 3.f;
  + centroids[i * 3 + 2] = (va[2] + vb[2] + vc[2]) / 3.f;
  }
  - size_t face_count = index_count / 3;
  -
  unsigned int* remap = allocator.allocate<unsigned int>(face_count);
  meshopt_spatialSortRemap(remap, centroids, face_count, sizeof(float) * 3);
  