Live: add monitors, cyalumes, and skirt collision tuning
This commit is contained in:
@@ -63,6 +63,12 @@ public class DynamicBone : MonoBehaviour
|
||||
public float m_Radius = 0;
|
||||
public AnimationCurve m_RadiusDistrib = null;
|
||||
|
||||
// Point-only collision allows a long skirt bone segment to pass through a
|
||||
// limb even when both of its endpoints are outside the collider.
|
||||
public bool m_ContinuousCollision = false;
|
||||
// Assigned by the CySpring importer so runtime tuning can target a semantic group.
|
||||
public string m_MotionGroup = string.Empty;
|
||||
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
[Tooltip("If End Length is not zero, an extra bone is generated at the end of transform hierarchy.")]
|
||||
#endif
|
||||
@@ -118,6 +124,10 @@ public class DynamicBone : MonoBehaviour
|
||||
float m_Time = 0;
|
||||
float m_Weight = 1.0f;
|
||||
bool m_DistantDisabled = false;
|
||||
Transform m_MotionReference = null;
|
||||
Vector3 m_MotionReferencePrevPosition = Vector3.zero;
|
||||
Quaternion m_MotionReferencePrevRotation = Quaternion.identity;
|
||||
bool m_MotionReferenceInitialized = false;
|
||||
|
||||
public class Particle
|
||||
{
|
||||
@@ -138,6 +148,7 @@ public class DynamicBone : MonoBehaviour
|
||||
public Vector3 m_LimitAngel_Max = Vector3.zero;
|
||||
public Vector3 m_Position = Vector3.zero;
|
||||
public Vector3 m_PrevPosition = Vector3.zero;
|
||||
public Vector3 m_PreviousFramePosition = Vector3.zero;
|
||||
public Vector3 m_EndOffset = Vector3.zero;
|
||||
public Vector3 m_InitLocalPosition = Vector3.zero;
|
||||
public Quaternion m_InitLocalRotation = Quaternion.identity;
|
||||
@@ -277,6 +288,7 @@ public class DynamicBone : MonoBehaviour
|
||||
return;
|
||||
|
||||
m_ObjectScale = Mathf.Abs(transform.lossyScale.x);
|
||||
StabilizeLargeReferenceMotion();
|
||||
m_ObjectMove = transform.position - m_ObjectPrevPosition;
|
||||
m_ObjectPrevPosition = transform.position;
|
||||
|
||||
@@ -287,11 +299,11 @@ public class DynamicBone : MonoBehaviour
|
||||
{
|
||||
if (m_UpdateRate > 0)
|
||||
{
|
||||
timeVar = Time.deltaTime * m_UpdateRate;
|
||||
timeVar = Mathf.Min(t * m_UpdateRate, 1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
timeVar = Time.deltaTime;
|
||||
timeVar = t;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -344,6 +356,62 @@ public class DynamicBone : MonoBehaviour
|
||||
m_BoneTotalLength = 0;
|
||||
AppendParticles(m_Root, -1, 0);
|
||||
UpdateParameters();
|
||||
ResetMotionReference();
|
||||
}
|
||||
|
||||
private void ResetMotionReference()
|
||||
{
|
||||
m_MotionReference = m_Root != null && m_Root.parent != null ? m_Root.parent : m_Root;
|
||||
if (m_MotionReference == null)
|
||||
{
|
||||
m_MotionReferenceInitialized = false;
|
||||
return;
|
||||
}
|
||||
|
||||
m_MotionReferencePrevPosition = m_MotionReference.position;
|
||||
m_MotionReferencePrevRotation = m_MotionReference.rotation;
|
||||
m_MotionReferenceInitialized = true;
|
||||
}
|
||||
|
||||
private void StabilizeLargeReferenceMotion()
|
||||
{
|
||||
Transform currentReference = m_Root != null && m_Root.parent != null ? m_Root.parent : m_Root;
|
||||
if (currentReference == null)
|
||||
return;
|
||||
|
||||
if (!m_MotionReferenceInitialized || currentReference != m_MotionReference)
|
||||
{
|
||||
ResetMotionReference();
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 currentPosition = currentReference.position;
|
||||
Quaternion currentRotation = currentReference.rotation;
|
||||
float translation = Vector3.Distance(currentPosition, m_MotionReferencePrevPosition);
|
||||
float rotation = Quaternion.Angle(m_MotionReferencePrevRotation, currentRotation);
|
||||
float translationThreshold = Mathf.Max(0.05f * m_ObjectScale, m_BoneTotalLength * 0.2f);
|
||||
|
||||
if (translation > translationThreshold || rotation > 30f)
|
||||
{
|
||||
Quaternion rotationDelta = currentRotation * Quaternion.Inverse(m_MotionReferencePrevRotation);
|
||||
for (int i = 0; i < Particles.Count; ++i)
|
||||
{
|
||||
Particle particle = Particles[i];
|
||||
particle.m_Position = currentPosition + rotationDelta *
|
||||
(particle.m_Position - m_MotionReferencePrevPosition);
|
||||
particle.m_PrevPosition = currentPosition + rotationDelta *
|
||||
(particle.m_PrevPosition - m_MotionReferencePrevPosition);
|
||||
particle.m_PreviousFramePosition = currentPosition + rotationDelta *
|
||||
(particle.m_PreviousFramePosition - m_MotionReferencePrevPosition);
|
||||
}
|
||||
|
||||
// The animated parent motion has already been applied to the particle
|
||||
// state and must not be counted again as Verlet velocity/inertia.
|
||||
m_ObjectPrevPosition = transform.position;
|
||||
}
|
||||
|
||||
m_MotionReferencePrevPosition = currentPosition;
|
||||
m_MotionReferencePrevRotation = currentRotation;
|
||||
}
|
||||
|
||||
void AppendParticles(Transform b, int parentIndex, float boneLength)
|
||||
@@ -472,15 +540,18 @@ public class DynamicBone : MonoBehaviour
|
||||
if (p.m_Transform != null)
|
||||
{
|
||||
p.m_Position = p.m_PrevPosition = p.m_Transform.position;
|
||||
p.m_PreviousFramePosition = p.m_Position;
|
||||
}
|
||||
else // end bone
|
||||
{
|
||||
Transform pb = Particles[p.m_ParentIndex].m_Transform;
|
||||
p.m_Position = p.m_PrevPosition = pb.TransformPoint(p.m_EndOffset);
|
||||
p.m_PreviousFramePosition = p.m_Position;
|
||||
}
|
||||
p.m_isCollide = false;
|
||||
}
|
||||
m_ObjectPrevPosition = transform.position;
|
||||
ResetMotionReference();
|
||||
}
|
||||
|
||||
void UpdateParticles1(float timeVar)
|
||||
@@ -497,8 +568,16 @@ public class DynamicBone : MonoBehaviour
|
||||
Particle p = Particles[i];
|
||||
if (p.m_ParentIndex >= 0)
|
||||
{
|
||||
p.m_PreviousFramePosition = p.m_Position;
|
||||
// verlet integration
|
||||
Vector3 v = p.m_Position - p.m_PrevPosition;
|
||||
if (m_ContinuousCollision)
|
||||
{
|
||||
Particle parent = Particles[p.m_ParentIndex];
|
||||
float maxStep = Vector3.Distance(parent.m_Position, p.m_Position);
|
||||
if (maxStep > Mathf.Epsilon)
|
||||
v = Vector3.ClampMagnitude(v, maxStep);
|
||||
}
|
||||
Vector3 rmove = m_ObjectMove * p.m_Inert;
|
||||
p.m_PrevPosition = p.m_Position + rmove;
|
||||
float damping = p.m_Damping;
|
||||
@@ -560,18 +639,6 @@ public class DynamicBone : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// collide
|
||||
if (p.m_Colliders != null)
|
||||
{
|
||||
float particleRadius = p.m_Radius * m_ObjectScale;
|
||||
for (int j = 0; j < p.m_Colliders.Count; ++j)
|
||||
{
|
||||
DynamicBoneColliderBase c = p.m_Colliders[j];
|
||||
if (c != null && c.enabled)
|
||||
p.m_isCollide |= c.Collide(ref p.m_Position, particleRadius);
|
||||
}
|
||||
}
|
||||
|
||||
// freeze axis, project to plane
|
||||
if (m_FreezeAxis != FreezeAxis.None)
|
||||
{
|
||||
@@ -595,9 +662,110 @@ public class DynamicBone : MonoBehaviour
|
||||
float leng = dd.magnitude;
|
||||
if (leng > 0)
|
||||
p.m_Position += dd * ((leng - restLen) / leng);
|
||||
|
||||
// This must be the final positional constraint. Otherwise the
|
||||
// length correction can pull the skirt back inside a leg volume.
|
||||
float particleRadius = p.m_Radius * m_ObjectScale;
|
||||
ResolveParticleCollisions(p, particleRadius);
|
||||
|
||||
if (m_ContinuousCollision)
|
||||
{
|
||||
ResolveSegmentCollisions(p0, p, particleRadius);
|
||||
ResolveSweptCollisions(p, particleRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ResolveParticleCollisions(Particle particle, float particleRadius)
|
||||
{
|
||||
if (particle.m_Colliders == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < particle.m_Colliders.Count; ++i)
|
||||
{
|
||||
DynamicBoneColliderBase collider = particle.m_Colliders[i];
|
||||
if (collider != null && collider.enabled)
|
||||
particle.m_isCollide |= collider.Collide(ref particle.m_Position, particleRadius);
|
||||
}
|
||||
}
|
||||
|
||||
private void ResolveSegmentCollisions(Particle parent, Particle particle, float particleRadius)
|
||||
{
|
||||
if (particle.m_Colliders == null)
|
||||
return;
|
||||
|
||||
Vector3 correction = Vector3.zero;
|
||||
|
||||
// Test several points because a segment can enter a capsule near either
|
||||
// endpoint while its midpoint remains outside.
|
||||
for (int sampleIndex = 1; sampleIndex <= 3; ++sampleIndex)
|
||||
{
|
||||
float t = sampleIndex * 0.25f;
|
||||
Vector3 segmentPoint = Vector3.Lerp(parent.m_Position, particle.m_Position, t);
|
||||
for (int i = 0; i < particle.m_Colliders.Count; ++i)
|
||||
{
|
||||
DynamicBoneColliderBase collider = particle.m_Colliders[i];
|
||||
if (collider == null || !collider.enabled)
|
||||
continue;
|
||||
|
||||
Vector3 projectedPoint = segmentPoint;
|
||||
if (!collider.Collide(ref projectedPoint, particleRadius))
|
||||
continue;
|
||||
|
||||
// Move the child enough to move this sample onto the surface.
|
||||
Vector3 candidate = (projectedPoint - segmentPoint) / t;
|
||||
if (candidate.sqrMagnitude > correction.sqrMagnitude)
|
||||
correction = candidate;
|
||||
}
|
||||
}
|
||||
|
||||
if (correction == Vector3.zero)
|
||||
return;
|
||||
|
||||
particle.m_Position += correction;
|
||||
particle.m_PrevPosition += correction;
|
||||
particle.m_isCollide = true;
|
||||
ResolveParticleCollisions(particle, particleRadius);
|
||||
}
|
||||
|
||||
private void ResolveSweptCollisions(Particle particle, float particleRadius)
|
||||
{
|
||||
if (particle.m_Colliders == null)
|
||||
return;
|
||||
|
||||
Vector3 start = particle.m_PreviousFramePosition;
|
||||
Vector3 end = particle.m_Position;
|
||||
|
||||
// Catch a skirt particle that crossed a leg between rendered frames.
|
||||
// The final point may already be outside the collider, so checking it
|
||||
// alone cannot detect this case.
|
||||
float travel = Vector3.Distance(start, end);
|
||||
int sampleCount = Mathf.Clamp(Mathf.CeilToInt(travel / Mathf.Max(particleRadius * 0.5f, 0.01f)), 4, 8);
|
||||
for (int sampleIndex = 1; sampleIndex <= sampleCount; ++sampleIndex)
|
||||
{
|
||||
float t = sampleIndex / (float)sampleCount;
|
||||
Vector3 probe = Vector3.Lerp(start, end, t);
|
||||
for (int i = 0; i < particle.m_Colliders.Count; ++i)
|
||||
{
|
||||
DynamicBoneColliderBase collider = particle.m_Colliders[i];
|
||||
if (collider == null || !collider.enabled)
|
||||
continue;
|
||||
|
||||
Vector3 projected = probe;
|
||||
if (!collider.Collide(ref projected, particleRadius))
|
||||
continue;
|
||||
|
||||
Vector3 correction = projected - probe;
|
||||
particle.m_Position += correction;
|
||||
particle.m_PrevPosition += correction;
|
||||
particle.m_isCollide = true;
|
||||
end = particle.m_Position;
|
||||
}
|
||||
}
|
||||
|
||||
ResolveParticleCollisions(particle, particleRadius);
|
||||
}
|
||||
|
||||
// only update stiffness and keep bone length
|
||||
void SkipUpdateParticles()
|
||||
{
|
||||
@@ -718,4 +886,9 @@ public class DynamicBone : MonoBehaviour
|
||||
p.m_Transform.position = p.m_Position;
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyParticlesToTransformsNow()
|
||||
{
|
||||
ApplyParticlesToTransforms();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,9 @@ public class HandleManager : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (UmaViewerUI.Instance == null || UmaViewerUI.Instance.PoseManager == null)
|
||||
return;
|
||||
|
||||
var camera = Camera.main;
|
||||
var poseModeOn = UmaViewerUI.Instance.PoseManager.PoseModeOn;
|
||||
|
||||
@@ -134,4 +137,4 @@ public class HandleManager : MonoBehaviour
|
||||
{
|
||||
EnabledLines = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,6 +353,109 @@ public class UmaContainerCharacter : UmaContainer
|
||||
{
|
||||
cySpringDataContainers[i].InitializePhysics(bones, colliders);
|
||||
}
|
||||
|
||||
SkirtSurfaceCollisionSolver surfaceSolver = GetComponent<SkirtSurfaceCollisionSolver>();
|
||||
if (surfaceSolver == null)
|
||||
surfaceSolver = gameObject.AddComponent<SkirtSurfaceCollisionSolver>();
|
||||
bones.TryGetValue("Hip", out Transform skirtHip);
|
||||
var skirtColliders = new List<DynamicBoneColliderBase>();
|
||||
foreach (Transform transform in colliders.Values)
|
||||
{
|
||||
DynamicBoneColliderBase collider = transform.GetComponent<DynamicBoneColliderBase>();
|
||||
if (collider != null)
|
||||
{
|
||||
if (IsBodySkirtCollider(collider) && collider.GetComponent<SkirtCollisionVisualizer>() == null)
|
||||
collider.gameObject.AddComponent<SkirtCollisionVisualizer>();
|
||||
if (IsThighSkirtCollider(collider.ColliderName))
|
||||
skirtColliders.Add(collider);
|
||||
}
|
||||
}
|
||||
surfaceSolver.Initialize(GetComponentsInChildren<DynamicBone>(true), skirtHip, skirtColliders);
|
||||
}
|
||||
|
||||
private static bool IsBodySkirtCollider(DynamicBoneColliderBase collider)
|
||||
{
|
||||
if (collider == null || string.IsNullOrEmpty(collider.ColliderName) ||
|
||||
collider.ColliderName.IndexOf("Skirt", StringComparison.OrdinalIgnoreCase) < 0)
|
||||
return false;
|
||||
|
||||
if (collider.ColliderName.IndexOf("Thigh", StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
return true;
|
||||
|
||||
DynamicBoneCollider dynamicCollider = collider as DynamicBoneCollider;
|
||||
bool isSideHip = collider.ColliderName.EndsWith("_L", StringComparison.OrdinalIgnoreCase) ||
|
||||
collider.ColliderName.EndsWith("_R", StringComparison.OrdinalIgnoreCase);
|
||||
return collider.ColliderName.IndexOf("Hip", StringComparison.OrdinalIgnoreCase) >= 0 &&
|
||||
isSideHip && (dynamicCollider == null || dynamicCollider.m_Radius <= 0.25f);
|
||||
}
|
||||
|
||||
private static bool IsThighSkirtCollider(string colliderName)
|
||||
{
|
||||
return !string.IsNullOrEmpty(colliderName) &&
|
||||
colliderName.IndexOf("Thigh", StringComparison.OrdinalIgnoreCase) >= 0 &&
|
||||
colliderName.IndexOf("MSkirt", StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
}
|
||||
|
||||
public void LoadSchoolUniformSkirtCollision(UmaDatabaseEntry entry)
|
||||
{
|
||||
if (entry == null)
|
||||
return;
|
||||
|
||||
GameObject source = entry.Get<GameObject>();
|
||||
if (source == null)
|
||||
return;
|
||||
|
||||
if (!PhysicsContainer)
|
||||
{
|
||||
PhysicsContainer = new GameObject("PhysicsController");
|
||||
PhysicsContainer.transform.SetParent(transform);
|
||||
}
|
||||
|
||||
CySpringDataContainer destination = PhysicsContainer.GetComponent<CySpringDataContainer>();
|
||||
if (destination == null)
|
||||
destination = PhysicsContainer.AddComponent<CySpringDataContainer>();
|
||||
if (destination.collisionParam == null)
|
||||
destination.collisionParam = new List<CySpringCollisionData>();
|
||||
if (destination.springParam == null)
|
||||
destination.springParam = new List<CySpringParamDataElement>();
|
||||
|
||||
foreach (CySpringDataContainer sourceContainer in source.GetComponentsInChildren<CySpringDataContainer>(true))
|
||||
{
|
||||
foreach (CySpringCollisionData collision in sourceContainer.collisionParam)
|
||||
{
|
||||
if (!IsSchoolUniformSkirtCollider(collision))
|
||||
continue;
|
||||
destination.collisionParam.Add(CloneCollisionData(collision));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsSchoolUniformSkirtCollider(CySpringCollisionData collision)
|
||||
{
|
||||
if (collision == null)
|
||||
return false;
|
||||
|
||||
return string.Equals(collision._collisionName, "Col_B_Thigh_L_MSkirt_L", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(collision._collisionName, "Col_B_Thigh_R_MSkirt_R", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(collision._collisionName, "Col_B_Hip_MSkirt_L", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(collision._collisionName, "Col_B_Hip_MSkirt_R", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private static CySpringCollisionData CloneCollisionData(CySpringCollisionData source)
|
||||
{
|
||||
return new CySpringCollisionData
|
||||
{
|
||||
_collisionName = source._collisionName,
|
||||
_targetObjectName = source._targetObjectName,
|
||||
_isOtherTarget = source._isOtherTarget,
|
||||
_offset = source._offset,
|
||||
_offset2 = source._offset2,
|
||||
_radius = source._radius,
|
||||
_distance = source._distance,
|
||||
_normal = source._normal,
|
||||
_type = source._type,
|
||||
_isInner = source._isInner
|
||||
};
|
||||
}
|
||||
|
||||
public void SetDynamicBoneEnable(bool isOn)
|
||||
|
||||
@@ -202,6 +202,13 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
else
|
||||
{
|
||||
umaContainer.LoadBody(asset);
|
||||
// Winner costumes use their own cloth physics, but their skirt collision
|
||||
// volumes are not consistently authored. Reuse the verified school-uniform
|
||||
// MSkirt collision definition on the current character skeleton.
|
||||
const string schoolUniformCollision = "3d/chara/body/bdy0002_00/clothes/pfb_bdy0002_00_cloth00";
|
||||
if (Main.AbList.TryGetValue(schoolUniformCollision, out UmaDatabaseEntry schoolCollisionAsset))
|
||||
umaContainer.LoadSchoolUniformSkirtCollision(schoolCollisionAsset);
|
||||
|
||||
//Load Physics
|
||||
var asset1 = Main.AbList[UmaDatabaseController.BodyPath + $"bdy{id}_{costumeId}/clothes/pfb_bdy{id}_{costumeId}_cloth00"];
|
||||
umaContainer.LoadPhysics(asset1);
|
||||
|
||||
@@ -150,17 +150,20 @@ public class UmaViewerUI : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Builder.CurrentAudioSources.Count > 0 && Builder.CurrentAudioSources[0])
|
||||
if (Builder == null)
|
||||
return;
|
||||
|
||||
if (Builder.CurrentAudioSources != null && Builder.CurrentAudioSources.Count > 0 && Builder.CurrentAudioSources[0])
|
||||
{
|
||||
AudioSource MianSource = Builder.CurrentAudioSources[0];
|
||||
if (MianSource.clip)
|
||||
if (MianSource.clip && AudioSettings != null)
|
||||
{
|
||||
AudioSettings.UpdateTrack(MianSource);
|
||||
}
|
||||
}
|
||||
|
||||
var umaContainer = Builder.CurrentUMAContainer;
|
||||
if (umaContainer != null && umaContainer.OverrideController != null)
|
||||
if (umaContainer != null && umaContainer.OverrideController != null && AnimationSettings != null)
|
||||
{
|
||||
AnimationSettings.UpdateAnimationInfo(umaContainer);
|
||||
}
|
||||
@@ -1347,4 +1350,4 @@ public class UmaViewerUI : MonoBehaviour
|
||||
UmaViewerUI.Instance.ShowMessage($"ColorSet data saved: {fullPath}", UIMessageType.Success);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,16 +34,25 @@ namespace Gallop
|
||||
foreach (CySpringCollisionData collider in collisionParam)
|
||||
{
|
||||
if (collider._isInner) continue;
|
||||
if (bones.TryGetValue(collider._targetObjectName, out Transform bone))
|
||||
{
|
||||
if (IsSkirtLegOrHipCollider(collider._collisionName) &&
|
||||
!IsActiveSkirtBodyCollider(collider._collisionName))
|
||||
continue;
|
||||
Transform child;
|
||||
Transform bone = null;
|
||||
bool authoredTransform = bones.TryGetValue(collider._collisionName, out child);
|
||||
if (!authoredTransform && !bones.TryGetValue(collider._targetObjectName, out bone))
|
||||
continue;
|
||||
|
||||
var child = new GameObject(collider._collisionName);
|
||||
if (!authoredTransform)
|
||||
{
|
||||
child = new GameObject(collider._collisionName).transform;
|
||||
child.transform.SetParent(bone);
|
||||
child.transform.localPosition = Vector3.zero;
|
||||
child.transform.localRotation = Quaternion.identity;
|
||||
child.transform.localScale = Vector3.one;
|
||||
colliders.Add(child.name, child.transform);
|
||||
|
||||
}
|
||||
if (!colliders.ContainsKey(child.name))
|
||||
colliders.Add(child.name, child);
|
||||
|
||||
//修改(动骨与碰撞相关)
|
||||
if (collider._collisionName == "Col_B_Hip_Tail")
|
||||
@@ -54,9 +63,9 @@ namespace Gallop
|
||||
{
|
||||
collider._radius *= 1.14f;
|
||||
}
|
||||
else if (collider._collisionName.Contains("Col_B_Hip_Skirt"))
|
||||
else if (collider._collisionName.IndexOf("Skirt", System.StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
{
|
||||
collider._radius *= 0.8f;
|
||||
// Skirt collision volumes are authored for the skirt and must stay at source size.
|
||||
}
|
||||
else if (collider._collisionName.Contains("Col_B_Hip_Jacket"))
|
||||
{
|
||||
@@ -80,33 +89,44 @@ namespace Gallop
|
||||
switch (collider._type)
|
||||
{
|
||||
case CySpringCollisionData.CollisionType.Capsule:
|
||||
var dynamic = child.AddComponent<DynamicBoneCollider>();
|
||||
var dynamic = child.gameObject.AddComponent<DynamicBoneCollider>();
|
||||
dynamic.ColliderName = collider._collisionName;
|
||||
child.transform.localPosition = (collider._offset + collider._offset2) / 2;
|
||||
child.transform.LookAt(child.transform.TransformPoint(collider._offset2));
|
||||
dynamic.m_Direction = DynamicBoneColliderBase.Direction.Z;
|
||||
dynamic.m_Height = (collider._offset - collider._offset2).magnitude + collider._radius;
|
||||
Vector3 capsuleAxis = collider._offset2 - collider._offset;
|
||||
if (!authoredTransform)
|
||||
{
|
||||
child.transform.localPosition = (collider._offset + collider._offset2) / 2;
|
||||
if (capsuleAxis.sqrMagnitude > 0.000001f)
|
||||
child.transform.localRotation = Quaternion.FromToRotation(Vector3.forward, capsuleAxis);
|
||||
}
|
||||
dynamic.m_Direction = authoredTransform
|
||||
? DynamicBoneColliderBase.Direction.Y
|
||||
: DynamicBoneColliderBase.Direction.Z;
|
||||
// DynamicBone stores full capsule height, including both hemispheres.
|
||||
dynamic.m_Height = capsuleAxis.magnitude + collider._radius * 2f;
|
||||
dynamic.m_Radius = collider._radius;
|
||||
dynamic.m_Bound = collider._isInner ? DynamicBoneColliderBase.Bound.Inside : DynamicBoneColliderBase.Bound.Outside;
|
||||
break;
|
||||
case CySpringCollisionData.CollisionType.Sphere:
|
||||
var Spheredynamic = child.AddComponent<DynamicBoneCollider>();
|
||||
var Spheredynamic = child.gameObject.AddComponent<DynamicBoneCollider>();
|
||||
Spheredynamic.ColliderName = collider._collisionName;
|
||||
child.transform.localPosition = collider._offset;
|
||||
if (!authoredTransform)
|
||||
child.transform.localPosition = collider._offset;
|
||||
Spheredynamic.m_Radius = collider._radius;
|
||||
Spheredynamic.m_Height = collider._distance;
|
||||
// A CySpring sphere's distance is not DynamicBone capsule height.
|
||||
// Giving it a height turns the authored hip sphere into a long capsule.
|
||||
Spheredynamic.m_Height = 0f;
|
||||
Spheredynamic.m_Bound = collider._isInner ? DynamicBoneColliderBase.Bound.Inside : DynamicBoneColliderBase.Bound.Outside;
|
||||
break;
|
||||
case CySpringCollisionData.CollisionType.Plane:
|
||||
var planedynamic = child.AddComponent<DynamicBonePlaneCollider>();
|
||||
var planedynamic = child.gameObject.AddComponent<DynamicBonePlaneCollider>();
|
||||
planedynamic.ColliderName = collider._collisionName;
|
||||
child.transform.localPosition = collider._offset;
|
||||
if (!authoredTransform)
|
||||
child.transform.localPosition = collider._offset;
|
||||
planedynamic.m_Bound = collider._isInner ? DynamicBoneColliderBase.Bound.Inside : DynamicBoneColliderBase.Bound.Outside;
|
||||
break;
|
||||
case CySpringCollisionData.CollisionType.None:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return colliders;
|
||||
}
|
||||
@@ -117,11 +137,23 @@ namespace Gallop
|
||||
public void InitializePhysics(Dictionary<string, Transform> bones, Dictionary<string, Transform> colliders)
|
||||
{
|
||||
DynamicBones.Clear();
|
||||
var skirtColliders = new List<DynamicBoneColliderBase>();
|
||||
foreach (Transform transform in colliders.Values)
|
||||
{
|
||||
DynamicBoneColliderBase collider = transform.GetComponent<DynamicBoneColliderBase>();
|
||||
if (collider != null && IsSharedThighSkirtCollider(collider.ColliderName))
|
||||
{
|
||||
skirtColliders.Add(collider);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取对象名称并判断类型
|
||||
string nameLower = gameObject.name.ToLower();
|
||||
bool isTailObject = nameLower.Contains("tail"); // 判断是否为尾巴
|
||||
bool isClothObject = !isTailObject && nameLower.Contains("chr"); // 判断是否为头发,排除尾巴避免重复匹配
|
||||
bool isChestBowObject = !isTailObject &&
|
||||
(nameLower.Contains("ribbon") || nameLower.Contains("bow") ||
|
||||
nameLower.Contains("tie") || nameLower.Contains("bust"));
|
||||
|
||||
foreach (CySpringParamDataElement spring in springParam)
|
||||
{
|
||||
@@ -129,6 +161,8 @@ namespace Gallop
|
||||
|
||||
var dynamic = bone.gameObject.AddComponent<DynamicBone>();
|
||||
dynamic.m_Root = bone;
|
||||
dynamic.m_MotionGroup = isChestBowObject ? "ChestBow" :
|
||||
(isClothObject ? "Hair" : string.Empty);
|
||||
|
||||
// 设置重力
|
||||
dynamic.m_Gravity = new Vector3(0, Mathf.Clamp01(-30f / spring._gravity), 0);
|
||||
@@ -166,13 +200,41 @@ namespace Gallop
|
||||
|
||||
dynamic.SetupParticles();
|
||||
DynamicBones.Add(dynamic);
|
||||
|
||||
bool isSkirtChain = spring._boneName.IndexOf("Skirt", System.StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
if (isSkirtChain)
|
||||
{
|
||||
dynamic.m_ContinuousCollision = true;
|
||||
}
|
||||
|
||||
// 主碰撞器添加
|
||||
// The source list belongs to the root spring node. DynamicBone particle zero
|
||||
// is fixed, so apply it to the first simulated particle for skirt chains.
|
||||
foreach (string collisionName in spring._collisionNameList)
|
||||
{
|
||||
if (colliders.TryGetValue(collisionName, out Transform tmp))
|
||||
if (!colliders.TryGetValue(collisionName, out Transform tmp))
|
||||
continue;
|
||||
|
||||
DynamicBoneColliderBase collider = tmp.GetComponent<DynamicBoneColliderBase>();
|
||||
if (isSkirtChain && !ShouldUseAuthoredSkirtCollider(collider))
|
||||
continue;
|
||||
int particleIndex = isSkirtChain && dynamic.Particles.Count > 1 ? 1 : 0;
|
||||
AddCollider(dynamic.Particles[particleIndex], collider);
|
||||
}
|
||||
|
||||
if (isSkirtChain)
|
||||
{
|
||||
Transform hipBone;
|
||||
bones.TryGetValue("Hip", out hipBone);
|
||||
foreach (DynamicBoneColliderBase collider in skirtColliders)
|
||||
AddColliderToSkirtParticles(dynamic, collider);
|
||||
|
||||
foreach (Transform transform in colliders.Values)
|
||||
{
|
||||
dynamic.Particles[0].m_Colliders.Add(tmp.GetComponent<DynamicBoneColliderBase>());
|
||||
DynamicBoneColliderBase collider = transform.GetComponent<DynamicBoneColliderBase>();
|
||||
if (collider == null || !IsHipSkirtCollider(collider.ColliderName) ||
|
||||
!IsSameSkirtSide(dynamic.m_Root, collider, hipBone))
|
||||
continue;
|
||||
AddColliderToSkirtParticles(dynamic, collider);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,18 +280,96 @@ namespace Gallop
|
||||
{
|
||||
if (colliders.TryGetValue(collisionName, out Transform tmp))
|
||||
{
|
||||
var collider = tmp.GetComponent<DynamicBoneColliderBase>();
|
||||
if (collider != null)
|
||||
{
|
||||
tempParticle.m_Colliders.Add(collider);
|
||||
}
|
||||
DynamicBoneColliderBase collider = tmp.GetComponent<DynamicBoneColliderBase>();
|
||||
if (!isSkirtChain || ShouldUseAuthoredSkirtCollider(collider))
|
||||
AddCollider(tempParticle, collider);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddColliderToSkirtParticles(DynamicBone dynamic, DynamicBoneColliderBase collider)
|
||||
{
|
||||
// Particle zero is the fixed skirt root and is not simulated.
|
||||
for (int i = 1; i < dynamic.Particles.Count; i++)
|
||||
AddCollider(dynamic.Particles[i], collider);
|
||||
}
|
||||
|
||||
private static void AddCollider(DynamicBone.Particle particle, DynamicBoneColliderBase collider)
|
||||
{
|
||||
if (particle != null && collider != null && !particle.m_Colliders.Contains(collider))
|
||||
particle.m_Colliders.Add(collider);
|
||||
}
|
||||
|
||||
private static bool IsThighSkirtCollider(string colliderName)
|
||||
{
|
||||
return !string.IsNullOrEmpty(colliderName) &&
|
||||
colliderName.IndexOf("Skirt", System.StringComparison.OrdinalIgnoreCase) >= 0 &&
|
||||
colliderName.IndexOf("Thigh", System.StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
}
|
||||
|
||||
private static bool IsSkirtLegOrHipCollider(string colliderName)
|
||||
{
|
||||
return !string.IsNullOrEmpty(colliderName) &&
|
||||
colliderName.IndexOf("Skirt", System.StringComparison.OrdinalIgnoreCase) >= 0 &&
|
||||
(colliderName.IndexOf("Thigh", System.StringComparison.OrdinalIgnoreCase) >= 0 ||
|
||||
colliderName.IndexOf("Hip", System.StringComparison.OrdinalIgnoreCase) >= 0);
|
||||
}
|
||||
|
||||
private static bool IsActiveSkirtBodyCollider(string colliderName)
|
||||
{
|
||||
return string.Equals(colliderName, "Col_B_Thigh_L_MSkirt_L", System.StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(colliderName, "Col_B_Thigh_R_MSkirt_R", System.StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(colliderName, "Col_B_Hip_MSkirt_L", System.StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(colliderName, "Col_B_Hip_MSkirt_R", System.StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private static bool IsSharedThighSkirtCollider(string colliderName)
|
||||
{
|
||||
return !string.IsNullOrEmpty(colliderName) &&
|
||||
colliderName.IndexOf("Thigh", System.StringComparison.OrdinalIgnoreCase) >= 0 &&
|
||||
colliderName.IndexOf("MSkirt", System.StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
}
|
||||
|
||||
private static bool ShouldUseAuthoredSkirtCollider(DynamicBoneColliderBase collider)
|
||||
{
|
||||
if (collider == null || string.IsNullOrEmpty(collider.ColliderName))
|
||||
return false;
|
||||
|
||||
if (IsThighSkirtCollider(collider.ColliderName))
|
||||
return false;
|
||||
|
||||
bool isHipSkirt = collider.ColliderName.IndexOf(
|
||||
"Hip", System.StringComparison.OrdinalIgnoreCase) >= 0 &&
|
||||
collider.ColliderName.IndexOf(
|
||||
"Skirt", System.StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
|
||||
// The original CySpring solver can use broad rear/center hip spheres,
|
||||
// but they over-expand an independent DynamicBone skirt chain. This is
|
||||
// true for both the old MSkirt names and newer Col_B_Hip_Skirt_B/BLR.
|
||||
// Keep only an explicitly left/right localized hip pair.
|
||||
return !isHipSkirt || IsHipSkirtCollider(collider.ColliderName);
|
||||
}
|
||||
|
||||
private static bool IsHipSkirtCollider(string colliderName)
|
||||
{
|
||||
return !string.IsNullOrEmpty(colliderName) &&
|
||||
colliderName.IndexOf("Skirt", System.StringComparison.OrdinalIgnoreCase) >= 0 &&
|
||||
colliderName.IndexOf("Hip", System.StringComparison.OrdinalIgnoreCase) >= 0 &&
|
||||
(colliderName.EndsWith("_L", System.StringComparison.OrdinalIgnoreCase) ||
|
||||
colliderName.EndsWith("_R", System.StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private static bool IsSameSkirtSide(Transform skirtRoot, DynamicBoneColliderBase collider, Transform hip)
|
||||
{
|
||||
if (skirtRoot == null || collider == null || hip == null)
|
||||
return true;
|
||||
|
||||
bool rootLeft = hip.InverseTransformPoint(skirtRoot.position).x < 0f;
|
||||
bool colliderLeft = hip.InverseTransformPoint(collider.transform.position).x < 0f;
|
||||
return rootLeft == colliderLeft;
|
||||
}
|
||||
|
||||
public void EnablePhysics(bool isOn)
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+8
@@ -0,0 +1,8 @@
|
||||
namespace Gallop
|
||||
{
|
||||
// Asset bundles reference this original qualified signature. The recovered implementation
|
||||
// lives in the global namespace, so inherit it to preserve all serialized collision fields.
|
||||
public class CySpringCollisionComponent : global::CySpringCollisionComponent
|
||||
{
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9459a406c0ff58349bd3255f1827c124
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -78,6 +78,19 @@ namespace Gallop.Live.Cutt
|
||||
public event Action<LiveTimelineChromaticAberrationData, LiveTimelineKeyChromaticAberrationData> OnUpdateChromaticAberration;
|
||||
public event Action<LiveTimelineHdrBloomData, LiveTimelineKeyHdrBloomData> OnUpdateHdrBloom;
|
||||
public event Action<LiveTimelineColorCorrectionData, LiveTimelineKeyColorCorrectionData> OnUpdateColorCorrection;
|
||||
public event MobCyalumeUpdateInfoDelegate OnUpdateMobControl;
|
||||
public event MobCyalumeUpdateInfoDelegate OnUpdateCyalumeControl;
|
||||
public event Action<LiveTimelineMonitorControlData, LiveTimelineKeyMonitorControlData> OnUpdateMonitorControl;
|
||||
public event Action<LiveTimelineMonitorCameraPositionData, LiveTimelineKeyMonitorCameraPositionData> OnUpdateMonitorCameraPosition;
|
||||
public event Action<LiveTimelineMonitorCameraLookAtData, LiveTimelineKeyMonitorCameraLookAtData> OnUpdateMonitorCameraLookAt;
|
||||
public event Action<LiveTimelineLensFlareData, LiveTimelineKeyLensFlareData> OnUpdateLensFlare;
|
||||
public event Action<LiveTimelineStageEnvironmentData, LiveTimelineKeyStageEnvironmentData> OnUpdateEnvironment;
|
||||
public event Action<int, LiveTimelineKeyFacialToonData> OnUpdateFacialToon;
|
||||
public event Action<LiveTimelinePropsData, LiveTimelineKeyPropsData> OnUpdateProps;
|
||||
public event Action<LiveTimelinePropsAttachData, LiveTimelineKeyPropsAttachData> OnUpdatePropsAttach;
|
||||
public event Action<LiveTimelineKeyCharaFootLightData> OnUpdateCharaFootLight;
|
||||
public event Action<LiveTimelineAdditionalLight, LiveTimelineKeyData_AdditionalLight> OnUpdateAdditionalLight;
|
||||
public event Action<LiveTimelineLightProjectionData, LiveTimelineKeyLightProjectionData> OnUpdateLightProjection;
|
||||
|
||||
private static Func<LiveTimelineKeyCameraPositionData, LiveTimelineControl, FindTimelineConfig, Vector3> fnGetCameraPosValue = GetCameraPosValue;
|
||||
|
||||
@@ -210,6 +223,7 @@ namespace Gallop.Live.Cutt
|
||||
private Vector3 _liveStageCenterPos = Vector3.zero;
|
||||
|
||||
private TimelinePlayerMode _playMode = TimelinePlayerMode.Default;
|
||||
public TimelinePlayerMode PlayMode => _playMode;
|
||||
|
||||
public static int liveCharaPositionMax
|
||||
{
|
||||
@@ -382,6 +396,19 @@ namespace Gallop.Live.Cutt
|
||||
// 分发保留,接上只需订阅 OnUpdateHdrBloom。
|
||||
AlterUpdate_SimpleListControl(workSheet.hdrBloomKeys, d => d.keys, OnUpdateHdrBloom, _currentFrame);
|
||||
AlterUpdate_SimpleListControl(workSheet.colorCorrectionDataLists, d => d.keys, OnUpdateColorCorrection, _currentFrame);
|
||||
AlterUpdate_MobCyalumeControl(workSheet.MobControlKeys, _currentFrame, OnUpdateMobControl);
|
||||
AlterUpdate_MobCyalumeControl(workSheet.CyalumeControlKeys, _currentFrame, OnUpdateCyalumeControl);
|
||||
AlterUpdate_SimpleListControl(workSheet.monitorControlList, d => d.keys, OnUpdateMonitorControl, _currentFrame);
|
||||
AlterUpdate_SimpleListControl(workSheet.monitorCameraPosKeys, d => d.keys, OnUpdateMonitorCameraPosition, _currentFrame);
|
||||
AlterUpdate_SimpleListControl(workSheet.monitorCameraLookAtKeys, d => d.keys, OnUpdateMonitorCameraLookAt, _currentFrame);
|
||||
AlterUpdate_SimpleListControl(workSheet.lensFlareList, d => d.keys, OnUpdateLensFlare, _currentFrame);
|
||||
AlterUpdate_SimpleListControl(workSheet.environmentDataLists, d => d.keys, OnUpdateEnvironment, _currentFrame);
|
||||
AlterUpdate_FacialToon(workSheet.facialToonSet, _currentFrame);
|
||||
AlterUpdate_SimpleListControl(workSheet.propsList, d => d.keys, OnUpdateProps, _currentFrame);
|
||||
AlterUpdate_SimpleListControl(workSheet.propsAttachList, d => d.keys, OnUpdatePropsAttach, _currentFrame);
|
||||
AlterUpdate_SimpleListControl(workSheet.AdditionalLightList, d => d.keys, OnUpdateAdditionalLight, _currentFrame);
|
||||
AlterUpdate_CharaFootLight(workSheet.charaFootLightKeys, _currentFrame);
|
||||
AlterUpdate_SimpleListControl(workSheet.lightProjectionList, d => d.keys, OnUpdateLightProjection, _currentFrame);
|
||||
AlterUpdate_PostFilm(workSheet.postFilmKeys, 0, _currentFrame);
|
||||
AlterUpdate_PostFilm(workSheet.postFilm2Keys, 1, _currentFrame);
|
||||
AlterUpdate_PostFilm(workSheet.postFilm3Keys, 2, _currentFrame);
|
||||
@@ -609,9 +636,14 @@ namespace Gallop.Live.Cutt
|
||||
{
|
||||
|
||||
var formationList = data.worksheetList[0].formationOffsetSet.Init();
|
||||
if (formationList == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < Director.instance.characterCount; i++)
|
||||
int count = Mathf.Min(Director.instance.characterCount, formationList.Count);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (formationList[i] == null)
|
||||
continue;
|
||||
LiveTimelineKeyIndex curKey = AlterUpdate_Key(formationList[i], liveTime);
|
||||
|
||||
if (curKey != null && curKey.index != -1)
|
||||
@@ -2015,6 +2047,72 @@ namespace Gallop.Live.Cutt
|
||||
}
|
||||
}
|
||||
|
||||
private void AlterUpdate_MobCyalumeControl(
|
||||
List<LiveTimelineMobCyalumeControlData> dataList,
|
||||
float currentFrame,
|
||||
MobCyalumeUpdateInfoDelegate callback)
|
||||
{
|
||||
if (callback == null || dataList == null) return;
|
||||
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
var data = dataList[i];
|
||||
var keys = data != null ? data.keys : null;
|
||||
if (keys == null || keys.Count == 0 || keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) ||
|
||||
!keys.EnablePlayModeTimeline(_playMode)) continue;
|
||||
|
||||
FindTimelineKey(out var curKey, out var nextKey, keys, currentFrame);
|
||||
var current = curKey as LiveTimelineKeyMobCyalumeControlData;
|
||||
var next = nextKey as LiveTimelineKeyMobCyalumeControlData;
|
||||
if (current == null) continue;
|
||||
|
||||
var info = new MobCyalumeUpdateInfo
|
||||
{
|
||||
data = data,
|
||||
unk0 = (uint)keys.unk48 < 11u ? keys.unk48 : i,
|
||||
currentFrame = currentFrame,
|
||||
currentLiveTime = currentLiveTime
|
||||
};
|
||||
|
||||
if (next != null && next.interpolateType != LiveCameraInterpolateType.None)
|
||||
{
|
||||
float t = CalculateInterpolationValue(current, next, currentFrame);
|
||||
info.position = Vector3.Lerp(current.position, next.position, t);
|
||||
info.rotation = Quaternion.Lerp(current.GetRotation(), next.GetRotation(), t);
|
||||
info.scale = Vector3.Lerp(current.scale, next.scale, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
info.position = current.position;
|
||||
info.rotation = current.GetRotation();
|
||||
info.scale = current.scale;
|
||||
}
|
||||
|
||||
callback.Invoke(ref info);
|
||||
}
|
||||
}
|
||||
|
||||
private void AlterUpdate_FacialToon(LiveTimelineFacialToonData data, float currentFrame)
|
||||
{
|
||||
if (data == null || OnUpdateFacialToon == null) return;
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
var keys = data.GetKeys(i);
|
||||
if (keys == null || keys.Count == 0 || keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) ||
|
||||
!keys.EnablePlayModeTimeline(_playMode)) continue;
|
||||
FindTimelineKey(out var current, out var _, keys, currentFrame);
|
||||
if (current is LiveTimelineKeyFacialToonData key) OnUpdateFacialToon.Invoke(i, key);
|
||||
}
|
||||
}
|
||||
|
||||
private void AlterUpdate_CharaFootLight(LiveTimelineKeyCharaFootLightDataList keys, float currentFrame)
|
||||
{
|
||||
if (keys == null || OnUpdateCharaFootLight == null || keys.Count == 0 ||
|
||||
keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !keys.EnablePlayModeTimeline(_playMode)) return;
|
||||
FindTimelineKey(out var current, out var _, keys, currentFrame);
|
||||
if (current is LiveTimelineKeyCharaFootLightData key) OnUpdateCharaFootLight.Invoke(key);
|
||||
}
|
||||
|
||||
private void AlterUpdate_GlobalFogControl(LiveTimelineWorkSheet sheet, float currentFrame)
|
||||
{
|
||||
if (sheet.globalFogDataLists == null || OnUpdateGlobalFog == null) return;
|
||||
@@ -2070,4 +2168,3 @@ namespace Gallop.Live.Cutt
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
+311
@@ -0,0 +1,311 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gallop.Live.Cutt
|
||||
{
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyLensFlareData : LiveTimelineKeyWithInterpolate
|
||||
{
|
||||
public Vector3 offset;
|
||||
public Color color = Color.white;
|
||||
public float brightness = 1f;
|
||||
public float fadeSpeed = 1f;
|
||||
public int enableParameter;
|
||||
public int enableFlare;
|
||||
public int IsAutoBrightness;
|
||||
public int IsOverridePosition;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyLensFlareDataList : LiveTimelineKeyDataListTemplate<LiveTimelineKeyLensFlareData> { }
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineLensFlareData : ILiveTimelineGroupDataWithName
|
||||
{
|
||||
public LiveTimelineKeyLensFlareDataList keys;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyStageEnvironmentData : LiveTimelineKey
|
||||
{
|
||||
public bool isValidMirror;
|
||||
public bool isMirror;
|
||||
public bool isBgMirror;
|
||||
public bool IsMirrorBg3d;
|
||||
public bool EnableCharacterMirrorExpandFaceBounds;
|
||||
public int characterMirror;
|
||||
public int CharacterMirrorHead;
|
||||
public int CharacterMirrorExpandFaceBounds;
|
||||
public float mirrorReflectionRate = 1f;
|
||||
public bool isValidShadow;
|
||||
public int characterShadow;
|
||||
public bool isSoftShadow;
|
||||
public bool IsToonMirror;
|
||||
public bool isValidWaterReflection;
|
||||
public float waterReflection;
|
||||
public float waveScale;
|
||||
public float waterDistortion;
|
||||
public float waterUCross;
|
||||
public float waterVCross;
|
||||
public float waterUSpeed;
|
||||
public float waterVSpeed;
|
||||
public float waterNormalPower;
|
||||
public float waveDistortionPower;
|
||||
public float waveClearly;
|
||||
public float waveDiffusion;
|
||||
public float waveDecline;
|
||||
public Color waterColor;
|
||||
public float waterVOffset;
|
||||
public bool IsValidStageFovShift;
|
||||
public float BaseFov;
|
||||
public float ShiftPower;
|
||||
public bool IsShiftY;
|
||||
public bool _isValidMirror;
|
||||
public int _mirror;
|
||||
public int _bgMirror;
|
||||
public int _characterMirror;
|
||||
public float _mirrorReflectionRate = -1f;
|
||||
|
||||
public bool MirrorIsValid => isValidMirror || _isValidMirror;
|
||||
public bool MirrorEnabled => isMirror || isBgMirror || IsMirrorBg3d || _mirror != 0 || _bgMirror != 0;
|
||||
public float ReflectionRate => _mirrorReflectionRate >= 0f ? _mirrorReflectionRate : mirrorReflectionRate;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyStageEnvironmentDataList : LiveTimelineKeyDataListTemplate<LiveTimelineKeyStageEnvironmentData> { }
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineStageEnvironmentData : ILiveTimelineGroupDataWithName
|
||||
{
|
||||
public LiveTimelineKeyStageEnvironmentDataList keys;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyFacialToonData : LiveTimelineKeyWithInterpolate
|
||||
{
|
||||
public float CheekPretenseThreshold;
|
||||
public float NosePretenseThreshold;
|
||||
public float CylinderBlend;
|
||||
public float HairNormalBlend;
|
||||
public int UseOriginalDirectionalLight;
|
||||
public Vector3 OriginalDirectionalLightDir;
|
||||
public float EyeToonStep;
|
||||
public float EyeToonFeather;
|
||||
public float EyeSaturation;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyFacialToonDataList : LiveTimelineKeyDataListTemplate<LiveTimelineKeyFacialToonData> { }
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineFacialToonData
|
||||
{
|
||||
public LiveTimelineKeyFacialToonDataList centerKeys;
|
||||
public LiveTimelineKeyFacialToonDataList left1Keys;
|
||||
public LiveTimelineKeyFacialToonDataList right1Keys;
|
||||
public LiveTimelineKeyFacialToonDataList left2Keys;
|
||||
public LiveTimelineKeyFacialToonDataList right2Keys;
|
||||
public LiveTimelineKeyFacialToonDataList motion5Keys;
|
||||
public LiveTimelineKeyFacialToonDataList motion6Keys;
|
||||
public LiveTimelineKeyFacialToonDataList motion7Keys;
|
||||
public LiveTimelineKeyFacialToonDataList motion8Keys;
|
||||
public LiveTimelineKeyFacialToonDataList motion9Keys;
|
||||
public LiveTimelineKeyFacialToonDataList motion10Keys;
|
||||
public LiveTimelineKeyFacialToonDataList motion11Keys;
|
||||
public LiveTimelineKeyFacialToonDataList motion12Keys;
|
||||
public LiveTimelineKeyFacialToonDataList motion13Keys;
|
||||
public LiveTimelineKeyFacialToonDataList motion14Keys;
|
||||
public LiveTimelineKeyFacialToonDataList motion15Keys;
|
||||
public LiveTimelineKeyFacialToonDataList motion16Keys;
|
||||
public LiveTimelineKeyFacialToonDataList motion17Keys;
|
||||
public LiveTimelineKeyFacialToonDataList motion18Keys;
|
||||
public LiveTimelineKeyFacialToonDataList motion19Keys;
|
||||
|
||||
public LiveTimelineKeyFacialToonDataList GetKeys(int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0: return centerKeys; case 1: return left1Keys; case 2: return right1Keys;
|
||||
case 3: return left2Keys; case 4: return right2Keys; case 5: return motion5Keys;
|
||||
case 6: return motion6Keys; case 7: return motion7Keys; case 8: return motion8Keys;
|
||||
case 9: return motion9Keys; case 10: return motion10Keys; case 11: return motion11Keys;
|
||||
case 12: return motion12Keys; case 13: return motion13Keys; case 14: return motion14Keys;
|
||||
case 15: return motion15Keys; case 16: return motion16Keys; case 17: return motion17Keys;
|
||||
case 18: return motion18Keys; case 19: return motion19Keys; default: return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyCameraLayerData : LiveTimelineKeyWithInterpolate
|
||||
{
|
||||
public Vector3 offsetMaxPosition;
|
||||
public Vector3 offsetMinPosition;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyCameraLayerDataList : LiveTimelineKeyDataListTemplate<LiveTimelineKeyCameraLayerData> { }
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyPropsData : LiveTimelineKeyWithInterpolate
|
||||
{
|
||||
public int settingFlags;
|
||||
public int propsID;
|
||||
public int rendererEnable;
|
||||
public int IsVisibleAttachedCharaLinked;
|
||||
public int AutoSwitchLayerOnMirrorRendering;
|
||||
public Color color = Color.white;
|
||||
public Color rootColor = Color.white;
|
||||
public Color tipColor = Color.white;
|
||||
public float colorPower = 1f;
|
||||
public int IsApplyAnimation;
|
||||
public int IsApplyReserveWarming;
|
||||
public AnimationClip AnimationClip;
|
||||
public float StartAnimationTime;
|
||||
public int AnimationHeadFrame;
|
||||
public Color ToonDarkColor;
|
||||
public Color ToonBrightColor;
|
||||
public int IsCastShadow;
|
||||
public int IsCastShadowForced;
|
||||
public Vector3 _directionalLightAngle;
|
||||
public int IsUpdateOutline;
|
||||
public float OutlineWidth;
|
||||
public Color OutlineColor;
|
||||
public int IsEmissive;
|
||||
public Color EmissiveColor;
|
||||
public float EmissiveScrollTimeScale = 1f;
|
||||
public float EmissiveScrollEnergyScale = 1f;
|
||||
}
|
||||
|
||||
[Serializable] public class LiveTimelineKeyPropsDataList : LiveTimelineKeyDataListTemplate<LiveTimelineKeyPropsData> { }
|
||||
[Serializable]
|
||||
public class LiveTimelinePropsData : ILiveTimelineGroupDataWithName
|
||||
{
|
||||
public LiveTimelineKeyPropsDataList keys;
|
||||
public bool _applyVariation;
|
||||
public int _variationId;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyPropsAttachData : LiveTimelineKeyWithInterpolate
|
||||
{
|
||||
public string _attachJointName;
|
||||
public int _attachJointHash;
|
||||
public string _copyPositionJointName;
|
||||
public int _copyPositionJointHash;
|
||||
public int _settingFlags;
|
||||
public int _propsId;
|
||||
public Vector3 _offsetPosition;
|
||||
public Vector3 OffsetRotate;
|
||||
public Vector3 OffsetScale = Vector3.one;
|
||||
public int IsLinkAttachBone;
|
||||
public int _attachType;
|
||||
public int _attachPropId = -1;
|
||||
public string _attachTargetPropNodeName;
|
||||
}
|
||||
|
||||
[Serializable] public class LiveTimelineKeyPropsAttachDataList : LiveTimelineKeyDataListTemplate<LiveTimelineKeyPropsAttachData> { }
|
||||
[Serializable]
|
||||
public class LiveTimelinePropsAttachData : ILiveTimelineGroupDataWithName
|
||||
{
|
||||
public LiveTimelineKeyPropsAttachDataList keys;
|
||||
public bool _applyVariation;
|
||||
public int _variationId;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyCharaFootLightData : LiveTimelineKeyWithInterpolate
|
||||
{
|
||||
public int positionFlag;
|
||||
public float[] hightMax = Array.Empty<float>();
|
||||
public Color[] lightColor = Array.Empty<Color>();
|
||||
public int[] LightBlendModeArray = Array.Empty<int>();
|
||||
public int[] EasingArray = Array.Empty<int>();
|
||||
}
|
||||
|
||||
[Serializable] public class LiveTimelineKeyCharaFootLightDataList : LiveTimelineKeyDataListTemplate<LiveTimelineKeyCharaFootLightData> { }
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyData_AdditionalLight : LiveTimelineKeyWithInterpolate
|
||||
{
|
||||
public Vector3 Position;
|
||||
public Vector3 Rotate;
|
||||
public int IsEnable;
|
||||
public int Type;
|
||||
public float Range;
|
||||
public int SpotAngle;
|
||||
public int IndirectMultiplier;
|
||||
public int ShadowType;
|
||||
public float Strength = 1f;
|
||||
public float Bias = 0.05f;
|
||||
public float NormalBias = 0.4f;
|
||||
public float NearPlane = 0.2f;
|
||||
}
|
||||
|
||||
[Serializable] public class LiveTimelineKeyAdditionalLightList : LiveTimelineKeyDataListTemplate<LiveTimelineKeyData_AdditionalLight> { }
|
||||
[Serializable]
|
||||
public class LiveTimelineAdditionalLight : ILiveTimelineGroupDataWithName
|
||||
{
|
||||
public LiveTimelineKeyAdditionalLightList keys;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineLightProjectionAnimationParam
|
||||
{
|
||||
public int TextureId = -1;
|
||||
public int DivisionNumberX;
|
||||
public int DivisionNumberY;
|
||||
public int MaxCut;
|
||||
public float AnimationTime;
|
||||
public Vector2 ScaleUV = Vector2.one;
|
||||
public Vector2 OffsetUV;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyLightProjectionData : LiveTimelineKeyWithInterpolate
|
||||
{
|
||||
public int IsEnable;
|
||||
public int OverrideIgnoreLayer;
|
||||
public LayerMask OverrideLayerMask;
|
||||
public int BacksideOff;
|
||||
public float MirrorBallBacksideFeather;
|
||||
public int ProjectionToCharacterModelOnly;
|
||||
public int TextureId;
|
||||
public Color Color = Color.white;
|
||||
public Vector3 Position;
|
||||
public Vector3 Angle;
|
||||
public Vector3 Scale = Vector3.one;
|
||||
public int Orthographic;
|
||||
public float OrthographicSize = 10f;
|
||||
public float NearClipPlane = 0.1f;
|
||||
public float FarClipPlane = 100f;
|
||||
public float FieldOfView = 60f;
|
||||
public float ColorPower = 1f;
|
||||
public int LightBlendMode;
|
||||
public int CharacterAttach;
|
||||
public int CharacterAttachPosition;
|
||||
public string BlinkLightName;
|
||||
public int BlinkLightNameHash;
|
||||
public int BlinkLightContainerIndex;
|
||||
public float BlinkLightBrightnessPower = 1f;
|
||||
public int IsAdjustedBlinkLightColor;
|
||||
public Vector3 MirrorBallRotateAxis = Vector3.up;
|
||||
public float MirrorBallRotateValue;
|
||||
public float MirrorBallProjectionRadius = 20f;
|
||||
public float MirrorBallFallOffPower = 2f;
|
||||
public int MirrorBallIsLoopRotation;
|
||||
public float MirrorBallLoopRotationSpeed;
|
||||
public Vector2 MirrorBallUVOffset;
|
||||
public Vector2 MirrorBallUVScale = Vector2.one;
|
||||
public int MirrorBallUseCubeMap;
|
||||
public LiveTimelineLightProjectionAnimationParam AnimationParam;
|
||||
}
|
||||
|
||||
[Serializable] public class LiveTimelineKeyLightProjectionDataList : LiveTimelineKeyDataListTemplate<LiveTimelineKeyLightProjectionData> { }
|
||||
[Serializable]
|
||||
public class LiveTimelineLightProjectionData : ILiveTimelineGroupDataWithName
|
||||
{
|
||||
public LiveTimelineKeyLightProjectionDataList keys;
|
||||
public int ContentType;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7ae1a98a234410e4d87de597cb89e723
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gallop.Live.Cutt
|
||||
{
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyMobCyalumeControlData : LiveTimelineKeyWithInterpolate
|
||||
{
|
||||
public Vector3 position;
|
||||
public Vector3 angle;
|
||||
public Vector3 scale = Vector3.one;
|
||||
|
||||
[NonSerialized] private Quaternion _rotationCache = Quaternion.identity;
|
||||
[NonSerialized] private bool _hasRotationCache;
|
||||
|
||||
public Quaternion GetRotation()
|
||||
{
|
||||
if (!_hasRotationCache)
|
||||
{
|
||||
_rotationCache = Quaternion.Euler(angle);
|
||||
_hasRotationCache = true;
|
||||
}
|
||||
|
||||
return _rotationCache;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyMobCyalumeControlDataList : LiveTimelineKeyDataListTemplate<LiveTimelineKeyMobCyalumeControlData>
|
||||
{
|
||||
public int unk48;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineMobCyalumeControlData : ILiveTimelineGroupDataWithName
|
||||
{
|
||||
public LiveTimelineKeyMobCyalumeControlDataList keys;
|
||||
}
|
||||
|
||||
public delegate void MobCyalumeUpdateInfoDelegate(ref MobCyalumeUpdateInfo updateInfo);
|
||||
|
||||
public struct MobCyalumeUpdateInfo
|
||||
{
|
||||
public LiveTimelineMobCyalumeControlData data;
|
||||
public int unk0;
|
||||
public Vector3 position;
|
||||
public Quaternion rotation;
|
||||
public Vector3 scale;
|
||||
public float currentFrame;
|
||||
public float currentLiveTime;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 280ab9377b79c584084b467f575dcf5e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gallop.Live.Cutt
|
||||
{
|
||||
[Serializable]
|
||||
public class LiveTimelineMonitorDressCondition
|
||||
{
|
||||
public int IsCheck;
|
||||
public int CharaId;
|
||||
public int DressId;
|
||||
public bool IsEnabled => IsCheck != 0;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineMonitorChangeUVSetting
|
||||
{
|
||||
public int IsChangeUVSetting;
|
||||
public int DispID = -1;
|
||||
public LiveTimelineMonitorDressCondition[] ConditionArray = Array.Empty<LiveTimelineMonitorDressCondition>();
|
||||
public bool IsEnabled => IsChangeUVSetting != 0;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyMonitorControlData : LiveTimelineKeyWithInterpolate
|
||||
{
|
||||
public Vector2 position;
|
||||
public Vector2 size = Vector2.one;
|
||||
public int dispID;
|
||||
public float speed = 1f;
|
||||
public string outputTextureLabel = string.Empty;
|
||||
public int playStartOffsetFrame;
|
||||
public float blendFactor = 1f;
|
||||
public Color colorFade = Color.clear;
|
||||
public Color BaseColor = Color.clear;
|
||||
public int SrcBlendMode = 1;
|
||||
public int DstBlendMode;
|
||||
public int RenderQueueNo = 2000;
|
||||
public int IsRenderQueue;
|
||||
public int DispID2 = -1;
|
||||
public float CrossFadeRate;
|
||||
public int LightImageNo;
|
||||
public int LightImageNo2;
|
||||
public float FilterTexScale = 1f;
|
||||
public LiveTimelineMonitorChangeUVSetting[] ChangeUVSettingArray = Array.Empty<LiveTimelineMonitorChangeUVSetting>();
|
||||
public int extraContent;
|
||||
|
||||
private const int AttrMulti = 65536;
|
||||
private const int AttrPlayReverse = 131072;
|
||||
private const int AttrUseMonitorCamera = 262144;
|
||||
private const int AttrForcedUseMonitorCamera = 524288;
|
||||
private const int AttrEnableBlendMode = 1048576;
|
||||
|
||||
public bool IsMultiFlag() => (((int)attribute) & AttrMulti) != 0;
|
||||
public bool IsReversePlayFlag() => (((int)attribute) & AttrPlayReverse) != 0;
|
||||
public bool IsMonitorCameraFlag() => (((int)attribute) & AttrUseMonitorCamera) != 0;
|
||||
public bool IsForcedUseMonitorCamera => (((int)attribute) & AttrForcedUseMonitorCamera) != 0;
|
||||
public bool IsEnabledBlendMode => (((int)attribute) & AttrEnableBlendMode) != 0;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyMonitorControlDataList : LiveTimelineKeyDataListTemplate<LiveTimelineKeyMonitorControlData> { }
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineMonitorControlData : ILiveTimelineGroupDataWithName
|
||||
{
|
||||
public LiveTimelineKeyMonitorControlDataList keys;
|
||||
public string SafeName => string.IsNullOrWhiteSpace(name) ? "Monitor" : name;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyMonitorCameraPositionData : LiveTimelineKeyCameraPositionData { }
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyMonitorCameraPositionDataList : LiveTimelineKeyDataListTemplate<LiveTimelineKeyMonitorCameraPositionData> { }
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineMonitorCameraPositionData : ILiveTimelineGroupDataWithName
|
||||
{
|
||||
public LiveTimelineKeyMonitorCameraPositionDataList keys;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyMonitorCameraLookAtData : LiveTimelineKeyCameraLookAtData { }
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineKeyMonitorCameraLookAtDataList : LiveTimelineKeyDataListTemplate<LiveTimelineKeyMonitorCameraLookAtData> { }
|
||||
|
||||
[Serializable]
|
||||
public class LiveTimelineMonitorCameraLookAtData : ILiveTimelineGroupDataWithName
|
||||
{
|
||||
public LiveTimelineKeyMonitorCameraLookAtDataList keys;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cfdc8a520019e8544b2904b4954b6182
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -952,6 +952,22 @@ namespace Gallop.Live.Cutt
|
||||
[SerializeField] public List<LiveTimelineHdrBloomData> hdrBloomKeys;
|
||||
[SerializeField] public List<LiveTimelineColorCorrectionData> colorCorrectionDataLists;
|
||||
|
||||
// Names verified against the cutt TypeTree. The capital letters are required for Unity deserialization.
|
||||
[SerializeField] public List<LiveTimelineMobCyalumeControlData> MobControlKeys;
|
||||
[SerializeField] public List<LiveTimelineMobCyalumeControlData> CyalumeControlKeys;
|
||||
[SerializeField] public List<LiveTimelineMonitorControlData> monitorControlList;
|
||||
[SerializeField] public List<LiveTimelineMonitorCameraPositionData> monitorCameraPosKeys;
|
||||
[SerializeField] public List<LiveTimelineMonitorCameraLookAtData> monitorCameraLookAtKeys;
|
||||
[SerializeField] public List<LiveTimelineLensFlareData> lensFlareList;
|
||||
[SerializeField] public List<LiveTimelineStageEnvironmentData> environmentDataLists;
|
||||
[SerializeField] public LiveTimelineFacialToonData facialToonSet;
|
||||
[SerializeField] public LiveTimelineKeyCameraLayerDataList cameraLayerKeys;
|
||||
[SerializeField] public List<LiveTimelinePropsData> propsList;
|
||||
[SerializeField] public List<LiveTimelinePropsAttachData> propsAttachList;
|
||||
[SerializeField] public LiveTimelineKeyCharaFootLightDataList charaFootLightKeys;
|
||||
[SerializeField] public List<LiveTimelineAdditionalLight> AdditionalLightList;
|
||||
[SerializeField] public List<LiveTimelineLightProjectionData> lightProjectionList;
|
||||
|
||||
// PostFilm (39):全语料 ~20200 keys / 59 首,是未实现轨道里数据量最大的一块。
|
||||
// 旧扫描把它记成「58/58 首存在但全部 0 keyframe(空占位)」,实测是错的
|
||||
// (song 1177 分别有 100 / 161 / 87 keys)。字段名取自 bundle TypeTree。
|
||||
@@ -1039,4 +1055,3 @@ namespace Gallop.Live.Cutt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
using UnityEngine;
|
||||
|
||||
// Compatibility component for scenes authored with the master4 helper. Runtime setup is now
|
||||
// owned by Director.InitializeCyalumeStage, so this type intentionally has no behavior.
|
||||
[DisallowMultipleComponent]
|
||||
public sealed class CyalumeAutoBinder : MonoBehaviour
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76a8f506f7e580449b2e8dee47ca1120
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,55 +1,524 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Gallop.Cyalume;
|
||||
using Gallop.Live.Cutt;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gallop.Live.Cyalume
|
||||
{
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
public class CyalumeController3D : CyalumeControllerBase
|
||||
{
|
||||
float passedtime = 0.0f;
|
||||
float intervaltime = 0.033333333f;
|
||||
float y_offset = 0.0f;
|
||||
GameObject CyalumeObj;
|
||||
Material CyalumeMaterial;
|
||||
private void Awake()
|
||||
[SerializeField] private bool _initializedObjects;
|
||||
[SerializeField] private bool _autoSetupOnStart;
|
||||
[SerializeField] private float _forceReplaceWarmupSeconds = 1.5f;
|
||||
|
||||
private readonly List<Renderer> _defaultRenderers = new List<Renderer>();
|
||||
private readonly List<Renderer> _randomRenderers = new List<Renderer>();
|
||||
|
||||
private GameObject _defaultInstance;
|
||||
private GameObject _randomInstance;
|
||||
private bool _usingRandomTarget;
|
||||
private Coroutine _setupCoroutine;
|
||||
private Coroutine _forceReplaceCoroutine;
|
||||
|
||||
[Header("Mob")]
|
||||
[SerializeField] private bool _enableMobController = true;
|
||||
[SerializeField] private string _mobPrefabName = "mob";
|
||||
[SerializeField] private GameObject _mobRootOverride;
|
||||
[SerializeField] private Color _mobColor = Color.white;
|
||||
[SerializeField] private Color _mobAmbientColor = Color.white;
|
||||
[SerializeField] private bool _mobVerboseLog;
|
||||
|
||||
private GameObject _mobInstance;
|
||||
private MobShadowController _mobShadowController;
|
||||
private LiveTimelineControl _mobTimelineControl;
|
||||
private readonly Vector3[] _mobPositions = new Vector3[11];
|
||||
private readonly Quaternion[] _mobRotations = new Quaternion[11];
|
||||
private readonly Vector3[] _mobScales = new Vector3[11];
|
||||
private readonly bool[] _mobDirtySlots = new bool[11];
|
||||
private bool _mobHasDirty;
|
||||
|
||||
public bool UsingRandomTarget => _usingRandomTarget;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
InitializeCyalume();
|
||||
gameObject.GetComponent<CyalumeController3D>().enabled = true;
|
||||
|
||||
base.Awake();
|
||||
if (_autoSetupOnStart)
|
||||
InitializeCyalumeObjectsOnly();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
private void Start()
|
||||
{
|
||||
if (CyalumeMaterial == null)
|
||||
if (_autoSetupOnStart)
|
||||
StartOfficialLikeSetup();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
TryBindGroupTimeline();
|
||||
MarkGroupMatrixDirty();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
UnbindGroupTimeline();
|
||||
}
|
||||
|
||||
public void StartOfficialLikeSetup(bool forceRebuild = false)
|
||||
{
|
||||
if (_setupCoroutine != null)
|
||||
{
|
||||
StopCoroutine(_setupCoroutine);
|
||||
_setupCoroutine = null;
|
||||
}
|
||||
|
||||
_setupCoroutine = StartCoroutine(SetupOfficialLike(forceRebuild));
|
||||
}
|
||||
|
||||
public IEnumerator SetupOfficialLike(bool forceRebuild = false)
|
||||
{
|
||||
ResetRuntimeState();
|
||||
InitializeCyalumeObjectsOnly(forceRebuild);
|
||||
|
||||
int musicId = ResolveMusicId();
|
||||
if (musicId <= 0)
|
||||
{
|
||||
Debug.LogWarning("[CyalumeController3D] musicId is unavailable.");
|
||||
yield break;
|
||||
}
|
||||
|
||||
var provider = ResolvePlaybackProvider();
|
||||
provider?.InitializeForMusicId(musicId);
|
||||
|
||||
string liveKey = CyalumePlaybackProvider.BuildPrimaryLiveKey(musicId);
|
||||
LoadTextureBundlesFromIndex(liveKey);
|
||||
|
||||
ApplyTargetSelection(false, true);
|
||||
EnsureCustomShaderOnCurrentTargets();
|
||||
CollectTargetMeshAndMaterials();
|
||||
CreateVertexColorCacheOfficialConservative();
|
||||
yield return null;
|
||||
|
||||
_textureSet.Clear();
|
||||
foreach (var pair in ResolveTexSetFromLoadedBundles(liveKey))
|
||||
_textureSet[pair.Key] = pair.Value;
|
||||
yield return null;
|
||||
|
||||
InitializeAudienceUvSpreadOfficialConservative();
|
||||
RefreshRendererEnabledState();
|
||||
_isInitialized = _targetRendererList.Count > 0 && _materialArray.Length > 0;
|
||||
ForceReplaceOfficialMaterialsInMemory();
|
||||
ForceReplaceCustomShaderInHierarchy(transform, true);
|
||||
ForceReplaceOfficialShaderAcrossLoadedScene();
|
||||
LogTargetShaderSummary("SetupOfficialLike");
|
||||
WriteCyalumeSceneSnapshot("SetupOfficialLike");
|
||||
|
||||
if (_verboseLog)
|
||||
{
|
||||
Debug.Log($"[CyalumeController3D] Setup complete. liveKey={liveKey}, targets={_targetRendererList.Count}, meshes={_meshFilters.Length}, materials={_materialArray.Length}, patterns={_textureSet.Count}");
|
||||
}
|
||||
|
||||
StartForceReplaceWarmup();
|
||||
_setupCoroutine = null;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
TryBindGroupTimeline();
|
||||
|
||||
if (!_isEnabledCyalume || !_initializedObjects || !_isInitialized)
|
||||
return;
|
||||
if (passedtime >= intervaltime)
|
||||
|
||||
if (!TryGetCurrentPlayback(out int patternId, out _, out _, out _, out _))
|
||||
return;
|
||||
|
||||
bool preferRandom = _playbackProvider != null && _playbackProvider.IsRandomPattern(patternId);
|
||||
bool targetChanged = ApplyTargetSelection(preferRandom);
|
||||
bool shaderChanged = EnsureCustomShaderOnCurrentTargets() > 0;
|
||||
bool memoryChanged = ForceReplaceOfficialMaterialsInMemory() > 0;
|
||||
if (targetChanged)
|
||||
{
|
||||
y_offset += (float)0.03125;
|
||||
if (y_offset >= 1.0f)
|
||||
{
|
||||
y_offset = 0.0f;
|
||||
}
|
||||
CyalumeMaterial.SetTextureOffset("_MainTex", new Vector2(0, y_offset));
|
||||
passedtime = 0;
|
||||
ForceReplaceOfficialMaterialsInMemory();
|
||||
ForceReplaceCustomShaderInHierarchy(transform, true);
|
||||
ForceReplaceOfficialShaderAcrossLoadedScene();
|
||||
CollectTargetMeshAndMaterials();
|
||||
CreateVertexColorCacheOfficialConservative();
|
||||
InitializeAudienceUvSpreadOfficialConservative();
|
||||
}
|
||||
passedtime += Time.fixedDeltaTime;
|
||||
else if (shaderChanged || memoryChanged)
|
||||
{
|
||||
CollectTargetMeshAndMaterials();
|
||||
ForceReplaceOfficialShaderAcrossLoadedScene();
|
||||
LogTargetShaderSummary(memoryChanged ? "ForceReplaceOfficialMaterialsInMemory" : "EnsureCustomShaderOnCurrentTargets");
|
||||
}
|
||||
|
||||
UpdateCyalumeOfficialConservative(false);
|
||||
}
|
||||
|
||||
public void InitializeCyalume()
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
AssetHolder CyalumeAssetHolder = gameObject.GetComponent<AssetHolder>();
|
||||
List<StringObjectPair> CyalumeObject = CyalumeAssetHolder._assetTable.list;
|
||||
foreach (StringObjectPair obj in CyalumeObject)
|
||||
TryBindGroupTimeline();
|
||||
FlushGroupMatrix();
|
||||
FlushMobShadowIfNeeded();
|
||||
}
|
||||
|
||||
private void StartForceReplaceWarmup()
|
||||
{
|
||||
if (_forceReplaceCoroutine != null)
|
||||
{
|
||||
GameObject tempObj = Instantiate((GameObject)obj.Value, transform);
|
||||
if (obj.Value.name.Contains("cyalume")){
|
||||
CyalumeObj = tempObj;
|
||||
CyalumeMaterial = gameObject.GetComponentInChildren<MeshRenderer>().material;
|
||||
StopCoroutine(_forceReplaceCoroutine);
|
||||
_forceReplaceCoroutine = null;
|
||||
}
|
||||
|
||||
if (_forceReplaceWarmupSeconds <= 0f)
|
||||
return;
|
||||
|
||||
_forceReplaceCoroutine = StartCoroutine(ForceReplaceWarmupCoroutine());
|
||||
}
|
||||
|
||||
private IEnumerator ForceReplaceWarmupCoroutine()
|
||||
{
|
||||
float endTime = Time.unscaledTime + _forceReplaceWarmupSeconds;
|
||||
while (Time.unscaledTime < endTime)
|
||||
{
|
||||
int replacedCount = 0;
|
||||
replacedCount += ForceReplaceOfficialMaterialsInMemory();
|
||||
replacedCount += ForceReplaceCustomShaderInHierarchy(transform, true);
|
||||
replacedCount += ForceReplaceOfficialShaderAcrossLoadedScene();
|
||||
if (replacedCount > 0)
|
||||
{
|
||||
CollectTargetMeshAndMaterials();
|
||||
LogTargetShaderSummary("ForceReplaceWarmup");
|
||||
WriteCyalumeSceneSnapshot("ForceReplaceWarmup");
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
_forceReplaceCoroutine = null;
|
||||
}
|
||||
|
||||
public override void InitializeCyalumeObjectsOnly(bool forceRebuild = false)
|
||||
{
|
||||
if (_initializedObjects && !forceRebuild)
|
||||
return;
|
||||
|
||||
_initializedObjects = false;
|
||||
_usingRandomTarget = false;
|
||||
_defaultInstance = null;
|
||||
_randomInstance = null;
|
||||
|
||||
_allRendererList.Clear();
|
||||
_targetRendererList.Clear();
|
||||
_defaultRenderers.Clear();
|
||||
_randomRenderers.Clear();
|
||||
|
||||
var assetHolder = GetComponent<AssetHolder>();
|
||||
if (assetHolder == null || assetHolder._assetTable == null)
|
||||
{
|
||||
Debug.LogWarning("[CyalumeController3D] AssetHolder or asset table is missing.");
|
||||
return;
|
||||
}
|
||||
|
||||
DestroyExistingCyalumeChildren();
|
||||
TryInstantiateNamedPrefab(assetHolder, "default", out _defaultInstance, _defaultRenderers);
|
||||
TryInstantiateNamedPrefab(assetHolder, "random", out _randomInstance, _randomRenderers);
|
||||
InitializeMobController(assetHolder);
|
||||
|
||||
_allRendererList.AddRange(_defaultRenderers);
|
||||
_allRendererList.AddRange(_randomRenderers);
|
||||
RefreshRendererEnabledState();
|
||||
|
||||
_initializedObjects = true;
|
||||
ApplyTargetSelection(false, true);
|
||||
}
|
||||
|
||||
public override bool ApplyTargetSelection(bool preferRandom, bool forceRefresh = false)
|
||||
{
|
||||
if (!_initializedObjects)
|
||||
{
|
||||
InitializeCyalumeObjectsOnly();
|
||||
if (!_initializedObjects)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool useRandom = preferRandom || _defaultRenderers.Count == 0;
|
||||
if (!useRandom && _defaultRenderers.Count == 0 && _randomRenderers.Count > 0)
|
||||
useRandom = true;
|
||||
|
||||
bool changed = forceRefresh || _usingRandomTarget != useRandom || _targetRendererList.Count == 0;
|
||||
_usingRandomTarget = useRandom;
|
||||
|
||||
_targetRendererList.Clear();
|
||||
if (_usingRandomTarget)
|
||||
_targetRendererList.AddRange(_randomRenderers.Count > 0 ? _randomRenderers : _defaultRenderers);
|
||||
else
|
||||
_targetRendererList.AddRange(_defaultRenderers.Count > 0 ? _defaultRenderers : _randomRenderers);
|
||||
|
||||
RefreshRendererEnabledState();
|
||||
|
||||
if (changed && _verboseLog)
|
||||
{
|
||||
Debug.Log($"[CyalumeController3D] Target selection -> {(_usingRandomTarget ? "random" : "default")}, count={_targetRendererList.Count}");
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
public bool ContainsTargetRenderer(Renderer renderer)
|
||||
{
|
||||
if (renderer == null)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < _targetRendererList.Count; i++)
|
||||
{
|
||||
if (_targetRendererList[i] == renderer)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool ContainsAnyRenderer(Renderer renderer)
|
||||
{
|
||||
if (renderer == null)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < _allRendererList.Count; i++)
|
||||
{
|
||||
if (_allRendererList[i] == renderer)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void TryBindGroupTimeline()
|
||||
{
|
||||
var director = Gallop.Live.Director.instance;
|
||||
if (director == null)
|
||||
return;
|
||||
|
||||
var timeline = director._liveTimelineControl;
|
||||
if (timeline == null || ReferenceEquals(_mobTimelineControl, timeline))
|
||||
return;
|
||||
|
||||
UnbindGroupTimeline();
|
||||
_mobTimelineControl = timeline;
|
||||
_mobTimelineControl.OnUpdateCyalumeControl += OnCyalumeControl;
|
||||
|
||||
if (_enableMobController)
|
||||
_mobTimelineControl.OnUpdateMobControl += OnMobControl;
|
||||
}
|
||||
|
||||
private void UnbindGroupTimeline()
|
||||
{
|
||||
if (_mobTimelineControl == null)
|
||||
return;
|
||||
|
||||
_mobTimelineControl.OnUpdateCyalumeControl -= OnCyalumeControl;
|
||||
_mobTimelineControl.OnUpdateMobControl -= OnMobControl;
|
||||
_mobTimelineControl = null;
|
||||
}
|
||||
|
||||
private void InitializeMobController(AssetHolder assetHolder)
|
||||
{
|
||||
_mobInstance = null;
|
||||
_mobShadowController = null;
|
||||
_mobHasDirty = false;
|
||||
Array.Clear(_mobDirtySlots, 0, _mobDirtySlots.Length);
|
||||
|
||||
if (!_enableMobController)
|
||||
return;
|
||||
|
||||
GameObject mobRoot = _mobRootOverride;
|
||||
if (!mobRoot && assetHolder != null && !string.IsNullOrEmpty(_mobPrefabName))
|
||||
{
|
||||
TryInstantiateNamedPrefab(assetHolder, _mobPrefabName, out _mobInstance, null);
|
||||
mobRoot = _mobInstance;
|
||||
}
|
||||
|
||||
if (!mobRoot)
|
||||
{
|
||||
if (_mobVerboseLog)
|
||||
Debug.LogWarning($"[CyalumeController3D] Mob root not found. prefabName='{_mobPrefabName}'");
|
||||
return;
|
||||
}
|
||||
|
||||
_mobShadowController = mobRoot.GetComponent<MobShadowController>();
|
||||
if (_mobShadowController == null)
|
||||
_mobShadowController = mobRoot.AddComponent<MobShadowController>();
|
||||
|
||||
_mobShadowController.Initialize(mobRoot);
|
||||
_mobShadowController.SetMobColor(_mobColor);
|
||||
_mobShadowController.SetAmbientColor(_mobAmbientColor);
|
||||
|
||||
if (_mobVerboseLog)
|
||||
Debug.Log($"[CyalumeController3D] Mob controller initialized on '{mobRoot.name}'.");
|
||||
}
|
||||
|
||||
private void OnCyalumeControl(ref MobCyalumeUpdateInfo info)
|
||||
{
|
||||
int index = ResolveGroupIndex(info);
|
||||
if ((uint)index >= 11u)
|
||||
return;
|
||||
|
||||
var position = info.position;
|
||||
var rotation = info.rotation;
|
||||
var scale = info.scale;
|
||||
SetGroupTRS(index, ref position, ref rotation, ref scale);
|
||||
}
|
||||
|
||||
private void OnMobControl(ref MobCyalumeUpdateInfo info)
|
||||
{
|
||||
int index = ResolveGroupIndex(info);
|
||||
if ((uint)index >= 11u)
|
||||
return;
|
||||
|
||||
_mobPositions[index] = info.position;
|
||||
_mobRotations[index] = info.rotation;
|
||||
_mobScales[index] = info.scale;
|
||||
_mobDirtySlots[index] = true;
|
||||
_mobHasDirty = true;
|
||||
}
|
||||
|
||||
private static int ResolveGroupIndex(MobCyalumeUpdateInfo info)
|
||||
{
|
||||
if ((uint)info.unk0 < 11u)
|
||||
return info.unk0;
|
||||
|
||||
if (info.data != null && info.data.keys != null && (uint)info.data.keys.unk48 < 11u)
|
||||
return info.data.keys.unk48;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void FlushMobShadowIfNeeded()
|
||||
{
|
||||
if (!_mobHasDirty)
|
||||
return;
|
||||
|
||||
if (_mobShadowController == null)
|
||||
{
|
||||
var assetHolder = GetComponent<AssetHolder>();
|
||||
InitializeMobController(assetHolder);
|
||||
if (_mobShadowController == null)
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < _mobDirtySlots.Length; i++)
|
||||
{
|
||||
if (!_mobDirtySlots[i])
|
||||
continue;
|
||||
|
||||
var position = _mobPositions[i];
|
||||
var rotation = _mobRotations[i];
|
||||
var scale = _mobScales[i];
|
||||
_mobShadowController.SetGroupTRS(i, ref position, ref rotation, ref scale);
|
||||
_mobDirtySlots[i] = false;
|
||||
}
|
||||
|
||||
_mobShadowController.FlushGroupMatrix();
|
||||
_mobHasDirty = false;
|
||||
}
|
||||
|
||||
private void DestroyExistingCyalumeChildren()
|
||||
{
|
||||
for (int i = transform.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
var child = transform.GetChild(i);
|
||||
if (child == null)
|
||||
continue;
|
||||
|
||||
string childName = child.name ?? string.Empty;
|
||||
bool isKnownCyalumeChild =
|
||||
childName.Equals("default", StringComparison.OrdinalIgnoreCase) ||
|
||||
childName.Equals("random", StringComparison.OrdinalIgnoreCase) ||
|
||||
(!string.IsNullOrEmpty(_mobPrefabName) && childName.Equals(_mobPrefabName, StringComparison.OrdinalIgnoreCase)) ||
|
||||
childName.IndexOf("cyalume", StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
|
||||
if (isKnownCyalumeChild)
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryInstantiateNamedPrefab(AssetHolder assetHolder, string assetName, out GameObject instance, List<Renderer> destination)
|
||||
{
|
||||
instance = null;
|
||||
destination?.Clear();
|
||||
|
||||
if (!TryResolvePrefab(assetHolder, assetName, out var prefab) || !prefab)
|
||||
{
|
||||
if (_verboseLog)
|
||||
Debug.LogWarning($"[CyalumeController3D] Missing cyalume prefab: {assetName}");
|
||||
return false;
|
||||
}
|
||||
|
||||
instance = Instantiate(prefab, transform);
|
||||
instance.name = prefab.name;
|
||||
SetLayerRecursively(instance, gameObject.layer);
|
||||
|
||||
if (destination != null)
|
||||
{
|
||||
var renderers = instance.GetComponentsInChildren<Renderer>(true);
|
||||
ApplyCustomShaderOverrideToRenderers(renderers);
|
||||
destination.AddRange(renderers);
|
||||
}
|
||||
|
||||
if (_verboseLog)
|
||||
{
|
||||
Debug.Log($"[CyalumeController3D] Spawned cyalume prefab '{assetName}' renderers={destination?.Count ?? 0}");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void SetLayerRecursively(GameObject root, int layer)
|
||||
{
|
||||
if (!root)
|
||||
return;
|
||||
|
||||
root.layer = layer;
|
||||
for (int i = 0; i < root.transform.childCount; i++)
|
||||
{
|
||||
var child = root.transform.GetChild(i);
|
||||
if (child)
|
||||
SetLayerRecursively(child.gameObject, layer);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryResolvePrefab(AssetHolder assetHolder, string assetName, out GameObject prefab)
|
||||
{
|
||||
prefab = null;
|
||||
if (assetHolder == null || assetHolder._assetTable == null || assetHolder._assetTable.list == null)
|
||||
return false;
|
||||
|
||||
foreach (var pair in assetHolder._assetTable.list)
|
||||
{
|
||||
var candidate = pair.Value as GameObject;
|
||||
if (!candidate)
|
||||
continue;
|
||||
|
||||
if (candidate.name.Equals(assetName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
prefab = candidate;
|
||||
return true;
|
||||
}
|
||||
|
||||
string keyText = pair.Key != null ? pair.Key.ToString() : string.Empty;
|
||||
if (!string.IsNullOrEmpty(keyText) && keyText.Equals(assetName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
prefab = candidate;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,903 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using Gallop.Live;
|
||||
|
||||
namespace Gallop.Live.Cyalume
|
||||
{
|
||||
[Serializable]
|
||||
public class CyalumePlaybackData
|
||||
{
|
||||
public int DataNo;
|
||||
public int PatternId;
|
||||
public float StartTime;
|
||||
public float PlaySpeed = 1f;
|
||||
public int ChoreographyType;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class CyalumePatternDefinition
|
||||
{
|
||||
public int PatternId;
|
||||
public string MoveType;
|
||||
public string ColorPattern;
|
||||
public string[] Colors = Array.Empty<string>();
|
||||
public string[] Widths = Array.Empty<string>();
|
||||
public string Signature;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class CyalumePartFrame
|
||||
{
|
||||
public float StartTime;
|
||||
public int[] States = new int[7];
|
||||
public float[] Volumes = new float[7];
|
||||
public float[] Pans = new float[7];
|
||||
public float VolumeRate = 1f;
|
||||
|
||||
public int GetState(int zoneIndex)
|
||||
{
|
||||
if (States == null || zoneIndex < 0 || zoneIndex >= States.Length)
|
||||
return 0;
|
||||
return States[zoneIndex];
|
||||
}
|
||||
|
||||
public bool IsActive(int zoneIndex)
|
||||
{
|
||||
return GetState(zoneIndex) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
public class CyalumePlaybackProvider : MonoBehaviour
|
||||
{
|
||||
[Header("Loaded playback data used by the controller.")]
|
||||
public List<CyalumePlaybackData> data = new List<CyalumePlaybackData>();
|
||||
|
||||
[Header("Debug: unique choreography pattern definitions built from the CSV.")]
|
||||
public List<CyalumePatternDefinition> patternDefinitions = new List<CyalumePatternDefinition>();
|
||||
|
||||
[Header("Loaded part data.")]
|
||||
public List<CyalumePartFrame> partFrames = new List<CyalumePartFrame>();
|
||||
|
||||
[Header("Auto-load mXXXX_cyalume.csv for the current live.")]
|
||||
public bool autoLoadForCurrentLive = true;
|
||||
public bool preferResourcesCsv = true;
|
||||
public bool tryLoadBundleEntryFromIndex = true;
|
||||
public bool verboseLog = true;
|
||||
public float bpmReference = 140f;
|
||||
public bool keepPreviousPatternOnPause = true;
|
||||
|
||||
[SerializeField] private int _loadedMusicId;
|
||||
[SerializeField] private string _loadedCsvSource;
|
||||
[SerializeField] private string _loadedPartCsvSource;
|
||||
|
||||
public int LoadedMusicId => _loadedMusicId;
|
||||
public string LoadedCsvSource => _loadedCsvSource;
|
||||
public string LoadedPartCsvSource => _loadedPartCsvSource;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (!autoLoadForCurrentLive || _loadedMusicId > 0 || (data != null && data.Count > 0))
|
||||
return;
|
||||
|
||||
if (Director.instance != null && Director.instance.live != null)
|
||||
{
|
||||
int resolvedMusicId = Director.instance.live.MusicId;
|
||||
if (resolvedMusicId > 0)
|
||||
InitializeForMusicId(resolvedMusicId);
|
||||
}
|
||||
}
|
||||
|
||||
public bool InitializeForMusicId(int musicId, bool forceReload = false)
|
||||
{
|
||||
if (musicId <= 0)
|
||||
{
|
||||
if (verboseLog)
|
||||
Debug.LogWarning("[CyalumePlaybackProvider] InitializeForMusicId failed: invalid musicId.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!forceReload && _loadedMusicId == musicId && data.Count > 0)
|
||||
return true;
|
||||
|
||||
data.Clear();
|
||||
patternDefinitions.Clear();
|
||||
partFrames.Clear();
|
||||
|
||||
_loadedMusicId = musicId;
|
||||
_loadedCsvSource = null;
|
||||
_loadedPartCsvSource = null;
|
||||
|
||||
if (!TryLoadCsvText(musicId, out string csvText, out string sourceName) || string.IsNullOrEmpty(csvText))
|
||||
{
|
||||
if (verboseLog)
|
||||
Debug.LogWarning($"[CyalumePlaybackProvider] Failed to resolve cyalume CSV for musicId={musicId}.");
|
||||
return false;
|
||||
}
|
||||
|
||||
_loadedCsvSource = sourceName;
|
||||
BuildPlaybackDataFromCsv(csvText);
|
||||
|
||||
if (TryLoadPartCsvText(musicId, out string partCsvText, out string partSource) && !string.IsNullOrEmpty(partCsvText))
|
||||
{
|
||||
_loadedPartCsvSource = partSource;
|
||||
BuildPartFramesFromCsv(partCsvText);
|
||||
if (verboseLog)
|
||||
Debug.Log($"[CyalumePlaybackProvider] Loaded part CSV: musicId={musicId}, source={partSource}, rows={partFrames.Count}");
|
||||
}
|
||||
|
||||
if (verboseLog)
|
||||
{
|
||||
Debug.Log($"[CyalumePlaybackProvider] Loaded cyalume CSV: musicId={musicId}, source={sourceName}, rows={data.Count}, uniquePatterns={patternDefinitions.Count}");
|
||||
}
|
||||
|
||||
return data.Count > 0;
|
||||
}
|
||||
|
||||
public bool TryGetCurrent(float liveTime, out CyalumePlaybackData current)
|
||||
{
|
||||
current = null;
|
||||
if (data == null || data.Count == 0)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < data.Count; i++)
|
||||
{
|
||||
var item = data[i];
|
||||
if (item == null)
|
||||
continue;
|
||||
|
||||
if (item.StartTime <= liveTime)
|
||||
current = item;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return current != null;
|
||||
}
|
||||
|
||||
public bool TryGetCurrentPartFrame(float liveTime, out CyalumePartFrame current)
|
||||
{
|
||||
current = null;
|
||||
if (partFrames == null || partFrames.Count == 0)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < partFrames.Count; i++)
|
||||
{
|
||||
var item = partFrames[i];
|
||||
if (item == null)
|
||||
continue;
|
||||
|
||||
if (item.StartTime <= liveTime)
|
||||
current = item;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return current != null;
|
||||
}
|
||||
|
||||
public bool TryGetCurrentState(float liveTime, out int patternId, out float patternStartTime, out float playSpeed, out int choreographyType)
|
||||
{
|
||||
if (TryGetCurrent(liveTime, out var current) && current != null)
|
||||
{
|
||||
patternId = Mathf.Max(0, current.PatternId);
|
||||
patternStartTime = current.StartTime;
|
||||
playSpeed = current.PlaySpeed > 0f ? current.PlaySpeed : 1f;
|
||||
choreographyType = current.ChoreographyType;
|
||||
return true;
|
||||
}
|
||||
|
||||
patternId = 0;
|
||||
patternStartTime = 0f;
|
||||
playSpeed = 1f;
|
||||
choreographyType = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryGetPatternDefinition(int patternId, out CyalumePatternDefinition definition)
|
||||
{
|
||||
definition = null;
|
||||
if (patternDefinitions == null || patternDefinitions.Count == 0)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < patternDefinitions.Count; i++)
|
||||
{
|
||||
var item = patternDefinitions[i];
|
||||
if (item != null && item.PatternId == patternId)
|
||||
{
|
||||
definition = item;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsRandomPattern(int patternId)
|
||||
{
|
||||
return TryGetPatternDefinition(patternId, out var definition) &&
|
||||
!string.IsNullOrEmpty(definition.ColorPattern) &&
|
||||
definition.ColorPattern.StartsWith("Random", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public static string BuildPrimaryLiveKey(int musicId)
|
||||
{
|
||||
return $"m{musicId}";
|
||||
}
|
||||
|
||||
public static string[] BuildLiveKeyCandidates(int musicId)
|
||||
{
|
||||
var keys = new List<string>();
|
||||
string raw = $"m{musicId}";
|
||||
keys.Add(raw);
|
||||
|
||||
string padded4 = $"m{musicId:D4}";
|
||||
if (!keys.Any(x => string.Equals(x, padded4, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
keys.Add(padded4);
|
||||
}
|
||||
|
||||
return keys.ToArray();
|
||||
}
|
||||
|
||||
private bool TryLoadCsvText(int musicId, out string csvText, out string sourceName)
|
||||
{
|
||||
csvText = null;
|
||||
sourceName = null;
|
||||
|
||||
string[] liveKeys = BuildLiveKeyCandidates(musicId);
|
||||
string[] resourcePaths = BuildResourcePathCandidates(liveKeys);
|
||||
|
||||
if (preferResourcesCsv)
|
||||
{
|
||||
for (int i = 0; i < resourcePaths.Length; i++)
|
||||
{
|
||||
string resourcePath = resourcePaths[i];
|
||||
if (string.IsNullOrEmpty(resourcePath))
|
||||
continue;
|
||||
|
||||
TextAsset asset = null;
|
||||
try
|
||||
{
|
||||
asset = Resources.Load<TextAsset>(resourcePath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
asset = null;
|
||||
}
|
||||
|
||||
if (asset != null && !string.IsNullOrEmpty(asset.text))
|
||||
{
|
||||
csvText = asset.text;
|
||||
sourceName = $"Resources/{resourcePath}";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (TryFindCsvInLoadedBundles(liveKeys, out csvText, out sourceName))
|
||||
return true;
|
||||
|
||||
if (tryLoadBundleEntryFromIndex)
|
||||
{
|
||||
TryLoadCsvBundlesFromIndex(liveKeys);
|
||||
if (TryFindCsvInLoadedBundles(liveKeys, out csvText, out sourceName))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryLoadPartCsvText(int musicId, out string csvText, out string sourceName)
|
||||
{
|
||||
csvText = null;
|
||||
sourceName = null;
|
||||
|
||||
string[] liveKeys = BuildLiveKeyCandidates(musicId);
|
||||
|
||||
for (int i = 0; i < liveKeys.Length; i++)
|
||||
{
|
||||
string liveKey = liveKeys[i];
|
||||
string[] candidates =
|
||||
{
|
||||
$"live/musicscores/{liveKey}/{liveKey}_part",
|
||||
$"live/musicscores/{liveKey}/{liveKey}_part.csv",
|
||||
$"{liveKey}_part"
|
||||
};
|
||||
|
||||
for (int j = 0; j < candidates.Length; j++)
|
||||
{
|
||||
TextAsset asset = null;
|
||||
try
|
||||
{
|
||||
asset = Resources.Load<TextAsset>(candidates[j]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
asset = null;
|
||||
}
|
||||
|
||||
if (asset != null && !string.IsNullOrEmpty(asset.text))
|
||||
{
|
||||
csvText = asset.text;
|
||||
sourceName = $"Resources/{candidates[j]}";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (TryFindAuxCsvInLoadedBundles(liveKeys, "part", out csvText, out sourceName))
|
||||
return true;
|
||||
|
||||
if (tryLoadBundleEntryFromIndex)
|
||||
{
|
||||
TryLoadAuxCsvBundlesFromIndex(liveKeys, "part");
|
||||
if (TryFindAuxCsvInLoadedBundles(liveKeys, "part", out csvText, out sourceName))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string[] BuildResourcePathCandidates(string[] liveKeys)
|
||||
{
|
||||
var candidates = new List<string>();
|
||||
for (int i = 0; i < liveKeys.Length; i++)
|
||||
{
|
||||
string liveKey = liveKeys[i];
|
||||
candidates.Add($"live/musicscores/{liveKey}/{liveKey}_cyalume");
|
||||
candidates.Add($"live/musicscores/{liveKey}/{liveKey}_cyalume.csv");
|
||||
candidates.Add($"{liveKey}_cyalume");
|
||||
}
|
||||
return candidates.Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
|
||||
}
|
||||
|
||||
private void TryLoadCsvBundlesFromIndex(string[] liveKeys)
|
||||
{
|
||||
var main = FindObjectOfType<UmaViewerMain>();
|
||||
if (main == null || main.AbList == null)
|
||||
return;
|
||||
|
||||
var entries = main.AbList.Values
|
||||
.Where(e => e != null && !string.IsNullOrEmpty(e.Name))
|
||||
.Where(e => liveKeys.Any(liveKey =>
|
||||
e.Name.IndexOf($"live/musicscores/{liveKey}/", StringComparison.OrdinalIgnoreCase) >= 0 &&
|
||||
e.Name.IndexOf($"{liveKey}_cyalume", StringComparison.OrdinalIgnoreCase) >= 0))
|
||||
.ToList();
|
||||
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
try
|
||||
{
|
||||
UmaAssetManager.LoadAssetBundle(entry, neverUnload: true, isRecursive: true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (verboseLog)
|
||||
{
|
||||
Debug.LogWarning($"[CyalumePlaybackProvider] Failed to load CSV bundle entry {entry?.Name}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TryLoadAuxCsvBundlesFromIndex(string[] liveKeys, string suffix)
|
||||
{
|
||||
var main = FindObjectOfType<UmaViewerMain>();
|
||||
if (main == null || main.AbList == null)
|
||||
return;
|
||||
|
||||
var entries = main.AbList.Values
|
||||
.Where(e => e != null && !string.IsNullOrEmpty(e.Name))
|
||||
.Where(e => liveKeys.Any(liveKey =>
|
||||
e.Name.IndexOf($"live/musicscores/{liveKey}/", StringComparison.OrdinalIgnoreCase) >= 0 &&
|
||||
e.Name.IndexOf($"{liveKey}_{suffix}", StringComparison.OrdinalIgnoreCase) >= 0))
|
||||
.ToList();
|
||||
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
try
|
||||
{
|
||||
UmaAssetManager.LoadAssetBundle(entry, neverUnload: true, isRecursive: true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (verboseLog)
|
||||
{
|
||||
Debug.LogWarning($"[CyalumePlaybackProvider] Failed to load {suffix} CSV bundle entry {entry?.Name}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryFindCsvInLoadedBundles(string[] liveKeys, out string csvText, out string sourceName)
|
||||
{
|
||||
csvText = null;
|
||||
sourceName = null;
|
||||
|
||||
foreach (var assetBundle in AssetBundle.GetAllLoadedAssetBundles())
|
||||
{
|
||||
if (!assetBundle)
|
||||
continue;
|
||||
|
||||
string[] names;
|
||||
try
|
||||
{
|
||||
names = assetBundle.GetAllAssetNames();
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (names == null || names.Length == 0)
|
||||
continue;
|
||||
|
||||
for (int i = 0; i < names.Length; i++)
|
||||
{
|
||||
string path = names[i];
|
||||
if (!IsMatchingCyalumeCsvPath(path, liveKeys))
|
||||
continue;
|
||||
|
||||
TextAsset textAsset = null;
|
||||
try
|
||||
{
|
||||
textAsset = assetBundle.LoadAsset<TextAsset>(path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
textAsset = null;
|
||||
}
|
||||
|
||||
if (textAsset == null || string.IsNullOrEmpty(textAsset.text))
|
||||
continue;
|
||||
|
||||
csvText = textAsset.text;
|
||||
sourceName = path;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryFindAuxCsvInLoadedBundles(string[] liveKeys, string suffix, out string csvText, out string sourceName)
|
||||
{
|
||||
csvText = null;
|
||||
sourceName = null;
|
||||
|
||||
foreach (var assetBundle in AssetBundle.GetAllLoadedAssetBundles())
|
||||
{
|
||||
if (!assetBundle)
|
||||
continue;
|
||||
|
||||
string[] names;
|
||||
try
|
||||
{
|
||||
names = assetBundle.GetAllAssetNames();
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (names == null || names.Length == 0)
|
||||
continue;
|
||||
|
||||
for (int i = 0; i < names.Length; i++)
|
||||
{
|
||||
string path = names[i];
|
||||
if (!IsMatchingAuxCsvPath(path, liveKeys, suffix))
|
||||
continue;
|
||||
|
||||
TextAsset textAsset = null;
|
||||
try
|
||||
{
|
||||
textAsset = assetBundle.LoadAsset<TextAsset>(path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
textAsset = null;
|
||||
}
|
||||
|
||||
if (textAsset == null || string.IsNullOrEmpty(textAsset.text))
|
||||
continue;
|
||||
|
||||
csvText = textAsset.text;
|
||||
sourceName = path;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool IsMatchingCyalumeCsvPath(string path, string[] liveKeys)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path) || liveKeys == null || liveKeys.Length == 0)
|
||||
return false;
|
||||
|
||||
string normalized = path.Replace('\\', '/');
|
||||
for (int i = 0; i < liveKeys.Length; i++)
|
||||
{
|
||||
string liveKey = liveKeys[i];
|
||||
if (normalized.IndexOf($"live/musicscores/{liveKey}/", StringComparison.OrdinalIgnoreCase) < 0)
|
||||
continue;
|
||||
|
||||
string fileName = Path.GetFileNameWithoutExtension(normalized);
|
||||
if (string.Equals(fileName, $"{liveKey}_cyalume", StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool IsMatchingAuxCsvPath(string path, string[] liveKeys, string suffix)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path) || liveKeys == null || liveKeys.Length == 0)
|
||||
return false;
|
||||
|
||||
string normalized = path.Replace('\\', '/');
|
||||
for (int i = 0; i < liveKeys.Length; i++)
|
||||
{
|
||||
string liveKey = liveKeys[i];
|
||||
if (normalized.IndexOf($"live/musicscores/{liveKey}/", StringComparison.OrdinalIgnoreCase) < 0)
|
||||
continue;
|
||||
|
||||
string fileName = Path.GetFileNameWithoutExtension(normalized);
|
||||
if (string.Equals(fileName, $"{liveKey}_{suffix}", StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void BuildPlaybackDataFromCsv(string csvText)
|
||||
{
|
||||
data.Clear();
|
||||
patternDefinitions.Clear();
|
||||
|
||||
if (string.IsNullOrEmpty(csvText))
|
||||
return;
|
||||
|
||||
var rows = ParseCsvRows(csvText);
|
||||
if (rows.Count <= 1)
|
||||
return;
|
||||
|
||||
var headerMap = BuildHeaderMap(rows[0]);
|
||||
if (!headerMap.ContainsKey("time"))
|
||||
{
|
||||
if (verboseLog)
|
||||
Debug.LogWarning("[CyalumePlaybackProvider] CSV missing time column.");
|
||||
return;
|
||||
}
|
||||
|
||||
var patternMap = new Dictionary<string, int>(StringComparer.Ordinal);
|
||||
int lastVisualPatternId = 0;
|
||||
bool hasLastVisualPattern = false;
|
||||
|
||||
for (int rowIndex = 1; rowIndex < rows.Count; rowIndex++)
|
||||
{
|
||||
var row = rows[rowIndex];
|
||||
if (row == null || row.Count == 0)
|
||||
continue;
|
||||
|
||||
if (!TryParseTimeSeconds(GetCell(row, headerMap, "time"), out float startTime))
|
||||
continue;
|
||||
|
||||
string moveType = NormalizeCell(GetCell(row, headerMap, "move_type"));
|
||||
string colorPattern = NormalizeCell(GetCell(row, headerMap, "color_pattern"));
|
||||
string[] colors = GetSeriesCells(row, headerMap, "color", 5);
|
||||
string[] widths = GetSeriesCells(row, headerMap, "width", 5);
|
||||
|
||||
int choreographyType = ComputeChoreographyType(moveType);
|
||||
bool isPauseLike = keepPreviousPatternOnPause && choreographyType >= 8;
|
||||
|
||||
int patternId;
|
||||
if (isPauseLike)
|
||||
{
|
||||
patternId = hasLastVisualPattern ? lastVisualPatternId : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
string signature = BuildPatternSignature(moveType, colorPattern, colors, widths);
|
||||
if (!patternMap.TryGetValue(signature, out patternId))
|
||||
{
|
||||
patternId = patternMap.Count;
|
||||
patternMap[signature] = patternId;
|
||||
|
||||
patternDefinitions.Add(new CyalumePatternDefinition
|
||||
{
|
||||
PatternId = patternId,
|
||||
MoveType = moveType,
|
||||
ColorPattern = colorPattern,
|
||||
Colors = colors.ToArray(),
|
||||
Widths = widths.ToArray(),
|
||||
Signature = signature,
|
||||
});
|
||||
}
|
||||
|
||||
lastVisualPatternId = patternId;
|
||||
hasLastVisualPattern = true;
|
||||
}
|
||||
|
||||
float playSpeed = ComputePlaySpeed(GetCell(row, headerMap, "bpm"));
|
||||
|
||||
data.Add(new CyalumePlaybackData
|
||||
{
|
||||
DataNo = data.Count,
|
||||
PatternId = patternId,
|
||||
StartTime = startTime,
|
||||
PlaySpeed = playSpeed,
|
||||
ChoreographyType = choreographyType,
|
||||
});
|
||||
}
|
||||
|
||||
data.Sort((a, b) => a.StartTime.CompareTo(b.StartTime));
|
||||
for (int i = 0; i < data.Count; i++)
|
||||
{
|
||||
data[i].DataNo = i;
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildPartFramesFromCsv(string csvText)
|
||||
{
|
||||
partFrames.Clear();
|
||||
if (string.IsNullOrEmpty(csvText))
|
||||
return;
|
||||
|
||||
var rows = ParseCsvRows(csvText);
|
||||
if (rows.Count <= 1)
|
||||
return;
|
||||
|
||||
var headerMap = BuildHeaderMap(rows[0]);
|
||||
if (!headerMap.ContainsKey("time"))
|
||||
{
|
||||
if (verboseLog)
|
||||
Debug.LogWarning("[CyalumePlaybackProvider] Part CSV missing time column.");
|
||||
return;
|
||||
}
|
||||
|
||||
string[] zoneNames = { "left3", "left2", "left", "center", "right", "right2", "right3" };
|
||||
|
||||
for (int rowIndex = 1; rowIndex < rows.Count; rowIndex++)
|
||||
{
|
||||
var row = rows[rowIndex];
|
||||
if (row == null || row.Count == 0)
|
||||
continue;
|
||||
|
||||
if (!TryParseTimeSeconds(GetCell(row, headerMap, "time"), out float startTime))
|
||||
continue;
|
||||
|
||||
var frame = new CyalumePartFrame();
|
||||
frame.StartTime = startTime;
|
||||
|
||||
for (int i = 0; i < zoneNames.Length; i++)
|
||||
{
|
||||
frame.States[i] = ParseIntOrDefault(GetCell(row, headerMap, zoneNames[i]), 0);
|
||||
frame.Volumes[i] = ParseFloatOrSentinel(GetCell(row, headerMap, zoneNames[i] + "_vol"));
|
||||
frame.Pans[i] = ParseFloatOrSentinel(GetCell(row, headerMap, zoneNames[i] + "_pan"));
|
||||
}
|
||||
|
||||
frame.VolumeRate = ParseFloatOrDefault(GetCell(row, headerMap, "volume_rate"), 1f);
|
||||
partFrames.Add(frame);
|
||||
}
|
||||
|
||||
partFrames.Sort((a, b) => a.StartTime.CompareTo(b.StartTime));
|
||||
}
|
||||
|
||||
private static Dictionary<string, int> BuildHeaderMap(List<string> header)
|
||||
{
|
||||
var map = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
||||
if (header == null)
|
||||
return map;
|
||||
|
||||
for (int i = 0; i < header.Count; i++)
|
||||
{
|
||||
string key = NormalizeHeader(header[i]);
|
||||
if (string.IsNullOrEmpty(key) || map.ContainsKey(key))
|
||||
continue;
|
||||
map[key] = i;
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private static string NormalizeHeader(string value)
|
||||
{
|
||||
return (value ?? string.Empty).Trim().Trim('\ufeff').ToLowerInvariant();
|
||||
}
|
||||
|
||||
private static string GetCell(List<string> row, Dictionary<string, int> headerMap, string key)
|
||||
{
|
||||
if (row == null || headerMap == null || !headerMap.TryGetValue(key, out int index))
|
||||
return null;
|
||||
|
||||
return index >= 0 && index < row.Count ? row[index] : null;
|
||||
}
|
||||
|
||||
private static string[] GetSeriesCells(List<string> row, Dictionary<string, int> headerMap, string prefix, int count)
|
||||
{
|
||||
var values = new string[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
values[i] = NormalizeCell(GetCell(row, headerMap, $"{prefix}{i + 1}"));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
private static string NormalizeCell(string value)
|
||||
{
|
||||
return (value ?? string.Empty).Trim();
|
||||
}
|
||||
|
||||
private static string BuildPatternSignature(string moveType, string colorPattern, string[] colors, string[] widths)
|
||||
{
|
||||
var parts = new List<string>(2 + (colors?.Length ?? 0) + (widths?.Length ?? 0))
|
||||
{
|
||||
NormalizeSignatureValue(moveType),
|
||||
NormalizeSignatureValue(colorPattern)
|
||||
};
|
||||
|
||||
if (colors != null)
|
||||
{
|
||||
for (int i = 0; i < colors.Length; i++)
|
||||
parts.Add(NormalizeSignatureValue(colors[i]));
|
||||
}
|
||||
|
||||
if (widths != null)
|
||||
{
|
||||
for (int i = 0; i < widths.Length; i++)
|
||||
parts.Add(NormalizeSignatureValue(widths[i]));
|
||||
}
|
||||
|
||||
return string.Join("|", parts);
|
||||
}
|
||||
|
||||
private static string NormalizeSignatureValue(string value)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(value) ? "-" : value.Trim().ToLowerInvariant();
|
||||
}
|
||||
|
||||
private bool TryParseTimeSeconds(string rawValue, out float seconds)
|
||||
{
|
||||
seconds = 0f;
|
||||
if (string.IsNullOrWhiteSpace(rawValue))
|
||||
return false;
|
||||
|
||||
rawValue = rawValue.Trim();
|
||||
if (int.TryParse(rawValue, out int milliseconds))
|
||||
{
|
||||
seconds = milliseconds / 1000f;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (float.TryParse(rawValue, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out float value))
|
||||
{
|
||||
seconds = value > 1000f ? (value / 1000f) : value;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private float ComputePlaySpeed(string bpmValue)
|
||||
{
|
||||
float fallback = 1f;
|
||||
if (string.IsNullOrWhiteSpace(bpmValue))
|
||||
return fallback;
|
||||
|
||||
if (!float.TryParse(bpmValue, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out float bpm))
|
||||
return fallback;
|
||||
|
||||
if (bpm <= 0f)
|
||||
return fallback;
|
||||
|
||||
float reference = bpmReference > 0f ? bpmReference : 140f;
|
||||
return Mathf.Max(0.01f, bpm / reference);
|
||||
}
|
||||
|
||||
private static int ComputeChoreographyType(string moveType)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(moveType))
|
||||
return 0;
|
||||
|
||||
return string.Equals(moveType.Trim(), "Pause", StringComparison.OrdinalIgnoreCase) ? 8 : 0;
|
||||
}
|
||||
|
||||
private static int ParseIntOrDefault(string raw, int fallback)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(raw))
|
||||
return fallback;
|
||||
|
||||
return int.TryParse(raw.Trim(), out int value) ? value : fallback;
|
||||
}
|
||||
|
||||
private static float ParseFloatOrDefault(string raw, float fallback)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(raw))
|
||||
return fallback;
|
||||
|
||||
return float.TryParse(raw.Trim(), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out float value)
|
||||
? value
|
||||
: fallback;
|
||||
}
|
||||
|
||||
private static float ParseFloatOrSentinel(string raw)
|
||||
{
|
||||
float value = ParseFloatOrDefault(raw, 999f);
|
||||
return Mathf.Approximately(value, 999f) ? float.NaN : value;
|
||||
}
|
||||
|
||||
private static List<List<string>> ParseCsvRows(string text)
|
||||
{
|
||||
var rows = new List<List<string>>();
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return rows;
|
||||
|
||||
var row = new List<string>();
|
||||
var cell = new StringBuilder();
|
||||
bool inQuotes = false;
|
||||
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
char c = text[i];
|
||||
if (inQuotes)
|
||||
{
|
||||
if (c == '"')
|
||||
{
|
||||
bool escapedQuote = i + 1 < text.Length && text[i + 1] == '"';
|
||||
if (escapedQuote)
|
||||
{
|
||||
cell.Append('"');
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
inQuotes = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.Append(c);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '"':
|
||||
inQuotes = true;
|
||||
break;
|
||||
case ',':
|
||||
row.Add(cell.ToString());
|
||||
cell.Length = 0;
|
||||
break;
|
||||
case '\r':
|
||||
break;
|
||||
case '\n':
|
||||
row.Add(cell.ToString());
|
||||
cell.Length = 0;
|
||||
rows.Add(row);
|
||||
row = new List<string>();
|
||||
break;
|
||||
default:
|
||||
cell.Append(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
row.Add(cell.ToString());
|
||||
if (row.Count > 1 || !string.IsNullOrEmpty(row[0]))
|
||||
rows.Add(row);
|
||||
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2acb0c9d0ca50ba45b7d9a2ae70d860d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,140 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gallop.Cyalume
|
||||
{
|
||||
[AddComponentMenu("")]
|
||||
public class MobShadowController : MonoBehaviour
|
||||
{
|
||||
private static readonly int MobGroupMatrixPropertyId = Shader.PropertyToID("_MobGroupMatrix");
|
||||
|
||||
[SerializeField] private string _mobColorPropertyName = "_MobColor";
|
||||
[SerializeField] private string _maskPosArrayPropertyName = "_MaskPosArray";
|
||||
[SerializeField] private string _groupMatrixArrayPropertyName = "_MobGroupMatrix";
|
||||
|
||||
private GameObject _targetObject;
|
||||
private Transform _targetObjectTransform;
|
||||
private Vector3 _targetObjectInitPosition;
|
||||
private bool _isInitialized;
|
||||
private Renderer[] _renderers;
|
||||
private Color _mobColor;
|
||||
private Color _ambientColor;
|
||||
private int _mobColorPropertyId;
|
||||
private int _maskPosArrayPropertyId;
|
||||
private int _groupMatrixArrayPropertyId;
|
||||
private Vector4[] _maskPosArray;
|
||||
private Matrix4x4[] _groupMatrixArray;
|
||||
private bool _isUpdateGroupMatrix;
|
||||
|
||||
public Vector4[] MaskPosArray
|
||||
{
|
||||
set
|
||||
{
|
||||
_maskPosArray = value;
|
||||
}
|
||||
}
|
||||
|
||||
public MobShadowController()
|
||||
{
|
||||
_mobColor = Color.white;
|
||||
_ambientColor = Color.white;
|
||||
_mobColorPropertyId = -1;
|
||||
_maskPosArrayPropertyId = -1;
|
||||
_groupMatrixArrayPropertyId = -1;
|
||||
_groupMatrixArray = new Matrix4x4[11];
|
||||
}
|
||||
|
||||
public void Initialize(GameObject targetObject)
|
||||
{
|
||||
_mobColorPropertyId = string.IsNullOrEmpty(_mobColorPropertyName) ? -1 : Shader.PropertyToID(_mobColorPropertyName);
|
||||
_maskPosArrayPropertyId = string.IsNullOrEmpty(_maskPosArrayPropertyName) ? -1 : Shader.PropertyToID(_maskPosArrayPropertyName);
|
||||
_groupMatrixArrayPropertyId = string.IsNullOrEmpty(_groupMatrixArrayPropertyName) ? -1 : Shader.PropertyToID(_groupMatrixArrayPropertyName);
|
||||
|
||||
_targetObject = targetObject;
|
||||
if (_targetObject == null)
|
||||
return;
|
||||
|
||||
_targetObjectTransform = _targetObject.transform;
|
||||
if (_targetObjectTransform == null)
|
||||
return;
|
||||
|
||||
_targetObjectInitPosition = _targetObjectTransform.position;
|
||||
_renderers = _targetObject.GetComponentsInChildren<Renderer>();
|
||||
|
||||
if (_groupMatrixArray == null)
|
||||
_groupMatrixArray = new Matrix4x4[11];
|
||||
|
||||
for (int i = 0; i < _groupMatrixArray.Length; i++)
|
||||
{
|
||||
_groupMatrixArray[i] = Matrix4x4.identity;
|
||||
}
|
||||
|
||||
_isUpdateGroupMatrix = true;
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
public void SetMobColor(Color color)
|
||||
{
|
||||
_mobColor = color;
|
||||
_UpdateShaderParamColor();
|
||||
}
|
||||
|
||||
public void SetAmbientColor(Color color)
|
||||
{
|
||||
_ambientColor = color;
|
||||
_UpdateShaderParamColor();
|
||||
}
|
||||
|
||||
public void SetGroupTRS(int index, ref Vector3 position, ref Quaternion rotation, ref Vector3 scale)
|
||||
{
|
||||
if (!_isInitialized)
|
||||
return;
|
||||
|
||||
if (_groupMatrixArray == null)
|
||||
return;
|
||||
|
||||
if ((uint)index >= (uint)_groupMatrixArray.Length)
|
||||
return;
|
||||
|
||||
_groupMatrixArray[index].SetTRS(position, rotation, scale);
|
||||
_isUpdateGroupMatrix = true;
|
||||
}
|
||||
|
||||
public void FlushGroupMatrix()
|
||||
{
|
||||
if (!_isInitialized || !_isUpdateGroupMatrix || _groupMatrixArray == null)
|
||||
return;
|
||||
|
||||
_isUpdateGroupMatrix = false;
|
||||
|
||||
int propertyId = _groupMatrixArrayPropertyId >= 0
|
||||
? _groupMatrixArrayPropertyId
|
||||
: MobGroupMatrixPropertyId;
|
||||
|
||||
Shader.SetGlobalMatrixArray(propertyId, _groupMatrixArray);
|
||||
}
|
||||
|
||||
private void _UpdateShaderParamColor()
|
||||
{
|
||||
if (_renderers == null)
|
||||
return;
|
||||
|
||||
Color finalColor = new Color(
|
||||
_ambientColor.r * _mobColor.r,
|
||||
_ambientColor.g * _mobColor.g,
|
||||
_ambientColor.b * _mobColor.b,
|
||||
_ambientColor.a * _mobColor.a
|
||||
);
|
||||
|
||||
if (_mobColorPropertyId >= 0)
|
||||
Shader.SetGlobalColor(_mobColorPropertyId, finalColor);
|
||||
|
||||
if (_maskPosArray != null && _maskPosArrayPropertyId >= 0)
|
||||
Shader.SetGlobalVectorArray(_maskPosArrayPropertyId, _maskPosArray);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab50ba8b988b5cd43823243f52c6136b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -6,6 +6,8 @@ using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using Gallop.Live.Cyalume;
|
||||
using Gallop.RenderPipeline;
|
||||
|
||||
namespace Gallop.Live
|
||||
{
|
||||
@@ -54,6 +56,9 @@ namespace Gallop.Live
|
||||
private Dictionary<string, Vector2> _uvScrollAccum = new Dictionary<string, Vector2>();
|
||||
|
||||
private Volume _postProcessVolume;
|
||||
private readonly Dictionary<int, GameObject> _liveProps = new Dictionary<int, GameObject>();
|
||||
private readonly Dictionary<LiveTimelineAdditionalLight, Light> _additionalLights = new Dictionary<LiveTimelineAdditionalLight, Light>();
|
||||
private readonly Dictionary<LiveTimelineLightProjectionData, Light> _projectionLights = new Dictionary<LiveTimelineLightProjectionData, Light>();
|
||||
|
||||
public UmaViewerAudio.CuteAudioSource liveMusic = new UmaViewerAudio.CuteAudioSource();
|
||||
|
||||
@@ -80,6 +85,12 @@ namespace Gallop.Live
|
||||
public Transform MainCameraTransform => _mainCameraTransform;
|
||||
|
||||
private Transform _mainCameraTransform;
|
||||
private bool _playbackPaused;
|
||||
private bool _freeCameraActive;
|
||||
private FreeCam _freeCamera;
|
||||
|
||||
public bool PlaybackPaused => _playbackPaused;
|
||||
public bool FreeCameraActive => _freeCameraActive;
|
||||
|
||||
public bool isTimelineControlled
|
||||
{
|
||||
@@ -111,6 +122,10 @@ namespace Gallop.Live
|
||||
if (live != null)
|
||||
{
|
||||
_instance = this;
|
||||
if (GetComponent<SkirtCollisionRuntimeTuner>() == null)
|
||||
gameObject.AddComponent<SkirtCollisionRuntimeTuner>();
|
||||
if (GetComponent<LivePlaybackToolbar>() == null)
|
||||
gameObject.AddComponent<LivePlaybackToolbar>();
|
||||
Debug.Log(string.Format(CUTT_PATH, live.MusicId));
|
||||
Builder.LoadAssetPath(string.Format(CUTT_PATH, live.MusicId), transform);
|
||||
if (RequireStage)
|
||||
@@ -119,6 +134,8 @@ namespace Gallop.Live
|
||||
Builder.LoadAssetPath(string.Format(STAGE_PATH, live.BackGroundId), transform);
|
||||
_liveTimelineControl.StageObjectMap = _stageController.StageObjectMap;
|
||||
_liveTimelineControl.StageObjectUnitMap = _stageController.StageObjectUnitMap;
|
||||
InitializeCyalumeStage();
|
||||
InitializeStageMonitor();
|
||||
}
|
||||
|
||||
//Make CharacterObject
|
||||
@@ -231,6 +248,14 @@ namespace Gallop.Live
|
||||
_liveTimelineControl.OnUpdateChromaticAberration += OnChromaticAberrationUpdate;
|
||||
_liveTimelineControl.OnUpdateColorCorrection += OnColorCorrectionUpdate;
|
||||
_liveTimelineControl.OnUpdatePostFilm += OnPostFilmUpdate;
|
||||
_liveTimelineControl.OnUpdateLensFlare += OnLensFlareUpdate;
|
||||
_liveTimelineControl.OnUpdateEnvironment += OnEnvironmentUpdate;
|
||||
_liveTimelineControl.OnUpdateFacialToon += OnFacialToonUpdate;
|
||||
_liveTimelineControl.OnUpdateProps += OnPropsUpdate;
|
||||
_liveTimelineControl.OnUpdatePropsAttach += OnPropsAttachUpdate;
|
||||
_liveTimelineControl.OnUpdateCharaFootLight += OnCharaFootLightUpdate;
|
||||
_liveTimelineControl.OnUpdateAdditionalLight += OnAdditionalLightUpdate;
|
||||
_liveTimelineControl.OnUpdateLightProjection += OnLightProjectionUpdate;
|
||||
PostFilmRendererFeature.ResetLayers();
|
||||
|
||||
// 获取或创建摄像机上的 Volume 组件,供后处理 handler 使用
|
||||
@@ -252,6 +277,39 @@ namespace Gallop.Live
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeCyalumeStage()
|
||||
{
|
||||
if (_stageController == null) return;
|
||||
|
||||
foreach (var holder in _stageController.GetComponentsInChildren<AssetHolder>(true))
|
||||
{
|
||||
if (holder == null || holder._assetTable == null || holder._assetTable.list == null) continue;
|
||||
|
||||
bool hasDefault = false;
|
||||
bool hasRandom = false;
|
||||
foreach (var entry in holder._assetTable.list)
|
||||
{
|
||||
if (string.Equals(entry.Key, "default", StringComparison.OrdinalIgnoreCase)) hasDefault = true;
|
||||
if (string.Equals(entry.Key, "random", StringComparison.OrdinalIgnoreCase)) hasRandom = true;
|
||||
}
|
||||
|
||||
if (!hasDefault && !hasRandom) continue;
|
||||
var controller = holder.GetComponent<CyalumeController3D>();
|
||||
if (controller == null) controller = holder.gameObject.AddComponent<CyalumeController3D>();
|
||||
controller.StartOfficialLikeSetup();
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log("[Cyalume] no audience AssetHolder was present on this stage.");
|
||||
}
|
||||
|
||||
private void InitializeStageMonitor()
|
||||
{
|
||||
if (_stageController == null) return;
|
||||
if (_stageController.GetComponent<StageMonitorDriver>() == null)
|
||||
_stageController.gameObject.AddComponent<StageMonitorDriver>();
|
||||
}
|
||||
|
||||
private void OnEffectUpdate(LiveTimelineEffectData effectData, LiveTimelineKeyEffectData keyData)
|
||||
{
|
||||
if (keyData == null) return;
|
||||
@@ -280,6 +338,195 @@ namespace Gallop.Live
|
||||
_activeEffects[effectData] = (keyData.frame, instance);
|
||||
}
|
||||
|
||||
private void OnLensFlareUpdate(LiveTimelineLensFlareData data, LiveTimelineKeyLensFlareData key)
|
||||
{
|
||||
if (key == null || _stageController == null) return;
|
||||
bool enabled = key.enableParameter == 0 || key.enableFlare != 0;
|
||||
foreach (var flare in _stageController.GetComponentsInChildren<CustomLensFlare>(true))
|
||||
{
|
||||
if (flare == null) continue;
|
||||
flare.ApplyTimeline(enabled,
|
||||
key.IsOverridePosition != 0 ? key.offset : flare.transform.localPosition,
|
||||
key.color, key.brightness, key.fadeSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnvironmentUpdate(LiveTimelineStageEnvironmentData data, LiveTimelineKeyStageEnvironmentData key)
|
||||
{
|
||||
if (key == null || _stageController == null) return;
|
||||
foreach (var mirror in _stageController.GetComponentsInChildren<MirrorReflection>(true))
|
||||
mirror.ApplyTimeline(key.MirrorIsValid, key.MirrorEnabled, key.ReflectionRate);
|
||||
}
|
||||
|
||||
private void OnFacialToonUpdate(int characterIndex, LiveTimelineKeyFacialToonData key)
|
||||
{
|
||||
if (key == null || characterIndex < 0 || characterIndex >= CharaContainerScript.Count) return;
|
||||
var container = CharaContainerScript[characterIndex];
|
||||
if (container == null) return;
|
||||
var block = PropBlock;
|
||||
foreach (var renderer in container.GetComponentsInChildren<Renderer>(true))
|
||||
{
|
||||
if (renderer == null) continue;
|
||||
renderer.GetPropertyBlock(block);
|
||||
foreach (var material in renderer.sharedMaterials)
|
||||
{
|
||||
if (material == null) continue;
|
||||
if (material.HasProperty("_CheekPretenseThreshold")) block.SetFloat("_CheekPretenseThreshold", key.CheekPretenseThreshold);
|
||||
if (material.HasProperty("_NosePretenseThreshold")) block.SetFloat("_NosePretenseThreshold", key.NosePretenseThreshold);
|
||||
if (material.HasProperty("_CylinderBlend")) block.SetFloat("_CylinderBlend", key.CylinderBlend);
|
||||
if (material.HasProperty("_HairNormalBlend")) block.SetFloat("_HairNormalBlend", key.HairNormalBlend);
|
||||
if (material.HasProperty("_UseOriginalDirectionalLight")) block.SetFloat("_UseOriginalDirectionalLight", key.UseOriginalDirectionalLight);
|
||||
if (material.HasProperty("_OriginalDirectionalLightDir")) block.SetVector("_OriginalDirectionalLightDir", key.OriginalDirectionalLightDir);
|
||||
if (material.HasProperty("_EyeToonStep")) block.SetFloat("_EyeToonStep", key.EyeToonStep);
|
||||
if (material.HasProperty("_EyeToonFeather")) block.SetFloat("_EyeToonFeather", key.EyeToonFeather);
|
||||
if (material.HasProperty("_EyeSaturation")) block.SetFloat("_EyeSaturation", key.EyeSaturation);
|
||||
}
|
||||
renderer.SetPropertyBlock(block);
|
||||
}
|
||||
}
|
||||
|
||||
private GameObject ResolveLiveProp(int propsId)
|
||||
{
|
||||
if (_liveProps.TryGetValue(propsId, out var existing) && existing != null) return existing;
|
||||
var settings = _liveTimelineControl?.data?.propsSettings;
|
||||
if (settings?.propsDataGroup == null || propsId < 0 || propsId >= settings.propsDataGroup.Length) return null;
|
||||
var group = settings.propsDataGroup[propsId];
|
||||
if (group == null || string.IsNullOrEmpty(group.propsName) || !UmaViewerMain.Instance.AbList.TryGetValue(group.propsName, out var entry)) return null;
|
||||
var prefab = entry.Get<GameObject>();
|
||||
if (prefab == null) return null;
|
||||
var instance = Instantiate(prefab, transform);
|
||||
instance.name = prefab.name;
|
||||
_liveProps[propsId] = instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
private void OnPropsUpdate(LiveTimelinePropsData data, LiveTimelineKeyPropsData key)
|
||||
{
|
||||
if (key == null) return;
|
||||
var prop = ResolveLiveProp(key.propsID);
|
||||
if (prop == null) return;
|
||||
foreach (var renderer in prop.GetComponentsInChildren<Renderer>(true))
|
||||
{
|
||||
renderer.enabled = key.rendererEnable != 0;
|
||||
var block = PropBlock;
|
||||
renderer.GetPropertyBlock(block);
|
||||
foreach (var material in renderer.sharedMaterials)
|
||||
{
|
||||
if (material == null) continue;
|
||||
if (material.HasProperty("_Color")) block.SetColor("_Color", key.color);
|
||||
if (material.HasProperty("_RootColor")) block.SetColor("_RootColor", key.rootColor);
|
||||
if (material.HasProperty("_TipColor")) block.SetColor("_TipColor", key.tipColor);
|
||||
if (material.HasProperty("_ColorPower")) block.SetFloat("_ColorPower", key.colorPower);
|
||||
if (key.IsUpdateOutline != 0 && material.HasProperty("_OutlineWidth")) block.SetFloat("_OutlineWidth", key.OutlineWidth);
|
||||
if (key.IsUpdateOutline != 0 && material.HasProperty("_OutlineColor")) block.SetColor("_OutlineColor", key.OutlineColor);
|
||||
if (key.IsEmissive != 0 && material.HasProperty("_EmissiveColor")) block.SetColor("_EmissiveColor", key.EmissiveColor);
|
||||
}
|
||||
renderer.SetPropertyBlock(block);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPropsAttachUpdate(LiveTimelinePropsAttachData data, LiveTimelineKeyPropsAttachData key)
|
||||
{
|
||||
if (key == null) return;
|
||||
var prop = ResolveLiveProp(key._propsId);
|
||||
if (prop == null) return;
|
||||
Transform target = null;
|
||||
for (int i = 0; i < _liveTimelineControl.liveCharactorLocators.Length && target == null; i++)
|
||||
{
|
||||
if (_liveTimelineControl.liveCharactorLocators[i] is LiveTimelineCharaLocator locator &&
|
||||
locator.Bones != null && locator.Bones.TryGetValue(key._attachJointName, out var bone)) target = bone;
|
||||
}
|
||||
if (target == null) return;
|
||||
prop.transform.SetParent(target, false);
|
||||
prop.transform.localPosition = key._offsetPosition;
|
||||
prop.transform.localRotation = Quaternion.Euler(key.OffsetRotate);
|
||||
prop.transform.localScale = key.OffsetScale;
|
||||
}
|
||||
|
||||
private void OnCharaFootLightUpdate(LiveTimelineKeyCharaFootLightData key)
|
||||
{
|
||||
if (key == null) return;
|
||||
for (int i = 0; i < CharaContainerScript.Count; i++)
|
||||
{
|
||||
if (key.positionFlag != 0 && (key.positionFlag & (1 << i)) == 0) continue;
|
||||
if (i >= key.lightColor.Length || i >= key.hightMax.Length) continue;
|
||||
var container = CharaContainerScript[i];
|
||||
if (container == null) continue;
|
||||
float blend = i < key.LightBlendModeArray.Length ? key.LightBlendModeArray[i] : 0f;
|
||||
float easing = i < key.EasingArray.Length ? key.EasingArray[i] : 0f;
|
||||
var block = PropBlock;
|
||||
foreach (var renderer in container.GetComponentsInChildren<Renderer>(true))
|
||||
{
|
||||
if (renderer == null) continue;
|
||||
bool supported = false;
|
||||
foreach (var material in renderer.sharedMaterials)
|
||||
supported |= material != null && material.HasProperty("_HightLightColor") && material.HasProperty("_HightLightParam");
|
||||
if (!supported) continue;
|
||||
renderer.GetPropertyBlock(block);
|
||||
block.SetColor("_HightLightColor", key.lightColor[i]);
|
||||
block.SetVector("_HightLightParam", new Vector4(key.hightMax[i], blend, easing, 0f));
|
||||
renderer.SetPropertyBlock(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAdditionalLightUpdate(LiveTimelineAdditionalLight data, LiveTimelineKeyData_AdditionalLight key)
|
||||
{
|
||||
if (data == null || key == null) return;
|
||||
if (!_additionalLights.TryGetValue(data, out var light) || light == null)
|
||||
{
|
||||
var go = new GameObject(string.IsNullOrEmpty(data.name) ? "AdditionalLight" : data.name);
|
||||
go.transform.SetParent(_stageController != null ? _stageController.transform : transform, false);
|
||||
light = go.AddComponent<Light>();
|
||||
_additionalLights[data] = light;
|
||||
}
|
||||
light.gameObject.SetActive(key.IsEnable != 0);
|
||||
light.transform.localPosition = key.Position;
|
||||
light.transform.localRotation = Quaternion.Euler(key.Rotate);
|
||||
light.type = (LightType)Mathf.Clamp(key.Type, 0, 2);
|
||||
light.range = Mathf.Max(0f, key.Range);
|
||||
light.spotAngle = Mathf.Clamp(key.SpotAngle, 1f, 179f);
|
||||
light.intensity = Mathf.Max(0f, key.Strength);
|
||||
light.bounceIntensity = Mathf.Max(0f, key.IndirectMultiplier);
|
||||
light.shadows = (LightShadows)Mathf.Clamp(key.ShadowType, 0, 2);
|
||||
light.shadowStrength = Mathf.Clamp01(key.Strength);
|
||||
light.shadowBias = Mathf.Max(0f, key.Bias);
|
||||
light.shadowNormalBias = Mathf.Max(0f, key.NormalBias);
|
||||
light.shadowNearPlane = Mathf.Max(0.01f, key.NearPlane);
|
||||
}
|
||||
|
||||
private void OnLightProjectionUpdate(LiveTimelineLightProjectionData data, LiveTimelineKeyLightProjectionData key)
|
||||
{
|
||||
if (data == null || key == null || _stageController == null) return;
|
||||
if (!_projectionLights.TryGetValue(data, out var light) || light == null)
|
||||
{
|
||||
CustomProjector authored = null;
|
||||
foreach (var candidate in _stageController.GetComponentsInChildren<CustomProjector>(true))
|
||||
{
|
||||
if (candidate != null && string.Equals(candidate.name, data.name, StringComparison.OrdinalIgnoreCase))
|
||||
{ authored = candidate; break; }
|
||||
}
|
||||
var host = authored != null ? authored.gameObject : new GameObject(data.name ?? "LightProjection");
|
||||
if (authored == null) host.transform.SetParent(_stageController.transform, false);
|
||||
light = host.GetComponent<Light>();
|
||||
if (light == null) light = host.AddComponent<Light>();
|
||||
light.type = LightType.Spot;
|
||||
if (authored != null) light.cookie = authored.ProjectionTexture;
|
||||
_projectionLights[data] = light;
|
||||
}
|
||||
|
||||
light.gameObject.SetActive(key.IsEnable != 0);
|
||||
light.transform.localPosition = key.Position;
|
||||
light.transform.localRotation = Quaternion.Euler(key.Angle);
|
||||
light.transform.localScale = key.Scale;
|
||||
light.range = Mathf.Max(0.01f, key.FarClipPlane);
|
||||
light.spotAngle = Mathf.Clamp(key.FieldOfView, 1f, 179f);
|
||||
light.color = key.Color;
|
||||
light.intensity = Mathf.Max(0f, key.ColorPower * key.BlinkLightBrightnessPower);
|
||||
light.shadowNearPlane = Mathf.Max(0.01f, key.NearClipPlane);
|
||||
if (key.OverrideIgnoreLayer != 0) light.cullingMask = key.OverrideLayerMask.value;
|
||||
}
|
||||
|
||||
private static GameObject LoadEffectPrefab(string effectName)
|
||||
{
|
||||
string path = string.Format(EFFECT_PATH, effectName);
|
||||
@@ -1311,9 +1558,15 @@ namespace Gallop.Live
|
||||
|
||||
private void UpdateMainCamera()
|
||||
{
|
||||
if (_cameraObjects == null) return;
|
||||
if (_cameraObjects == null || _cameraNodes == null || _cameraTransforms == null) return;
|
||||
if (_freeCameraActive && _freeCamera != null)
|
||||
{
|
||||
_mainCameraTransform = _freeCamera.transform;
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < _cameraNodes.Length; i++)
|
||||
{
|
||||
if (_cameraNodes[i] == null) continue;
|
||||
bool activeSelf = _cameraNodes[i].activeSelf;
|
||||
bool flag = i == _activeCameraIndex;
|
||||
_cameraNodes[i].SetActive(flag);
|
||||
@@ -1322,7 +1575,77 @@ namespace Gallop.Live
|
||||
_cameraLookAt.ActivationUpdate();
|
||||
}
|
||||
}
|
||||
_mainCameraTransform = _cameraTransforms[_activeCameraIndex];
|
||||
if (_activeCameraIndex >= 0 && _activeCameraIndex < _cameraTransforms.Length)
|
||||
_mainCameraTransform = _cameraTransforms[_activeCameraIndex];
|
||||
}
|
||||
|
||||
public void SetPlaybackPaused(bool paused)
|
||||
{
|
||||
if (_playbackPaused == paused || IsRecordVMD)
|
||||
return;
|
||||
|
||||
_playbackPaused = paused;
|
||||
SetAudioPaused(liveMusic, paused);
|
||||
foreach (var vocal in liveVocal)
|
||||
SetAudioPaused(vocal, paused);
|
||||
}
|
||||
|
||||
public void SeekPlayback(float time)
|
||||
{
|
||||
_liveCurrentTime = Mathf.Clamp(time, 0f, Mathf.Max(0f, totalTime - 0.001f));
|
||||
UI.ProgressBar.SetValueWithoutNotify(totalTime > 0f ? _liveCurrentTime / totalTime : 0f);
|
||||
if (liveMusic != null && liveMusic.sourceList != null)
|
||||
UmaViewerAudio.SetTime(liveMusic, _liveCurrentTime);
|
||||
foreach (var vocal in liveVocal)
|
||||
if (vocal != null && vocal.sourceList != null)
|
||||
UmaViewerAudio.SetTime(vocal, _liveCurrentTime);
|
||||
OnTimelineUpdate(_liveCurrentTime);
|
||||
if (_liveTimelineControl != null)
|
||||
_liveTimelineControl.AlterLateUpdate();
|
||||
_syncTime = !_playbackPaused;
|
||||
}
|
||||
|
||||
public void SetFreeCameraEnabled(bool enabled)
|
||||
{
|
||||
if (_freeCameraActive == enabled)
|
||||
return;
|
||||
|
||||
if (_freeCamera == null)
|
||||
_freeCamera = Resources.FindObjectsOfTypeAll<FreeCam>().FirstOrDefault(cam => cam.gameObject.scene.IsValid());
|
||||
if (_freeCamera == null)
|
||||
return;
|
||||
|
||||
_freeCameraActive = enabled;
|
||||
if (enabled)
|
||||
{
|
||||
Transform source = _cameraTransforms != null && _activeCameraIndex >= 0 && _activeCameraIndex < _cameraTransforms.Length
|
||||
? _cameraTransforms[_activeCameraIndex] : null;
|
||||
if (source != null)
|
||||
_freeCamera.transform.SetPositionAndRotation(source.position, source.rotation);
|
||||
_freeCamera.gameObject.SetActive(true);
|
||||
if (_cameraNodes != null)
|
||||
{
|
||||
for (int i = 0; i < _cameraNodes.Length; i++)
|
||||
if (_cameraNodes[i] != null) _cameraNodes[i].SetActive(false);
|
||||
}
|
||||
_mainCameraTransform = _freeCamera.transform;
|
||||
}
|
||||
else
|
||||
{
|
||||
_freeCamera.gameObject.SetActive(false);
|
||||
UpdateMainCamera();
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetAudioPaused(UmaViewerAudio.CuteAudioSource source, bool paused)
|
||||
{
|
||||
if (source == null || source.sourceList == null)
|
||||
return;
|
||||
foreach (var audioSource in source.sourceList)
|
||||
{
|
||||
if (paused) audioSource.Pause();
|
||||
else audioSource.UnPause();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupCharacterLocator()
|
||||
@@ -1371,6 +1694,13 @@ namespace Gallop.Live
|
||||
public void Play()
|
||||
{
|
||||
|
||||
// Play can be invoked after scene/UI setup has been rebuilt; ensure the
|
||||
// debugging overlay exists and is enabled for the whole playback.
|
||||
LivePlaybackToolbar toolbar = GetComponent<LivePlaybackToolbar>();
|
||||
if (toolbar == null)
|
||||
toolbar = gameObject.AddComponent<LivePlaybackToolbar>();
|
||||
toolbar.enabled = true;
|
||||
|
||||
foreach (var vocal in liveVocal)
|
||||
{
|
||||
UmaViewerAudio.Play(vocal);
|
||||
@@ -1448,6 +1778,10 @@ namespace Gallop.Live
|
||||
OnTimelineUpdate(_liveCurrentTime);
|
||||
_liveTimelineControl.AlterLateUpdate();
|
||||
}
|
||||
else if (_playbackPaused)
|
||||
{
|
||||
// The toolbar can still seek while paused; the timeline itself remains frozen.
|
||||
}
|
||||
else if (sliderControl.is_Outed)
|
||||
{
|
||||
_liveCurrentTime = UI.ProgressBar.value * totalTime;
|
||||
@@ -1612,4 +1946,4 @@ namespace Gallop.Live
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gallop.Live
|
||||
{
|
||||
/// <summary>Always-visible live debugging controls independent of the scene's auto-hidden UI.</summary>
|
||||
public sealed class LivePlaybackToolbar : MonoBehaviour
|
||||
{
|
||||
private bool _draggingTimeline;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Director.instance == null || !Director.instance._isLiveSetup)
|
||||
return;
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
Director.instance.SetPlaybackPaused(!Director.instance.PlaybackPaused);
|
||||
if (Input.GetKeyDown(KeyCode.F6))
|
||||
Director.instance.SetFreeCameraEnabled(!Director.instance.FreeCameraActive);
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
Director director = Director.instance;
|
||||
if (director == null || !director._isLiveSetup)
|
||||
return;
|
||||
|
||||
// Keep this overlay above the scene's Canvas/UI, which may cover the lower edge.
|
||||
int oldDepth = GUI.depth;
|
||||
GUI.depth = 1000;
|
||||
GUILayout.BeginArea(new Rect(16, Mathf.Max(8, Screen.height - 68), 560, 52), GUI.skin.window);
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
if (GUILayout.Button(director.PlaybackPaused ? "Play" : "Pause", GUILayout.Width(62)))
|
||||
director.SetPlaybackPaused(!director.PlaybackPaused);
|
||||
|
||||
bool freeCamera = GUILayout.Toggle(director.FreeCameraActive, "Free Camera", GUILayout.Width(105));
|
||||
if (freeCamera != director.FreeCameraActive)
|
||||
director.SetFreeCameraEnabled(freeCamera);
|
||||
|
||||
float time = GUILayout.HorizontalSlider(director._liveCurrentTime, 0f, Mathf.Max(0.01f, director.totalTime), GUILayout.Width(245));
|
||||
Rect sliderRect = GUILayoutUtility.GetLastRect();
|
||||
Event currentEvent = Event.current;
|
||||
if (currentEvent.type == EventType.MouseDown && sliderRect.Contains(currentEvent.mousePosition))
|
||||
_draggingTimeline = true;
|
||||
if (_draggingTimeline && (currentEvent.type == EventType.MouseDrag || currentEvent.type == EventType.MouseDown))
|
||||
director.SeekPlayback(time);
|
||||
if (currentEvent.type == EventType.MouseUp)
|
||||
_draggingTimeline = false;
|
||||
|
||||
GUILayout.Label(director._liveCurrentTime.ToString("0.00") + " / " + director.totalTime.ToString("0.00"), GUILayout.Width(84));
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.EndArea();
|
||||
GUI.depth = oldDepth;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5307220bda8922d4ea2911ec6f0dd3e1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b86c3dce210ee2e4bbd36c6c48abfccb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b3a700e79167fe49bb840bdda6f8d34
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,2 @@
|
||||
// Kept intentionally empty so stale Unity-generated project files that referenced the
|
||||
// superseded temporary driver remain buildable until Unity regenerates the project.
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3049c310353c9934a8b7c3f938f32bfc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56c2bfe19657a4c4bb1708407b98fa28
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,357 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gallop.Live
|
||||
{
|
||||
/// <summary>Runtime tuning for hair, cloth, tail, and accessory spring motion.</summary>
|
||||
public sealed class SkirtCollisionRuntimeTuner : MonoBehaviour
|
||||
{
|
||||
private enum MotionCategory
|
||||
{
|
||||
Skirt,
|
||||
Other
|
||||
}
|
||||
|
||||
private sealed class ParticleDefaults
|
||||
{
|
||||
public DynamicBone.Particle Particle;
|
||||
public MotionCategory Category;
|
||||
public float Damping;
|
||||
public float Elasticity;
|
||||
public float Stiffness;
|
||||
public float Inert;
|
||||
}
|
||||
|
||||
private sealed class ColliderDefaults
|
||||
{
|
||||
public DynamicBoneCollider Collider;
|
||||
public float Radius;
|
||||
}
|
||||
|
||||
private readonly List<ParticleDefaults> _particles = new List<ParticleDefaults>();
|
||||
private readonly HashSet<DynamicBone.Particle> _knownParticles = new HashSet<DynamicBone.Particle>();
|
||||
private readonly List<ColliderDefaults> _hipColliders = new List<ColliderDefaults>();
|
||||
private readonly HashSet<DynamicBoneCollider> _knownHipColliders = new HashSet<DynamicBoneCollider>();
|
||||
private readonly List<ColliderDefaults> _legColliders = new List<ColliderDefaults>();
|
||||
private readonly HashSet<DynamicBoneCollider> _knownLegColliders = new HashSet<DynamicBoneCollider>();
|
||||
private bool _visible;
|
||||
private bool _initialized;
|
||||
private float _dampingScale = 3f;
|
||||
private float _elasticityScale = 1.5f;
|
||||
private float _stiffnessScale = 2f;
|
||||
private float _inertScale = 1.1f;
|
||||
private float _hipRadiusScale = 0.2f;
|
||||
private float _legRadiusScale = 0.8f;
|
||||
private float _horizontalStiffness = 0.5f;
|
||||
private float _otherDampingScale = 3f;
|
||||
private float _otherElasticityScale = 1.5f;
|
||||
private float _otherStiffnessScale = 2f;
|
||||
private float _otherInertScale = 1.1f;
|
||||
private float _otherRigidity = 0.85f;
|
||||
private float _monitorBrightness = 1f;
|
||||
private bool _showSkirtColliders;
|
||||
private bool _skirtBodyCollisionEnabled = true;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.F8))
|
||||
_visible = !_visible;
|
||||
|
||||
if (Director.instance == null || Director.instance.CharaContainerScript.Count == 0)
|
||||
return;
|
||||
|
||||
bool added = false;
|
||||
bool addedCollider = false;
|
||||
foreach (UmaContainerCharacter character in Director.instance.CharaContainerScript)
|
||||
{
|
||||
if (character == null)
|
||||
continue;
|
||||
|
||||
foreach (DynamicBone dynamicBone in character.GetComponentsInChildren<DynamicBone>(true))
|
||||
{
|
||||
MotionCategory category = GetMotionCategory(dynamicBone);
|
||||
foreach (DynamicBone.Particle particle in dynamicBone.Particles)
|
||||
{
|
||||
if (!_knownParticles.Add(particle))
|
||||
continue;
|
||||
|
||||
_particles.Add(new ParticleDefaults
|
||||
{
|
||||
Particle = particle,
|
||||
Category = category,
|
||||
Damping = particle.m_Damping,
|
||||
Elasticity = particle.m_Elasticity,
|
||||
Stiffness = particle.m_Stiffness,
|
||||
Inert = particle.m_Inert
|
||||
});
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (DynamicBoneCollider collider in character.GetComponentsInChildren<DynamicBoneCollider>(true))
|
||||
{
|
||||
if (IsHipSkirtCollider(collider) && _knownHipColliders.Add(collider))
|
||||
{
|
||||
_hipColliders.Add(new ColliderDefaults
|
||||
{
|
||||
Collider = collider,
|
||||
Radius = collider.m_Radius
|
||||
});
|
||||
addedCollider = true;
|
||||
}
|
||||
if (IsLegSkirtCollider(collider) && _knownLegColliders.Add(collider))
|
||||
{
|
||||
_legColliders.Add(new ColliderDefaults
|
||||
{
|
||||
Collider = collider,
|
||||
Radius = collider.m_Radius
|
||||
});
|
||||
addedCollider = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_initialized = _particles.Count > 0;
|
||||
if (added || addedCollider)
|
||||
Apply();
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (!_visible || !_initialized)
|
||||
return;
|
||||
|
||||
GUILayout.BeginArea(new Rect(16, 16, 430, 720), GUI.skin.window);
|
||||
GUILayout.Label("Secondary Motion Tuning");
|
||||
|
||||
bool changed = false;
|
||||
changed |= SliderRow("Damping", ref _dampingScale, 0.25f, 4f);
|
||||
changed |= SliderRow("Elasticity", ref _elasticityScale, 0f, 1.5f);
|
||||
changed |= SliderRow("Stiffness", ref _stiffnessScale, 0.25f, 2f);
|
||||
changed |= SliderRow("Inertia", ref _inertScale, 0f, 1.5f);
|
||||
changed |= SliderRow("Hip radius", ref _hipRadiusScale, 0.1f, 1.5f);
|
||||
changed |= SliderRow("Leg radius", ref _legRadiusScale, 0.5f, 1.5f);
|
||||
changed |= SliderRow("Horizontal stiffness", ref _horizontalStiffness, 0f, 1f);
|
||||
|
||||
GUILayout.Space(5);
|
||||
GUILayout.Label("All non-skirt physics (relative to skirt base)");
|
||||
changed |= SliderRow("Other damping", ref _otherDampingScale, 0.25f, 4f);
|
||||
changed |= SliderRow("Other elasticity", ref _otherElasticityScale, 0f, 1.5f);
|
||||
changed |= SliderRow("Other stiffness", ref _otherStiffnessScale, 0.25f, 2f);
|
||||
changed |= SliderRow("Other inertia", ref _otherInertScale, 0f, 1.5f);
|
||||
changed |= SliderRow("Other rigidity", ref _otherRigidity, 0f, 1f);
|
||||
|
||||
GUILayout.Space(5);
|
||||
GUILayout.Label("Live display");
|
||||
changed |= SliderRow("Screen brightness", ref _monitorBrightness, 0f, 1.5f);
|
||||
|
||||
if (GUILayout.Button("Restore defaults", GUILayout.Width(165)))
|
||||
{
|
||||
_dampingScale = 3f;
|
||||
_elasticityScale = 1.5f;
|
||||
_stiffnessScale = 2f;
|
||||
_inertScale = 1.1f;
|
||||
_hipRadiusScale = 0.2f;
|
||||
_legRadiusScale = 0.8f;
|
||||
_horizontalStiffness = 0.5f;
|
||||
_otherDampingScale = 3f;
|
||||
_otherElasticityScale = 1.5f;
|
||||
_otherStiffnessScale = 2f;
|
||||
_otherInertScale = 1.1f;
|
||||
_otherRigidity = 0.85f;
|
||||
_monitorBrightness = 1f;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
Apply();
|
||||
|
||||
bool showColliders = GUILayout.Toggle(_showSkirtColliders, "Show skirt colliders");
|
||||
if (showColliders != _showSkirtColliders)
|
||||
{
|
||||
_showSkirtColliders = showColliders;
|
||||
foreach (SkirtCollisionVisualizer visualizer in Object.FindObjectsOfType<SkirtCollisionVisualizer>(true))
|
||||
visualizer.SetVisible(_showSkirtColliders);
|
||||
}
|
||||
|
||||
bool bodyCollisionEnabled = GUILayout.Toggle(_skirtBodyCollisionEnabled, "Enable skirt body collision");
|
||||
if (bodyCollisionEnabled != _skirtBodyCollisionEnabled)
|
||||
{
|
||||
_skirtBodyCollisionEnabled = bodyCollisionEnabled;
|
||||
SetSkirtBodyCollisionEnabled(_skirtBodyCollisionEnabled);
|
||||
}
|
||||
|
||||
UmaContainerCharacter firstCharacter = Director.instance.CharaContainerScript[0];
|
||||
SkirtSurfaceCollisionSolver solver = firstCharacter != null
|
||||
? firstCharacter.GetComponent<SkirtSurfaceCollisionSolver>() : null;
|
||||
GUILayout.Label(solver != null
|
||||
? "Skirt rings: " + solver.RingCount + " colliders: " + solver.ColliderCount +
|
||||
" contacts: " + solver.LastContactCount
|
||||
: "Skirt surface solver: not initialized");
|
||||
if (firstCharacter != null)
|
||||
{
|
||||
foreach (DynamicBoneCollider collider in firstCharacter.GetComponentsInChildren<DynamicBoneCollider>(true))
|
||||
{
|
||||
if (!IsBodySkirtCollider(collider))
|
||||
continue;
|
||||
|
||||
GUILayout.Label(collider.ColliderName + " r=" + collider.m_Radius.ToString("0.000") +
|
||||
" h=" + collider.m_Height.ToString("0.000"));
|
||||
}
|
||||
}
|
||||
GUILayout.Label("F8: close");
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
private static bool SliderRow(string label, ref float value, float min, float max)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label(label, GUILayout.Width(105));
|
||||
float updated = GUILayout.HorizontalSlider(value, min, max, GUILayout.Width(165));
|
||||
GUILayout.Label(updated.ToString("0.00") + "x", GUILayout.Width(55));
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
bool changed = !Mathf.Approximately(value, updated);
|
||||
value = updated;
|
||||
return changed;
|
||||
}
|
||||
|
||||
private void Apply()
|
||||
{
|
||||
foreach (ParticleDefaults defaults in _particles)
|
||||
{
|
||||
DynamicBone.Particle particle = defaults.Particle;
|
||||
if (particle == null)
|
||||
continue;
|
||||
|
||||
float categoryDamping = 1f;
|
||||
float categoryElasticity = 1f;
|
||||
float categoryStiffness = 1f;
|
||||
float categoryInert = 1f;
|
||||
if (defaults.Category == MotionCategory.Other)
|
||||
{
|
||||
categoryDamping = _otherDampingScale;
|
||||
categoryElasticity = _otherElasticityScale;
|
||||
categoryStiffness = _otherStiffnessScale;
|
||||
categoryInert = _otherInertScale;
|
||||
}
|
||||
|
||||
particle.m_Damping = Mathf.Clamp01(defaults.Damping * _dampingScale * categoryDamping);
|
||||
particle.m_Elasticity = Mathf.Clamp01(defaults.Elasticity * _elasticityScale * categoryElasticity);
|
||||
particle.m_Stiffness = Mathf.Clamp01(defaults.Stiffness * _stiffnessScale * categoryStiffness);
|
||||
particle.m_Inert = Mathf.Clamp01(defaults.Inert * _inertScale * categoryInert);
|
||||
|
||||
if (defaults.Category == MotionCategory.Other && _otherRigidity > 0f)
|
||||
{
|
||||
// Multipliers alone cannot make a low-value source spring rigid.
|
||||
// This is a direct, non-skirt constraint preset: high damping and
|
||||
// stiffness, with limited rebound and body-motion lag.
|
||||
particle.m_Damping = Mathf.Max(particle.m_Damping, Mathf.Lerp(0f, 0.9f, _otherRigidity));
|
||||
particle.m_Stiffness = Mathf.Max(particle.m_Stiffness, Mathf.Lerp(0f, 0.98f, _otherRigidity));
|
||||
particle.m_Elasticity = Mathf.Min(particle.m_Elasticity, Mathf.Lerp(1f, 0.05f, _otherRigidity));
|
||||
particle.m_Inert = Mathf.Min(particle.m_Inert, Mathf.Lerp(1f, 0f, _otherRigidity));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ColliderDefaults defaults in _hipColliders)
|
||||
{
|
||||
if (defaults.Collider != null)
|
||||
defaults.Collider.m_Radius = defaults.Radius * _hipRadiusScale;
|
||||
}
|
||||
|
||||
foreach (ColliderDefaults defaults in _legColliders)
|
||||
{
|
||||
if (defaults.Collider != null)
|
||||
defaults.Collider.m_Radius = defaults.Radius * _legRadiusScale;
|
||||
}
|
||||
|
||||
if (Director.instance == null)
|
||||
return;
|
||||
|
||||
foreach (UmaContainerCharacter character in Director.instance.CharaContainerScript)
|
||||
{
|
||||
if (character == null)
|
||||
continue;
|
||||
|
||||
SkirtSurfaceCollisionSolver solver = character.GetComponent<SkirtSurfaceCollisionSolver>();
|
||||
if (solver != null)
|
||||
solver.HorizontalStiffness = _horizontalStiffness;
|
||||
}
|
||||
|
||||
foreach (StageMonitorDriver monitorDriver in Object.FindObjectsOfType<StageMonitorDriver>(true))
|
||||
monitorDriver.brightnessMultiplier = _monitorBrightness;
|
||||
}
|
||||
|
||||
private void SetSkirtBodyCollisionEnabled(bool enabled)
|
||||
{
|
||||
foreach (UmaContainerCharacter character in Director.instance.CharaContainerScript)
|
||||
{
|
||||
if (character == null)
|
||||
continue;
|
||||
|
||||
foreach (DynamicBoneCollider collider in character.GetComponentsInChildren<DynamicBoneCollider>(true))
|
||||
{
|
||||
if (IsBodySkirtCollider(collider))
|
||||
collider.enabled = enabled;
|
||||
}
|
||||
|
||||
SkirtSurfaceCollisionSolver solver = character.GetComponent<SkirtSurfaceCollisionSolver>();
|
||||
if (solver != null)
|
||||
solver.enabled = enabled;
|
||||
character.ResetDynamicBone();
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsBodySkirtCollider(DynamicBoneCollider collider)
|
||||
{
|
||||
if (collider == null || string.IsNullOrEmpty(collider.ColliderName) ||
|
||||
collider.ColliderName.IndexOf("Skirt", System.StringComparison.OrdinalIgnoreCase) < 0)
|
||||
return false;
|
||||
|
||||
if (collider.ColliderName.IndexOf("Thigh", System.StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
return true;
|
||||
|
||||
bool isSideHip = collider.ColliderName.EndsWith("_L", System.StringComparison.OrdinalIgnoreCase) ||
|
||||
collider.ColliderName.EndsWith("_R", System.StringComparison.OrdinalIgnoreCase);
|
||||
return collider.ColliderName.IndexOf("Hip", System.StringComparison.OrdinalIgnoreCase) >= 0 &&
|
||||
isSideHip && collider.m_Radius <= 0.25f;
|
||||
}
|
||||
|
||||
private static bool IsHipSkirtCollider(DynamicBoneCollider collider)
|
||||
{
|
||||
return collider != null && collider.ColliderName != null &&
|
||||
collider.ColliderName.IndexOf("Hip", System.StringComparison.OrdinalIgnoreCase) >= 0 &&
|
||||
collider.ColliderName.IndexOf("Skirt", System.StringComparison.OrdinalIgnoreCase) >= 0 &&
|
||||
(collider.ColliderName.EndsWith("_L", System.StringComparison.OrdinalIgnoreCase) ||
|
||||
collider.ColliderName.EndsWith("_R", System.StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private static bool IsLegSkirtCollider(DynamicBoneCollider collider)
|
||||
{
|
||||
return collider != null && collider.ColliderName != null &&
|
||||
collider.ColliderName.IndexOf("Thigh", System.StringComparison.OrdinalIgnoreCase) >= 0 &&
|
||||
collider.ColliderName.IndexOf("MSkirt", System.StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
}
|
||||
|
||||
private static MotionCategory GetMotionCategory(DynamicBone dynamicBone)
|
||||
{
|
||||
string name = GetMotionName(dynamicBone);
|
||||
return dynamicBone != null && (dynamicBone.m_ContinuousCollision ||
|
||||
name.IndexOf("Skirt", System.StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
? MotionCategory.Skirt : MotionCategory.Other;
|
||||
}
|
||||
|
||||
private static string GetMotionName(DynamicBone dynamicBone)
|
||||
{
|
||||
string name = dynamicBone != null && dynamicBone.m_Root != null
|
||||
? dynamicBone.m_Root.name : string.Empty;
|
||||
for (Transform transform = dynamicBone != null ? dynamicBone.transform.parent : null;
|
||||
transform != null; transform = transform.parent)
|
||||
{
|
||||
name += "/" + transform.name;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65925dd2ac8aec44a9998f1d12dd2b2d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -57,6 +57,20 @@ namespace Gallop
|
||||
private static readonly int kReflectionRate = Shader.PropertyToID("_ReflectionRate");
|
||||
private static readonly int kColor = Shader.PropertyToID("_Color");
|
||||
|
||||
public void ApplyTimeline(bool valid, bool enabled, float reflectionRate)
|
||||
{
|
||||
if (!valid) return;
|
||||
_mirrorReflectionRate = Mathf.Max(0f, reflectionRate);
|
||||
this.enabled = enabled;
|
||||
if (_renderer != null)
|
||||
{
|
||||
_block ??= new MaterialPropertyBlock();
|
||||
_renderer.GetPropertyBlock(_block);
|
||||
_block.SetFloat(kReflectionRate, _mirrorReflectionRate);
|
||||
_renderer.SetPropertyBlock(_block);
|
||||
}
|
||||
}
|
||||
|
||||
// URP 下不能用 Camera.Render()(SRP 会直接报错、什么都不画),
|
||||
// 必须挂 beginCameraRendering 拿到 ScriptableRenderContext 再 RenderSingleCamera。
|
||||
private void OnEnable() => RenderPipelineManager.beginCameraRendering += OnBeginCamera;
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace Gallop.RenderPipeline
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class CustomProjector : MonoBehaviour
|
||||
{
|
||||
public float _nearClipPlane = 0.1f;
|
||||
public float _farClipPlane = 60f;
|
||||
public float _fieldOfView = 30f;
|
||||
public float _aspectRatio = 1f;
|
||||
public Material _material;
|
||||
|
||||
public Texture ProjectionTexture
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_material == null) return null;
|
||||
string[] names = { "_MainTex", "_BaseMap", "_ProjectionTex" };
|
||||
foreach (string name in names)
|
||||
if (_material.HasProperty(name) && _material.GetTexture(name) != null) return _material.GetTexture(name);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LensFlareElement
|
||||
{
|
||||
public int ImageIndex;
|
||||
public float Position;
|
||||
public float Size = 1f;
|
||||
public Color Color = Color.white;
|
||||
public bool UseLightColor;
|
||||
public bool Rotate;
|
||||
public bool Zoom;
|
||||
public bool Fade;
|
||||
}
|
||||
|
||||
public class LensFlareData : ScriptableObject
|
||||
{
|
||||
public int TextureLayout;
|
||||
public Texture2D Texture;
|
||||
public LensFlareElement[] ElementArray = Array.Empty<LensFlareElement>();
|
||||
public bool UseFog;
|
||||
}
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
public class CustomLensFlare : MonoBehaviour
|
||||
{
|
||||
public LensFlareData Flare;
|
||||
public float Brightness = 1f;
|
||||
public float FadeSpeed = 1f;
|
||||
public Color Color = Color.white;
|
||||
public LayerMask IgnoreLayers;
|
||||
public bool IsDirectional;
|
||||
|
||||
private LensFlareComponentSRP _component;
|
||||
private LensFlareDataSRP _runtimeData;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
BuildRuntimeFlare();
|
||||
ApplyRuntimeParameters();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (_component != null) _component.enabled = false;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_runtimeData != null) Destroy(_runtimeData);
|
||||
}
|
||||
|
||||
public void ApplyTimeline(bool enabled, Vector3 offset, Color color, float brightness, float fadeSpeed)
|
||||
{
|
||||
if (_component == null || _runtimeData == null) BuildRuntimeFlare();
|
||||
transform.localPosition = offset;
|
||||
Color = color;
|
||||
Brightness = Mathf.Max(0f, brightness);
|
||||
FadeSpeed = Mathf.Max(0f, fadeSpeed);
|
||||
ApplyRuntimeParameters();
|
||||
if (_component != null) _component.enabled = enabled;
|
||||
}
|
||||
|
||||
private void BuildRuntimeFlare()
|
||||
{
|
||||
if (Flare == null) return;
|
||||
_component = GetComponent<LensFlareComponentSRP>();
|
||||
if (_component == null) _component = gameObject.AddComponent<LensFlareComponentSRP>();
|
||||
|
||||
if (_runtimeData != null) Destroy(_runtimeData);
|
||||
_runtimeData = ScriptableObject.CreateInstance<LensFlareDataSRP>();
|
||||
|
||||
var source = Flare.ElementArray ?? Array.Empty<LensFlareElement>();
|
||||
var elements = new LensFlareDataElementSRP[source.Length];
|
||||
for (int i = 0; i < source.Length; i++)
|
||||
{
|
||||
LensFlareElement item = source[i] ?? new LensFlareElement();
|
||||
var element = new LensFlareDataElementSRP
|
||||
{
|
||||
flareType = SRPLensFlareType.Image,
|
||||
lensFlareTexture = Flare.Texture,
|
||||
position = item.Position,
|
||||
uniformScale = Mathf.Max(0.001f, item.Size),
|
||||
sizeXY = Vector2.one,
|
||||
tint = item.Color,
|
||||
autoRotate = item.Rotate,
|
||||
modulateByLightColor = item.UseLightColor,
|
||||
blendMode = SRPLensFlareBlendMode.Additive,
|
||||
preserveAspectRatio = true
|
||||
};
|
||||
elements[i] = element;
|
||||
}
|
||||
|
||||
_runtimeData.elements = elements;
|
||||
_component.lensFlareData = _runtimeData;
|
||||
_component.useOcclusion = true;
|
||||
_component.allowOffScreen = false;
|
||||
_component.attenuationByLightShape = false;
|
||||
}
|
||||
|
||||
private void ApplyRuntimeParameters()
|
||||
{
|
||||
if (_component == null || _runtimeData == null) return;
|
||||
_component.intensity = Mathf.Max(0f, Brightness);
|
||||
for (int i = 0; i < _runtimeData.elements.Length; i++)
|
||||
{
|
||||
LensFlareElement source = Flare != null && Flare.ElementArray != null && i < Flare.ElementArray.Length
|
||||
? Flare.ElementArray[i]
|
||||
: null;
|
||||
Color sourceColor = source != null ? source.Color : UnityEngine.Color.white;
|
||||
_runtimeData.elements[i].tint = sourceColor * Color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da09622a71394244b822f4f9d136b344
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,128 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>Runtime wireframe display for generated skirt collision volumes.</summary>
|
||||
public sealed class SkirtCollisionVisualizer : MonoBehaviour
|
||||
{
|
||||
private const int Segments = 24;
|
||||
private readonly List<LineRenderer> _lines = new List<LineRenderer>();
|
||||
private DynamicBoneCollider _collider;
|
||||
private bool _visible;
|
||||
private float _lastRadius = -1f;
|
||||
private float _lastHeight = -1f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_collider = GetComponent<DynamicBoneCollider>();
|
||||
CreateLines();
|
||||
SetVisible(false);
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (_visible && _collider != null &&
|
||||
(!Mathf.Approximately(_lastRadius, _collider.m_Radius) ||
|
||||
!Mathf.Approximately(_lastHeight, _collider.m_Height)))
|
||||
UpdateGeometry();
|
||||
}
|
||||
|
||||
public void SetVisible(bool visible)
|
||||
{
|
||||
_visible = visible;
|
||||
foreach (LineRenderer line in _lines)
|
||||
line.enabled = visible;
|
||||
if (visible)
|
||||
UpdateGeometry();
|
||||
}
|
||||
|
||||
private void CreateLines()
|
||||
{
|
||||
Color color = name.Contains("Hip") ? new Color(1f, 0.35f, 0.2f) : new Color(0.2f, 0.85f, 1f);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
GameObject lineObject = new GameObject("Wire");
|
||||
lineObject.transform.SetParent(transform, false);
|
||||
LineRenderer line = lineObject.AddComponent<LineRenderer>();
|
||||
line.useWorldSpace = false;
|
||||
line.loop = i < 3;
|
||||
line.widthMultiplier = 0.006f;
|
||||
line.numCornerVertices = 2;
|
||||
line.numCapVertices = 2;
|
||||
line.material = SkirtCollisionWireMaterial.Instance;
|
||||
line.startColor = color;
|
||||
line.endColor = color;
|
||||
_lines.Add(line);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateGeometry()
|
||||
{
|
||||
if (_collider == null)
|
||||
return;
|
||||
|
||||
float radius = _collider.m_Radius;
|
||||
_lastRadius = radius;
|
||||
_lastHeight = _collider.m_Height;
|
||||
float halfSegment = Mathf.Max(0f, _collider.m_Height * 0.5f - radius);
|
||||
if (halfSegment == 0f)
|
||||
{
|
||||
SetCircle(_lines[0], radius, 0f, 0);
|
||||
SetCircle(_lines[1], radius, 0f, 1);
|
||||
SetCircle(_lines[2], radius, 0f, 2);
|
||||
for (int i = 3; i < _lines.Count; i++)
|
||||
_lines[i].positionCount = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
SetCircle(_lines[0], radius, -halfSegment, 0);
|
||||
SetCircle(_lines[1], radius, halfSegment, 0);
|
||||
_lines[2].positionCount = 0;
|
||||
SetLine(_lines[3], new Vector3(radius, 0f, -halfSegment), new Vector3(radius, 0f, halfSegment));
|
||||
SetLine(_lines[4], new Vector3(-radius, 0f, -halfSegment), new Vector3(-radius, 0f, halfSegment));
|
||||
SetLine(_lines[5], new Vector3(0f, radius, -halfSegment), new Vector3(0f, radius, halfSegment));
|
||||
}
|
||||
|
||||
private static void SetCircle(LineRenderer line, float radius, float axisOffset, int plane)
|
||||
{
|
||||
line.positionCount = Segments;
|
||||
for (int i = 0; i < Segments; i++)
|
||||
{
|
||||
float angle = Mathf.PI * 2f * i / Segments;
|
||||
float a = Mathf.Cos(angle) * radius;
|
||||
float b = Mathf.Sin(angle) * radius;
|
||||
switch (plane)
|
||||
{
|
||||
case 0: line.SetPosition(i, new Vector3(a, b, axisOffset)); break;
|
||||
case 1: line.SetPosition(i, new Vector3(a, axisOffset, b)); break;
|
||||
default: line.SetPosition(i, new Vector3(axisOffset, a, b)); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetLine(LineRenderer line, Vector3 from, Vector3 to)
|
||||
{
|
||||
line.positionCount = 2;
|
||||
line.SetPosition(0, from);
|
||||
line.SetPosition(1, to);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class SkirtCollisionWireMaterial
|
||||
{
|
||||
private static Material _instance;
|
||||
|
||||
public static Material Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
Shader shader = Shader.Find("Universal Render Pipeline/Unlit");
|
||||
if (shader == null)
|
||||
shader = Shader.Find("Sprites/Default");
|
||||
_instance = new Material(shader);
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc01f9558187f96469b7bd90a47e5ebc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Keeps a DynamicBone capsule aligned with the animated hip-to-knee segment.
|
||||
/// </summary>
|
||||
[DefaultExecutionOrder(-1000)]
|
||||
public sealed class SkirtLegCollisionProxy : MonoBehaviour
|
||||
{
|
||||
public Transform StartBone;
|
||||
public Transform EndBone;
|
||||
public DynamicBoneCollider Collider;
|
||||
public float RadiusScale;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdateColliderTransform();
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
// Refresh after the character animation has written the current leg pose,
|
||||
// before DynamicBone performs its late-frame collision solve.
|
||||
UpdateColliderTransform();
|
||||
}
|
||||
|
||||
public void UpdateColliderTransform()
|
||||
{
|
||||
if (StartBone == null || EndBone == null || Collider == null)
|
||||
return;
|
||||
|
||||
Vector3 segment = EndBone.position - StartBone.position;
|
||||
float length = segment.magnitude;
|
||||
if (length <= Mathf.Epsilon)
|
||||
return;
|
||||
|
||||
transform.SetPositionAndRotation(
|
||||
StartBone.position + segment * 0.5f,
|
||||
Quaternion.LookRotation(segment));
|
||||
|
||||
if (RadiusScale > 0f)
|
||||
Collider.m_Radius = length * RadiusScale;
|
||||
|
||||
// DynamicBone measures capsule height including both rounded ends.
|
||||
Collider.m_Height = length + Collider.m_Radius * 2f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73a040a00b60d4243b83dc5eda9511fe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,305 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Resolves collisions across the horizontal spans between adjacent skirt chains.
|
||||
/// DynamicBone itself only checks each independent vertical chain.
|
||||
/// </summary>
|
||||
[DefaultExecutionOrder(1000)]
|
||||
public sealed class SkirtSurfaceCollisionSolver : MonoBehaviour
|
||||
{
|
||||
private sealed class HorizontalLink
|
||||
{
|
||||
public DynamicBone.Particle Left;
|
||||
public DynamicBone.Particle Right;
|
||||
public float RestLength;
|
||||
}
|
||||
|
||||
private readonly List<List<DynamicBone>> _rings = new List<List<DynamicBone>>();
|
||||
private readonly List<DynamicBoneColliderBase> _colliders = new List<DynamicBoneColliderBase>();
|
||||
private readonly List<HorizontalLink> _horizontalLinks = new List<HorizontalLink>();
|
||||
private Transform _hip;
|
||||
|
||||
public int RingCount => _rings.Count;
|
||||
public int ColliderCount => _colliders.Count;
|
||||
public int LastContactCount { get; private set; }
|
||||
public float HorizontalStiffness { get; set; } = 0.25f;
|
||||
|
||||
public void Initialize(DynamicBone[] dynamics, Transform hip, IEnumerable<DynamicBoneColliderBase> colliders)
|
||||
{
|
||||
_hip = hip;
|
||||
_rings.Clear();
|
||||
_colliders.Clear();
|
||||
_horizontalLinks.Clear();
|
||||
foreach (DynamicBoneColliderBase collider in colliders)
|
||||
{
|
||||
if (IsSurfaceCollider(collider) && !_colliders.Contains(collider))
|
||||
_colliders.Add(collider);
|
||||
}
|
||||
|
||||
var layers = new Dictionary<string, List<DynamicBone>>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (DynamicBone dynamicBone in dynamics)
|
||||
{
|
||||
if (dynamicBone == null || !dynamicBone.m_ContinuousCollision ||
|
||||
dynamicBone.m_Root == null || dynamicBone.Particles.Count < 2)
|
||||
continue;
|
||||
|
||||
string layer = GetSkirtLayer(dynamicBone.m_Root.name);
|
||||
if (!layers.TryGetValue(layer, out List<DynamicBone> ring))
|
||||
{
|
||||
ring = new List<DynamicBone>();
|
||||
layers.Add(layer, ring);
|
||||
}
|
||||
ring.Add(dynamicBone);
|
||||
}
|
||||
|
||||
foreach (List<DynamicBone> ring in layers.Values)
|
||||
{
|
||||
if (ring.Count < 3)
|
||||
continue;
|
||||
|
||||
ring.Sort((left, right) => GetAngle(left).CompareTo(GetAngle(right)));
|
||||
_rings.Add(ring);
|
||||
AddHorizontalLinks(ring);
|
||||
}
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
LastContactCount = 0;
|
||||
SolveHorizontalLinks();
|
||||
for (int iteration = 0; iteration < 1; ++iteration)
|
||||
{
|
||||
foreach (List<DynamicBone> ring in _rings)
|
||||
LastContactCount += ResolveRing(ring, _colliders);
|
||||
}
|
||||
|
||||
foreach (List<DynamicBone> ring in _rings)
|
||||
{
|
||||
foreach (DynamicBone dynamicBone in ring)
|
||||
dynamicBone.ApplyParticlesToTransformsNow();
|
||||
}
|
||||
}
|
||||
|
||||
private void AddHorizontalLinks(List<DynamicBone> ring)
|
||||
{
|
||||
for (int chainIndex = 0; chainIndex < ring.Count; ++chainIndex)
|
||||
{
|
||||
DynamicBone leftChain = ring[chainIndex];
|
||||
DynamicBone rightChain = ring[(chainIndex + 1) % ring.Count];
|
||||
int depthCount = Mathf.Min(leftChain.Particles.Count, rightChain.Particles.Count);
|
||||
for (int depth = 1; depth < depthCount; ++depth)
|
||||
{
|
||||
DynamicBone.Particle left = leftChain.Particles[depth];
|
||||
DynamicBone.Particle right = rightChain.Particles[depth];
|
||||
_horizontalLinks.Add(new HorizontalLink
|
||||
{
|
||||
Left = left,
|
||||
Right = right,
|
||||
RestLength = Vector3.Distance(left.m_Position, right.m_Position)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SolveHorizontalLinks()
|
||||
{
|
||||
float strength = Mathf.Clamp01(HorizontalStiffness);
|
||||
if (strength <= 0f)
|
||||
return;
|
||||
|
||||
foreach (HorizontalLink link in _horizontalLinks)
|
||||
{
|
||||
Vector3 delta = link.Right.m_Position - link.Left.m_Position;
|
||||
float length = delta.magnitude;
|
||||
if (length <= Mathf.Epsilon)
|
||||
continue;
|
||||
|
||||
Vector3 correction = delta * ((length - link.RestLength) / length * strength * 0.5f);
|
||||
link.Left.m_Position += correction;
|
||||
link.Left.m_PrevPosition += correction;
|
||||
link.Right.m_Position -= correction;
|
||||
link.Right.m_PrevPosition -= correction;
|
||||
}
|
||||
}
|
||||
|
||||
private static int ResolveRing(List<DynamicBone> ring, List<DynamicBoneColliderBase> colliders)
|
||||
{
|
||||
int contacts = 0;
|
||||
for (int chainIndex = 0; chainIndex < ring.Count; ++chainIndex)
|
||||
{
|
||||
DynamicBone leftChain = ring[chainIndex];
|
||||
DynamicBone rightChain = ring[(chainIndex + 1) % ring.Count];
|
||||
int depthCount = Mathf.Min(leftChain.Particles.Count, rightChain.Particles.Count);
|
||||
|
||||
for (int depth = 1; depth < depthCount; ++depth)
|
||||
{
|
||||
DynamicBone.Particle left = leftChain.Particles[depth];
|
||||
DynamicBone.Particle right = rightChain.Particles[depth];
|
||||
float objectScale = Mathf.Abs(leftChain.transform.lossyScale.x);
|
||||
float particleRadius = Mathf.Max(left.m_Radius, right.m_Radius) * objectScale;
|
||||
float maxCorrection = Mathf.Max(
|
||||
Vector3.Distance(leftChain.Particles[depth - 1].m_Position, left.m_Position),
|
||||
Vector3.Distance(rightChain.Particles[depth - 1].m_Position, right.m_Position)) * 0.75f;
|
||||
maxCorrection = Mathf.Max(maxCorrection, 0.005f * objectScale);
|
||||
contacts += ResolveSpan(left, right, colliders, particleRadius, maxCorrection);
|
||||
contacts += ResolvePanel(
|
||||
leftChain.Particles[depth - 1], rightChain.Particles[depth - 1],
|
||||
left, right, depth > 1, colliders, particleRadius, maxCorrection);
|
||||
}
|
||||
}
|
||||
return contacts;
|
||||
}
|
||||
|
||||
private static int ResolvePanel(
|
||||
DynamicBone.Particle leftTop,
|
||||
DynamicBone.Particle rightTop,
|
||||
DynamicBone.Particle leftBottom,
|
||||
DynamicBone.Particle rightBottom,
|
||||
bool topIsMovable,
|
||||
List<DynamicBoneColliderBase> colliders,
|
||||
float particleRadius,
|
||||
float maxCorrection)
|
||||
{
|
||||
if (colliders.Count == 0)
|
||||
return 0;
|
||||
|
||||
int contacts = 0;
|
||||
|
||||
for (int verticalIndex = 1; verticalIndex <= 2; ++verticalIndex)
|
||||
{
|
||||
float vertical = verticalIndex / 3f;
|
||||
for (int horizontalIndex = 1; horizontalIndex <= 2; ++horizontalIndex)
|
||||
{
|
||||
float horizontal = horizontalIndex / 3f;
|
||||
Vector3 top = Vector3.Lerp(leftTop.m_Position, rightTop.m_Position, horizontal);
|
||||
Vector3 bottom = Vector3.Lerp(leftBottom.m_Position, rightBottom.m_Position, horizontal);
|
||||
Vector3 sample = Vector3.Lerp(top, bottom, vertical);
|
||||
|
||||
foreach (DynamicBoneColliderBase collider in colliders)
|
||||
{
|
||||
if (!IsSurfaceCollider(collider))
|
||||
continue;
|
||||
|
||||
Vector3 projected = sample;
|
||||
if (!collider.Collide(ref projected, particleRadius))
|
||||
continue;
|
||||
|
||||
++contacts;
|
||||
|
||||
float leftTopWeight = (1f - horizontal) * (1f - vertical);
|
||||
float rightTopWeight = horizontal * (1f - vertical);
|
||||
float leftBottomWeight = (1f - horizontal) * vertical;
|
||||
float rightBottomWeight = horizontal * vertical;
|
||||
float normalization = leftBottomWeight * leftBottomWeight + rightBottomWeight * rightBottomWeight;
|
||||
if (topIsMovable)
|
||||
normalization += leftTopWeight * leftTopWeight + rightTopWeight * rightTopWeight;
|
||||
|
||||
Vector3 correction = projected - sample;
|
||||
if (topIsMovable)
|
||||
{
|
||||
ApplyCorrection(leftTop, correction * (leftTopWeight / normalization), maxCorrection);
|
||||
ApplyCorrection(rightTop, correction * (rightTopWeight / normalization), maxCorrection);
|
||||
}
|
||||
ApplyCorrection(leftBottom, correction * (leftBottomWeight / normalization), maxCorrection);
|
||||
ApplyCorrection(rightBottom, correction * (rightBottomWeight / normalization), maxCorrection);
|
||||
sample = projected;
|
||||
}
|
||||
}
|
||||
}
|
||||
return contacts;
|
||||
}
|
||||
|
||||
private static int ResolveSpan(
|
||||
DynamicBone.Particle left,
|
||||
DynamicBone.Particle right,
|
||||
List<DynamicBoneColliderBase> colliders,
|
||||
float particleRadius,
|
||||
float maxCorrection)
|
||||
{
|
||||
if (colliders.Count == 0)
|
||||
return 0;
|
||||
|
||||
int contacts = 0;
|
||||
|
||||
for (int sampleIndex = 1; sampleIndex <= 1; ++sampleIndex)
|
||||
{
|
||||
float t = 0.5f;
|
||||
Vector3 sample = Vector3.Lerp(left.m_Position, right.m_Position, t);
|
||||
|
||||
foreach (DynamicBoneColliderBase collider in colliders)
|
||||
{
|
||||
if (!IsSurfaceCollider(collider))
|
||||
continue;
|
||||
|
||||
Vector3 projected = sample;
|
||||
if (!collider.Collide(ref projected, particleRadius))
|
||||
continue;
|
||||
|
||||
++contacts;
|
||||
|
||||
Vector3 correction = projected - sample;
|
||||
float leftWeight = 1f - t;
|
||||
float rightWeight = t;
|
||||
float normalization = leftWeight * leftWeight + rightWeight * rightWeight;
|
||||
Vector3 leftCorrection = correction * (leftWeight / normalization);
|
||||
Vector3 rightCorrection = correction * (rightWeight / normalization);
|
||||
|
||||
ApplyCorrection(left, leftCorrection, maxCorrection);
|
||||
ApplyCorrection(right, rightCorrection, maxCorrection);
|
||||
sample = projected;
|
||||
}
|
||||
}
|
||||
return contacts;
|
||||
}
|
||||
|
||||
private static bool IsSurfaceCollider(DynamicBoneColliderBase collider)
|
||||
{
|
||||
return collider != null && collider.enabled &&
|
||||
IsBodySkirtCollider(collider);
|
||||
}
|
||||
|
||||
private static bool IsBodySkirtCollider(DynamicBoneColliderBase collider)
|
||||
{
|
||||
if (collider == null || string.IsNullOrEmpty(collider.ColliderName) ||
|
||||
collider.ColliderName.IndexOf("Skirt", StringComparison.OrdinalIgnoreCase) < 0)
|
||||
return false;
|
||||
|
||||
if (collider.ColliderName.IndexOf("Thigh", StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
return true;
|
||||
|
||||
DynamicBoneCollider dynamicCollider = collider as DynamicBoneCollider;
|
||||
return collider.ColliderName.IndexOf("Hip", StringComparison.OrdinalIgnoreCase) >= 0 &&
|
||||
(dynamicCollider == null || dynamicCollider.m_Radius <= 0.25f);
|
||||
}
|
||||
|
||||
private static void ApplyCorrection(DynamicBone.Particle particle, Vector3 correction, float maxCorrection)
|
||||
{
|
||||
correction = Vector3.ClampMagnitude(correction, maxCorrection);
|
||||
particle.m_Position += correction;
|
||||
particle.m_PrevPosition += correction;
|
||||
particle.m_isCollide = true;
|
||||
}
|
||||
|
||||
private float GetAngle(DynamicBone dynamicBone)
|
||||
{
|
||||
Vector3 center = _hip != null ? _hip.position : transform.position;
|
||||
Vector3 direction = dynamicBone.m_Root.position - center;
|
||||
if (_hip != null)
|
||||
direction = _hip.InverseTransformDirection(direction);
|
||||
return Mathf.Atan2(direction.x, direction.z);
|
||||
}
|
||||
|
||||
private static string GetSkirtLayer(string boneName)
|
||||
{
|
||||
int marker = boneName.IndexOf("MSkirt", StringComparison.OrdinalIgnoreCase);
|
||||
if (marker < 0)
|
||||
return boneName;
|
||||
|
||||
int end = marker + "MSkirt".Length;
|
||||
while (end < boneName.Length && char.IsDigit(boneName[end]))
|
||||
++end;
|
||||
return boneName.Substring(marker, end - marker);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dae4cd93a4add8345b1a3a77b32a83fa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user