Example #1
0
    public static byte[] TileToVox(VTile tile)
    {
        List <byte> data = new List <byte>();

        Add(data, (byte)'V', (byte)'O', (byte)'X', (byte)' ');
        Add(data, System.BitConverter.GetBytes(150));
        Add(data, (byte)'M', (byte)'A', (byte)'I', (byte)'N');
        Add(data, System.BitConverter.GetBytes(0));
        int mainChildSizeIndex = data.Count;

        Add(data, (byte)'S', (byte)'I', (byte)'Z', (byte)'E');
        Add(data, System.BitConverter.GetBytes(12));
        Add(data, System.BitConverter.GetBytes(0));
        Add(data, System.BitConverter.GetBytes(tile.GetWidth()));
        Add(data, System.BitConverter.GetBytes(tile.GetHeight()));
        Add(data, System.BitConverter.GetBytes(tile.GetDepth()));
        Add(data, (byte)'X', (byte)'Y', (byte)'Z', (byte)'I');
        int xyziContentSizeIndex = data.Count;

        Add(data, System.BitConverter.GetBytes(0));
        int numVoxelsIndex = data.Count;
        int numVoxels      = 0;

        for (int x = 0; x < tile.GetWidth(); x++)
        {
            for (int y = 0; y < tile.GetHeight(); y++)
            {
                for (int z = 0; z < tile.GetDepth(); z++)
                {
                    int index = GetIndex(tile, x, y, z);
                    if (index != 0)
                    {
                        Add(data, (byte)x, (byte)(tile.GetHeight() - z - 1), (byte)y, (byte)(255 - index + 1));
                        numVoxels++;
                    }
                }
            }
        }
        data.InsertRange(numVoxelsIndex, System.BitConverter.GetBytes(numVoxels));
        data.InsertRange(xyziContentSizeIndex, System.BitConverter.GetBytes(data.Count - xyziContentSizeIndex - 4));
        Add(data, (byte)'R', (byte)'G', (byte)'B', (byte)'A');
        Add(data, System.BitConverter.GetBytes(256 * 4));
        Add(data, System.BitConverter.GetBytes(0));
        for (int i = 255; i >= 0; i--)
        {
            VColor c;
            if (i >= tile.GetPalette().GetCount())
            {
                c = new VColor(255, 0, 255, 255, 0, 0, 255, 0);
            }
            else
            {
                c = tile.GetPalette().GetColor(i);
            }
            Add(data, c.r, c.g, c.b, c.a);
        }
        data.InsertRange(mainChildSizeIndex, System.BitConverter.GetBytes(data.Count - mainChildSizeIndex));
        return(data.ToArray());
    }
Example #2
0
    void Awake()
    {
        use        = this;
        tile       = new VTile();
        refPalette = new VPalette();

        width  = tile.GetWidth();
        height = tile.GetHeight();
        depth  = tile.GetDepth();
    }
Example #3
0
    void LateUpdate()
    {
        VTile t = tile.GetTile();

        cachedVChunk = chunk;

        if (chunk.GetWidth() != t.GetWidth() ||
            chunk.GetHeight() != t.GetHeight() ||
            chunk.GetDepth() != t.GetDepth())
        {
            chunk.Resize(t.GetWidth(), t.GetHeight(), t.GetDepth());
        }

        if (GetChunk().IsDirty() || t.GetPalette().IsDirty())
        {
            Refresh();
        }

        mr.enabled = Tool.editing;
    }
Example #4
0
    public static Mesh TileToMesh(VTile tile)
    {
        Mesh mesh = new Mesh();

        v = 0;

        for (int x = 0; x < tile.GetWidth(); x++)
        {
            for (int y = 0; y < tile.GetHeight(); y++)
            {
                for (int z = 0; z < tile.GetDepth(); z++)
                {
                    VColor c = GetColor(tile, x, y, z);
                    if (GetColor(tile, x, y, z).a == 0)
                    {
                        continue;
                    }
                    Vector3 p = new Vector3(x, y, z);

                    bool useSubMesh = c.a < 255;

                    if (x == 0 || (GetColor(tile, x - 1, y, z).a < 255 && GetColor(tile, x - 1, y, z) != c))
                    {
                        verts.Add(p + new Vector3(0f, 0f, 1f));
                        verts.Add(p + new Vector3(0f, 1f, 1f));
                        verts.Add(p + new Vector3(0f, 1f, 0f));
                        verts.Add(p + new Vector3(0f, 0f, 0f));

                        AddFace(tile, x, y, z, Vector3.left, useSubMesh);
                    }
                    if (x == tile.GetWidth() - 1 || (GetColor(tile, x + 1, y, z).a < 255 && GetColor(tile, x + 1, y, z) != c))
                    {
                        verts.Add(p + new Vector3(1f, 0f, 0f));
                        verts.Add(p + new Vector3(1f, 1f, 0f));
                        verts.Add(p + new Vector3(1f, 1f, 1f));
                        verts.Add(p + new Vector3(1f, 0f, 1f));

                        AddFace(tile, x, y, z, Vector3.right, useSubMesh);
                    }
                    if (y == 0 || (GetColor(tile, x, y - 1, z).a < 255 && GetColor(tile, x, y - 1, z) != c))
                    {
                        verts.Add(p + new Vector3(1f, 0f, 0f));
                        verts.Add(p + new Vector3(1f, 0f, 1f));
                        verts.Add(p + new Vector3(0f, 0f, 1f));
                        verts.Add(p + new Vector3(0f, 0f, 0f));

                        AddFace(tile, x, y, z, Vector3.down, useSubMesh);
                    }
                    if (y == tile.GetHeight() - 1 || (GetColor(tile, x, y + 1, z).a < 255 && GetColor(tile, x, y + 1, z) != c))
                    {
                        verts.Add(p + new Vector3(0f, 1f, 0f));
                        verts.Add(p + new Vector3(0f, 1f, 1f));
                        verts.Add(p + new Vector3(1f, 1f, 1f));
                        verts.Add(p + new Vector3(1f, 1f, 0f));

                        AddFace(tile, x, y, z, Vector3.up, useSubMesh);
                    }
                    if (z == 0 || (GetColor(tile, x, y, z - 1).a < 255 && GetColor(tile, x, y, z - 1) != c))
                    {
                        verts.Add(p + new Vector3(0f, 0f, 0f));
                        verts.Add(p + new Vector3(0f, 1f, 0f));
                        verts.Add(p + new Vector3(1f, 1f, 0f));
                        verts.Add(p + new Vector3(1f, 0f, 0f));

                        AddFace(tile, x, y, z, Vector3.back, useSubMesh);
                    }
                    if (z == tile.GetDepth() - 1 || (GetColor(tile, x, y, z + 1).a < 255 && GetColor(tile, x, y, z + 1) != c))
                    {
                        verts.Add(p + new Vector3(1f, 0f, 1f));
                        verts.Add(p + new Vector3(1f, 1f, 1f));
                        verts.Add(p + new Vector3(0f, 1f, 1f));
                        verts.Add(p + new Vector3(0f, 0f, 1f));

                        AddFace(tile, x, y, z, Vector3.forward, useSubMesh);
                    }
                }
            }
        }

        mesh.vertices  = verts.ToArray();
        mesh.normals   = normals.ToArray();
        mesh.uv        = uvs.ToArray();
        mesh.triangles = tris.ToArray();

        mesh.RecalculateBounds();

        verts.Clear();
        normals.Clear();
        uvs.Clear();
        tris.Clear();

        return(mesh);
    }