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
25 changes: 23 additions & 2 deletions AGXUnity/IO/OpenPLX/Errors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum AgxUnityOpenPLXErrors
InvalidLinkDescription = 20,
InsufficientTrackWheels = 21,
MissingTrackWheelBody = 22,
IncompatibleSamplers = 23,
}

public class BaseError : openplx.Error
Expand Down Expand Up @@ -88,6 +89,17 @@ protected BaseError( string sourceID, AgxUnityOpenPLXErrors code )
{ }
}

public class BaseWarning : BaseError
{
protected BaseWarning( openplx.Core.Object source, AgxUnityOpenPLXErrors code )
: base( source, code )
{ }

protected BaseWarning( string sourceID, AgxUnityOpenPLXErrors code )
: base( sourceID, code )
{ }
}

public class InternalMapperError : BaseError
{
string m_error;
Expand All @@ -101,11 +113,11 @@ public InternalMapperError( openplx.Core.Object source, string error )
protected override string createErrorMessage() => m_error;
}

public class UnimplementedError : BaseError
public class UnimplementedWarning : BaseWarning
{
string m_modelName;

public UnimplementedError( openplx.Core.Object source )
public UnimplementedWarning( openplx.Core.Object source )
: base( source, AgxUnityOpenPLXErrors.Unimplemented )
{
m_modelName = source.getType().getNameWithNamespace( "." );
Expand Down Expand Up @@ -333,4 +345,13 @@ public MissingTrackWheelBodyError( openplx.Vehicles.TrackSystem.Components.Track

protected override string createErrorMessage() => $"Track wheel's body was not properly mapped to a RigidBody";
}

public class IncompatibleSamplersError : BaseError
{
public IncompatibleSamplersError( openplx.Core.Object source )
: base( source, AgxUnityOpenPLXErrors.IncompatibleSamplers )
{ }

protected override string createErrorMessage() => $"Base Color map and Alpha map sampler traits need to match or be unspecified";
}
}
8 changes: 4 additions & 4 deletions AGXUnity/IO/OpenPLX/InteractionMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void EnableSpringInteraction( LockController agxLock, Interactions.SpringInterac
else if ( spring is Interactions.LinearSpring ls )
agxLock.Position = (float)ls.position();
else
Utils.ReportUnimplemented<System.Object>( spring, Data.ErrorReporter );
Utils.ReportUnimplemented<System.Object>( spring, Data );

MapControllerDissipation( spring.dissipation(), spring.flexibility(), agxLock );
MapControllerFlexibility( spring.flexibility(), agxLock );
Expand Down Expand Up @@ -357,7 +357,7 @@ Constraint CreateConstraintForInteraction( openplx.Physics.Interactions.Interact
Interactions.LinearVelocityMotor => ConstraintType.GenericConstraint1DOF,
Interactions.ForceMotor => ConstraintType.GenericConstraint1DOF,
// Unknown
_ => Utils.ReportUnimplementedS<ConstraintType>( interaction, Data.ErrorReporter )
_ => Utils.ReportUnimplementedS<ConstraintType>( interaction, Data )
};

if ( type == null )
Expand Down Expand Up @@ -403,7 +403,7 @@ system is openplx.Robotics.Robots.Robot
};

if ( angleType == null )
return Utils.ReportUnimplemented<GameObject>( interaction, Data.ErrorReporter );
return Utils.ReportUnimplemented<GameObject>( interaction, Data );

g1dof.DOFType = angleType.Value;

Expand All @@ -429,7 +429,7 @@ system is openplx.Robotics.Robots.Robot
EnableForceMotorInteraction( constraint.GetController<TargetSpeedController>(), fm );
break;
default:
return Utils.ReportUnimplemented<GameObject>( interaction, Data.ErrorReporter );
return Utils.ReportUnimplemented<GameObject>( interaction, Data );
}

return constraint.gameObject;
Expand Down
5 changes: 4 additions & 1 deletion AGXUnity/IO/OpenPLX/MapperData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public ShapeMaterial DefaultMaterial
public Dictionary<openplx.Terrain.Shovel, DeformableTerrainShovelSettings> ShovelSettingsCache { get; } = new Dictionary<openplx.Terrain.Shovel, DeformableTerrainShovelSettings>();

