wheel dolly for preview

This commit is contained in:
ousttrue 2018-04-10 13:07:17 +09:00
parent f5886de2f8
commit 0c0e9ffaf3
4 changed files with 61 additions and 46 deletions

View File

@ -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

View File

@ -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)
{

View File

@ -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
/// カメラパラメーターを決める
/// </summary>
/// <param name="camera"></param>
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;

View File

@ -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";
}
}