Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions AGXUnity/IO/OpenPLX/Errors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ public FileDoesNotExistError( string path )

public class InvalidWheelChassisError : BaseError
{
private openplx.Vehicles.Suspensions.Interactions.Mate m_suspension;
private openplx.Vehicles.Suspensions.SingleMate.Base m_suspension;

public InvalidWheelChassisError( openplx.Vehicles.Suspensions.Interactions.Mate suspension )
public InvalidWheelChassisError( openplx.Vehicles.Suspensions.SingleMate.Base suspension )
: base( suspension, AgxUnityOpenPLXErrors.InvalidWheelChassis )
{
m_suspension = suspension;
Expand All @@ -225,9 +225,9 @@ public InvalidWheelChassisError( openplx.Vehicles.Suspensions.Interactions.Mate

public class MissingWheelBodyError : BaseError
{
private openplx.Vehicles.Suspensions.Interactions.Mate m_suspension;
private openplx.Vehicles.Suspensions.SingleMate.Base m_suspension;

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

public class UnmappedWheelError : BaseError
{
private openplx.Vehicles.Suspensions.Suspension m_wheel;
private openplx.Vehicles.Suspensions.SingleMate.Base m_wheel;

public UnmappedWheelError( openplx.Vehicles.Suspensions.Suspension wheel )
public UnmappedWheelError( openplx.Vehicles.Suspensions.SingleMate.Base wheel )
: base( wheel, AgxUnityOpenPLXErrors.UnmappedWheel )
{
m_wheel = wheel;
Expand Down
4 changes: 3 additions & 1 deletion AGXUnity/IO/OpenPLX/InteractionMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public void MapMateConnector( MateConnector mc )

// Since redirected MCs can be placed in other places than the unique location derived by their
// names, we need to add some unique identifier to avoid name collisions in the hierarchy.
var mcObject = Data.CreateOpenPLXObject( mc.getName() + (mc is RedirectedMateConnector ? $"_rd_#{mc.To32BitFnv1aHash()}" : "") );
var mcObject = Data.CreateOpenPLXObject( mc.getName() );
if ( mc is RedirectedMateConnector )
mcObject.name = mcObject.name + $"_rd_#{mc.To32BitFnv1aHash()}";
mcObject.AddComponent<ObserverFrame>();
openplx.Core.Object owner = mc.getOwner();
if ( mc is RedirectedMateConnector redirected )
Expand Down
7 changes: 7 additions & 0 deletions AGXUnity/IO/OpenPLX/MappingUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public static bool IsDefault( this openplx.Math.Quat quat )
}

public static uint To32BitFnv1aHash( this openplx.Core.Object obj ) => obj.getName().To32BitFnv1aHash();

public static bool HasTrait<T>( this openplx.Core.Object obj )
where T : class
{
string traitName = typeof( T ).FullName.Substring( 8 );
return obj.hasTrait( traitName );
}
}
public static class Utils
{
Expand Down
67 changes: 42 additions & 25 deletions AGXUnity/IO/OpenPLX/OpenPLXObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,49 @@ bool NeedsNativeMapping( openplx.Core.Object obj )
};
}

internal agx.Referenced FindCorrespondingNative( OpenPLX.OpenPLXRoot root, openplx.Core.Object obj ) => obj switch
internal agx.Referenced FindCorrespondingNative( OpenPLX.OpenPLXRoot root, openplx.Core.Object obj )
{
Interactions.Lock => GetNativeConstraint().asLockJoint(),
Interactions.Hinge => GetNativeConstraint().asHinge(),
Interactions.Prismatic => GetNativeConstraint().asPrismatic(),
Interactions.Cylindrical => GetNativeConstraint().asCylindricalJoint(),
Interactions.Ball => GetNativeConstraint().asBallJoint(),
Interactions.Distance => GetNativeConstraint().asDistanceJoint(),
Interactions.RotationalRange => GetGeneric1DOFNative().getRange1D(),
Interactions.TorsionSpring => GetGeneric1DOFNative().getLock1D(),
Interactions.RotationalVelocityMotor => GetGeneric1DOFNative().getMotor1D(),
Interactions.TorqueMotor => GetGeneric1DOFNative().getMotor1D(),
Interactions.LinearRange => GetGeneric1DOFNative().getRange1D(),
Interactions.LinearSpring => GetGeneric1DOFNative().getLock1D(),
Interactions.LinearVelocityMotor => GetGeneric1DOFNative().getMotor1D(),
Interactions.ForceMotor => GetGeneric1DOFNative().getMotor1D(),
openplx.Physics.Geometries.ContactGeometry => gameObject.GetInitializedComponent<Shape>().NativeGeometry,
Interactions.MateConnector => gameObject.GetInitializedComponent<ObserverFrame>().Native,
openplx.Physics3D.Bodies.RigidBody => gameObject.GetInitializedComponent<RigidBody>().Native,
openplx.Terrain.Terrain => gameObject.GetInitializedComponent<MovableTerrain>().Native,
openplx.Terrain.Shovel => gameObject.GetInitializedComponent<DeformableTerrainShovel>().Native,
openplx.Sensors.SensorLogic => gameObject.GetInitializedComponent<LidarSensor>().Native,
openplx.Vehicles.Steering.Interactions.DualSuspensionSteering => gameObject.GetInitializedComponent<Steering>().Native,
openplx.Vehicles.Suspensions.Interactions.LinearSpringDamperMate => gameObject.GetInitializedComponent<WheelJoint>().Native,
_ => DefaultHandling( obj )
};
if ( obj.getOwner() is openplx.Vehicles.Suspensions.SingleMate.Base wj ) {
if ( obj == wj.range() )
return gameObject.GetInitializedComponent<WheelJoint>().GetController<RangeController>( WheelJoint.WheelDimension.Suspension ).Native;
else if ( obj == wj.mate() )
return gameObject.GetInitializedComponent<WheelJoint>().Native;
}

if ( obj.getOwner() is openplx.Vehicles.Steering.Kinematic.Base steer ) {
if ( obj == steer.interaction() )
return gameObject.GetInitializedComponent<Steering>().Native;
}

return obj switch
{
Interactions.Lock => GetNativeConstraint().asLockJoint(),
Interactions.Hinge => GetNativeConstraint().asHinge(),
Interactions.Prismatic => GetNativeConstraint().asPrismatic(),
Interactions.Cylindrical => GetNativeConstraint().asCylindricalJoint(),
Interactions.Ball => GetNativeConstraint().asBallJoint(),
Interactions.Distance => GetNativeConstraint().asDistanceJoint(),
Interactions.RotationalRange => GetGeneric1DOFNative().getRange1D(),
Interactions.TorsionSpring => GetGeneric1DOFNative().getLock1D(),
Interactions.RotationalVelocityMotor => GetGeneric1DOFNative().getMotor1D(),
Interactions.TorqueMotor => GetGeneric1DOFNative().getMotor1D(),
Interactions.LinearRange => GetGeneric1DOFNative().getRange1D(),
Interactions.LinearSpring => GetGeneric1DOFNative().getLock1D(),
Interactions.LinearVelocityMotor => GetGeneric1DOFNative().getMotor1D(),
Interactions.ForceMotor => GetGeneric1DOFNative().getMotor1D(),
openplx.Physics.Geometries.ContactGeometry => gameObject.GetInitializedComponent<Shape>().NativeGeometry,
Interactions.MateConnector => gameObject.GetInitializedComponent<ObserverFrame>().Native,
openplx.Physics3D.Bodies.RigidBody => gameObject.GetInitializedComponent<RigidBody>().Native,
openplx.Terrain.Terrain => gameObject.GetInitializedComponent<MovableTerrain>().Native,
openplx.Terrain.Shovel => gameObject.GetInitializedComponent<DeformableTerrainShovel>().Native,
openplx.Sensors.SensorLogic => gameObject.GetInitializedComponent<LidarSensor>().Native,
openplx.Vehicles.Steering.Kinematic.Base => gameObject.GetInitializedComponent<Steering>().Native,
openplx.Vehicles.Steering.Kinematic.Interactions.Base => gameObject.GetInitializedComponent<Steering>().Native,
openplx.Vehicles.Suspensions.SingleMate.Base => gameObject.GetInitializedComponent<WheelJoint>().Native,
openplx.Vehicles.Suspensions.SingleMate.Interactions.Base => gameObject.GetInitializedComponent<WheelJoint>().Native,
_ => DefaultHandling( obj )
};
}

[field: SerializeField]
[DisableInRuntimeInspector]
Expand Down
4 changes: 2 additions & 2 deletions AGXUnity/IO/OpenPLX/OpenPLXRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public string PrunedNativeName
throw new System.NullReferenceException( "Cannot get the pruned name before the OpenPLX root has been initialized" );
var prunedNativeName = Native.getName();
if ( prunedNativeName.Contains( "." ) )
prunedNativeName = prunedNativeName[ ( prunedNativeName.IndexOf( "." ) + 1 ).. ];
prunedNativeName = prunedNativeName[ ( prunedNativeName.LastIndexOf( "." ) + 1 ).. ];
return prunedNativeName;
}
}
Expand Down Expand Up @@ -107,7 +107,7 @@ protected override bool Initialize()
continue;
var native = openPLXObj.FindCorrespondingNative( this, obj );
if ( native != null )
m_nativeMap.Add( new( decl, native ) );
m_nativeMap.Add( new( obj.getName(), native ) );
}
}

