mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-01 15:33:24 -05:00
WIP ObjectSpace.model
This commit is contained in:
parent
744d0e54bc
commit
abafd14ff2
|
|
@ -11,7 +11,7 @@ namespace UniVRM10
|
|||
|
||||
readonly TRS m_initial;
|
||||
|
||||
public ConstraintDestination(Transform t, ObjectSpace coords)
|
||||
public ConstraintDestination(Transform t, ObjectSpace coords, Transform modelRoot = null)
|
||||
{
|
||||
m_transform = t;
|
||||
m_coords = coords;
|
||||
|
|
@ -26,6 +26,10 @@ namespace UniVRM10
|
|||
m_initial = TRS.GetLocal(t);
|
||||
break;
|
||||
|
||||
case ObjectSpace.model:
|
||||
m_initial = TRS.GetRelative(t, modelRoot.worldToLocalMatrix);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
@ -49,7 +53,7 @@ namespace UniVRM10
|
|||
}
|
||||
}
|
||||
|
||||
public void ApplyRotation(Quaternion delta, float weight)
|
||||
public void ApplyRotation(Quaternion delta, float weight, Transform modelRoot = null)
|
||||
{
|
||||
// 0~1 で clamp しない slerp
|
||||
var value = Quaternion.LerpUnclamped(Quaternion.identity, delta, weight) * m_initial.Rotation;
|
||||
|
|
@ -63,6 +67,10 @@ namespace UniVRM10
|
|||
m_transform.localRotation = value;
|
||||
break;
|
||||
|
||||
case ObjectSpace.model:
|
||||
m_transform.rotation = modelRoot.rotation * value;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,5 +27,15 @@ namespace UniVRM10
|
|||
Scale = t.localScale,
|
||||
};
|
||||
}
|
||||
|
||||
public static TRS GetRelative(Transform t, Matrix4x4 toRelative)
|
||||
{
|
||||
return new TRS
|
||||
{
|
||||
Translation = toRelative.MultiplyPoint(t.position),
|
||||
Rotation = toRelative.rotation * t.rotation,
|
||||
Scale = toRelative.MultiplyVector(t.lossyScale),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,16 @@ namespace UniVRM10
|
|||
m_dst = null;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
var current = transform;
|
||||
while (current.parent != null)
|
||||
{
|
||||
current = current.parent;
|
||||
}
|
||||
ModelRoot = current;
|
||||
}
|
||||
|
||||
public override void Process()
|
||||
{
|
||||
if (Source == null)
|
||||
|
|
@ -56,7 +66,7 @@ namespace UniVRM10
|
|||
}
|
||||
if (m_dst == null)
|
||||
{
|
||||
m_dst = new ConstraintDestination(transform, DestinationCoordinate);
|
||||
m_dst = new ConstraintDestination(transform, DestinationCoordinate, ModelRoot);
|
||||
}
|
||||
|
||||
var delta = FreezeAxes.Freeze(m_src.TranslationDelta);
|
||||
|
|
|
|||
|
|
@ -43,6 +43,16 @@ namespace UniVRM10
|
|||
m_dst = null;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
var current = transform;
|
||||
while (current.parent != null)
|
||||
{
|
||||
current = current.parent;
|
||||
}
|
||||
ModelRoot = current;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SourceのUpdateよりも先か後かはその時による。
|
||||
/// 厳密に制御するのは無理。
|
||||
|
|
@ -61,7 +71,7 @@ namespace UniVRM10
|
|||
}
|
||||
if (m_dst == null)
|
||||
{
|
||||
m_dst = new ConstraintDestination(transform, DestinationCoordinate);
|
||||
m_dst = new ConstraintDestination(transform, DestinationCoordinate, ModelRoot);
|
||||
}
|
||||
|
||||
// 軸制限をしたオイラー角
|
||||
|
|
@ -70,7 +80,7 @@ namespace UniVRM10
|
|||
var rotation = Quaternion.Euler(fleezed);
|
||||
// Debug.Log($"{delta} => {rotation}");
|
||||
// オイラー角を再度Quaternionへ。weight を加味してSlerpする
|
||||
m_dst.ApplyRotation(rotation, Weight);
|
||||
m_dst.ApplyRotation(rotation, Weight, ModelRoot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user