Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GPU skinning and update multi-return modes #353

Merged
merged 4 commits into from
Oct 1, 2024
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,11 @@ MonoBehaviour:
m_EditorClassIdentifier:
AutomaticCaptureHz: 10
modelPreset: 8
returnType: 0
returnMode: 16777220
applyDistanceGaussianNoise: 1
applyAngularGaussianNoise: 1
applyVelocityDistortion: 0
simulateBeamDivergence: 0
doValidateConfigurationOnStartup: 1
configuration:
id: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,11 @@ MonoBehaviour:
m_EditorClassIdentifier:
AutomaticCaptureHz: 10
modelPreset: 11
returnType: 0
returnMode: 16777220
applyDistanceGaussianNoise: 1
applyAngularGaussianNoise: 1
applyVelocityDistortion: 0
simulateBeamDivergence: 0
doValidateConfigurationOnStartup: 1
configuration:
id: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,11 @@ MonoBehaviour:
m_EditorClassIdentifier:
AutomaticCaptureHz: 10
modelPreset: 6
returnType: 0
returnMode: 16777220
applyDistanceGaussianNoise: 1
applyAngularGaussianNoise: 1
applyVelocityDistortion: 0
simulateBeamDivergence: 0
doValidateConfigurationOnStartup: 1
configuration:
id: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,11 @@ MonoBehaviour:
m_EditorClassIdentifier:
AutomaticCaptureHz: 10
modelPreset: 5
returnType: 0
returnMode: 16777220
applyDistanceGaussianNoise: 1
applyAngularGaussianNoise: 1
applyVelocityDistortion: 0
simulateBeamDivergence: 0
doValidateConfigurationOnStartup: 1
configuration:
id: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,11 @@ MonoBehaviour:
m_EditorClassIdentifier:
AutomaticCaptureHz: 10
modelPreset: 9
returnType: 0
returnMode: 16777220
applyDistanceGaussianNoise: 1
applyAngularGaussianNoise: 1
applyVelocityDistortion: 0
simulateBeamDivergence: 0
doValidateConfigurationOnStartup: 1
configuration:
id: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ MonoBehaviour:
m_EditorClassIdentifier:
AutomaticCaptureHz: 10
modelPreset: 10
returnType: 0
returnMode: 16777220
applyDistanceGaussianNoise: 1
applyAngularGaussianNoise: 1
applyVelocityDistortion: 0
simulateBeamDivergence: 0
doValidateConfigurationOnStartup: 1
configuration:
id: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ MonoBehaviour:
m_EditorClassIdentifier:
AutomaticCaptureHz: 20
modelPreset: 7
returnType: 0
returnMode: 16777220
applyDistanceGaussianNoise: 1
applyAngularGaussianNoise: 1
applyVelocityDistortion: 0
simulateBeamDivergence: 0
doValidateConfigurationOnStartup: 1
configuration:
id: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ MonoBehaviour:
m_EditorClassIdentifier:
AutomaticCaptureHz: 10
modelPreset: 2
returnType: 0
returnMode: 16777220
applyDistanceGaussianNoise: 1
applyAngularGaussianNoise: 1
applyVelocityDistortion: 0
simulateBeamDivergence: 0
doValidateConfigurationOnStartup: 1
configuration:
id: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ MonoBehaviour:
m_EditorClassIdentifier:
AutomaticCaptureHz: 10
modelPreset: 3
returnType: 0
returnMode: 16777220
applyDistanceGaussianNoise: 1
applyAngularGaussianNoise: 1
applyVelocityDistortion: 0
simulateBeamDivergence: 0
doValidateConfigurationOnStartup: 1
configuration:
id: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,11 @@ MonoBehaviour:
m_EditorClassIdentifier:
AutomaticCaptureHz: 10
modelPreset: 4
returnType: 0
returnMode: 16777220
applyDistanceGaussianNoise: 1
applyAngularGaussianNoise: 1
applyVelocityDistortion: 0
simulateBeamDivergence: 0
doValidateConfigurationOnStartup: 1
configuration:
id: 0
Expand Down
Binary file not shown.
Binary file not shown.
33 changes: 21 additions & 12 deletions Assets/RGLUnityPlugin/Scripts/LidarSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public class LidarSensor : MonoBehaviour
[Tooltip("Allows to select one of built-in LiDAR models")]
public LidarModel modelPreset = LidarModel.RangeMeter;

