Optimize Physics

This commit is contained in:
CroakFang
2022-11-09 18:16:24 +08:00
parent 5b8a376a81
commit e5f4cdb10c
5 changed files with 33 additions and 15 deletions
@@ -82,11 +82,13 @@ public class DynamicBone : MonoBehaviour
[Tooltip("The force apply to bones.")]
#endif
public Vector3 m_Force = Vector3.zero;
#if UNITY_5_3_OR_NEWER
[Tooltip("Bones exclude from physics simulation.")]
[Tooltip("The limit angle to bones.")]
#endif
public Vector3 m_LimitAngel_Min = Vector3.zero;
public Vector3 m_LimitAngel_Max = Vector3.zero;
#if UNITY_5_3_OR_NEWER
[Tooltip("Bones exclude from physics simulation.")]
#endif
public List<Transform> m_Exclusions = null;
@@ -131,6 +133,9 @@ public class DynamicBone : MonoBehaviour
public float m_BoneLength = 0;
public bool m_isCollide = false;
public Vector3 m_LimitAngel_Min = Vector3.zero;
public Vector3 m_LimitAngel_Max = Vector3.zero;
public Vector3 m_Position = Vector3.zero;
public Vector3 m_PrevPosition = Vector3.zero;
public Vector3 m_EndOffset = Vector3.zero;
@@ -417,6 +422,8 @@ public class DynamicBone : MonoBehaviour
p.m_Inert = m_Inert;
p.m_Friction = m_Friction;
p.m_Radius = m_Radius;
p.m_LimitAngel_Min = m_LimitAngel_Min;
p.m_LimitAngel_Max = m_LimitAngel_Max;
if (m_BoneTotalLength > 0)
{
@@ -529,7 +536,8 @@ public class DynamicBone : MonoBehaviour
// keep shape
float stiffness = Mathf.Lerp(1.0f, p.m_Stiffness, m_Weight);
if (stiffness > 0 || p.m_Elasticity > 0)
float elasticity = p.m_Elasticity;
if (stiffness > 0 || elasticity > 0)
{
Matrix4x4 m0 = p0.m_Transform.localToWorldMatrix;
m0.SetColumn(3, p0.m_Position);
@@ -540,7 +548,7 @@ public class DynamicBone : MonoBehaviour
restPos = m0.MultiplyPoint3x4(p.m_EndOffset);
Vector3 d = restPos - p.m_Position;
p.m_Position += d * (p.m_Elasticity * timeVar);
p.m_Position += d * (elasticity * timeVar);
if (stiffness > 0)
{
+1 -1
View File
@@ -167,7 +167,7 @@ public class UmaViewerBuilder : MonoBehaviour
//Load Physics
foreach (var asset1 in UmaViewerMain.Instance.AbChara.Where(a => a.Name.StartsWith(UmaDatabaseController.BodyPath + $"bdy{id}_{costumeId}/clothes")))
{
if (asset1.Name.Contains("cloth04"))
if (asset1.Name.Contains("cloth00"))
RecursiveLoadAsset(asset1);
}
}
+2 -1
View File
@@ -8,8 +8,9 @@ public class UmaViewerDownload : MonoBehaviour
public static IEnumerator DownloadText(string url, System.Action<string> callback)
{
UnityWebRequest www = UnityWebRequest.Get(url);
www.timeout = 3;
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
Debug.Log(www.error);
@@ -36,6 +36,9 @@ namespace Gallop
DynamicBones.Clear();
List<Transform> gameObjects = new List<Transform>();
gameObjects.AddRange(transform.parent.transform.parent.GetComponentsInChildren<Transform>());
List<DynamicBoneColliderBase> colliders = new List<DynamicBoneColliderBase>();
foreach (CySpringCollisionData collider in collisionParam)
{
if (collider._isInner) continue;
@@ -61,6 +64,7 @@ namespace Gallop
dynamic.m_Height = (collider._offset - collider._offset2).magnitude + collider._radius;
dynamic.m_Radius = collider._radius;
dynamic.m_Bound = collider._isInner ? DynamicBoneColliderBase.Bound.Inside : DynamicBoneColliderBase.Bound.Outside;
colliders.Add(dynamic);
break;
case CySpringCollisionData.CollisionType.Sphere:
var Spheredynamic = child.AddComponent<DynamicBoneCollider>();
@@ -69,12 +73,14 @@ namespace Gallop
Spheredynamic.m_Radius = collider._radius;
Spheredynamic.m_Height = collider._distance;
Spheredynamic.m_Bound = collider._isInner ? DynamicBoneColliderBase.Bound.Inside : DynamicBoneColliderBase.Bound.Outside;
colliders.Add(Spheredynamic);
break;
case CySpringCollisionData.CollisionType.Plane:
var planedynamic = child.AddComponent<DynamicBonePlaneCollider>();
planedynamic.ColliderName = collider._collisionName;
child.transform.localPosition = collider._offset;
planedynamic.m_Bound = collider._isInner ? DynamicBoneColliderBase.Bound.Inside : DynamicBoneColliderBase.Bound.Outside;
colliders.Add(planedynamic);
break;
case CySpringCollisionData.CollisionType.None:
break;
@@ -82,8 +88,7 @@ namespace Gallop
}
}
gameObjects.Clear();
gameObjects.AddRange(transform.parent.transform.parent.GetComponentsInChildren<Transform>());
foreach(CySpringParamDataElement spring in springParam)
{
var bone = gameObjects.Find(a => { return a.name == spring._boneName; });
@@ -94,6 +99,8 @@ namespace Gallop
dynamic.m_Root = bone;
dynamic.m_UpdateMode = DynamicBone.UpdateMode.Normal;
dynamic.m_Gravity = new Vector3(0, Mathf.Clamp01(-30 / spring._gravity), 0);
dynamic.m_LimitAngel_Min = spring._limitAngleMin;
dynamic.m_LimitAngel_Max = spring._limitAngleMax;
if (isTail)
{
dynamic.m_Damping = 0.1f;
@@ -108,13 +115,13 @@ namespace Gallop
}
dynamic.m_Radius = spring._collisionRadius;
dynamic.m_Friction = 0.5f;
dynamic.SetupParticles();
DynamicBones.Add(dynamic);
foreach (string collisionName in spring._collisionNameList)
{
var tmp = gameObjects.Find(a => { return a.name == collisionName; });
var tmp = colliders.Find(a => { return a.gameObject.name == collisionName; });
if (tmp)
{
dynamic.Particles[0].m_Colliders.Add(tmp.GetComponent<DynamicBoneColliderBase>());
@@ -137,10 +144,13 @@ namespace Gallop
tempParticle.m_Stiffness = Mathf.Clamp01(45 / spring._stiffnessForce);
tempParticle.m_Elasticity = Mathf.Clamp01(45 / spring._dragForce);
}
tempParticle.m_Friction = 0.5f;
tempParticle.m_Radius = Childcollision._collisionRadius;
tempParticle.m_LimitAngel_Min = Childcollision._limitAngleMin;
tempParticle.m_LimitAngel_Max = Childcollision._limitAngleMax;
foreach (string collisionName in Childcollision._collisionNameList)
{
var tmp = gameObjects.Find(a => { return a.name == collisionName; });
var tmp = colliders.Find(a => { return a.gameObject.name == collisionName; });
if (tmp)
{
tempParticle.m_Colliders.Add(tmp.GetComponent<DynamicBoneColliderBase>());
@@ -148,7 +158,6 @@ namespace Gallop
}
}
}
}
}
}