Ejemplo n.º 1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (PlayerId.Length != 0)
            {
                hash ^= PlayerId.GetHashCode();
            }
            if (Codename.Length != 0)
            {
                hash ^= Codename.GetHashCode();
            }
            if (Team.Length != 0)
            {
                hash ^= Team.GetHashCode();
            }
            if (Score != 0)
            {
                hash ^= Score.GetHashCode();
            }
            if (DataWithMe.Length != 0)
            {
                hash ^= DataWithMe.GetHashCode();
            }
            if (Version != 0L)
            {
                hash ^= Version.GetHashCode();
            }
            if (CreatedMs != 0L)
            {
                hash ^= CreatedMs.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (friendshipLevelData_ != null)
            {
                hash ^= FriendshipLevelData.GetHashCode();
            }
            hash ^= giftboxDetails_.GetHashCode();
            if (Codename.Length != 0)
            {
                hash ^= Codename.GetHashCode();
            }
            if (Nickname.Length != 0)
            {
                hash ^= Nickname.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Ejemplo n.º 3
0
        /* Example:
         * Purpose:
         *
         * Example concepts:
         *  1) Create Code from code string
         *  2) Extracting codename from Code
         *  3) Loading library of Triangles
         *  4) Rendering Grid to Triangles
         *  5) Scaling for absolute real-world dimensions in inches
         *  6) Converting inches to millimeters
         *  7) Saving New STL to file
         */
        static void Main()
        {
            //Glyphics codeString string

            /*
             *                    const string code = @"PrintableNexus,Size3D4 64 64 64;Spawn 25 5 25;PenShape 1;
             *        PenColorD4 31 127 255 255;WallCube 1;
             *
             *        PenColorD4 255 255 255 255;PenSize 1 2 1;Rect 0 0 0 31 0 31;Rect 0 0 32 31 0 63;Rect 32 0 0 63 0 31;Rect 32 0 32 63 0 63;Rect 16 0 16 48 0 48;
             *        PenSize 1 1 1;PenColorD4 31 127 255 255;FillRect 17 0 17 47 0 47;FillRect 16 1 49 48 16 63;
             *        PenColorD4 0 0 0 0;
             *        FillRect 17 1 49 47 15 63;
             *        Rect 0 1 0 63 63 63;
             *        ImgEdgeX 255 255 255 255;ImgEdgeY 255 255 255 255;ImgEdgeZ 255 255 255 255;
             #Now draw the multicolor volumes
             *        PenShape 2;
             *        PenColorD3 127 255 127;FillRect 2 1 2 13 12 13;
             *        PenColorD3 255 127 127;FillRect 2 1 18 13 12 29;
             *        PenColorD3 127 127 255;FillRect 2 1 34 13 12 45;
             *        PenColorD3 255 255 127;FillRect 2 1 50 13 12 61;
             *        PenColorD3 255 127 255;FillRect 18 1 2 29 12 13;
             *
             # Shape on top
             #        PenShape 3;PenColorD3 255 255 255;FillRect 26 17 51 36 28 62;
             #
             #Finally create a mirror image to the other side
             #        ImgMirrorX
             #        ";
             */
            const string code = @"_Palette,
Size3D4 16 16 16
PenShape 1
PenColorD4 31 127 255 255
WallCube 1

PenShape 1
Plot 2 1 2
Rect 1 1 1 14 2 14
FillRect 4 1 4 11 10 11

#Cylinders
PenShape 2
Rect 1 3 1 2 12 2

#Cone
PenShape 3
Rect 1 13 1 2 14 2
FillRect 4 10 4 11 16 11

ImgMirrorX
ImgMirrorZ
";

            //Then render that to triangles
            string dir = "C:\\Github\\Glyphics2\\Stl Files\\";

            Console.WriteLine("Creating triangle library");

            TrianglesList trianglesList = RasterLib.RasterApi.CreateTrianglesList();

            trianglesList.ImportAndReduceToUnit(dir + "Box.stl");                //1
            trianglesList.ImportAndReduceToUnit(dir + "Cylinder.stl");           //2
            trianglesList.ImportAndReduceToUnit(dir + "Cone.stl");               //3
            trianglesList.ImportAndReduceToUnit(dir + "Wedge.stl");              //3
            trianglesList.ImportAndReduceToUnit(dir + "WedgeCorn1.stl");         //4
            trianglesList.ImportAndReduceToUnit(dir + "WedgeCorn2.stl");         //5
            trianglesList.ImportAndReduceToUnit(dir + "WedgeCurved.stl");        //6
            trianglesList.ImportAndReduceToUnit(dir + "WedgeCurvedCorner1.stl"); //7
            trianglesList.ImportAndReduceToUnit(dir + "WedgeCurvedCorner2.stl"); //8

            //            const string codeString = @"PrintableNexus,Size3D4 4 4 4;PenColorD4 255 255 255 255;FillRect 0 0 0 4 4 4;";
            Console.WriteLine("Code: {0}", code);

            //Glyphics codeString object
            Code rasterCode = RasterLib.RasterApi.CreateCode(code);

            //Extract codename from codeString object, to use for filename
            Codename codename = RasterLib.RasterApi.CodeToCodename(rasterCode);

            //Create filename
            string outputFilename = dir + codename.Name + ".STL";

            Console.WriteLine("\nOutput Filename: {0}", outputFilename);

            //Convert the codeString to actual grid
            Console.WriteLine("Code to grid");
            Grid grid = RasterLib.RasterApi.CodeToGrid(rasterCode);

            //Convert to rects
            Console.WriteLine("Grid to rects");
            RectList rects = RasterLib.RasterApi.GridToRects(grid);

//            Triangles tris = trianglesList.GetTriangles(2);
//          Console.WriteLine(tris);

            /*
             * const string filename1 = "C:\\Github\\Glyphics2\\Examples\\ExampleCodeToSTL\\cube_ascii.stl";
             * const string filename2 = "C:\\Github\\Glyphics2\\Examples\\ExampleCodeToSTL\\archquad.stl";
             * const string filename3 = "C:\\Github\\Glyphics2\\Examples\\ExampleCodeToSTL\\pipesphere.stl";
             *
             * //Import the models and make sure they are unit sized
             * trianglesList.ImportAndReduceToUnit(filename1);
             * trianglesList.ImportAndReduceToUnit(filename2);
             * trianglesList.ImportAndReduceToUnit(filename3);
             */
            //Render the rectangles out as shapes(Triangles) to a new set of triangles
            Triangles triangles = RasterLib.RasterApi.Renderer.RenderRectsAsStlMapping(rects, trianglesList);

            Console.WriteLine("Rendering triangles to grid");

            //Reduce scale to 1x1x1, making it 1mm x 1mm x 1mm
            triangles.CalcNormals();
            triangles.ReduceToUnit();
            triangles.Translate(0.5f, 0.5f, 0.5f);

            //Scale up to make an exactly sized models in inches then millimeters
            const float finalSizeInInches      = 2;
            const float finalSizeInMillimeters = finalSizeInInches * 25.4f; //Inches to millimeters

            triangles.Scale(finalSizeInMillimeters, finalSizeInMillimeters, finalSizeInMillimeters);

            //Save final result to STL file
            Console.WriteLine("Saving triangles to {0}", outputFilename);
            RasterLib.RasterApi.SaveTrianglesToStlAscii(outputFilename, triangles);

            //So.. as long as we are here.. let's make a preview

            //Since we can, normalize it now
            triangles.ReduceToUnit();

            //Save a rendering out to a PNG, why not, too.
            Console.WriteLine("Creating preview grid");
            Grid gridFromStl = RasterLib.RasterApi.CreateGrid(96, 96, 96, 4);

            Console.WriteLine("Rendering triangles to grid");
            RasterLib.RasterApi.Renderer.RenderTrianglesToGrid(triangles, gridFromStl);

            //Then render to a new grid
            Console.WriteLine("Rendering grid to oblique preview grid");
            Grid gridObliqueRendered = RasterLib.RasterApi.Renderer.RenderObliqueCells(gridFromStl);

            //Then save
            //const string filenamePreview = "..\\..\\preview.png";
            //Console.WriteLine("Saving file to {0}", filenamePreview);
            //GraphicsApi.SaveFlatPng(filenamePreview, gridObliqueRendered);

            //.. and write finish
            Console.WriteLine("\nDone.");
        }
Ejemplo n.º 4
0
 public DownSolver(Codename inCodename)
 {
     codename = inCodename;
 }
Ejemplo n.º 5
0
        public static void SuperDebug(ScratchControl ctl)
        {
            Grid grid = null;

            if (ctl.FileNameInCode == null && ctl.FileNameInImage == null && ctl.FileNameInStl == null && ctl.FileNameInSvg == null)
            {
                Console.WriteLine("Must have FileNameIn type.");
                return;
            }

            if (ctl.FileNameInSvg != null)
            {
                Console.WriteLine("SVG Input filename: {0}", ctl.FileNameInSvg);
                string codeString = Svg2Gly.ConvertSvg2Gly(ctl.FileNameInSvg);
                Console.WriteLine("SVG:\n" + codeString);

                Code code = RasterLib.RasterApi.CreateCode(codeString);
                if (ctl.Resize != null)
                {
                    code = RasterLib.RasterApi.CodeToRescaledCode(code, ctl.Resize[0], ctl.Resize[1], ctl.Resize[2]);
                }

                Console.WriteLine("Code: {0}\n", codeString);
                grid = RasterLib.RasterApi.CodeToGrid(code);
            }
            else if (ctl.FileNameInStl != null)
            {
                grid = RasterLib.RasterApi.CreateGrid(64, 64, 64, 4);

                Console.WriteLine("STL Input filename: {0}", ctl.FileNameInStl);

                //Load the triangles from the STL file and reduce to a unit 1x1x1 size
                Triangles triangles = RasterLib.RasterApi.StlToTriangles(ctl.FileNameInStl);
                triangles.ReduceToUnit();
                Console.WriteLine("Triangle count: {0}", triangles.Count);

                //Render the triangles to the grid, will autosize to grid size
                RasterLib.RasterApi.Renderer.RenderTrianglesToGrid(triangles, grid);
            }
            else if (ctl.FileNameInImage != null)
            {
                Grid        gridImg = GraphicsApi.FileToGrid(ctl.FileNameInImage);
                GridContext gc      = new GridContext(gridImg);
                RasterLib.RasterApi.Painter.FlipY(gc);
                int div = 63;// 31;// 15;
                grid = RasterLib.RasterApi.CreateGrid(gridImg.SizeX, 255 / div + 1, gridImg.SizeY, 4);

                Console.WriteLine("Extruding");
                Extrusion(grid, gridImg, div);
                Console.WriteLine("Rendering");
                Grid gridIsometricScaledQuick = RasterLib.RasterApi.Renderer.RenderIsometricCellsScaled(grid, 0, 0, 0, 0, 4, 4);
                Console.WriteLine("Saving");
                GraphicsApi.SaveFlatPng(ctl.FileNameOutIsometric, gridIsometricScaledQuick);
                Console.WriteLine("Saved");
            }
            else if (ctl.FileNameInCode != null)
            {
                string codeString = RasterLib.RasterApi.ReadGlyc(ctl.FileNameInCode).Replace(';', '\n');

                Code code = RasterLib.RasterApi.CreateCode(codeString);
                Console.WriteLine("Code: {0}\n", codeString);

                Codename codename = RasterLib.RasterApi.CodeToCodename(code);
                Console.WriteLine("Codename: {0}\n", codename);

                if (ctl.OutputTokens)
                {
                    TokenList glyphTokens = RasterLib.RasterApi.CodeToTokens(code);
                    string    tokenDesc   = "Tokens:\n" + glyphTokens + "\n";
                    Console.WriteLine(tokenDesc);
                }

                if (ctl.Resize != null)
                {
                    code = RasterLib.RasterApi.CodeToRescaledCode(code, ctl.Resize[0], ctl.Resize[1], ctl.Resize[2]);
                }

                grid = RasterLib.RasterApi.CodeToGrid(code);
                Console.WriteLine("Grid: {0}\n", grid);

                if (ctl.FileNameOutOrthogonalAnimated || ctl.FileNameOutIsometricAnimated)
                {
                    ControlAnimator.DoAnimation(ctl, code.codeString, codename.ToString());
                }
            }

            //DownSolver ds = new GeneralLibrary.DownSolver(codeString);

            if (ctl.OutputBytes && grid != null)
            {
                string bytesDesc = RasterLib.RasterApi.BytesToString(grid.CloneData());
                Console.WriteLine("GridBytes:\n{0}\n", bytesDesc);
            }

            RectList rects = RasterLib.RasterApi.GridToRects(grid);

            if (ctl.OutputRectangles)//rects
            {
                Console.WriteLine("Rects: {0}\n{1}", rects.Count, rects);
                RasterLib.RasterApi.BuildCircuit(rects, true);

                string serialized = RasterLib.RasterApi.RectsToSerializedRectsLimit255(rects).SerializedData;
                Console.WriteLine("Serialized Rects: (len={0})\n{1}\n", serialized.Length, serialized);

                RasterLib.RasterApi.SaveFlatText("..\\..\\foo.txt", serialized);
                //Clipboard.SetText(serialized);
                SerializedRects serializedRects = new SerializedRects(serialized);
                RectList        rectsDecoded    = RectConverter.SerializedRectsToRects(serializedRects);

                int count = 0;
                Console.WriteLine("# of Decoded Rects = {0}", rectsDecoded.Count);
                foreach (Rect rect in rectsDecoded)
                {
                    Console.WriteLine(count + " : " + rect);
                    count++;
                }
            }

            if (ctl.OutputRenderedAscii)
            {
                Console.WriteLine("2d view:\n{0}", RasterLib.RasterApi.Renderer.GridToHexDescription(grid));
                Console.WriteLine("3d view:\n{0}", RasterLib.RasterApi.Renderer.GridTo3DDescription(grid, 0, 0, 0));
            }

            if (ctl.OutputSceneGraph)
            {
                Scene     scene     = RasterLib.RasterApi.RectsToScene(rects); Console.WriteLine("Scene: {0}", scene);
                QuadList  quads     = RasterLib.RasterApi.RectsToQuads(rects); Console.WriteLine("Quads: {0}", quads);
                Triangles triangles = RasterLib.RasterApi.QuadsToTriangles(quads); Console.WriteLine("Triangles: {0}", triangles);
            }

            if (ctl.FileNameOutStl != null)
            {
                ControlStl.Control(ctl, rects);
            }

            if (ctl.FileNameOutOrthogonal != null)
            {
                Console.WriteLine("Orthogonal Rendering..");
                Grid gridOrthogonal = RasterLib.RasterApi.Renderer.RenderObliqueCells(grid);
                GraphicsApi.SaveFlatPng(ctl.FileNameOutOrthogonal, gridOrthogonal);
            }

            if (ctl.FileNameOutIsometric != null)
            {
                Console.WriteLine("Isometric Rendering..");
                if (ctl.IsometricCellWidth < 1)
                {
                    ctl.IsometricCellWidth = 1;
                }
                if (ctl.IsometricCellHeight < 1)
                {
                    ctl.IsometricCellHeight = 1;
                }
                Grid gridIsometricScaled = RasterLib.RasterApi.Renderer.RenderIsometricCellsScaled(grid,
                                                                                                   ctl.IsometricBgRgba[0],
                                                                                                   ctl.IsometricBgRgba[1],
                                                                                                   ctl.IsometricBgRgba[2],
                                                                                                   ctl.IsometricBgRgba[3],
                                                                                                   ctl.IsometricCellWidth, ctl.IsometricCellHeight);
                GraphicsApi.SaveFlatPng(ctl.FileNameOutIsometric, gridIsometricScaled);
            }

            Console.WriteLine();
        }