Skip to content

Commit

Permalink
Merge pull request #171 from Algoryx/feature/eye-node-friction
Browse files Browse the repository at this point in the history
Added support for extra route node data and added eye node friction
  • Loading branch information
FilipAlg authored Nov 21, 2024
2 parents e4ecb89 + 1fe298d commit 7206048
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
8 changes: 8 additions & 0 deletions AGXUnity/RouteNode.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
27 changes: 27 additions & 0 deletions AGXUnity/WireRouteNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/// <summary>
/// Representation of nodes, used while routing.
/// </summary>
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
}
}
11 changes: 11 additions & 0 deletions Editor/AGXUnityEditor/Tools/RouteNodeTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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( "<b>Eye Node Data</b>", 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;
Expand Down
6 changes: 4 additions & 2 deletions Editor/AGXUnityEditor/Tools/RouteTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down

0 comments on commit 7206048

Please sign in to comment.