Skip to content

Made it possible to initialize LiDARSensor later so that it works with the built app. #197

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

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ public class DepthBufferLiDARSensor : LiDARSensor

protected override void Init()
{
base.Init();
if (scanPattern == null)
{
Debug.LogWarning("Initialization postponed: scanPattern is null. Ensure that scanPattern is assigned before calling Init.");
return;
}
Initialize();
}

public override void Initialize()
{
base.Initialize();
_transform = this.transform;
SetupCamera();
LoadScanData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public abstract class LiDARSensor : UnitySensor, IPointCloudInterface<PointXYZI>
public int pointsNum { get => _pointsNumPerScan; }

protected override void Init()
{
if (_scanPattern == null)
{
return;
}
Initialize();
}

public virtual void Initialize()
{
_pointsNumPerScan = Mathf.Clamp(_pointsNumPerScan, 1, scanPattern.size);
_pointCloud = new PointCloud<PointXYZI>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ public class RaycastLiDARSensor : LiDARSensor

protected override void Init()
{
base.Init();
if (scanPattern == null)
{
Debug.LogWarning("RaycastLiDARSensor: scanPattern is null. Initialization is delayed until scanPattern is set.");
return;
}
Initialize();
}

public override void Initialize()
{
base.Initialize();

_transform = this.transform;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public class LiDARPointCloud2MsgPublisher : PointCloud2MsgPublisher<PointXYZI>

private void Awake()
{
if (_source == null)
{
Debug.LogError("Source is not set in LiDARPointCloud2MsgPublisher. Please ensure that the '_source' field is assigned in the Unity Editor or via code. Expected type: IPointCloudInterface<PointXYZI>.");
return;
}
_serializer.SetSource(_source as IPointCloudInterface<PointXYZI>);
}
}
Expand Down
Loading