private void UpdateRoot() { var point = cachedTerrain.GetAboveGroundObserverCubePoint(); var middle = resolution / 2; var center = middle * point; var bounds = new SgtLongBounds((long)center.x, (long)center.y, (long)center.z, radius); var outer = new SgtLongBounds(-middle, -middle, middle - 1, middle, middle, middle); Mark(); for (var i = 0; i < 6; i++) { var quadBounds = SgtTerrainTopology.GetQuadBounds(i, bounds); quadBounds.ClampTo(outer); UpdateColliders(i, quadBounds, middle); } Sweep(); }
private void UpdateLod() { var spherePoint = GetSpherePoint(); for (var i = 0; i < cubes.Count; i++) { var cube = cubes[i]; var cubeBounds = GetCubeBound(i, spherePoint, cube.Middle); var cubeLimits = new SgtLongBounds(0, 0, 0, cube.Middle); for (var j = 0; j < 6; j++) { var quad = cube.Quads[j]; var quadBounds = SgtTerrainTopology.GetQuadBounds(j, cubeBounds); if (i == 0) { quad.PendingOuter = new SgtLongBounds(0, 0, 0, cube.Middle); quad.VirtualOuter = new SgtLongBounds(0, 0, 0, cube.Middle * 2); } else { var prevCube = cubes[i - 1]; var prevQuad = prevCube.Quads[j]; var prevResolution = prevCube.Resolution; quad.PendingOuter = prevQuad.PendingInner * 2; quad.VirtualOuter = prevQuad.VirtualInner * 2; } if (quadBounds.minZ <= cube.Middle && quadBounds.maxZ >= cube.Middle) { quad.VirtualInner = quadBounds; } else { quad.VirtualInner = default(SgtLongBounds); } quad.PendingInner = quad.VirtualInner; quad.PendingInner.ClampTo(cubeLimits); if (quad.PendingOuter.SizeX < 0 || quad.PendingOuter.SizeY < 0 || quad.PendingOuter.SizeZ < 0) { quad.PendingOuter = default(SgtLongBounds); quad.PendingInner = default(SgtLongBounds); } var forceUpdate = false; if (dirty == true) { if (quad.CurrentOuter.Volume > 0 || quad.CurrentInner.Volume > 0) { forceUpdate = true; quad.CurrentOuter.Clear(); quad.CurrentInner.Clear(); } } if (quad.CurrentOuter.Volume == 0) { quad.CurrentOuter = default(SgtLongBounds); } if (quad.PendingOuter.Volume == 0) { quad.PendingOuter = default(SgtLongBounds); } if (quad.CurrentInner.Volume == 0) { quad.CurrentInner = default(SgtLongBounds); } if (quad.PendingInner.Volume == 0) { quad.PendingInner = default(SgtLongBounds); } if (quad.CurrentOuter != quad.PendingOuter || quad.CurrentInner != quad.PendingInner || forceUpdate == true) { pendingQuads.Push(quad); } } } dirty = false; }