From a9696a37b2d6d8da92c3ec1948da57f1ced131e3 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 27 Feb 2025 00:37:14 +0900 Subject: [PATCH 1/2] VRM10ObjectLookAtEditor --- .../Editor/Components/VRM10ObjectEditor.cs | 4 +- .../Components/VRM10ObjectLookAtEditor.cs | 89 +++++++++++++++++++ .../VRM10ObjectLookAtEditor.cs.meta | 11 +++ 3 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 Assets/VRM10/Editor/Components/VRM10ObjectLookAtEditor.cs create mode 100644 Assets/VRM10/Editor/Components/VRM10ObjectLookAtEditor.cs.meta diff --git a/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs b/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs index 55efce643..95b9d17fb 100644 --- a/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs +++ b/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs @@ -22,7 +22,7 @@ namespace UniVRM10 // for SerializedProperty SerializedPropertyEditor m_expression; SerializedPropertyEditor m_meta; - SerializedPropertyEditor m_lookAt; + VRM10ObjectLookAtEditor m_lookAt; SerializedPropertyEditor m_firstPerson; SerializedProperty m_prefab; @@ -36,7 +36,7 @@ namespace UniVRM10 m_expression = SerializedPropertyEditor.Create(serializedObject, nameof(m_target.Expression)); m_meta = VRM10MetaEditor.Create(serializedObject); - m_lookAt = SerializedPropertyEditor.Create(serializedObject, nameof(m_target.LookAt)); + m_lookAt = new(serializedObject); m_firstPerson = SerializedPropertyEditor.Create(serializedObject, nameof(m_target.FirstPerson)); m_prefab = serializedObject.FindProperty("m_prefab"); diff --git a/Assets/VRM10/Editor/Components/VRM10ObjectLookAtEditor.cs b/Assets/VRM10/Editor/Components/VRM10ObjectLookAtEditor.cs new file mode 100644 index 000000000..45576c5bb --- /dev/null +++ b/Assets/VRM10/Editor/Components/VRM10ObjectLookAtEditor.cs @@ -0,0 +1,89 @@ +using UniGLTF.Extensions.VRMC_vrm; +using UnityEditor; + +namespace UniVRM10 +{ + public class VRM10ObjectLookAtEditor + { + private readonly SerializedObject _serializedObject; + private readonly SerializedProperty _OffsetFromHead; + private readonly SerializedProperty _LookAtType; + + + class CurveMapEditor + { + private readonly SerializedProperty _CurveXRangeDegree; + private readonly SerializedProperty _CurveYRangeDegree; + private readonly string _name; + + public CurveMapEditor(SerializedObject serializedObject, string name) + { + _CurveXRangeDegree = serializedObject.FindProperty($"LookAt.{name}.CurveXRangeDegree"); + _CurveYRangeDegree = serializedObject.FindProperty($"LookAt.{name}.CurveYRangeDegree"); + _name = name; + } + + public void OnInspectorGUI(float yMax) + { + EditorGUILayout.LabelField(_name); + EditorGUI.indentLevel++; + // EditorGUILayout.PropertyField(_CurveXRangeDegree); + _CurveXRangeDegree.floatValue = EditorGUILayout.Slider("CurveXRangeDegree", _CurveXRangeDegree.floatValue, 0, 90.0f); + // EditorGUILayout.PropertyField(_CurveYRangeDegree); + _CurveYRangeDegree.floatValue = EditorGUILayout.Slider("CurveYRangeDegree", _CurveYRangeDegree.floatValue, 0, yMax); + EditorGUI.indentLevel--; + EditorGUILayout.Space(); + } + } + private readonly CurveMapEditor _HorizontalOuter; + private readonly CurveMapEditor _HorizontalInner; + private readonly CurveMapEditor _VerticalDown; + private readonly CurveMapEditor _VerticalUp; + + public VRM10ObjectLookAtEditor(SerializedObject serializedObject) + { + _serializedObject = serializedObject; + _OffsetFromHead = serializedObject.FindProperty("LookAt.OffsetFromHead"); + _LookAtType = serializedObject.FindProperty("LookAt.LookAtType"); + _HorizontalOuter = new(serializedObject, "HorizontalOuter"); + _HorizontalInner = new(serializedObject, "HorizontalInner"); + _VerticalDown = new(serializedObject, "VerticalDown"); + _VerticalUp = new(serializedObject, "VerticalUp"); + } + + public void OnInspectorGUI() + { + EditorGUILayout.PropertyField(_OffsetFromHead); + EditorGUILayout.PropertyField(_LookAtType); + EditorGUILayout.Space(); + + switch ((LookAtType)_LookAtType.enumValueIndex) + { + case LookAtType.bone: + { + EditorGUILayout.HelpBox("Degree Input (0-90) => EyeBone Degree(0-90)", MessageType.Info); + _HorizontalOuter.OnInspectorGUI(90); + _HorizontalInner.OnInspectorGUI(90); + _VerticalDown.OnInspectorGUI(90); + _VerticalUp.OnInspectorGUI(90); + } + break; + + case LookAtType.expression: + { + EditorGUILayout.HelpBox("Degree Input (0-90) => Expression Weight(0-1.0)", MessageType.Info); + _HorizontalOuter.OnInspectorGUI(1); + _HorizontalInner.OnInspectorGUI(1); + _VerticalDown.OnInspectorGUI(1); + _VerticalUp.OnInspectorGUI(1); + } + break; + + default: + break; + } + + _serializedObject.ApplyModifiedProperties(); + } + } +} \ No newline at end of file diff --git a/Assets/VRM10/Editor/Components/VRM10ObjectLookAtEditor.cs.meta b/Assets/VRM10/Editor/Components/VRM10ObjectLookAtEditor.cs.meta new file mode 100644 index 000000000..db73ba5ee --- /dev/null +++ b/Assets/VRM10/Editor/Components/VRM10ObjectLookAtEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d31d0e4c86e078746b74b86dc473e15a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From fb59c601ab289f04b8938adbbf731954296db9f2 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 27 Feb 2025 13:00:45 +0900 Subject: [PATCH 2/2] Vrm10EditorUtility.LimitBreakSlider --- .../SpringBone/VRM10SpringBoneJointEditor.cs | 53 +----------------- .../Components/VRM10ObjectLookAtEditor.cs | 6 +- Assets/VRM10/Editor/Vrm10EditorUtility.cs | 55 +++++++++++++++++++ .../VRM10/Editor/Vrm10EditorUtility.cs.meta | 11 ++++ .../Runtime/Components/LookAt/CurveMapper.cs | 14 ++++- 5 files changed, 83 insertions(+), 56 deletions(-) create mode 100644 Assets/VRM10/Editor/Vrm10EditorUtility.cs create mode 100644 Assets/VRM10/Editor/Vrm10EditorUtility.cs.meta diff --git a/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringBoneJointEditor.cs b/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringBoneJointEditor.cs index 8d7699112..2bb0fbd61 100644 --- a/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringBoneJointEditor.cs +++ b/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringBoneJointEditor.cs @@ -59,12 +59,12 @@ namespace UniVRM10 m_showJointSettings = EditorGUILayout.Foldout(m_showJointSettings, "Joint Settings"); if (m_showJointSettings) { - LimitBreakSlider(m_stiffnessForceProp, 0.0f, 4.0f, 0.0f, Mathf.Infinity); - LimitBreakSlider(m_gravityPowerProp, 0.0f, 2.0f, 0.0f, Mathf.Infinity); + Vrm10EditorUtility.LimitBreakSlider(m_stiffnessForceProp, 0.0f, 4.0f, 0.0f, Mathf.Infinity); + Vrm10EditorUtility.LimitBreakSlider(m_gravityPowerProp, 0.0f, 2.0f, 0.0f, Mathf.Infinity); EditorGUILayout.PropertyField(m_gravityDirProp); EditorGUILayout.PropertyField(m_dragForceProp); EditorGUILayout.Space(); - LimitBreakSlider(m_jointRadiusProp, 0.0f, 0.5f, 0.0f, Mathf.Infinity); + Vrm10EditorUtility.LimitBreakSlider(m_jointRadiusProp, 0.0f, 0.5f, 0.0f, Mathf.Infinity); } if (serializedObject.ApplyModifiedProperties()) @@ -143,53 +143,6 @@ namespace UniVRM10 return jointIndex == (spring.Joints.Count - 1); } - /// - /// スライダーと数値入力で限界値の違う、所謂「限界突破スライダー」を作成する - /// `EditorGUILayout.PropertyField` の代替として利用する - /// - private static void LimitBreakSlider(SerializedProperty property, float sliderLeft, float sliderRight, float numberLeft, float numberRight) - { - var label = new GUIContent(property.displayName); - var currentValue = property.floatValue; - - var rect = EditorGUILayout.GetControlRect(); - - EditorGUI.BeginProperty(rect, label, property); - - rect = EditorGUI.PrefixLabel(rect, label); - - // slider - { - EditorGUI.BeginChangeCheck(); - - var sliderRect = rect; - sliderRect.width -= 55.0f; - rect.xMin += rect.width - 50.0f; - - var clampedvalue = Mathf.Clamp(currentValue, sliderLeft, sliderRight); - var sliderValue = GUI.HorizontalSlider(sliderRect, clampedvalue, sliderLeft, sliderRight); - - if (EditorGUI.EndChangeCheck()) - { - property.floatValue = sliderValue; - } - } - - // number - { - EditorGUI.BeginChangeCheck(); - - var numberValue = Mathf.Clamp(EditorGUI.FloatField(rect, currentValue), numberLeft, numberRight); - - if (EditorGUI.EndChangeCheck()) - { - property.floatValue = numberValue; - } - } - - EditorGUI.EndProperty(); - } - void OnSceneGUI() { if (m_root == null) diff --git a/Assets/VRM10/Editor/Components/VRM10ObjectLookAtEditor.cs b/Assets/VRM10/Editor/Components/VRM10ObjectLookAtEditor.cs index 45576c5bb..3e53763af 100644 --- a/Assets/VRM10/Editor/Components/VRM10ObjectLookAtEditor.cs +++ b/Assets/VRM10/Editor/Components/VRM10ObjectLookAtEditor.cs @@ -27,10 +27,8 @@ namespace UniVRM10 { EditorGUILayout.LabelField(_name); EditorGUI.indentLevel++; - // EditorGUILayout.PropertyField(_CurveXRangeDegree); - _CurveXRangeDegree.floatValue = EditorGUILayout.Slider("CurveXRangeDegree", _CurveXRangeDegree.floatValue, 0, 90.0f); - // EditorGUILayout.PropertyField(_CurveYRangeDegree); - _CurveYRangeDegree.floatValue = EditorGUILayout.Slider("CurveYRangeDegree", _CurveYRangeDegree.floatValue, 0, yMax); + Vrm10EditorUtility.LimitBreakSlider(_CurveXRangeDegree, 0, 90.0f, 0, 90.0f); + Vrm10EditorUtility.LimitBreakSlider(_CurveYRangeDegree, 0, yMax, 0, 90.0f); EditorGUI.indentLevel--; EditorGUILayout.Space(); } diff --git a/Assets/VRM10/Editor/Vrm10EditorUtility.cs b/Assets/VRM10/Editor/Vrm10EditorUtility.cs new file mode 100644 index 000000000..4df9bfba3 --- /dev/null +++ b/Assets/VRM10/Editor/Vrm10EditorUtility.cs @@ -0,0 +1,55 @@ +using UnityEditor; +using UnityEngine; + +namespace UniVRM10 +{ + public static class Vrm10EditorUtility + { + /// + /// スライダーと数値入力で限界値の違う、所謂「限界突破スライダー」を作成する + /// `EditorGUILayout.PropertyField` の代替として利用する + /// + public static void LimitBreakSlider(SerializedProperty property, float sliderLeft, float sliderRight, float numberLeft, float numberRight) + { + var label = new GUIContent(property.displayName); + var currentValue = property.floatValue; + + var rect = EditorGUILayout.GetControlRect(); + + EditorGUI.BeginProperty(rect, label, property); + + rect = EditorGUI.PrefixLabel(rect, label); + + // slider + { + EditorGUI.BeginChangeCheck(); + + var sliderRect = rect; + sliderRect.width -= 55.0f; + rect.xMin += rect.width - 50.0f; + + var clampedvalue = Mathf.Clamp(currentValue, sliderLeft, sliderRight); + var sliderValue = GUI.HorizontalSlider(sliderRect, clampedvalue, sliderLeft, sliderRight); + + if (EditorGUI.EndChangeCheck()) + { + property.floatValue = sliderValue; + } + } + + // number + { + EditorGUI.BeginChangeCheck(); + + var numberValue = Mathf.Clamp(EditorGUI.FloatField(rect, currentValue), numberLeft, numberRight); + + if (EditorGUI.EndChangeCheck()) + { + property.floatValue = numberValue; + } + } + + EditorGUI.EndProperty(); + } + } +} \ No newline at end of file diff --git a/Assets/VRM10/Editor/Vrm10EditorUtility.cs.meta b/Assets/VRM10/Editor/Vrm10EditorUtility.cs.meta new file mode 100644 index 000000000..2517d5419 --- /dev/null +++ b/Assets/VRM10/Editor/Vrm10EditorUtility.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4b75cffea6a5f03418a9a698a32c15cb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs b/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs index 1e7109d2a..b7f0508d8 100644 --- a/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs +++ b/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs @@ -7,10 +7,20 @@ namespace UniVRM10 [Serializable] public class CurveMapper { - [Range(20.0f, 90.0f)] + /// + /// v0.128.3 VRM10ObjectLookAtEditor + /// + /// DegreeINput 0-90 + /// public float CurveXRangeDegree; - [Range(0, 90.0f)] + /// + /// v0.128.3 VRM10ObjectLookAtEditor + /// + /// EyeBoneDegree 0-90 + /// or + /// ExpressionWeight 0-1.0 + /// public float CurveYRangeDegree; public CurveMapper(float xRange, float yRange)