mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-07-13 17:28:08 +00:00
ModelEditor - Add highlighting of sinfgle model boxes
This commit is contained in:
29
PCK-Studio/Extensions/ModelBoxExtension.cs
Normal file
29
PCK-Studio/Extensions/ModelBoxExtension.cs
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user