From 1fe298dbaa8605d7f745cca7870bda79110396e2 Mon Sep 17 00:00:00 2001 From: Filip Henningsson Date: Fri, 15 Nov 2024 09:58:35 +0100 Subject: [PATCH] Added support for extra route node data and added eye node friction --- AGXUnity/RouteNode.cs | 8 ++++++ AGXUnity/WireRouteNode.cs | 27 ++++++++++++++++++++ Editor/AGXUnityEditor/Tools/RouteNodeTool.cs | 11 ++++++++ Editor/AGXUnityEditor/Tools/RouteTool.cs | 6 +++-- 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/AGXUnity/RouteNode.cs b/AGXUnity/RouteNode.cs index 6c1624f5..231efcbc 100644 --- a/AGXUnity/RouteNode.cs +++ b/AGXUnity/RouteNode.cs @@ -1,9 +1,17 @@ using System; +using UnityEngine; namespace AGXUnity { + public interface IExtraNodeData + { + public abstract bool Initialize( WireRouteNode parent ); + } + [Serializable] public abstract class RouteNode : IFrame { + [field: SerializeReference] + public IExtraNodeData NodeData { get; protected set; } = null; } } diff --git a/AGXUnity/WireRouteNode.cs b/AGXUnity/WireRouteNode.cs index fc6f847b..b0e60718 100644 --- a/AGXUnity/WireRouteNode.cs +++ b/AGXUnity/WireRouteNode.cs @@ -5,6 +5,23 @@ namespace AGXUnity { + + [Serializable] + public class EyeNodeData : IExtraNodeData + { + + [field: SerializeField] + public Vector2 FrictionCoefficients { get; set; } = new Vector2( 0, 0 ); + + + public virtual bool Initialize( WireRouteNode parent ) + { + parent.Native.getMaterial().setFrictionCoefficient( FrictionCoefficients.x, agxWire.NodeMaterial.Direction.NEGATIVE ); + parent.Native.getMaterial().setFrictionCoefficient( FrictionCoefficients.y, agxWire.NodeMaterial.Direction.POSITIVE ); + return true; + } + } + /// /// Representation of nodes, used while routing. /// @@ -129,6 +146,9 @@ protected override bool Initialize() Native = Winch.Native != null ? Winch.Native.getStopNode() : null; } + if ( NodeData != null && Native != null ) + NodeData.Initialize( this ); + return Native != null; } @@ -151,6 +171,13 @@ private void OnNodeType() } else if ( Wire != null && Type == Wire.NodeType.WinchNode ) Winch = new WireWinch(); + + if ( Type == Wire.NodeType.EyeNode ) { + if ( NodeData is not EyeNodeData ) + NodeData = new EyeNodeData(); + } + else + NodeData = null; } } } diff --git a/Editor/AGXUnityEditor/Tools/RouteNodeTool.cs b/Editor/AGXUnityEditor/Tools/RouteNodeTool.cs index 7428fa39..2ff9ae7f 100644 --- a/Editor/AGXUnityEditor/Tools/RouteNodeTool.cs +++ b/Editor/AGXUnityEditor/Tools/RouteNodeTool.cs @@ -79,6 +79,17 @@ public override void OnSceneViewGUI( SceneView sceneView ) Visual.SetTransform( Node.Position, Node.Rotation, radius, true, 1.2f * m_radius(), Mathf.Max( 1.5f * m_radius(), 0.25f ) ); } + public override void OnPostTargetMembersGUI() + { + if ( Node.NodeData is EyeNodeData end ) { + EditorGUILayout.LabelField( "Eye Node Data", InspectorGUISkin.Instance.Label ); + using ( new InspectorGUI.IndentScope() ) { + end.FrictionCoefficients = InspectorGUI.Vector2Field( AGXUnity.Utils.GUI.MakeLabel( "Friction Coefficients" ), end.FrictionCoefficients, "F,B" ); + } + } + base.OnPostTargetMembersGUI(); + } + private void OnClick( Utils.Raycast.Result result, Utils.VisualPrimitive primitive ) { Selected = true; diff --git a/Editor/AGXUnityEditor/Tools/RouteTool.cs b/Editor/AGXUnityEditor/Tools/RouteTool.cs index ef5935cc..7d5fd1d8 100644 --- a/Editor/AGXUnityEditor/Tools/RouteTool.cs +++ b/Editor/AGXUnityEditor/Tools/RouteTool.cs @@ -278,11 +278,13 @@ private void RouteGUI() using ( InspectorGUI.IndentScope.Single ) { var foldoutState = NodeFoldout( validatedNode ); if ( foldoutState.Foldout ) { - OnPreFrameGUI( node ); + var tool = GetRouteNodeTool( node ); + tool.OnPreTargetMembersGUI(); + OnPreFrameGUI( node ); InspectorGUI.HandleFrame( node, 1 ); - OnPostFrameGUI( node ); + tool.OnPostTargetMembersGUI(); } if ( listOpNode == null && foldoutState.ButtonPressed )