Skip to content

Commit d91688b

Browse files
committed
fixed rgb depth camera
1 parent 1994fa6 commit d91688b

File tree

9 files changed

+87
-327
lines changed

9 files changed

+87
-327
lines changed

Runtime/Scripts/Sensors/RGBCamera/ZORGBCamera.cs

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace ZO.Sensors {
1717
/// Simulation of a color RGB camera sensor.
1818
/// </summary>
1919
[RequireComponent(typeof(Camera))] //[ExecuteInEditMode]
20-
public class ZORGBCamera : ZOGameObjectBase, ZOSerializationInterface {
20+
public class ZORGBCamera : ZOGameObjectBase {
2121
[Header("Camera Parameters")]
2222
public Camera _camera;
2323
// public bool _isMonochrome = false;
@@ -287,60 +287,6 @@ private set {
287287
}
288288
}
289289

290-
private JObject _json;
291-
public JObject JSON {
292-
get => _json;
293-
}
294-
295-
296-
public JObject Serialize(ZOSimDocumentRoot documentRoot, UnityEngine.Object parent = null) {
297-
JObject json = new JObject(
298-
new JProperty("name", Name),
299-
new JProperty("type", Type),
300-
new JProperty("width", _width),
301-
new JProperty("height", _height),
302-
new JProperty("aspect_ratio", UnityCamera.aspect),
303-
new JProperty("field_of_view", UnityCamera.fieldOfView),
304-
new JProperty("depth", UnityCamera.depth),
305-
new JProperty("sensor_size", UnityCamera.sensorSize.ToJSON()),
306-
new JProperty("focal_length", UnityCamera.focalLength)
307-
);
308-
309-
310-
ZOSimOccurrence parent_occurrence = GetComponent<ZOSimOccurrence>();
311-
if (parent_occurrence) {
312-
json["parent_occurrence"] = parent_occurrence.Name;
313-
}
314-
315-
_json = json;
316-
317-
return json;
318-
}
319-
320-
321-
public void Deserialize(ZOSimDocumentRoot documentRoot, JObject json) {
322-
// Assert.Equals(json["type"].Value<string>() == Type);
323-
324-
if (UnityCamera == null) { // check if there is already a camera assigned.
325-
UnityCamera = GetComponent<Camera>(); // check if we have a camera component but it is unassigend
326-
if (UnityCamera == null) {
327-
// we have no camera so create one
328-
UnityCamera = gameObject.AddComponent<Camera>();
329-
}
330-
}
331-
_json = json;
332-
Name = json.ValueOrDefault("name", Name);
333-
_width = json.ValueOrDefault("width", _width);
334-
_height = json.ValueOrDefault("height", _height);
335-
UnityCamera.aspect = json.ValueOrDefault("aspect_ratio", UnityCamera.aspect);
336-
UnityCamera.fieldOfView = json.ValueOrDefault("field_of_view", UnityCamera.fieldOfView);
337-
UnityCamera.depth = json.ValueOrDefault("depth", UnityCamera.depth);
338-
UnityCamera.sensorSize = json.ToVector2OrDefault("sensor_size", UnityCamera.sensorSize);
339-
UnityCamera.focalLength = json.ValueOrDefault("focal_length", UnityCamera.focalLength);
340-
341-
Initialize();
342-
343-
}
344290
#endregion
345291

346292

Runtime/Scripts/Sensors/RGBDepthCamera/ZORGBDepthCamera.cs

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,6 @@
1212

1313
namespace 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

Comments
 (0)