//=========================================================================================
 /// <summary>
 /// ランタイム状態でのライン表示
 /// </summary>
 /// <param name="scr"></param>
 /// <param name="deformer"></param>
 /// <param name="clothData"></param>
 static void DrawLineRuntime(
     PhysicsTeam team,
     ClothData clothData,
     ClothSetup setup,
     List <int> selList
     )
 {
     if (ClothMonitorMenu.Monitor.UI.DrawClothStructDistanceLine)
     {
         DrawLineRuntimeSub(team, GizmoUtility.ColorStructLine, clothData.structDistanceDataList);
     }
     if (ClothMonitorMenu.Monitor.UI.DrawClothBendDistanceLine)
     {
         DrawLineRuntimeSub(team, GizmoUtility.ColorBendLine, clothData.bendDistanceDataList);
     }
     if (ClothMonitorMenu.Monitor.UI.DrawClothNearDistanceLine)
     {
         DrawLineRuntimeSub(team, GizmoUtility.ColorNearLine, clothData.nearDistanceDataList);
     }
 }
        //=========================================================================================
        /// <summary>
        /// ランタイム状態での回転ライン表示
        /// </summary>
        /// <param name="scr"></param>
        /// <param name="deformer"></param>
        /// <param name="clothData"></param>
        static void DrawRotationLineRuntime(
            PhysicsTeam team,
            ClothData clothData,
            ClothSetup setup,
            List <int> selList
            )
        {
            if (ClothMonitorMenu.Monitor.UI.DrawClothRotationLine == false)
            {
                return;
            }
            if (clothData == null)
            {
                return;
            }
            if (clothData.parentList == null || clothData.parentList.Count != clothData.VertexUseCount)
            {
                return;
            }

            var manager = MagicaPhysicsManager.Instance;

            Gizmos.color = GizmoUtility.ColorRotationLine;

            for (int i = 0; i < clothData.VertexUseCount; i++)
            {
                int pi = clothData.parentList[i];
                if (pi < 0)
                {
                    continue;
                }

                int pindex0 = team.ParticleChunk.startIndex + i;
                int pindex1 = team.ParticleChunk.startIndex + pi;

                Vector3 pos0 = manager.Particle.posList[pindex0];
                Vector3 pos1 = manager.Particle.posList[pindex1];

                Gizmos.DrawLine(pos0, pos1);
            }
        }
        //=========================================================================================
