public TextureViewModel(string filename, FlatWithPositions flat)
        {
            List.Get = TexturePositions.Textures.ToList();

            this.TextureForFlat = new TextureForFlat
            {
                FlatId = flat.FlatId
            };

            this.flat = flat;

            OkCommand = new Command
            {
                ExecuteFunc = x =>
                {
                    this.TextureForFlat.Coordinates.ForEach(coord =>
                    {
                        coord.X /= 700.0f;
                        coord.Y /= (float)Height.Get;
                    });
                    IsOK = true;
                    Close();
                }
            };

            CancelCommand = new Command
            {
                ExecuteFunc = x =>
                {
                    IsOK = false;
                    Close();
                }
            };

            AddCommand = new Command
            {
                ExecuteFunc = x => add()
            };

            SelectedItem.AdditionalAction = x =>
            {
                if (x != null)
                {
                    TextureForFlat = new TextureForFlat
                    {
                        FlatId      = TextureForFlat.FlatId,
                        Coordinates = x.Coordinates
                    };
                    renderLines();
                }
            };

            SetPropertyChangeForAll();
            Image            = System.Drawing.Image.FromFile(filename);
            Height.Get       = (int)((700.0f / Image.Width) * Image.Height);
            TextureImage.Get = ImageHelper.ConvertImageToWpfImage(Image);
        }
        public List <FlatWithPositions> GetFlatBetweenZY(int z, int y)
        {
            var result = new List <FlatWithPositions>();
            var p      = new fPoint(z * multiplicator, y * multiplicator);

            foreach (var flat in flats)
            {
                bool b = false;
                if (flat.Points.Count() == 4)
                {
                    var v1 = vertices[flat.Points[0].VertexId - 1];
                    var v2 = vertices[flat.Points[1].VertexId - 1];
                    var v3 = vertices[flat.Points[2].VertexId - 1];
                    var v4 = vertices[flat.Points[3].VertexId - 1];

                    b = PointInTriangle(p,
                                        new fPoint(v1.Z, v1.Y),
                                        new fPoint(v2.Z, v2.Y),
                                        new fPoint(v3.Z, v3.Y)
                                        ) &&
                        PointInTriangle(p,
                                        new fPoint(v3.Z, v3.Y),
                                        new fPoint(v4.Z, v4.Y),
                                        new fPoint(v1.Z, v1.Y)
                                        );
                }
                else if (flat.Points.Count() == 3)
                {
                    var v1 = vertices[flat.Points[0].VertexId - 1];
                    var v2 = vertices[flat.Points[1].VertexId - 1];
                    var v3 = vertices[flat.Points[2].VertexId - 1];
                    b = PointInTriangle(p,
                                        new fPoint(v1.Z, v1.Y),
                                        new fPoint(v2.Z, v2.Y),
                                        new fPoint(v3.Z, v3.Y)
                                        );
                }
                if (b)
                {
                    var f = new FlatWithPositions();
                    f.FlatId = flats.IndexOf(flat);
                    foreach (var posi in flat.Points)
                    {
                        var vert = vertices[posi.VertexId - 1];
                        f.Positions.Add(new Position3D
                        {
                            X = vert.X / multiplicator,
                            Y = vert.Y / multiplicator * -1.0f,
                            Z = vert.Z / multiplicator,
                        });
                    }
                    result.Add(f);
                }
            }

            return(result);
        }
示例#3
0
        void setTexture(FlatWithPositions flat)
        {
            var vm = new TextureViewModel(textureFile, flat);

            ViewManager.ShowDialogView(typeof(TextureView), vm);
            if (vm.IsOK)
            {
                exporter.SetTextureforFlat(vm.TextureForFlat.FlatId, vm.TextureForFlat);
                //update3DView();
            }
        }
