diff --git a/PCK-Studio/Extensions/SkinBOXExtensions.cs b/PCK-Studio/Extensions/SkinBOXExtensions.cs index ad02584b..4e211bf1 100644 --- a/PCK-Studio/Extensions/SkinBOXExtensions.cs +++ b/PCK-Studio/Extensions/SkinBOXExtensions.cs @@ -50,5 +50,19 @@ namespace PckStudio.Extensions { return skinBOX.GetUVGraphicsPath(Vector2.One); } + + public static bool IsOverlayPart(this SkinBOX skinBOX) + { + return skinBOX.Type switch + { + "HEADWEAR" or + "JACKET" or + "SLEEVE0" or + "SLEEVE1" or + "PANTS0" or + "PANTS1" => true, + _ => false, + }; + } } } diff --git a/PCK-Studio/Forms/Editor/CustomSkinEditor.cs b/PCK-Studio/Forms/Editor/CustomSkinEditor.cs index 32ef3e4c..fb50c805 100644 --- a/PCK-Studio/Forms/Editor/CustomSkinEditor.cs +++ b/PCK-Studio/Forms/Editor/CustomSkinEditor.cs @@ -28,6 +28,8 @@ namespace PckStudio.Forms.Editor private Image _previewImage; private Skin _skin; private Random rng; + private bool _inflateOverlayParts; + private bool _allowInflate; private BindingSource skinPartListBindingSource; private BindingSource skinOffsetListBindingSource; @@ -44,15 +46,17 @@ namespace PckStudio.Forms.Editor rng = new Random(); } - public CustomSkinEditor(Skin skin) : this() + public CustomSkinEditor(Skin skin, bool inflateOverlayParts = false, bool allowInflate = false) : this() { _skin = skin; + _allowInflate = allowInflate; + _inflateOverlayParts = inflateOverlayParts; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); - renderer3D1.InitializeGL(); + renderer3D1.InitializeGL(_inflateOverlayParts); if (_skin.Texture is not null) { renderer3D1.Texture = _skin.Texture; @@ -102,7 +106,7 @@ namespace PckStudio.Forms.Editor private void createToolStripMenuItem_Click(object sender, EventArgs e) { - var boxEditor = new BoxEditor(SkinBOX.Empty, true); + var boxEditor = new BoxEditor(SkinBOX.Empty, _allowInflate); if (boxEditor.ShowDialog() == DialogResult.OK) { var newBox = boxEditor.Result; @@ -162,19 +166,6 @@ namespace PckStudio.Forms.Editor "Custom Skin Model Binary File (*.csmb)|*.csmb|"; if (saveFileDialog.ShowDialog() != DialogResult.OK) return; - //string contents = ""; - //foreach (ListViewItem listViewItem in listViewBoxes.Items) - //{ - // string str = ""; - // foreach (ListViewItem.ListViewSubItem subItem in listViewItem.SubItems) - // { - // if (subItem.Text != "unchecked") - // str = str + subItem.Text + Environment.NewLine; - // } - // contents += (listViewItem.Text + Environment.NewLine + listViewItem.Tag) + Environment.NewLine + str; - //} - - //File.WriteAllText(saveFileDialog.FileName, contents); } [Obsolete("Kept for backwards compatibility.")] @@ -289,7 +280,7 @@ namespace PckStudio.Forms.Editor { if (skinPartListBox.SelectedItem is SkinBOX box) { - var boxEditor = new BoxEditor(box, true); + var boxEditor = new BoxEditor(box, _allowInflate); if (boxEditor.ShowDialog() == DialogResult.OK) { renderer3D1.ModelData[skinPartListBox.SelectedIndex] = boxEditor.Result; diff --git a/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.cs b/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.cs index 68108ddd..ad985253 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.cs @@ -28,7 +28,7 @@ namespace PckStudio.Forms protected override void OnLoad(EventArgs e) { base.OnLoad(e); - ModelView.InitializeGL(); + ModelView.InitializeGL(true); foreach (var item in data) { ModelView.ModelData.Add(item); diff --git a/PCK-Studio/Rendering/CubeGroupMesh.cs b/PCK-Studio/Rendering/CubeGroupMesh.cs index 79967273..0a142e24 100644 --- a/PCK-Studio/Rendering/CubeGroupMesh.cs +++ b/PCK-Studio/Rendering/CubeGroupMesh.cs @@ -28,13 +28,23 @@ namespace PckStudio.Rendering internal class CubeGroupMesh : GenericMesh { private List cubes; + + public bool FlipZMapping + { + get => _flipZMapping; + set + { + _flipZMapping = value; + UpdateCollection(); + } + } - public float Inflate { get; set; } = 0f; - public bool FlipZMapping { get; set; } = false; public Vector3 Translation { get; set; } = Vector3.Zero; public Vector3 Pivot { get; set; } = Vector3.Zero; public Vector3 Offset { get; set; } = Vector3.Zero; + private bool _flipZMapping = false; + internal CubeGroupMesh(string name) : base(name, PrimitiveType.Triangles) { cubes = new List(5); @@ -46,12 +56,6 @@ namespace PckStudio.Rendering FlipZMapping = flipZMapping; } - internal CubeGroupMesh(string name, float inflate) - : this(name) - { - Inflate = inflate; - } - public static VertexBufferLayout GetLayout() { var layout = new VertexBufferLayout(); @@ -60,10 +64,11 @@ namespace PckStudio.Rendering return layout; } - internal void AddSkinBox(SkinBOX skinBox) + internal void AddSkinBox(SkinBOX skinBox, float inflate = 0f) { var cube = CubeMesh.Create(skinBox); cube.FlipZMapping = FlipZMapping; + cube.Inflate += inflate; cubes.Add(cube); } @@ -94,9 +99,9 @@ namespace PckStudio.Rendering Submit(); } - internal void AddCube(Vector3 position, Vector3 size, Vector2 uv, float inflate = 0f, bool mirrorTexture = false, bool flipZMapping = false) + internal void AddCube(Vector3 position, Vector3 size, Vector2 uv, float inflate = 0f, bool mirrorTexture = false) { - var cube = new CubeMesh(position, size, uv, Inflate + inflate, mirrorTexture, flipZMapping || FlipZMapping); + var cube = new CubeMesh(position, size, uv, inflate, mirrorTexture, FlipZMapping); cubes.Add(cube); } @@ -118,10 +123,18 @@ namespace PckStudio.Rendering cube.Position = position; cube.Size = size; cube.Uv = uv; - cube.Inflate = Inflate + inflate; + cube.Inflate = inflate; cube.MirrorTexture = mirrorTexture; } + private void UpdateCollection() + { + foreach (var cube in cubes) + { + cube.FlipZMapping = FlipZMapping; + } + } + private Vector3 Transform { get diff --git a/PCK-Studio/Rendering/SkinRenderer.cs b/PCK-Studio/Rendering/SkinRenderer.cs index cde39272..f73773dd 100644 --- a/PCK-Studio/Rendering/SkinRenderer.cs +++ b/PCK-Studio/Rendering/SkinRenderer.cs @@ -181,8 +181,6 @@ namespace PckStudio.Rendering private DrawContext _skyboxRenderBuffer; private CubeTexture _skyboxTexture; - private float skyboxRotation = 0f; - private float skyboxRotationStep = 0.5f; private Dictionary meshStorage; private Dictionary offsetSpecificMeshStorage; @@ -199,6 +197,7 @@ namespace PckStudio.Rendering private float animationMaxAngleInDegrees = 5f; private bool showWireFrame = false; + private bool autoInflateOverlayParts; private Matrix4 RightArmMatrix { get; set; } = Matrix4.CreateFromAxisAngle(Vector3.UnitZ, 25f); private Matrix4 LeftArmMatrix { get; set; } = Matrix4.CreateFromAxisAngle(Vector3.UnitZ, -25f); @@ -260,8 +259,11 @@ namespace PckStudio.Rendering ModelData.CollectionChanged += ModelData_CollectionChanged; } - public void InitializeGL() + public void InitializeGL(bool inflateOverlayParts) { + if (initialized) + Debug.Fail("Already Initialized!"); + autoInflateOverlayParts = inflateOverlayParts; MakeCurrent(); InitializeShaders(); InitializeFramebuffer(); @@ -329,44 +331,44 @@ namespace PckStudio.Rendering { const float armorInflation = 0.75f; - var helmet = new CubeGroupMesh("HELMET", armorInflation); - helmet.AddCube(new(-4, -8, -4), new(8, 8, 8), new(0, 0)); + var helmet = new CubeGroupMesh("HELMET"); + helmet.AddCube(new(-4, -8, -4), new(8, 8, 8), new(0, 0), inflate: armorInflation); - var chest = new CubeGroupMesh("CHEST", armorInflation); - chest.AddCube(new(-4, 0, -2), new(8, 12, 4), new(16, 16)); + var chest = new CubeGroupMesh("CHEST"); + chest.AddCube(new(-4, 0, -2), new(8, 12, 4), new(16, 16), inflate: armorInflation + 0.01f); - var shoulder0 = new CubeGroupMesh("SHOULDER0", armorInflation); + var shoulder0 = new CubeGroupMesh("SHOULDER0"); shoulder0.Pivot = new Vector3(4f, 2f, 0f); shoulder0.Translation = new Vector3(-5f, -2f, 0f); - shoulder0.AddCube(new(-3, -2, -2), new(4, 12, 4), new(40, 16)); + shoulder0.AddCube(new(-3, -2, -2), new(4, 12, 4), new(40, 16), inflate: armorInflation); - var shoulder1 = new CubeGroupMesh("SHOULDER1", armorInflation); + var shoulder1 = new CubeGroupMesh("SHOULDER1"); shoulder1.Pivot = new Vector3(-4f, 2f, 0f); shoulder1.Translation = new Vector3(5f, -2f, 0f); - shoulder1.AddCube(new(-1, -2, -2), new(4, 12, 4), new(40, 16), mirrorTexture: true); + shoulder1.AddCube(new(-1, -2, -2), new(4, 12, 4), new(40, 16), inflate: armorInflation, mirrorTexture: true); - var waist = new CubeGroupMesh("WAIST", armorInflation - 0.1f); - waist.AddCube(new(-4, 0, -2), new(8, 12, 4), new(16, 48)); + var waist = new CubeGroupMesh("WAIST"); + waist.AddCube(new(-4, 0, -2), new(8, 12, 4), new(16, 48), inflate: armorInflation); - var pants0 = new CubeGroupMesh("PANTS0", armorInflation); + var pants0 = new CubeGroupMesh("PANTS0"); pants0.Pivot = new Vector3(0f, 12f, 0f); pants0.Translation = new Vector3(-2f, -12f, 0f); - pants0.AddCube(new(-2, 0, -2), new(4, 12, 4), new(0, 48)); + pants0.AddCube(new(-2, 0, -2), new(4, 12, 4), new(0, 48), inflate: armorInflation); - var pants1 = new CubeGroupMesh("PANTS1", armorInflation); + var pants1 = new CubeGroupMesh("PANTS1"); pants1.Pivot = new Vector3(0f, 12f, 0f); pants1.Translation = new Vector3(2f, -12f, 0f); - pants1.AddCube(new(-2, 0, -2), new(4, 12, 4), new(0, 48), mirrorTexture: true); + pants1.AddCube(new(-2, 0, -2), new(4, 12, 4), new(0, 48), inflate: armorInflation, mirrorTexture: true); - var boot0 = new CubeGroupMesh("BOOT0", armorInflation + 0.25f); + var boot0 = new CubeGroupMesh("BOOT0"); boot0.Pivot = new Vector3(0f, 12f, 0f); boot0.Translation = new Vector3(-2f, -12f, 0f); - boot0.AddCube(new(-2, 0, -2), new(4, 12, 4), new(0, 16)); + boot0.AddCube(new(-2, 0, -2), new(4, 12, 4), new(0, 16), inflate: armorInflation + 0.25f); - var boot1 = new CubeGroupMesh("BOOT1", armorInflation + 0.25f); + var boot1 = new CubeGroupMesh("BOOT1"); boot1.Pivot = new Vector3(0f, 12f, 0f); boot1.Translation = new Vector3(2f, -12f, 0f); - boot1.AddCube(new(-2, 0, -2), new(4, 12, 4), new(0, 16), mirrorTexture: true); + boot1.AddCube(new(-2, 0, -2), new(4, 12, 4), new(0, 16), inflate: armorInflation + 0.25f, mirrorTexture: true); offsetSpecificMeshStorage = new Dictionary { @@ -423,8 +425,6 @@ namespace PckStudio.Rendering skinTexture.WrapS = TextureWrapMode.Repeat; skinTexture.WrapT = TextureWrapMode.Repeat; - Texture ??= Resources.classic_template; - GLErrorCheck(); } @@ -613,7 +613,6 @@ namespace PckStudio.Rendering d_debugDrawContext = new DrawContext(vao, debugVBO.GenIndexBuffer(), PrimitiveType.Points); } #endif - } private DrawContext GetGuidelineDrawContext() @@ -752,7 +751,7 @@ namespace PckStudio.Rendering throw new KeyNotFoundException(skinBox.Type); CubeGroupMesh cubeMesh = meshStorage[skinBox.Type]; - cubeMesh.AddSkinBox(skinBox); + cubeMesh.AddSkinBox(skinBox, autoInflateOverlayParts && skinBox.IsOverlayPart() ? OverlayScale : 0f); } [Conditional("DEBUG")]