SkinRenderer - Add option to show skins bounding box

This commit is contained in:
miku-666
2024-10-09 14:34:18 +02:00
parent 522a1e70fb
commit 2c7bcf3285
2 changed files with 23 additions and 5 deletions

View File

@@ -48,6 +48,7 @@ namespace PckStudio.Forms.Editor
_settingsManager.AddSetting("lockMouse" , true , "Lock mouse when paning/rotating", state => renderer3D1.LockMousePosition = state);
_settingsManager.AddSetting("showGuidelines" , false, "Show guidelines" , state => renderer3D1.ShowGuideLines = state);
_settingsManager.AddSetting("showArmor" , false, "Show Armor" , state => renderer3D1.ShowArmor = state);
_settingsManager.AddSetting("showBoundingBox", false, "Show Bounding Box" , state => renderer3D1.ShowBoundingBox = state);
}
public CustomSkinEditor(Skin skin, bool inflateOverlayParts = false, bool allowInflate = false) : this()

View File

@@ -110,6 +110,7 @@ namespace PckStudio.Rendering
}
public bool CenterOnSelect { get; set; } = false;
public bool ShowBoundingBox { get; set; }
public bool ShowArmor { get; set; } = false;
public bool Animate { get; set; } = true;
public bool ShowGuideLines
@@ -184,6 +185,7 @@ namespace PckStudio.Rendering
private GuidelineMode guidelineMode { get; set; } = GuidelineMode.None;
private int[] selectedIndices = Array.Empty<int>();
private BoundingBox _skinBounds;
public Size TextureSize { get; private set; } = new Size(64, 64);
public Vector2 TillingFactor => new Vector2(1f / TextureSize.Width, 1f / TextureSize.Height);
@@ -265,6 +267,7 @@ namespace PckStudio.Rendering
{ "PANTS0" , rightLeg },
{ "PANTS1" , leftLeg },
};
CalculateSkinBounds();
InitializeArmorData();
InitializeCamera();
InitializeComponent();
@@ -681,6 +684,12 @@ namespace PckStudio.Rendering
default:
break;
}
CalculateSkinBounds();
}
private void CalculateSkinBounds()
{
_skinBounds = BoundingBox.GetEnclosingBoundingBox(meshStorage.Values.Select(item => item.GetBounds(Matrix4.Identity)));
}
private void AddCustomModelPart(SkinBOX skinBox)
@@ -920,10 +929,10 @@ namespace PckStudio.Rendering
RenderPart(cubeShader, offsetSpecificMeshStorage["CHEST"], Matrix4.Identity, transform);
if (!ANIM.GetFlag(SkinAnimFlag.RIGHT_ARM_DISABLED) || ANIM.GetFlag(SkinAnimFlag.FORCE_RIGHT_ARM_ARMOR))
RenderPart(cubeShader, offsetSpecificMeshStorage["SHOULDER0"], RightArmMatrix * armRightMatrix, transform);
RenderPart(cubeShader, offsetSpecificMeshStorage["SHOULDER0"], armRightMatrix, transform);
if (!ANIM.GetFlag(SkinAnimFlag.LEFT_ARM_DISABLED) || ANIM.GetFlag(SkinAnimFlag.FORCE_LEFT_ARM_ARMOR))
RenderPart(cubeShader, offsetSpecificMeshStorage["SHOULDER1"], LeftArmMatrix * armLeftMatrix, transform);
RenderPart(cubeShader, offsetSpecificMeshStorage["SHOULDER1"], armLeftMatrix, transform);
bool showRightLegArmor = !ANIM.GetFlag(SkinAnimFlag.RIGHT_LEG_DISABLED) || ANIM.GetFlag(SkinAnimFlag.FORCE_RIGHT_LEG_ARMOR);
if (showRightLegArmor)
@@ -997,10 +1006,18 @@ namespace PckStudio.Rendering
}
}
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.SrcColor);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.SrcColor);
DrawBoundingBox(boundingBoxTransform, boundingBox, HighlightlingColor);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
}
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
// Show skin bounds
if (ShowBoundingBox)
{
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.SrcColor);
DrawBoundingBox(transform, _skinBounds, Color.BurlyWood);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
}
}
// Ground plane
{