Skip to content

Commit b12bb1a

Browse files
authored
Merge pull request #199 from Algoryx/feature/openplx-vehicle-update
Openplx vehicle update
2 parents a096a86 + 0a24209 commit b12bb1a

10 files changed

Lines changed: 194 additions & 123 deletions

File tree

AGXUnity/IO/OpenPLX/Errors.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ public FileDoesNotExistError( string path )
212212

213213
public class InvalidWheelChassisError : BaseError
214214
{
215-
private openplx.Vehicles.Suspensions.Interactions.Mate m_suspension;
215+
private openplx.Vehicles.Suspensions.SingleMate.Base m_suspension;
216216

217-
public InvalidWheelChassisError( openplx.Vehicles.Suspensions.Interactions.Mate suspension )
217+
public InvalidWheelChassisError( openplx.Vehicles.Suspensions.SingleMate.Base suspension )
218218
: base( suspension, AgxUnityOpenPLXErrors.InvalidWheelChassis )
219219
{
220220
m_suspension = suspension;
@@ -225,9 +225,9 @@ public InvalidWheelChassisError( openplx.Vehicles.Suspensions.Interactions.Mate
225225

226226
public class MissingWheelBodyError : BaseError
227227
{
228-
private openplx.Vehicles.Suspensions.Interactions.Mate m_suspension;
228+
private openplx.Vehicles.Suspensions.SingleMate.Base m_suspension;
229229

230-
public MissingWheelBodyError( openplx.Vehicles.Suspensions.Interactions.Mate suspension )
230+
public MissingWheelBodyError( openplx.Vehicles.Suspensions.SingleMate.Base suspension )
231231
: base( suspension, AgxUnityOpenPLXErrors.MissingWheelBody )
232232
{
233233
m_suspension = suspension;
@@ -238,9 +238,9 @@ public MissingWheelBodyError( openplx.Vehicles.Suspensions.Interactions.Mate sus
238238

239239
public class UnmappedWheelError : BaseError
240240
{
241-
private openplx.Vehicles.Suspensions.Suspension m_wheel;
241+
private openplx.Vehicles.Suspensions.SingleMate.Base m_wheel;
242242

243-
public UnmappedWheelError( openplx.Vehicles.Suspensions.Suspension wheel )
243+
public UnmappedWheelError( openplx.Vehicles.Suspensions.SingleMate.Base wheel )
244244
: base( wheel, AgxUnityOpenPLXErrors.UnmappedWheel )
245245
{
246246
m_wheel = wheel;

AGXUnity/IO/OpenPLX/InteractionMapper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ public void MapMateConnector( MateConnector mc )
4747

4848
// Since redirected MCs can be placed in other places than the unique location derived by their
4949
// names, we need to add some unique identifier to avoid name collisions in the hierarchy.
50-
var mcObject = Data.CreateOpenPLXObject( mc.getName() + (mc is RedirectedMateConnector ? $"_rd_#{mc.To32BitFnv1aHash()}" : "") );
50+
var mcObject = Data.CreateOpenPLXObject( mc.getName() );
51+
if ( mc is RedirectedMateConnector )
52+
mcObject.name = mcObject.name + $"_rd_#{mc.To32BitFnv1aHash()}";
5153
mcObject.AddComponent<ObserverFrame>();
5254
openplx.Core.Object owner = mc.getOwner();
5355
if ( mc is RedirectedMateConnector redirected )

AGXUnity/IO/OpenPLX/MappingUtils.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ public static bool IsDefault( this openplx.Math.Quat quat )
6767
}
6868

6969
public static uint To32BitFnv1aHash( this openplx.Core.Object obj ) => obj.getName().To32BitFnv1aHash();
70+
71+
public static bool HasTrait<T>( this openplx.Core.Object obj )
72+
where T : class
73+
{
74+
string traitName = typeof( T ).FullName.Substring( 8 );
75+
return obj.hasTrait( traitName );
76+
}
7077
}
7178
public static class Utils
7279
{

AGXUnity/IO/OpenPLX/OpenPLXObject.cs

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,49 @@ bool NeedsNativeMapping( openplx.Core.Object obj )
3939
};
4040
}
4141

42-
internal agx.Referenced FindCorrespondingNative( OpenPLX.OpenPLXRoot root, openplx.Core.Object obj ) => obj switch
42+
internal agx.Referenced FindCorrespondingNative( OpenPLX.OpenPLXRoot root, openplx.Core.Object obj )
4343
{
44-
Interactions.Lock => GetNativeConstraint().asLockJoint(),
45-
Interactions.Hinge => GetNativeConstraint().asHinge(),
46-
Interactions.Prismatic => GetNativeConstraint().asPrismatic(),
47-
Interactions.Cylindrical => GetNativeConstraint().asCylindricalJoint(),
48-
Interactions.Ball => GetNativeConstraint().asBallJoint(),
49-
Interactions.Distance => GetNativeConstraint().asDistanceJoint(),
50-
Interactions.RotationalRange => GetGeneric1DOFNative().getRange1D(),
51-
Interactions.TorsionSpring => GetGeneric1DOFNative().getLock1D(),
52-
Interactions.RotationalVelocityMotor => GetGeneric1DOFNative().getMotor1D(),
53-
Interactions.TorqueMotor => GetGeneric1DOFNative().getMotor1D(),
54-
Interactions.LinearRange => GetGeneric1DOFNative().getRange1D(),
55-
Interactions.LinearSpring => GetGeneric1DOFNative().getLock1D(),
56-
Interactions.LinearVelocityMotor => GetGeneric1DOFNative().getMotor1D(),
57-
Interactions.ForceMotor => GetGeneric1DOFNative().getMotor1D(),
58-
openplx.Physics.Geometries.ContactGeometry => gameObject.GetInitializedComponent<Shape>().NativeGeometry,
59-
Interactions.MateConnector => gameObject.GetInitializedComponent<ObserverFrame>().Native,
60-
openplx.Physics3D.Bodies.RigidBody => gameObject.GetInitializedComponent<RigidBody>().Native,
61-
openplx.Terrain.Terrain => gameObject.GetInitializedComponent<MovableTerrain>().Native,
62-
openplx.Terrain.Shovel => gameObject.GetInitializedComponent<DeformableTerrainShovel>().Native,
63-
openplx.Sensors.SensorLogic => gameObject.GetInitializedComponent<LidarSensor>().Native,
64-
openplx.Vehicles.Steering.Interactions.DualSuspensionSteering => gameObject.GetInitializedComponent<Steering>().Native,
65-
openplx.Vehicles.Suspensions.Interactions.LinearSpringDamperMate => gameObject.GetInitializedComponent<WheelJoint>().Native,
66-
_ => DefaultHandling( obj )
67-
};
44+
if ( obj.getOwner() is openplx.Vehicles.Suspensions.SingleMate.Base wj ) {
45+
if ( obj == wj.range() )
46+
return gameObject.GetInitializedComponent<WheelJoint>().GetController<RangeController>( WheelJoint.WheelDimension.Suspension ).Native;
47+
else if ( obj == wj.mate() )
48+
return gameObject.GetInitializedComponent<WheelJoint>().Native;
49+
}
50+
51+
if ( obj.getOwner() is openplx.Vehicles.Steering.Kinematic.Base steer ) {
52+
if ( obj == steer.interaction() )
53+
return gameObject.GetInitializedComponent<Steering>().Native;
54+
}
55+
56+
return obj switch
57+
{
58+
Interactions.Lock => GetNativeConstraint().asLockJoint(),
59+
Interactions.Hinge => GetNativeConstraint().asHinge(),
60+
Interactions.Prismatic => GetNativeConstraint().asPrismatic(),
61+
Interactions.Cylindrical => GetNativeConstraint().asCylindricalJoint(),
62+
Interactions.Ball => GetNativeConstraint().asBallJoint(),
63+
Interactions.Distance => GetNativeConstraint().asDistanceJoint(),
64+
Interactions.RotationalRange => GetGeneric1DOFNative().getRange1D(),
65+
Interactions.TorsionSpring => GetGeneric1DOFNative().getLock1D(),
66+
Interactions.RotationalVelocityMotor => GetGeneric1DOFNative().getMotor1D(),
67+
Interactions.TorqueMotor => GetGeneric1DOFNative().getMotor1D(),
68+
Interactions.LinearRange => GetGeneric1DOFNative().getRange1D(),
69+
Interactions.LinearSpring => GetGeneric1DOFNative().getLock1D(),
70+
Interactions.LinearVelocityMotor => GetGeneric1DOFNative().getMotor1D(),
71+
Interactions.ForceMotor => GetGeneric1DOFNative().getMotor1D(),
72+
openplx.Physics.Geometries.ContactGeometry => gameObject.GetInitializedComponent<Shape>().NativeGeometry,
73+
Interactions.MateConnector => gameObject.GetInitializedComponent<ObserverFrame>().Native,
74+
openplx.Physics3D.Bodies.RigidBody => gameObject.GetInitializedComponent<RigidBody>().Native,
75+
openplx.Terrain.Terrain => gameObject.GetInitializedComponent<MovableTerrain>().Native,
76+
openplx.Terrain.Shovel => gameObject.GetInitializedComponent<DeformableTerrainShovel>().Native,
77+
openplx.Sensors.SensorLogic => gameObject.GetInitializedComponent<LidarSensor>().Native,
78+
openplx.Vehicles.Steering.Kinematic.Base => gameObject.GetInitializedComponent<Steering>().Native,
79+
openplx.Vehicles.Steering.Kinematic.Interactions.Base => gameObject.GetInitializedComponent<Steering>().Native,
80+
openplx.Vehicles.Suspensions.SingleMate.Base => gameObject.GetInitializedComponent<WheelJoint>().Native,
81+
openplx.Vehicles.Suspensions.SingleMate.Interactions.Base => gameObject.GetInitializedComponent<WheelJoint>().Native,
82+
_ => DefaultHandling( obj )
83+
};
84+
}
6885

6986
[field: SerializeField]
7087
[DisableInRuntimeInspector]

AGXUnity/IO/OpenPLX/OpenPLXRoot.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public string PrunedNativeName
3131
throw new System.NullReferenceException( "Cannot get the pruned name before the OpenPLX root has been initialized" );
3232
var prunedNativeName = Native.getName();
3333
if ( prunedNativeName.Contains( "." ) )
34-
prunedNativeName = prunedNativeName[ ( prunedNativeName.IndexOf( "." ) + 1 ).. ];
34+
prunedNativeName = prunedNativeName[ ( prunedNativeName.LastIndexOf( "." ) + 1 ).. ];
3535
return prunedNativeName;
3636
}
3737
}
@@ -107,7 +107,7 @@ protected override bool Initialize()
107107
continue;
108108
var native = openPLXObj.FindCorrespondingNative( this, obj );
109109
if ( native != null )
110-
m_nativeMap.Add( new( decl, native ) );
110+
m_nativeMap.Add( new( obj.getName(), native ) );
111111
}
112112
}
113113

