修改调试渲染逻辑和选中时效果

This commit is contained in:
ww-rm
2025-05-28 19:37:22 +08:00
parent 5aaca437af
commit 550dafb2c2
3 changed files with 26 additions and 10 deletions

View File

@@ -177,7 +177,6 @@ namespace Spine
// 拷贝调试属性 // 拷贝调试属性
EnableDebug = other.EnableDebug; EnableDebug = other.EnableDebug;
DebugTexture = other.DebugTexture; DebugTexture = other.DebugTexture;
DebugNonTexture = other.DebugNonTexture;
DebugBounds = other.DebugBounds; DebugBounds = other.DebugBounds;
DebugBones = other.DebugBones; DebugBones = other.DebugBones;
DebugRegions = other.DebugRegions; DebugRegions = other.DebugRegions;
@@ -253,15 +252,10 @@ namespace Spine
/// </summary> /// </summary>
public bool DebugTexture { get; set; } = true; public bool DebugTexture { get; set; } = true;
/// <summary>
/// 是否显示非纹理内容, 一个总开关
/// </summary>
public bool DebugNonTexture { get; set; } = true;
/// <summary> /// <summary>
/// 显示包围盒 /// 显示包围盒
/// </summary> /// </summary>
public bool DebugBounds { get; set; } = true; public bool DebugBounds { get; set; } = false;
/// <summary> /// <summary>
/// 显示骨骼 /// 显示骨骼
@@ -864,7 +858,7 @@ namespace Spine
else else
{ {
if (DebugTexture) DrawTexture(target, states); if (DebugTexture) DrawTexture(target, states);
if (DebugNonTexture) DrawNonTexture(target); DrawNonTexture(target);
} }
} }

View File

@@ -42,7 +42,7 @@ namespace SpineViewer.Models
/// </summary> /// </summary>
public SpineObjectModel(string skelPath, string? atlasPath = null, SpineVersion? version = null) public SpineObjectModel(string skelPath, string? atlasPath = null, SpineVersion? version = null)
{ {
_spineObject = new(skelPath, atlasPath, version) { DebugNonTexture = false }; _spineObject = new(skelPath, atlasPath, version);
_skins = _spineObject.Data.Skins.Select(v => v.Name).ToImmutableArray(); _skins = _spineObject.Data.Skins.Select(v => v.Name).ToImmutableArray();
_slotAttachments = _spineObject.Data.SlotAttachments.ToFrozenDictionary(it => it.Key, it => it.Value.Keys); _slotAttachments = _spineObject.Data.SlotAttachments.ToFrozenDictionary(it => it.Key, it => it.Value.Keys);
_animations = _spineObject.Data.Animations.Select(v => v.Name).ToImmutableArray(); _animations = _spineObject.Data.Animations.Select(v => v.Name).ToImmutableArray();
@@ -73,7 +73,7 @@ namespace SpineViewer.Models
public bool IsSelected public bool IsSelected
{ {
get { lock (_lock) return _isSelected; } get { lock (_lock) return _isSelected; }
set { lock (_lock) if (SetProperty(ref _isSelected, value)) _spineObject.DebugNonTexture = _isSelected; } set { lock (_lock) SetProperty(ref _isSelected, value); }
} }
private bool _isSelected = false; private bool _isSelected = false;

View File

@@ -31,6 +31,16 @@ namespace SpineViewer.ViewModels
private readonly ObservableCollectionWithLock<SpineObjectModel> _models; private readonly ObservableCollectionWithLock<SpineObjectModel> _models;
private readonly ISFMLRenderer _renderer; private readonly ISFMLRenderer _renderer;
/// <summary>
/// 被选中对象的背景颜色
/// </summary>
private static readonly SFML.Graphics.Color _selectedBackgroundColor = new(255, 255, 255, 50);
/// <summary>
/// 被选中对象背景顶点缓冲区
/// </summary>
private readonly SFML.Graphics.VertexArray _selectedBackgroundVertices = new(SFML.Graphics.PrimitiveType.Quads, 4); // XXX: 暂时未使用 Dispose 释放
/// <summary> /// <summary>
/// 预览画面坐标轴颜色 /// 预览画面坐标轴颜色
/// </summary> /// </summary>
@@ -381,6 +391,18 @@ namespace SpineViewer.ViewModels
sp.Update(0); // 避免物理效果出现问题 sp.Update(0); // 避免物理效果出现问题
sp.Update(delta); sp.Update(delta);
// 为选中对象绘制一个半透明背景
if (sp.IsSelected)
{
var rc = sp.GetCurrentBounds().ToFloatRect();
_selectedBackgroundVertices[0] = new(new(rc.Left, rc.Top), _selectedBackgroundColor);
_selectedBackgroundVertices[1] = new(new(rc.Left + rc.Width, rc.Top), _selectedBackgroundColor);
_selectedBackgroundVertices[2] = new(new(rc.Left + rc.Width, rc.Top + rc.Height), _selectedBackgroundColor);
_selectedBackgroundVertices[3] = new(new(rc.Left, rc.Top + rc.Height), _selectedBackgroundColor);
_renderer.Draw(_selectedBackgroundVertices);
}
// 仅在预览画面临时启用调试模式
sp.EnableDebug = true; sp.EnableDebug = true;
_renderer.Draw(sp); _renderer.Draw(sp);
sp.EnableDebug = false; sp.EnableDebug = false;