[Tooltip("Allows to select between not divergent beams and different multi-return modes")]
public RGLReturnType returnType = RGLReturnType.RGL_RETURN_TYPE_NOT_DIVERGENT;
[Tooltip("Allows to select between LiDAR return modes")]
public RGLReturnMode returnMode = RGLReturnMode.SingleReturnFirst;

[Tooltip("Allows to quickly enable/disable distance gaussian noise")]
public bool applyDistanceGaussianNoise = true;
Expand All @@ -58,6 +58,9 @@ public class LidarSensor : MonoBehaviour
[Tooltip("Allows to quickly enable/disable velocity distortion")]
public bool applyVelocityDistortion = false;

[Tooltip("If disable, both beam divergence values are set to 0. Otherwise, they are set based on LiDAR configuration.")]
public bool simulateBeamDivergence = false;

[Tooltip(
"If enabled, validates whether the configuration is the same as the manual for the selected model (only on startup)")]
public bool doValidateConfigurationOnStartup = true;
Expand Down Expand Up @@ -85,7 +88,6 @@ public class LidarSensor : MonoBehaviour
private const string lidarPoseNodeId = "LIDAR_POSE";
private const string noiseLidarRayNodeId = "NOISE_LIDAR_RAY";
private const string lidarRaytraceNodeId = "LIDAR_RAYTRACE";
private const string lidarMRNodeId = "LIDAR_MR";
private const string noiseHitpointNodeId = "NOISE_HITPOINT";
private const string noiseDistanceNodeId = "NOISE_DISTANCE";
private const string pointsCompactNodeId = "POINTS_COMPACT";
Expand Down Expand Up @@ -113,7 +115,6 @@ public void Awake()
.AddNodeRaysTransform(lidarPoseNodeId, Matrix4x4.identity)
.AddNodeGaussianNoiseAngularRay(noiseLidarRayNodeId, 0, 0)
.AddNodeRaytrace(lidarRaytraceNodeId)
.AddNodeMultiReturnSwitch(lidarMRNodeId, RGLReturnType.RGL_RETURN_TYPE_NOT_DIVERGENT)
.AddNodeGaussianNoiseAngularHitpoint(noiseHitpointNodeId, 0, 0)
.AddNodeGaussianNoiseDistance(noiseDistanceNodeId, 0, 0, 0);

Expand All @@ -129,7 +130,7 @@ public void Awake()

public void Start()
{
sceneManager = FindObjectOfType<SceneManager>();
sceneManager = SceneManager.Instance;
if (sceneManager == null)
{
// TODO(prybicki): this is too tedious, implement automatic instantiation of RGL Scene Manager
Expand All @@ -144,8 +145,7 @@ public void Start()
if (LidarSnowManager.Instance != null)
{
// Add deactivated node with some initial values. To be activated and updated when validating.
rglGraphLidar.AddNodePointsSimulateSnow(snowNodeId, 0.0f, 1.0f, 0.0001f, 0.0001f, 0.2f, 0.01f, 1, 0.01f,
false, 0.0f);
rglGraphLidar.AddNodePointsSimulateSnow(snowNodeId, 0.0f, 1.0f, 0.0001f, 0.0001f, 0.2f, 0.01f, 1, 0.01f, 0.0f);
rglGraphLidar.SetActive(snowNodeId, false);
LidarSnowManager.Instance.OnNewConfig += OnValidate;
}
Expand Down Expand Up @@ -199,10 +199,9 @@ private void ApplyConfiguration(BaseLidarConfiguration newConfig)
newConfig.noiseParams.angularNoiseMean * Mathf.Deg2Rad,
newConfig.noiseParams.angularNoiseStDev * Mathf.Deg2Rad)
.UpdateNodeGaussianNoiseDistance(noiseDistanceNodeId, newConfig.noiseParams.distanceNoiseMean,
newConfig.noiseParams.distanceNoiseStDevBase, newConfig.noiseParams.distanceNoiseStDevRisePerMeter)
.UpdateMultiReturnSwitch(lidarMRNodeId, returnType);
newConfig.noiseParams.distanceNoiseStDevBase, newConfig.noiseParams.distanceNoiseStDevRisePerMeter);

