Beispiel #1
0
    //Inicializace

    private void initialization(ChunkFace parent, Vector3 position, float scale, Camera viewer, Vector4 directionX, Vector3 directionY, bool isVisible, int level)
    {
        this.parentChunk = parent;
        this.position    = position;
        this.scale       = scale;

        this.directionX = directionX;
        this.directionY = directionY;
        this.camera     = viewer;
        this.level      = level;

        this.isVisible = isVisible;
        chunkTree      = null;
        InitLists();
        generated = true;

        Vector3 newPosition = CalculePositionOfSphere(position);

        bounds         = new Bounds(newPosition, newPosition.normalized * scale);
        positionToDraw = new Vector4((position.x), (position.y), (position.z), scale);

        RecalculSteps();

        Update(viewer.transform.position, isVisible, position, scale);
    }
Beispiel #2
0
 // tohle je pouze apliková na kořenový uzel, kterému se dá reference na okolní stromy.
 public void UpdateTopNeighbor(ChunkFace[] topLevelneighbor)
 {
     topNeighbor    = topLevelneighbor[0];
     rightNeighbor  = topLevelneighbor[1];
     bottomNeighbor = topLevelneighbor[2];
     leftNeighbor   = topLevelneighbor[3];
 }
Beispiel #3
0
 private void GetActiveChunksFromChunkTree(ref List <ChunkFace> chunkFaceList, ChunkFace chunkTree)
 {
     if (chunkTree.getChunkTree() != null)
     {
         for (int i = 0; i < chunkTree.getChunkTree().Length; i++)
         {
             GetActiveChunksFromChunkTree(ref chunkFaceList, chunkTree.getChunkTree()[i]);
         }
     }
     else
     {
         chunkFaceList.Add(chunkTree);
     }
 }
    ///
    /// Inicializace vsech sest stromu a predani ukazetelu na sousednistormy
    ///

    private void createChunkFaces()
    {
        for (int i = 0; i < 6; i++)
        {
            chunkFace[i] = new ChunkFace(null, planetRadiusArray[i], this.scale, camera, directions[i], directionsY[i], true, i);
        }


        chunkFace[0].UpdateTopNeighbor(new ChunkFace[] { chunkFace[4], chunkFace[3], chunkFace[5], chunkFace[2] });
        chunkFace[1].UpdateTopNeighbor(new ChunkFace[] { chunkFace[4], chunkFace[2], chunkFace[5], chunkFace[3] });
        chunkFace[2].UpdateTopNeighbor(new ChunkFace[] { chunkFace[4], chunkFace[0], chunkFace[5], chunkFace[1] });
        chunkFace[3].UpdateTopNeighbor(new ChunkFace[] { chunkFace[4], chunkFace[1], chunkFace[5], chunkFace[0] });
        chunkFace[4].UpdateTopNeighbor(new ChunkFace[] { chunkFace[0], chunkFace[2], chunkFace[1], chunkFace[3] });
        chunkFace[5].UpdateTopNeighbor(new ChunkFace[] { chunkFace[0], chunkFace[2], chunkFace[1], chunkFace[3] });
    }
Beispiel #5
0
    public Chunk(float scale, int chunkSize, Material instanceMaterial, Transform viewer)
    {
        directions  = new Vector3[] { new Vector3(-1, 0, 0), new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, -1, 0), new Vector3(0, 0, 1), new Vector3(0, 0, -1) };
        directionsY = new Vector3[] { new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(1, 0, 0), new Vector3(1, 0, 0) };

        Vector3 axisA = new Vector3(directions[0].y, directions[0].z, directions[0].x);
        Vector3 axisB = Vector3.Cross(directions[0], axisA);


        this.scale     = scale;
        this.chunkSize = chunkSize;
        this.viewer    = viewer;

        planetRadius = (chunkSize - 1) * scale / 2;

        viewerPosition = viewer.position;
        chunkFace      = new ChunkFace[6];

        chunkFace[0] = new ChunkFace(null, new Vector3(0, 0, planetRadius), this.scale, (chunkSize - 1), viewerPosition, directions[0], directionsY[0]);
        chunkFace[1] = new ChunkFace(null, new Vector3(0, 0, -planetRadius), this.scale, (chunkSize - 1), viewerPosition, directions[1], directionsY[1]);
        chunkFace[2] = new ChunkFace(null, new Vector3(planetRadius, 0, 0), this.scale, (chunkSize - 1), viewerPosition, directions[2], directionsY[2]);
        chunkFace[3] = new ChunkFace(null, new Vector3(-planetRadius, 0, 0), this.scale, (chunkSize - 1), viewerPosition, directions[3], directionsY[3]);
        chunkFace[4] = new ChunkFace(null, new Vector3(0, planetRadius, 0), this.scale, (chunkSize - 1), viewerPosition, directions[4], directionsY[4]);
        chunkFace[5] = new ChunkFace(null, new Vector3(0, -planetRadius, 0), this.scale, (chunkSize - 1), viewerPosition, directions[5], directionsY[5]);


        meshData = MeshGenerator.GenerateTerrainMesh(chunkSize);
        meshData.CreateMesh();

        drawMesh = new DrawMesh(meshData.GetMesh(), instanceMaterial);

        for (int i = 0; i < test; i++)
        {
            positionsList.AddRange(chunkFace[i].GetPositionList());
            directionList.AddRange(chunkFace[i].GetDirectionList());
        }

        viewedChunkCoord = positionsList.ToArray();
        directionArray   = directionList.ToArray();

        drawMesh.UpdateData(positionsList.Count, viewedChunkCoord, directionArray);
        //  UpdateChunkMesh();
    }
Beispiel #6
0
    public ChunkFace(ChunkFace parent, Vector3 position, float scale, int chunkSize, Vector3 viewerPositon, Vector3 directionX, Vector3 directionY)
    {
        this.parentChunk = parent;
        this.position    = position;
        this.scale       = scale;
        this.chunkSize   = chunkSize;

        this.directionX = directionX;
        this.directionY = directionY;
        // this.position.y += radius;

        generated = true;

        bounds         = new Bounds(position, new Vector3(1, 0, 1) * chunkSize * scale);
        positionToDraw = new Vector4((position.x), (position.y), (position.z), scale);
        // this.position.y += radius;

        Update(viewerPositon);
    }
Beispiel #7
0
 public ChunkFace(ChunkFace parent, Vector3 position, float scale, Camera viewer, Vector4 directionX, Vector3 directionY, bool isVisible, int level)
 {
     initialization(parent, position, scale, viewer, directionX, directionY, isVisible, level);
 }
Beispiel #8
0
    //zde probíhá samotná aktualizace sousedu uzlu
    public void UpdateNeighbor(ChunkFace top, ChunkFace right, ChunkFace bottom, ChunkFace left)
    {
        // pokud je null, tak to znamená že uzel neprošel na test frustum culling a uzel se tedy o tohodle souseda nemusí zajímat
        if (top == null)
        {
            topNeighbor = null;
        }
        //Uzel je sesterským uzlem
        else if (top.level == level)
        {
            topNeighbor = top;
        }
        //pokud uzel dostane uzel, který ma úroven vyší tak to znamená že rodič nemá žádné informace o tom zda má uzel nějaké potomky proto pošele raději celý uzel, který si potomek zpracuje a najde si ze čtyř uzlů nejbližší uzel, který je jeho soused
        else if (top.chunkTree != null)
        {
            float distance    = 0;
            float oldDistance = 0;
            int   index       = 0;

            //prohledává potomky uzlu a hledá uzel, který je mu nejblíše
            for (int i = 0; i < 4; i++)
            {
                oldDistance = Vector3.Distance(bounds.center, top.chunkTree[i].bounds.center);
                if (i == 0 || oldDistance < distance)
                {
                    distance = oldDistance;
                    index    = i;
                }
            }

            topNeighbor = top.chunkTree[index];
        }
        else
        {
            topNeighbor = null;
        }


        //zde je to samé co nahoře
        if (right == null)
        {
            rightNeighbor = null;
        }
        else if (right.level == level)
        {
            rightNeighbor = right;
        }
        else if (right.chunkTree != null)
        {
            float distance    = 0;
            float oldDistance = 0;
            int   index       = 0;
            for (int i = 0; i < 4; i++)
            {
                oldDistance = Vector3.Distance(bounds.center, right.chunkTree[i].bounds.center);
                if (i == 0 || oldDistance <= distance)
                {
                    distance = oldDistance;
                    index    = i;
                }
            }

            rightNeighbor = right.chunkTree[index];
        }
        else
        {
            rightNeighbor = null;
        }

        if (bottom == null)
        {
            bottomNeighbor = null;
        }
        else if (bottom.level == level)
        {
            bottomNeighbor = bottom;
        }
        else if (bottom.chunkTree != null)
        {
            float distance    = 0;
            float oldDistance = 0;
            int   index       = 0;
            for (int i = 0; i < 4; i++)
            {
                oldDistance = Vector3.Distance(bounds.center, bottom.chunkTree[i].bounds.center);
                if (i == 0 || oldDistance < distance)
                {
                    distance = oldDistance;
                    index    = i;
                }
            }

            bottomNeighbor = bottom.chunkTree[index];
        }
        else
        {
            bottomNeighbor = null;
        }

        if (left == null)
        {
            leftNeighbor = null;
        }

        else if (left.level == level)
        {
            leftNeighbor = left;
        }
        else if (left.chunkTree != null)
        {
            float distance    = 0;
            float oldDistance = 0;
            int   index       = 0;
            for (int i = 0; i < 4; i++)
            {
                oldDistance = Vector3.Distance(bounds.center, left.chunkTree[i].bounds.center);
                if (i == 0 || oldDistance < distance)
                {
                    distance = oldDistance;
                    index    = i;
                }
            }

            leftNeighbor = left.chunkTree[index];
        }
        else
        {
            leftNeighbor = null;
        }
    }