public Dictionary<uint, Material> NativeMappedRenderMaterialCache { get; } = new Dictionary<uint, Material>();
public Dictionary<openplx.Visuals.Materials.Material, Material> RenderMaterialCache { get; } = new Dictionary<openplx.Visuals.Materials.Material, Material> { };
public Dictionary<openplx.Visuals.Textures.DefaultTexture, Texture2D> TextureCache { get; } = new Dictionary<openplx.Visuals.Textures.DefaultTexture, Texture2D>();
public Dictionary<openplx.Physics.Optics.Material, Material> RenderMaterialCache { get; } = new Dictionary<openplx.Physics.Optics.Material, Material> { };

public List<ContactMaterial> MappedContactMaterials { get; } = new List<ContactMaterial>();
public List<FrictionModel> MappedFrictionModels { get; } = new List<FrictionModel>();
Expand All @@ -74,6 +75,8 @@ public ShapeMaterial DefaultMaterial
public List<TrackInternalMergeProperties> MappedTrackInternalMergeProperties { get; } = new List<TrackInternalMergeProperties>();
public List<DeformableTerrainMaterial> MappedTerrainMaterials { get; } = new List<DeformableTerrainMaterial> { };

public List<Error> Warnings { get; } = new List<Error>();

public bool TerrainParticleRendererAdded { get; set; } = false;

public GameObject CreateGameObject( string name = null )
Expand Down
13 changes: 6 additions & 7 deletions AGXUnity/IO/OpenPLX/MappingUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,30 +129,29 @@ public static bool TryGetStringAnnotation( this openplx.Core.Object obj, string
}
public static class Utils
{

public static void MapLocalTransform( Transform transform, openplx.Math.AffineTransform local_transform )
{
transform.localPosition = local_transform.position().ToHandedVector3();
transform.localRotation = local_transform.rotation().ToHandedQuaternion();
}

public static T? ReportUnimplementedS<T>( openplx.Core.Object obj, openplx.ErrorReporter err )
public static T? ReportUnimplementedS<T>( openplx.Core.Object obj, MapperData data )
where T : struct
{
err.reportError( new UnimplementedError( obj ) );
data.Warnings.Add( new UnimplementedWarning( obj ) );
return null;
}

public static T ReportUnimplemented<T>( openplx.Core.Object obj, openplx.ErrorReporter err )
public static T ReportUnimplemented<T>( openplx.Core.Object obj, MapperData data )
where T : class
{
err.reportError( new UnimplementedError( obj ) );
data.Warnings.Add( new UnimplementedWarning( obj ) );
return null;
}

public static void ReportUnimplemented( openplx.Core.Object obj, openplx.ErrorReporter err )
public static void ReportUnimplemented( openplx.Core.Object obj, MapperData data )
{
err.reportError( new UnimplementedError( obj ) );
data.Warnings.Add( new UnimplementedWarning( obj ) );
}

public static void AddChild( GameObject parent, GameObject child, openplx.ErrorReporter err, openplx.Core.Object obj )
Expand Down
3 changes: 3 additions & 0 deletions AGXUnity/IO/OpenPLX/OpenPLXImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public UnityEngine.Object ImportOpenPLXFile( string path, string model = null )
UnityEngine.Object importedObject = null;
if ( loadedModel != null ) {
importedObject = mapper.MapObject( loadedModel, path );
foreach ( var warning in mapper.Data.Warnings )
ErrorReporter?.Invoke( warning );

if ( importedObject == null || mapper.Data.ErrorReporter.getErrorCount() > 0 ) {
foreach ( var error in mapper.Data.ErrorReporter.getErrors() )
ErrorReporter?.Invoke( error );
Expand Down
2 changes: 1 addition & 1 deletion AGXUnity/IO/OpenPLX/OpenPLXObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool NeedsNativeMapping( openplx.Core.Object obj )
return false;
return obj switch
{
openplx.Visuals.Geometries.Geometry => false,
openplx.Visuals.Node => false,
openplx.Physics.System => false,
openplx.Physics.KinematicLock => false,
_ => true
Expand Down
Loading
Loading