Skip to content

Commit

Permalink
アンカーモードで現在選択中の材質のボーンポリゴンをハイライト表示するように
Browse files Browse the repository at this point in the history
何も選択してない時にアンカー作成ボタンを押すとエラーが出るのを修正
ウィンドウの見た目が妙なのを修正
既定のボーンオブジェクトの強調色変更
  • Loading branch information
mfakane committed Jul 28, 2012
1 parent 77c7036 commit 154ffc0
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 34 deletions.
64 changes: 43 additions & 21 deletions Skeleton/MainPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public MainPlugin()
bone = new Metasequoia.Object
{
Name = "bone",
Color = new Color(1, 1, 0),
Color = new Color(1, 0.8f, 0.5f),
ColorValid = true,
};
this.BeginCallback(_ => _.AddObject(bone));
Expand All @@ -77,7 +77,11 @@ public MainPlugin()
e.Handled = e.Value;
};
this.IsActivated += (sender, e) => e.Handled = f.Visible;
this.MaterialList += (sender, e) => f.OnMaterialChanged(e.Document);
this.MaterialList += (sender, e) =>
{
f.OnMaterialChanged(e.Document);
this.BeginCallback(_ => this.RedrawAllScene());
};
this.ObjectList += (sender, e) => f.OnObjectChanged(e.Document);
this.Undo += (sender, e) =>
{
Expand Down Expand Up @@ -186,23 +190,24 @@ public MainPlugin()
EnsureBoneObject(e.Document);

if (bone != null)
this.BeginCallback(_ =>
{
createBonePointInfo = new CreateBonePointInfo
{
createBonePointInfo = new CreateBonePointInfo
{
BeginVertexIndex = CreateBone
(
_,
bone,
createBonePointInfo,
f.CreateNewMaterial,
f.BoneName
),
BeginWorld = createBonePointInfo.EndWorld,
};
f.OnBoneCreated();
this.UpdateUndo();
});
BeginVertexIndex = CreateBone
(
e.Document,
bone,
createBonePointInfo,
f.CreateNewMaterial,
f.BoneName
),
BeginWorld = createBonePointInfo.EndWorld,
};
f.OnBoneCreated();
this.UpdateUndo();
}
else
createBonePointInfo = null;
}
else
createBonePointInfo.HasEnd = false;
Expand All @@ -218,7 +223,7 @@ public MainPlugin()
var isDrag = Math.Abs(anchorSelect[1].Item1 - anchorSelect[0].Item1) > 4 || Math.Abs(anchorSelect[1].Item2 - anchorSelect[0].Item2) > 4;
var isAdd = Control.ModifierKeys.HasFlag(Keys.Shift);
var isRemove = Control.ModifierKeys.HasFlag(Keys.Control);

if (!isAdd & !isRemove)
e.Document.ClearSelect(Doc.ClearselectAll);

Expand Down Expand Up @@ -313,6 +318,19 @@ public MainPlugin()

break;
case SkeletonMode.Anchor:
EnsureBoneObject(e.Document);

if (bone != null)
using (var c = this.CreateDrawingObject(e.Document, DrawObjectVisibility.Point | DrawObjectVisibility.Line))
{
c.Color = highlightColor;
c.ColorValid = true;

foreach (var i in bone.Faces.Where(_ => _.Material == e.Document.CurrentMaterialIndex && _.PointCount == 3))
c.AddFace(i.Points.Select(_ => bone.Vertices[_].Point)
.Select(c.AddVertex));
}

