void UpdateMeshData(Vector3 pos)
    {
        int x = Mathf.FloorToInt(pos.x);
        int y = Mathf.FloorToInt(pos.y);
        int z = Mathf.FloorToInt(pos.z);

        VoxelState voxel = chunkData.map[x, y, z];

        float rot = 0f;

        switch (voxel.orientation)
        {
        case 0:
            rot = 180f;
            break;

        case 5:
            rot = 270f;
            break;

        case 1:
            rot = 0f;
            break;

        default:
            rot = 90f;
            break;
        }

        for (int p = 0; p < 6; p++)
        {
            int translatedP = p;

            if (voxel.orientation != 1)
            {
                if (voxel.orientation == 0)
                {
                    if (p == 0)
                    {
                        translatedP = 1;
                    }
                    else if (p == 1)
                    {
                        translatedP = 0;
                    }
                    else if (p == 4)
                    {
                        translatedP = 5;
                    }
                    else if (p == 5)
                    {
                        translatedP = 4;
                    }
                }
                else if (voxel.orientation == 5)
                {
                    if (p == 0)
                    {
                        translatedP = 5;
                    }
                    else if (p == 1)
                    {
                        translatedP = 4;
                    }
                    else if (p == 4)
                    {
                        translatedP = 0;
                    }
                    else if (p == 5)
                    {
                        translatedP = 1;
                    }
                }
                else if (voxel.orientation == 4)
                {
                    if (p == 0)
                    {
                        translatedP = 4;
                    }
                    else if (p == 1)
                    {
                        translatedP = 5;
                    }
                    else if (p == 4)
                    {
                        translatedP = 1;
                    }
                    else if (p == 5)
                    {
                        translatedP = 0;
                    }
                }
            }

            VoxelState neighbour = chunkData.map[x, y, z].neighbours[translatedP];

            if (neighbour != null && neighbour.properties.renderNeighborFaces && !(voxel.properties.isWater && chunkData.map[x, y + 1, z].properties.isWater))
            {
                float lightLevel    = neighbour.lightAsFloat;
                int   faceVertCount = 0;

                for (int i = 0; i < voxel.properties.meshData.faces[p].vertData.Length; i++)
                {
                    VertData vertData = voxel.properties.meshData.faces[p].GetVertData(i);
                    vertices.Add(pos + vertData.GetRotatedPosition(new Vector3(0, rot, 0)));
                    normals.Add(VoxelData.faceChecks[p]);
                    colors.Add(new Color(0, 0, 0, lightLevel));
                    if (voxel.properties.isWater)
                    {
                        uvs.Add(voxel.properties.meshData.faces[p].vertData[i].uv);
                    }
                    else
                    {
                        AddTexture(voxel.properties.GetTextureID(p), vertData.uv);
                    }
                    faceVertCount++;
                }

                if (!voxel.properties.renderNeighborFaces)
                {
                    for (int i = 0; i < voxel.properties.meshData.faces[p].triangles.Length; i++)
                    {
                        triangles.Add(vertexIndex + voxel.properties.meshData.faces[p].triangles[i]);
                    }
                }
                else
                {
                    if (voxel.properties.isWater)
                    {
                        for (int i = 0; i < voxel.properties.meshData.faces[p].triangles.Length; i++)
                        {
                            waterTriangles.Add(vertexIndex + voxel.properties.meshData.faces[p].triangles[i]);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < voxel.properties.meshData.faces[p].triangles.Length; i++)
                        {
                            transparentTriangles.Add(vertexIndex + voxel.properties.meshData.faces[p].triangles[i]);
                        }
                    }
                }

                vertexIndex += faceVertCount;
            }
        }
    }
Пример #2
0
    void UpdateMeshData(Vector3 pos)
    {
        int x = Mathf.FloorToInt(pos.x);
        int y = Mathf.FloorToInt(pos.y);
        int z = Mathf.FloorToInt(pos.z);

        byte       blockID = chunkData.map[x, y, z].id;
        VoxelState voxel   = chunkData.map[x, y, z];

        float rotation = 0;

        switch (chunkData.map[x, y, z].orientation)
        {
        case 0:
            rotation = 180f;
            break;

        case 5:
            rotation = 270f;
            break;

        case 1:
            rotation = 0f;
            break;

        default:
            rotation = 90f;
            break;
        }

        for (int p = 0; p < 6; p++)
        {
            int translatedP = p;
            if (voxel.orientation != 1)
            {
                if (voxel.orientation == 0)
                {
                    if (p == 0)
                    {
                        translatedP = 1;
                    }
                    else if (p == 1)
                    {
                        translatedP = 0;
                    }
                    else if (p == 4)
                    {
                        translatedP = 5;
                    }
                    else if (p == 5)
                    {
                        translatedP = 4;
                    }
                }
                else if (voxel.orientation == 5)
                {
                    if (p == 0)
                    {
                        translatedP = 5;
                    }
                    else if (p == 1)
                    {
                        translatedP = 4;
                    }
                    else if (p == 4)
                    {
                        translatedP = 0;
                    }
                    else if (p == 5)
                    {
                        translatedP = 1;
                    }
                }
                else if (voxel.orientation == 4)
                {
                    if (p == 0)
                    {
                        translatedP = 4;
                    }
                    else if (p == 1)
                    {
                        translatedP = 5;
                    }
                    else if (p == 4)
                    {
                        translatedP = 1;
                    }
                    else if (p == 5)
                    {
                        translatedP = 0;
                    }
                }
            }

            VoxelState neighbor = CheckVoxel(pos + VoxelData.faceChecks[translatedP]);

            if (neighbor != null && World.Instance.blocktypes[neighbor.id].renderNeighborFaces)
            {
                int faceVertCount = 0;

                for (int i = 0; i < World.Instance.blocktypes[blockID].meshData.faces[p].vertData.Length; i++)
                {
                    VertData vertData = World.Instance.blocktypes[blockID].meshData.faces[p].GetVertData(i);
                    vertices.Add(pos + vertData.GetRotatedPosition(new Vector3(0, rotation, 0)));
                    normals.Add(VoxelData.faceChecks[p]);
                    colors.Add(new Color(0, 0, 0, 255));
                    AddTexture(World.Instance.blocktypes[blockID].GetTextureID(p), vertData.uv);
                    faceVertCount++;
                }

                if (!World.Instance.blocktypes[blockID].renderNeighborFaces)
                {
                    for (int i = 0; i < World.Instance.blocktypes[blockID].meshData.faces[p].triangles.Length; i++)
                    {
                        triangles.Add(vertexIndex + World.Instance.blocktypes[blockID].meshData.faces[p].triangles[i]);
                    }
                }
                else
                {
                    for (int i = 0; i < World.Instance.blocktypes[blockID].meshData.faces[p].triangles.Length; i++)
                    {
                        transparentTriangles.Add(vertexIndex + World.Instance.blocktypes[blockID].meshData.faces[p].triangles[i]);
                    }
                }

                vertexIndex += faceVertCount;
            }
        }
    }