Skip to content

Commit

Permalink
CustomSkinEditor - Re-Implemented 'GenerateUVTextureMap'
Browse files Browse the repository at this point in the history
  • Loading branch information
NessieHax committed Feb 7, 2024
1 parent 2f72a44 commit 41b8144
Showing 1 changed file with 15 additions and 26 deletions.
41 changes: 15 additions & 26 deletions PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public partial class CustomSkinEditor : MetroForm
public Image PreviewImage => _previewImage;

private PckFileData _file;
private Random rng;

private BindingSource skinPartListBindingSource;
private BindingSource skinOffsetListBindingSource;
Expand All @@ -39,11 +40,11 @@ public CustomSkinEditor(PckFileData file)
InitializeComponent();

_file = file;
rng = new Random();
if (_file.Size > 0)
{
uvPictureBox.BackgroundImage = renderer3D1.Texture = _file.GetTexture();
renderer3D1.Texture = _file.GetTexture();
}
//comboParent.Items.AddRange(ValidModelBoxTypes);
LoadModelData(file.Properties);
}

Expand All @@ -64,44 +65,32 @@ private void LoadModelData(PckFileProperties properties)

skinOffsetListBindingSource = new BindingSource(renderer3D1.PartOffsets, null);
offsetListBox.DataSource = skinOffsetListBindingSource;
//offsetListBox.DisplayMember = ""
}

// TODO
private void GenerateUVTextureMap()
private void GenerateUVTextureMap(SkinBOX skinBox)
{
Random rng = new Random();
using (Graphics graphics = Graphics.FromImage(uvPictureBox.Image))
using (Graphics graphics = Graphics.FromImage(uvPictureBox.BackgroundImage))
{
graphics.ApplyConfig(_graphicsConfig);
//foreach (var part in modelBoxes)
//{
// float width = part.Size.X * 2;
// float height = part.Size.Y * 2;
// float length = part.Size.Z * 2;
// float u = part.UV.X * 2;
// float v = part.UV.Y * 2;
// int argb = rng.Next(-16777216, -1); // 0xFF000000 - 0xFFFFFFFF
// var color = Color.FromArgb(argb);
// Brush brush = new SolidBrush(color);
// graphics.FillRectangle(brush, u + length, v, width, length);
// graphics.FillRectangle(brush, u + length + width, v, width, length);
// graphics.FillRectangle(brush, u, length + v, length, height);
// graphics.FillRectangle(brush, u + length, v + length, width, height);
// graphics.FillRectangle(brush, u + length + width, v + length, width, height);
// graphics.FillRectangle(brush, u + length + width * 2, v + length, length, height);
//}
int argb = rng.Next(unchecked((int)0xFF000000), -1);
var color = Color.FromArgb(argb);
Brush brush = new SolidBrush(color);
graphics.FillPath(brush, skinBox.GetUVGraphicsPath());
}
uvPictureBox.Invalidate();
renderer3D1.Texture = uvPictureBox.BackgroundImage;
}

private void createToolStripMenuItem_Click(object sender, EventArgs e)
{
var boxEditor = new BoxEditor(SkinBOX.Empty, false);
if (boxEditor.ShowDialog() == DialogResult.OK)
{
renderer3D1.ModelData.Add(boxEditor.Result);
var newBox = boxEditor.Result;
renderer3D1.ModelData.Add(newBox);
skinPartListBindingSource.ResetBindings(false);
if (generateTextureCheckBox.Checked)
GenerateUVTextureMap(newBox);
}
}

Expand Down Expand Up @@ -164,7 +153,7 @@ private void buttonExportModel_Click(object sender, EventArgs e)
}

[Obsolete("Kept for backwards compatibility, remove later.")]
private void buttonImportModel_Click(object sender, EventArgs e)
private void importCustomSkinButton_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Custom Skin Model File | *.CSM";
Expand Down

0 comments on commit 41b8144

Please sign in to comment.