123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257 |
- // Magica Cloth.
- // Copyright (c) MagicaSoft, 2020-2022.
- // https://magicasoft.jp
- using System.Collections.Generic;
- using UnityEditor;
- using UnityEngine;
- namespace MagicaCloth
- {
- /// <summary>
- /// クロスのギズモ表示
- /// </summary>
- public class ClothGizmoDrawer
- {
- /// <summary>
- /// 常に表示するデータ
- /// </summary>
- /// <param name="team"></param>
- /// <param name="param"></param>
- internal static void AlwaysDrawClothGizmo(
- PhysicsTeam team,
- ClothParams param
- )
- {
- if (ClothMonitorMenu.Monitor.UI.DrawCloth == false)
- return;
- // 無条件で表示するもの
- //DrawSkinningBone(team);
- }
- /// <summary>
- /// データ存在時の表示
- /// </summary>
- /// <param name="team"></param>
- /// <param name="clothData"></param>
- /// <param name="param"></param>
- /// <param name="setup"></param>
- /// <param name="editorMesh"></param>
- /// <param name="editorCloth"></param>
- /// <returns></returns>
- 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.DrawClothAxis == false
- #if MAGICACLOTH_DEBUG
- && ClothMonitorMenu.Monitor.UI.DrawClothVertexNumber == false
- && ClothMonitorMenu.Monitor.UI.DrawClothVertexIndex == false
- && ClothMonitorMenu.Monitor.UI.DrawPenetrationOrigin == false
- #endif
- )
- return false;
- // 以下はデータが存在する場合のみ
- if (clothData == null)
- return false;
- if (Application.isPlaying)
- {
- if (clothData == null)
- return false;
- if (team.IsActive() == false)
- return false;
- if (team.IsCalculate == 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);
- //DrawBonePenetrationRuntime(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);
- //DrawBonePenetrationClothData(team, param, clothData, posList, norList, tanList, selList); // 一旦休眠
- // ベーススキニング
- //DrawBaseSkinningClothData(team, clothData, posList, selList);
- // ボリューム
- //DrawVolumeClothData(clothData, posList);
- // 回転調整ライン
- //DrawAdjustRotationLineClothData(clothData, posList);
- }
- return true;
- }
- //=========================================================================================
- /// <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 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 drawStaticFriction = ClothMonitorMenu.Monitor.UI.DrawClothStaticFriction;
- bool drawDepthNumber = ClothMonitorMenu.Monitor.UI.DrawClothDepthNumber;
- bool drawCollisionNormal = ClothMonitorMenu.Monitor.UI.DrawClothCollisionNormal;
- bool drawVelocity = ClothMonitorMenu.Monitor.UI.DrawClothVelocity;
- bool drawVelocityVector = ClothMonitorMenu.Monitor.UI.DrawClothVelocityVector;
- #else
- bool number = false;
- bool drawIndex = false;
- bool drawFriction = false;
- bool drawStaticFriction = false;
- bool drawDepthNumber = false;
- bool drawCollisionNormal = false;
- bool drawVelocity = false;
- bool drawVelocityVector = false;
- #endif
- if (!number && !drawVertex && !drawDepth && !drawAxis && !drawIndex && !drawFriction && !drawStaticFriction
- && !drawDepthNumber && !drawCollisionNormal && !drawVelocity && !drawVelocityVector)
- return;
- // チームスケール
- var teamTransform = team.InfluenceTarget ? team.InfluenceTarget : team.transform;
- float teamScale = clothData.initScale.magnitude > 0.0f ? teamTransform.lossyScale.magnitude / clothData.initScale.magnitude : 1.0f;
- float updateIntervalTime = MagicaPhysicsManager.Instance.UpdateTime.UpdateIntervalTime;
- 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 (drawCollisionNormal)
- {
- Vector3 cn = MagicaPhysicsManager.Instance.Particle.collisionNormalList[pindex];
- Gizmos.color = GizmoUtility.ColorCollisionNormal;
- Gizmos.DrawLine(pos, pos + cn * 0.03f);
- }
- if (drawVelocityVector)
- {
- Vector3 vel = MagicaPhysicsManager.Instance.Particle.velocityList[pindex];
- Gizmos.color = GizmoUtility.ColorVelocity;
- Gizmos.DrawLine(pos, pos + vel * updateIntervalTime);
- }
- 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 (drawStaticFriction)
- {
- float staticFriction = MagicaPhysicsManager.Instance.Particle.staticFrictionList[pindex];
- Handles.Label(pos, string.Format("{0:#.##}", staticFriction));
- }
- //if (drawDepthNumber)
- if (drawDepth)
- {
- float d = MagicaPhysicsManager.Instance.Particle.depthList[pindex];
- Handles.Label(pos, string.Format("{0:#.##}", d));
- }
- if (drawVelocity)
- {
- Vector3 v = MagicaPhysicsManager.Instance.Particle.velocityList[pindex];
- Handles.Label(pos, string.Format("{0:#.##}", v.magnitude));
- }
- }
- }
- /// <summary>
- /// エディタ状態での頂点表示
- /// </summary>
- /// <param name="scr"></param>
- /// <param name="deformer"></param>
- /// <param name="clothData"></param>
- static void DrawVertexClothData(
- ClothData clothData,
- ClothParams param,
- int vcnt,
- List<Vector3> posList,
- List<Vector3> norList,
- List<Vector3> tanList,
- List<int> selList
- )
- {
- bool drawVertex = ClothMonitorMenu.Monitor.UI.DrawClothVertex;
- bool drawRadius = ClothMonitorMenu.Monitor.UI.DrawClothRadius;
- bool drawDepth = ClothMonitorMenu.Monitor.UI.DrawClothDepth;
- bool drawAxis = ClothMonitorMenu.Monitor.UI.DrawClothAxis;
- #if MAGICACLOTH_DEBUG
- bool number = ClothMonitorMenu.Monitor.UI.DrawClothVertexNumber;
- bool drawDepthNumber = ClothMonitorMenu.Monitor.UI.DrawClothDepthNumber;
- #else
- bool number = false;
- bool drawDepthNumber = false;
- #endif
- if (!number && !drawVertex && !drawDepth && !drawAxis && !drawDepthNumber)
- return;
- for (int i = 0; i < clothData.VertexUseCount; i++)
- {
- int vindex = clothData.useVertexList[i];
- if (vindex >= posList.Count)
- continue;
- Vector3 pos = posList[vindex];
- if (drawVertex || drawDepth || drawAxis)
- {
- Vector3 nor = norList[vindex];
- Vector3 tan = tanList[vindex];
- Quaternion rot = Quaternion.LookRotation(nor, tan);
- float depth = clothData == null ? 0.0f : clothData.vertexDepthList[i];
- //float radius = param.GetRadius(depth);
- float radius = drawRadius ? param.GetRadius(depth) : 0.001f;
- Gizmos.color = GetVertexColor(vindex, depth, selList);
- GizmoUtility.DrawWireSphere(pos, rot, Vector3.one, radius, drawVertex || drawDepth, drawAxis);
- }
- if (number)
- {
- Handles.Label(pos, i.ToString());
- }
- //if (drawDepthNumber)
- if (drawDepth)
- {
- float depth = clothData == null ? 0.0f : clothData.vertexDepthList[i];
- Handles.Label(pos, string.Format("{0:#.##}", depth));
- }
- }
- }
- /// <summary>
- /// クロス頂点カラー設定
- /// </summary>
- /// <param name="vindex"></param>
- /// <param name="depth"></param>
- /// <returns></returns>
- static Color GetVertexColor(int vindex, float depth, List<int> selList)
- {
- if (ClothMonitorMenu.Monitor.UI.DrawClothDepth)
- {
- return Color.Lerp(Color.red, Color.blue, depth);
- }
- else
- {
- if (selList == null || vindex >= selList.Count)
- return GizmoUtility.ColorDeformerPoint;
- else if (selList[vindex] == SelectionData.Fixed)
- return GizmoUtility.ColorKinematic;
- else if (selList[vindex] == SelectionData.Move)
- return GizmoUtility.ColorDynamic;
- else
- return GizmoUtility.ColorInvalid;
- }
- }
- static bool IsMove(int vindex, List<int> selList)
- {
- if (selList == null || vindex >= selList.Count)
- return false;
- return selList[vindex] == SelectionData.Move;
- }
- //=========================================================================================
- /// <summary>
- /// クロスに紐づくコライダーの表示
- /// </summary>
- /// <param name="scr"></param>
- public static void DrawCollider(PhysicsTeam team)
- {
- if (ClothMonitorMenu.Monitor.UI.DrawClothCollider == false)
- return;
- var colliderlist = team.TeamData.ColliderList;
- foreach (var collider in colliderlist)
- {
- if (collider == null || collider.isActiveAndEnabled == false)
- continue;
- if (collider is MagicaSphereCollider)
- MagicaSphereColliderGizmoDrawer.DrawGizmo(collider as MagicaSphereCollider, true);
- else if (collider is MagicaCapsuleCollider)
- MagicaCapsuleColliderGizmoDrawer.DrawGizmo(collider as MagicaCapsuleCollider, true);
- }
- }
- //=========================================================================================
- #if false
- /// <summary>
- /// エディタ状態でのベーススキニング表示
- /// </summary>
- /// <param name="team"></param>
- /// <param name="clothData"></param>
- /// <param name="posList"></param>
- /// <param name="selList"></param>
- static void DrawBaseSkinningClothData(
- PhysicsTeam team,
- ClothData clothData,
- List<Vector3> posList,
- List<int> selList
- )
- {
- if (ClothMonitorMenu.Monitor.UI.DrawClothBaseSkinning == false)
- return;
- if (clothData.baseSkinningDataList == null)
- return;
- //var boneList = team.TeamData.SkinningBoneList;
- var boneList = team.TeamData.ColliderList;
- //Gizmos.color = GizmoUtility.ColorPenetration;
- for (int i = 0; i < clothData.VertexUseCount; i++)
- {
- int vindex = clothData.useVertexList[i];
- if (vindex >= posList.Count)
- continue;
- if (IsMove(vindex, selList) == false)
- continue;
- Vector3 pos = posList[vindex];
- for (int j = 0; j < Define.Compute.BaseSkinningWeightCount; j++)
- {
- int dindex = i * Define.Compute.BaseSkinningWeightCount + j;
- if (dindex >= clothData.baseSkinningDataList.Length)
- return;
- var data = clothData.baseSkinningDataList[dindex];
- if (data.IsValid() == false)
- continue;
- int bindex = data.boneIndex;
- if (bindex >= boneList.Count)
- continue;
- var bone = boneList[bindex];
- if (bone == null)
- continue;
- //Gizmos.color = j == 0 ? Color.red : Color.yellow;
- Gizmos.color = Color.gray;
- #if true
- Vector3 p, dir, d;
- bone.CalcNearPoint(pos, out p, out dir, out d, true);
- Gizmos.DrawLine(pos, p);
- #else
- //var cp = bone.TransformPoint(data.localPos);
- Vector3 cp;
- MeshUtility.ClosestPtBoneLine(pos, bone, 0.03f, out cp);
- Gizmos.DrawLine(pos, cp);
- #endif
- }
- }
- }
- #endif
- #if false // 一旦休眠
- /// <summary>
- /// スキニング用ボーン構造の表示
- /// </summary>
- /// <param name="team"></param>
- static void DrawSkinningBone(
- PhysicsTeam team
- )
- {
- if (ClothMonitorMenu.Monitor.UI.DrawClothSkinningBones == false)
- return;
- // スキニング用ボーン
- var boneList = team.TeamData.SkinningBoneList;
- if (boneList.Count >= 2)
- {
- //Gizmos.color = new Color(0.0f, 0.717f, 0.933f);
- //Gizmos.color = Color.magenta;
- foreach (var bone in boneList)
- {
- if (bone == null)
- continue;
- for (int k = 0; k < bone.childCount; k++)
- {
- var cbone = bone.GetChild(k);
- if (boneList.Contains(cbone))
- {
- //Gizmos.DrawLine(bone.position, cbone.position);
- GizmoUtility.DrawBone(bone.position, cbone.position, 0.01f);
- }
- }
- }
- }
- }
- #endif
- //=========================================================================================
- /// <summary>
- /// ランタイム状態での浸透制限表示
- /// </summary>
- /// <param name="team"></param>
- /// <param name="clothData"></param>
- /// <param name="selList"></param>
- static void DrawPenetrationRuntime(
- PhysicsTeam team,
- ClothParams param,
- ClothData clothData,
- List<int> selList
- )
- {
- #if !MAGICACLOTH_DEBUG
- if (ClothMonitorMenu.Monitor.UI.DrawClothPenetration == false)
- return;
- #else
- if (ClothMonitorMenu.Monitor.UI.DrawClothPenetration == false && ClothMonitorMenu.Monitor.UI.DrawPenetrationOrigin == false)
- return;
- #endif
- if (clothData.penetrationDataList == null)
- return;
- if (clothData.penetrationReferenceList == null)
- return;
- //var mode = param.GetPenetrationMode();
- var mode = clothData.penetrationMode;
- // 一旦休眠
- //if (mode == ClothParams.PenetrationMode.BonePenetration)
- // return;
- var colliderlist = team.TeamData.ColliderList;
- int vcnt = clothData.useVertexList.Count;
- for (int i = 0; i < vcnt; i++)
- {
- int vindex = clothData.useVertexList[i];
- if (IsMove(vindex, selList) == false)
- continue;
- int pindex = team.ParticleChunk.startIndex + i;
- Vector3 pos = MagicaPhysicsManager.Instance.Particle.posList[pindex];
- if (i >= clothData.penetrationReferenceList.Length)
- return;
- #if MAGICACLOTH_DEBUG
- Vector3 cen = Vector3.zero;
- Vector3 cdir = Vector3.zero;
- int ccnt = 0;
- GUIStyle style = new GUIStyle();
- style.normal.textColor = Color.cyan;
- #endif
- var refdata = clothData.penetrationReferenceList[i];
- for (int j = 0; j < refdata.count; j++)
- {
- var dindex = refdata.startIndex + j;
- var data = clothData.penetrationDataList[dindex];
- if (data.IsValid() == false)
- continue;
- if (mode == ClothParams.PenetrationMode.SurfacePenetration)
- {
- Vector3 bpos = MagicaPhysicsManager.Instance.Particle.basePosList[pindex];
- Quaternion brot = MagicaPhysicsManager.Instance.Particle.baseRotList[pindex];
- var dir = brot * data.localDir;
- var depth = clothData.vertexDepthList[i];
- var dist = param.GetPenetrationDistance().Evaluate(depth);
- Gizmos.color = GizmoUtility.ColorPenetration;
- Gizmos.DrawLine(bpos, bpos + dir * dist);
- break;
- }
- else if (mode == ClothParams.PenetrationMode.ColliderPenetration)
- {
- int cindex = data.colliderIndex;
- if (cindex >= colliderlist.Count)
- continue;
- var col = colliderlist[cindex];
- if (col == null)
- continue;
- var cp = col.transform.TransformPoint(data.localPos);
- #if MAGICACLOTH_DEBUG
- var dir = col.transform.TransformDirection(data.localDir);
- var c = cp + dir * data.distance;
- cen += c;
- cdir += dir;
- ccnt++;
- #endif
- if (ClothMonitorMenu.Monitor.UI.DrawClothPenetration)
- {
- Gizmos.color = GizmoUtility.ColorPenetration;
- Gizmos.DrawLine(pos, cp);
- }
- }
- }
- #if MAGICACLOTH_DEBUG
- if (ClothMonitorMenu.Monitor.UI.DrawPenetrationOrigin && ccnt > 0)
- {
- cen /= ccnt;
- cdir /= ccnt;
- Gizmos.color = new Color(0.0f, 1.0f, 1.0f);
- Gizmos.DrawSphere(cen, 0.002f);
- Gizmos.color = Color.yellow;
- Gizmos.DrawLine(cen, cen + cdir.normalized * 0.02f);
- //Handles.color = Color.cyan;
- Handles.Label(cen, i.ToString(), style);
- }
- #endif
- }
- }
- #if false // 一旦休眠
- static void DrawBonePenetrationRuntime(
- PhysicsTeam team,
- ClothParams param,
- ClothData clothData,
- List<int> selList
- )
- {
- if (ClothMonitorMenu.Monitor.UI.DrawClothPenetration == false)
- return;
- var mode = clothData.penetrationMode;
- if (mode != ClothParams.PenetrationMode.BonePenetration)
- return;
- if (clothData.penetrationDirectionDataList == null)
- return;
- for (int i = 0; i < clothData.VertexUseCount; i++)
- {
- int vindex = clothData.useVertexList[i];
- if (IsMove(vindex, selList) == false)
- continue;
- if (i >= clothData.penetrationDirectionDataList.Length)
- return;
- var depth = clothData.vertexDepthList[i];
- if (depth > param.PenetrationMaxDepth)
- continue;
- int pindex = team.ParticleChunk.startIndex + i;
- Vector3 bpos = MagicaPhysicsManager.Instance.Particle.basePosList[pindex];
- Quaternion brot = MagicaPhysicsManager.Instance.Particle.baseRotList[pindex];
- var ldir = clothData.penetrationDirectionDataList[i];
- var dir = brot * ldir;
- Gizmos.color = Color.blue;
- //Gizmos.color = GizmoUtility.ColorPenetration;
- Gizmos.DrawLine(bpos, bpos + dir * 0.1f);
- }
- }
- #endif
- /// <summary>
- /// エディタ状態での浸透制限表示
- /// </summary>
- /// <param name="team"></param>
- /// <param name="clothData"></param>
- /// <param name="posList"></param>
- /// <param name="selList"></param>
- static void DrawPenetrationClothData(
- PhysicsTeam team,
- ClothParams param,
- ClothData clothData,
- List<Vector3> posList,
- List<Vector3> norList,
- List<Vector3> tanList,
- List<int> selList
- )
- {
- if (ClothMonitorMenu.Monitor.UI.DrawClothPenetration == false)
- return;
- //var mode = param.GetPenetrationMode();
- var mode = clothData.penetrationMode;
- if (clothData.penetrationDataList == null)
- return;
- if (clothData.penetrationReferenceList == null)
- return;
- var colliderlist = team.TeamData.ColliderList;
- for (int i = 0; i < clothData.VertexUseCount; i++)
- {
- int vindex = clothData.useVertexList[i];
- if (vindex >= posList.Count)
- continue;
- if (IsMove(vindex, selList) == false)
- continue;
- //Vector3 pos = posList[vindex];
- if (i >= clothData.penetrationReferenceList.Length)
- return;
- var refdata = clothData.penetrationReferenceList[i];
- for (int j = 0; j < refdata.count; j++)
- {
- var dindex = refdata.startIndex + j;
- var data = clothData.penetrationDataList[dindex];
- if (data.IsValid() == false)
- continue;
- if (mode == ClothParams.PenetrationMode.SurfacePenetration)
- {
- var pos = posList[vindex];
- var rot = Quaternion.LookRotation(norList[vindex], tanList[vindex]);
- var dir = rot * data.localDir;
- var depth = clothData.vertexDepthList[i];
- var dist = param.GetPenetrationDistance().Evaluate(depth);
- Gizmos.color = GizmoUtility.ColorPenetration;
- Gizmos.DrawLine(pos, pos + dir * dist);
- break;
- }
- else if (mode == ClothParams.PenetrationMode.ColliderPenetration)
- {
- int cindex = data.colliderIndex;
- if (cindex >= colliderlist.Count)
- continue;
- var col = colliderlist[cindex];
- if (col == null)
- continue;
- var cp = col.transform.TransformPoint(data.localPos);
- var pos = cp + col.transform.TransformDirection(data.localDir) * data.distance;
- Gizmos.color = GizmoUtility.ColorPenetration;
- Gizmos.DrawLine(pos, cp);
- }
- }
- }
- }
- #if false // 一旦休眠
- static void DrawBonePenetrationClothData(
- PhysicsTeam team,
- ClothParams param,
- ClothData clothData,
- List<Vector3> posList,
- List<Vector3> norList,
- List<Vector3> tanList,
- List<int> selList
- )
- {
- if (ClothMonitorMenu.Monitor.UI.DrawClothPenetration == false)
- return;
- var mode = clothData.penetrationMode;
- if (mode != ClothParams.PenetrationMode.BonePenetration)
- return;
- if (clothData.penetrationDirectionDataList == null)
- return;
- for (int i = 0; i < clothData.VertexUseCount; i++)
- {
- int vindex = clothData.useVertexList[i];
- if (IsMove(vindex, selList) == false)
- continue;
- if (i >= clothData.penetrationDirectionDataList.Length)
- return;
- var depth = clothData.vertexDepthList[i];
- if (depth > param.PenetrationMaxDepth)
- continue;
- var pos = posList[vindex];
- var rot = Quaternion.LookRotation(norList[vindex], tanList[vindex]);
- var ldir = clothData.penetrationDirectionDataList[i];
- var dir = rot * ldir;
- Gizmos.color = Color.blue;
- //Gizmos.color = GizmoUtility.ColorPenetration;
- Gizmos.DrawLine(pos, pos + dir * 0.1f);
- }
- }
- #endif
- //=========================================================================================
- /// <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, false);
- }
- if (ClothMonitorMenu.Monitor.UI.DrawClothBendDistanceLine)
- {
- DrawLineRuntimeSub(team, GizmoUtility.ColorBendLine, clothData.bendDistanceDataList, false);
- }
- if (ClothMonitorMenu.Monitor.UI.DrawClothNearDistanceLine)
- {
- DrawLineRuntimeSub(team, GizmoUtility.ColorNearLine, clothData.nearDistanceDataList, false);
- }
- if (ClothMonitorMenu.Monitor.UI.DrawClothBase)
- {
- DrawLineRuntimeSub(team, Color.red, clothData.structDistanceDataList, true);
- }
- }
- static void DrawLineRuntimeSub(
- PhysicsTeam team,
- Color color,
- RestoreDistanceConstraint.RestoreDistanceData[] distanceDataList,
- bool useBase
- )
- {
- if (distanceDataList == null || distanceDataList.Length == 0)
- return;
- var manager = MagicaPhysicsManager.Instance;
- Gizmos.color = color;
- int cnt = distanceDataList.Length;
- for (int i = 0; i < cnt; i++)
- {
- var data = distanceDataList[i];
- int vindex0, vindex1;
- vindex0 = data.vertexIndex;
- vindex1 = data.targetVertexIndex;
- int pindex0 = team.ParticleChunk.startIndex + vindex0;
- int pindex1 = team.ParticleChunk.startIndex + vindex1;
- Vector3 pos0 = useBase ? manager.Particle.basePosList[pindex0] : manager.Particle.posList[pindex0];
- Vector3 pos1 = useBase ? manager.Particle.basePosList[pindex1] : manager.Particle.posList[pindex1];
- Gizmos.DrawLine(pos0, pos1);
- }
- }
- /// <summary>
- /// エディタ状態でのライン表示
- /// </summary>
- /// <param name="scr"></param>
- /// <param name="deformer"></param>
- /// <param name="clothData"></param>
- static void DrawLineClothData(
- ClothData clothData,
- List<Vector3> posList,
- List<int> selList
- )
- {
- if (clothData == null)
- return;
- if (ClothMonitorMenu.Monitor.UI.DrawClothStructDistanceLine)
- {
- DrawLineClothDataSub(clothData, posList, GizmoUtility.ColorStructLine, clothData.structDistanceDataList);
- }
- if (ClothMonitorMenu.Monitor.UI.DrawClothBendDistanceLine)
- {
- DrawLineClothDataSub(clothData, posList, GizmoUtility.ColorBendLine, clothData.bendDistanceDataList);
- }
- if (ClothMonitorMenu.Monitor.UI.DrawClothNearDistanceLine)
- {
- DrawLineClothDataSub(clothData, posList, GizmoUtility.ColorNearLine, clothData.nearDistanceDataList);
- }
- if (ClothMonitorMenu.Monitor.UI.DrawClothBase)
- {
- DrawLineClothDataSub(clothData, posList, Color.red, clothData.structDistanceDataList);
- }
- }
- static void DrawLineClothDataSub(
- ClothData clothData,
- List<Vector3> posList,
- Color color,
- RestoreDistanceConstraint.RestoreDistanceData[] distanceDataList
- )
- {
- if (distanceDataList == null || distanceDataList.Length == 0)
- return;
- Gizmos.color = color;
- int cnt = distanceDataList.Length;
- for (int i = 0; i < cnt; i++)
- {
- var data = distanceDataList[i];
- int index0, index1;
- index0 = data.vertexIndex;
- index1 = data.targetVertexIndex;
- int vindex0 = clothData.useVertexList[index0];
- int vindex1 = clothData.useVertexList[index1];
- if (vindex0 >= posList.Count || vindex1 >= posList.Count)
- continue;
- Vector3 pos0 = posList[vindex0];
- Vector3 pos1 = posList[vindex1];
- Gizmos.DrawLine(pos0, pos1);
- }
- }
- //=========================================================================================
- /// <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);
- }
- }
- /// <summary>
- /// エディタ状態での回転ライン表示
- /// </summary>
- /// <param name="scr"></param>
- /// <param name="deformer"></param>
- /// <param name="clothData"></param>
- static void DrawRotationLineClothData(
- ClothData clothData,
- List<Vector3> posList,
- List<int> selList
- )
- {
- if (ClothMonitorMenu.Monitor.UI.DrawClothRotationLine == false)
- return;
- if (clothData == null)
- return;
- if (clothData.parentList == null || clothData.parentList.Count != clothData.VertexUseCount)
- return;
- Gizmos.color = GizmoUtility.ColorRotationLine;
- for (int i = 0; i < clothData.VertexUseCount; i++)
- {
- int pi = clothData.parentList[i];
- if (pi < 0)
- continue;
- int vindex0 = clothData.useVertexList[i];
- int vindex1 = clothData.useVertexList[pi];
- if (vindex0 >= posList.Count || vindex1 >= posList.Count)
- continue;
- Vector3 pos0 = posList[vindex0];
- Vector3 pos1 = posList[vindex1];
- Gizmos.DrawLine(pos0, pos1);
- }
- }
- //=========================================================================================
- #if false
- static void DrawAdjustRotationLineRuntime(
- PhysicsTeam team,
- ClothData clothData
- )
- {
- if (ClothMonitorMenu.Monitor.UI.DrawAdjustRotationLine == false)
- return;
- var manager = MagicaPhysicsManager.Instance;
- Gizmos.color = GizmoUtility.ColorAdjustLine;
- int cnt = clothData.AdjustRotationConstraintCount;
- for (int i = 0; i < cnt; i++)
- {
- var data = clothData.adjustRotationDataList[i];
- int tindex = data.targetIndex;
- if (tindex < 0)
- tindex = -tindex - 1;
- int pindex0 = team.ParticleChunk.startIndex + data.keyIndex;
- int pindex1 = team.ParticleChunk.startIndex + tindex;
- Vector3 pos0 = manager.Particle.posList[pindex0];
- Vector3 pos1 = manager.Particle.posList[pindex1];
- Gizmos.DrawLine(pos0, pos1);
- }
- }
- static void DrawAdjustRotationLineClothData(
- ClothData clothData,
- List<Vector3> posList
- )
- {
- if (ClothMonitorMenu.Monitor.UI.DrawAdjustRotationLine == false)
- return;
- if (clothData == null)
- return;
- Gizmos.color = GizmoUtility.ColorAdjustLine;
- int cnt = clothData.AdjustRotationConstraintCount;
- for (int i = 0; i < cnt; i++)
- {
- var data = clothData.adjustRotationDataList[i];
- int tindex = data.targetIndex;
- if (tindex < 0)
- tindex = -tindex - 1;
- int vindex0 = clothData.useVertexList[data.keyIndex];
- int vindex1 = clothData.useVertexList[tindex];
- Vector3 pos0 = posList[vindex0];
- Vector3 pos1 = posList[vindex1];
- Gizmos.DrawLine(pos0, pos1);
- }
- }
- #endif
- //=========================================================================================
- /// <summary>
- /// ランタイム状態でのトライアングルベンド表示
- /// </summary>
- /// <param name="scr"></param>
- /// <param name="deformer"></param>
- /// <param name="clothData"></param>
- static void DrawTriangleBendRuntime(
- PhysicsTeam team,
- ClothData clothData,
- ClothSetup setup
- )
- {
- if (ClothMonitorMenu.Monitor.UI.DrawClothTriangleBend == false)
- return;
- var manager = MagicaPhysicsManager.Instance;
- Gizmos.color = GizmoUtility.ColorTriangle;
- int cnt = clothData.TriangleBendConstraintCount;
- for (int i = 0; i < cnt; i++)
- {
- var data = clothData.triangleBendDataList[i];
- int pindex0 = team.ParticleChunk.startIndex + data.vindex0;
- int pindex1 = team.ParticleChunk.startIndex + data.vindex1;
- int pindex2 = team.ParticleChunk.startIndex + data.vindex2;
- Vector3 pos0 = manager.Particle.posList[pindex0];
- Vector3 pos1 = manager.Particle.posList[pindex1];
- Vector3 pos2 = manager.Particle.posList[pindex2];
- if (data.IsPositionBend() == false)
- {
- int pindex3 = team.ParticleChunk.startIndex + data.vindex3;
- Vector3 pos3 = manager.Particle.posList[pindex3];
- Gizmos.DrawLine(pos0, pos2);
- Gizmos.DrawLine(pos0, pos3);
- Gizmos.DrawLine(pos2, pos3);
- Gizmos.DrawLine(pos2, pos1);
- Gizmos.DrawLine(pos3, pos1);
- }
- else
- {
- Gizmos.DrawLine(pos0, pos1);
- Gizmos.DrawLine(pos0, pos2);
- Gizmos.DrawLine(pos1, pos2);
- }
- }
- }
- /// <summary>
- /// エディタ状態でのトライアングルベンド表示
- /// </summary>
- /// <param name="scr"></param>
- /// <param name="deformer"></param>
- /// <param name="clothData"></param>
- static void DrawTriangleBendClothData(
- ClothData clothData,
- List<Vector3> posList
- )
- {
- if (ClothMonitorMenu.Monitor.UI.DrawClothTriangleBend == false)
- return;
- if (clothData == null)
- return;
- Gizmos.color = GizmoUtility.ColorTriangle;
- int cnt = clothData.TriangleBendConstraintCount;
- for (int i = 0; i < cnt; i++)
- {
- var data = clothData.triangleBendDataList[i];
- int vindex0 = clothData.useVertexList[data.vindex0];
- int vindex1 = clothData.useVertexList[data.vindex1];
- int vindex2 = clothData.useVertexList[data.vindex2];
- Vector3 pos0 = posList[vindex0];
- Vector3 pos1 = posList[vindex1];
- Vector3 pos2 = posList[vindex2];
- if (data.IsPositionBend() == false)
- {
- int vindex3 = clothData.useVertexList[data.vindex3];
- Vector3 pos3 = posList[vindex3];
- Gizmos.DrawLine(pos0, pos2);
- Gizmos.DrawLine(pos0, pos3);
- Gizmos.DrawLine(pos2, pos3);
- Gizmos.DrawLine(pos2, pos1);
- Gizmos.DrawLine(pos3, pos1);
- }
- else
- {
- Gizmos.DrawLine(pos0, pos1);
- Gizmos.DrawLine(pos0, pos2);
- Gizmos.DrawLine(pos1, pos2);
- }
- }
- }
- //=========================================================================================
- #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 DrawVolumeClothData(
- ClothData clothData,
- List<Vector3> posList
- )
- {
- if (ClothMonitorMenu.Monitor.UI.DrawClothVolume == false)
- return;
- if (clothData == null)
- return;
- Gizmos.color = GizmoUtility.ColorTriangle;
- int cnt = clothData.VolumeConstraintCount;
- for (int i = 0; i < cnt; i++)
- {
- var data = clothData.volumeDataList[i];
- int vindex0 = clothData.useVertexList[data.vindex0];
- int vindex1 = clothData.useVertexList[data.vindex1];
- int vindex2 = clothData.useVertexList[data.vindex2];
- int vindex3 = clothData.useVertexList[data.vindex3];
- Vector3 pos0 = posList[vindex0];
- Vector3 pos1 = posList[vindex1];
- Vector3 pos2 = posList[vindex2];
- Vector3 pos3 = posList[vindex3];
- Gizmos.DrawLine(pos0, pos1);
- Gizmos.DrawLine(pos0, pos2);
- Gizmos.DrawLine(pos0, pos3);
- Gizmos.DrawLine(pos1, pos2);
- Gizmos.DrawLine(pos2, pos3);
- Gizmos.DrawLine(pos3, pos1);
- }
- }
- #endif
- }
- }
|