Esempio n. 1
0
        private void AddNodeIfNotPresent(Vector3 normal, float step, int depth, Vector3 min, Vector3 max)
        {
            //don't build if already under way.
            Vector3 mid = (min + max) / 2;

            if (nodesBeingBuilt.ContainsKey(mid))
            {
                return;
            }

            if (activePatches.ContainsKey(mid))
            {
                PlanetNode node = activePatches[mid];
                node.remove = false;
                return;
            }


            var patchBeingBuilt = new PatchMinMax(min, max);

            nodesBeingBuilt.Add(mid, patchBeingBuilt);
            PlanetBuilder.Enqueue(testEffect, module, this, depth, min, max, step, normal, radius);
        }
Esempio n. 2
0
        private void CalculateConnectivity()
        {
            ReinitialiseTracker();

            // have to go through the tree in a breadth first fashion, building connectivity.
            Queue <PatchMinMax> nodesToCheck = new Queue <PatchMinMax>();

            foreach (PlanetNode rootNode in rootNodes)
            {
                nodesToCheck.Enqueue(new PatchMinMax(rootNode.min, rootNode.max, rootNode.depth, rootNode.normal,
                                                     rootNode.step, neighbourTracker.nodeDictionary[(rootNode.min + rootNode.max) / 2].side));
            }


            while (nodesToCheck.Count > 0)
            {
                PatchMinMax next = nodesToCheck.Dequeue();
                if (ShouldSplit(next.Min, next.Max, radius, next.depth))
                {
                    Vector3 se, sw, mid1, mid2, nw, ne, midBottom, midRight, midLeft, midTop;
                    PlanetNode.CalculatePatchBoundaries(next.normal, next.step, next.Min, next.Max, out se, out sw, out mid1, out mid2, out nw, out ne, out midBottom, out midRight, out midLeft, out midTop);

                    //remove this node in the neighbour tracker, generate and connect children
                    NeighbourTrackerNode southEast = new NeighbourTrackerNode(next.depth + 1, se, mid1, next.step / 2, next.normal);
                    southEast.quadrant = NeighbourTrackerNode.Quadrant.se;
                    southEast.side     = next.side;
                    PatchMinMax sePatchMinMax = new PatchMinMax(se, mid1, next.depth + 1, next.normal, next.step / 2, next.side);
                    nodesToCheck.Enqueue(sePatchMinMax);

                    NeighbourTrackerNode northWest = new NeighbourTrackerNode(next.depth + 1, mid2, nw, next.step / 2, next.normal);
                    northWest.quadrant = NeighbourTrackerNode.Quadrant.nw;
                    northWest.side     = next.side;
                    PatchMinMax nwPatchMinMax = new PatchMinMax(mid2, nw, next.depth + 1, next.normal, next.step / 2, next.side);
                    nodesToCheck.Enqueue(nwPatchMinMax);

                    NeighbourTrackerNode southWest = new NeighbourTrackerNode(next.depth + 1, midBottom, midLeft,
                                                                              next.step / 2, next.normal);
                    southWest.quadrant = NeighbourTrackerNode.Quadrant.sw;
                    southWest.side     = next.side;
                    PatchMinMax swPatchMinMax = new PatchMinMax(midBottom, midLeft, next.depth + 1, next.normal, next.step / 2, next.side);
                    nodesToCheck.Enqueue(swPatchMinMax);

                    NeighbourTrackerNode northEast = new NeighbourTrackerNode(next.depth + 1, midRight, midTop, next.step / 2, next.normal);
                    northEast.quadrant = NeighbourTrackerNode.Quadrant.ne;
                    northEast.side     = next.side;
                    PatchMinMax nePatchMinMax = new PatchMinMax(midRight, midTop, next.depth + 1, next.normal, next.step / 2, next.side);
                    nodesToCheck.Enqueue(nePatchMinMax);

                    //if (next.side == NeighbourTrackerNode.CubeSide.right || next.side == NeighbourTrackerNode.CubeSide.back)
                    //{
                    //    southEast.quadrant = NeighbourTrackerNode.Quadrant.sw;
                    //    northEast.quadrant = NeighbourTrackerNode.Quadrant.nw;
                    //    southWest.quadrant = NeighbourTrackerNode.Quadrant.se;
                    //    northWest.quadrant = NeighbourTrackerNode.Quadrant.ne;
                    //}

                    neighbourTracker.ReplaceNodeWithChildren(neighbourTracker.nodeDictionary[(next.Min + next.Max) / 2],
                                                             northWest, southWest, southEast, northEast);
                }
            }


            neighbourTracker.CopyConnectionDataToThreadSafeBuffer();
        }