AGXUnity/IO/OpenPLX/OpenPLXUnityMapper.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ private void MapSignals( Object obj, OpenPLXSignals signals, string prefix = ""
127127
sigInt.Enabled = sigInterface.enable();
128128
sigInt.Inputs = new List<InputTarget>();
129129
foreach ( var (inpName, input) in sigInterface.getEntries<openplx.Physics.Signals.Input>() )
130-
sigInt.Inputs.Add( new InputTarget( sigInterface.getName() + "." + inpName, input ) );
130+
sigInt.Inputs.Add( new InputTarget( prefix + "." + name + "." + inpName, input ) );
131131
sigInt.Outputs = new List<OutputSource>();
132132
foreach ( var (outName, output) in sigInterface.getEntries<openplx.Physics.Signals.Output>() )
133-
sigInt.Outputs.Add( new OutputSource( sigInterface.getName() + "." + outName, output ) );
133+
sigInt.Outputs.Add( new OutputSource( prefix + "." + name + "." + outName, output ) );
134134

135135
signals.RegisterInterface( sigInt );
136136
}
@@ -946,20 +946,18 @@ void MapSystemPass4( openplx.Physics3D.System system )
946946
foreach ( var subSystem in system.getNonReferenceValues<openplx.Physics3D.System>() )
947947
MapSystemPass4( subSystem );
948948