示例#4
0
        void select(int xyz, int _x, int _y)
        {
            if (xy.ClickMode == CLICK_MODE.TEXTURE)
            {
                List <FlatWithPositions> result       = null;
                FlatWithPositions        selectedFlat = null;
                if (xyz == 1)
                {
                    result = exporter.GetFlatBetweenXY(_x, _y);
                }
                else if (xyz == 2)
                {
                    result = exporter.GetFlatBetweenXY(_x, _y);
                }
                else if (xyz == 3)
                {
                    result = exporter.GetFlatBetweenXY(_x, _y);
                }
                if (result?.Count() > 1)
                {
                    setLines(result);
                    var vm = new FlatListViewModel(result, x =>
                    {
                        selectedFlat = x;
                        setLines(result, x);
                    });
                    ViewManager.ShowDialogView(typeof(FlatListView), vm);
                    if (!vm.IsOK)
                    {
                        selectedFlat = null;
                    }
                }
                if (result?.Count() == 1)
                {
                    selectedFlat = result.First();
                }

                if (selectedFlat != null)
                {
                    setLines(null, selectedFlat);
                    if (textureFile == null)
                    {
                        if (ViewManager.FileDialog(
                                out string filename,
                                "Image Files (*.png, *.jpg)|*.png;*.jpg",
                                ConfigLoader.Instance.Config.DefaultTexturepath))
                        {
                            textureFile = filename;
                            setTexture(selectedFlat);
                        }
                    }
                    else
                    {
                        setTexture(selectedFlat);
                    }
                }
                setLines();

                return;
            }

            clearSelection(false);
            var selectedElement = Elements.Get.FirstOrDefault(x => x.IsSelected);

            if (selectedElement == null)
            {
                return;
            }
            List <Position3D> list = null;

            if (xyz == 1)
            {
                list = selectedElement.Positions.Where(p => p.X == _x && p.Y == _y)
                       .ToList();
            }
            else if (xyz == 2)
            {
                list = selectedElement.Positions.Where(p => p.X == _x && p.Z == _y)
                       .ToList();
            }
            else if (xyz == 3)
            {
                list = selectedElement.Positions.Where(p => p.Z == _x && p.Y == _y)
                       .ToList();
            }
            list?.ForEach(point =>
            {
                point.IsSelected = true;
            });
        }
