/// <summary> /// Initializes the Map after loading. /// Assigns textures to textureitems and populates the cache and such. /// </summary> public void Initialize() { // Clear the currently cached MapItems MapItems.Clear(); // Iterate through all layer items, initialize them and add to the MapItems container for (int i = 0; i < _layers.Count; i++) { for (int j = 0; j < _layers[i].Items.Count; j++) { // If an item is a TextureItem we look for the correct texture and add it to the item if (_layers[i].Items[j] is TextureItem) { // Search for a texture in the texture libraries and assign the texture to the item TextureItem textureItem = (TextureItem)_layers[i].Items[j]; Texture texture = FindTexture(textureItem.TextureName); if (texture != null) { textureItem.Texture = texture; } else { throw new InvalidOperationException( string.Format("No texture named '{0}' was found for TextureItem '{1}'.", textureItem.TextureName, textureItem.Name) ); } } // Add the layer item to the MapItems list MapItems.Add(_layers[i].Items[j]); } } }
private void TextureSelected(TextureItem selection) { var dis = SelectionPictureBox.Image; SelectionPictureBox.Image = null; //if (dis != null) dis.Dispose(); SizeLabel.Text = ""; if (selection == null || DocumentManager.CurrentDocument == null) { return; } TextureComboBox.SetSelectedTexture(selection); using (var tp = DocumentManager.CurrentDocument.TextureCollection.GetStreamSource(128, 128)) { var bmp = tp.GetImage(selection); if (bmp != null) { if (bmp.Bitmap.Width > SelectionPictureBox.Width || bmp.Bitmap.Height > SelectionPictureBox.Height) { SelectionPictureBox.SizeMode = PictureBoxSizeMode.Zoom; } else { SelectionPictureBox.SizeMode = PictureBoxSizeMode.CenterImage; } } SelectionPictureBox.Image = bmp.Bitmap; } SizeLabel.Text = string.Format("{0} x {1}", selection.Width, selection.Height); }
protected virtual void OnTextureApply(TextureItem texture) { if (TextureApply != null) { TextureApply(this, texture); } }
protected virtual void OnTextureChanged(TextureItem texture) { if (TextureChanged != null) { TextureChanged(this, texture); } }
public void SelectTexture(TextureItem item) { if (_freeze) { return; } if (item == null) { SelectedTexturesList.SetSelectedTextures(new TextureItem[0]); return; } UpdateRecentTextureList(); // If the texture is in the list of selected faces, select the texture in that list var sl = SelectedTexturesList.GetTextures(); if (sl.Any(x => String.Equals(x.Name, item.Name, StringComparison.InvariantCultureIgnoreCase))) { SelectedTexturesList.SetSelectedTextures(new[] { item }); SelectedTexturesList.ScrollToItem(item); } else if (RecentTexturesList.GetTextures().Contains(item)) { // Otherwise, select the texture in the recent list RecentTexturesList.SetSelectedTextures(new[] { item }); RecentTexturesList.ScrollToItem(item); } RecentTexturesList.Refresh(); SelectedTexturesList.Refresh(); }
private static void SetSprite(Entity entity, TextureItem tex) { entity.MetaData.Set(SpriteMetaKey, tex.Name); var scale = 1m; if (entity.GameData != null && entity.GameData.Properties.Any(x => String.Equals(x.Name, "scale", StringComparison.CurrentCultureIgnoreCase))) { var scaleStr = entity.GetEntityData().GetPropertyValue("scale"); if (!Decimal.TryParse(scaleStr, out scale)) { scale = 1; } if (scale <= 0.1m) { scale = 1; } } var bb = new Coordinate(tex.Width, tex.Width, tex.Height) * scale; // Don't set the bounding box if the sprite comes from the iconsprite gamedata if (entity.GameData == null || !entity.GameData.Behaviours.Any(x => String.Equals(x.Name, "iconsprite", StringComparison.CurrentCultureIgnoreCase))) { entity.MetaData.Set(SpriteBoundingBoxMetaKey, new Box(-bb / 2, bb / 2)); entity.MetaData.Set("RotateBoundingBox", false); // todo rotations entity.UpdateBoundingBox(); } }
static void Postfix(MaterialImporter __instance, ref Material __result, int i, glTFMaterial x, bool hasVertexColor) { __result.SetFloat("_DoubleSided", x.doubleSided ? 0 : 2); __result.SetFloat("_Cutout", x.alphaCutoff); if (x.pbrMetallicRoughness != null) { if (x.pbrMetallicRoughness.baseColorFactor != null && x.pbrMetallicRoughness.baseColorFactor.Length == 3) { float[] baseColorFactor2 = x.pbrMetallicRoughness.baseColorFactor; __result.SetColor("_MainColor", new Color(baseColorFactor2[0], baseColorFactor2[1], baseColorFactor2[2]).gamma); } else if (x.pbrMetallicRoughness.baseColorFactor != null && x.pbrMetallicRoughness.baseColorFactor.Length == 4) { float[] baseColorFactor2 = x.pbrMetallicRoughness.baseColorFactor; __result.SetColor("_MainColor", new Color(baseColorFactor2[0], baseColorFactor2[1], baseColorFactor2[2], baseColorFactor2[3]).gamma); } __result.SetFloat("_RefMetallic", x.pbrMetallicRoughness.metallicFactor); } if (x.normalTexture != null && x.normalTexture.index != -1) { __result.SetFloat("_N_F_NM", 1.0f); var func = __instance.GetRefField <MaterialImporter, Func <int, TextureItem> >("GetTextureFunc"); TextureItem textureItem4 = func(x.normalTexture.index); if (textureItem4 != null) { string text2 = "_NormalMap"; __result.SetTexture(text2, textureItem4.ConvertTexture(text2, 1f)); __result.SetFloat("_NormalMapIntensity", x.normalTexture.scale); } SetTextureOffsetAndScale(__result, x.normalTexture, "_NormalMap"); } }
public TextureSubItem(TextureItem item, string name, int width, int height) { Name = name; Width = width; Height = height; Item = item; }
private void DrawImage(System.Drawing.Graphics g, Image bmp, TextureItem ti, int x, int y, int w, int h) { if (bmp == null) { return; } var iw = bmp.Width; var ih = bmp.Height; if (iw > w && iw >= ih) { ih = (int)Math.Floor(h * (ih / (float)iw)); iw = w; } else if (ih > h) { iw = (int)Math.Floor(w * (iw / (float)ih)); ih = h; } g.FillRectangle(System.Drawing.Brushes.Black, x - 3, y - 3, w + 6, h + 10 + SystemFonts.MessageBoxFont.Height); g.DrawImage(bmp, x, y, iw, ih); if (_selection.Contains(ti)) { g.DrawRectangle(Pens.Red, x - 1, y - 1, w + 2, h + 2); g.DrawRectangle(Pens.Red, x - 2, y - 2, w + 4, h + 4); } else { g.DrawRectangle(Pens.Gray, x - 2, y - 2, w + 4, h + 4); } g.DrawString(ti.Name, SystemFonts.MessageBoxFont, System.Drawing.Brushes.White, x - 2, y + h + 3); }
public override async Task <IEnumerable <TextureItem> > GetTextures(IEnumerable <string> names) { var textures = new HashSet <string>(names); textures.IntersectWith(Textures); if (!textures.Any()) { return(new TextureItem[0]); } var wp = new WadPackage(_file); var list = new List <TextureItem>(); foreach (var name in textures) { var entry = wp.GetEntry(name); if (entry == null) { continue; } var item = new TextureItem(entry.Name, GetFlags(entry), (int)entry.Width, (int)entry.Height); list.Add(item); } return(list); }
public void SetTextureList(IEnumerable <TextureItem> textures) { _textures.Clear(); _lastSelectedItem = null; _selection.Clear(); _textures.AddRange(textures); var packs = _textures.Select(t => t.Package).Distinct(); if (_streamSource != null) { _streamSource.Dispose(); } if (DocumentManager.CurrentDocument == null) { _streamSource = null; } else { _streamSource = DocumentManager.CurrentDocument.TextureCollection.GetStreamSource(_imageSize, _imageSize, packs); } OnSelectionChanged(_selection); UpdateRectangles(); }
private void OnTextureCreated(TextureItem texture) { if (!IsHandleCreated) { return; } BeginInvoke(new Action(() => { TreeNode[] groupNodes = textureTreeView.Nodes.Find(texture.Group, false); if (groupNodes.Length > 0) { TreeNode groupNode = groupNodes[0]; TreeNode newTextureNode = new TreeNode { Name = texture.Id, Text = texture.Name, Tag = NodeType.Texture }; groupNode.Nodes.Add(newTextureNode); textureTreeView.Invalidate(); textureListView.Refresh(); } })); }
private void OnTextureSelected(TextureItem item) { if (TextureSelected != null) { TextureSelected(this, item); } }
private void OnTextureRenamed(string oldId, TextureItem texture) { if (!IsHandleCreated) { return; } BeginInvoke(new Action(() => { TreeNode[] groupNodes = textureTreeView.Nodes.Find(texture.Group, false); if (groupNodes.Length > 0) { TreeNode groupNode = groupNodes[0]; TreeNode[] textureNode = groupNode.Nodes.Find(oldId, false); if (textureNode.Length > 0) { textureNode[0].Name = texture.Id; textureNode[0].Text = texture.Name; textureTreeView.Invalidate(); textureListView.Refresh(); } } })); }
public int[] loadAnimationProperty2(TextureItem item, string property) { string type = null; int[] fArray = null; if (item.CustomProperties.ContainsKey(property)) { if (item.CustomProperties[property].type == typeof(string)) { Console.WriteLine(property + " Loaded"); type = (String)item.CustomProperties[property].value; string[] array = type.Split(new char[] { ' ' }); fArray = new int[array.Count()]; for (int i = 0; i < array.Count(); i++) { fArray[i] = int.Parse(array[i]); } } } else { Console.WriteLine("Failed to load " + property); } return(fArray); }
public Texture2D[] loadAnimationSprite(TextureItem item, string property) { Texture2D [] animationSprites = null; if (item.CustomProperties.ContainsKey(property)) { if (item.CustomProperties[property].type == typeof(string)) { Console.WriteLine(property + " Loaded"); String animationPath = (String)item.CustomProperties[property].value; string[] array = animationPath.Split(new char[] { ' ' }); animationSprites = new Texture2D[array.Count()]; for (int i = 0; i < array.Count(); i++) { animationSprites[i] = content.Load <Texture2D>(array[i]); } } } else { Console.WriteLine("Failed to load " + property); } return(animationSprites); }
public void SelectTexture(TextureItem item) { if (item == null) { SelectedTexturesList.SetSelectedTextures(new TextureItem[0]); return; } UpdateRecentTextureList(); // If the texture is in the list of selected faces, select the texture in that list var sl = SelectedTexturesList.GetTextures(); if (sl.Contains(item)) { SelectedTexturesList.SetSelectedTextures(new[] { item }); SelectedTexturesList.ScrollToItem(item); } else if (RecentTexturesList.GetTextures().Contains(item)) { // Otherwise, select the texture in the recent list RecentTexturesList.SetSelectedTextures(new[] { item }); RecentTexturesList.ScrollToItem(item); } RecentTexturesList.Refresh(); SelectedTexturesList.Refresh(); }
private static Schedulable <GameObject> LoadVrmAsyncInternal(VRMImporterContext ctx, bool show) { var schedulable = Schedulable.Create(); return(schedulable .AddTask(Scheduler.ThreadPool, () => { return glTF_VRM_Material.Parse(ctx.Json); }) .ContinueWith(Scheduler.MainThread, x => { // material function ctx.CreateMaterial = VRMImporter.GetMaterialFunc(x); }) .OnExecute(Scheduler.ThreadPool, parent => { // textures for (int i = 0; i < ctx.GLTF.textures.Count; ++i) { var index = i; parent.AddTask(Scheduler.MainThread, () => { var texture = new TextureItem(ctx.GLTF, index); texture.Process(ctx.GLTF, ctx.Storage); return texture; }) .ContinueWith(Scheduler.ThreadPool, x => ctx.Textures.Add(x)); } }) .ContinueWithCoroutine(Scheduler.MainThread, () => LoadMaterials(ctx)) .OnExecute(Scheduler.ThreadPool, parent => { // meshes for (int i = 0; i < ctx.GLTF.meshes.Count; ++i) { var index = i; parent.AddTask(Scheduler.ThreadPool, () => gltfImporter.ReadMesh(ctx, index)) .ContinueWith(Scheduler.MainThread, x => gltfImporter.BuildMesh(ctx, x)) .ContinueWith(Scheduler.ThreadPool, x => ctx.Meshes.Add(x)) ; } }) .ContinueWithCoroutine(Scheduler.MainThread, () => LoadNodes(ctx)) .ContinueWithCoroutine(Scheduler.MainThread, () => BuildHierarchy(ctx)) .ContinueWith(Scheduler.CurrentThread, _ => VRMImporter.OnLoadModel(ctx)) .ContinueWith(Scheduler.CurrentThread, _ => { ctx.Root.name = "VRM"; if (show) { ctx.ShowMeshes(); } return ctx.Root; })); }
public TextureSubItem(TextureSubItemType type, TextureItem item, string name, int width, int height) { Type = type; Name = name; Width = width; Height = height; Item = item; }
static IEnumerator LoadTextures(VRMImporterContext context) { for (int i = 0; i < context.GLTF.textures.Count; ++i) { var x = new TextureItem(context.GLTF, i); x.Process(); context.Textures.Add(x); yield return(null); } }
void RemoveTexture(TextureItem t) { textureList.Items.Remove(t); TileItem[] buff = t.TileItems.ToArray(); foreach (TileItem item in buff) { RemoveTile(item); } }
private async Task <IResource> UploadTexture(IEnvironment environment, TextureItem item, ITextureStreamSource source) { using (var bitmap = await source.GetImage(item.Name, 512, 512)) { var lb = bitmap.LockBits(new Rectangle(0, 0, item.Width, item.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); var data = new byte[lb.Stride * lb.Height]; Marshal.Copy(lb.Scan0, data, 0, data.Length); bitmap.UnlockBits(lb); return(_engine.Value.UploadTexture($"{environment.ID}::{item.Name}", bitmap.Width, bitmap.Height, data, TextureSampleType.Standard)); } }
/// <summary> /// Gets frame count of any item. /// </summary> /// <returns>Number of frame in this set.</returns> public int GetFrameCount(int archive, int record) { int count = 0; int key = MakeTextureKey((short)archive, (byte)record, (byte)0); TextureItem item = new TextureItem(); if (textureItems.TryGetValue(key, out item)) { count = item.frameCount; } return(count); }
private void SetHistory(TextureItem ti) { if (ti == null) { return; } var rem = FindItem(ti.Name, true) ?? GetTexture(ti, true); Items.Remove(rem); Items.Insert(0, rem); FixHistoryBorder(); SelectedItem = rem; }
public List <Polygon> loadPolygons(TextureItem item, string property) { List <Polygon> polygons = new List <Polygon>(); int numberToLoad = 1; int numberOfLoaded = 0; bool loadNext = true; while (loadNext) { string tempProperty = property + numberToLoad.ToString(); if (item.CustomProperties.ContainsKey(tempProperty)) { //Console.WriteLine(tempProperty); if (item.CustomProperties[tempProperty].type == typeof(Item)) { Console.WriteLine(tempProperty + " Loaded"); PathItem pathItem = (PathItem)item.CustomProperties[tempProperty].value; if (pathItem != null) { List <Vector2> liste = new List <Vector2>(pathItem.WorldPoints); Polygon polygon = new Polygon(); foreach (Vector2 point in liste) { polygon.getPoints().Add(point); } polygon.buildEdges(); polygons.Add(polygon); numberToLoad++; numberOfLoaded++; } else { loadNext = false; } } } else { loadNext = false; } } if (numberOfLoaded == 0) { polygons = null; //Console.WriteLine("Did not load Polygons"); } return(polygons); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (!AllowSelection) { return; } if (!AllowMultipleSelection || !KeyboardState.Ctrl) { _selection.Clear(); } if (e.Button == MouseButtons.Left) { _down = true; _downPoint = e.Location; } var x = e.X; var y = _scrollBar.Value + e.Y; var clickedIndex = GetIndexAt(x, y); var item = clickedIndex >= 0 && clickedIndex < _textures.Count ? GetTextures().ElementAt(clickedIndex) : null; if (item == null) { _selection.Clear(); } else if (AllowMultipleSelection && KeyboardState.Ctrl && _selection.Contains(item)) { _selection.Remove(item); _lastSelectedItem = null; } else if (AllowMultipleSelection && KeyboardState.Shift && _lastSelectedItem != null) { var bef = GetTextures().ToList().IndexOf(_lastSelectedItem); var start = Math.Min(bef, clickedIndex); var count = Math.Abs(clickedIndex - bef) + 1; _selection.AddRange(GetTextures().ToList().GetRange(start, count).Where(i => !_selection.Contains(i))); } else { _selection.Add(item); _lastSelectedItem = item; } OnSelectionChanged(_selection); Refresh(); }
private void TextureApplied(object sender, TextureItem texture) { var ti = texture.GetTexture(); Action <Document, Face> action = (document, face) => { face.Texture.Name = texture.Name; face.Texture.Texture = ti; face.CalculateTextureCoordinates(false); }; // When the texture changes, the entire list needs to be regenerated, can't do a partial update. Document.PerformAction("Apply texture", new EditFace(Document.Selection.GetSelectedFaces(), action, true)); Mediator.Publish(EditorMediator.TextureSelected, texture); }
public void Clear() { _textures.Clear(); _lastSelectedItem = null; _selection.Clear(); if (_streamSource != null) { _streamSource.Dispose(); } _streamSource = null; OnSelectionChanged(_selection); }
/// <summary> /// Creates a new Texture Item on the Canvas map /// </summary> /// <param name="layerId">The layer put the object on</param> /// <param name="name">The name of the object</param> /// <param name="texture">The texture for the item</param> /// <param name="position">The position</param> /// <returns>The created item</returns> public IRenderable CreateItem(string layerId, string name, Texture texture, WorldPosition position) { // TODO: Make the layer id a string lookup TextureItem textureItem = TextureItem.Create( layerId, name, texture, position, 0 ); this.AddItem(layerId, textureItem); return(textureItem); }
public void ScrollToItem(TextureItem item) { var index = GetTextures().ToList().IndexOf(item); if (index < 0) { return; } var rec = _rectangles[index]; var yscroll = Math.Max(0, Math.Min(rec.Top - 3, _scrollBar.Maximum - ClientRectangle.Height)); _scrollBar.Value = yscroll; Refresh(); }
public void RemoveAllTextures() { _textures.Clear(); _lastSelectedItem = null; _selection.Clear(); if (_streamSource != null) { _streamSource.Dispose(); } _streamSource = null; OnSelectionChanged(_selection); UpdateRectangles(); }
public TextureItem[] Pack() { var result = new List<TextureItem>(); Rect[] rects = _atlasTexture.PackTextures(_textures.ToArray(), 5); int i = 0; foreach(Texture2D texture in _textures) { TextureItem item = new TextureItem() { textureName = texture.name, atlas = _atlasTexture, uvPosition = GetUvCoordinates(rects[i]), }; result.Add(item); i++; } _textures.Clear(); return result.ToArray(); }
ItemEditor convertTextureItem(TextureItem old) { var editor = (ItemEditor)Activator.CreateInstance(getType(@"Oglr.Plugins.TextureItemEditor, Oglr.Plugins")); var @new = (TextureItemProperties) editor.ItemProperties ; copyPropertiesFromOldToNew( old, @new ); @new.Origin = old.Origin; @new.Rotation = old.Rotation ; @new.Scale = old.Scale ; @new.FlipHorizontally = old.FlipHorizontally ; @new.FlipVertically = old.FlipVertically ; @new.TintColor = old.TintColor ; @new.IsTemplate = old.isTemplate ; @new.TexturePathRelativeToContentRoot = old.texture_filename ; return editor ; }
private static Vector2 getWorldCenterPosition(TextureItem item) { return item.Position; /* //x' = Cos(Theta) * x - Sin(Theta) * y //y' = Sin(Theta) * x + Cos(Theta) * y Vector2 ret = new Vector2(); float textureCenterX = item.texture.Width / 2; float textureCenterY = item.texture.Height / 2; textureCenterY = (float)Math.Cos(-item.Rotation) * textureCenterX - (float)Math.Sin(-item.Rotation) * textureCenterY; textureCenterY = (float)Math.Sin(-item.Rotation) * textureCenterX + (float)Math.Cos(-item.Rotation) * textureCenterY; float xDiff = textureCenterX - item.Origin.X; float yDiff = textureCenterY - item.Origin.Y; ret.X = item.Position.X + xDiff; ret.Y = item.Position.Y + yDiff; return ret; */ }
/// A-----B 0----1 /// | | | | /// D-----C 3----2 void AppendQuad( Vector3[] points, TextureItem pTexItem ) { //A _indices.Add (_vertices.Count); _vertices.Add(points[0]); _uvs.Add(pTexItem.uvPosition[0]); //C _indices.Add (_vertices.Count); _vertices.Add(points[2]); _uvs.Add(pTexItem.uvPosition[2]); //B _indices.Add (_vertices.Count); _vertices.Add(points[1]); _uvs.Add(pTexItem.uvPosition[1]); //A _indices.Add (_vertices.Count); _vertices.Add(points[0]); _uvs.Add(pTexItem.uvPosition[0]); //D _indices.Add (_vertices.Count); _vertices.Add(points[3]); _uvs.Add(pTexItem.uvPosition[3]); //C _indices.Add (_vertices.Count); _vertices.Add(points[2]); _uvs.Add(pTexItem.uvPosition[2]); }
/// <summary> /// Add a new texture item to source list. /// These items are used to build atlas. /// </summary> /// <param name="texture">Individual Texture2D. Must be readable.</param> /// <param name="archive">Archive index of this texture.</param> /// <param name="record">Record index of this texture.</param> /// <param name="frame">Frame index of this texture.</param> /// <param name="frameCount">Number of frames in this set.</param> public void AddTextureItem(Texture2D texture, int archive, int record, int frame, int frameCount, Vector2 size, Vector2 scale) { // Create texture item int key = MakeTextureKey((short)archive, (byte)record, (byte)frame); TextureItem item = new TextureItem() { key = key, texture = texture, archive = archive, record = record, frame = frame, frameCount = frameCount, size = size, scale = scale, }; textureItems.Add(key, item); }
/// <summary> /// Gets frame count of any item. /// </summary> /// <returns>Number of frame in this set.</returns> public int GetFrameCount(int archive, int record) { int count = 0; int key = MakeTextureKey((short)archive, (byte)record, (byte)0); TextureItem item = new TextureItem(); if (textureItems.TryGetValue(key, out item)) { count = item.frameCount; } return count; }
public void AddTextureItem(TextureItem pTextureItem) { _textureItems[pTextureItem.textureName] = pTextureItem; }
public void AddTextureItems(TextureItem[] items) { items.ForEach(AddTextureItem); }