private void UpdateSectionValues(TextureSection updatedSection) { var sections = _textureSections.ToList(); sections[updatedSection.Index] = updatedSection.Coords; CommandHandler.Execute(new UpdateTextureSectionsCommand(sections)); }
private static TextureSection[] ReadTextureHeaders(Stream xgrStream, WpdEntry[] textureEntries) { TextureSection[] result = new TextureSection[textureEntries.Length]; for (int i = 0; i < result.Length; i++) { WpdEntry entry = textureEntries[i]; using (StreamSegment textureHeaderInput = new StreamSegment(xgrStream, entry.Offset, entry.Length, FileAccess.Read)) result[i] = textureHeaderInput.ReadContent <TextureSection>(); } return(result); }
private void AddNewSection(TextureSectionCoords? coords = null) { var newSections = _textureSections.Concat(new[] { coords ?? new TextureSectionCoords(0, 0, _texture.Width, _texture.Height), }).ToList(); CommandHandler.Execute(new UpdateTextureSectionsCommand(newSections)); // Set the new section as current one, so it's auto selected _currentSection = new TextureSection(newSections.Count - 1, new TextureSectionCoords()); }
private void RenderSectionList(Vector2 popupSize) { ImGui.Text("Sections:"); if (CommandHandler.CanUndo && CommandHandler.PreviousCommand.GetType() == typeof(UpdateTextureSectionsCommand)) { ImGui.SameLine(ImGui.GetWindowWidth() - 120); if (ImGui.Button("Undo")) { CommandHandler.Undo(); } } if (CommandHandler.CanRedo && CommandHandler.NextCommand.GetType() == typeof(UpdateTextureSectionsCommand)) { ImGui.SameLine(ImGui.GetColumnWidth() - 40); if (ImGui.Button("Redo")) { CommandHandler.Redo(); } } var sectionWindowSize = new Vector2(popupSize.X - 20, 100); ImGui.BeginChild("sections", sectionWindowSize, true); var size = new Vector2(70, 70); for (var x = 0; x < _textureSections.Count; x++) { var section = _textureSections[x]; var uv0 = new Vector2(section.LeftX / (float) _texture.Width, section.TopY / (float) _texture.Height); var uv1 = new Vector2(section.RightX / (float) _texture.Width, section.BottomY / (float) _texture.Height); ImGui.PushID("section_" + x); if (ImGui.ImageButton(_imguiTextureId, size, uv0, uv1)) { _currentSection = new TextureSection(x, section); } ImGui.PopID(); ImGui.SameLine(); } if (ImGui.Button("+##AddSection")) { AddNewSection(); } ImGui.EndChild(); }
public void Inject(WpdEntry entry, Stream input, Lazy <Stream> headers, Lazy <Stream> content, Byte[] buff) { int sourceSize = (int)input.Length; headers.Value.Position = entry.Offset; TextureSection textureHeader = headers.Value.ReadContent <TextureSection>(); GtexData data = textureHeader.Gtex; if (data.MipMapData.Length != 1) { throw new NotImplementedException(); } DdsHeader ddsHeader = DdsHeaderDecoder.FromFileStream(input); DdsHeaderEncoder.ToGtexHeader(ddsHeader, data.Header); GtexMipMapLocation mipMapLocation = data.MipMapData[0]; int dataSize = sourceSize - 128; if (dataSize <= mipMapLocation.Length) { content.Value.Seek(mipMapLocation.Offset, SeekOrigin.Begin); } else { content.Value.Seek(0, SeekOrigin.End); mipMapLocation.Offset = (int)content.Value.Position; } input.CopyToStream(content.Value, dataSize, buff); mipMapLocation.Length = dataSize; using (MemoryStream ms = new MemoryStream(96)) { textureHeader.WriteToStream(ms); ms.SetPosition(0); DefaultWpdEntryInjector defaultInjector = new DefaultWpdEntryInjector(); defaultInjector.Inject(entry, ms, headers, content, buff); } }
protected override void OnNewSettingsLoaded() { _texture = TextureFileLoader.LoadTexture2D(EmitterSettings.TextureFileName); _imguiTextureId = MonoGameImGuiRenderer.BindTexture(_texture); _textureSections.Clear(); _textureSections.AddRange(EmitterSettings.TextureSections); if (_currentSection != null) { if (_currentSection.Index >= _textureSections.Count) { _currentSection = null; } else { var section = _textureSections[_currentSection.Index]; _currentSection = new TextureSection(_currentSection.Index, section); } } }
public PreviewTexture(GtexData gtex) : base() { this.tex = new TextureSection("__previewTexture", gtex); this.EnableCamera = false; }
public PreviewTexture(TextureSection tex) : base() { this.tex = tex; }
public void Add(TextureSection textureSection) { Texture texture = null; CubeTexture cube = null; try { TextureHolder texHolder = new TextureHolder(); int texWidth = textureSection.Gtex.Header.Width; int texHeight = textureSection.Gtex.Header.Height; if (textureSection.Gtex.Header.IsCubeMap) { cube = new CubeTexture(device, texWidth, 0, Usage.None, textureSection.Gtex.Format, Pool.Managed); texHolder.Texture = cube; texHolder.Name = textureSection.ResourceId; texHolder.Gtex = textureSection.Gtex; CubeMapFace[] faces = new CubeMapFace[] { CubeMapFace.NegativeX, CubeMapFace.NegativeY, CubeMapFace.NegativeZ, CubeMapFace.PositiveX, CubeMapFace.PositiveY, CubeMapFace.PositiveZ }; for (var i = 0; i < 6; i++) { var texData = cube.LockRectangle(faces[i], 0, LockFlags.None); texData.Data.Write(texHolder.Gtex.TextureData[i], 0, texHolder.Gtex.TextureData[i].Length); cube.UnlockRectangle(faces[i], 0); } } else { int numMipMaps = textureSection.Gtex.Header.MipMapCount; Format format = textureSection.Gtex.Format; texture = new Texture(device, texWidth, texHeight, numMipMaps, Usage.None, format, Pool.Managed); texHolder.Texture = texture; texHolder.Name = textureSection.ResourceId; texHolder.Gtex = textureSection.Gtex; for (var i = 0; i < numMipMaps; i++) { var texData = texture.LockRectangle(i, LockFlags.None); texData.Data.Write(texHolder.Gtex.TextureData[i], 0, texHolder.Gtex.TextureData[i].Length); texture.UnlockRectangle(i); } } TextureHolder removeMe; if (this.textureLookup.TryGetValue(texHolder.Name, out removeMe)) { removeMe.Texture.Dispose(); this.textures.Remove(removeMe); this.textureLookup.Remove(texHolder.Name); } this.textures.Add(texHolder); this.textureLookup.Add(texHolder.Name, texHolder); } catch { if (texture != null) { texture.Dispose(); } if (cube != null) { cube.Dispose(); } throw; } }