private void Update() { if (BuildEveryFrame) { Camera cam = SceneCamera.Camera; if (cam.transform.rotation.Approximately(LastCameraRotation) && cam.transform.position.Approximately(LastCameraPosition)) { return; } LastCameraRotation = cam.transform.rotation; LastCameraPosition = cam.transform.position; FrustumPlanes2.FromCamera(cam, SourcePlanes, Planes); RenderNodes.Clear(); BuildTerrainJob job = BuildTerrainJob.Create(Extents, cam.transform.position, Planes, RenderNodes); JobHandle = job.Schedule(); BuildCount++; } }
public void Build() { Camera camera = SceneCamera.Camera; FrustumPlanes2.FromCamera(camera, SourcePlanes, Planes); RenderNodes.Clear(); BuildTerrainJob job = BuildTerrainJob.Create(Extents, camera.transform.position, Planes, RenderNodes); var watch = System.Diagnostics.Stopwatch.StartNew(); job.Run(); watch.Stop(); Debug.LogFormat("Construct: {0}", watch.ElapsedTicks); Debug.LogFormat("RenderNode count {0}", RenderNodes.Length); }
public void GetRenderNodes(QuadTree tree, NativeList <RenderNode> renderNodes, NativeArray <float4> planes) { NativeList <int> results = new NativeList <int>(Allocator.Temp); var nodes = tree.Nodes; for (int i = 0; i < nodes.Length; i++) { Node node = nodes[i]; if (!node.IsLeaf) { continue; } NodeBounds bounds = node.Bounds; bounds.Expand(2f); float2 center = bounds.Center; float2 extents = bounds.Extents; Bounds frustumBounds = new Bounds(); frustumBounds.center = new Vector3(center.x, 0f, center.y); frustumBounds.extents = new Vector3(extents.x, 1000f, extents.y); var intersectResult = FrustumPlanes2.Intersect(planes, frustumBounds); if (intersectResult == FrustumPlanes2.IntersectResult.Out) { continue; } tree.FindOverlapping(bounds, results); NodeSides sides = default; for (int j = 0; j < results.Length; j++) { int otherId = results[j]; if (otherId == i) { continue; } Node other = nodes[otherId]; // only smaller neighbors set different edges if (!(node.Bounds.Size.x + 1 < other.Bounds.Size.x)) { continue; } if (IsLeft(node.Bounds, other.Bounds)) { sides.Left = true; } else if (IsRight(node.Bounds, other.Bounds)) { sides.Right = true; } else if (IsForward(node.Bounds, other.Bounds)) { sides.Forward = true; } else if (IsBack(node.Bounds, other.Bounds)) { sides.Back = true; } } results.Clear(); RenderNode renderNode = new RenderNode { Node = node, MeshType = sides.GetMeshType() }; renderNodes.Add(renderNode); } }