UniVRM/Assets/VRM10/Runtime/Components/Constraint/VRM10RotationConstraint.cs
ousttrue fcfe82588d constraint rotation:local to local only に縮小。
その他のものは後に。
2021-12-28 16:39:17 +09:00

41 lines
1.2 KiB
C#

using System;
using UniGLTF.Extensions.VRMC_node_constraint;
using UnityEngine;
namespace UniVRM10
{
/// <summary>
/// 対象の初期回転と現在回転の差分(delta)を、自身の初期回転と自身の初期回転にdeltaを乗算したものに対してWeightでSlerpする。
/// </summary>
[DisallowMultipleComponent]
public class VRM10RotationConstraint : VRM10RotationPositionConstraintBase
{
public override Vector3 Delta => FreezeAxes.Freeze(Quaternion.Slerp(Quaternion.identity, m_delta.Rotation, Weight).eulerAngles);
public override TR GetSourceCurrent()
{
var coords = GetSourceCoords();
if (m_src == null)
{
return coords;
}
return coords * new TR(m_delta.Rotation);
}
public override TR GetDstCurrent()
{
var coords = GetDstCoords();
if (m_src == null)
{
return coords;
}
return coords * new TR(m_delta.Rotation);
}
protected override void ApplyDelta()
{
m_dst.ApplyLocal(m_dst.LocalInitial * new TR(DestinationOffset) * new TR(Quaternion.Euler(Delta)));
}
}
}