ModelEditor - Add highlighting of sinfgle model boxes

This commit is contained in:
miku-666
2025-05-27 21:44:07 +02:00
parent 2dee088dee
commit a757f22b41
4 changed files with 44 additions and 4 deletions

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ICSharpCode.SharpZipLib.Zip.Compression;
using System.Windows.Media;
using System.Windows;
using OMI.Formats.Model;
using PckStudio.Rendering;
using System.Numerics;
namespace PckStudio.Extensions
{
static class ModelBoxExtension
{
public static BoundingBox GetBoundingBox(this ModelBox modelBox)
{
Vector3 halfSize = modelBox.Size / 2f;
Vector3 halfSizeInflated = new Vector3(modelBox.Inflate) + halfSize;
Vector3 transformedCenter = modelBox.Position + halfSize;
Vector3 start = transformedCenter - halfSizeInflated;
Vector3 end = transformedCenter + halfSizeInflated;
return new BoundingBox(start, end);
}
}
}

View File

@@ -163,6 +163,7 @@ namespace PckStudio.Forms.Editor
private class ModelBoxNode : TreeNode
{
private ModelBox _modelBox;
public ModelBox Box => _modelBox;
private ModelBoxNode(ModelBox modelBox)
: base($"Box: pos:{modelBox.Position} size:{modelBox.Size}")
{
@@ -260,10 +261,12 @@ namespace PckStudio.Forms.Editor
{
modelViewport.Highlight(modelPartNode.Part);
}
//if (e.Node is ModelBoxNode modelBoxNode)
//{
//}
if (e.Node is ModelBoxNode modelBoxNode && modelBoxNode.Parent is ModelPartNode parentPartNode && parentPartNode.Parent is ModelNode parentNode1 &&
modelViewport.CurrentModelName == parentNode1.Model.Name)
{
modelViewport.Highlight(modelBoxNode.Box, parentPartNode.Part);
}
}
private IEnumerable<NamedTexture> GetModelTextures(string modelName)

View File

@@ -149,6 +149,7 @@
<Compile Include="Extensions\BoundingBoxExtensions.cs" />
<Compile Include="Extensions\MaterialContainerExtensions.cs" />
<Compile Include="Extensions\MaterialExtensions.cs" />
<Compile Include="Extensions\ModelBoxExtension.cs" />
<Compile Include="Extensions\PictureBoxExtensions.cs" />
<Compile Include="Extensions\TreeViewExtensions.cs" />
<Compile Include="Forms\Additional-Popups\FilterPrompt.cs">

View File

@@ -282,12 +282,19 @@ namespace PckStudio.Rendering
DrawBoundingBox(renderTransform, _maxBounds, Color.Red);
}
}
internal void Highlight(ModelPart part)
{
BoundingBox bb = part.GetBoxes().Select(b => new BoundingBox(b.Position, b.Position + b.Size)).GetEnclosingBoundingBox();
BoundingBox bb = part.GetBoxes().Select(b => b.GetBoundingBox()).GetEnclosingBoundingBox();
_highlightingInfo = new HighlightInfo(part.Translation, part.Rotation + part.AdditionalRotation, bb);
}
internal void Highlight(ModelBox box, ModelPart parent)
{
BoundingBox bb = box.GetBoundingBox();
_highlightingInfo = new HighlightInfo(parent.Translation, parent.Rotation + parent.AdditionalRotation, bb);
}
internal void ResetHighlight()
{
_highlightingInfo = HighlightInfo.Empty;