Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a19cb8b
Added initial support for non-homogeneous materials in with the pager
FilipAlg Aug 5, 2024
4d98e3b
Merge branch 'master' into feature/non-homogeneous-pager
FilipAlg Aug 9, 2024
4994804
Merge branch 'master' into feature/non-homogeneous-pager
FilipAlg Sep 17, 2024
a22a425
Reduced memory allocations in terrain callbacks
FilipAlg Sep 17, 2024
46d8906
Fixed agx warning
FilipAlg Sep 17, 2024
d270183
Merge branch 'master' into feature/non-homogeneous-pager
FilipAlg May 27, 2025
033ecff
Update prototype
FilipAlg May 28, 2025
29adfe3
Merge remote-tracking branch 'origin/master' into feature/non-homogen…
FilipAlg May 19, 2026
a7a41fb
Set materials on data source directy
FilipAlg May 20, 2026
090fa2f
Update terrain pager to allow different soil types
FilipAlg May 25, 2026
9145b9a
Fix formating
FilipAlg May 25, 2026
f538e41
Fix version gate in editor code
FilipAlg May 26, 2026
b71020f
Merge branch 'master' into feature/non-homogeneous-pager
FilipAlg May 29, 2026
73d53af
Fix Missing semicolon
FilipAlg May 29, 2026
89e7d5b
Fix deprecation warnings
FilipAlg May 29, 2026
e5fba35
Update agx dll
FilipAlg May 29, 2026
346a74b
Add Missing migrations
FilipAlg Jun 2, 2026
3e2b6d9
Add options to mark geometries as track support geometriesand/or wire…
FilipAlg Jun 2, 2026
35756a9
Add pulley test
FilipAlg Jun 3, 2026
c2b8de9
Add tests for track support geometry
FilipAlg Jun 3, 2026
255ac61
Ignore lidar tests for now
FilipAlg Jun 4, 2026
ce3e917
Update tests to recreate the simulation for each test run
FilipAlg Jun 5, 2026
cf73a10
Force GC after importing OpenPLX
FilipAlg Jun 5, 2026
59ea1aa
Fix null reference error when track friction model is not set in a co…
FilipAlg Jun 5, 2026
ea875da
Fix RigidBody mass incorrectly being updated when shapes are reenabled
FilipAlg Jun 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions AGXUnity/Collide/Shape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,30 @@ public ShapeMaterial Material
}
}

[SerializeField]
private bool m_isPulley = false;

/// <summary>
/// When enabled, Wires will snap onto this geometry to simulate a sheave or pulley geometry without having to rely on contacts
/// </summary>
[Tooltip( "When enabled, Wires will snap onto this geometry to simulate a sheave or pulley geometry without having to rely on contacts" )]
[InspectorGroupBegin( Name = "Extra Properties" )]
[InspectorGroupEnd]
public bool IsPulley
{
get => m_isPulley;
set
{
m_isPulley = value;
if ( NativeGeometry != null ) {
if ( m_isPulley )
NativeGeometry.getPropertyContainer().addPropertyBool( "Pulley", true );
else
NativeGeometry.getPropertyContainer().removePropertyBool( "Pulley" );
}
}
}

/// <summary>
/// Native geometry object, if initialized.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions AGXUnity/IO/OpenPLX/OpenPLXImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public UnityEngine.Object ImportOpenPLXFile( string path, string model = null )
else
ErrorCallback?.Invoke();

GC.Collect();
return importedObject;
}

Expand Down
9 changes: 1 addition & 8 deletions AGXUnity/Model/DeformableTerrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected override bool Initialize()
LicenseManager.LicenseInfo.HasModuleLogError( LicenseInfo.Module.AGXTerrain | LicenseInfo.Module.AGXGranular, this );

m_initialHeights = TerrainData.GetHeights( 0, 0, TerrainDataResolution, TerrainDataResolution );

Terrain.terrainData = Instantiate( Terrain.terrainData );
InitializeNative();

