Skip to content

Instantly share code, notes, and snippets.

@tracebox55
Last active March 7, 2018 12:04
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/f5cc182729ad0c48aa58 to your computer and use it in GitHub Desktop.
Save tracebox55/f5cc182729ad0c48aa58 to your computer and use it in GitHub Desktop.
[PMDE]頂点モーフを合成する
/// <summary>
/// [PMDE]頂点モーフを合成する
/// [簡易形式]MixVertexMorph.cx
/// 複数の頂点モーフを割合を指定して合成します。
/// </summary>
string[] Option = new string[10];
string TargetName = "まばたきNEW"; // 作成モーフ名(同名モーフが既存なら上書き)
// 以下に合成するモーフ名(と倍率・省略可)を列挙(10個まで)
Option[0] = "まばたき,1";
Option[1] = "右上,1";
Option[2] = "右下,1";
Option[3] = "左上,1";
Option[4] = "左下,1";
// 名前からモーフ番号を得る
Func<string, int> getMorph = delegate(string name)
{
foreach (IPXMorph m in morph)
{
if (m.Name == name)
{
return morph.IndexOf(m);
}
}
return -1;
};
// 新規モーフ作成
IPXMorph newMorph;
int targetIndex = getMorph(TargetName);
if (targetIndex >= 0)
{
// 同名のモーフがあれば基本情報を複製(最終的に入れ替える)
newMorph = (IPXMorph)morph[targetIndex].Clone();
newMorph.Offsets.Clear(); // モーフ情報は初期化しておく
}
else
{
// 同名のモーフがなければ新規作成
newMorph = bdx.Morph();
newMorph.Name = TargetName;
newMorph.Kind = MorphKind.Vertex;
}
// 追加するモーフを順次処理する
foreach (string s in Option)
{
if (s == null || s.Length == 0)
{
continue;
}
string[] optary = s.Split(',');
if (optary.Length > 0)
{
string morphname = optary[0]; // 追加するモーフ名
float morphratio = 1f; // 割合(指定なしならデフォルト1.0)
if (optary.Length > 1)
{
try
{
morphratio = float.Parse(optary[1]);
}
catch
{
}
}
int morphindex = getMorph(morphname);
if (morphindex >= 0 && morph[morphindex].Kind == MorphKind.Vertex) // 追加するモーフが存在する頂点モーフか?
{
foreach (IPXVertexMorphOffset e in morph[morphindex].Offsets)
{
IPXVertexMorphOffset moo = bdx.VertexMorphOffset();
moo.Vertex = e.Vertex;
moo.Offset = e.Offset * morphratio;
newMorph.Offsets.Add(moo);
}
// 追加するモーフのパネルと同じにする
if (targetIndex < 0)
{
newMorph.Panel = morph[morphindex].Panel;
}
}
}
}
// 反映処理
if (newMorph.Offsets.Count > 0)
{
if (targetIndex < 0)
{
// 新規追加
morph.Add(newMorph);
}
else
{
// モーフオフセットの上書き
morph[targetIndex].Offsets.Clear();
foreach (IPXVertexMorphOffset e in newMorph.Offsets)
{
morph[targetIndex].Offsets.Add(e);
}
}
// 更新
connect.Pmx.Update(pmx);
connect.Form.UpdateList(UpdateObject.All);
connect.View.PMDView.UpdateModel();
connect.View.PMDView.UpdateView();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment