UniVRM/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs
ousttrue d53942a7bd merge vrm10
* MeshUtility を UniGLTF 下に移動
* Assets/VRM10 を追加
* JsonSchemaからのコード生成 UniGLTF/Editor/Generator を追加
2021-01-07 13:37:24 +09:00

62 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace UniVRM10
{
[Serializable]
public class CurveMapper
{
private AnimationCurve _curve = AnimationCurve.Linear(0, 0, 1.0f, 1.0f);
[Range(20.0f, 90.0f)]
public float CurveXRangeDegree;
[Range(0, 90.0f)]
public float CurveYRangeDegree;
public CurveMapper(float xRange, float yRange)
{
CurveXRangeDegree = xRange;
CurveYRangeDegree = yRange;
}
public void OnValidate()
{
if (CurveXRangeDegree == 0)
{
CurveXRangeDegree = 90.0f;
}
}
public void Apply(VrmLib.LookAtRangeMap map)
{
CurveXRangeDegree = map.InputMaxValue;
CurveYRangeDegree = map.OutputScaling;
}
IEnumerable<Keyframe> ToKeys(float[] values)
{
for (int i = 0; i < values.Length; i += 4)
{
yield return new Keyframe(values[i], values[i + 1], values[i + 2], values[i + 3]);
}
}
public float Map(float src)
{
if (src < 0)
{
src = 0;
}
else if (src > CurveXRangeDegree)
{
src = CurveXRangeDegree;
}
return _curve.Evaluate(src / CurveXRangeDegree) * CurveYRangeDegree;
}
}
}