Expand Down
22 changes: 10 additions & 12 deletions AGXUnity/IO/OpenPLX/OpenPLXUnityMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ private void MapSignals( Object obj, OpenPLXSignals signals, string prefix = ""
sigInt.Enabled = sigInterface.enable();
sigInt.Inputs = new List<InputTarget>();
foreach ( var (inpName, input) in sigInterface.getEntries<openplx.Physics.Signals.Input>() )
sigInt.Inputs.Add( new InputTarget( sigInterface.getName() + "." + inpName, input ) );
sigInt.Inputs.Add( new InputTarget( prefix + "." + name + "." + inpName, input ) );
sigInt.Outputs = new List<OutputSource>();
foreach ( var (outName, output) in sigInterface.getEntries<openplx.Physics.Signals.Output>() )
sigInt.Outputs.Add( new OutputSource( sigInterface.getName() + "." + outName, output ) );
sigInt.Outputs.Add( new OutputSource( prefix + "." + name + "." + outName, output ) );

signals.RegisterInterface( sigInt );
}
Expand Down Expand Up @@ -946,20 +946,18 @@ void MapSystemPass4( openplx.Physics3D.System system )
foreach ( var subSystem in system.getNonReferenceValues<openplx.Physics3D.System>() )
MapSystemPass4( subSystem );

