Publish verified live restoration source snapshot and known limits

This commit is contained in:
0xcjy
2026-10-01 19:42:22 +08:00
parent 0dd0d3bdaa
commit d70a65c7ce
896 changed files with 105420 additions and 12745 deletions
@@ -1,9 +1,11 @@
using UnityEngine;
using UnityEngine;
using System.Collections.Generic;
[AddComponentMenu("Dynamic Bone/Dynamic Bone")]
public class DynamicBone : MonoBehaviour
{
private static readonly Unity.Profiling.ProfilerMarker LivePhysicsMarker =
new Unity.Profiling.ProfilerMarker("Live.DynamicBone");
#if UNITY_5_3_OR_NEWER
[Tooltip("The root of the transform hierarchy to apply physics.")]
#endif
@@ -175,6 +177,8 @@ public class DynamicBone : MonoBehaviour
void LateUpdate()
{
using (LivePhysicsMarker.Auto())
{
if (m_DistantDisable)
CheckDistance();
@@ -187,6 +191,7 @@ public class DynamicBone : MonoBehaviour
#endif
UpdateDynamicBones(dt);
}
}
}
void PreUpdate()
@@ -326,18 +331,22 @@ public class DynamicBone : MonoBehaviour
}
}
if (loop > 0)
using (DynamicBoneCollider.BeginCollisionBatch())
{
for (int i = 0; i < loop; ++i)
if (loop > 0)
{
UpdateParticles1(timeVar);
UpdateParticles2(timeVar);
m_ObjectMove = Vector3.zero;
for (int i = 0; i < loop; ++i)
{
UpdateParticles1(timeVar);
UpdateParticles2(timeVar);
m_ObjectMove = Vector3.zero;
}
}
}
else
{
SkipUpdateParticles();
else
{
SkipUpdateParticles();
}
}
ApplyParticlesToTransforms();
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
[AddComponentMenu("Dynamic Bone/Dynamic Bone Collider")]
public class DynamicBoneCollider : DynamicBoneColliderBase
@@ -19,7 +19,64 @@ public class DynamicBoneCollider : DynamicBoneColliderBase
m_Height = Mathf.Max(m_Height, 0);
}
// A batch ends BEFORE particle poses are written back to Transforms. Never cache
// across bones or frames: one chain can move a collider used by the next chain.
public static bool UseGeometryCache = true;
private static ulong nextBatch;
private static ulong activeBatch;
private ulong geometryBatch;
private float worldRadius;
private bool isSphere;
private Vector3 worldStart, worldEnd;
public struct CollisionBatch : System.IDisposable
{
private readonly ulong previous;
internal CollisionBatch(ulong previousBatch) { previous = previousBatch; }
public void Dispose() { activeBatch = previous; }
}
public static CollisionBatch BeginCollisionBatch()
{
var scope = new CollisionBatch(activeBatch);
activeBatch = ++nextBatch;
if (activeBatch == 0) activeBatch = ++nextBatch;
return scope;
}
public override bool Collide(ref Vector3 particlePosition, float particleRadius)
{
if (!UseGeometryCache || activeBatch == 0)
return CollideUncached(ref particlePosition, particleRadius);
if (geometryBatch != activeBatch)
{
worldRadius = m_Radius * Mathf.Abs(transform.lossyScale.x);
float halfSpan = m_Height * 0.5f - m_Radius;
isSphere = halfSpan <= 0f;
Vector3 start = m_Center, end = m_Center;
if (!isSphere)
{
switch (m_Direction)
{
case Direction.X: start.x -= halfSpan; end.x += halfSpan; break;
case Direction.Y: start.y -= halfSpan; end.y += halfSpan; break;
case Direction.Z: start.z -= halfSpan; end.z += halfSpan; break;
}
}
worldStart = transform.TransformPoint(start);
worldEnd = isSphere ? worldStart : transform.TransformPoint(end);
geometryBatch = activeBatch;
}
if (isSphere)
return m_Bound == Bound.Outside
? OutsideSphere(ref particlePosition, particleRadius, worldStart, worldRadius)
: InsideSphere(ref particlePosition, particleRadius, worldStart, worldRadius);
return m_Bound == Bound.Outside
? OutsideCapsule(ref particlePosition, particleRadius, worldStart, worldEnd, worldRadius)
: InsideCapsule(ref particlePosition, particleRadius, worldStart, worldEnd, worldRadius);
}
private bool CollideUncached(ref Vector3 particlePosition, float particleRadius)
{
float radius = m_Radius * Mathf.Abs(transform.lossyScale.x);
float h = m_Height * 0.5f - m_Radius;