| | using System; |
| | using Unity.MLAgents.Sensors; |
| |
|
| | namespace Unity.MLAgents.Extensions.Sensors |
| | { |
| | |
| | |
| | |
| | [Serializable] |
| | public struct PhysicsSensorSettings |
| | { |
| | |
| | |
| | |
| | public bool UseModelSpaceTranslations; |
| |
|
| | |
| | |
| | |
| | public bool UseModelSpaceRotations; |
| |
|
| | |
| | |
| | |
| | public bool UseLocalSpaceTranslations; |
| |
|
| | |
| | |
| | |
| | public bool UseLocalSpaceRotations; |
| |
|
| | |
| | |
| | |
| | public bool UseModelSpaceLinearVelocity; |
| |
|
| | |
| | |
| | |
| | public bool UseLocalSpaceLinearVelocity; |
| |
|
| | |
| | |
| | |
| | public bool UseJointPositionsAndAngles; |
| |
|
| | |
| | |
| | |
| | public bool UseJointForces; |
| |
|
| | |
| | |
| | |
| | |
| | public static PhysicsSensorSettings Default() |
| | { |
| | return new PhysicsSensorSettings |
| | { |
| | UseModelSpaceTranslations = true, |
| | UseModelSpaceRotations = true, |
| | }; |
| | } |
| |
|
| | |
| | |
| | |
| | public bool UseModelSpace |
| | { |
| | get { return UseModelSpaceTranslations || UseModelSpaceRotations || UseModelSpaceLinearVelocity; } |
| | } |
| |
|
| | |
| | |
| | |
| | public bool UseLocalSpace |
| | { |
| | get { return UseLocalSpaceTranslations || UseLocalSpaceRotations || UseLocalSpaceLinearVelocity; } |
| | } |
| | } |
| |
|
| | internal static class ObservationWriterPhysicsExtensions |
| | { |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public static int WritePoses(this ObservationWriter writer, PhysicsSensorSettings settings, PoseExtractor poseExtractor, int baseOffset = 0) |
| | { |
| | var offset = baseOffset; |
| | if (settings.UseModelSpace) |
| | { |
| | foreach (var pose in poseExtractor.GetEnabledModelSpacePoses()) |
| | { |
| | if (settings.UseModelSpaceTranslations) |
| | { |
| | writer.Add(pose.position, offset); |
| | offset += 3; |
| | } |
| |
|
| | if (settings.UseModelSpaceRotations) |
| | { |
| | writer.Add(pose.rotation, offset); |
| | offset += 4; |
| | } |
| | } |
| |
|
| | foreach (var vel in poseExtractor.GetEnabledModelSpaceVelocities()) |
| | { |
| | if (settings.UseModelSpaceLinearVelocity) |
| | { |
| | writer.Add(vel, offset); |
| | offset += 3; |
| | } |
| | } |
| | } |
| |
|
| | if (settings.UseLocalSpace) |
| | { |
| | foreach (var pose in poseExtractor.GetEnabledLocalSpacePoses()) |
| | { |
| | if (settings.UseLocalSpaceTranslations) |
| | { |
| | writer.Add(pose.position, offset); |
| | offset += 3; |
| | } |
| |
|
| | if (settings.UseLocalSpaceRotations) |
| | { |
| | writer.Add(pose.rotation, offset); |
| | offset += 4; |
| | } |
| | } |
| |
|
| | foreach (var vel in poseExtractor.GetEnabledLocalSpaceVelocities()) |
| | { |
| | if (settings.UseLocalSpaceLinearVelocity) |
| | { |
| | writer.Add(vel, offset); |
| | offset += 3; |
| | } |
| | } |
| | } |
| |
|
| | return offset - baseOffset; |
| | } |
| | } |
| | } |
| |
|