Simulation.Instance.StepCallbacks.PostStepForward += OnPostStepForward;
Expand Down Expand Up @@ -144,13 +144,6 @@ private void ResetTerrainDataHeightsAndTransform()

TerrainData.SetHeights( 0, 0, m_initialHeights );
transform.position = transform.position + MaximumDepth * Vector3.up;

#if UNITY_EDITOR
// If the editor is closed during play the modified height
// data isn't saved, this resolves corrupt heights in such case.
UnityEditor.EditorUtility.SetDirty( TerrainData );
UnityEditor.AssetDatabase.SaveAssets();
#endif
}

private void OnPostStepForward()
Expand Down
8 changes: 2 additions & 6 deletions AGXUnity/Model/DeformableTerrainConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public Vector3 GetOffsetPosition()
if ( InitialHeights != null )
return needsReturnData ? Terrain.terrainData.GetHeights( 0, 0, resolution, resolution ) : null;

Terrain.terrainData = Instantiate( Terrain.terrainData );

if ( float.IsNaN( MaximumDepth ) ) {
Debug.LogError( "Writing terrain offset without first setting depth!" );
MaximumDepth = 0;
Expand All @@ -41,12 +43,6 @@ internal void OnReset()
transform.position += MaximumDepth * Vector3.up;
Terrain.terrainData.SetHeights( 0, 0, InitialHeights );

#if UNITY_EDITOR
// If the editor is closed during play the modified height
// data isn't saved, this resolves corrupt heights in such case.
UnityEditor.EditorUtility.SetDirty( Terrain.terrainData );
UnityEditor.AssetDatabase.SaveAssets();
#endif
InitialHeights = null;
}
}
Expand Down
36 changes: 26 additions & 10 deletions AGXUnity/Model/DeformableTerrainPager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,7 @@ private void InitializeNative()
foreach ( var rb in m_rigidbodies )
Native.add( rb.Body.GetInitialized<RigidBody>().Native, rb.requiredRadius, rb.preloadRadius );

if ( MaterialPatches.Length != 0 )
Debug.LogWarning( "Nonhomogenous terrain is not yet supported for DeformableTerrainPager.", this );
GetSimulation().add( Native );
}

protected override void OnDestroy()
Expand Down Expand Up @@ -444,7 +443,7 @@ private void UpdateHeights()

