public void TrySplit(int min_size, float threshold, int grid_size, List<VertexPositionColorNormal> vertices)
{
// This part taken from http://www.volume-gfx.com/ as a listed optimization, though it's disabled right now by setting the value to 1000
float minSplitDistanceDiagonalFactor = 1000.0f;
if (Sampler.Sample(position + Vector2.One * size * 0.5f) > size * (float)Math.Sqrt(2) * minSplitDistanceDiagonalFactor || size <= min_size || GetError(threshold) < threshold)
{
dualgrid_pos = 0.5f * size * Vector2.One;
isovalue = Sampler.Sample(dualgrid_pos);
normal = Sampler.GetNormal(dualgrid_pos);
vertex_index = vertices.Count;
leaf = true;
Color n_c = new Color(210, 220, 210);
vertices.Add(new VertexPositionColorNormal(new Vector3(position * grid_size + dualgrid_pos * grid_size, 0), n_c, new Vector3(normal, 0)));
return;
}
for (int i = 0; i < 4; i++)
{
children[i] = new QuadtreeNode();
children[i].index = i;
children[i].position = position + (float)(size / 2) * new Vector2(i / 2, i % 2);
children[i].size = size / 2;
children[i].TrySplit(min_size, threshold, grid_size, vertices);
}
}