コード例 #1
0
ファイル: Edit.cs プロジェクト: Hawkbat/Reptile
    void Awake()
    {
        use        = this;
        tile       = new VTile();
        refPalette = new VPalette();

        width  = tile.GetWidth();
        height = tile.GetHeight();
        depth  = tile.GetDepth();
    }
コード例 #2
0
ファイル: ExportUtil.cs プロジェクト: Hawkbat/Reptile
    public static byte[] PaletteToPng(VPalette pal)
    {
        Texture2D tex = new Texture2D(256, 1, TextureFormat.ARGB32, false);

        for (int i = 0; i < pal.GetCount(); i++)
        {
            VColor c = pal.GetColor(i);
            tex.SetPixel(i, 0, new Color32(c.r, c.g, c.b, c.a));
        }
        tex.Apply();
        return(tex.EncodeToPNG());
    }
コード例 #3
0
    void Palette()
    {
        GUILayout.BeginVertical("box", GUILayout.Width(145));
        showPalette = GUILayout.Toggle(showPalette, "Palette", "boxhead");
        int      index   = ed.tile.GetPalette().GetIndex();
        VPalette palette = Edit.use.tile.GetPalette();

        if (showPalette)
        {
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Load"))
            {
                string path = TinyFileDialogs.OpenFileDialog("Load Palette", Edit.GetDirectory(), new[] { "*.rpal" }, "Reptile Palettes (*.rpal)", false);
                if (!string.IsNullOrEmpty(path))
                {
                    actQueue.Enqueue(new LoadPaletteAct(System.IO.File.ReadAllBytes(path)));
                }
            }
            if (GUILayout.Button("Save"))
            {
                string path = TinyFileDialogs.SaveFileDialog("Save Palette", Edit.GetDirectory(), new[] { "*.rpal" }, "Reptile Palettes (*.rpal)");
                if (!string.IsNullOrEmpty(path))
                {
                    if (!path.Contains("."))
                    {
                        path += ".rpal";
                    }
                    System.IO.File.WriteAllBytes(path, new BinaryWriter(palette).GetOutput());
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            if (palette.GetCount() > 1 && GUILayout.Button("-", GUILayout.Width(25)))
            {
                actQueue.Enqueue(new RemovePaletteColorAct());
            }
            GUILayout.FlexibleSpace();
            if (palette.GetCount() < 256 && GUILayout.Button("+", GUILayout.Width(25)))
            {
                actQueue.Enqueue(new AddPaletteColorAct(new VColor(255, 255, 255, 255)));
            }
            GUILayout.EndHorizontal();
            palScroll = GUILayout.BeginScrollView(palScroll);
            for (int i = 0; i < palette.GetCount(); i++)
            {
                if (i % 4 == 0)
                {
                    if (i > 0)
                    {
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.BeginHorizontal();
                }
                VColor c = palette.GetColor(i);
                index = Swatch(i == index, new Color32(c.r, c.g, c.b, c.a)) ? i : index;
            }
            GUILayout.EndHorizontal();
            GUILayout.EndScrollView();
        }
        GUILayout.EndVertical();
        if (repaint)
        {
            boxRects.Add(GUILayoutUtility.GetLastRect());
        }

        if (index != ed.tile.GetPalette().GetIndex())
        {
            actQueue.Enqueue(new ChangePaletteIndexAct(index));
        }
    }
コード例 #4
0
ファイル: ExportUtil.cs プロジェクト: Hawkbat/Reptile
    public static VTile VoxToTile(byte[] vox)
    {
        VTile tile = new VTile();

        VPalette pal = tile.GetPalette();

        for (int j = 0; j < 256; j++)
        {
            byte[] bits = System.BitConverter.GetBytes(vox_default_palette[j]);
            VColor c    = new VColor(bits[0], bits[1], bits[2], bits[3]);
            if (j >= pal.GetCount())
            {
                pal.AddColor(c);
            }
            else
            {
                pal.SetColor(j, c);
            }
        }

        int    i     = 0;
        string chunk = "" + (char)vox[i + 0] + (char)vox[i + 1] + (char)vox[i + 2] + (char)vox[i + 3];

        i += 4;
        if (chunk != "VOX ")
        {
            throw new System.Exception("Invalid VOX file");
        }
        int version = System.BitConverter.ToInt32(vox, i);

        i += 4;
        if (version != 150)
        {
            throw new System.Exception("Unsupported VOX version (expected 150, got " + version + ")");
        }

        while (i < vox.Length)
        {
            chunk = "" + (char)vox[i + 0] + (char)vox[i + 1] + (char)vox[i + 2] + (char)vox[i + 3];
            i    += 4;
            int contentLength = System.BitConverter.ToInt32(vox, i);
            i += 4;
            //int childrenLength = System.BitConverter.ToInt32(vox, i);
            i += 4;
            if (chunk == "MAIN")
            {
            }
            else if (chunk == "PACK")
            {
                int numModels = System.BitConverter.ToInt32(vox, i);
                i += 4;
                if (numModels > 1)
                {
                    throw new System.Exception("Unsupported VOX feature (cannot read multi-model pack files)");
                }
            }
            else if (chunk == "SIZE")
            {
                int x = System.BitConverter.ToInt32(vox, i);
                i += 4;
                int y = System.BitConverter.ToInt32(vox, i);
                i += 4;
                int z = System.BitConverter.ToInt32(vox, i);
                i += 4;
                tile.Resize(x, z, y);
            }
            else if (chunk == "XYZI")
            {
                int count = System.BitConverter.ToInt32(vox, i);
                i += 4;
                for (int j = 0; j < count; j++)
                {
                    byte x = vox[i + 0];
                    byte y = vox[i + 1];
                    byte z = vox[i + 2];
                    byte c = vox[i + 3];
                    tile.GetChunk(0, 0, 0).SetPaletteIndexAt(x, z, tile.GetDepth() - y - 1, (byte)(255 - c + 1));
                    i += 4;
                }
            }
            else if (chunk == "RGBA")
            {
                for (int j = 0; j < 256; j++)
                {
                    VColor c = new VColor(vox[i + 0], vox[i + 1], vox[i + 2], vox[i + 3]);
                    i += 4;
                    // Palette color 0 is always transparent
                    if (j == 255)
                    {
                        c.a = 0;
                    }
                    if (j >= pal.GetCount())
                    {
                        pal.AddColor(c);
                    }
                    else
                    {
                        pal.SetColor(255 - j, c);
                    }
                }
            }
            else
            {
                i += contentLength;
            }
        }

        return(tile);
    }