Expose and document various APIs of Visject for plugins to use
This commit is contained in:
@@ -482,7 +482,7 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
var startPos = PointToParent(ref center);
|
var startPos = PointToParent(ref center);
|
||||||
targetState.GetConnectionEndPoint(ref startPos, out var endPos);
|
targetState.GetConnectionEndPoint(ref startPos, out var endPos);
|
||||||
var color = style.Foreground;
|
var color = style.Foreground;
|
||||||
StateMachineState.DrawConnection(ref startPos, ref endPos, ref color);
|
SurfaceStyle.DrawStraightConnection(startPos, endPos, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,7 +512,7 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void DrawConnectingLine(ref Float2 startPos, ref Float2 endPos, ref Color color)
|
public void DrawConnectingLine(ref Float2 startPos, ref Float2 endPos, ref Color color)
|
||||||
{
|
{
|
||||||
StateMachineState.DrawConnection(ref startPos, ref endPos, ref color);
|
SurfaceStyle.DrawStraightConnection(startPos, endPos, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -676,38 +676,6 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Draws the connection between two state machine nodes.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="startPos">The start position.</param>
|
|
||||||
/// <param name="endPos">The end position.</param>
|
|
||||||
/// <param name="color">The line color.</param>
|
|
||||||
public static void DrawConnection(ref Float2 startPos, ref Float2 endPos, ref Color color)
|
|
||||||
{
|
|
||||||
var sub = endPos - startPos;
|
|
||||||
var length = sub.Length;
|
|
||||||
if (length > Mathf.Epsilon)
|
|
||||||
{
|
|
||||||
var dir = sub / length;
|
|
||||||
var arrowRect = new Rectangle(0, 0, 16.0f, 16.0f);
|
|
||||||
float rotation = Float2.Dot(dir, Float2.UnitY);
|
|
||||||
if (endPos.X < startPos.X)
|
|
||||||
rotation = 2 - rotation;
|
|
||||||
var sprite = Editor.Instance.Icons.VisjectArrowClosed32;
|
|
||||||
var arrowTransform =
|
|
||||||
Matrix3x3.Translation2D(-6.5f, -8) *
|
|
||||||
Matrix3x3.RotationZ(rotation * Mathf.PiOverTwo) *
|
|
||||||
Matrix3x3.Translation2D(endPos - dir * 8);
|
|
||||||
|
|
||||||
Render2D.PushTransform(ref arrowTransform);
|
|
||||||
Render2D.DrawSprite(sprite, arrowRect, color);
|
|
||||||
Render2D.PopTransform();
|
|
||||||
|
|
||||||
endPos -= dir * 4.0f;
|
|
||||||
}
|
|
||||||
Render2D.DrawLine(startPos, endPos, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the connection end point for the given input position. Puts the end point near the edge of the node bounds.
|
/// Gets the connection end point for the given input position. Puts the end point near the edge of the node bounds.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1308,7 +1276,7 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
isMouseOver = Float2.DistanceSquared(ref mousePosition, ref point) < 25.0f;
|
isMouseOver = Float2.DistanceSquared(ref mousePosition, ref point) < 25.0f;
|
||||||
}
|
}
|
||||||
var color = isMouseOver ? Color.Wheat : t.LineColor;
|
var color = isMouseOver ? Color.Wheat : t.LineColor;
|
||||||
DrawConnection(ref t.StartPos, ref t.EndPos, ref color);
|
SurfaceStyle.DrawStraightConnection(t.StartPos, t.EndPos, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1337,7 +1305,7 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void DrawConnectingLine(ref Float2 startPos, ref Float2 endPos, ref Color color)
|
public void DrawConnectingLine(ref Float2 startPos, ref Float2 endPos, ref Color color)
|
||||||
{
|
{
|
||||||
DrawConnection(ref startPos, ref endPos, ref color);
|
SurfaceStyle.DrawStraightConnection(startPos, endPos, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace FlaxEditor.Surface
|
|||||||
var editor = Editor.Instance;
|
var editor = Editor.Instance;
|
||||||
var style = SurfaceStyle.CreateStyleHandler(editor);
|
var style = SurfaceStyle.CreateStyleHandler(editor);
|
||||||
style.DrawBox = DrawBox;
|
style.DrawBox = DrawBox;
|
||||||
style.DrawConnection = DrawConnection;
|
style.DrawConnection = SurfaceStyle.DrawStraightConnection;
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,11 +49,6 @@ namespace FlaxEditor.Surface
|
|||||||
Render2D.FillRectangle(rect, color);
|
Render2D.FillRectangle(rect, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DrawConnection(Float2 start, Float2 end, Color color, float thickness)
|
|
||||||
{
|
|
||||||
Archetypes.Animation.StateMachineStateBase.DrawConnection(ref start, ref end, ref color);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnActiveContextMenuVisibleChanged(Control activeCM)
|
private void OnActiveContextMenuVisibleChanged(Control activeCM)
|
||||||
{
|
{
|
||||||
_nodesCache.Wait();
|
_nodesCache.Wait();
|
||||||
|
|||||||
@@ -295,5 +295,38 @@ namespace FlaxEditor.Surface
|
|||||||
Background = editor.UI.VisjectSurfaceBackground,
|
Background = editor.UI.VisjectSurfaceBackground,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Draws a simple straight connection between two locations.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="startPos">The start position.</param>
|
||||||
|
/// <param name="endPos">The end position.</param>
|
||||||
|
/// <param name="color">The line color.</param>
|
||||||
|
/// <param name="thickness">The line thickness.</param>
|
||||||
|
public static void DrawStraightConnection(Float2 startPos, Float2 endPos, Color color, float thickness = 1.0f)
|
||||||
|
{
|
||||||
|
var sub = endPos - startPos;
|
||||||
|
var length = sub.Length;
|
||||||
|
if (length > Mathf.Epsilon)
|
||||||
|
{
|
||||||
|
var dir = sub / length;
|
||||||
|
var arrowRect = new Rectangle(0, 0, 16.0f, 16.0f);
|
||||||
|
float rotation = Float2.Dot(dir, Float2.UnitY);
|
||||||
|
if (endPos.X < startPos.X)
|
||||||
|
rotation = 2 - rotation;
|
||||||
|
var sprite = Editor.Instance.Icons.VisjectArrowClosed32;
|
||||||
|
var arrowTransform =
|
||||||
|
Matrix3x3.Translation2D(-6.5f, -8) *
|
||||||
|
Matrix3x3.RotationZ(rotation * Mathf.PiOverTwo) *
|
||||||
|
Matrix3x3.Translation2D(endPos - dir * 8);
|
||||||
|
|
||||||
|
Render2D.PushTransform(ref arrowTransform);
|
||||||
|
Render2D.DrawSprite(sprite, arrowRect, color);
|
||||||
|
Render2D.PopTransform();
|
||||||
|
|
||||||
|
endPos -= dir * 4.0f;
|
||||||
|
}
|
||||||
|
Render2D.DrawLine(startPos, endPos, color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,15 @@ namespace FlaxEditor.Surface
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Utility for easy nodes archetypes generation for Visject Surface based on scripting types.
|
/// Utility for easy nodes archetypes generation for Visject Surface based on scripting types.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class NodesCache
|
[HideInEditor]
|
||||||
|
public class NodesCache
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Delegate for scripting types filtering into cache.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="scriptType">The input type to process.</param>
|
||||||
|
/// <param name="cache">Node groups cache that can be used for reusing groups for different nodes.</param>
|
||||||
|
/// <param name="version">The cache version number. Can be used to reject any cached data after <see cref="NodesCache"/> rebuilt.</param>
|
||||||
public delegate void IterateType(ScriptType scriptType, Dictionary<KeyValuePair<string, ushort>, GroupArchetype> cache, int version);
|
public delegate void IterateType(ScriptType scriptType, Dictionary<KeyValuePair<string, ushort>, GroupArchetype> cache, int version);
|
||||||
|
|
||||||
internal static readonly List<NodesCache> Caches = new List<NodesCache>(8);
|
internal static readonly List<NodesCache> Caches = new List<NodesCache>(8);
|
||||||
@@ -33,11 +40,18 @@ namespace FlaxEditor.Surface
|
|||||||
private VisjectCM _taskContextMenu;
|
private VisjectCM _taskContextMenu;
|
||||||
private Dictionary<KeyValuePair<string, ushort>, GroupArchetype> _cache;
|
private Dictionary<KeyValuePair<string, ushort>, GroupArchetype> _cache;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="NodesCache"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="iterator">The iterator callback to build node types from Scripting.</param>
|
||||||
public NodesCache(IterateType iterator)
|
public NodesCache(IterateType iterator)
|
||||||
{
|
{
|
||||||
_iterator = iterator;
|
_iterator = iterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Waits for the async caching job to finish.
|
||||||
|
/// </summary>
|
||||||
public void Wait()
|
public void Wait()
|
||||||
{
|
{
|
||||||
if (_task != null)
|
if (_task != null)
|
||||||
@@ -48,6 +62,9 @@ namespace FlaxEditor.Surface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clears cache.
|
||||||
|
/// </summary>
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
Wait();
|
Wait();
|
||||||
@@ -62,6 +79,10 @@ namespace FlaxEditor.Surface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the Visject Context Menu to contain current nodes.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="contextMenu">The output context menu to setup.</param>
|
||||||
public void Get(VisjectCM contextMenu)
|
public void Get(VisjectCM contextMenu)
|
||||||
{
|
{
|
||||||
Profiler.BeginEvent("Setup Context Menu");
|
Profiler.BeginEvent("Setup Context Menu");
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace FlaxEditor.Surface
|
|||||||
/// The base interface for editor windows that use <see cref="FlaxEditor.Surface.VisjectSurface"/> for content editing.
|
/// The base interface for editor windows that use <see cref="FlaxEditor.Surface.VisjectSurface"/> for content editing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <seealso cref="FlaxEditor.Surface.IVisjectSurfaceOwner" />
|
/// <seealso cref="FlaxEditor.Surface.IVisjectSurfaceOwner" />
|
||||||
interface IVisjectSurfaceWindow : IVisjectSurfaceOwner
|
public interface IVisjectSurfaceWindow : IVisjectSurfaceOwner
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the asset edited by the window.
|
/// Gets the asset edited by the window.
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using FlaxEditor.Gizmo;
|
using FlaxEditor.Gizmo;
|
||||||
using FlaxEditor.Content;
|
using FlaxEditor.Content;
|
||||||
using FlaxEditor.GUI.Tree;
|
using FlaxEditor.GUI.Tree;
|
||||||
@@ -14,7 +13,6 @@ using FlaxEditor.Scripting;
|
|||||||
using FlaxEditor.States;
|
using FlaxEditor.States;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using FlaxEngine.GUI;
|
using FlaxEngine.GUI;
|
||||||
using static FlaxEditor.GUI.ItemsListContextMenu;
|
|
||||||
|
|
||||||
namespace FlaxEditor.Windows
|
namespace FlaxEditor.Windows
|
||||||
{
|
{
|
||||||
@@ -24,8 +22,6 @@ namespace FlaxEditor.Windows
|
|||||||
/// <seealso cref="FlaxEditor.Windows.SceneEditorWindow" />
|
/// <seealso cref="FlaxEditor.Windows.SceneEditorWindow" />
|
||||||
public partial class SceneTreeWindow : SceneEditorWindow
|
public partial class SceneTreeWindow : SceneEditorWindow
|
||||||
{
|
{
|
||||||
public Panel SceneTreePanel => _sceneTreePanel;
|
|
||||||
|
|
||||||
private TextBox _searchBox;
|
private TextBox _searchBox;
|
||||||
private Tree _tree;
|
private Tree _tree;
|
||||||
private Panel _sceneTreePanel;
|
private Panel _sceneTreePanel;
|
||||||
@@ -37,6 +33,11 @@ namespace FlaxEditor.Windows
|
|||||||
private DragScriptItems _dragScriptItems;
|
private DragScriptItems _dragScriptItems;
|
||||||
private DragHandlers _dragHandlers;
|
private DragHandlers _dragHandlers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Scene tree panel.
|
||||||
|
/// </summary>
|
||||||
|
public Panel SceneTreePanel => _sceneTreePanel;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SceneTreeWindow"/> class.
|
/// Initializes a new instance of the <see cref="SceneTreeWindow"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ public:
|
|||||||
/// Visject graph parameter.
|
/// Visject graph parameter.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <seealso cref="GraphParameter" />
|
/// <seealso cref="GraphParameter" />
|
||||||
API_CLASS() class VisjectGraphParameter : public GraphParameter
|
API_CLASS() class FLAXENGINE_API VisjectGraphParameter : public GraphParameter
|
||||||
{
|
{
|
||||||
DECLARE_SCRIPTING_TYPE_WITH_CONSTRUCTOR_IMPL(VisjectGraphParameter, GraphParameter);
|
DECLARE_SCRIPTING_TYPE_WITH_CONSTRUCTOR_IMPL(VisjectGraphParameter, GraphParameter);
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -5,10 +5,6 @@
|
|||||||
#include "Engine/Serialization/ReadStream.h"
|
#include "Engine/Serialization/ReadStream.h"
|
||||||
#include "Engine/Serialization/WriteStream.h"
|
#include "Engine/Serialization/WriteStream.h"
|
||||||
|
|
||||||
VisjectMeta::VisjectMeta()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool VisjectMeta::Load(ReadStream* stream, bool loadData)
|
bool VisjectMeta::Load(ReadStream* stream, bool loadData)
|
||||||
{
|
{
|
||||||
Release();
|
Release();
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Visject metadata container
|
/// Visject metadata container
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class VisjectMeta
|
class FLAXENGINE_API VisjectMeta
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -27,19 +27,6 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
Array<Entry, FixedAllocation<8>> Entries;
|
Array<Entry, FixedAllocation<8>> Entries;
|
||||||
|
|
||||||
public:
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="VisjectMeta"/> class.
|
|
||||||
/// </summary>
|
|
||||||
VisjectMeta();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Finalizes an instance of the <see cref="VisjectMeta"/> class.
|
|
||||||
/// </summary>
|
|
||||||
~VisjectMeta()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Load from the stream
|
/// Load from the stream
|
||||||
|
|||||||
Reference in New Issue
Block a user