Example #1
0
    public IList <QuadTreeTerrainFace> FindWesternNeighborsOfSmallerSize(QuadTreeTerrainFace neighbor)
    {
        IList <QuadTreeTerrainFace> candidates = new List <QuadTreeTerrainFace>();
        IList <QuadTreeTerrainFace> neighbors  = new List <QuadTreeTerrainFace>();

        if (neighbor != null)
        {
            candidates.Add(neighbor);
        }

        while (candidates.Count > 0)
        {
            if (!candidates[0].isDivided)
            {
                neighbors.Add(candidates[0]);
            }
            else
            {
                candidates.Add(candidates[0].NorthEast);
                candidates.Add(candidates[0].SouthEast);
            }

            candidates.RemoveAt(0);
        }

        return(neighbors);
    }
Example #2
0
    public QuadTreeTerrainFace FindWesternNeighborOfGreaterOrEqualSize()
    {
        if (ParentFace == null)
        {
            return(null);
        }

        if (ParentFace.NorthEast == this)
        {
            return(ParentFace.NorthWest);
        }

        if (ParentFace.SouthEast == this)
        {
            return(ParentFace.SouthWest);
        }

        QuadTreeTerrainFace node = ParentFace.FindWesternNeighborOfGreaterOrEqualSize();

        if (node == null || !node.isDivided)
        {
            return(node);
        }

        return(ParentFace.NorthEast == this ? node.NorthWest : node.SouthWest);
    }
Example #3
0
    public IList <QuadTreeTerrainFace> FindWesternNeighbors()
    {
        QuadTreeTerrainFace         largerNeighbor = FindWesternNeighborOfGreaterOrEqualSize();
        IList <QuadTreeTerrainFace> neighbors      = FindWesternNeighborsOfSmallerSize(largerNeighbor);

        return(neighbors);
    }
Example #4
0
    public static QuadTreeTerrainFace Create(Transform parentTransform, string name, QuadTreeTerrainFace parent = null)
    {
        GameObject quadTreeRoot = new GameObject(name);

        quadTreeRoot.transform.parent   = parentTransform;
        quadTreeRoot.transform.position = Vector3.zero;

        QuadTreeTerrainFace face = quadTreeRoot.AddComponent <QuadTreeTerrainFace>();

        face.ParentFace = parent;
        return(face);
    }
Example #5
0
    private void Update()
    {
        // find the face that the camera is closest to
        float closestDistance           = float.MaxValue;
        QuadTreeTerrainFace closestFace = null;
        QuadTreeTerrainFace parentFace  = null;
        Vector3             position    = Camera.main.transform.position;

        foreach (QuadTreeTerrainFace face in quadTreeTerrainFaces)
        {
            QuadTreeTerrainFace currentClosestFace = face.FindClosestFace(position);
            float faceDistance = currentClosestFace.DistanceTo(position);
            if (faceDistance <= closestDistance)
            {
                closestFace     = currentClosestFace;
                parentFace      = face;
                closestDistance = faceDistance;
            }
        }

        //foreach (QuadTreeTerrainFace face in quadTreeTerrainFaces) {
        //  face.gameObject.SetActive(face == closestFace);
        //}

        Debug.Log(closestDistance);
        Debug.DrawLine(Camera.main.transform.position, closestFace.Mesh.bounds.ClosestPoint(Camera.main.transform.position), Color.red);

        int currentLevelOfDetail = 0;

        for (int i = 0; i < levelsOfDetail.Length; i++)
        {
            if (closestDistance < levelsOfDetail[i].startDistance)
            {
                currentLevelOfDetail = i;
            }
        }

        closestFace.SetLevelOfDetail(currentLevelOfDetail);

        GenerateMesh();
        GenerateColors();
    }
Example #6
0
    public void Initialize()
    {
        shapeGenerator.UpdateSettings(seed, shapeSettings);
        colorGenerator.UpdateSettings(seed, colorSettings);

        if (quadTreeTerrainFaces == null || quadTreeTerrainFaces.Length == 0)
        {
            quadTreeTerrainFaces = new QuadTreeTerrainFace[6];
        }

        Vector3[] directions = { Vector3.up, Vector3.down, Vector3.left, Vector3.right, Vector3.forward, Vector3.back };

        for (int i = 0; i < 6; i++)
        {
            if (quadTreeTerrainFaces[i] == null)
            {
                quadTreeTerrainFaces[i] = QuadTreeTerrainFace.Create(transform, "Mesh - " + i);
            }
            quadTreeTerrainFaces[i].Initialize(shapeGenerator, colorSettings, directions[i], resolution);

            bool renderFace = faceRenderMask == FaceRenderMask.All || (int)faceRenderMask - 1 == i;
            quadTreeTerrainFaces[i].gameObject.SetActive(renderFace);
        }
    }
Example #7
0
 public LODNode(QuadTreeTerrainFace face, int wantedLevelOfDetail)
 {
     Face = face;
     WantedLevelOfDetail = wantedLevelOfDetail;
 }