From 0c0e9ffaf3c885ad0d42cd69a33cfb8a9277bbf6 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Tue, 10 Apr 2018 13:07:17 +0900 Subject: [PATCH] wheel dolly for preview --- Scripts/BlendShape/Editor/PreviewEditor.cs | 89 +++++++++++-------- .../BlendShape/Editor/PreviewFaceRenderer.cs | 4 +- Scripts/BlendShape/PreviewSceneManager.cs | 6 +- Scripts/Format/VRMVersion.cs | 8 +- 4 files changed, 61 insertions(+), 46 deletions(-) diff --git a/Scripts/BlendShape/Editor/PreviewEditor.cs b/Scripts/BlendShape/Editor/PreviewEditor.cs index e5c93cac1..52816f7cf 100644 --- a/Scripts/BlendShape/Editor/PreviewEditor.cs +++ b/Scripts/BlendShape/Editor/PreviewEditor.cs @@ -119,41 +119,8 @@ namespace VRM } private static int sliderHash = "Slider".GetHashCode(); - public static Vector2 Drag2D(Vector2 scrollPosition, Rect position) - { - int controlId = GUIUtility.GetControlID(sliderHash, FocusType.Passive); - Event current = Event.current; - switch (current.GetTypeForControl(controlId)) - { - case EventType.MouseDown: - if (position.Contains(current.mousePosition) && (double)position.width > 50.0) - { - GUIUtility.hotControl = controlId; - current.Use(); - EditorGUIUtility.SetWantsMouseJumping(1); - break; - } - break; - case EventType.MouseUp: - if (GUIUtility.hotControl == controlId) - GUIUtility.hotControl = 0; - EditorGUIUtility.SetWantsMouseJumping(0); - break; - case EventType.MouseDrag: - if (GUIUtility.hotControl == controlId) - { - scrollPosition -= current.delta * (!current.shift ? 1f : 3f) / Mathf.Min(position.width, position.height) * 140f; - scrollPosition.y = Mathf.Clamp(scrollPosition.y, -90f, 90f); - current.Use(); - GUI.changed = true; - break; - } - break; - } - return scrollPosition; - } - - Vector2 previewDir; + Vector2 m_previewDir; + float m_distance = 1.0f; // very important to override this, it tells Unity to render an ObjectPreview at the bottom of the inspector public override bool HasPreviewGUI() { return true; } @@ -172,7 +139,55 @@ namespace VRM return; } - previewDir = Drag2D(previewDir, r); + //previewDir = Drag2D(previewDir, r); + { + int controlId = GUIUtility.GetControlID(sliderHash, FocusType.Passive); + Event current = Event.current; + switch (current.GetTypeForControl(controlId)) + { + case EventType.MouseDown: + if (r.Contains(current.mousePosition) && (double)r.width > 50.0) + { + GUIUtility.hotControl = controlId; + current.Use(); + EditorGUIUtility.SetWantsMouseJumping(1); + break; + } + break; + + case EventType.MouseUp: + if (GUIUtility.hotControl == controlId) + GUIUtility.hotControl = 0; + EditorGUIUtility.SetWantsMouseJumping(0); + break; + + case EventType.MouseDrag: + if (GUIUtility.hotControl == controlId) + { + m_previewDir -= current.delta * (!current.shift ? 1f : 3f) / Mathf.Min(r.width, r.height) * 140f; + m_previewDir.y = Mathf.Clamp(m_previewDir.y, -90f, 90f); + current.Use(); + GUI.changed = true; + break; + } + break; + + case EventType.ScrollWheel: + //Debug.LogFormat("wheel: {0}", current.delta); + if (current.delta.y > 0) + { + m_distance *= 1.1f; + Repaint(); + } + else if (current.delta.y < 0) + { + m_distance *= 0.9f; + Repaint(); + } + break; + } + //return scrollPosition; + } //Debug.LogFormat("{0}", previewDir); if (Event.current.type != EventType.Repaint) @@ -183,7 +198,7 @@ namespace VRM if (m_renderer != null && m_scene != null) { - var texture = m_renderer.Render(r, background, m_scene, previewDir); + var texture = m_renderer.Render(r, background, m_scene, m_previewDir, m_distance); if (texture != null) { // draw the RenderTexture in the ObjectPreview pane diff --git a/Scripts/BlendShape/Editor/PreviewFaceRenderer.cs b/Scripts/BlendShape/Editor/PreviewFaceRenderer.cs index 62c0711fd..17ad0efc4 100644 --- a/Scripts/BlendShape/Editor/PreviewFaceRenderer.cs +++ b/Scripts/BlendShape/Editor/PreviewFaceRenderer.cs @@ -81,7 +81,7 @@ namespace VRM //const float FACTOR = 0.1f; - public Texture Render(Rect r, GUIStyle background, PreviewSceneManager scene, Vector2 drag) + public Texture Render(Rect r, GUIStyle background, PreviewSceneManager scene, Vector2 drag, float distance) { if (scene == null) return null; @@ -90,7 +90,7 @@ namespace VRM m_previewUtility.BeginPreview(r, background); // set up the PreviewRenderUtility's mini internal scene // setup the ObjectPreview's camera - scene.SetupCamera(PreviewCamera, scene.TargetPosition, -drag.x, drag.y); + scene.SetupCamera(PreviewCamera, scene.TargetPosition, -drag.x, drag.y, distance); foreach (var item in scene.EnumRenderItems) { diff --git a/Scripts/BlendShape/PreviewSceneManager.cs b/Scripts/BlendShape/PreviewSceneManager.cs index 9de0e9217..800378658 100644 --- a/Scripts/BlendShape/PreviewSceneManager.cs +++ b/Scripts/BlendShape/PreviewSceneManager.cs @@ -205,7 +205,7 @@ namespace VRM { return new Vector3(0, 1.4f, 0); } - return m_target.position; + return m_target.position + new Vector3(0, 0.1f, 0); } } @@ -266,7 +266,7 @@ namespace VRM /// カメラパラメーターを決める /// /// - public void SetupCamera(Camera camera, Vector3 target, float yaw, float pitch) + public void SetupCamera(Camera camera, Vector3 target, float yaw, float pitch, float distance) { camera.backgroundColor = Color.gray; camera.clearFlags = CameraClearFlags.Color; @@ -274,7 +274,7 @@ namespace VRM // projection //float magnitude = m_bounds.extents.magnitude * 0.5f; //float distance = magnitude; - var distance = target.magnitude; + //var distance = target.magnitude; camera.fieldOfView = 27f; camera.nearClipPlane = 0.3f; diff --git a/Scripts/Format/VRMVersion.cs b/Scripts/Format/VRMVersion.cs index 5a0424182..cb1ae0574 100644 --- a/Scripts/Format/VRMVersion.cs +++ b/Scripts/Format/VRMVersion.cs @@ -4,11 +4,11 @@ namespace VRM public static class VRMVersion { public const int MAJOR = 0; - public const int MINOR = 22; + public const int MINOR = 23; - public const string VERSION = "0.22"; + public const string VERSION = "0.23"; - public const string DecrementMenuName = "VRM/Version(0.22) Decrement"; - public const string IncrementMenuName = "VRM/Version(0.22) Increment"; + public const string DecrementMenuName = "VRM/Version(0.23) Decrement"; + public const string IncrementMenuName = "VRM/Version(0.23) Increment"; } }