-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature10/spring bone editor #994
Changes from all commits
7c9e642
8ec1688
4ff958e
29a3f43
99c9b87
895952d
ae95aa6
169d7df
7dcbfa1
6eb5fa6
dfd8c2c
14eeb48
df8969f
f3ac33f
db0453a
d06af40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
using System.Text; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace UniVRM10 | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Collections.Generic; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace UniVRM10 | ||
{ | ||
public class ExpressionSlider | ||
{ | ||
Dictionary<ExpressionKey, float> m_expressionKeys; | ||
ExpressionKey m_key; | ||
|
||
public ExpressionSlider(Dictionary<ExpressionKey, float> expressionKeys, ExpressionKey key) | ||
{ | ||
m_expressionKeys = expressionKeys; | ||
m_key = key; | ||
} | ||
|
||
public KeyValuePair<ExpressionKey, float> Slider() | ||
{ | ||
var oldValue = m_expressionKeys[m_key]; | ||
var enable = GUI.enabled; | ||
GUI.enabled = Application.isPlaying; | ||
var newValue = EditorGUILayout.Slider(m_key.ToString(), oldValue, 0, 1.0f); | ||
GUI.enabled = enable; | ||
return new KeyValuePair<ExpressionKey, float>(m_key, newValue); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace UniVRM10 | ||
{ | ||
// | ||
// Expression 向けの Inspector | ||
// | ||
// Runtime に Expression 操作用の Slider を表示する | ||
// | ||
class VRM10ControllerEditorExpression | ||
{ | ||
VRM10Controller m_target; | ||
Dictionary<ExpressionKey, float> m_expressionKeyWeights = new Dictionary<ExpressionKey, float>(); | ||
List<ExpressionSlider> m_sliders; | ||
|
||
public VRM10ControllerEditorExpression(VRM10Controller target) | ||
{ | ||
m_target = target; | ||
|
||
m_expressionKeyWeights = m_target.Expression.Clips.ToDictionary(x => ExpressionKey.CreateFromClip(x), x => 0.0f); | ||
m_sliders = m_target.Expression.Clips | ||
.Where(x => x != null) | ||
.Select(x => new ExpressionSlider(m_expressionKeyWeights, ExpressionKey.CreateFromClip(x))) | ||
.ToList() | ||
; | ||
} | ||
|
||
public void OnGUI() | ||
{ | ||
EditorGUILayout.Space(); | ||
|
||
if (!Application.isPlaying) | ||
{ | ||
EditorGUILayout.HelpBox("Enable when playing", MessageType.Info); | ||
} | ||
|
||
if (m_sliders != null) | ||
{ | ||
EditorGUILayout.Space(); | ||
EditorGUILayout.LabelField("Expression Weights", EditorStyles.boldLabel); | ||
|
||
var sliders = m_sliders.Select(x => x.Slider()); | ||
foreach (var slider in sliders) | ||
{ | ||
m_expressionKeyWeights[slider.Key] = slider.Value; | ||
} | ||
m_target.Expression.SetWeights(m_expressionKeyWeights); | ||
} | ||
|
||
EditorGUILayout.Space(); | ||
EditorGUILayout.LabelField("Override rates", EditorStyles.boldLabel); | ||
EditorGUI.BeginDisabledGroup(true); | ||
{ | ||
EditorGUILayout.Slider("Blink override rate", m_target.Expression.BlinkOverrideRate, 0f, 1f); | ||
EditorGUILayout.Slider("LookAt override rate", m_target.Expression.LookAtOverrideRate, 0f, 1f); | ||
EditorGUILayout.Slider("Mouth override rate", m_target.Expression.MouthOverrideRate, 0f, 1f); | ||
} | ||
EditorGUI.EndDisabledGroup(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace UniVRM10 | ||
{ | ||
public static class LookAtEditor | ||
{ | ||
public static void Draw2D(VRM10Controller target) | ||
{ | ||
|
||
} | ||
|
||
public static void Draw3D(VRM10Controller target) | ||
{ | ||
if(target==null) | ||
{ | ||
return; | ||
} | ||
OnSceneGUIOffset(target); | ||
if (!Application.isPlaying) | ||
{ | ||
// offset | ||
var p = target.LookAt.OffsetFromHead; | ||
Handles.Label(target.Head.position, $"fromHead: [{p.x:0.00}, {p.y:0.00}, {p.z:0.00}]"); | ||
} | ||
else | ||
{ | ||
target.LookAt.OnSceneGUILookAt(target.Head); | ||
} | ||
} | ||
|
||
static void OnSceneGUIOffset(VRM10Controller m_target) | ||
{ | ||
if (!m_target.LookAt.DrawGizmo) | ||
{ | ||
return; | ||
} | ||
|
||
var head = m_target.Head; | ||
if (head == null) | ||
{ | ||
return; | ||
} | ||
|
||
EditorGUI.BeginChangeCheck(); | ||
|
||
var worldOffset = head.localToWorldMatrix.MultiplyPoint(m_target.LookAt.OffsetFromHead); | ||
worldOffset = Handles.PositionHandle(worldOffset, head.rotation); | ||
|
||
Handles.DrawDottedLine(head.position, worldOffset, 5); | ||
Handles.SphereHandleCap(0, head.position, Quaternion.identity, 0.02f, Event.current.type); | ||
Handles.SphereHandleCap(0, worldOffset, Quaternion.identity, 0.02f, Event.current.type); | ||
|
||
if (EditorGUI.EndChangeCheck()) | ||
{ | ||
Undo.RecordObject(m_target, "Changed FirstPerson"); | ||
|
||
m_target.LookAt.OffsetFromHead = head.worldToLocalMatrix.MultiplyPoint(worldOffset); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using UnityEditor; | ||
|
||
namespace UniVRM10 | ||
{ | ||
/// <summary> | ||
/// 指定した SerializedProperty を起点に再帰的に SerializedProperty を表示する。 | ||
/// </summary> | ||
class PropGui | ||
{ | ||
SerializedProperty m_root; | ||
|
||
public PropGui(SerializedProperty property) | ||
{ | ||
m_root = property; | ||
} | ||
|
||
// public static PropGui FromSerializedObject(SerializedObject serializedObject, string name) | ||
// { | ||
// var prop = serializedObject.FindProperty(name); | ||
// return new PropGui(prop); | ||
// } | ||
|
||
public void RecursiveProperty() | ||
{ | ||
var depth = m_root.depth; | ||
var iterator = m_root.Copy(); | ||
for (var enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false) | ||
{ | ||
if (iterator.depth < depth) | ||
return; | ||
|
||
depth = iterator.depth; | ||
|
||
using (new EditorGUI.DisabledScope("m_Script" == iterator.propertyPath)) | ||
{ | ||
EditorGUILayout.PropertyField(iterator, true); | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace UniVRM10 | ||
{ | ||
public class ScrollView | ||
{ | ||
Vector2 m_scrollPosition; | ||
|
||
public void Draw(float height, Action content, Action repaint) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. やっぱ IMGUI の部品作ろうと思うと |
||
{ | ||
m_scrollPosition = EditorGUILayout.BeginScrollView(m_scrollPosition); | ||
|
||
// mouse wheel scroll part 1 | ||
var isScroll = Event.current.isScrollWheel; | ||
if (isScroll) | ||
{ | ||
m_scrollPosition += Event.current.delta * EditorGUIUtility.singleLineHeight; | ||
if (m_scrollPosition.y < 0) | ||
{ | ||
m_scrollPosition = Vector2.zero; | ||
} | ||
} | ||
|
||
content(); | ||
|
||
// mouse wheel scroll part 2 | ||
var bottom = EditorGUILayout.GetControlRect(); | ||
if (isScroll) | ||
{ | ||
var maxScroll = bottom.y - (height - EditorGUIUtility.singleLineHeight * 2); | ||
// Debug.Log($"{bottom.y}: {this.position.size.y}: {maxScroll}"); | ||
if (m_scrollPosition.y > maxScroll) | ||
{ | ||
m_scrollPosition = new Vector2(0, maxScroll); | ||
} | ||
repaint(); | ||
} | ||
|
||
EditorGUILayout.EndScrollView(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
いずれ Editor 向けのクラスは
UniVRM10.Editor
にしたい