Skip to content
14 changes: 12 additions & 2 deletions AGXUnity/Cable.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AGXUnity.Utils;
using agxCable;
using AGXUnity.Utils;
using System;
using System.Collections.Generic;
using UnityEngine;
Expand Down Expand Up @@ -516,7 +517,7 @@ private void OnPropertyValueUpdate( CableProperties.Direction dir )
{
if ( Native != null ) {
Native.getCableProperties().setYoungsModulus( Convert.ToDouble( Properties[ dir ].YoungsModulus ), CableProperties.ToNative( dir ) );
Native.getCableProperties().setDamping( Convert.ToDouble( Properties[ dir ].Damping ), CableProperties.ToNative( dir ) );
Native.getCableProperties().setAttenuation( Convert.ToDouble( Properties[ dir ].Attenuation ), CableProperties.ToNative( dir ) );
Native.getCableProperties().setPoissonsRatio( Convert.ToDouble( Properties[ dir ].PoissonsRatio ), CableProperties.ToNative( dir ) );

var plasticityComponent = Native.getCablePlasticity();
Expand Down Expand Up @@ -566,5 +567,14 @@ public PointCurve.SegmentationResult SynchronizeRoutePointCurve()

return new PointCurve.SegmentationResult() { Error = float.PositiveInfinity, Successful = false };
}
protected override bool PerformMigration()
{
if ( m_serializationVersion < 3 ) {
foreach ( CableProperties.Direction dir in Enum.GetValues( typeof( CableProperties.Direction ) ) )
Properties[ dir ].Attenuation *= Time.fixedDeltaTime;
return true;
}
return false;
}
}
}
14 changes: 8 additions & 6 deletions AGXUnity/CableProperties.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;

namespace AGXUnity
{
Expand Down Expand Up @@ -79,16 +80,17 @@ public float YieldPoint
}

[SerializeField]
private float m_damping = 2.0f / 50;
[FormerlySerializedAs( "m_damping" )]
private float m_attenuation = 2.0f;

[ClampAboveZeroInInspector( true )]
[Tooltip( "The damping of the constraint" )]
public float Damping
[Tooltip( "The attenuation of the constraint" )]
public float Attenuation
{
get { return m_damping; }
get { return m_attenuation; }
set
{
m_damping = value;
m_attenuation = value;

OnValueCanged( Direction );
}
Expand Down Expand Up @@ -130,7 +132,7 @@ public CableProperties RestoreLocalDataFrom( agxCable.CableProperties native, ag

foreach ( Direction dir in Directions ) {
this[ dir ].YoungsModulus = Convert.ToSingle( native.getYoungsModulus( ToNative( dir ) ) );
this[ dir ].Damping = Convert.ToSingle( native.getDamping( ToNative( dir ) ) );
this[ dir ].Attenuation = Convert.ToSingle( native.getAttenuation( ToNative( dir ) ) );
this[ dir ].PoissonsRatio = Convert.ToSingle( native.getPoissonsRatio( ToNative( dir ) ) );
this[ dir ].YieldPoint = plasticity != null ?
Convert.ToSingle( plasticity.getYieldPoint( ToNative( dir ) ) ) :
Expand Down
43 changes: 27 additions & 16 deletions AGXUnity/Constraints/Constraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public void TraverseRowData<T>( Action<ElementaryConstraintRowData> callback, T
public void SetCompliance( float compliance );
public void SetCompliance( float compliance, TranslationalDof dof );
public void SetCompliance( float compliance, RotationalDof dof );
public void SetDamping( float damping );
public void SetDamping( float damping, TranslationalDof dof );
public void SetDamping( float damping, RotationalDof dof );
public void SetAttenuation( float attenuation );
public void SetAttenuation( float attenuation, TranslationalDof dof );
public void SetAttenuation( float attenuation, RotationalDof dof );
public void SetForceRange( RangeReal forceRange );
public void SetForceRange( RangeReal forceRange, TranslationalDof dof );
public void SetForceRange( RangeReal forceRange, RotationalDof dof );
Expand Down Expand Up @@ -480,36 +480,36 @@ public void SetCompliance( float compliance, RotationalDof dof )
}

/// <summary>
/// Set damping to all ordinary degrees of freedom (not including controllers)
/// Set attenuation to all ordinary degrees of freedom (not including controllers)
/// of this constraint.
/// </summary>
/// <param name="damping">New damping.</param>
public void SetDamping( float damping )
/// <param name="attenuation">New attenuation.</param>
public void SetAttenuation( float attenuation )
{
TraverseRowData( data => data.Damping = damping, TranslationalDof.All );
TraverseRowData( data => data.Damping = damping, RotationalDof.All );
TraverseRowData( data => data.Attenuation = attenuation, TranslationalDof.All );
TraverseRowData( data => data.Attenuation = attenuation, RotationalDof.All );
}

/// <summary>
/// Set damping to one or all translational ordinary degrees of freedom
/// Set attenuation to one or all translational ordinary degrees of freedom
/// (not including controllers) of this constraint.
/// </summary>
/// <param name="damping">New damping.</param>
/// <param name="attenuation">New attenuation.</param>
/// <param name="dof">Specific translational degree of freedom or all.</param>
public void SetDamping( float damping, TranslationalDof dof )
public void SetAttenuation( float attenuation, TranslationalDof dof )
{
TraverseRowData( data => data.Damping = damping, dof );
TraverseRowData( data => data.Attenuation = attenuation, dof );
}

/// <summary>
/// Set damping to one or all rotational ordinary degrees of freedom
/// Set attenuation to one or all rotational ordinary degrees of freedom
/// (not including controllers) of this constraint.
/// </summary>
/// <param name="damping">New damping.</param>
/// <param name="attenuation">New attenuation.</param>
/// <param name="dof">Specific rotational degree of freedom or all.</param>
public void SetDamping( float damping, RotationalDof dof )
public void SetAttenuation( float attenuation, RotationalDof dof )
{
TraverseRowData( data => data.Damping = damping, dof );
TraverseRowData( data => data.Attenuation = attenuation, dof );
}

/// <summary>
Expand Down Expand Up @@ -1028,5 +1028,16 @@ private void OnDrawGizmosSelected()

DrawGizmos( Color.green, AttachmentPair, true );
}

protected override bool PerformMigration()
{
if ( m_serializationVersion < 3 ) {
// Migrate from damping to attenuation
TraverseRowData( data => data.Attenuation *= Time.fixedDeltaTime, TranslationalDof.All );
TraverseRowData( data => data.Attenuation *= Time.fixedDeltaTime, RotationalDof.All );
return true;
}
return false;
}
}
}
4 changes: 2 additions & 2 deletions AGXUnity/Constraints/ElementaryConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public bool Enable
public int NumRows => RowData.Length;

/// <summary>
/// Data (compliance, damping etc.) for each row in this elementary constraint.
/// Data (compliance, attenuation etc.) for each row in this elementary constraint.
/// </summary>
[field: SerializeField]
public ElementaryConstraintRowData[] RowData { get; private set; }
Expand Down Expand Up @@ -174,7 +174,7 @@ public void MigrateInternalData( AGXUnity.Deprecated.ElementaryConstraint ec )
newRDs.Add( newRowData );
}
newRowData.Compliance = row.Compliance;
newRowData.Damping = row.Damping;
newRowData.Attenuation = row.Attenuation;
newRowData.ForceRange = row.ForceRange;
}
if ( newRDs.Count > 0 )
Expand Down
8 changes: 4 additions & 4 deletions AGXUnity/Constraints/ElementaryConstraintController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public float Compliance
}

/// <summary>
/// Get/set the damping of this controller (ignored for nonholonomic controllers).
/// Get/set the attenuation of this controller (ignored for nonholonomic controllers).
/// </summary>
[HideInInspector]
public float Damping
public float Attenuation
{
get { return RowData[ 0 ].Damping; }
set { RowData[ 0 ].Damping = value; }
get { return RowData[ 0 ].Attenuation; }
set { RowData[ 0 ].Attenuation = value; }
}

/// <summary>
Expand Down
23 changes: 11 additions & 12 deletions AGXUnity/Constraints/ElementaryConstraintRowData.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;

namespace AGXUnity
{
Expand Down Expand Up @@ -63,23 +64,24 @@ public float Compliance
}

/// <summary>
/// Damping of this row in the elementary constraint. Paired with property Damping.
/// Attenuation of this row in the elementary constraint. Paired with property Attenuation.
/// </summary>
[SerializeField]
private float m_damping = 2.0f / 50.0f;
[FormerlySerializedAs("m_damping")]
private float m_attenuation = 2.0f;

/// <summary>
/// Damping of this row in the elementary constraint.
/// Attenuation of this row in the elementary constraint.
/// </summary>
[ClampAboveZeroInInspector( true )]
public float Damping
public float Attenuation
{
get { return m_damping; }
get { return m_attenuation; }
set
{
m_damping = value;
m_attenuation = value;
if ( ElementaryConstraint?.Native != null )
ElementaryConstraint.Native.setDamping( m_damping, Row );
ElementaryConstraint.Native.setAttenuation( m_attenuation, Row );
}
}

Expand Down Expand Up @@ -116,10 +118,7 @@ public ElementaryConstraintRowData( ElementaryConstraint elementaryConstraint, i
m_row = row;
if ( tmpEc != null ) {
m_compliance = Convert.ToSingle( tmpEc.getCompliance( RowUInt ) );
// AGX Dynamics damping is optimized for 60 Hz simulations. Assuming
// a fixed update of 50 Hz in Unity we scale the damping by 60 / 50 = 1.2
// to transform the damping to 50 Hz.
m_damping = 1.2f * Convert.ToSingle( tmpEc.getDamping( RowUInt ) );
m_attenuation = Convert.ToSingle( tmpEc.getAttenuation( RowUInt ) );
m_forceRange = new RangeReal( tmpEc.getForceRange( RowUInt ) );
}
}
Expand All @@ -139,7 +138,7 @@ public ElementaryConstraintRowData( ElementaryConstraint elementaryConstraint, E
public void CopyFrom( ElementaryConstraintRowData source )
{
m_compliance = source.m_compliance;
m_damping = source.m_damping;
m_attenuation = source.m_attenuation;
m_forceRange = new RangeReal( source.m_forceRange );
}
}
Expand Down
2 changes: 1 addition & 1 deletion AGXUnity/Constraints/Generic1DOFControlledConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void RecreateElementary()
if ( old != null ) {
ConstraintController.Enable = old.Enable;
ConstraintController.Compliance = old.Compliance;
ConstraintController.Damping = old.Damping;
ConstraintController.Attenuation = old.Attenuation;
ConstraintController.ForceRange = old.ForceRange;
}

Expand Down
31 changes: 21 additions & 10 deletions AGXUnity/ContactMaterial.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;

namespace AGXUnity
{
Expand Down Expand Up @@ -211,24 +212,25 @@ public float Restitution
}

/// <summary>
/// Damping of the contact constraint, paired with property Damping.
/// Attenuation of the contact constraint, paired with property Attenuation.
/// </summary>
[SerializeField]
private float m_damping = 4.5f / 60.0f;
[FormerlySerializedAs( "m_damping" )]
private float m_attenuation = 4.5f;

/// <summary>
/// Damping of the contact constraint. Default: 4.5 / 60 = 0.075.
/// Attenuation of the contact constraint. Default: 2.
/// </summary>
[ClampAboveZeroInInspector( true )]
[Tooltip( "This defines the time it should take for the solver to restore an overlap. A higher value will lead to higher restoration forces as overlaps should be minimized faster" )]
public float Damping
[Tooltip( "This defines the number of integration steps the solver is given to satisfy the constraint. A higher value will lead to higher restoration forces as overlaps should be minimized faster" )]
public float Attenuation
{
get { return m_damping; }
get { return m_attenuation; }
set
{
m_damping = value;
m_attenuation = value;
if ( Native != null )
Native.setDamping( m_damping );
Native.setAttenuation( m_attenuation );
}
}

Expand Down Expand Up @@ -266,7 +268,7 @@ public float AdhesiveForce
/// at higher overlap, the (usual) contact force.
/// </summary>
[ClampAboveZeroInInspector( true )]
[Tooltip( "allowed overlap from surface for resting contact. At this overlap, no force is applied. At lower overlap, the adhesion force will work, at higher overlap, the (usual) contact force" )]
[Tooltip( "Allowed overlap from surface for resting contact. At this overlap, no force is applied. At lower overlap, the adhesion force will work, at higher overlap, the (usual) contact force" )]
public float AdhesiveOverlap
{
get { return m_adhesiveOverlap; }
Expand Down Expand Up @@ -385,7 +387,7 @@ public ContactMaterial RestoreLocalDataFrom( agx.ContactMaterial contactMaterial
FrictionCoefficients = new Vector2( Convert.ToSingle( contactMaterial.getFrictionCoefficient( agx.ContactMaterial.FrictionDirection.PRIMARY_DIRECTION ) ),
Convert.ToSingle( contactMaterial.getFrictionCoefficient( agx.ContactMaterial.FrictionDirection.SECONDARY_DIRECTION ) ) );
Restitution = Convert.ToSingle( contactMaterial.getRestitution() );
Damping = Convert.ToSingle( contactMaterial.getDamping() );
Attenuation = Convert.ToSingle( contactMaterial.getAttenuation() );
AdhesiveForce = Convert.ToSingle( contactMaterial.getAdhesion() );
AdhesiveOverlap = Convert.ToSingle( contactMaterial.getAdhesiveOverlap() );
UseContactArea = contactMaterial.getUseContactAreaApproach();
Expand Down Expand Up @@ -508,5 +510,14 @@ private void OnFrictionModelNativeInstanceChanged( agx.FrictionModel frictionMod
if ( Native != null )
Native.setFrictionModel( frictionModel );
}

protected override bool PerformMigration()
{
if ( m_serializationVersion < 3 ) {
m_attenuation *= Time.fixedDeltaTime;
return true;
}
return false;
}
}
}
4 changes: 2 additions & 2 deletions AGXUnity/Deprecated/ElementaryConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ public bool Enable
public int NumRows { get { return m_rowData.Length; } }

/// <summary>
/// Data (compliance, damping etc.) for each row in this elementary constraint.
/// Data (compliance, attenuation etc.) for each row in this elementary constraint.
/// Paired with property RowData.
/// </summary>
[SerializeField]
private ElementaryConstraintRowData[] m_rowData = null;

/// <summary>
/// Data (compliance, damping etc.) for each row in this elementary constraint.
/// Data (compliance, attenuation etc.) for each row in this elementary constraint.
/// </summary>
public ElementaryConstraintRowData[] RowData { get { return m_rowData; } }

Expand Down
8 changes: 4 additions & 4 deletions AGXUnity/Deprecated/ElementaryConstraintController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public float Compliance
}

/// <summary>
/// Get/set the damping of this controller (ignored for nonholonomic controllers).
/// Get/set the attenuation of this controller (ignored for nonholonomic controllers).
/// </summary>
[HideInInspector]
public float Damping
public float Attenuation
{
get { return RowData[ 0 ].Damping; }
set { RowData[ 0 ].Damping = value; }
get { return RowData[ 0 ].Attenuation; }
set { RowData[ 0 ].Attenuation = value; }
}

/// <summary>
Expand Down
Loading
Loading