949+
if ( system is openplx.Vehicles.Suspensions.SingleMate.Base suspension )
950+
VehicleMapper.MapSingleMateSuspensionOnto( suspension, s );
951+
949952
foreach ( var lidar in system.getNonReferenceValues<openplx.Sensors.LidarLogic>() )
950953
Utils.AddChild( s, SensorMapper.MapLidar( lidar ), Data.ErrorReporter, lidar );
951954

952955
foreach ( var kinematicLock in system.getNonReferenceValues<openplx.Physics.KinematicLock>() )
953956
Utils.AddChild( s, MapKinematicLock( kinematicLock ), Data.ErrorReporter, kinematicLock );
954957

955-
foreach ( var interaction in system.getNonReferenceValues<openplx.Physics.Interactions.Interaction>() ) {
956-
if ( !Utils.IsRuntimeMapped( interaction ) && interaction is not openplx.Vehicles.Steering.Interactions.DualSuspensionSteering ) {
957-
if ( interaction is openplx.Vehicles.Suspensions.Interactions.Mate suspension )
958-
Utils.AddChild( s, VehicleMapper.MapSuspension( suspension ), Data.ErrorReporter, suspension );
959-
else
960-
Utils.AddChild( s, InteractionMapper.MapInteraction( interaction, system ), Data.ErrorReporter, interaction );
961-
}
962-
}
958+
foreach ( var interaction in system.getNonReferenceValues<openplx.Physics.Interactions.Interaction>() )
959+
if ( !Utils.IsRuntimeMapped( interaction ) && !VehicleMapper.HandledInteraction( interaction ) )
960+
Utils.AddChild( s, InteractionMapper.MapInteraction( interaction, system ), Data.ErrorReporter, interaction );
963961

964962
foreach ( var contactModel in system.getNonReferenceValues<openplx.Physics.Interactions.SurfaceContact.Model>() )
965963
InteractionMapper.MapContactModel( contactModel );
@@ -987,8 +985,8 @@ void MapSystemPass5( openplx.Physics3D.System system )
987985
foreach ( var subSystem in system.getNonReferenceValues<openplx.Physics3D.System>() )
988986
MapSystemPass5( subSystem );
989987

990-
foreach ( var steering in system.getNonReferenceValues<openplx.Vehicles.Steering.Interactions.DualSuspensionSteering>() )
991-
Utils.AddChild( s, VehicleMapper.MapSteering( steering ), Data.ErrorReporter, steering );
988+
if ( system is openplx.Vehicles.Steering.Kinematic.Base steering )
989+
VehicleMapper.MapSteeringOnto( steering, s );
992990

993991
foreach ( var wheel in system.getNonReferenceValues<openplx.Vehicles.Wheels.ElasticWheel>() )
994992
VehicleMapper.MapElasticWheel( wheel );

0 commit comments

Comments
 (0)