1212
1313namespace ZO . Sensors {
1414
15- /// <summary>
16- /// This job process the framebuffer data of float32 R, G, B, D pixels and converts to
17- /// </summary>
18- [ BurstCompile ( CompileSynchronously = true ) ]
19- struct ZOPostProcessFrameBuffer : IJobParallelForBatch {
20- [ ReadOnly ] public float DepthScale ;
21- [ ReadOnly ] public NativeArray < float > FrameBuffer ;
22-
23- public NativeArray < float > DepthValues ;
24- public NativeArray < byte > RGBValues ;
25- public void Execute ( int startIndex , int count ) {
26- int end = startIndex + count ;
27- int pixelIdx = startIndex / 4 ;
28- int rgbPixelIdx = pixelIdx * 3 ;
29- float r = FrameBuffer [ startIndex + 0 ] ;
30- float g = FrameBuffer [ startIndex + 0 ] ;
31- float b = FrameBuffer [ startIndex + 0 ] ;
32- float d = FrameBuffer [ startIndex + 0 ] ;
33-
34- RGBValues [ rgbPixelIdx + 0 ] = ( byte ) ( b * 255.0f ) ;
35- RGBValues [ rgbPixelIdx + 1 ] = ( byte ) ( g * 255.0f ) ;
36- RGBValues [ rgbPixelIdx + 2 ] = ( byte ) ( r * 255.0f ) ;
37- DepthValues [ pixelIdx ] = d * DepthScale ;
38-
39-
40- }
41- } ;
42-
43-
4415 /// <summary>
4516 /// A RGB image + depth camera sensor.
4617 /// </summary>
@@ -52,15 +23,6 @@ public enum FrameOutputType {
5223 } ;
5324
5425 [ Header ( "Camera Parameters" ) ]
55- public string _cameraId = "none" ;
56-
57- /// <summary>
58- /// The unique name identifying this depth camera.
59- /// </summary>
60- /// <value></value>
61- public string Name {
62- get => _cameraId ;
63- }
6426 public Camera _camera ;
6527
6628 /// <summary>
@@ -170,12 +132,33 @@ public Vector2 SensorSizeMM {
170132 private Queue < Task > _publishTasks = new Queue < Task > ( ) ;
171133
172134
173- protected override void ZOReset ( ) {
174- base . ZOReset ( ) ;
175- UpdateRateHz = 30 ;
176-
135+
136+ protected override void ZOOnValidate ( ) {
137+ base . ZOOnValidate ( ) ;
138+ // if camera is not assigned see if we have a camera component on this game object
139+ if ( _camera == null ) {
140+ _camera = this . GetComponent < Camera > ( ) ;
141+ }
142+
143+ // if no post process material then assign default
144+ if ( _rgbDepthCameraShader == null ) {
145+ #if UNITY_EDITOR
146+ _rgbDepthCameraShader = Resources . Load < Material > ( "ZORGBDMaterial" ) ;
147+ #else // UNITY_EDITOR
148+ _rgbDepthCameraShader = ZOROSUnityManager . Instance . DefaultAssets . LoadAsset < Material > ( "ZORGBDMaterial" ) ;
149+ #endif // UNITY_EDITOR
150+ }
151+
152+ if ( UpdateRateHz == 0 ) {
153+ UpdateRateHz = 10 ;
154+ }
155+
156+ if ( Name == "" ) {
157+ Name = gameObject . name + "_" + Type ;
158+ }
177159 }
178160
161+
179162 protected override void ZOAwake ( ) {
180163 base . ZOAwake ( ) ;
181164 _fieldOfViewDegrees = UnityCamera . fieldOfView ;
@@ -300,7 +283,7 @@ private void DoRenderTextureUpdate() {
300283 _averageDepth = d ;
301284
302285 }
303- OnPublishDelegate ( this , _cameraId , _width , _height , _colorPixels24 , _depthBufferFloat ) ;
286+ OnPublishDelegate ( this , Name , _width , _height , _colorPixels24 , _depthBufferFloat ) ;
304287 } ) ;
305288
306289 _publishTasks . Enqueue ( publishTask ) ;
@@ -326,6 +309,19 @@ private void OnDestroy() {
326309 _rgbValues . Dispose ( ) ;
327310 }
328311
312+ public string Type {
313+ get { return "sensor.rgbdebthgcamera" ; }
314+ }
315+
316+ [ SerializeField ] public string _name ;
317+ public string Name {
318+ get {
319+ return _name ;
320+ }
321+ private set {
322+ _name = value ;
323+ }
324+ }
329325
330326
331327 }
0 commit comments