if (anchorSelect != null)
using (var c = this.CreateDrawingObject(e.Document, DrawObjectVisibility.Line))
{
Expand Down Expand Up @@ -355,7 +373,7 @@ void CreateAnchor(Document doc, float margin, bool snap, bool autoMirror)
return;

var targetObject = doc.Objects[doc.CurrentObjectIndex];
var targetBoneFace = bone == null ? null : bone.Faces.FirstOrDefault(_ => _.Material == doc.CurrentMaterialIndex);
var targetBoneFace = bone == null ? null : bone.Faces.FirstOrDefault(_ => _.Material == doc.CurrentMaterialIndex && _.PointCount == 3);
var targetBone = targetBoneFace == null ? null : new Bone(doc, targetBoneFace);
var beginToEnd = targetBone == null ? Point.Zero : targetBone.End.Point - targetBone.Begin.Point;
var unit = new Point(0, 1, 0);
Expand All @@ -371,7 +389,7 @@ void CreateAnchor(Document doc, float margin, bool snap, bool autoMirror)
var targetBoneInverseMatrix = targetBone == null || !snap
? Matrix.Identity
: Matrix.Invert(targetBoneMatrix);
var anchorName = "anchor|" + targetObject.Name;
var anchorName = "anchor|" + targetObject.Name.Split(':').Last();

while (doc.Objects.Any(_ => _.Name == anchorName))
anchorName = anchorName.Replace("|", "_|");
Expand All @@ -380,6 +398,10 @@ void CreateAnchor(Document doc, float margin, bool snap, bool autoMirror)
.Where(_ => _.IsSelected)
.Select(_ => Point.Transform(_.Point, targetBoneInverseMatrix))
.ToArray();

if (!vertices.Any())
return;

var min = vertices.Aggregate(vertices.First(), (x, y) => new Point(Math.Min(x.X, y.X), Math.Min(x.Y, y.Y), Math.Min(x.Z, y.Z))) - margin;
var max = vertices.Aggregate(vertices.First(), (x, y) => new Point(Math.Max(x.X, y.X), Math.Max(x.Y, y.Y), Math.Max(x.Z, y.Z))) + margin;
var obj = new Metasequoia.Object
Expand Down
2 changes: 1 addition & 1 deletion Skeleton/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
[assembly: AssemblyCopyright("Copyright © mfakane 2012")]
[assembly: ComVisible(false)]
[assembly: Guid("62a49687-fcf7-4d1a-b800-a710ea906f22")]
[assembly: AssemblyVersion("0.0.*")]
[assembly: AssemblyVersion("0.1.*")]
11 changes: 11 additions & 0 deletions Skeleton/Skeleton.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ Keynote 向けのボーンポリゴンの作成を支援します。
更新履歴
=======

Version 0.2, Sat, 14 Jul 2012

アンカーモードで現在選択中の材質のボーンポリゴンをハイライト表示するように
何も選択してない時にアンカー作成ボタンを押すとエラーが出るのを修正
ウィンドウの見た目が妙なのを修正
既定のボーンオブジェクトの強調色変更

Version 0.1, Tue, 08 May 2012

オブジェクト名に sdef: などの指定子が含まれる際、アンカー作成でアンカー名にも含まれてしまうのを修正

Version 0.0, Wed, 18 Apr 2012

製作
Expand Down
21 changes: 10 additions & 11 deletions Skeleton/SkeletonForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Skeleton/SkeletonForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ partial class SkeletonForm : Form
{ "薬指2[]", "薬指3[]" },
{ "薬指3[]", "小指1[]" },
{ "小指1[]", "小指2[]" },
{ "小指2[]", "親指1[]" },
{ "小指2[]", "小指3[]" },
{ "小指3[]", "親指1[]" },
{ "親指1[]", "親指2[]" },
{ "下半身", "足[]" },
{ "足[]", "ひざ[]" },
Expand Down Expand Up @@ -114,6 +115,11 @@ public SkeletonMode Mode
public SkeletonForm()
{
InitializeComponent();

if (Application.RenderWithVisualStyles)
foreach (TabPage i in this.mainTabControl.TabPages)
i.BackColor = SystemColors.Window;

this.Font = SystemFonts.MessageBoxFont;
}

Expand Down

0 comments on commit 154ffc0

Please sign in to comment.