ReductionData.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Magica Cloth.
  2. // Copyright (c) MagicaSoft, 2020-2022.
  3. // https://magicasoft.jp
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. namespace MagicaReductionMesh
  7. {
  8. /// <summary>
  9. /// リダクション
  10. /// </summary>
  11. public class ReductionData : ReductionMeshAccess
  12. {
  13. //=========================================================================================
  14. /// <summary>
  15. /// ゼロ距離の頂点をマージする
  16. /// </summary>
  17. public void ReductionZeroDistance(float radius = 0.0001f)
  18. {
  19. var reduction = new NearPointReduction(radius);
  20. reduction.Create(MeshData);
  21. reduction.Reduction();
  22. }
  23. //=========================================================================================
  24. /// <summary>
  25. /// 指定半径の頂点をまとめる
  26. /// </summary>
  27. /// <param name="radius"></param>
  28. public void ReductionRadius(float radius)
  29. {
  30. var reduction = new NearPointReduction(radius);
  31. reduction.Create(MeshData);
  32. reduction.Reduction();
  33. }
  34. //=========================================================================================
  35. /// <summary>
  36. /// ポリゴンの接続のみを利用した距離マージ
  37. /// </summary>
  38. /// <param name="length"></param>
  39. public void ReductionPolygonLink(float length)
  40. {
  41. var reduction = new PolygonLinkReduction(length);
  42. reduction.Create(MeshData);
  43. reduction.Reduction();
  44. }
  45. //=========================================================================================
  46. /// <summary>
  47. /// 未使用のボーンを削除する
  48. /// </summary>
  49. public void ReductionBone()
  50. {
  51. var boneSet = new HashSet<Transform>();
  52. foreach (var sv in MeshData.shareVertexList)
  53. {
  54. for (int i = 0; i < sv.boneWeightList.Count; i++)
  55. {
  56. var w = sv.boneWeightList[i];
  57. if (w.boneWeight > 0.0f)
  58. {
  59. boneSet.Add(MeshData.boneList[w.boneIndex]);
  60. }
  61. }
  62. }
  63. // 新しいボーンリスト
  64. var newBoneList = new List<Transform>(boneSet);
  65. // ボーンインデックスを変更する
  66. foreach (var sv in MeshData.shareVertexList)
  67. {
  68. for (int i = 0; i < sv.boneWeightList.Count; i++)
  69. {
  70. var w = sv.boneWeightList[i];
  71. if (w.boneWeight > 0.0f)
  72. {
  73. w.boneIndex = newBoneList.IndexOf(MeshData.boneList[w.boneIndex]);
  74. }
  75. }
  76. }
  77. // 新しいボーンリストに変更
  78. MeshData.boneList = newBoneList;
  79. }
  80. }
  81. }