private void UpdateTerrain( agxTerrain.TerrainPager.TileAttachments tile )
{
var terrain = tile.m_terrainTile;
var terrain = tile.m_terrainTile.get();
var modifications = terrain.getModifiedVertices();
if ( modifications.Count == 0 )
return;
Expand All @@ -456,12 +455,12 @@ private void UpdateTerrain( agxTerrain.TerrainPager.TileAttachments tile )
var result = new float[,] { { 0.0f } };

agx.Vec2i index = new agx.Vec2i(0,0);
Vector2Int tileIndex = GetTileIndex(terrain.get());
Vector2Int tileIndex = GetTileIndex(terrain);

UnityTerrainAdapter.UnityModificationCallback modCallbackFn = ( Terrain tile, Vector2Int unityIndex ) =>
{
tile.terrainData.SetHeightsDelayLOD( unityIndex.x, unityIndex.y, result );
OnModification?.Invoke( terrain.get(), index, tile, unityIndex );
OnModification?.Invoke( terrain, index, tile, unityIndex );
m_updatedTerrains.Add( tile );
};

Expand Down Expand Up @@ -845,17 +844,33 @@ public override void TriggerModifyAllCells()

public override bool ReplaceTerrainMaterial( DeformableTerrainMaterial oldMat, DeformableTerrainMaterial newMat )
{
throw new NotImplementedException( "Terrain pager does not yet support Inhomogeneous terrain" );
if ( Native == null )
return true;

if ( oldMat == null || newMat == null )
return false;

var success = m_terrainDataSource.exchangeTerrainMaterial(oldMat.GetInitialized().Native, newMat.GetInitialized().Native);
return success;
}

public override void SetAssociatedMaterial( DeformableTerrainMaterial terrMat, ShapeMaterial shapeMat )
{
throw new NotImplementedException( "Terrain pager does not yet support Inhomogeneous terrain" );
if ( Native == null )
return;

m_terrainDataSource.setAssociatedMaterial( shapeMat.GetInitialized().Native, terrMat.GetInitialized().Native );
}

public override void AddTerrainMaterial( DeformableTerrainMaterial terrMat, Shape shape = null )
{
throw new NotImplementedException( "Terrain pager does not yet support Inhomogeneous terrain" );
if ( Native == null )
return;

if ( shape != null )
m_terrainDataSource.addTerrainMaterial( terrMat.GetInitialized().Native, shape.GetInitialized().NativeGeometry );
else
m_terrainDataSource.addTerrainMaterial( terrMat.GetInitialized().Native );
}

protected override bool IsNativeNull() { return Native == null; }
Expand All @@ -867,8 +882,9 @@ protected override void SetShapeMaterial( agx.Material material, agxTerrain.Terr

protected override void SetTerrainMaterial( agxTerrain.TerrainMaterial material )
{
Native?.getTemplateTerrain().setTerrainMaterial( material );
OnPropertiesUpdated();
m_terrainDataSource.setDefaultTerrainMaterial( material );
if ( Material != null )
m_terrainDataSource.setAssociatedMaterial( Material.Native, material );
}

protected override void SetEnable( bool enable )
Expand Down
9 changes: 9 additions & 0 deletions AGXUnity/Model/MovableTerrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,15 @@ public override void EditorUpdate()
#endif
}

protected override bool PerformMigration()
{
if ( m_serializationVersion < 2 ) {
PlacementMode = Placement.Manual;
return true;
}
return false;
}

protected override bool Initialize()
{
// Only printing the errors if something is wrong.
Expand Down
9 changes: 7 additions & 2 deletions AGXUnity/Model/TerrainMaterialPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ public DeformableTerrainMaterial TerrainMaterial
return;
}

if ( (bool)ParentTerrain?.ReplaceTerrainMaterial( m_terrainMaterial, value ) )
if ( m_terrainMaterial == null ) {
ParentTerrain?.AddTerrainMaterial( value );
m_terrainMaterial = value;
}
else if ( (bool)ParentTerrain?.ReplaceTerrainMaterial( m_terrainMaterial, value ) )
m_terrainMaterial = value;
}
}
Expand All @@ -51,7 +55,8 @@ public DeformableTerrainMaterial TerrainMaterial
public void AddShape( Shape shape )
{
shape.enabled &= !DisableShapes;
shape.Visual.GetComponent<MeshRenderer>().enabled &= !DisableVisuals;
if ( shape.Visual != null )
shape.Visual.GetComponent<MeshRenderer>().enabled &= !DisableVisuals;
ParentTerrain?.AddTerrainMaterial( m_terrainMaterial, shape.GetInitialized<Shape>() );
}

Expand Down
88 changes: 70 additions & 18 deletions AGXUnity/Model/Track.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using AGXUnity.Collide;
using AGXUnity.Utils;
using agxVehicle;
using System.Collections.Generic;
Expand Down Expand Up @@ -266,19 +267,7 @@ public ShapeMaterial Material
/// Registered track wheel instances.
/// </summary>
[HideInInspector]
public TrackWheel[] Wheels
{
get { return m_wheels.ToArray(); }
}

protected override bool PerformMigration()
{
if ( m_serializationVersion < 2 ) {
FullDoF = true;
return true;
}
return false;
}
public TrackWheel[] Wheels => m_wheels.ToArray();

/// <summary>
/// Associate track wheel instance to this track.
Expand Down Expand Up @@ -313,18 +302,77 @@ public bool Remove( TrackWheel wheel )
/// </summary>
/// <param name="wheel">Track wheel instance.</param>
/// <returns>True if <paramref name="wheel"/> is associated to this track.</returns>
public bool Contains( TrackWheel wheel )
public bool Contains( TrackWheel wheel ) => m_wheels.Contains( wheel );

