Ejemplo n.º 1
0
        //Return true if the raw bytes = expectedResult bytes
        public bool IsEqualTo(Grid grid)
        {
            if ((grid == null) ||
                (grid.SizeX != SizeX) ||
                (grid.SizeY != SizeY) ||
                (grid.SizeZ != SizeZ) ||
                (grid.Bpp != Bpp) ||
                (grid.Size != Size))
            {
                return(false);
            }

            for (int z = 0; z < grid.SizeZ; z++)
            {
                for (int y = 0; y < grid.SizeY; y++)
                {
                    for (int x = 0; x < grid.SizeX; x++)
                    {
                        CellProperties v1 = grid.GetProperty(x, y, z);
                        CellProperties v2 = GetProperty(x, y, z);

                        if (v1.IsEqualTo(v2) == false)
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        //Duplicate object
        public CellProperties Clone()
        {
            CellProperties cp = new CellProperties();

            cp.CopyFrom(this);
            return(cp);
        }
Ejemplo n.º 3
0
        public static void Vox2Glyc(string dirName, string name)
        {
            Console.Write("Vox2Glyc converting: " + name + " ... ");
            VoxFile_VoxelSet voxels = null;
            voxels = ReadVox(dirName + name + ".vox");

            Grid grid = RasterLib.RasterApi.CreateGrid(64, 64, 64, 4);

            for (int i = 0; i < voxels.voxels.Length; i++)
            {
                VoxFile_Voxel voxel = voxels.voxels[i];
                CellProperties cp = new CellProperties();

                byte r = (byte)voxel.I;
                byte g = (byte)voxel.I;
                byte b = (byte)voxel.I;
                byte a = (byte)voxel.I;
                r = (byte)((voxels.palette[voxel.I] >> 0) & 255);
                g = (byte)((voxels.palette[voxel.I] >> 8) & 255);
                b = (byte)((voxels.palette[voxel.I] >> 16) & 255);
                a = (byte)((voxels.palette[voxel.I] >> 24) & 255);

                cp.Rgba = RasterLib.RasterApi.Rgba2Ulong(r, g, b, a);
                grid.Plot(voxel.X, voxel.Y, voxel.Z, cp);
            }

            RectList rects = RasterLib.RasterApi.GridToRects(grid);
            RasterLib.Language.Code code = RasterLib.RasterApi.RectsToCode(rects);
            //Console.WriteLine(code.codeString);

            RasterLib.RasterApi.CodeToGlyC(dirName + name + ".glyc", name + ",\n" + code.codeString);
        }
Ejemplo n.º 4
0
 //Set dimensions of Rect
 private void Set(double nx1, double ny1, double nz1, double nx2, double ny2, double nz2)
 {
     Pt1        = new double[3];
     Pt2        = new double[3];
     Properties = new CellProperties
     {
         ShapeId   = 1,
         TextureId = 1
     };
     Pt1[0] = nx1; Pt1[1] = ny1; Pt1[2] = nz1; Pt2[0] = nx2; Pt2[1] = ny2; Pt2[2] = nz2;
 }
Ejemplo n.º 5
0
        //Get the cell properties at xyz
        public CellProperties GetProperty(int x, int y, int z)
        {
            if (x < 0 || y < 0 || z < 0 || x >= _sizeX || y >= _sizeY || z >= _sizeZ)
            {
                return(null);
            }
            int offset = (z * _size2D) + (y * _sizeX) + (x);

            if (_properties[offset] == null)
            {
                _properties[offset] = new CellProperties();                             //REMOVEME - will require fix to RunLengthReduceXy
            }
            return(_properties[offset]);
        }
Ejemplo n.º 6
0
        //Plot an rgba values straight to grid
        public void Plot(int x, int y, int z, ulong rgba)
        {
            if (!InRange(x, y, z))
            {
                return;
            }
            long offsetTrack = (z * _size2D) + (y * _sizeX) + (x);

            if (_properties[offsetTrack] == null)
            {
                _properties[offsetTrack] = new CellProperties();
            }
            _properties[offsetTrack].Rgba = rgba;
        }
Ejemplo n.º 7
0
 //Linearly interpolate between properties A and B, modulated by mux (0 to 1)
 public void Lerp(double mux, CellProperties propsA, CellProperties propsB)
 {
     if (propsA == null || propsB == null)
     {
         return;
     }
     Rgba      = MathLerper.LerpRgba(mux, propsA.Rgba, propsB.Rgba);
     TextureId = (byte)MathLerper.ThresholdAb(mux, propsA.TextureId, propsB.TextureId);
     ShapeId   = (byte)MathLerper.ThresholdAb(mux, propsA.ShapeId, propsB.ShapeId);
     PhysicsId = (byte)MathLerper.ThresholdAb(mux, propsA.PhysicsId, propsB.PhysicsId);
     GroupId   = (byte)MathLerper.ThresholdAb(mux, propsA.GroupId, propsB.GroupId);
     WorldId   = (ulong)MathLerper.ThresholdAb(mux, propsA.WorldId, propsB.WorldId);
     CalcUnified();
 }
Ejemplo n.º 8
0
        //MathCompare if two properties are equal
        public bool IsEqualTo(CellProperties asCell)
        {
            if (asCell == null)
            {
                return(false);
            }

            return((Rgba == asCell.Rgba) &&
                   (TextureId == asCell.TextureId) &&
                   (ShapeId == asCell.ShapeId) &&
                   (GroupId == asCell.GroupId) &&
                   (WorldId == asCell.WorldId)
                   );
        }
Ejemplo n.º 9
0
        //Copy properties from src to self
        public void CopyFrom(CellProperties src)
        {
            if (src == null)
            {
                return;
            }

            Rgba      = src.Rgba;
            TrackId   = src.TrackId;
            TextureId = src.TextureId;
            ShapeId   = src.ShapeId;
            PhysicsId = src.PhysicsId;
            GroupId   = src.GroupId;
            WorldId   = src.WorldId;
            CalcUnified();
        }
Ejemplo n.º 10
0
        public static string SerializeCircuitProperties(CellProperties properties)
        {
            string str = "";

            if (properties.CircuitIds != null)
            {
                foreach (int circuitId in properties.CircuitIds)
                {
                    if (circuitId > 0)
                    {
                        str += "" + CharCircuit;
                        str += Transcode64.To64(properties.PhysicsId);
                        str += Transcode64.To64(circuitId);
                    }
                }
            }

            return(str);
        }
Ejemplo n.º 11
0
        public void Plot(int x, int y, int z, CellProperties cp)
        {
            if (!InRange(x, y, z))
            {
                return;
            }
            long offsetTrack = (z * _size2D) + (y * _sizeX) + (x);

            if (_properties[offsetTrack] == null)
            {
                _properties[offsetTrack] = new CellProperties();
            }
            _properties[offsetTrack].Rgba = cp.Rgba;
            if (_codeTrackingInhibit == false)
            {
                _properties[offsetTrack].TrackId = _trackId;
            }
            SetProperties(offsetTrack, cp.TextureId, cp.ShapeId, cp.GroupId, cp.PhysicsId, cp.WorldId);
        }
Ejemplo n.º 12
0
        //Compact all rectangles on a height/depth axis
        private static void RunLengthReduceXy(ref List <Rect> aabbs, Grid grid, int height, int z)
        {
            CellProperties lastProperties = new CellProperties();
            int            runLength      = 1;
            int            runStart       = 1;
            int            sizeX          = grid.SizeX;

            for (int x = 0; x < sizeX; x++)
            {
                CellProperties currProperties = grid.GetProperty(x, height, z);

                if (currProperties.Rgba == 0)                                                                                   //Now in void space
                {
                    if ((currProperties.Rgba != lastProperties.Rgba) || (currProperties.PhysicsId != lastProperties.PhysicsId)) //If last wasn't void space, then save the RLE
                    {
                        MergedAddAabb(ref aabbs, new Rect(runStart, height, z, runStart + runLength, height + 1, z + 1, lastProperties));
                        runLength      = 1;
                        lastProperties = currProperties;
                    }
                }
                else if ((currProperties.Rgba != lastProperties.Rgba) || (currProperties.PhysicsId != lastProperties.PhysicsId)) //Something changed
                {
                    if ((lastProperties.Rgba != 0))                                                                              //something turning to something else
                    {
                        MergedAddAabb(ref aabbs, new Rect(runStart, height, z, runStart + runLength, height + 1, z + 1, lastProperties));
                        runLength = 1;
                    }
                    runStart       = x;
                    lastProperties = currProperties;
                }
                else
                {
                    runLength++; //CompareDoublesAreEqual properties as before, so increase RLE count
                }
            }


            //Add tail end
            if (lastProperties.Rgba != 0)
            {
                MergedAddAabb(ref aabbs, new Rect(runStart, height, z, runStart + runLength, height + 1, z + 1, lastProperties));
            }
        }
Ejemplo n.º 13
0
        public void Plot(int x, int y, int z, Pen pen)
        {
            if (!InRange(x, y, z))
            {
                return;
            }
            long offsetTrack = (z * _size2D) + (y * _sizeX) + (x);

            if (_properties[offsetTrack] == null)
            {
                _properties[offsetTrack] = new CellProperties();
            }

            _properties[offsetTrack].Rgba = pen.Rgba;
            if (_codeTrackingInhibit == false)
            {
                _properties[offsetTrack].TrackId = _trackId;
            }
            SetProperties(offsetTrack, pen.TextureByte, pen.ShapeByte, pen.GroupByte, pen.PhysicsByte, pen.World);
        }
Ejemplo n.º 14
0
        //Plot a set of cell properties at xyz
        public void Plot(int x, int y, int z, ulong rgba, byte physics, byte shape, byte texture, byte group, ulong world)
        {
            if (!InRange(x, y, z))
            {
                return;
            }
            long offsetTrack = (z * _size2D) + (y * _sizeX) + (x);

            if (_properties[offsetTrack] == null)
            {
                _properties[offsetTrack] = new CellProperties();
            }
            _properties[offsetTrack].Rgba = rgba;

            if (_codeTrackingInhibit == false)
            {
                _properties[offsetTrack].TrackId = _trackId;
            }
            SetProperties(offsetTrack, texture, shape, group, physics, world);
        }
Ejemplo n.º 15
0
        //Serialize cellproperties to a string
        private static string SerializeRectProperties(CellProperties properties, bool Mode2D)
        {
            string str = "";

            if (Mode2D)
            {
                str += CharRects2D;
            }
            else
            {
                str += CharRgba;
            }

            byte r, g, b, a;

            Transcode64.RecodeUlongtoRgba(properties.Rgba, out r, out g, out b, out a);
            str += Transcode64.To64(r);
            str += Transcode64.To64(g);
            str += Transcode64.To64(b);
            str += Transcode64.To64(a);
            str += Transcode64.To64(properties.ShapeId);
            str += Transcode64.To64(properties.TextureId);

            if (properties.GroupId > 0)
            {
                str += "" + CharGroup;
                str += Transcode64.To64(properties.GroupId);
            }

            if (properties.WorldId > 0)
            {
                str += "" + CharWorld;
                str += Transcode64.To64((byte)((properties.WorldId >> 24) & 0xFF));
                str += Transcode64.To64((byte)((properties.WorldId >> 16) & 0xFF));
                str += Transcode64.To64((byte)((properties.WorldId >> 8) & 0xFF));
                str += Transcode64.To64((byte)((properties.WorldId >> 0) & 0xFF));
            }

            return(str);
        }
Ejemplo n.º 16
0
 //Assignment constructor
 public Rect(double nx1, double ny1, double nz1, double nx2, double ny2, double nz2, CellProperties newProperties)
 {
     Set(nx1, ny1, nz1, nx2, ny2, nz2);
     Properties.Rgba      = newProperties.Rgba;
     Properties.ShapeId   = newProperties.ShapeId;
     Properties.TextureId = newProperties.TextureId;
     Properties.GroupId   = newProperties.GroupId;
     Properties.PhysicsId = newProperties.PhysicsId;
     Properties.WorldId   = newProperties.WorldId;
 }
Ejemplo n.º 17
0
 //Constructor
 public Element()
 {
     Properties = new CellProperties();
     Transform = new Transform();
 }