private void Button_Create_Click(object sender, RoutedEventArgs e)
        {
            float X = Convert.ToInt32(TextBox_X.Text);
            float Y = Convert.ToInt32(TextBox_Y.Text);
            //float Z = Convert.ToInt32(TextBox_Z.Text);
            float t = 0.4f + (float)Convert.ToDouble(TextBox_thickness.Text);

            dynamic circle = new JObject();

            HashSet <Point3D> points = new HashSet <Point3D>();

            double precision = 0.95;
            double pp        = 0;

            for (float x = -X; x < X; x++)
            {
                for (float y = -Y; y < Y; y++)
                {
                    if ((Math.Pow(x / X, 2) + Math.Pow(y / Y, 2)) < precision &&
                        (Math.Pow((x) / (X - t), 2) + Math.Pow((y) / (Y - t), 2)) > (precision - pp))
                    {
                        points.Add(new Point3D(x, y, 1));
                    }
                }
            }


            circle = BlueprintOptimizer.CreateBlueprintFromPoints(points);


            if (circle.bodies[0].childs.Count > 0)
            {
                string  message       = "++ An ellipse/circle with " + circle.bodies[0].childs.Count + " shapes has been generated!";
                Random  r             = new Random();
                string  blueprintpath = Database.User_ + "\\Blueprints\\Generatedellipse-" + r.Next() + r.Next();
                dynamic description   = new JObject();
                description.description = "generated ellipsoid";
                description.name        = "generated ellipse/circle" + r.Next();
                description.type        = "Blueprint";
                description.version     = 0;

                if (BP.Blueprintpath == null)
                {//no blueprint exists, initialize new one
                    new BP(blueprintpath, circle, description);
                }
                else
                {//overwrite current blueprint
                    BP.setblueprint(circle);
                    BP.Description.description += message;
                }
                mainwindow.RenderBlueprint();
            }
            else
            {
                MessageBox.Show("no circle has been generated");
            }
        }