if ( system is openplx.Vehicles.Suspensions.SingleMate.Base suspension )
VehicleMapper.MapSingleMateSuspensionOnto( suspension, s );

foreach ( var lidar in system.getNonReferenceValues<openplx.Sensors.LidarLogic>() )
Utils.AddChild( s, SensorMapper.MapLidar( lidar ), Data.ErrorReporter, lidar );

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

foreach ( var interaction in system.getNonReferenceValues<openplx.Physics.Interactions.Interaction>() ) {
if ( !Utils.IsRuntimeMapped( interaction ) && interaction is not openplx.Vehicles.Steering.Interactions.DualSuspensionSteering ) {
if ( interaction is openplx.Vehicles.Suspensions.Interactions.Mate suspension )
Utils.AddChild( s, VehicleMapper.MapSuspension( suspension ), Data.ErrorReporter, suspension );
else
Utils.AddChild( s, InteractionMapper.MapInteraction( interaction, system ), Data.ErrorReporter, interaction );
}
}
foreach ( var interaction in system.getNonReferenceValues<openplx.Physics.Interactions.Interaction>() )
if ( !Utils.IsRuntimeMapped( interaction ) && !VehicleMapper.HandledInteraction( interaction ) )
Utils.AddChild( s, InteractionMapper.MapInteraction( interaction, system ), Data.ErrorReporter, interaction );

foreach ( var contactModel in system.getNonReferenceValues<openplx.Physics.Interactions.SurfaceContact.Model>() )
InteractionMapper.MapContactModel( contactModel );
Expand Down Expand Up @@ -987,8 +985,8 @@ void MapSystemPass5( openplx.Physics3D.System system )
foreach ( var subSystem in system.getNonReferenceValues<openplx.Physics3D.System>() )
MapSystemPass5( subSystem );

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

foreach ( var wheel in system.getNonReferenceValues<openplx.Vehicles.Wheels.ElasticWheel>() )
VehicleMapper.MapElasticWheel( wheel );
Expand Down
Loading