@@ -22,9 +22,11 @@ public class LivoxSensor : Sensor
22
22
private int _scanSeparation = 40 ;
23
23
24
24
[ SerializeField ]
25
- private float _minRange = 0.1f ;
25
+ private float _minDistance = 0.1f ;
26
26
[ SerializeField ]
27
- private float _maxRange = 100.0f ;
27
+ private float _maxDistance = 100.0f ;
28
+ [ SerializeField ]
29
+ private float _maxIntensity = 255.0f ;
28
30
[ SerializeField ]
29
31
private float _gaussianNoiseSigma = 0.0f ;
30
32
@@ -45,6 +47,7 @@ public class LivoxSensor : Sensor
45
47
private UpdateGaussianNoisesJob _updateGaussianNoisesJob ;
46
48
private Random _random ;
47
49
public NativeArray < Vector3 > points ;
50
+ public NativeArray < float > intensities ;
48
51
private NativeArray < Vector3 > _directions ;
49
52
private NativeArray < int > _pixelIndices ;
50
53
private NativeArray < float > _noises ;
@@ -89,8 +92,8 @@ private void SetupCamera()
89
92
90
93
_cam . targetTexture = _rt ;
91
94
_cam . fieldOfView = fov ;
92
- _cam . nearClipPlane = _minRange ;
93
- _cam . farClipPlane = _maxRange ;
95
+ _cam . nearClipPlane = _minDistance ;
96
+ _cam . farClipPlane = _maxDistance ;
94
97
_cam . gameObject . AddComponent < DepthCamera > ( ) ;
95
98
_cam . clearFlags = CameraClearFlags . SolidColor ;
96
99
@@ -118,6 +121,7 @@ private void SetupIndicesAndDirections()
118
121
private void SetupJob ( )
119
122
{
120
123
points = new NativeArray < Vector3 > ( _pointsNum , Allocator . Persistent ) ;
124
+ intensities = new NativeArray < float > ( _pointsNum , Allocator . Persistent ) ;
121
125
_randomSeed = ( uint ) Environment . TickCount ;
122
126
_random = new Random ( _randomSeed ) ;
123
127
@@ -132,14 +136,18 @@ private void SetupJob()
132
136
133
137
_textureToPointsJob = new TextureToPointsJob ( )
134
138
{
135
- far = _maxRange ,
136
139
scanSeparation = _scanSeparation ,
137
140
separationCounter = 0 ,
141
+ minDistance = _minDistance ,
142
+ minDistance_sqr = _minDistance * _minDistance ,
143
+ maxDistance = _maxDistance ,
144
+ maxIntensity = _maxIntensity ,
138
145
pixelIndices = _pixelIndices ,
139
146
directions = _directions ,
140
147
pixels = _texture . GetPixelData < Color > ( 0 ) ,
141
148
noises = _noises ,
142
- points = points
149
+ points = points ,
150
+ intensities = intensities
143
151
} ;
144
152
}
145
153
@@ -183,6 +191,7 @@ private void OnDestroy()
183
191
_pixelIndices . Dispose ( ) ;
184
192
_directions . Dispose ( ) ;
185
193
points . Dispose ( ) ;
194
+ intensities . Dispose ( ) ;
186
195
187
196
_rt . Release ( ) ;
188
197
}
@@ -208,10 +217,18 @@ public void Execute(int index)
208
217
[ BurstCompile ]
209
218
private struct TextureToPointsJob : IJobParallelFor
210
219
{
211
- public float far ;
212
220
public int scanSeparation ;
213
221
public int separationCounter ;
214
222
223
+ [ ReadOnly ]
224
+ public float minDistance ;
225
+ [ ReadOnly ]
226
+ public float minDistance_sqr ;
227
+ [ ReadOnly ]
228
+ public float maxDistance ;
229
+ [ ReadOnly ]
230
+ public float maxIntensity ;
231
+
215
232
[ ReadOnly ]
216
233
public NativeArray < int > pixelIndices ;
217
234
[ ReadOnly ]
@@ -223,13 +240,18 @@ private struct TextureToPointsJob : IJobParallelFor
223
240
public NativeArray < float > noises ;
224
241
225
242
public NativeArray < Vector3 > points ;
243
+ public NativeArray < float > intensities ;
226
244
227
245
public void Execute ( int index )
228
246
{
229
247
int offset = points . Length * separationCounter / scanSeparation ;
230
248
int pixelIndex = pixelIndices . AsReadOnly ( ) [ index + offset ] ;
231
- float distance = pixels . AsReadOnly ( ) [ pixelIndex ] . r ;
232
- points [ index ] = directions . AsReadOnly ( ) [ index + offset ] * ( far * Mathf . Clamp01 ( 1.0f - distance ) + noises [ index ] ) ;
249
+ float distance = maxDistance * Mathf . Clamp01 ( 1.0f - pixels . AsReadOnly ( ) [ pixelIndex ] . r ) + noises [ index ] ;
250
+ bool isValid = ( minDistance <= distance && distance <= maxDistance ) ;
251
+ if ( ! isValid ) distance = 0 ;
252
+ points [ index ] = directions . AsReadOnly ( ) [ index + offset ] * distance ;
253
+ float distance_sqr = distance * distance ;
254
+ intensities [ index ] = isValid ? maxIntensity * minDistance_sqr / distance_sqr : 0 ;
233
255
}
234
256
}
235
257
}
0 commit comments