Пример #2
0
        private void Convertobj(object sender, DoWorkEventArgs e)
        {
            Scene scene = new AssimpImporter().ImportFile(file, PostProcessSteps.Triangulate);

            //List<Triangle> splittriangles = new List<Triangle>();
            pointlist = new HashSet <Point3D>();
            //pointlist.ToDictionary<>
            int progress = 0;
            int total    = 0;

            try
            {
                foreach (Mesh m in scene.Meshes)
                {
                    foreach (Face face in m.Faces)
                    {
                        total++;
                    }
                }
                foreach (Mesh m in scene.Meshes)
                {
                    foreach (Face face in m.Faces)
                    {
                        IList <Point3D> vertices = new List <Point3D>();
                        foreach (uint i in face.Indices)
                        {
                            double  x = m.Vertices[i].X * scale;
                            double  y = m.Vertices[i].Y * scale;
                            double  z = m.Vertices[i].Z * scale;
                            Point3D point;
                            if (flipyz)
                            {
                                if (flipxz)
                                {
                                    point = new Point3D(y, z, flipz * x);
                                }
                                else
                                {
                                    point = new Point3D(x, z, flipz * y);
                                }
                            }
                            else
                            {
                                if (flipxz)
                                {
                                    point = new Point3D(z, y, flipz * x);
                                }
                                else
                                {
                                    point = new Point3D(x, y, flipz * z);
                                }
                            }
                            vertices.Add(point);
                            pointlist.Add(new Point3D((int)Math.Floor(point.X), (int)Math.Floor(point.Y), (int)Math.Floor(point.Z)));
                        }
                        if (vertices.Count == 3)
                        {
                            Triangle triangle = new Triangle(vertices);
                            if (!triangle.BoundsSmallerThan(bounds))
                            {
                                Splittriangles(triangle);
                            }
                        }
                        else
                        {
                        }
                        progress++;
                        backgroundWorker.ReportProgress((progress * 100) / total);
                        if (backgroundWorker.CancellationPending)
                        {
                            e.Cancel = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (!(ex is OperationCanceledException))
                {
                    System.Windows.MessageBox.Show(ex.Message, "Something went wrong converting the obj");
                }
                else
                {
                    e.Cancel = true;
                }
            }

            try
            {
                if (backgroundWorker.CancellationPending)
                {
                    throw new OperationCanceledException();
                }

                dynamic blueprint = new JObject();
                try
                {
                    blueprint = BlueprintOptimizer.CreateBlueprintFromPoints(pointlist);
                }
                catch (Exception bpex)
                {
                    System.Windows.MessageBox.Show(bpex.Message, "Something went wrong building the blueprint");
                }
                int    amountgenerated = blueprint.bodies[0].childs.Count;
                string message         = "converted obj to blueprint with " + amountgenerated + " blocks !";
                //MessageBox.Show(message+"\n\nOptimized to: "+count+" shapes");
                Random  r             = new Random();
                string  blueprintpath = Database.User_ + "\\Blueprints\\Generatedblueprintobj-" + r.Next() + r.Next();
                dynamic description   = new JObject();
                description.description = "generated obj blueprint with " + amountgenerated + " block";
                description.name        = "generated blueprint" + r.Next();
                description.type        = "Blueprint";
                description.version     = 0;
                new Task(() =>
                {
                    System.Windows.MessageBox.Show(message + "\nPLEASE WAIT for the rendering to complete");
                }).Start();
                if (BP.Blueprintpath == null)
                {//no blueprint exists, initialize new one
                    new BP(blueprintpath, blueprint, description);
                }
                else
                {//overwrite current blueprint
                    BP.setblueprint(blueprint);
                    BP.Description.description += message;
                }
            }
            catch (Exception exc)
            {
                System.Windows.MessageBox.Show(exc.Message, "error");
            }
        }
Пример #3
0
        private void Convertobjwtexture(object sender, DoWorkEventArgs e)
        {
            try
            {
                Scene scene = new AssimpImporter().ImportFile(file, PostProcessSteps.Triangulate);

                coloredpoints = new Dictionary <Point3D, Point3D>();
                //List<Triangle> splittriangles = new List<Triangle>();
                //pointlist = new HashSet<Point3D>();


                //pointlist.ToDictionary<>
                int progress = 0;
                int total    = 0;

                foreach (Mesh m in scene.Meshes)
                {
                    foreach (Face face in m.Faces)
                    {
                        total++;
                    }
                }
                foreach (Mesh m in scene.Meshes)
                {
                    var texturecoords = m.GetTextureCoords(0);

                    foreach (Face face in m.Faces)
                    {
                        IList <Point3D> vertices      = new List <Point3D>();
                        IList <Point3D> texturepoints = new List <Point3D>();
                        foreach (uint i in face.Indices)
                        {
                            double          x = m.Vertices[i].X * scale;
                            double          y = m.Vertices[i].Y * scale;
                            double          z = m.Vertices[i].Z * scale;
                            Point3D         point;
                            Assimp.Vector3D texturep     = texturecoords[i];
                            Point3D         texturepoint = new Point3D(texturep.X, 1 - texturep.Y, texturep.Z);
                            if (flipyz)
                            {
                                if (flipxz)
                                {
                                    point = new Point3D(y, z, flipz * x);
                                }
                                else
                                {
                                    point = new Point3D(x, z, flipz * y);
                                }
                            }
                            else
                            {
                                if (flipxz)
                                {
                                    point = new Point3D(z, y, flipz * x);
                                }
                                else
                                {
                                    point = new Point3D(x, y, flipz * z);
                                }
                            }
                            vertices.Add(point);
                            texturepoints.Add(texturepoint);
                            Point3D flooredpoint = new Point3D((int)Math.Floor(point.X), (int)Math.Floor(point.Y), (int)Math.Floor(point.Z));
                            if (!coloredpoints.ContainsKey(flooredpoint))
                            {
                                coloredpoints.Add(flooredpoint, texturepoint);
                            }
                        }
                        if (vertices.Count == 3)
                        {
                            ColorTriangle triangle = new ColorTriangle(vertices, texturepoints);
                            if (!triangle.BoundsSmallerThan(bounds))
                            {
                                Splitcolortriangles(triangle);
                            }
                        }
                        else
                        {
                        }
                        progress++;
                        backgroundWorker.ReportProgress((progress * 100) / total);
                        if (backgroundWorker.CancellationPending)
                        {
                            e.Cancel = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (!(ex is OperationCanceledException))
                {
                    System.Windows.MessageBox.Show(ex.Message, "Something went wrong converting the obj+texture");
                }
                else
                {
                    e.Cancel = true;
                }
            }

            try
            {
                if (backgroundWorker.CancellationPending)
                {
                    throw new OperationCanceledException();
                }

                dynamic blueprint = new JObject();
                try
                {
                    Bitmap texturemap = new Bitmap(this.texture);
                    HashSet <Tuple <Point3D, string> > pointswithcolor = new HashSet <Tuple <Point3D, string> >();
                    int width  = texturemap.Width;
                    int height = texturemap.Height;
                    foreach (var pair in coloredpoints)
                    {
                        int x = (int)(pair.Value.X * width);
                        int y = (int)(pair.Value.Y * height);
                        if (pair.Value.Y > 1)
                        {
                        }
                        while (y < 0)
                        {
                            y++;
                        }
                        while (x < 0)
                        {
                            x++;
                        }
                        if (Math.Abs(x) > width / 2)
                        {
                        }
                        while (x >= width)
                        {
                            x -= width;
                        }
                        while (y >= height)
                        {
                            y -= height;
                        }
                        System.Drawing.Color color = texturemap.GetPixel(x, y);
                        string c = color.Name.Substring(2);
                        pointswithcolor.Add(new Tuple <Point3D, string>(pair.Key, c));
                    }
                    coloredpoints.Clear();
                    blueprint = BlueprintOptimizer.CreateBlueprintFromPointsAndColor(pointswithcolor);
                }
                catch (Exception bpex)
                {
                    System.Windows.MessageBox.Show(bpex.Message, "Something went wrong building the blueprint");
                }
                int    amountgenerated = blueprint.bodies[0].childs.Count;
                string message         = "converted obj to blueprint with " + amountgenerated + " blocks !";
                //MessageBox.Show(message+"\n\nOptimized to: "+count+" shapes");
                Random  r             = new Random();
                string  blueprintpath = Database.User_ + "\\Blueprints\\Generatedblueprintobj-" + r.Next() + r.Next();
                dynamic description   = new JObject();
                description.description = "generated obj blueprint with " + amountgenerated + " block";
                description.name        = "generated blueprint" + r.Next();
                description.type        = "Blueprint";
                description.version     = 0;
                new Task(() =>
                {
                    System.Windows.MessageBox.Show(message + "\nPLEASE WAIT for the rendering to complete");
                }).Start();
                if (BP.Blueprintpath == null)
                {//no blueprint exists, initialize new one
                    new BP(blueprintpath, blueprint, description);
                }
                else
                {//overwrite current blueprint
                    BP.setblueprint(blueprint);
                    BP.Description.description += message;
                }
            }
            catch (Exception exc)
            {
                System.Windows.MessageBox.Show(exc.Message, "error");
            }
        }