Skip to content

Instantly share code, notes, and snippets.

@tracebox55
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tracebox55/c8a3c874e58729ab75b8 to your computer and use it in GitHub Desktop.
Save tracebox55/c8a3c874e58729ab75b8 to your computer and use it in GitHub Desktop.
[PMDE]頂点モーフから選択頂点のみを抜き出す
/// <summary>
/// [PMDE]頂点モーフから選択頂点のみを抜き出す
/// [簡易形式]ExtractVertexFromMorph.cx
/// PMDEのリストから対象のモーフを選択し、PMDViewで頂点を選択して使用します
/// </summary>
// 処理元のモーフ取得
int selectedMorph = connect.Form.SelectedExpressionIndex;
if (selectedMorph < 0)
{
throw new Exception("モーフが選択されていません。");
}
IPXMorph srcMorph = morph[selectedMorph];
if (srcMorph.Kind != MorphKind.Vertex)
{
throw new Exception(string.Format("'{0}' は頂点モーフではありません。", srcMorph.Name));
}
// 選択中のモーフ取得
int[] vlist = view.GetSelectedVertexIndices();
if (vlist.Length == 0)
{
throw new Exception("頂点が選択されていない。");
}
// 新規モーフ作成
IPXMorph dstMorph = bdx.Morph();
dstMorph.Name = srcMorph.Name + "NEW"; // 処理元モーフの名前にNEWを付けた名前で作成
dstMorph.NameE = srcMorph.NameE;
dstMorph.Panel = srcMorph.Panel; // 表示パネルは処理元を継承
dstMorph.Kind = srcMorph.Kind;
// 処理元モーフのうち選択中頂点の情報のみコピーする
foreach (IPXVertexMorphOffset mo in srcMorph.Offsets)
{
if( Array.IndexOf(vlist, vertex.IndexOf(mo.Vertex)) >= 0 ) // 選択中頂点?
{
dstMorph.Offsets.Add(mo); // 新規モーフに情報コピー
}
}
// 新規モーフを反映
if (dstMorph.Offsets.Count > 0)
{
morph.Add(dstMorph);
connect.Pmx.Update(pmx);
connect.Form.UpdateList(UpdateObject.All);
connect.View.PMDView.UpdateModel();
connect.View.PMDView.UpdateView();
MessageBox.Show(string.Format("'{0}' を作成しました。", dstMorph.Name));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment