public void GetMesh(int freeSides, GrowableMesh growableMesh, Vector3 position)
 {
     if ((freeSides & 63) == 0)
     {
         return;
     }
     if ((freeSides & 1) == 1)
     {
         growableMesh.AddMeshPiece(blockCoordinates[0], blockSides[0], colors[0], textureCoords[TextureID][0], position);
     }
     if ((freeSides & 2) == 2)
     {
         growableMesh.AddMeshPiece(blockCoordinates[1], blockSides[1], colors[1], textureCoords[TextureID][1], position);
     }
     if ((freeSides & 4) == 4)
     {
         growableMesh.AddMeshPiece(blockCoordinates[2], blockSides[2], colors[2], textureCoords[TextureID][2], position);
     }
     if ((freeSides & 8) == 8)
     {
         growableMesh.AddMeshPiece(blockCoordinates[3], blockSides[3], colors[3], textureCoords[TextureID][3], position);
     }
     if ((freeSides & 16) == 16)
     {
         growableMesh.AddMeshPiece(blockCoordinates[4], blockSides[4], colors[4], textureCoords[TextureID][4], position);
     }
     if ((freeSides & 32) == 32)
     {
         growableMesh.AddMeshPiece(blockCoordinates[5], blockSides[5], colors[5], textureCoords[TextureID][5], position);
     }
 }
Exemplo n.º 2
0
    void RefreshChunk()
    {
        test.Start();
        Global.statistics.ChunkRender();
        GrowableMesh growableMesh = new GrowableMesh();
        Vector3i     renderPosition;
        int          index = 0;

        for (int x = 0; x < chunkSize; x++)         //TODO: Multithread this
        {
            for (int y = 0; y < chunkSize; y++)     //TODO: For real do multithread this
            {
                for (int z = 0; z < chunkSize; z++)
                {
                    renderPosition = new Vector3i(x, y, z);
                    if (isNotNull[x, y, z])
                    {
                        int freeSides = world.GetFreeSides(renderPosition + (position << log2ChunkSize));
                        blocks[x, y, z].GetMesh(freeSides, growableMesh, new Vector3(x, y, z));
                    }
                }
            }
        }

        index += chunkSize;
        Mesh colliderMesh = new Mesh();

        colliderMesh.vertices   = growableMesh.GetVertices();
        colliderMesh.triangles  = growableMesh.GetIndices();
        meshCollider.sharedMesh = colliderMesh;
        Mesh mesh = new Mesh();

        mesh.vertices  = growableMesh.GetVertices();
        mesh.triangles = growableMesh.GetIndices();
        mesh.colors    = growableMesh.GetColors();
        mesh.uv        = growableMesh.GetUvs();
        mesh.RecalculateNormals();         //TODO: Add normals to block class
        meshFilter.mesh = mesh;
        test.Stop();
        Global.statistics.AddChunkRenderTime(test.ElapsedMilliseconds);
        if (test.ElapsedMilliseconds > 0)
        {
            UnityEngine.Debug.Log(test.ElapsedMilliseconds);
        }
        test.Reset();
    }