#if false
        /// <summary>
        /// ランタイム状態でのボリューム表示
        /// </summary>
        /// <param name="scr"></param>
        /// <param name="deformer"></param>
        /// <param name="clothData"></param>
        static void DrawVolumeRuntime(
            PhysicsTeam team,
            ClothData clothData,
            ClothSetup setup
            )
        {
            if (ClothMonitorMenu.Monitor.UI.DrawClothVolume == false)
            {
                return;
            }

            var manager = MagicaPhysicsManager.Instance;

            Gizmos.color = GizmoUtility.ColorTriangle;
            int cnt = clothData.VolumeConstraintCount;

            for (int i = 0; i < cnt; i++)
            {
                var data = clothData.volumeDataList[i];

                int pindex0 = team.ParticleChunk.startIndex + data.vindex0;
                int pindex1 = team.ParticleChunk.startIndex + data.vindex1;
                int pindex2 = team.ParticleChunk.startIndex + data.vindex2;
                int pindex3 = team.ParticleChunk.startIndex + data.vindex3;

                Vector3 pos0 = manager.Particle.posList[pindex0];
                Vector3 pos1 = manager.Particle.posList[pindex1];
                Vector3 pos2 = manager.Particle.posList[pindex2];
                Vector3 pos3 = manager.Particle.posList[pindex3];

                Gizmos.DrawLine(pos0, pos1);
                Gizmos.DrawLine(pos0, pos2);
                Gizmos.DrawLine(pos0, pos3);
                Gizmos.DrawLine(pos1, pos2);
                Gizmos.DrawLine(pos2, pos3);
                Gizmos.DrawLine(pos3, pos1);
            }
        }
        //=========================================================================================
        /// <summary>
        /// ランタイム状態での頂点表示
        /// </summary>
        /// <param name="scr"></param>
        /// <param name="deformer"></param>
        /// <param name="clothData"></param>
        static void DrawVertexRuntime(
            PhysicsTeam team,
            ClothData clothData,
            ClothParams param,
            ClothSetup setup,
            List <int> selList
            )
        {
            bool drawVertex = ClothMonitorMenu.Monitor.UI.DrawClothVertex;
            bool drawRadius = ClothMonitorMenu.Monitor.UI.DrawClothRadius;
            bool drawDepth  = ClothMonitorMenu.Monitor.UI.DrawClothDepth;
            bool drawBase   = ClothMonitorMenu.Monitor.UI.DrawClothBase;
            bool drawAxis   = ClothMonitorMenu.Monitor.UI.DrawClothAxis;

#if MAGICACLOTH_DEBUG
            bool number          = ClothMonitorMenu.Monitor.UI.DrawClothVertexNumber;
            bool drawIndex       = ClothMonitorMenu.Monitor.UI.DrawClothVertexIndex;
            bool drawFriction    = ClothMonitorMenu.Monitor.UI.DrawClothFriction;
            bool drawDepthNumber = ClothMonitorMenu.Monitor.UI.DrawClothDepthNumber;
#else
            bool number          = false;
            bool drawIndex       = false;
            bool drawFriction    = false;
            bool drawDepthNumber = false;
#endif

            if (!number && !drawVertex && !drawDepth && !drawBase && !drawAxis && !drawIndex && !drawFriction && !drawDepthNumber)
            {
                return;
            }

            // チームスケール
            var   teamTransform = team.InfluenceTarget ? team.InfluenceTarget : team.transform;
            float teamScale     = clothData.initScale.magnitude > 0.0f ? teamTransform.lossyScale.magnitude / clothData.initScale.magnitude : 1.0f;

            int vcnt = clothData.useVertexList.Count;
            for (int i = 0; i < vcnt; i++)
            {
                int     vindex = clothData.useVertexList[i];
                int     pindex = team.ParticleChunk.startIndex + i;
                Vector3 pos    = MagicaPhysicsManager.Instance.Particle.posList[pindex];
                float   depth  = MagicaPhysicsManager.Instance.Particle.depthList[pindex];
                //float radius = PhysicsManager.Instance.Particle.radiusList[pindex];
                float radius = drawRadius ? MagicaPhysicsManager.Instance.Particle.radiusList[pindex].x * teamScale : 0.001f;
                //float radius = param.GetRadius(depth);

                if (drawVertex || drawDepth || drawAxis)
                {
                    Quaternion rot = MagicaPhysicsManager.Instance.Particle.rotList[pindex];
                    Gizmos.color = GetVertexColor(vindex, depth, selList);
                    GizmoUtility.DrawWireSphere(pos, rot, Vector3.one, radius, drawVertex || drawDepth, drawAxis);
                }
                if (drawBase)
                {
                    Vector3    bpos = MagicaPhysicsManager.Instance.Particle.basePosList[pindex];
                    Quaternion brot = MagicaPhysicsManager.Instance.Particle.baseRotList[pindex];
                    Gizmos.color = GizmoUtility.ColorBasePosition;
                    GizmoUtility.DrawWireSphere(bpos, brot, Vector3.one, radius, true, false);
                }

                if (number)
                {
                    Handles.Label(pos, i.ToString());
                }
                if (drawIndex)
                {
                    Handles.Label(pos, pindex.ToString());
                }
                if (drawFriction)
                {
                    float friction = MagicaPhysicsManager.Instance.Particle.frictionList[pindex];
                    Handles.Label(pos, string.Format("{0:#.##}", friction));
                }
                //if (drawDepthNumber)
                if (drawDepth)
                {
                    float d = MagicaPhysicsManager.Instance.Particle.depthList[pindex];
                    Handles.Label(pos, string.Format("{0:#.##}", d));
                }
            }
        }
        public static bool DrawClothGizmo(
            PhysicsTeam team,
            ClothData clothData,
            ClothParams param,
            ClothSetup setup,
            IEditorMesh editorMesh,
            IEditorCloth editorCloth
            )
        {
            if (ClothMonitorMenu.Monitor.UI.DrawCloth == false)
            {
                return(false);
            }

            if (ClothMonitorMenu.Monitor.UI.DrawClothVertex == false &&
                ClothMonitorMenu.Monitor.UI.DrawClothDepth == false &&
                ClothMonitorMenu.Monitor.UI.DrawClothBase == false &&
                ClothMonitorMenu.Monitor.UI.DrawClothCollider == false &&
                ClothMonitorMenu.Monitor.UI.DrawClothStructDistanceLine == false &&
                ClothMonitorMenu.Monitor.UI.DrawClothBendDistanceLine == false &&
                ClothMonitorMenu.Monitor.UI.DrawClothNearDistanceLine == false &&
                ClothMonitorMenu.Monitor.UI.DrawClothRotationLine == false &&
                ClothMonitorMenu.Monitor.UI.DrawClothTriangleBend == false &&
                ClothMonitorMenu.Monitor.UI.DrawClothPenetration == false
                //&& ClothMonitorMenu.Monitor.UI.DrawClothBaseSkinning == false
                && ClothMonitorMenu.Monitor.UI.DrawClothAxis == false
                //&& ClothMonitorMenu.Monitor.UI.DrawClothVolume == false
#if MAGICACLOTH_DEBUG
                && ClothMonitorMenu.Monitor.UI.DrawClothVertexNumber == false &&
                ClothMonitorMenu.Monitor.UI.DrawClothVertexIndex == false &&
                ClothMonitorMenu.Monitor.UI.DrawPenetrationOrigin == false
                //&& ClothMonitorMenu.Monitor.UI.DrawAdjustRotationLine == false
#endif
                )
            {
                return(false);
            }

            if (clothData == null)
            {
                return(false);
            }

            if (Application.isPlaying)
            {
                if (clothData == null)
                {
                    return(false);
                }

                if (team.IsActive() == false)
                {
                    return(false);
                }

                // 頂点使用状態
                //var useList = editorCloth.GetUseList();
                var selList = editorCloth.GetSelectionList();

                // 頂点情報
                DrawVertexRuntime(team, clothData, param, setup, selList);

                // コライダー
                DrawCollider(team);

                // ライン
                DrawLineRuntime(team, clothData, setup, selList);

                // トライアングルベンド
                DrawTriangleBendRuntime(team, clothData, setup);

                // 回転ライン
                DrawRotationLineRuntime(team, clothData, setup, selList);

                // コライダー移動制限
                DrawPenetrationRuntime(team, param, clothData, selList);

                // ボリューム
                //DrawVolumeRuntime(team, clothData, setup);

                // 回転調整ライン
                //DrawAdjustRotationLineRuntime(team, clothData);
            }
            else
            {
                // メッシュ頂点法線接線
                List <Vector3> posList;
                List <Vector3> norList;
                List <Vector3> tanList;
                int            vcnt = editorMesh.GetEditorPositionNormalTangent(out posList, out norList, out tanList);

                // 頂点使用状態
                //var useList = editorCloth.GetUseList();
                var selList = editorCloth.GetSelectionList();

                // 頂点情報
                DrawVertexClothData(clothData, param, vcnt, posList, norList, tanList, selList);

                // コライダー
                DrawCollider(team);

                // ライン
                DrawLineClothData(clothData, posList, selList);

                // トライアングルベンド
                DrawTriangleBendClothData(clothData, posList);

                // 回転ライン
                DrawRotationLineClothData(clothData, posList, selList);

                // コライダー移動制限
                DrawPenetrationClothData(team, param, clothData, posList, norList, tanList, selList);

                // ベーススキニング
                //DrawBaseSkinningClothData(team, clothData, posList, selList);

                // ボリューム
                //DrawVolumeClothData(clothData, posList);

                // 回転調整ライン
                //DrawAdjustRotationLineClothData(clothData, posList);
            }

            return(true);
        }