ClothMonitorUI.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. // Magica Cloth.
  2. // Copyright (c) MagicaSoft, 2020-2022.
  3. // https://magicasoft.jp
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace MagicaCloth
  7. {
  8. [System.Serializable]
  9. public class ClothMonitorUI : ClothMonitorAccess
  10. {
  11. // クロス表示
  12. [SerializeField]
  13. private bool alwaysClothShow = false;
  14. [SerializeField]
  15. private bool drawCloth = true;
  16. [SerializeField]
  17. private bool drawClothVertex = true;
  18. [SerializeField]
  19. private bool drawClothRadius = true;
  20. [SerializeField]
  21. private bool drawClothDepth;
  22. [SerializeField]
  23. private bool drawClothBase;
  24. [SerializeField]
  25. private bool drawClothCollider = true;
  26. [SerializeField]
  27. private bool drawClothStructDistanceLine = true;
  28. [SerializeField]
  29. private bool drawClothBendDistanceLine;
  30. [SerializeField]
  31. private bool drawClothNearDistanceLine;
  32. [SerializeField]
  33. private bool drawClothRotationLine = true;
  34. [SerializeField]
  35. private bool drawClothTriangleBend = true;
  36. [SerializeField]
  37. private bool drawClothPenetration = false;
  38. [SerializeField]
  39. private bool drawClothAxis;
  40. [SerializeField]
  41. private bool drawClothSkinningBones = true;
  42. // デフォーマー表示
  43. [SerializeField]
  44. private bool alwaysDeformerShow = false;
  45. [SerializeField]
  46. private bool drawDeformer = true;
  47. [SerializeField]
  48. private bool drawDeformerVertexPosition;
  49. [SerializeField]
  50. private bool drawDeformerLine = true;
  51. [SerializeField]
  52. private bool drawDeformerTriangle = true;
  53. [SerializeField]
  54. private bool drawDeformerVertexAxis;
  55. // 風表示
  56. [SerializeField]
  57. private bool alwaysWindShow = true;
  58. [SerializeField]
  59. private bool drawWind = true;
  60. #if MAGICACLOTH_DEBUG
  61. // デバッグ用
  62. [SerializeField]
  63. private bool drawClothVertexNumber;
  64. [SerializeField]
  65. private bool drawClothVertexIndex;
  66. [SerializeField]
  67. private bool drawClothFriction;
  68. [SerializeField]
  69. private bool drawClothStaticFriction;
  70. [SerializeField]
  71. private bool drawClothCollisionNormal;
  72. [SerializeField]
  73. private bool drawClothVelocity;
  74. [SerializeField]
  75. private bool drawClothVelocityVector;
  76. [SerializeField]
  77. private bool drawClothDepthNumber;
  78. [SerializeField]
  79. private bool drawPenetrationOrigin;
  80. [SerializeField]
  81. private int debugDrawDeformerTriangleNumber = -1;
  82. [SerializeField]
  83. private int debugDrawDeformerVertexNumber = -1;
  84. [SerializeField]
  85. private bool drawDeformerVertexNumber;
  86. [SerializeField]
  87. private bool drawDeformerTriangleNormal;
  88. [SerializeField]
  89. private bool drawDeformerTriangleNumber;
  90. #endif
  91. //=========================================================================================
  92. Vector2 scrollPos;
  93. //=========================================================================================
  94. public override void Disable()
  95. {
  96. }
  97. public override void Enable()
  98. {
  99. }
  100. protected override void Create()
  101. {
  102. }
  103. public override void Destroy()
  104. {
  105. }
  106. public void OnGUI()
  107. {
  108. if (menu == null)
  109. return;
  110. Version();
  111. scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
  112. Information();
  113. DebugOption();
  114. EditorGUILayout.EndScrollView();
  115. }
  116. //=========================================================================================
  117. public bool AlwaysClothShow => alwaysClothShow;
  118. public bool AlwaysDeformerShow => alwaysDeformerShow;
  119. public bool DrawDeformer => drawDeformer;
  120. public bool DrawDeformerVertexPosition => drawDeformerVertexPosition;
  121. public bool DrawDeformerLine => drawDeformerLine;
  122. public bool DrawDeformerTriangle => drawDeformerTriangle;
  123. public bool DrawCloth => drawCloth;
  124. public bool DrawClothVertex => drawClothVertex;
  125. public bool DrawClothRadius => drawClothRadius;
  126. public bool DrawClothDepth => drawClothDepth;
  127. public bool DrawClothBase => drawClothBase;
  128. public bool DrawClothCollider => drawClothCollider;
  129. public bool DrawClothStructDistanceLine => drawClothStructDistanceLine;
  130. public bool DrawClothBendDistanceLine => drawClothBendDistanceLine;
  131. public bool DrawClothNearDistanceLine => drawClothNearDistanceLine;
  132. public bool DrawClothRotationLine => drawClothRotationLine;
  133. public bool DrawClothTriangleBend => drawClothTriangleBend;
  134. public bool DrawClothPenetration => drawClothPenetration;
  135. public bool DrawClothAxis => drawClothAxis;
  136. public bool DrawDeformerVertexAxis => drawDeformerVertexAxis;
  137. public bool AlwaysWindShow => alwaysWindShow;
  138. public bool DrawWind => drawWind;
  139. public bool DrawClothSkinningBones => drawClothSkinningBones;
  140. #if MAGICACLOTH_DEBUG
  141. // デバッグ用
  142. public bool DrawClothVertexNumber => drawClothVertexNumber;
  143. public bool DrawClothVertexIndex => drawClothVertexIndex;
  144. public bool DrawClothFriction => drawClothFriction;
  145. public bool DrawClothStaticFriction => drawClothStaticFriction;
  146. public bool DrawClothCollisionNormal => drawClothCollisionNormal;
  147. public bool DrawClothVelocity => drawClothVelocity;
  148. public bool DrawClothVelocityVector => drawClothVelocityVector;
  149. public bool DrawClothDepthNumber => drawClothDepthNumber;
  150. public bool DrawPenetrationOrigin => drawPenetrationOrigin;
  151. public int DebugDrawDeformerTriangleNumber => debugDrawDeformerTriangleNumber;
  152. public int DebugDrawDeformerVertexNumber => debugDrawDeformerVertexNumber;
  153. public bool DrawDeformerTriangleNormal => drawDeformerTriangleNormal;
  154. public bool DrawDeformerTriangleNumber => drawDeformerTriangleNumber;
  155. public bool DrawDeformerVertexNumber => drawDeformerVertexNumber;
  156. #endif
  157. //=========================================================================================
  158. void Version()
  159. {
  160. EditorGUILayout.Space();
  161. EditorGUILayout.LabelField("Magica Cloth. (Version " + AboutMenu.MagicaClothVersion + ")", EditorStyles.boldLabel);
  162. }
  163. void Information()
  164. {
  165. StaticStringBuilder.Clear();
  166. int teamCnt = 0;
  167. int normalTeamCnt = 0;
  168. int physicsTeamCnt = 0;
  169. int activeTeamCnt = 0;
  170. int teamCalculation = 0;
  171. #if MAGICACLOTH_DEBUG
  172. int sharedVirtualMeshCnt = 0;
  173. int virtualMeshCnt = 0;
  174. int sharedChildMeshCnt = 0;
  175. int sharedRenderMeshCnt = 0;
  176. int renderMeshCnt = 0;
  177. int virtualMeshVertexCnt = 0;
  178. int virtualMeshTriangleCnt = 0;
  179. int renderMeshVertexCnt = 0;
  180. #endif
  181. int virtualMeshUseCnt = 0;
  182. int virtualMeshUseCalculation = 0;
  183. int virtualMeshVertexUseCnt = 0;
  184. int renderMeshUseCnt = 0;
  185. int renderMeshUseCalculation = 0;
  186. int renderMeshVertexUseCnt = 0;
  187. int particleCnt = 0;
  188. int colliderCnt = 0;
  189. int restoreBoneCnt = 0;
  190. int readBoneCnt = 0;
  191. int writeBoneCnt = 0;
  192. int windCnt = 0;
  193. if (EditorApplication.isPlaying && MagicaPhysicsManager.IsInstance())
  194. {
  195. var manager = MagicaPhysicsManager.Instance;
  196. teamCnt = manager.Team.TeamCount;
  197. normalTeamCnt = manager.Team.NormalUpdateCount;
  198. physicsTeamCnt = manager.Team.PhysicsUpdateCount;
  199. activeTeamCnt = manager.Team.ActiveTeamCount;
  200. teamCalculation = activeTeamCnt - manager.Team.PauseCount;
  201. #if MAGICACLOTH_DEBUG
  202. sharedVirtualMeshCnt = manager.Mesh.SharedVirtualMeshCount;
  203. virtualMeshCnt = manager.Mesh.VirtualMeshCount;
  204. sharedChildMeshCnt = manager.Mesh.SharedChildMeshCount;
  205. sharedRenderMeshCnt = manager.Mesh.SharedRenderMeshCount;
  206. renderMeshCnt = manager.Mesh.RenderMeshCount;
  207. virtualMeshVertexCnt = manager.Mesh.VirtualMeshVertexCount;
  208. virtualMeshTriangleCnt = manager.Mesh.VirtualMeshTriangleCount;
  209. renderMeshVertexCnt = manager.Mesh.RenderMeshVertexCount;
  210. #endif
  211. virtualMeshUseCnt = manager.Mesh.VirtualMeshUseCount;
  212. virtualMeshUseCalculation = virtualMeshUseCnt - manager.Mesh.VirtualMeshPauseCount;
  213. virtualMeshVertexUseCnt = manager.Mesh.VirtualMeshVertexUseCount;
  214. renderMeshUseCnt = manager.Mesh.RenderMeshUseCount;
  215. renderMeshUseCalculation = renderMeshUseCnt - manager.Mesh.RenderMeshPauseCount;
  216. renderMeshVertexUseCnt = manager.Mesh.RenderMeshVertexUseCount;
  217. particleCnt = manager.Particle.Count;
  218. colliderCnt = manager.Particle.ColliderCount;
  219. restoreBoneCnt = manager.Bone.RestoreBoneCount;
  220. readBoneCnt = manager.Bone.ReadBoneCount;
  221. writeBoneCnt = manager.Bone.WriteBoneCount;
  222. windCnt = manager.Wind.Count;
  223. }
  224. //StaticStringBuilder.AppendLine("Cloth Team: ", teamCnt, " (Normal: ", normalTeamCnt, " ,UnityPhysics: ", physicsTeamCnt, ")");
  225. StaticStringBuilder.AppendLine("Cloth Team: ", teamCnt);
  226. StaticStringBuilder.AppendLine("Active: ", activeTeamCnt);
  227. StaticStringBuilder.AppendLine("> Normal Update: ", normalTeamCnt);
  228. StaticStringBuilder.AppendLine("> Physics Update: ", physicsTeamCnt);
  229. StaticStringBuilder.AppendLine("Calculation: ", teamCalculation);
  230. StaticStringBuilder.AppendLine();
  231. #if MAGICACLOTH_DEBUG
  232. StaticStringBuilder.AppendLine("Shared Virtual Mesh: ", sharedVirtualMeshCnt);
  233. StaticStringBuilder.AppendLine("Virtual Mesh: ", virtualMeshCnt);
  234. StaticStringBuilder.AppendLine("Shared Child Mesh: ", sharedChildMeshCnt);
  235. StaticStringBuilder.AppendLine("Shared Render Mesh: ", sharedRenderMeshCnt);
  236. StaticStringBuilder.AppendLine("Render Mesh: ", renderMeshCnt);
  237. StaticStringBuilder.AppendLine();
  238. StaticStringBuilder.AppendLine("Virtual Mesh Vertex: ", virtualMeshVertexCnt);
  239. StaticStringBuilder.AppendLine("Virtual Mesh Triangle: ", virtualMeshTriangleCnt);
  240. StaticStringBuilder.AppendLine("Render Mesh Vertex: ", renderMeshVertexCnt);
  241. StaticStringBuilder.AppendLine();
  242. #endif
  243. StaticStringBuilder.AppendLine("Virtual Mesh Used: ", virtualMeshUseCnt);
  244. StaticStringBuilder.AppendLine("Virtual Mesh Calculation: ", virtualMeshUseCalculation);
  245. StaticStringBuilder.AppendLine("Virtual Mesh Vertex Used: ", virtualMeshVertexUseCnt);
  246. StaticStringBuilder.AppendLine();
  247. StaticStringBuilder.AppendLine("Render Mesh Used: ", renderMeshUseCnt);
  248. StaticStringBuilder.AppendLine("Render Mesh Calculation: ", renderMeshUseCalculation);
  249. StaticStringBuilder.AppendLine("Render Mesh Vertex Used: ", renderMeshVertexUseCnt);
  250. StaticStringBuilder.AppendLine();
  251. StaticStringBuilder.AppendLine("Particle: ", particleCnt);
  252. StaticStringBuilder.AppendLine("Collider: ", colliderCnt);
  253. StaticStringBuilder.AppendLine("Restore Transform: ", restoreBoneCnt);
  254. StaticStringBuilder.AppendLine("Read Transform: ", readBoneCnt);
  255. StaticStringBuilder.AppendLine("Write Transform: ", writeBoneCnt);
  256. StaticStringBuilder.Append("Wind: ", windCnt);
  257. EditorGUILayout.HelpBox(StaticStringBuilder.ToString(), MessageType.Info);
  258. }
  259. void DebugOption()
  260. {
  261. EditorGUI.BeginChangeCheck();
  262. EditorInspectorUtility.Foldout("Cloth Team Gizmos", "Cloth Team Gizmos",
  263. () =>
  264. {
  265. EditorGUI.BeginDisabledGroup(!drawCloth);
  266. using (new EditorGUI.IndentLevelScope())
  267. {
  268. alwaysClothShow = EditorGUILayout.Toggle("Always Show", alwaysClothShow);
  269. drawClothVertex = EditorGUILayout.Toggle("Particle Position", drawClothVertex);
  270. drawClothRadius = EditorGUILayout.Toggle("Particle Radius", drawClothRadius);
  271. drawClothDepth = EditorGUILayout.Toggle("Particle Depth", drawClothDepth);
  272. drawClothAxis = EditorGUILayout.Toggle("Particle Axis", drawClothAxis);
  273. drawClothCollider = EditorGUILayout.Toggle("Collider", drawClothCollider);
  274. drawClothBase = EditorGUILayout.Toggle("Base Pose", drawClothBase);
  275. //drawClothSkinningBones = EditorGUILayout.Toggle("Skinning Bone", drawClothSkinningBones);
  276. drawClothStructDistanceLine = EditorGUILayout.Toggle("Struct Distance Line", drawClothStructDistanceLine);
  277. drawClothBendDistanceLine = EditorGUILayout.Toggle("Bend Distance Line", drawClothBendDistanceLine);
  278. drawClothNearDistanceLine = EditorGUILayout.Toggle("Near Distance Line", drawClothNearDistanceLine);
  279. drawClothRotationLine = EditorGUILayout.Toggle("Rotation Line", drawClothRotationLine);
  280. drawClothTriangleBend = EditorGUILayout.Toggle("Triangle Bend", drawClothTriangleBend);
  281. drawClothPenetration = EditorGUILayout.Toggle("Penetration", drawClothPenetration);
  282. #if MAGICACLOTH_DEBUG
  283. drawClothVertexNumber = EditorGUILayout.Toggle("[D] Particle Number", drawClothVertexNumber);
  284. drawClothVertexIndex = EditorGUILayout.Toggle("[D] Particle Index", drawClothVertexIndex);
  285. drawClothFriction = EditorGUILayout.Toggle("[D] Particle Friction", drawClothFriction);
  286. drawClothStaticFriction = EditorGUILayout.Toggle("[D] Particle Static Friction", drawClothStaticFriction);
  287. drawClothCollisionNormal = EditorGUILayout.Toggle("[D] Particle Col Normal", drawClothCollisionNormal);
  288. drawClothVelocity = EditorGUILayout.Toggle("[D] Particle Velocity", drawClothVelocity);
  289. drawClothVelocityVector = EditorGUILayout.Toggle("[D] Particle Velocity V", drawClothVelocityVector);
  290. drawClothDepthNumber = EditorGUILayout.Toggle("[D] Particle Depth", drawClothDepthNumber);
  291. drawPenetrationOrigin = EditorGUILayout.Toggle("[D] Penetration Origin", drawPenetrationOrigin);
  292. #endif
  293. }
  294. EditorGUI.EndDisabledGroup();
  295. },
  296. (sw) =>
  297. {
  298. drawCloth = sw;
  299. },
  300. drawCloth
  301. );
  302. EditorInspectorUtility.Foldout("Deformer Gizmos", "Deformer Gizmos",
  303. () =>
  304. {
  305. EditorGUI.BeginDisabledGroup(!drawDeformer);
  306. using (new EditorGUI.IndentLevelScope())
  307. {
  308. alwaysDeformerShow = EditorGUILayout.Toggle("Always Show", alwaysDeformerShow);
  309. drawDeformerVertexPosition = EditorGUILayout.Toggle("Vertex Position", drawDeformerVertexPosition);
  310. drawDeformerVertexAxis = EditorGUILayout.Toggle("Vertex Axis", drawDeformerVertexAxis);
  311. drawDeformerLine = EditorGUILayout.Toggle("Line", drawDeformerLine);
  312. drawDeformerTriangle = EditorGUILayout.Toggle("Triangle", drawDeformerTriangle);
  313. #if MAGICACLOTH_DEBUG
  314. drawDeformerVertexNumber = EditorGUILayout.Toggle("[D] Vertex Number", drawDeformerVertexNumber);
  315. debugDrawDeformerVertexNumber = EditorGUILayout.IntField("[D] Vertex Number", debugDrawDeformerVertexNumber);
  316. drawDeformerTriangleNormal = EditorGUILayout.Toggle("[D] Triangle Normal", drawDeformerTriangleNormal);
  317. drawDeformerTriangleNumber = EditorGUILayout.Toggle("[D] Triangle Number", drawDeformerTriangleNumber);
  318. debugDrawDeformerTriangleNumber = EditorGUILayout.IntField("[D] Triangle Number", debugDrawDeformerTriangleNumber);
  319. #endif
  320. }
  321. EditorGUI.EndDisabledGroup();
  322. },
  323. (sw) =>
  324. {
  325. drawDeformer = sw;
  326. },
  327. drawDeformer
  328. );
  329. EditorInspectorUtility.Foldout("Wind Gizmos", "Wind Gizmos",
  330. () =>
  331. {
  332. EditorGUI.BeginDisabledGroup(!drawWind);
  333. using (new EditorGUI.IndentLevelScope())
  334. {
  335. alwaysWindShow = EditorGUILayout.Toggle("Always Show", alwaysWindShow);
  336. }
  337. EditorGUI.EndDisabledGroup();
  338. },
  339. (sw) =>
  340. {
  341. drawWind = sw;
  342. },
  343. drawWind
  344. );
  345. if (EditorGUI.EndChangeCheck())
  346. {
  347. // Sceneビュー更新
  348. SceneView.RepaintAll();
  349. }
  350. }
  351. }
  352. }