mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-11 13:04:17 -05:00
implement BlendShape LookAt
This commit is contained in:
parent
2bc3a48d6b
commit
87a7212a4c
|
|
@ -208,6 +208,7 @@ namespace VRM
|
|||
var blendShapeApplyer = exporter.Copy.GetComponent<VRMLookAtBlendShapeApplyer>();
|
||||
if (boneApplyer != null)
|
||||
{
|
||||
gltf.extensions.VRM.firstPerson.lookAtType = LookAtType.Bone;
|
||||
gltf.extensions.VRM.firstPerson.lookAtHorizontalInner.Apply(boneApplyer.HorizontalInner);
|
||||
gltf.extensions.VRM.firstPerson.lookAtHorizontalOuter.Apply(boneApplyer.HorizontalOuter);
|
||||
gltf.extensions.VRM.firstPerson.lookAtVerticalDown.Apply(boneApplyer.VerticalDown);
|
||||
|
|
@ -215,8 +216,10 @@ namespace VRM
|
|||
}
|
||||
else if (blendShapeApplyer != null)
|
||||
{
|
||||
// ToDo
|
||||
throw new NotImplementedException();
|
||||
gltf.extensions.VRM.firstPerson.lookAtType = LookAtType.BlendShape;
|
||||
gltf.extensions.VRM.firstPerson.lookAtHorizontalOuter.Apply(blendShapeApplyer.Horizontal);
|
||||
gltf.extensions.VRM.firstPerson.lookAtVerticalDown.Apply(blendShapeApplyer.VerticalDown);
|
||||
gltf.extensions.VRM.firstPerson.lookAtVerticalUp.Apply(blendShapeApplyer.VerticalUp);
|
||||
}
|
||||
}
|
||||
else if (lookAt != null)
|
||||
|
|
|
|||
|
|
@ -192,12 +192,27 @@ namespace VRM
|
|||
// LookAt
|
||||
var lookAtHead = context.Root.AddComponent<VRMLookAtHead>();
|
||||
|
||||
var lookAt = context.Root.AddComponent<VRMLookAtBoneApplyer>();
|
||||
lookAt.HorizontalInner.Apply(gltfFirstPerson.lookAtHorizontalInner);
|
||||
lookAt.HorizontalOuter.Apply(gltfFirstPerson.lookAtHorizontalOuter);
|
||||
lookAt.VerticalDown.Apply(gltfFirstPerson.lookAtVerticalDown);
|
||||
lookAt.VerticalUp.Apply(gltfFirstPerson.lookAtVerticalUp);
|
||||
//lookAt.GetBones();
|
||||
switch(gltfFirstPerson.lookAtType)
|
||||
{
|
||||
case LookAtType.Bone:
|
||||
{
|
||||
var applyer = context.Root.AddComponent<VRMLookAtBoneApplyer>();
|
||||
applyer.HorizontalInner.Apply(gltfFirstPerson.lookAtHorizontalInner);
|
||||
applyer.HorizontalOuter.Apply(gltfFirstPerson.lookAtHorizontalOuter);
|
||||
applyer.VerticalDown.Apply(gltfFirstPerson.lookAtVerticalDown);
|
||||
applyer.VerticalUp.Apply(gltfFirstPerson.lookAtVerticalUp);
|
||||
}
|
||||
break;
|
||||
|
||||
case LookAtType.BlendShape:
|
||||
{
|
||||
var applyer = context.Root.AddComponent<VRMLookAtBlendShapeApplyer>();
|
||||
applyer.Horizontal.Apply(gltfFirstPerson.lookAtHorizontalOuter);
|
||||
applyer.VerticalDown.Apply(gltfFirstPerson.lookAtVerticalDown);
|
||||
applyer.VerticalUp.Apply(gltfFirstPerson.lookAtVerticalUp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void LoadSecondaryMotions(VRMImporterContext context)
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ namespace VRM
|
|||
public static class VRMVersion
|
||||
{
|
||||
public const int MAJOR = 0;
|
||||
public const int MINOR = 14;
|
||||
public const int MINOR = 15;
|
||||
|
||||
public const string VERSION = "0.14";
|
||||
public const string VERSION = "0.15";
|
||||
|
||||
public const string DecrementMenuName = "VRM/Version(0.14) Decrement";
|
||||
public const string IncrementMenuName = "VRM/Version(0.14) Increment";
|
||||
public const string DecrementMenuName = "VRM/Version(0.15) Decrement";
|
||||
public const string IncrementMenuName = "VRM/Version(0.15) Increment";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,13 @@ namespace VRM
|
|||
}
|
||||
}
|
||||
|
||||
public enum LookAtType
|
||||
{
|
||||
None,
|
||||
Bone,
|
||||
BlendShape,
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class glTF_VRM_Firstperson : UniGLTF.JsonSerializableBase
|
||||
{
|
||||
|
|
@ -65,6 +72,19 @@ namespace VRM
|
|||
public List<glTF_VRM_MeshAnnotation> meshAnnotations = new List<glTF_VRM_MeshAnnotation>();
|
||||
|
||||
// lookat
|
||||
public string lookAtTypeName = "Bone";
|
||||
public LookAtType lookAtType
|
||||
{
|
||||
get {
|
||||
if (string.IsNullOrEmpty(lookAtTypeName))
|
||||
{
|
||||
// fallback
|
||||
return LookAtType.Bone;
|
||||
}
|
||||
return (LookAtType)Enum.Parse(typeof(LookAtType), lookAtTypeName, true);
|
||||
}
|
||||
set { lookAtTypeName = value.ToString(); }
|
||||
}
|
||||
public glTF_VRM_DegreeMap lookAtHorizontalInner = new glTF_VRM_DegreeMap();
|
||||
public glTF_VRM_DegreeMap lookAtHorizontalOuter = new glTF_VRM_DegreeMap();
|
||||
public glTF_VRM_DegreeMap lookAtVerticalDown = new glTF_VRM_DegreeMap();
|
||||
|
|
@ -76,6 +96,7 @@ namespace VRM
|
|||
f.KeyValue(() => firstPersonBoneOffset);
|
||||
f.KeyValue(() => meshAnnotations);
|
||||
|
||||
f.KeyValue(() => lookAtTypeName);
|
||||
f.KeyValue(() => lookAtHorizontalInner);
|
||||
f.KeyValue(() => lookAtHorizontalOuter);
|
||||
f.KeyValue(() => lookAtVerticalDown);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace VRM
|
|||
|
||||
void OnSceneGUI()
|
||||
{
|
||||
if (!Application.isPlaying) return;
|
||||
//if (!Application.isPlaying) return;
|
||||
if (!m_target.DrawGizmo) return;
|
||||
if (m_target.Target == null) return;
|
||||
if (m_target.Head.Transform == null) return;
|
||||
|
|
|
|||
|
|
@ -8,16 +8,14 @@ namespace VRM
|
|||
{
|
||||
public bool DrawGizmo = true;
|
||||
|
||||
[SerializeField, Header("Degree Mapping")]
|
||||
public CurveMapper Horizontal = new CurveMapper();
|
||||
|
||||
[SerializeField]
|
||||
float Range = 20.0f;
|
||||
public CurveMapper VerticalDown = new CurveMapper();
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
}
|
||||
[SerializeField]
|
||||
public CurveMapper VerticalUp = new CurveMapper();
|
||||
|
||||
VRMLookAtHead m_head;
|
||||
VRMBlendShapeProxy m_propxy;
|
||||
|
|
@ -48,26 +46,27 @@ namespace VRM
|
|||
if (yaw < 0)
|
||||
{
|
||||
// Left
|
||||
m_propxy.SetValue(BlendShapePreset.LookLeft, -yaw / Range);
|
||||
m_propxy.SetValue(BlendShapePreset.LookLeft, Horizontal.Map(-yaw));
|
||||
m_propxy.SetValue(BlendShapePreset.LookRight, 0);
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
// Right
|
||||
m_propxy.SetValue(BlendShapePreset.LookLeft, 0);
|
||||
m_propxy.SetValue(BlendShapePreset.LookRight, yaw / Range);
|
||||
m_propxy.SetValue(BlendShapePreset.LookRight, Horizontal.Map(yaw));
|
||||
}
|
||||
|
||||
if (pitch < 0)
|
||||
{
|
||||
// Up
|
||||
m_propxy.SetValue(BlendShapePreset.LookUp, -pitch / Range);
|
||||
m_propxy.SetValue(BlendShapePreset.LookDown, 0);
|
||||
// Down
|
||||
m_propxy.SetValue(BlendShapePreset.LookUp, 0);
|
||||
m_propxy.SetValue(BlendShapePreset.LookDown, VerticalDown.Map(-pitch));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Down
|
||||
m_propxy.SetValue(BlendShapePreset.LookUp, 0);
|
||||
m_propxy.SetValue(BlendShapePreset.LookDown, pitch / Range);
|
||||
// Up
|
||||
m_propxy.SetValue(BlendShapePreset.LookUp, VerticalUp.Map(pitch));
|
||||
m_propxy.SetValue(BlendShapePreset.LookDown, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user