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/b9005acfebd185ae3296 to your computer and use it in GitHub Desktop.
Save tracebox55/b9005acfebd185ae3296 to your computer and use it in GitHub Desktop.
[PMDE]選択頂点の鏡像選択
/// <summary>
/// [PMDE]選択頂点の鏡像選択
/// [簡易形式]SelectMirror.cx
/// 選択中頂点の鏡像を選択しなおします。SHIFT実行で追加選択となります。
/// </summary>
// 選択中の頂点
int[] selectedV = view.GetSelectedVertexIndices();
if (selectedV.Length == 0)
{
throw new Exception("頂点は選択されていません。");
}
HashSet<int> selectedVH = new HashSet<int>();
foreach (int i in selectedV)
{
selectedVH.Add(i);
}
// 処理対象頂点辞書
HashSet<int> targetV = new HashSet<int>();
if (connect.View.PMDViewHelper.PartsSelect.SelectObject == PartsSelectObject.Material)
{
foreach(int mi in connect.View.PMDViewHelper.PartsSelect.GetCheckedMaterialIndices())
{
foreach(IPXFace f in material[mi].Faces)
{
targetV.Add(vertex.IndexOf(f.Vertex1));
targetV.Add(vertex.IndexOf(f.Vertex2));
targetV.Add(vertex.IndexOf(f.Vertex3));
}
}
}else{
for(int i = 0; i < vertex.Count; i++)
{
targetV.Add(i);
}
}
// 結果記憶領域
HashSet<int> result = new HashSet<int>();
// 選択中頂点に対して順次調査する
foreach (int vi in selectedV)
{
// 相対位置
V3 pos1 = new V3(vertex[vi].Position);
pos1.X = pos1.X * -1f; // 左右反転
float shortest = float.MaxValue; // 最短距離
int foundV = -1; // 特定した頂点
foreach (int vi2 in targetV)
{
if (!result.Contains(vi2) && !selectedVH.Contains(vi2)) // 選択中と選択済みは検索から除外
{
V3 pos2 = vertex[vi2].Position;
float distance = (float)Math.Sqrt((Math.Pow(pos1.X - pos2.X, 2) + Math.Pow(pos1.Y - pos2.Y, 2) + Math.Pow(pos1.Z - pos2.Z, 2)));
if (distance < shortest)
{
foundV = vi2;
shortest = distance;
}
}
}
if (foundV != -1)
{
result.Add(foundV);
}
}
// 選択状態にする
if (result.Count > 0)
{
// SHIFTキーが選択状態を残す
if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
{
foreach (int vi in selectedV)
{
result.Add(vi);
}
}
view.SetSelectedVertexIndices(result.ToArray());
connect.View.PMDView.UpdateView();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment