Skip to content

Commit caf123e

Browse files
authored
Merge pull request #195 from Algoryx/feature/movable-terrain-updates
Update MovableTerrain with Automatic placment functionality
2 parents 3d6b25a + fcc2a6f commit caf123e

15 files changed

Lines changed: 1184 additions & 123 deletions

AGXUnity/Attributes.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ public bool IsValid( Vector2Int value )
196196

197197
public bool OptionalOverrideIsValid( object value )
198198
{
199-
var wrappedType = value.GetType().GenericTypeArguments[ 0 ];
200-
var ooType = typeof( OptionalOverrideValue<> ).MakeGenericType( wrappedType );
201-
var wrappedVal = ooType.GetProperty( "OverrideValue" ).GetValue( value );
202-
var validator = this.GetType().GetMethod( "IsValid", new Type[] { wrappedType } );
199+
var wrappedType = value.GetType().GenericTypeArguments[0];
200+
var ooType = typeof(OptionalOverrideValue<>).MakeGenericType(wrappedType);
201+
var wrappedVal = ooType.GetProperty("OverrideValue").GetValue(value);
202+
var validator = this.GetType().GetMethod("IsValid", new Type[] { wrappedType });
203203
if ( validator == null )
204204
return true;
205205
return (bool)validator.Invoke( this, new object[] { wrappedVal } );
@@ -244,6 +244,14 @@ public DynamicallyShowInInspector( string name, bool isMethod = false, bool inve
244244
public bool Invert { get; private set; }
245245
}
246246

247+
[AttributeUsage( AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false )]
248+
public class DelayedInspectorAttribute : Attribute
249+
{
250+
public DelayedInspectorAttribute()
251+
{
252+
}
253+
}
254+
247255
[AttributeUsage( AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false )]
248256
public class RuntimeValue : Attribute
249257
{

AGXUnity/IO/OpenPLX/OpenPLXUnityMapper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,11 +805,12 @@ GameObject MapTerrain( openplx.Terrain.Terrain terrain )
805805
rbComp.MotionControl = agx.RigidBody.MotionControl.KINEMATICS;
806806

807807
var terrainComp = terrainGO.AddComponent<MovableTerrain>();
808+
terrainComp.PlacementMode = MovableTerrain.Placement.Manual;
808809

809810
terrainComp.ElementSize = (float)terrain.element_size();
810811
terrainComp.MaximumDepth = (float)terrain.max_depth();
811812
terrainComp.SizeCells = new Vector2Int( (int)terrain.num_elements_y(), (int)terrain.num_elements_x() );
812-
terrainComp.InvertDepthDirection = false;
813+
terrainComp.MaxDepthAsInitialHeight = false;
813814

814815
var terrainMat = terrain.material();
815816
if ( !terrainMat.is_default_terrain_material() ) {

AGXUnity/Model/DeformableTerrainBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public DeformableTerrainProperties TerrainProperties
122122
[IgnoreSynchronization]
123123
[DisableInRuntimeInspector]
124124
[ClampAboveZeroInInspector( true )]
125+
[DelayedInspector]
125126
public float MaximumDepth
126127
{
127128
get { return m_maximumDepth; }

AGXUnity/Model/DeformableTerrainFailureVolume.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,40 @@ namespace AGXUnity.Model
1010
[HelpURL( "https://us.download.algoryx.se/AGXUnity/documentation/current/editor_interface.html#soil-failure-volumes" )]
1111
public class DeformableTerrainFailureVolume : ScriptComponent
1212
{
13+
[field: SerializeField]
1314
public bool AddAllTerrainsOnStart { get; set; } = true;
1415

15-
private HashSet<DeformableTerrainBase> m_terrains = new HashSet<DeformableTerrainBase>();
16+
[field: SerializeField]
17+
private List<DeformableTerrainBase> m_terrains = new List<DeformableTerrainBase>();
1618

1719
public DeformableTerrainBase[] Terrains => m_terrains.ToArray();
1820

1921
public bool Add( DeformableTerrainBase terrain )
2022
{
21-
return m_terrains.Add( terrain );
23+
if ( m_terrains.Contains( terrain ) ) {
24+
Debug.LogWarning( $"Failure volume '{name}' already contains terrain '{terrain.name}'" );
25+
return false;
26+
}
27+
m_terrains.Add( terrain );
28+
return true;
2229
}
2330

2431
public bool Remove( DeformableTerrainBase terrain )
2532
{
33+
if ( !m_terrains.Contains( terrain ) ) {
34+
Debug.LogWarning( $"Failure volume '{name}' does not contain terrain '{terrain.name}'" );
35+
return false;
36+
}
2637
return m_terrains.Remove( terrain );
2738
}
2839

2940
protected override bool Initialize()
3041
{
3142
if ( AddAllTerrainsOnStart ) {
3243
#if UNITY_2022_2_OR_NEWER
33-
m_terrains.UnionWith( FindObjectsByType<DeformableTerrainBase>( FindObjectsSortMode.None ) );
44+
m_terrains.AddRange( FindObjectsByType<DeformableTerrainBase>( FindObjectsSortMode.None ).Where( t => !m_terrains.Contains( t ) ) );
3445
#else
35-
m_terrains.UnionWith( FindObjectsOfType<DeformableTerrainBase>() );
46+
m_terrains.AddRange( FindObjectsOfType<DeformableTerrainBase>().Where( t => !m_terrains.Contains( t ) ) );
3647
#endif
3748
}
3849
return base.Initialize();
@@ -59,5 +70,4 @@ private void TriggerFailure()
5970
terr.ConvertToDynamicMassInShape( shape );
6071
}
6172
}
62-
6373
}

0 commit comments

Comments
 (0)