From 016e84f8133e5ab0ca00a8434d21259137a34491 Mon Sep 17 00:00:00 2001 From: Sherif Nafee Date: Wed, 13 Aug 2025 12:35:32 +0300 Subject: [PATCH 1/2] Update PointsToPointCloud2MsgJob.cs --- Runtime/Tx/PointsToPointCloud2MsgJob.cs | 27 ++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Runtime/Tx/PointsToPointCloud2MsgJob.cs b/Runtime/Tx/PointsToPointCloud2MsgJob.cs index 7395f52..5cea4e8 100644 --- a/Runtime/Tx/PointsToPointCloud2MsgJob.cs +++ b/Runtime/Tx/PointsToPointCloud2MsgJob.cs @@ -6,21 +6,34 @@ namespace ProBridge.Tx.Sensor { [BurstCompile] - public struct PointsToPointCloud2MsgJob : IJobParallelFor - where T : struct, IPointXYZInterface + public struct PointsToPointCloud2MsgJob : IJobParallelFor { - [ReadOnly] public NativeArray points; + [ReadOnly] public NativeArray points; + [ReadOnly] public bool _includeIntensity; public NativeArray data; - + public void Execute(int index) { - NativeArray tmp = new NativeArray(3, Allocator.Temp); + var tmp = CreateTempArray(index); + var slice = new NativeSlice(tmp).SliceConvert(); + var bytesPerPoint = _includeIntensity ? 16 : 12; + slice.CopyTo(data.GetSubArray(index * bytesPerPoint, bytesPerPoint)); + } + + private NativeArray CreateTempArray(int index) + { + var size = _includeIntensity ? 4 : 3; + var tmp = new NativeArray(size, Allocator.Temp); tmp[0] = points[index].position.z; tmp[1] = -points[index].position.x; tmp[2] = points[index].position.y; - var slice = new NativeSlice(tmp).SliceConvert(); - slice.CopyTo(data.GetSubArray(index * 12, 12)); + if (_includeIntensity) + { + tmp[3] = points[index].intensity; + } + return tmp; } + } } \ No newline at end of file From 33cd34bb4db7f06af68fde9e616bdf617ea60353 Mon Sep 17 00:00:00 2001 From: Sherif Nafee Date: Wed, 13 Aug 2025 12:35:36 +0300 Subject: [PATCH 2/2] Update RaycastLiDARTx.cs --- Runtime/Tx/RaycastLiDARTx.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Runtime/Tx/RaycastLiDARTx.cs b/Runtime/Tx/RaycastLiDARTx.cs index 2b8d3f0..e1d0066 100644 --- a/Runtime/Tx/RaycastLiDARTx.cs +++ b/Runtime/Tx/RaycastLiDARTx.cs @@ -20,6 +20,7 @@ public class RaycastLiDARTx : ProBridgeTxStamped public float _minRange = 0.5f; public float _maxRange = 100.0f; public float _gaussianNoiseSigma = 0.0f; + public bool _includeIntensity; public float _maxIntensity = 255.0f; public float minAzimuthAngle = 0; public float maxAzimuthAngle = 360f; @@ -28,7 +29,7 @@ public class RaycastLiDARTx : ProBridgeTxStamped private RaycastLiDARSensor sensor; - private PointsToPointCloud2MsgJob _pointsToPointCloud2MsgJob; + private PointsToPointCloud2MsgJob _pointsToPointCloud2MsgJob; private FilterZeroPointsParallelJob _zeroFilterJob; private JobHandle _jobHandle; @@ -60,7 +61,7 @@ protected override void AfterEnable() sensor.UpdateSensor(); - data.fields = new PointField[3]; + data.fields = new PointField[_includeIntensity ? 4 : 3]; for (int i = 0; i < 3; i++) { data.fields[i] = new PointField(); @@ -70,6 +71,15 @@ protected override void AfterEnable() data.fields[i].count = 1; } + if (_includeIntensity) + { + data.fields[3] = new PointField(); + data.fields[3].name = "intensity"; + data.fields[3].offset = 0; + data.fields[3].datatype = PointField.FLOAT32; + data.fields[3].count = 1; + } + CalculateFieldsOffset(); } @@ -155,10 +165,11 @@ protected override ProBridge.Msg GetMsg(TimeSpan ts) data.data = new byte[data.row_step * data.height]; tempData = new NativeArray((int)(data.row_step * data.height), Allocator.TempJob); tempPointsInput = tempQueue.ToArray(Allocator.TempJob); - _pointsToPointCloud2MsgJob = new PointsToPointCloud2MsgJob() + _pointsToPointCloud2MsgJob = new PointsToPointCloud2MsgJob { points = tempPointsInput, - data = tempData + data = tempData, + _includeIntensity = _includeIntensity }; _jobHandle = _pointsToPointCloud2MsgJob.Schedule(tempQueue.Count, 12);