Expose and document various APIs of Visject for plugins to use

This commit is contained in:
Wojtek Figat
2024-02-18 11:06:42 +01:00
parent dfbde5f8eb
commit d76b5234c5
9 changed files with 68 additions and 67 deletions

View File

@@ -482,7 +482,7 @@ namespace FlaxEditor.Surface.Archetypes
var startPos = PointToParent(ref center);
targetState.GetConnectionEndPoint(ref startPos, out var endPos);
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 />
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 />
@@ -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>
/// Gets the connection end point for the given input position. Puts the end point near the edge of the node bounds.
/// </summary>
@@ -1308,7 +1276,7 @@ namespace FlaxEditor.Surface.Archetypes
isMouseOver = Float2.DistanceSquared(ref mousePosition, ref point) < 25.0f;
}
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 />
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 />

View File

@@ -31,7 +31,7 @@ namespace FlaxEditor.Surface
var editor = Editor.Instance;
var style = SurfaceStyle.CreateStyleHandler(editor);
style.DrawBox = DrawBox;
style.DrawConnection = DrawConnection;
style.DrawConnection = SurfaceStyle.DrawStraightConnection;
return style;
}
@@ -49,11 +49,6 @@ namespace FlaxEditor.Surface
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)
{
_nodesCache.Wait();

View File

@@ -295,5 +295,38 @@ namespace FlaxEditor.Surface
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);
}
}
}

View File

@@ -20,8 +20,15 @@ namespace FlaxEditor.Surface
/// <summary>
/// Utility for easy nodes archetypes generation for Visject Surface based on scripting types.
/// </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);
internal static readonly List<NodesCache> Caches = new List<NodesCache>(8);
@@ -33,11 +40,18 @@ namespace FlaxEditor.Surface
private VisjectCM _taskContextMenu;
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)
{
_iterator = iterator;
}
/// <summary>
/// Waits for the async caching job to finish.
/// </summary>
public void Wait()
{
if (_task != null)
@@ -48,6 +62,9 @@ namespace FlaxEditor.Surface
}
}
/// <summary>
/// Clears cache.
/// </summary>
public void Clear()
{
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)
{
Profiler.BeginEvent("Setup Context Menu");

View File

@@ -25,7 +25,7 @@ namespace FlaxEditor.Surface
/// The base interface for editor windows that use <see cref="FlaxEditor.Surface.VisjectSurface"/> for content editing.
/// </summary>
/// <seealso cref="FlaxEditor.Surface.IVisjectSurfaceOwner" />
interface IVisjectSurfaceWindow : IVisjectSurfaceOwner
public interface IVisjectSurfaceWindow : IVisjectSurfaceOwner
{
/// <summary>
/// Gets the asset edited by the window.

View File

@@ -2,7 +2,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FlaxEditor.Gizmo;
using FlaxEditor.Content;
using FlaxEditor.GUI.Tree;
@@ -14,7 +13,6 @@ using FlaxEditor.Scripting;
using FlaxEditor.States;
using FlaxEngine;
using FlaxEngine.GUI;
using static FlaxEditor.GUI.ItemsListContextMenu;
namespace FlaxEditor.Windows
{
@@ -24,8 +22,6 @@ namespace FlaxEditor.Windows
/// <seealso cref="FlaxEditor.Windows.SceneEditorWindow" />
public partial class SceneTreeWindow : SceneEditorWindow
{
public Panel SceneTreePanel => _sceneTreePanel;
private TextBox _searchBox;
private Tree _tree;
private Panel _sceneTreePanel;
@@ -37,6 +33,11 @@ namespace FlaxEditor.Windows
private DragScriptItems _dragScriptItems;
private DragHandlers _dragHandlers;
/// <summary>
/// Scene tree panel.
/// </summary>
public Panel SceneTreePanel => _sceneTreePanel;
/// <summary>
/// Initializes a new instance of the <see cref="SceneTreeWindow"/> class.
/// </summary>

View File

@@ -101,7 +101,7 @@ public:
/// Visject graph parameter.
/// </summary>
/// <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);
public:

View File

@@ -5,10 +5,6 @@
#include "Engine/Serialization/ReadStream.h"
#include "Engine/Serialization/WriteStream.h"
VisjectMeta::VisjectMeta()
{
}
bool VisjectMeta::Load(ReadStream* stream, bool loadData)
{
Release();

View File

@@ -8,7 +8,7 @@
/// <summary>
/// Visject metadata container
/// </summary>
class VisjectMeta
class FLAXENGINE_API VisjectMeta
{
public:
/// <summary>
@@ -27,19 +27,6 @@ public:
/// </summary>
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:
/// <summary>
/// Load from the stream