Ejemplo n.º 1
0
        public static QubicleVoxel FromBGRA(uint bgra)
        {
            QubicleVoxel result = new QubicleVoxel
            {
                B = (byte)((bgra >> 0) & 0xFF),
                G = (byte)((bgra >> 8) & 0xFF),
                R = (byte)((bgra >> 16) & 0xFF),
                A = (byte)((bgra >> 24) & 0xFF)
            };

            return(result);
        }
Ejemplo n.º 2
0
        public static QubicleVoxel FromRGBA(uint rgba)
        {
            QubicleVoxel result = new QubicleVoxel
            {
                R = (byte)((rgba >> 0) & 0xFF),
                G = (byte)((rgba >> 8) & 0xFF),
                B = (byte)((rgba >> 16) & 0xFF),
                A = (byte)((rgba >> 24) & 0xFF)
            };

            return(result);
        }
Ejemplo n.º 3
0
            private QubicleVoxel[,,] ReadCompressedVoxels(Vector3i size)
            {
                //throw new NotImplementedException();

                const uint CODEFLAG      = 2;
                const uint NEXTSLICEFLAG = 6;

                QubicleVoxel[,,] voxels = new QubicleVoxel[size.X, size.Y, size.Z];

                //TODO: Check if we should start it 1 (https://getqubicle.com/learn/article.php?id=22&oid=34)
                for (int z = 0; z < size.Z; z++)
                {
                    int index = 0;

                    while (true)
                    {
                        uint data = ReadUInt();

                        if (data == NEXTSLICEFLAG)
                        {
                            break;
                        }

                        if (data == CODEFLAG)
                        {
                            uint         count = ReadUInt();
                            QubicleVoxel voxel = ReadVoxel();

                            for (int i = 0; i < count; i++)
                            {
                                int x = index % size.X;
                                int y = index / size.X;

                                index++;

                                voxels[x, y, z] = voxel;
                            }
                        }
                        else
                        {
                            int x = index % size.X;
                            int y = index / size.X;

                            index++;

                            voxels[x, y, z] = GetVoxel(data);
                        }
                    }
                }

                return(voxels);
            }
Ejemplo n.º 4
0
        public Mesh CreateMesh(float scale = 1)
        {
            List <Vertex> vertices = new();

            Vector3 size = new Vector3(scale);

            for (int z = 0; z < Size.Z; z++)
            {
                for (int y = 0; y < Size.Y; y++)
                {
                    for (int x = 0; x < Size.X; x++)
                    {
                        QubicleVoxel voxel = this[x, y, z];

                        Vector3 pos = new Vector3(x, y, z) * scale;

                        if (voxel.LeftVisible)
                        {
                            vertices.AddRange(CubeHelper.GetLeftVertices(pos, size, voxel.Color, Vector2.Zero, Vector2.One));
                        }

                        if (voxel.RightVisible)
                        {
                            vertices.AddRange(CubeHelper.GetRightVertices(pos, size, voxel.Color, Vector2.Zero, Vector2.One));
                        }

                        if (voxel.BottomVisible)
                        {
                            vertices.AddRange(CubeHelper.GetBottomVertices(pos, size, voxel.Color, Vector2.Zero, Vector2.One));
                        }

                        if (voxel.TopVisible)
                        {
                            vertices.AddRange(CubeHelper.GetTopVertices(pos, size, voxel.Color, Vector2.Zero, Vector2.One));
                        }

                        if (voxel.BackVisible)
                        {
                            vertices.AddRange(CubeHelper.GetBackVertices(pos, size, voxel.Color, Vector2.Zero, Vector2.One));
                        }

                        if (voxel.FrontVisible)
                        {
                            vertices.AddRange(CubeHelper.GetFrontVertices(pos, size, voxel.Color, Vector2.Zero, Vector2.One));
                        }
                    }
                }
            }

            return(new Mesh(vertices.ToArray()));
        }
Ejemplo n.º 5
0
            private QubicleVoxel[,,] ReadUncompressed(Vector3i size)
            {
                QubicleVoxel[,,] voxels = new QubicleVoxel[size.X, size.Y, size.Z];

                for (int z = 0; z < size.Z; z++)
                {
                    for (int y = 0; y < size.Y; y++)
                    {
                        for (int x = 0; x < size.X; x++)
                        {
                            voxels[x, y, z] = ReadVoxel();
                        }
                    }
                }

                return(voxels);
            }
Ejemplo n.º 6
0
 private QubicleVoxel GetVoxel(uint value) => Bgra?QubicleVoxel.FromBGRA(value) : QubicleVoxel.FromRGBA(value);