public void SetTextureForElement(int id, TextureForFlat texture) { var element = elements.First(x => x.Id == id); var _flats = flats.Where(x => x.ModelId == id).ToList(); if (element.GetType() == typeof(Cube)) { foreach (var flat in _flats) { SetTextureforFlat(flat.Id, texture); } } else if (element.GetType() == typeof(Sphere)) { //var sphere = (Sphere)element; //var curY = 0.0f; //foreach (var posi in element.Positions) //{ // flats.Where(x => x.ModelId == id).ToList().ForEach(x => x.Points.ForEach(y => // { // var tex = textureCoordinates[y.TextureId - 1]; // y.TextureId = addTexture( // texture.Coordinates[0].X + tex.X * (texture.Coordinates[0].X - texture.Coordinates[1].X), // ); // })); //} } }
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); }
void add() { var coords = TextureForFlat.GetTextureCoordinates(); if (!TexturePositions.Textures.Any(x => x == coords)) { TexturePositions.Textures.Add(coords); } List.Get = TexturePositions.Textures.ToList(); }
void setTextureforFlat(Flat flat, TextureForFlat texture) { if (flat.Points.Count == texture.Coordinates.Count) { for (int i = 0; i < flat.Points.Count; i++) { var textureCoord = texture.Coordinates[i]; flat.Points[i].TextureId = addTexture(textureCoord.X, textureCoord.Y); } } }
void calcTexturePosition(TextureForFlat texture, float _x, float _y, out float x, out float y) { var c1 = texture.Coordinates[0]; var c2 = texture.Coordinates[1]; var c3 = texture.Coordinates[2]; var c4 = texture.Coordinates[3]; var a1 = (c1.Y - c4.Y) / (c1.X - c4.X); var b1 = c4.Y; var a2 = (c2.Y - c1.Y) / (c2.X - c1.X); var b2 = c1.Y; var a3 = (c3.Y - c4.Y) / (c3.X - c4.X); var b3 = c4.Y; x = c4.X; y = 0.0f; }
public void SetTextureforFlat(int id, TextureForFlat texture) { var flat = flats[id]; setTextureforFlat(flat, texture); }