Пример #1
0
        public void CleanLastVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, Dictionary <double, VoxelUndoData> modifiedVoxels)
        {
            VoxelUndoData removed = new VoxelUndoData();

            for (int z = volume.minz; z <= volume.maxz; z++)
            {
                for (int y = volume.miny; y <= volume.maxy; y++)
                {
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        if (!currentVolume.ContainsPoint(x, y, z))
                        {
                            if (modifiedVoxels.TryGetValue(matrix.GetHash(x, y, z), out removed))
                            {
                                if (removed.alphamask > 1)
                                {
                                    matrix.Add(x, y, z, matrix.colors[removed.colorindex]);
                                }
                                modifiedVoxels.Remove(matrix.GetHash(x, y, z));
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        public void RemoveVolume(VoxelVolume volume, QbMatrix matrix, Dictionary <double, VoxelUndoData> modifiedVoxels)
        {
            VoxelUndoData _temp;

            for (int z = volume.minz; z <= volume.maxz; z++)
            {
                for (int y = volume.miny; y <= volume.maxy; y++)
                {
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        if (modifiedVoxels.TryGetValue(matrix.GetHash(x, y, z), out _temp) && _temp.changed)
                        {
                            matrix.Remove(x, y, z, false, false);
                            modifiedVoxels.Remove(matrix.GetHash(x, y, z));
                        }
                    }
                }
            }
        }
Пример #3
0
 public void CleanLastVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, Dictionary <double, VoxelUndoData> modifiedVoxels)
 {
     for (int z = volume.minz; z <= volume.maxz; z++)
     {
         for (int y = volume.miny; y <= volume.maxy; y++)
         {
             for (int x = volume.minx; x <= volume.maxx; x++)
             {
                 if (!currentVolume.ContainsPoint(x, y, z))
                 {
                     if (modifiedVoxels[matrix.GetHash(x, y, z)].changed)
                     {
                         matrix.Remove(x, y, z, false, false);
                         modifiedVoxels.Remove(matrix.GetHash(x, y, z));
                     }
                 }
             }
         }
     }
 }
Пример #4
0
        public void AddVolume(VoxelVolume volume, QbMatrix matrix, ref Colort color, Dictionary <double, VoxelUndoData> modifiedVoxels)
        {
            VoxelUndoData removed = new VoxelUndoData();

            for (int z = volume.minz; z <= volume.maxz; z++)
            {
                for (int y = volume.miny; y <= volume.maxy; y++)
                {
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        if (!modifiedVoxels.ContainsKey(matrix.GetHash(x, y, z)))
                        {
                            if (matrix.GetColorIndex_Alphamask(x, y, z, out removed.colorindex, out removed.alphamask))
                            {
                                if (matrix.Remove(x, y, z, true, false))
                                {
                                    modifiedVoxels.Add(matrix.GetHash(x, y, z), removed);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #5
0
 public void EnumerateVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, ref Colort color, Dictionary <double, VoxelUndoData> modifiedVoxels)
 {
     for (int z = currentVolume.minz; z <= currentVolume.maxz; z++)
     {
         for (int y = currentVolume.miny; y <= currentVolume.maxy; y++)
         {
             for (int x = currentVolume.minx; x <= currentVolume.maxx; x++)
             {
                 if (!volume.ContainsPoint(x, y, z) && !modifiedVoxels.ContainsKey(matrix.GetHash(x, y, z)))
                 {
                     modifiedVoxels.Add(matrix.GetHash(x, y, z), new VoxelUndoData(matrix.Add(x, y, z, color)));
                 }
             }
         }
     }
 }
Пример #6
0
        public void AddVolume(VoxelVolume volume, QbMatrix matrix, ref Colort color, Dictionary <double, VoxelUndoData> modifiedVoxels)
        {
            double hash;

            for (int z = volume.minz; z <= volume.maxz; z++)
            {
                for (int y = volume.miny; y <= volume.maxy; y++)
                {
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        hash = matrix.GetHash(x, y, z);
                        if (!modifiedVoxels.ContainsKey(hash))
                        {
                            modifiedVoxels.Add(hash, new VoxelUndoData(matrix.Add(x, y, z, color)));
                        }
                    }
                }
            }
        }
Пример #7
0
        public void RemoveVolume(VoxelVolume volume, QbMatrix matrix, Dictionary <double, VoxelUndoData> modifiedVoxels)
        {
            double        hash;
            VoxelUndoData voxel = new VoxelUndoData();

            for (int z = volume.minz; z <= volume.maxz; z++)
            {
                for (int y = volume.miny; y <= volume.maxy; y++)
                {
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        hash = matrix.GetHash(x, y, z);
                        if (modifiedVoxels.TryGetValue(hash, out voxel))
                        {
                            matrix.Color(x, y, z, voxel.colorindex, false, true);
                            modifiedVoxels.Remove(hash);
                        }
                    }
                }
            }
        }
Пример #8
0
        public void AddVolume(VoxelVolume volume, QbMatrix matrix, ref Colort color, Dictionary <double, VoxelUndoData> modifiedVoxels)
        {
            double hash;
            Voxel  voxel = null;

            for (int z = volume.minz; z <= volume.maxz; z++)
            {
                for (int y = volume.miny; y <= volume.maxy; y++)
                {
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        hash = matrix.GetHash(x, y, z);

                        if (!modifiedVoxels.ContainsKey(hash) && matrix.voxels.TryGetValue(hash, out voxel) && voxel.alphamask > 1)
                        {
                            modifiedVoxels.Add(hash, new VoxelUndoData(matrix.voxels[hash].colorindex, 0));
                            matrix.Color(x, y, z, color);
                        }
                    }
                }
            }
        }
Пример #9
0
        public void write(string path, string name, QbModel model)
        {
            string fullpath = Path.Combine(path, name + extension);

            using (FileStream f = new FileStream(fullpath, FileMode.OpenOrCreate))
            {
                using (BinaryWriter w = new BinaryWriter(f))
                {
                    w.Write(model.version);
                    w.Write(model.colorFormat);
                    w.Write(model.zAxisOrientation);
                    w.Write(model.compressed);
                    w.Write(model.visibilityMaskEncoded);

                    w.Write((uint)model.matrices.Count);

                    for (int i = 0; i < model.numMatrices; i++)
                    {
                        QbMatrix m = model.matrices[i];
                        if (!m.Visible)
                        {
                            continue;
                        }

                        int startx = Math.Min(0, m.minx);
                        int starty = Math.Min(0, m.miny);
                        int startz = Math.Min(0, m.minz);

                        int width  = (int)(Math.Abs(Math.Min(0, m.minx)) + m.maxx + 1);
                        int height = (int)(Math.Abs(Math.Min(0, m.miny)) + m.maxy + 1);
                        int length = (int)(Math.Abs(Math.Min(0, m.minz)) + m.maxz + 1);

                        if (width < m.size.X)
                        {
                            width = (int)m.size.X;
                        }

                        if (height < m.size.Y)
                        {
                            height = (int)m.size.Y;
                        }

                        if (length < m.size.Z)
                        {
                            length = (int)m.size.Z;
                        }

                        w.Write(m.name);
                        w.Write((uint)width);
                        w.Write((uint)height);
                        w.Write((uint)length);

                        w.Write((int)m.position.X);
                        w.Write((int)m.position.Y);
                        w.Write((int)m.position.Z);

                        if (model.compressed == 0)
                        {
                            Voxel voxel;
                            for (int z = startz; z < startz + length; z++)
                            {
                                for (int y = starty; y < starty + height; y++)
                                {
                                    for (int x = startx; x < startx + width; x++)
                                    {
                                        int zz = model.zAxisOrientation == (int)0 ? z : (int)(length - z - 1);

                                        if (m.voxels.TryGetValue(m.GetHash(x, y, zz), out voxel))
                                        {
                                            Colort c = m.colors[voxel.colorindex];

                                            int r = (int)(c.R * 255f);
                                            int g = (int)(c.G * 255f);
                                            int b = (int)(c.B * 255f);

                                            w.Write((byte)r);
                                            w.Write((byte)g);
                                            w.Write((byte)b);
                                            w.Write(voxel.alphamask);
                                        }
                                        else
                                        {
                                            w.Write((byte)0);
                                            w.Write((byte)0);
                                            w.Write((byte)0);
                                            w.Write((byte)0);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #10
0
        public QbModel _read(string path)
        {
            QbModel model = new QbModel(path.Split('\\').Last().Split('.').First());

            using (FileStream f = new FileStream(path, FileMode.Open))
                using (BinaryReader reader = new BinaryReader(f))
                {
                    int version = reader.ReadInt32();
                    int len     = reader.ReadInt32();
                    reader.ReadBytes(len);

                    int colorpalleteflag = reader.ReadInt32();

                    for (int i = 0; i < 10; i++)
                    {
                        var colorpal = Singleton <GUI> .INSTANCE.Get <EmptyWidget>(GUIID.START_COLOR_SELECTORS + i);

                        var c = colorpal.appearence.Get <PlainBackground>("background");
                        c.color.R = reader.ReadSingle();
                        c.color.G = reader.ReadSingle();
                        c.color.B = reader.ReadSingle();

                        bool e = (bool)colorpal.customData["active"];
                        if (e)
                        {
                            Singleton <Broadcaster> .INSTANCE.Broadcast(Message.ColorSelectionChanged, colorpal, c.color);
                        }
                    }

                    model.version               = reader.ReadUInt32();
                    model.colorFormat           = reader.ReadUInt32();
                    model.zAxisOrientation      = reader.ReadUInt32();
                    model.compressed            = reader.ReadUInt32();
                    model.visibilityMaskEncoded = reader.ReadUInt32();
                    model.setmatrixcount(reader.ReadUInt32());

                    for (int i = 0; i < model.numMatrices; i++)
                    {
                        QbMatrix m = model.matrices[i];

                        byte l = reader.ReadByte();
                        m.name = System.Text.Encoding.Default.GetString(reader.ReadBytes(l));
                        m.setsize((int)reader.ReadUInt32(), (int)reader.ReadUInt32(), (int)reader.ReadUInt32());
                        m.position = new OpenTK.Vector3(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());

                        byte r;
                        byte g;
                        byte b;
                        byte a;
                        int  zz;

                        if (model.compressed == 0)
                        {
                            for (int z = 0; z < m.size.Z; z++)
                            {
                                for (int y = 0; y < m.size.Y; y++)
                                {
                                    for (int x = 0; x < m.size.X; x++)
                                    {
                                        r  = reader.ReadByte();
                                        g  = reader.ReadByte();
                                        b  = reader.ReadByte();
                                        a  = reader.ReadByte();
                                        zz = model.zAxisOrientation == (int)0 ? z : (int)(m.size.Z - z - 1);

                                        if (a != 0)
                                        {
                                            m.voxels.GetOrAdd(m.GetHash(x, y, zz), new Voxel(x, y, zz, a, m.getcolorindex(r, g, b, model.colorFormat)));
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (int z = 0; z < m.size.Z; z++)
                            {
                                zz = model.zAxisOrientation == 0 ? z : (int)m.size.Z - z - 1;
                                int index = 0;
                                while (true)
                                {
                                    r = reader.ReadByte();
                                    g = reader.ReadByte();
                                    b = reader.ReadByte();
                                    a = reader.ReadByte();
                                    if (r == 6 && g == 0 && b == 0 && a == 0) // NEXTSLICEFLAG
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        if (r == 2 && g == 0 && b == 0 && a == 0) //CODEFLAG
                                        {
                                            uint count = reader.ReadUInt32();
                                            r = reader.ReadByte();
                                            g = reader.ReadByte();
                                            b = reader.ReadByte();
                                            a = reader.ReadByte();
                                            if (a != 0)
                                            {
                                                for (int j = 0; j < count; j++)
                                                {
                                                    int x = index % (int)m.size.X;
                                                    int y = index / (int)m.size.X;
                                                    index++;
                                                    m.voxels.GetOrAdd(m.GetHash(x, y, zz), new Voxel(x, y, zz, a, m.getcolorindex(r, g, b, model.colorFormat)));
                                                }
                                            }
                                            else
                                            {
                                                index += (int)count;
                                            }
                                        }
                                        else
                                        {
                                            int x = index % (int)m.size.X;
                                            int y = index / (int)m.size.X;
                                            index++;
                                            if (a != 0)
                                            {
                                                m.voxels.GetOrAdd(m.GetHash(x, y, zz), new Voxel(x, y, zz, a, m.getcolorindex(r, g, b, model.colorFormat)));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            return(model);
        }
Пример #11
0
        public void AddVolume(VoxelVolume volume, QbMatrix matrix, ref Colort color, Dictionary<double, VoxelUndoData> modifiedVoxels)
        {
            VoxelUndoData removed = new VoxelUndoData();

            for (int z = volume.minz; z <= volume.maxz; z++)
                for (int y = volume.miny; y <= volume.maxy; y++)
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        if (!modifiedVoxels.ContainsKey(matrix.GetHash(x, y, z)))
                        {
                            if (matrix.GetColorIndex_Alphamask(x, y, z, out removed.colorindex, out removed.alphamask))
                            {
                                if (matrix.Remove(x, y, z, true, false))
                                    modifiedVoxels.Add(matrix.GetHash(x, y, z), removed);
                            }
                        }
                    }
        }
Пример #12
0
        public void RemoveVolume(VoxelVolume volume, QbMatrix matrix, Dictionary<double, VoxelUndoData> modifiedVoxels)
        {
            VoxelUndoData removed = new VoxelUndoData();

            for (int z = volume.minz; z <= volume.maxz; z++)
                for (int y = volume.miny; y <= volume.maxy; y++)
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        if (modifiedVoxels.TryGetValue(matrix.GetHash(x, y, z), out removed))
                        {
                            if (removed.alphamask > 1)
                                matrix.Add(x, y, z, matrix.colors[removed.colorindex]);
                            modifiedVoxels.Remove(matrix.GetHash(x, y, z));
                        }
                    }
        }
Пример #13
0
 public void CleanLastVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
     for (int z = volume.minz; z <= volume.maxz; z++)
         for (int y = volume.miny; y <= volume.maxy; y++)
             for (int x = volume.minx; x <= volume.maxx; x++)
             {
                 if (!currentVolume.ContainsPoint(x, y, z))
                 {
                     if (modifiedVoxels[matrix.GetHash(x, y, z)].changed)
                     {
                         matrix.Remove(x, y, z, false, false);
                         modifiedVoxels.Remove(matrix.GetHash(x, y, z));
                     }
                 }
             }
 }
Пример #14
0
        public void write(string path, string name, QbModel model)
        {
            Client.OpenGLContextThread.Add(() =>
            {
                int Wwidth  = Client.window.Width;
                int Wheight = Client.window.Height;

                int framebuffer = GL.GenBuffer();
                GL.BindFramebuffer(FramebufferTarget.FramebufferExt, framebuffer);

                int color = GL.GenTexture();
                GL.BindTexture(TextureTarget.Texture2D, color);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, Wwidth, Wheight, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
                GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, color, 0);

                int depth = GL.GenTexture();
                GL.BindTexture(TextureTarget.Texture2D, depth);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.DepthComponent24, Wwidth, Wheight, 0, PixelFormat.DepthComponent, PixelType.UnsignedByte, IntPtr.Zero);
                GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, TextureTarget.Texture2D, depth, 0);

                GL.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);

                GL.BindFramebuffer(FramebufferTarget.FramebufferExt, framebuffer);
                GL.DrawBuffers(1, new DrawBuffersEnum[] { DrawBuffersEnum.ColorAttachment0 });

                GL.ClearColor(0, 0, 0, 0);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                int minx  = 10000;
                int miny  = 10000;
                int minz  = 10000;
                int maxx  = 0;
                int maxy  = 0;
                int maxz  = 0;
                int sizex = 0;
                int sizey = 0;
                int sizez = 0;

                foreach (var matrix in model.matrices)
                {
                    if (!matrix.Visible)
                    {
                        continue;
                    }
                    if (matrix.minx < minx)
                    {
                        minx = matrix.minx;
                    }
                    if (matrix.maxx > maxx)
                    {
                        maxx = matrix.maxx;
                    }

                    if (matrix.miny < miny)
                    {
                        miny = matrix.miny;
                    }
                    if (matrix.maxy > maxy)
                    {
                        maxy = matrix.maxy;
                    }

                    if (matrix.minz < minz)
                    {
                        minz = matrix.minz;
                    }
                    if (matrix.maxz > maxz)
                    {
                        maxz = matrix.maxz;
                    }
                }

                sizex = maxx - minx;
                sizey = maxy - miny;
                sizez = maxz - minz;

                float backup = 0;

                if (sizey * 1.5f > 20)
                {
                    backup = sizey * 1.5f;
                }
                else if (sizex * 1.5f > 20)
                {
                    backup = sizex * 1.5f;
                }
                else
                {
                    backup = 20;
                }

                var centerpos = new Vector3((minx + ((maxx - minx) / 2)), (miny + ((maxy - miny) / 2)), (minz + ((maxz - minz) / 2)));
                var position  = centerpos + new Vector3(.5f, sizey * .65f, backup);
                Vector3 direction;

                Vector3.Subtract(ref centerpos, ref position, out direction);
                direction.Normalize();

                var cameraright = Vector3.Cross(direction, VectorUtils.UP);
                var cameraup    = Vector3.Cross(cameraright, direction);

                var view = Matrix4.LookAt(position, position + direction, cameraup);
                var modelviewprojection = view * Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(45), (float)Wwidth / (float)Wheight, 1, 300);

                Shader voxelShader = ShaderUtil.GetShader("qb");

                voxelShader.UseShader();
                voxelShader.WriteUniform("modelview", modelviewprojection);

                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                model.RenderAll(voxelShader);

                string fullpath = Path.Combine(path, name + extension);
                using (FileStream f = new FileStream(fullpath, FileMode.OpenOrCreate))
                {
                    var bit       = Screenshot.ScreenShot(ReadBufferMode.ColorAttachment0);
                    bit           = cropImage(bit, new Rectangle(Wwidth / 4, 0, Wwidth - ((Wwidth / 4) * 2), Wheight));
                    bit           = bit.ResizeImage(ResizeKeepAspect(bit.Size, 400, 400));
                    byte[] buffer = new byte[0];
                    using (MemoryStream m = new MemoryStream())
                    {
                        bit.Save(m, System.Drawing.Imaging.ImageFormat.Png);
                        buffer = m.ToArray();
                    }

                    using (BinaryWriter w = new BinaryWriter(f))
                    {
                        w.Write(version);
                        w.Write((int)buffer.Length);
                        w.Write(buffer);

                        // note - just in case i allow extending the color pattet
                        // which i probably will
                        w.Write(colorpalletflag);
                        for (int i = 0; i < 10; i++)
                        {
                            var c = Singleton <GUI> .INSTANCE.Get <EmptyWidget>(GUIID.START_COLOR_SELECTORS + i).appearence.Get <PlainBackground>("background").color;
                            w.Write(c.R);
                            w.Write(c.G);
                            w.Write(c.B);
                        }

                        w.Write(model.version);
                        w.Write(model.colorFormat);
                        w.Write(model.zAxisOrientation);
                        w.Write(model.compressed);
                        w.Write(model.visibilityMaskEncoded);

                        w.Write((uint)model.matrices.Count);

                        for (int i = 0; i < model.numMatrices; i++)
                        {
                            QbMatrix m = model.matrices[i];
                            if (!m.Visible)
                            {
                                continue;
                            }

                            int startx = Math.Min(0, m.minx);
                            int starty = Math.Min(0, m.miny);
                            int startz = Math.Min(0, m.minz);

                            int width  = (int)(Math.Abs(Math.Min(0, m.minx)) + m.maxx + 1);
                            int height = (int)(Math.Abs(Math.Min(0, m.miny)) + m.maxy + 1);
                            int length = (int)(Math.Abs(Math.Min(0, m.minz)) + m.maxz + 1);

                            if (width < m.size.X)
                            {
                                width = (int)m.size.X;
                            }

                            if (height < m.size.Y)
                            {
                                height = (int)m.size.Y;
                            }

                            if (length < m.size.Z)
                            {
                                length = (int)m.size.Z;
                            }

                            w.Write(m.name);
                            w.Write((uint)width);
                            w.Write((uint)height);
                            w.Write((uint)length);

                            w.Write((int)m.position.X);
                            w.Write((int)m.position.Y);
                            w.Write((int)m.position.Z);

                            if (model.compressed == 0)
                            {
                                Voxel voxel;
                                for (int z = startz; z < startz + length; z++)
                                {
                                    for (int y = starty; y < starty + height; y++)
                                    {
                                        for (int x = startx; x < startx + width; x++)
                                        {
                                            int zz = model.zAxisOrientation == (int)0 ? z : (int)(length - z - 1);

                                            if (m.voxels.TryGetValue(m.GetHash(x, y, zz), out voxel))
                                            {
                                                Colort c = m.colors[voxel.colorindex];
                                                w.Write((byte)(c.R * 255));
                                                w.Write((byte)(c.G * 255));
                                                w.Write((byte)(c.B * 255));
                                                w.Write(voxel.alphamask);
                                            }
                                            else
                                            {
                                                w.Write((byte)0);
                                                w.Write((byte)0);
                                                w.Write((byte)0);
                                                w.Write((byte)0);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    GL.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
                    GL.DeleteTexture(color);
                    GL.DeleteTexture(depth);
                    GL.DeleteFramebuffer(framebuffer);
                }
            });
        }
Пример #15
0
        public QbModel _read(string path)
        {
            QbModel model = new QbModel(path.Split('\\').Last().Split('.').First());

            using (FileStream f = new FileStream(path, FileMode.Open))
                using (BinaryReader reader = new BinaryReader(f))
                {
                    model.version               = reader.ReadUInt32();
                    model.colorFormat           = reader.ReadUInt32();
                    model.zAxisOrientation      = reader.ReadUInt32();
                    model.compressed            = reader.ReadUInt32();
                    model.visibilityMaskEncoded = reader.ReadUInt32();
                    model.setmatrixcount(reader.ReadUInt32());

                    for (int i = 0; i < model.numMatrices; i++)
                    {
                        QbMatrix m = model.matrices[i];

                        byte l = reader.ReadByte();
                        m.name = System.Text.Encoding.Default.GetString(reader.ReadBytes(l));
                        m.setsize((int)reader.ReadUInt32(), (int)reader.ReadUInt32(), (int)reader.ReadUInt32());
                        m.position = new OpenTK.Vector3(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());

                        byte r;
                        byte g;
                        byte b;
                        byte a;
                        int  zz;

                        if (model.compressed == 0)
                        {
                            for (int z = 0; z < m.size.Z; z++)
                            {
                                for (int y = 0; y < m.size.Y; y++)
                                {
                                    for (int x = 0; x < m.size.X; x++)
                                    {
                                        r  = reader.ReadByte();
                                        g  = reader.ReadByte();
                                        b  = reader.ReadByte();
                                        a  = reader.ReadByte();
                                        zz = model.zAxisOrientation == (int)0 ? z : (int)(m.size.Z - z - 1);

                                        if (a != 0)
                                        {
                                            m.voxels.GetOrAdd(m.GetHash(x, y, zz), new Voxel(x, y, zz, a, m.getcolorindex(r, g, b, model.colorFormat)));
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (int z = 0; z < m.size.Z; z++)
                            {
                                zz = model.zAxisOrientation == 0 ? z : (int)m.size.Z - z - 1;
                                int index = 0;
                                while (true)
                                {
                                    r = reader.ReadByte();
                                    g = reader.ReadByte();
                                    b = reader.ReadByte();
                                    a = reader.ReadByte();
                                    if (r == 6 && g == 0 && b == 0 && a == 0) // NEXTSLICEFLAG
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        if (r == 2 && g == 0 && b == 0 && a == 0) //CODEFLAG
                                        {
                                            uint count = reader.ReadUInt32();
                                            r = reader.ReadByte();
                                            g = reader.ReadByte();
                                            b = reader.ReadByte();
                                            a = reader.ReadByte();
                                            if (a != 0)
                                            {
                                                for (int j = 0; j < count; j++)
                                                {
                                                    int x = index % (int)m.size.X;
                                                    int y = index / (int)m.size.X;
                                                    index++;
                                                    m.voxels.GetOrAdd(m.GetHash(x, y, zz), new Voxel(x, y, zz, a, m.getcolorindex(r, g, b, model.colorFormat)));
                                                }
                                            }
                                            else
                                            {
                                                index += (int)count;
                                            }
                                        }
                                        else
                                        {
                                            int x = index % (int)m.size.X;
                                            int y = index / (int)m.size.X;
                                            index++;
                                            if (a != 0)
                                            {
                                                m.voxels.GetOrAdd(m.GetHash(x, y, zz), new Voxel(x, y, zz, a, m.getcolorindex(r, g, b, model.colorFormat)));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            return(model);
        }
Пример #16
0
 public void AddVolume(VoxelVolume volume, QbMatrix matrix, ref Colort color, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
     double hash;
     for (int z = volume.minz; z <= volume.maxz; z++)
         for (int y = volume.miny; y <= volume.maxy; y++)
             for (int x = volume.minx; x <= volume.maxx; x++)
             {
                 hash = matrix.GetHash(x, y, z);
                 if (!modifiedVoxels.ContainsKey(hash))
                     modifiedVoxels.Add(hash, new VoxelUndoData(matrix.Add(x, y, z, color)));
             }
 }
Пример #17
0
 public void RemoveVolume(VoxelVolume volume, QbMatrix matrix, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
     VoxelUndoData _temp;
     for (int z = volume.minz; z <= volume.maxz; z++)
         for (int y = volume.miny; y <= volume.maxy; y++)
             for (int x = volume.minx; x <= volume.maxx; x++)
             {
                 if (modifiedVoxels.TryGetValue(matrix.GetHash(x, y, z), out _temp) && _temp.changed)
                 {
                     matrix.Remove(x, y, z, false, false);
                     modifiedVoxels.Remove(matrix.GetHash(x, y, z));
                 }
             }
 }
Пример #18
0
 public void RemoveVolume(VoxelVolume volume, QbMatrix matrix, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
     double hash;
     VoxelUndoData voxel = new VoxelUndoData();
     for (int z = volume.minz; z <= volume.maxz; z++)
         for (int y = volume.miny; y <= volume.maxy; y++)
             for (int x = volume.minx; x <= volume.maxx; x++)
             {
                 hash = matrix.GetHash(x, y, z);
                 if (modifiedVoxels.TryGetValue(hash, out voxel))
                 {
                     matrix.Color(x, y, z, voxel.colorindex, false, true);
                     modifiedVoxels.Remove(hash);
                 }
             }
 }
Пример #19
0
        public void AddVolume(VoxelVolume volume, QbMatrix matrix, ref Colort color, Dictionary<double, VoxelUndoData> modifiedVoxels)
        {
            double hash;
            Voxel voxel = null;
            for (int z = volume.minz; z <= volume.maxz; z++)
                for (int y = volume.miny; y <= volume.maxy; y++)
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        hash = matrix.GetHash(x, y, z);

                        if (!modifiedVoxels.ContainsKey(hash) && matrix.voxels.TryGetValue(hash, out voxel) && voxel.alphamask > 1)
                        {
                            modifiedVoxels.Add(hash, new VoxelUndoData(matrix.voxels[hash].colorindex, 0));
                            matrix.Color(x, y, z, color);
                        }
                    }
        }
Пример #20
0
 public void EnumerateVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, ref Colort color, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
     for (int z = currentVolume.minz; z <= currentVolume.maxz; z++)
         for (int y = currentVolume.miny; y <= currentVolume.maxy; y++)
             for (int x = currentVolume.minx; x <= currentVolume.maxx; x++)
             {
                 if (!volume.ContainsPoint(x,y,z) && !modifiedVoxels.ContainsKey(matrix.GetHash(x,y,z)))
                     modifiedVoxels.Add(matrix.GetHash(x, y, z), new VoxelUndoData(matrix.Add(x, y, z, color)));
             }
 }