Merge branch 'fix-asset-viewports' of git://github.com/stefnotch/FlaxEngine into stefnotch-fix-asset-viewports

This commit is contained in:
Wojtek Figat
2021-01-28 23:30:05 +01:00
6 changed files with 30 additions and 25 deletions

View File

@@ -32,9 +32,9 @@ namespace FlaxEditor.Viewport.Cameras
/// </summary>
/// <param name="objectBounds">The target object bounds.</param>
/// <param name="marginDistanceScale">The margin distance scale of the orbit radius.</param>
public void SerArcBallView(BoundingBox objectBounds, float marginDistanceScale = 2.0f)
public void SetArcBallView(BoundingBox objectBounds, float marginDistanceScale = 2.0f)
{
SerArcBallView(BoundingSphere.FromBox(objectBounds), marginDistanceScale);
SetArcBallView(BoundingSphere.FromBox(objectBounds), marginDistanceScale);
}
/// <summary>
@@ -42,18 +42,18 @@ namespace FlaxEditor.Viewport.Cameras
/// </summary>
/// <param name="objectBounds">The target object bounds.</param>
/// <param name="marginDistanceScale">The margin distance scale of the orbit radius.</param>
public void SerArcBallView(BoundingSphere objectBounds, float marginDistanceScale = 2.0f)
public void SetArcBallView(BoundingSphere objectBounds, float marginDistanceScale = 2.0f)
{
SerArcBallView(new Quaternion(-0.08f, -0.92f, 0.31f, -0.23f), objectBounds.Center, objectBounds.Radius * marginDistanceScale);
SetArcBallView(new Quaternion(-0.08f, -0.92f, 0.31f, -0.23f), objectBounds.Center, objectBounds.Radius * marginDistanceScale);
}
/// <summary>
/// Sets view orientation and position to match the arc ball camera style view for the given orbit radius.
/// </summary>
/// <param name="orbitRadius">The orbit radius.</param>
public void SerArcBallView(float orbitRadius)
public void SetArcBallView(float orbitRadius)
{
SerArcBallView(new Quaternion(-0.08f, -0.92f, 0.31f, -0.23f), Vector3.Zero, orbitRadius);
SetArcBallView(new Quaternion(-0.08f, -0.92f, 0.31f, -0.23f), Vector3.Zero, orbitRadius);
}
/// <summary>
@@ -62,7 +62,7 @@ namespace FlaxEditor.Viewport.Cameras
/// <param name="orientation">The view rotation.</param>
/// <param name="orbitCenter">The orbit center location.</param>
/// <param name="orbitRadius">The orbit radius.</param>
public void SerArcBallView(Quaternion orientation, Vector3 orbitCenter, float orbitRadius)
public void SetArcBallView(Quaternion orientation, Vector3 orbitCenter, float orbitRadius)
{
// Rotate
Viewport.ViewOrientation = orientation;

View File

@@ -138,9 +138,7 @@ namespace FlaxEditor.Viewport
private bool _isControllingMouse;
private int _deltaFilteringStep;
private Vector2 _startPosMiddle;
private Vector2 _startPosRight;
private Vector2 _startPosLeft;
private Vector2 _startPos;
private Vector2 _mouseDeltaRightLast;
private Vector2[] _deltaFilteringBuffer = new Vector2[FpsCameraFilteringFrames];
@@ -850,7 +848,7 @@ namespace FlaxEditor.Viewport
/// </summary>
protected virtual void OnLeftMouseButtonDown()
{
_startPosLeft = _viewMousePos;
_startPos = _viewMousePos;
}
/// <summary>
@@ -865,7 +863,7 @@ namespace FlaxEditor.Viewport
/// </summary>
protected virtual void OnRightMouseButtonDown()
{
_startPosRight = _viewMousePos;
_startPos = _viewMousePos;
}
/// <summary>
@@ -880,7 +878,7 @@ namespace FlaxEditor.Viewport
/// </summary>
protected virtual void OnMiddleMouseButtonDown()
{
_startPosMiddle = _viewMousePos;
_startPos = _viewMousePos;
}
/// <summary>
@@ -1051,7 +1049,13 @@ namespace FlaxEditor.Viewport
moveDelta *= 0.3f;
// Calculate smooth mouse delta not dependant on viewport size
Vector2 offset = _viewMousePos - (_input.IsMouseMiddleDown ? _startPosMiddle : _startPosRight);
Vector2 offset = _viewMousePos - _startPos;
if (_input.IsZooming && !_input.IsMouseRightDown && !_input.IsMouseLeftDown && !_input.IsMouseMiddleDown)
{
offset = Vector2.Zero;
}
offset.X = offset.X > 0 ? Mathf.Floor(offset.X) : Mathf.Ceil(offset.X);
offset.Y = offset.Y > 0 ? Mathf.Floor(offset.Y) : Mathf.Ceil(offset.Y);
_mouseDeltaRight = offset / size;
@@ -1093,7 +1097,7 @@ namespace FlaxEditor.Viewport
// Move mouse back to the root position
if (centerMouse && (_input.IsMouseRightDown || _input.IsMouseLeftDown || _input.IsMouseMiddleDown))
{
Vector2 center = PointToWindow(_input.IsMouseMiddleDown ? _startPosMiddle : _startPosRight);
Vector2 center = PointToWindow(_startPos);
win.MousePosition = center;
}
}
@@ -1139,11 +1143,11 @@ namespace FlaxEditor.Viewport
if (_input.IsMouseLeftDown)
{
// Calculate smooth mouse delta not dependant on viewport size
Vector2 offset = _viewMousePos - _startPosLeft;
Vector2 offset = _viewMousePos - _startPos;
offset.X = offset.X > 0 ? Mathf.Floor(offset.X) : Mathf.Ceil(offset.X);
offset.Y = offset.Y > 0 ? Mathf.Floor(offset.Y) : Mathf.Ceil(offset.Y);
_mouseDeltaLeft = offset / size;
_startPosLeft = _viewMousePos;
_startPos = _viewMousePos;
}
else
{

View File

@@ -85,7 +85,7 @@ namespace FlaxEditor.Viewport.Previews
var orbitRadius = 200.0f;
if (camera is ArcBallCamera arcBallCamera)
orbitRadius = arcBallCamera.OrbitRadius;
camera.SerArcBallView(new Quaternion(-0.08f, -0.92f, 0.31f, -0.23f), Vector3.Zero, orbitRadius);
camera.SetArcBallView(new Quaternion(-0.08f, -0.92f, 0.31f, -0.23f), Vector3.Zero, orbitRadius);
if (useWidgets)
{

View File

@@ -159,13 +159,14 @@ namespace FlaxEditor.Viewport.Previews
float prevScale = _viewScale;
_viewScale = Mathf.Clamp(_viewScale + delta * 0.24f, 0.001f, 20.0f);
// Move view to make use of the control much more soother
//float coeff = (prevScale + (_viewScale - prevScale)) / prevScale;
//_viewPos += (location * coeff - location) / _viewScale;
//_viewPos += location / _viewScale;
Vector2 sizeDelta = (_viewScale - prevScale) * _textureRect.Size;
// Compensate for the Rectangle.MakeScaled
Vector2 sizeDelta = (_viewScale - prevScale) * _textureRect.Size * 0.5f;
_viewPos += sizeDelta * 0.5f;
// Move to zoom position
Vector2 locationOnTexture = (location - _textureRect.Location) / _textureRect.Size;
_viewPos -= sizeDelta * locationOnTexture;
return true;
}

View File

@@ -1004,7 +1004,7 @@ namespace FlaxEditor.Windows.Assets
protected override void OnAssetLoaded()
{
_refreshOnLODsLoaded = true;
_preview.ViewportCamera.SerArcBallView(Asset.GetBox());
_preview.ViewportCamera.SetArcBallView(Asset.GetBox());
UpdateEffectsOnAsset();
// TODO: disable streaming for this model

View File

@@ -1097,7 +1097,7 @@ namespace FlaxEditor.Windows.Assets
protected override void OnAssetLoaded()
{
_refreshOnLODsLoaded = true;
_preview.ViewportCamera.SerArcBallView(Asset.GetBox());
_preview.ViewportCamera.SetArcBallView(Asset.GetBox());
UpdateEffectsOnAsset();
// TODO: disable streaming for this model