/// <summary>
/// Verifies so that all added track wheels still exists. Wheels that
/// has been deleted are removed.
/// </summary>
public void RemoveInvalidWheels() => m_wheels.RemoveAll( wheel => wheel == null );

[SerializeField]
private List<Shape> m_supportGeometries = new List<Shape>();

/// <summary>
/// Registered support geometry instances.
/// </summary>
[HideInInspector]
public Shape[] SupportGeometries => m_supportGeometries.ToArray();

/// <summary>
/// Associate support geometry instance to this track.
/// </summary>
/// <param name="supportGeometry">support geometry instance to add.</param>
/// <returns>True if added, false if null or already added.</returns>
public bool Add( Shape supportGeometry )
{
return m_wheels.Contains( wheel );
if ( supportGeometry == null || m_supportGeometries.Contains( supportGeometry ) )
return false;

m_supportGeometries.Add( supportGeometry );

if ( Native != null )
Native.addSupportGroupId( supportGeometry.GetInitialized().NativeGeometry );

return true;
}

/// <summary>
/// Verifies so that all added track wheels still exists. Wheels that
/// Disassociate support geometry instance from this track.
/// </summary>
/// <param name="supportGeometry">Support geometry instance to remove.</param>
/// <returns>True if removed, false if null or not associated to this track.</returns>
public bool Remove( Shape supportGeometry )
{
if ( supportGeometry == null )
return false;

if ( Native != null )
Native.removeSupportGroupId( supportGeometry.GetInitialized().NativeGeometry );

return m_supportGeometries.Remove( supportGeometry );
}

/// <summary>
/// True if <paramref name="supportGeometry"/> is associated to this track.
/// </summary>
/// <param name="supportGeometry">Support geometry instance.</param>
/// <returns>True if <paramref name="supportGeometry"/> is associated to this track.</returns>
public bool Contains( Shape supportGeometry ) => m_supportGeometries.Contains( supportGeometry );

/// <summary>
/// Verifies so that all added support geometries still exists. Geometries that
/// has been deleted are removed.
/// </summary>
public void RemoveInvalidWheels()
public void RemoveInvalidSupportGeometries() => m_supportGeometries.RemoveAll( geom => geom == null );

protected override bool PerformMigration()
{
m_wheels.RemoveAll( wheel => wheel == null );
if ( m_serializationVersion < 2 ) {
FullDoF = true;
return true;
}
return false;
}

private class OnInitializeAdapter : TrackNodeOnInitializeCallback
Expand Down Expand Up @@ -354,6 +402,7 @@ protected override bool Initialize()
return false;

RemoveInvalidWheels();
RemoveInvalidSupportGeometries();

if ( m_wheels.Count == 0 ) {
Debug.LogError( "Component: Track requires at least one wheel to initialize.", this );
Expand Down Expand Up @@ -389,6 +438,9 @@ protected override bool Initialize()
foreach ( var wheel in Wheels )
Native.add( wheel.Native );

foreach ( var geom in SupportGeometries )
Native.addSupportGroupId( geom.GetInitialized().NativeGeometry );

if ( WidthVariation != null || ThicknessVariation != null )
Native.initialize( new OnInitializeAdapter( Width, Thickness, WidthVariation, ThicknessVariation ) );
else
Expand Down
2 changes: 2 additions & 0 deletions AGXUnity/Model/TrackProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ protected override bool PerformMigration()
HingeStiffnessRotational = new Vector3( convertCompliance( m_hingeComplianceRotational.x ), convertCompliance( m_hingeComplianceRotational.y ), 100.0f );
HingeAttenuationRotational = new Vector3( convertDamping( m_hingeDampingRotational.x ), convertDamping( m_hingeDampingRotational.y ), 2.0f );

FullDoF = true;

return true;
}

Expand Down
Loading
Loading