mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-12 13:31:56 +00:00
CustomSkinEditor - Add simple conversion to overlay part when importing block bench models
This commit is contained in:
@@ -46,23 +46,35 @@ namespace PckStudio.Extensions
|
||||
|
||||
}
|
||||
|
||||
public static GraphicsPath GetUVGraphicsPath(this SkinBOX skinBOX)
|
||||
public static GraphicsPath GetUVGraphicsPath(this SkinBOX skinBox)
|
||||
{
|
||||
return skinBOX.GetUVGraphicsPath(Vector2.One);
|
||||
return skinBox.GetUVGraphicsPath(Vector2.One);
|
||||
}
|
||||
|
||||
public static bool IsOverlayPart(this SkinBOX skinBOX)
|
||||
public static string GetOverlayType(this SkinBOX skinBox)
|
||||
{
|
||||
return skinBOX.Type switch
|
||||
{
|
||||
"HEADWEAR" or
|
||||
"JACKET" or
|
||||
"SLEEVE0" or
|
||||
"SLEEVE1" or
|
||||
"PANTS0" or
|
||||
"PANTS1" => true,
|
||||
_ => false,
|
||||
};
|
||||
if (!skinBox.IsValidType())
|
||||
return "";
|
||||
int index = Array.IndexOf(SkinBOX.BaseTypes, skinBox.Type);
|
||||
return SkinBOX.OverlayTypes.IndexInRange(index) ? SkinBOX.OverlayTypes[index] : "";
|
||||
}
|
||||
|
||||
public static string GetBaseType(this SkinBOX skinBox)
|
||||
{
|
||||
if (!skinBox.IsValidType())
|
||||
return "";
|
||||
int index = Array.IndexOf(SkinBOX.OverlayTypes, skinBox.Type);
|
||||
return SkinBOX.BaseTypes.IndexInRange(index) ? SkinBOX.BaseTypes[index] : "";
|
||||
}
|
||||
|
||||
public static bool IsBasePart(this SkinBOX skinBox)
|
||||
{
|
||||
return SkinBOX.BaseTypes.Contains(skinBox.Type);
|
||||
}
|
||||
|
||||
public static bool IsOverlayPart(this SkinBOX skinBox)
|
||||
{
|
||||
return SkinBOX.OverlayTypes.Contains(skinBox.Type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,22 +246,21 @@ namespace PckStudio.Forms.Editor
|
||||
_skin.ANIM.SetFlag(SkinAnimFlag.LEFT_LEG_OVERLAY_DISABLED, true);
|
||||
|
||||
|
||||
// IMPROVMENT: detect default body parts and toggle anim flag instead of adding box data -miku
|
||||
foreach (Outline outline in blockBenchModel.Outliner)
|
||||
{
|
||||
string type = outline.Name;
|
||||
if (!SkinBOX.IsValidType(type))
|
||||
continue;
|
||||
foreach (Element element in blockBenchModel.Elements.Where(e => outline.Children.Contains(e.Uuid)))
|
||||
{
|
||||
if (!element.UseBoxUv || !element.Visibility)
|
||||
continue;
|
||||
|
||||
//Debug.WriteLine($"{type} {element.Name}({element.Uuid})");
|
||||
BoundingBox boundingBox = new BoundingBox(element.From.ToOpenTKVector(), element.To.ToOpenTKVector());
|
||||
Vector3 pos = boundingBox.Start.ToNumericsVector();
|
||||
Vector3 size = boundingBox.Volume.ToNumericsVector();
|
||||
|
||||
//Debug.WriteLine($"{outline.Name} {element.Name}({element.Uuid})");
|
||||
//Debug.WriteLine($"boundingBox.Start({boundingBox.Start})");
|
||||
//Debug.WriteLine($"boundingBox.End({boundingBox.End})");
|
||||
//Debug.WriteLine($"size({size})");
|
||||
Vector2 uv = element.UvOffset;
|
||||
|
||||
Vector3 transformUnit = new Vector3(-1, -1, 1);
|
||||
Vector3 coordinateUnit = new Vector3(1, 1, 0);
|
||||
@@ -270,15 +269,19 @@ namespace PckStudio.Forms.Editor
|
||||
pos -= size * coordinateUnit;
|
||||
pos.Y += 24f;
|
||||
|
||||
Vector3 translation = renderer3D1.GetTranslation(outline.Name).ToNumericsVector();
|
||||
Vector3 pivot = renderer3D1.GetPivot(outline.Name).ToNumericsVector();
|
||||
Vector3 translation = renderer3D1.GetTranslation(type).ToNumericsVector();
|
||||
Vector3 pivot = renderer3D1.GetPivot(type).ToNumericsVector();
|
||||
|
||||
pos += translation * -Vector3.UnitX - pivot * Vector3.UnitY;
|
||||
//Debug.WriteLine(translation);
|
||||
//Debug.WriteLine(pivot);
|
||||
//Debug.WriteLine(pos);
|
||||
|
||||
_skin.AdditionalBoxes.Add(new SkinBOX(outline.Name, pos, size, element.UvOffset));
|
||||
// IMPROVMENT: detect default body parts and toggle anim flag instead of adding box data -miku
|
||||
|
||||
var box = new SkinBOX(type, pos, size, uv);
|
||||
if (box.IsBasePart() && element.Inflate == 0.5f)
|
||||
box.Type = box.GetOverlayType();
|
||||
|
||||
_skin.AdditionalBoxes.Add(box);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -89,6 +89,10 @@ namespace PckStudio.Internal
|
||||
return skinBox;
|
||||
}
|
||||
|
||||
public bool IsValidType() => IsValidType(Type);
|
||||
|
||||
public static bool IsValidType(string type) => ValidBoxTypes.Contains(type);
|
||||
|
||||
public KeyValuePair<string, string> ToProperty()
|
||||
{
|
||||
return new KeyValuePair<string, string>("BOX", ToString());
|
||||
|
||||
Reference in New Issue
Block a user