예제 #1
0
        public void TestDisplayRenderNodes()
        {
            GameObject parent = new GameObject();

            parent.transform.position = default;

            for (int i = 0; i < RenderNodes.Length; i++)
            {
                RenderNode node = RenderNodes[i];
                Mesh       mesh = QuadTerrainConfig.Instance.GetMesh(node.MeshType);
                GameObject go   = Instantiate(TestPrefab);
                go.transform.SetParent(parent.transform);
                MeshFilter filter = go.GetComponent <MeshFilter>();
                filter.sharedMesh          = mesh;
                go.transform.localPosition = node.WorldPosition;
                go.transform.localScale    = node.WorldScale;
            }
        }
예제 #2
0
        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);
            }
        }