示例#5
0
        void setLines(List <FlatWithPositions> flats = null, FlatWithPositions selectedFlat = null)
        {
            xy.Lines = new List <KeyValuePair <Shape, Brush> >();
            xz.Lines = new List <KeyValuePair <Shape, Brush> >();
            yz.Lines = new List <KeyValuePair <Shape, Brush> >();

            var lines1 = new List <KeyValuePair <Shape, Brush> >();
            var lines2 = new List <KeyValuePair <Shape, Brush> >();
            var lines3 = new List <KeyValuePair <Shape, Brush> >();

            var lines21 = new List <KeyValuePair <Shape, Brush> >();
            var lines22 = new List <KeyValuePair <Shape, Brush> >();
            var lines23 = new List <KeyValuePair <Shape, Brush> >();

            if (isMapElement)
            {
                for (int i = 0; i < mapSizeX; ++i)
                {
                    for (int j = 0; j < mapSizeY; ++j)
                    {
                        int _x1      = i * 128;
                        int _y1      = j * 128;
                        int _x2      = (i + 1) * 128;
                        int _y2      = (j + 1) * 128;
                        int _zOffset = 128 * 2;

                        var p1 = new Position3D
                        {
                            X = _x1,
                            Y = _zOffset,
                            Z = _y1
                        };
                        var p2 = new Position3D
                        {
                            X = _x2,
                            Y = _zOffset,
                            Z = _y1
                        };
                        var p3 = new Position3D
                        {
                            X = _x2,
                            Y = _zOffset,
                            Z = _y2
                        };
                        var p4 = new Position3D
                        {
                            X = _x1,
                            Y = _zOffset,
                            Z = _y2
                        };

                        lines1.Add(new KeyValuePair <Shape, Brush>(createLine(p1, p2, 1), Brushes.Black));
                        lines1.Add(new KeyValuePair <Shape, Brush>(createLine(p2, p3, 1), Brushes.Black));
                        lines1.Add(new KeyValuePair <Shape, Brush>(createLine(p3, p4, 1), Brushes.Black));
                        lines1.Add(new KeyValuePair <Shape, Brush>(createLine(p1, p4, 1), Brushes.Black));

                        lines2.Add(new KeyValuePair <Shape, Brush>(createLine(p1, p2, 2), Brushes.Black));
                        lines2.Add(new KeyValuePair <Shape, Brush>(createLine(p2, p3, 2), Brushes.Black));
                        lines2.Add(new KeyValuePair <Shape, Brush>(createLine(p3, p4, 2), Brushes.Black));
                        lines2.Add(new KeyValuePair <Shape, Brush>(createLine(p1, p4, 2), Brushes.Black));

                        lines3.Add(new KeyValuePair <Shape, Brush>(createLine(p1, p2, 3), Brushes.Black));
                        lines3.Add(new KeyValuePair <Shape, Brush>(createLine(p2, p3, 3), Brushes.Black));
                        lines3.Add(new KeyValuePair <Shape, Brush>(createLine(p3, p4, 3), Brushes.Black));
                        lines3.Add(new KeyValuePair <Shape, Brush>(createLine(p1, p4, 3), Brushes.Black));

                        foreach (var line in lines1)
                        {
                            line.Key.StrokeThickness = 4;
                        }
                        foreach (var line in lines2)
                        {
                            line.Key.StrokeThickness = 4;
                        }
                        foreach (var line in lines3)
                        {
                            line.Key.StrokeThickness = 4;
                        }
                    }
                }
            }

            var boneList1 = new List <KeyValuePair <Shape, Brush> >();
            var boneList2 = new List <KeyValuePair <Shape, Brush> >();
            var boneList3 = new List <KeyValuePair <Shape, Brush> >();
            int boneColor = 0;

            foreach (var bone in Skeletton.Bones)
            {
                boneColor++;
                boneList1.Add(new KeyValuePair <Shape, Brush>(createLine(bone.Positions[0], bone.Positions[1], 1), boneColor % 2 == 0 ? Brushes.Green : Brushes.DarkRed));
                boneList2.Add(new KeyValuePair <Shape, Brush>(createLine(bone.Positions[0], bone.Positions[1], 2), boneColor % 2 == 0 ? Brushes.Green : Brushes.DarkRed));
                boneList3.Add(new KeyValuePair <Shape, Brush>(createLine(bone.Positions[0], bone.Positions[1], 3), boneColor % 2 == 0 ? Brushes.Green : Brushes.DarkRed));
            }

            foreach (var cube in Elements.Get)
            {
                if (cube.IsSelected)
                {
                    lines21.AddRange(addLines(cube, 1));
                    lines22.AddRange(addLines(cube, 2));
                    lines23.AddRange(addLines(cube, 3));
                }
                else
                {
                    lines1.AddRange(addLines(cube, 1));
                    lines2.AddRange(addLines(cube, 2));
                    lines3.AddRange(addLines(cube, 3));
                }
            }
            xy.Lines.AddRange(lines1);
            xz.Lines.AddRange(lines2);
            yz.Lines.AddRange(lines3);
            xy.Lines.AddRange(lines21);
            xz.Lines.AddRange(lines22);
            yz.Lines.AddRange(lines23);
            xy.Lines.AddRange(boneList1);
            xz.Lines.AddRange(boneList2);
            yz.Lines.AddRange(boneList3);

            if (flats != null)
            {
                foreach (var flat in flats)
                {
                    xy.Lines.Add(new KeyValuePair <Shape, Brush>
                                     (createLine(flat.Positions[0], flat.Positions[flat.Positions.Count - 1], 1),
                                     Brushes.Cyan));
                    xz.Lines.Add(new KeyValuePair <Shape, Brush>
                                     (createLine(flat.Positions[0], flat.Positions[flat.Positions.Count - 1], 2),
                                     Brushes.Cyan));
                    yz.Lines.Add(new KeyValuePair <Shape, Brush>
                                     (createLine(flat.Positions[0], flat.Positions[flat.Positions.Count - 1], 3),
                                     Brushes.Cyan));

                    for (int i = 0; i < flat.Positions.Count - 1; i++)
                    {
                        xy.Lines.Add(new KeyValuePair <Shape, Brush>
                                         (createLine(flat.Positions[i], flat.Positions[i + 1], 1),
                                         Brushes.Cyan));
                        xz.Lines.Add(new KeyValuePair <Shape, Brush>
                                         (createLine(flat.Positions[i], flat.Positions[i + 1], 2),
                                         Brushes.Cyan));
                        yz.Lines.Add(new KeyValuePair <Shape, Brush>
                                         (createLine(flat.Positions[i], flat.Positions[i + 1], 3),
                                         Brushes.Cyan));
                    }
                }
            }

            if (selectedFlat != null)
            {
                xy.Lines.Add(new KeyValuePair <Shape, Brush>
                                 (createLine(selectedFlat.Positions[0], selectedFlat.Positions[selectedFlat.Positions.Count - 1], 1),
                                 Brushes.Red));
                xz.Lines.Add(new KeyValuePair <Shape, Brush>
                                 (createLine(selectedFlat.Positions[0], selectedFlat.Positions[selectedFlat.Positions.Count - 1], 2),
                                 Brushes.Red));
                yz.Lines.Add(new KeyValuePair <Shape, Brush>
                                 (createLine(selectedFlat.Positions[0], selectedFlat.Positions[selectedFlat.Positions.Count - 1], 3),
                                 Brushes.Red));

                for (int i = 0; i < selectedFlat.Positions.Count - 1; i++)
                {
                    xy.Lines.Add(new KeyValuePair <Shape, Brush>
                                     (createLine(selectedFlat.Positions[i], selectedFlat.Positions[i + 1], 1),
                                     Brushes.Red));
                    xz.Lines.Add(new KeyValuePair <Shape, Brush>
                                     (createLine(selectedFlat.Positions[i], selectedFlat.Positions[i + 1], 2),
                                     Brushes.Red));
                    yz.Lines.Add(new KeyValuePair <Shape, Brush>
                                     (createLine(selectedFlat.Positions[i], selectedFlat.Positions[i + 1], 3),
                                     Brushes.Red));
                }
            }

            xy.LoadCan();
            xz.LoadCan();
            yz.LoadCan();
            exporter.LoadData(Elements.Get);
            update3DView();
        }