if (returnType != RGLReturnType.RGL_RETURN_TYPE_NOT_DIVERGENT)
if (simulateBeamDivergence)
{
rglGraphLidar.ConfigureNodeRaytraceBeamDivergence(lidarRaytraceNodeId,
Mathf.Deg2Rad * newConfig.horizontalBeamDivergence,
Expand All @@ -212,6 +211,8 @@ private void ApplyConfiguration(BaseLidarConfiguration newConfig)
{
rglGraphLidar.ConfigureNodeRaytraceBeamDivergence(lidarRaytraceNodeId, 0.0f, 0.0f);
}

rglGraphLidar.ConfigureNodeRaytraceReturnMode(lidarRaytraceNodeId, returnMode);

rglGraphLidar.SetActive(noiseDistanceNodeId, applyDistanceGaussianNoise);
var angularNoiseType = newConfig.noiseParams.angularNoiseType;
Expand All @@ -235,8 +236,11 @@ private void ApplyConfiguration(BaseLidarConfiguration newConfig)
LidarSnowManager.Instance.Density,
newConfig.laserArray.GetLaserRingIds().Length,
newConfig.horizontalBeamDivergence * Mathf.Deg2Rad,
LidarSnowManager.Instance.DoSimulateEnergyLoss,
LidarSnowManager.Instance.SnowflakeOccupancyThreshold);
LidarSnowManager.Instance.OccupancyThreshold);
rglGraphLidar.UpdateNodePointsSnowDefaults(snowNodeId,
LidarSnowManager.Instance.SnowflakesId,
LidarSnowManager.Instance.FullBeamIntensity,
0.0f); // Default, because it is not supported in AWSIM.
}

rglGraphLidar.SetActive(snowNodeId, LidarSnowManager.Instance.IsSnowEnabled);
Expand All @@ -263,6 +267,11 @@ private void ApplyConfiguration(BaseLidarConfiguration newConfig)
public void OnEnable()
{
activeSensors.Add(this);
// Sync timer with the active sensors to achieve the best performance. It minimizes number of scene updates.
if (activeSensors.Count > 0)
{
timer = activeSensors[0].timer;
}
}

public void OnDisable()
Expand Down
24 changes: 17 additions & 7 deletions Assets/RGLUnityPlugin/Scripts/LidarSnowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public class LidarSnowManager : MonoBehaviour
public delegate void OnNewConfigDelegate();
public OnNewConfigDelegate OnNewConfig;

[field: Header("Base Settings")]

[field: SerializeField]
public bool IsSnowEnabled { get; private set; } = false;

// Snow model properties
[field: SerializeField]
[field: Tooltip("The precipitation rate for snow is expressed in rate of equivalent water depth in mm per hour")]
Expand All @@ -51,15 +56,20 @@ public class LidarSnowManager : MonoBehaviour
public float Density { get; private set; } = 0.07f;

[field: SerializeField]
[field: Tooltip("If true, a more sophisticated method is used, which takes into account the energy loss of the lidar beam when hitting snowflakes")]
public bool DoSimulateEnergyLoss { get; private set; } = true;

[field: SerializeField]
[field: Tooltip("Minimal snowflake occupancy (in fraction of ray beam angle) included in energy loss calculation")]
[field: Tooltip("Minimal beam aperture occupancy (ratio) that means a hit, both for snowflakes and for original hit")]
[field: Range(0.0f, 1.0f)]
public float SnowflakeOccupancyThreshold { get; private set; } = 0.0f;
public float OccupancyThreshold { get; private set; } = 0.0f;

public bool IsSnowEnabled { get; private set; } = false;
[field: Header("Defaults")]

[field: SerializeField]
[field: Tooltip("Entity ID that is assigned to cloud points resulting from snowflake hits")]
public int SnowflakesId { get; private set; } = 268435455; // Default RGL entity ID.

[field: SerializeField]
[field: Tooltip("Initial intensity of each LiDAR laser beam, used to evaluate energy loss based on beam aperture occupancy")]
[field: Min(0.0f)]
public float FullBeamIntensity { get; private set; } = 1.0f;

private void Awake()
{
Expand Down
Loading
Loading